Cygwin gfortran程序收到信号SIGSEGV,Segmentation fault

时间:2016-03-11 05:39:12

标签: fortran gfortran

我尝试运行一个fortran程序,用于从MODIS 8每日叶面积指数LAI和光合有效辐射FPAR的分数中提取数据。首先,我使用* .sh将MODIS raw * .hdf文件投影到* .dat文件。然后使用g ++从* .dat重新格式化为* .txt,这个阶段是我的数据准备的最后阶段,它将所有* .txt数据从头到尾全年组合到特定格式* .direct和* .8daily通过使用fortran代码。

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格式(1x,300i10)         做ir = 1,nnr           写(15,50)(fpar0(ir,ic),ic = 1,nnc)           写(16,50)(lai0(ir,ic),ic = 1,nnc)         结束了

   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  

我在cygwin中运行了该脚本。我在照片中遇到了以下问题。请检查并提供帮助。 gfortran run and error

1 个答案:

答案 0 :(得分:1)

索引变量的值大于两个数组维度

integer, dimension (300,300):: fpar0, lai0

nnc = 328           ! For Red River Basin
nnr = 395

稍后您将在发生此分段错误的循环中使用它们

do ir = 1, nnr
   do ic=1, nnc
     fpar0(ir,ic) = modis1(ir,ic) 
      lai0(ir,ic) = modis2(ir,ic)              

     end do
end do