Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Reading

Status
Not open for further replies.

Thardy

Technical User
Oct 29, 2011
13
Dear all,
Trying to read the climate binary program (then write to ascii) attached here but having an error at line 55. My Fortran program is below, thanks for the help:

implicit none
integer :: lon,lat,j,k,i
character*4 :: par !Psea
character*12 time !YYYYMMDDhhmm
integer*2 :: xpix,ypix !288,145
real*4 :: dxpix,dypix,d1,d2,d3,d4 !1.25,1.25,0.0,90.0,358.75,-90
character :: char*1,uni*3 !0,unit(Pa)
integer*4 :: size !size (byte)

integer*2 :: sea !pressure level at sea(1)
integer*2 :: rh !humidity levels(9)
integer*2 :: tem !alt, wind EW,Wind NS,temp levels(18)

integer*2 :: sea1(1:18) !levels(18*2=36)
character :: flag*1, zero*1 !flag,0
character :: fin*150,fout*150
real*4 :: t(288,145) !climate data
integer :: i_pix,j_pix
C integer, parameter:: irec=288*145*18
integer, parameter:: irec =288*145


fin='M2009.T'
fout='M2009.T.txt'

write(*,*)"start"

open(21,file=fin,form='unformatted',access='direct',
& recl=irec,status='old',convert='big_endian',err=999)

write(*,*) "step1"

read(21,rec=1)
& par,time,xpix,ypix,dxpix,dypix,d1,d2,d3,d4,
& char,uni,size,sea,(sea1(j),j=1,1)
& ,flag, zero
write(*,*) "step2"
write(*,*)
& par,time,xpix,ypix,dxpix,dypix,d1,d2,d3,d4,
& char,uni,size,sea,(sea1(j),j=1,18)
& ,flag,zero
write(*,*) "step3"
do j_pix=1,145
read(21,rec=j_pix)
& (t(i_pix,j_pix),i_pix=1,288)
write(*,*)
& par,time,xpix,ypix,dxpix,dypix,d1,d2,d3,d4,
& char,uni,size,sea,(sea1(j),j=1,18)
& ,flag, zero


write(*,*)
& (t(i_pix,j_pix),i_pix=1,288)
open(22,file=fout,form='formatted',status='old')

write(22,*)
& par,time,xpix,ypix,dxpix,dypix,d1,d2,d3,d4,
& char,uni,size,sea,(sea1(j),j=1,18),
& flag, zero,

& (t(i_pix,j_pix),i_pix=1,288)

end do

write(*,*) "zzzz"
close (21)
close (22)
999 continue
stop
End
 
Is the error in line 55 of the program or line 55 of the data?

What exactly does the error message say?
 
Why do you have the opening of the output file (fout) inside the loop? You are going to be opening this file over and over and over!?! You need to open such file just once before you enter the loop.

 
By the way, as much as I appreciate you consistency and style...I don't like it :-(

I am talking about your use of the continuation '&'.

Up to Fortran 77, continuation marks had to be in the following line and on column 6.

Starting in Fortran 90, which you are using, the recommendation is to have the continuation character in the SAME line, the one that is to be continued...this way, you KNOW right there and then when you finish the line, that it is to be continue so as to not be surprised by unfinished business or surprised when you thought you were done and come to find '&' in the next line.

Also, I think you are simply abusing it...you are using it even when there is no need for it and the statement more than fits in one line...but that's fine if that's how you wanna go about it...just place the '&' at the end of lines...well, that's just a recommendation, of course.
 
Oh, one last thing...I am no expert of binary stuff, but opening your binary file in an hex editor, the beginning reveals:

parameter 'par' to be 'T',
the date to be 2003-10-12 00:00:00

and after that it is a mess...
are you certain that this binary file was correctly written?

I tried to run your program and it sure fails when trying to open the binary file, no message.



 
Your error is that you open unit 22 with the status = 'old' clause on a file that does not exist. Skip this and your prog runs fine and produces a lot of output.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Hhhmmm...I can't get passed the opening the binary file.

g95 on cygwin on Windows XP

any ideas? just curious
 
Sorry, rereading my last post I found it could be misunderstood:

instead of

open(22,file=fout,form='formatted',status='old')

write

open(22,file=fout,form='formatted')

and your program runs fine. Of course, if you want to have all your output in your outputfile, you should observe Germàn's advice and put this statement before your loop. Just as it is right now, you will receive the data of the last execution of the loop only, for all other were superceded by the renewed opening of this file.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Hhhmmm...I can't get passed the opening the binary file.

Took me a while as well.

If you downloaaded the file it is called M2[bold]900[/bold].T instead of M2[bold]009[/bold].T as the name is in the prog.

Norbert




The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Though I'm still dealing with the issue of this file, thanks a lot for all the suggestions or answers provided by everyone. I appreciate them. Sorry for the file names' messup.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top