a question about fortran
Charles Seman
Charles.Seman at NOAA.GOV
Wed Feb 23 17:38:40 EST 2005
C Wang,
I would try the following (this hasn't been tested, so I don't know if
it will work...):
real a2d(ix,il)
IIREC=1
DO jj=1,JSTEPS/2
do k=1,kx
READ (11, REC=IIREC) a2d
WRITE (33, REC=IIREC) a2d
IIREC=IIREC+1
end do
END DO
IREC=1 <-- new index for unit 44...
IIREC=JSTEPS/2+1
DO jj=JSTEPS/2+1,JSTEPS <-- note the "+1" added to "JSTEPS/2", so we
don't run out of data from unit 11...
do k=1,kx
READ (11, REC=IIREC) a2d
IIREC=IIREC+1
WRITE (44, REC=IREC) a2d
IREC=IREC+1
end do
END DO
The Fortran units are expecting records with "ix*il" words, and we're
doing unformatted reads / writes above, which we have used here in our
codes. (depending on your computer system, you may not need the *4 in
the RECL specifier... if you've used the *4 in other codes with no
problems, then it is OK...)
I hope this helps,
Chuck
...
C wang wrote:
> Hi, can anybody help me with the question about how to read and write out
> files in fortran, I have a file which is bigger than 2G, so I cannot
> use it
> in grads directly, I need to divide it into 2 smaller files, the array of
> the original file is A(96,80,14) in 6000 days, if I want to write the
> file
> into 2 files, how can I do? this is what I have done, but it seems not
> right,
>
> open (11,file='a11.dat',form='unformatted',
> & STATUS='OLD', ACCESS='direct', RECL=IX*IL*4)
> OPEN (UNIT=33, FILE='33.dat', FORM='UNFORMATTED',
> & ACCESS='DIRECT', RECL=IX*IL*4)
> OPEN (UNIT=44, FILE='44.dat', FORM='UNFORMATTED',
> & ACCESS='DIRECT', RECL=IX*IL*4)
>
> IREC=1
> DO jj=1,JSTEPS
> DO k=1,kx
> READ (11, REC=IREC) ((A(I,J,K),J=1,IL),I=1,IX)
> IREC=IIREC+1
> END DO
> END DO
> c
> IIREC=1
> DO jj=1,JSTEPS/2
> do k=1,kx
> WRITE (33, REC=IIREC) ((A(I,J,K),J=1,IL),I=1,IX)
> IIREC=IIREC+1
> end do
> END DO
>
> IIREC=JSTEPS/2+1
> DO jj=JSTEPS/2,JSTEPS
> do k=1,kx
> WRITE (44, REC=IIREC) ((ASAVE(I,J,K),J=1,IL),I=1,IX)
> IIREC=IIREC+1
> end do
> END DO
>
> the error says: A direct access READ statement was executed past the
> end of
> file (unit=11, rec=84001).
>
> Thanks very much!
>
> _________________________________________________________________
> Is your PC infected? Get a FREE online computer virus scan from McAfee®
> Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
--
********************************************************************
Charles Seman Charles.Seman at noaa.gov
U.S. Department of Commerce / NOAA / OAR
Geophysical Fluid Dynamics Laboratory voice: (609) 452-6547
201 Forrestal Road fax: (609) 987-5063
Princeton, NJ 08542 http://www.gfdl.noaa.gov/~cjs/
********************************************************************
"The contents of this message are mine personally and do not reflect
any position of the Government or NOAA."
More information about the gradsusr
mailing list