[gradsusr] Reading 3d variable in FORTRAN after using fwrite

Thomas Robinson ter at hawaii.edu
Sat Apr 28 17:47:43 EDT 2012


Thank you very much this worked!

On Fri, Apr 27, 2012 at 6:14 PM, Hui Wang <hui.wang at noaa.gov> wrote:

> **
> Tom,
>
> You may try the following fortran codes,
>
>        real chi(nx,ny,nt)
>
>        open(29,file='CHI.2000.summer.dat',access='direct',
>      1 form='unformatted',recl=nx*ny*4)
>
>        do it=1,nt
>        read(29, rec=it) ((chi(i,j,it),i=1,nx),j=1,ny)
>        end do
>
> For recl, it may be just "nx*ny", depending on the computer you are using.
>
> Good luck,
> Hui
>
>
> On 4/27/2012 8:56 PM, Thomas Robinson wrote:
>
> Aloha,
>
> I used fwrite to write out a 2d variable that varies in time, so it has
> dimensions of x,y,t.
>
> nt=763
> 'set fwrite -le -sq -cl CHI.2000.summer.dat'
> 'set gxout fwrite'
> day = 360
> while (day <= nt)
>  'set t ' day
>  'd chi'
>   day=day+1
> endwhile
> 'disable fwrite'
>
> This seems to work fine.  When I go to try to open it using FORTRAN, I get
> an error.
>
>        real chi (nx,ny,nt)
>        open (29, file="CHI.2000.summer.dat", status="OLD",
>      &      access="sequential",form="unformatted")
>         read(29)chi
>
> If I have my chi variable as (nx,ny) there is no problem.  If I just set
> nt=2, then there is a problem when I run the program:
> PGFIO-F-219/unformatted read/unit=29/attempt to read/write past end of
> record.
>  File name = CHI.2000.summer.dat    unformatted, sequential access
> record = 1
>  In source file avg_chi.f, at line number 25
>
>
> I was feeling saucey and tried to change the code up adding
>       real chi_temp(nx,ny)
> and I tried this:
>       do 50 it=1,nt
>         write (6,*)it
>         read (29)chi_temp
>            do 51 ix=1,nx
>            do 52 iy=1,ny
>               chi(ix,iy,it)=chi_temp(ix,iy)
> 52        continue
> 51        continue
> 50    continue
>
> And this is what happened:
>             1
>             2
>             3
>             4
> PGFIO-F-217/unformatted read/unit=29/attempt to read past end of file.
>  File name = CHI.2000.summer.dat    unformatted, sequential access
> record = 4
>  In source file avg_chi.f, at line number 29
>
> I should have about 300 time steps.  Is there a limit or something?  Any
> help you could provide would be very much appreciated!
>
> --
> Tom Robinson
> At-Large Graduate Student Organization Representative
> Student Caucus Representative for the Graduate Student Organization
> Graduate Student - Department of Meteorology
> 732-718-2323
>
>
> _______________________________________________
> gradsusr mailing listgradsusr at gradsusr.orghttp://gradsusr.org/mailman/listinfo/gradsusr
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Tom Robinson
At-Large Graduate Student Organization Representative
Student Caucus Representative for the Graduate Student Organization
Graduate Student - Department of Meteorology
732-718-2323
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20120428/662a4226/attachment-0003.html 


More information about the gradsusr mailing list