Formatting 重新格式化未格式化的fortran文件

Formatting 重新格式化未格式化的fortran文件,formatting,fortran,Formatting,Fortran,我有一个“未格式化”的fortran文件,为此我编写了一个小的子程序,试图从中获取一些信息(如下所示)。我想做的,或者想知道是否有可能做的,是将名为fort.24的文件“格式化”为另一个格式化的、可读的文件,或者将可读的打印输出到屏幕上 我想在打开文件后放入一个循环,读取文件的每一行,然后将其打印到屏幕上,但我不知道如何做到这一点 我认为未格式化的文件可以重新格式化是正确的,还是“它不是这样工作的” 多谢各位 詹姆斯 不,您不能格式化未格式化的文件。您可以做的是读取未格式化的文件并将其内容写入格

我有一个“未格式化”的fortran文件,为此我编写了一个小的子程序,试图从中获取一些信息(如下所示)。我想做的,或者想知道是否有可能做的,是将名为fort.24的文件“格式化”为另一个格式化的、可读的文件,或者将可读的打印输出到屏幕上

我想在打开文件后放入一个循环,读取文件的每一行,然后将其打印到屏幕上,但我不知道如何做到这一点

我认为未格式化的文件可以重新格式化是正确的,还是“它不是这样工作的”

多谢各位

詹姆斯


不,您不能格式化未格式化的文件。您可以做的是读取未格式化的文件并将其内容写入格式化文件。如果需要,您可以删除未格式化的文件,将新文件重命名为旧文件的名称,并将其作为同一文件传递,但已格式化。非常感谢您的建议。我尝试将文件的每一行作为字符串读取,然后将该字符串打印到屏幕上,但这导致程序崩溃。你对怎么做有什么建议吗?(字符(len=80)::title1,title2…\\read(24)title1…print*,title1)错误是由于试图从未格式化文件中读取字符串行(实际上是一些整数)引起的。要读取“未格式化”fortran文件,您需要确切地知道它是如何写入的。如果您不知道写入文件的数据类型的确切顺序,则很难弄清楚。当然,标题中的具体问题的答案是,一旦你有了数据,你就可以用你喜欢的任何格式创建一个新文件。
  SUBROUTINE mod2

  implicit none

  !     Arguments
  integer :: nset_pw_dipoles, mgvn, stot, gutot, iprnt, iwrite, &
 &           ifail,dip_comp_present(3)
  character(len=11) ::  form_pw_dipoles
  character(len=80) ::  title
  integer, allocatable :: ichl(:), lvchl(:), mvchl(:)
  real(kind=8), allocatable :: evchl(:), escat(:),re_pw_dipoles(:,:,:,:), im_pw_dipoles(:,:,:,:)

  !     Local
  integer :: keydip, nchan, nbound, no_scat_energies, no_components, ierr
  no_components=3
  keydip=24

  open (unit=24,file = "fort.24", form="UNFORMATTED", iostat=ierr, err=100)

  !     Read set header
  !     ----------------
  read(24) keydip, nset_pw_dipoles
  read(24) title
  read(24) mgvn, stot, gutot, nchan, nbound, no_scat_energies, dip_comp_present

  !     Allocate space for channel info arrays
  allocate( ichl(nchan), lvchl(nchan), mvchl(nchan), evchl(nchan), escat(no_scat_energies) )

  read(24) ichl, lvchl, mvchl, evchl, escat

  !     Write Set Body
  !     --------------   

  !     Allocate space for partial wave dipoles
  allocate( re_pw_dipoles(nbound, nchan, no_components, no_scat_energies), &
 &          im_pw_dipoles(nbound, nchan, no_components, no_scat_energies) )

  read(24) re_pw_dipoles
  read(24) im_pw_dipoles

  return

  100 stop "ERROR: Reading partial wave dipoles"

  END SUBROUTINE mod2