How to read and write from files?

2012-05-01
2013-06-11
  • C. E. Coppola

    C. E. Coppola - 2012-05-01

    I have written one subroutine that generates a rank 4 array, and two subroutines that need to use this array.

    How can I write my input/output statements so that I will store this array efficiently in a file and also recall it quickly? I have been trying to use existing syntax but it is failing at runtime:

        to write:
      inquire(iolength=recl) array(:,:,:,:)
      open(10,file=trim(scrpath)//'OVERLAPS'//trim(filext),action='WRITE',form='UNFORMATTED',access='DIRECT',recl=recl)
      write(10,rec=ik) array(:,:,:,:)
      close(10)

       to read
        inquire(iolength=recl) array
      open(10,file=trim(scrpath)//'OVERLAPS'//trim(filext),action='READ',form='UNFORMATTED',access='DIRECT',recl=recl) 
      read(10,rec=ik) array
      close(10)

    The syntax "array_" doesn't seem to work, and the inquire fails to return a positive number. How can I write to and read from tjhe same file?

     
  • C. E. Coppola

    C. E. Coppola - 2012-05-01

    I searched for the read/write code on some other files in ELK. I came up with this syntax, but it gives me an error when I try to write:

    Error(global_index) : local index out of boundary
      ip :        1
      idxl :        9
    STOP execution
      global index of process :        0
    application called MPI_Abort(MPI_COMM_WORLD, -1) - process 0

    Here are the read/write codes:

      inquire(iolength=recl) overlap
      open(10,file='OVERLAPS.OUT',action='WRITE',form='UNFORMATTED',access='DIRECT',recl=recl)
      do ikloc=1,nkptnrloc
        ik=mpi_grid_map(nkpt,dim_k,loc=ikloc)
        write(10,rec=ik) overlap(:,:,:,ikloc)
      enddo
      close(10)

      inquire(iolength=recl) overlap
      open(10,file='OVERLAPS.OUT',action='WRITE',form='UNFORMATTED',access='DIRECT',recl=recl)
      do ikloc=1,nkptnrloc
        ik=mpi_grid_map(nkpt,dim_k,loc=ikloc)
        write(10,rec=ik) overlap(:,:,:,ikloc)
      enddo
      close(10)

    I just want it to store the array to a file so I can read from it in other subroutines. What is the best way to accomplish this?

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks