help with fortran program

Hi,
Please bear with me on this because I'm really not a programmer at all but I need some help with modifying a code in fortran. This program is supposed to extract data for a single month of data at a time from the file highlighted in red below which contains 108 years of data. First of all, I would like to be able to call forth that file automatically without having to type it in everytime. I tried to put in a 'write' line to do that but when it came up in the program run, it didn't have the backslashes.
Second, rather than getting one month at a time, I would like to get all the months from a given year in each output file.
Lastly, the part at the bottom highlighted in green is dealing with latitudes. I only want to get latitudes within a certain range, which I've already plugged in. however, for the values i.gt.8.5, I don't want them to be included, so what do I have to put on the right side of that part to make that happen. Thanks in advance for any help anyone can offer!

Program read_gridded_all

integer valu(36,72)
integer i
integer imonth,jmonth,iyear,jyear
integer datachk
integer openfile
integer loopcnt
real lat,lon
character*110 infile,outfile
character*5 FMT100
character*6 FMT20

C INITIALIZE VARIABLES
datachk = 0
openfile = 0
loopcnt = 0

C ASK USER FOR INPUT GRID SET
write(*,*) 'Enter gridded dataset filename. '
C [color=Red] write(*,*) 'C:Program FilesForce 2.0grid_prcp_1900-2008.dat'[/color]
read(*,10) infile
C OPEN INPUT FILE
open(10,file=infile,status='old',err=500)
openfile = 1

C GRIDDED FILENAME NOT VALID
500 do while(openfile .eq. 0)
write(*,*) 'Cannot open ',infile
write(*,*) 'Reenter gridded dataset filename.'
read(*,10) infile
open(10,file=infile,status='old',err=500)
openfile = 1
enddo

C ASK USER FOR OUTPUT FILENAME
write(*,*) 'Enter output filename for gridded subset. '
read(*,10) outfile
C OPEN OUTPUT FILE
open(11,file=outfile)

C ASK USER FOR MONTH AND YEAR TO EXTRACT
write(*,*) 'Enter month to extract',
*'- integer format (1=>Jan, 2=>Feb, etc.)'
read(*,40) imonth
write(*,*) 'Enter year to extract'
read(*,40) iyear

10 format(a110)
40 format(i5)

FMT100 = '(2i5)'

write(*,*) 'Enter type of data, 1==>temp, 2==>prcp'
read(*,*) itype

if(itype.eq.1) then
FMT20 = '(12i5)'
else
FMT20 = '(12i7)'
endif

C LOOP OVER ALL MONTHS AND YEARS UNTIL FIND REQUESTED DATA
do while(datachk .ne. 1)
read(10,FMT100,end=900) jmonth, jyear
loopcnt = loopcnt + 1
C IF FOUND, THEN READ IN GRIDDED DATA
if(imonth .eq. jmonth .and. iyear .eq. jyear) then
write(*,50) imonth, iyear
50 format(' Reading gridded data for month ', i2.2,
*' and year ',i4)
do i = 1,36
do j = 1,6
read(10,FMT20) (valu(i,k),k=j*12-11,j*12)
enddo
enddo
C SET BOOLEAN TO TRUE
datachk = 1
C NOT CORRECT MONTH AND YEAR, SO SKIP GRIDDED DATA FIELDS
else
if(loopcnt.eq.1) then
write(*,110) imonth,iyear
110 format(' Searching for month ', i2.2, ' and year ',i4)
endif
do i = 1,216
read(10,*)
enddo
endif
enddo

C WRITE DATA TO OUTPUT FILE
write(*,*)'Writing output data to file'
do i = 1,36
[color=Green] if(i.le.8.5) lat = 92.5 - i * 5.0
elseif(i.gt.8.5) lat = ((i-18) * (-5.0)) + 2.5[/color]
do j = 1,72
if(valu(i,j) .ne. -9999) then
if(j.le.36) lon = (182.5 - (j * 5.0)) * (-1)
if(j.gt.36) lon = ((j-36) * 5.0) - 2.5
write(11,30) lat,lon,valu(i,j)/100.
endif
enddo
enddo

C CLOSE INPUT AND OUTPUT FILES
close(10,err=540)
close(11,err=560)

GO TO 999

30 format(f6.1,2x,f7.1,2x,f8.2)

540 write(*,*) 'Cannot close ',infile
560 write(*,*) 'Cannot close output file'
900 write(*,*) 'Requested Data Not Available!!!!'
write(*,*) 'Sorry - Try Again. Exiting Program!!!!'

999 STOP
END

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories