Reputation: 11
I try to run a fortran program for extraction data from MODIS 8 daily Leaf Area Index LAI and Fraction of Photosynthetic Active Radiation FPAR. first I projected MODIS raw *.hdf file to *.dat file by using *.sh. Then reformat from *.dat to *.txt by using g++ and this stage is my final stage of data preparation, which is combining all the *.txt data to specific format *.direct and *.8daily throughout the year from start to end by using fortran code.
Program read_8daily
Implicit None
integer ir,ic
integer nnr, nnc
character filename1*80,filename2*80, string*20, year*4, day*3
character hour*2, outfile*200, ch2*2, ch5*5, chim*2
integer rec,count,i,j,sta,im, iday, ihour,iyear,d
integer, dimension (300,300):: fpar0, lai0
real, dimension (300,300):: fpar, lai
integer, dimension (300,300)::modis1, modis2
integer startday,endday,starthour,endhour
integer rec_no
nnc = 328 ! For Red River Basin
nnr = 395
do iyear = 2010, 2010 ! Change year
write(year, '(i4.4)') iyear
startday = 1 ! change start date (if)
endday = 361 ! change end date (if)
print *, 'EVALUATING from:', iyear, startday
print *, '.............To:', iyear, endday
print *, 'Reading modis data...'
OPEN (15, file='FPAR.'//year//'.8daily',
: status='unknown')
OPEN (16, file='LAI.'//year//'.8daily',
: status='unknown')
OPEN (25, file='FPAR.'//year//'.direct',
: form = 'unformatted', access = 'direct',
: recl = 4*nnc*nnr, status='unknown')
OPEN (26, file='LAI.'//year//'.direct',
: form = 'unformatted', access = 'direct',
: recl = 4*nnc*nnr, status='unknown')
print *,'Writing', '..modis.'//year//'.daily'
rec_no = 0 !record number for every monthly data file
do iday = startday, endday, 8 !8-day snow cover product
write(day, '(i3.3)') iday
filename1= year//day//'.fpar.txt'
c filename1='/home/maheswor/koshi/LAIFPAR/input/koshi_' c ://year//'_'//day//'_fpar.txt'
filename2= year//day//'.lai.txt'
c filename2='/home/maheswor/koshi/LAIFPAR/input/koshi_' c ://year//'_'//day//'_lai.txt'
OPEN(7, file=filename1)
OPEN(8, file=filename2)
read(7,*) ((modis1(ir, ic),ic=1,nnc), ir=1,nnr)
read(8,*) ((modis2(ir, ic),ic=1,nnc), ir=1,nnr)
rec_no = rec_no + 1
print *, 'record number:', rec_no
do ir = 1, nnr
do ic=1, nnc
fpar0(ir,ic) = modis1(ir,ic)
lai0(ir,ic) = modis2(ir,ic)
end do
end do
print *, 'begin writing'
50 format(1x, 300i10) do ir = 1 ,nnr write(15,50) (fpar0(ir,ic),ic=1,nnc) write(16,50) (lai0(ir,ic),ic=1,nnc) end do
write(25,rec = rec_no) ((fpar0(ir,ic),ic=1,nnc),ir=1,nnr)
write(26,rec = rec_no) ((lai0(ir,ic), ic=1,nnc),ir=1,nnr)
end do !do iday = startday, enday
close(7)
close(8)
close(25)
close(26)
close(15)
close(16)
end do !do iyear
end program
I ran that script in cygwin. I encountered the following problem in the photo. Please check and help. gfortran run and error
Upvotes: 1
Views: 289
Reputation: 573
Values of index variables are larger than both array dimensions
integer, dimension (300,300):: fpar0, lai0
nnc = 328 ! For Red River Basin
nnr = 395
later you are using them in loops where this segmentation fault is happens
do ir = 1, nnr
do ic=1, nnc
fpar0(ir,ic) = modis1(ir,ic)
lai0(ir,ic) = modis2(ir,ic)
end do
end do
Upvotes: 1