- 积分
- 1642
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-3-4
- 最后登录
- 1970-1-1
|
Fortran
系统平台: |
win10,64位,16G内存,AMD cpu |
问题概况: |
求助,forrtl: severe (174): SIGSEGV, segmentation fault occurred |
问题截图: |
- |
我看过提问的智慧: |
看过 |
自己思考时长(天): |
4 |
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
搞了好几天,在论坛和百度搜了很多,代码改了又改,还是没进展,只好来求助一下;代码写的比较笨,就是想读取一下利用grads的set fwrite提取ERA5的uvwnd的二进制文件,然后计算一下夏季风指数的时间序列;本来不用这么长的,为了防止数组太大,我声明了很多变量,这段代码在该之前我处理了ncep和jra55都没问题,但是era5就不行了,我猜是数组太大了,但是我没有好的办法,肯定是我哪里认知错误,希望可以援助一下,有什么建议都可以提出来
program samsi
implicit none
integer,parameter ::nx=241,ny=81,nz=27,nt=492
real,allocatable,dimension(:,:,:,:) ::uwnd1,uwnd2,uwnd3,uwnd4,uwnd5
real,allocatable,dimension(:,:,:,:) ::vwnd1,vwnd2,vwnd3,vwnd4,vwnd5
integer ::ix,iy,iz,it,irec
integer ::err_message
real ::mean,temp
real,dimension(nx,ny,nt) ::um1,um2,um3,um4,um5
real,dimension(nx,ny,nt) ::vm1,vm2,vm3,vm4,vm5
real,allocatable,dimension(:,:,:,:) ::us1,us2,us3,us4,us5
real,allocatable,dimension(:,:,:,:) ::vs1,vs2,vs3,vs4,vs5
real,allocatable,dimension(:,:,:,:) ::ks_sum1,ks_sum2,ks_sum3,ks_sum4,ks_sum5
real,allocatable,dimension(:,:,:,:) ::ks_summer
real,dimension(nx,ny,41) ::ks_zmean
real,dimension(nx,41) ::ks_ymean
real,dimension(41) ::ks_xmean,ks_t,ks_z
allocate(uwnd1(nx,ny,nz,96))
allocate(uwnd2(nx,ny,nz,96))
allocate(uwnd3(nx,ny,nz,96))
allocate(uwnd4(nx,ny,nz,96))
allocate(uwnd5(nx,ny,nz,108))
allocate(vwnd1(nx,ny,nz,96))
allocate(vwnd2(nx,ny,nz,96))
allocate(vwnd3(nx,ny,nz,96))
allocate(vwnd4(nx,ny,nz,96))
allocate(vwnd5(nx,ny,nz,108))
!if(err_message.NE.0) print*,'allocation error'
!!读取uwnd.dat文件
open(11,file='era5_u.dat', &
form='unformatted',&
status='old',&
access='direct',&
recl=nx*ny*1)
irec=0
do it=1,96
do iz=1,nz
irec=irec+1
read(11,rec=irec) ((uwnd1(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(11,rec=irec) ((uwnd2(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(11,rec=irec) ((uwnd3(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(11,rec=irec) ((uwnd4(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,108
do iz=1,nz
irec=irec+1
read(11,rec=irec) ((uwnd5(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
close(11)
!!读取vwnd.dat文件
open(12,file='era5_v.dat', &
form='unformatted',&
status='old',&
access='direct',&
recl=nx*ny*1)
irec=0
do it=1,96
do iz=1,nz
irec=irec+1
read(12,rec=irec) ((vwnd1(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(12,rec=irec) ((vwnd2(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(12,rec=irec) ((vwnd3(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,96
do iz=1,nz
irec=irec+1
read(12,rec=irec) ((vwnd4(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
do it=1,108
do iz=1,nz
irec=irec+1
read(12,rec=irec) ((vwnd5(ix,iy,iz,it),ix=1,nx),iy=1,ny)
end do
end do
close(12)
!!计算层数平均um和vm
um1 = sum(uwnd1,3)/nz
um2 = sum(uwnd2,3)/nz
um3 = sum(uwnd3,3)/nz
um4 = sum(uwnd3,3)/nz
um5 = sum(uwnd3,3)/nz
vm1 = sum(vwnd1,3)/nz
vm2 = sum(vwnd2,3)/nz
vm3 = sum(vwnd3,3)/nz
vm4 = sum(vwnd3,3)/nz
vm5 = sum(vwnd3,3)/nz
!!将原数据减去平均值得到us和vs
do iz=1,nz
us1(:,:,iz,:) = uwnd1(:,:,iz,:) - um1(:,:,:)
us2(:,:,iz,:) = uwnd2(:,:,iz,:) - um2(:,:,:)
us3(:,:,iz,:) = uwnd3(:,:,iz,:) - um3(:,:,:)
us4(:,:,iz,:) = uwnd4(:,:,iz,:) - um4(:,:,:)
us5(:,:,iz,:) = uwnd5(:,:,iz,:) - um5(:,:,:)
vs1(:,:,iz,:) = vwnd1(:,:,iz,:) - vm1(:,:,:)
vs2(:,:,iz,:) = vwnd2(:,:,iz,:) - vm2(:,:,:)
vs3(:,:,iz,:) = vwnd3(:,:,iz,:) - vm3(:,:,:)
vs4(:,:,iz,:) = vwnd4(:,:,iz,:) - vm4(:,:,:)
vs5(:,:,iz,:) = vwnd5(:,:,iz,:) - vm5(:,:,:)
end do
!!释放内存
deallocate(uwnd1,uwnd2,uwnd3,uwnd4,uwnd5)
deallocate(vwnd1,vwnd2,vwnd3,vwnd4,vwnd5)
!if(err_message.NE.0) print*,'allocation error'
!!分配内存
allocate(ks_summer(nx,ny,nz,41))
!!计算ks并提取出夏季的Ks
ks_sum1 = us1**2 + vs1**2
ks_sum2 = us2**2 + vs2**2
ks_sum3 = us3**2 + vs3**2
ks_sum4 = us4**2 + vs4**2
ks_sum5 = us5**2 + vs5**2
do it=7,96,12
ks_summer(:,:,:,0+((it-7)/12+1))=(ks_sum1(:,:,:,it+1)&
+ks_sum1(:,:,:,it)+ks_sum1(:,:,:,it-1))/3
end do
do it=7,96,12
ks_summer(:,:,:,8+((it-7)/12+1))=(ks_sum2(:,:,:,it+1)&
+ks_sum2(:,:,:,it)+ks_sum2(:,:,:,it-1))/3
end do
do it=7,96,12
ks_summer(:,:,:,16+((it-7)/12+1))=(ks_sum3(:,:,:,it+1)&
+ks_sum3(:,:,:,it)+ks_sum3(:,:,:,it-1))/3
end do
do it=7,96,12
ks_summer(:,:,:,24+((it-7)/12+1))=(ks_sum4(:,:,:,it+1)&
+ks_sum4(:,:,:,it)+ks_sum4(:,:,:,it-1))/3
end do
do it=7,108,12
ks_summer(:,:,:,32+((it-7)/12+1))=(ks_sum5(:,:,:,it+1)&
+ks_sum5(:,:,:,it)+ks_sum5(:,:,:,it-1))/3
end do
ks_zmean = sum(ks_summer,3)
ks_ymean = sum(ks_zmean,2)
ks_xmean = sum(ks_ymean,1)
ks_t = ks_xmean
!!释放内存
deallocate(ks_summer)
!!将得到的时间序列标准化
mean = sum(ks_t)/41
temp = 0
do it=1,41
temp = temp + (ks_t(it)-mean)**2
end do
temp = sqrt(temp)
do it=1,41
ks_z(it) = (ks_t(it)-mean)/temp
end do
!!写入txt
open(13,file='samsi_3.txt')
do it=1,41
write(13,*) it+1978,ks_z(it)
end do
close(13)
end program
gs:文件
'reinit'
'sdfopen D:\haoqin\datasets\era5\uvwnd\adaptor.mars.internal-1585704602.5630257-10874-7-9246115c-e399-45fd-aefa-80cef03dccae.nc'
'set gxout fwrite'
'set fwrite D:\haoqin\datasets\era5\uvwnd\era5_u.dat'
tt = 1
while(tt <= 492)
'set t ' tt
zz=1
while(zz<=27)
'set x 161 401'
'set y 361 441'
'set z ' zz
'd u'
zz = zz + 1
endwhile
tt = tt + 1
endwhile
'disable fwrite'
'c'
'reinit'
'sdfopen D:\haoqin\datasets\era5\uvwnd\adaptor.mars.internal-1585853797.28691-3397-3-66219613-4fd1-435a-a1d9-b6b3f0ffe612.nc'
'set gxout fwrite'
'set fwrite D:\haoqin\datasets\era5\uvwnd\era5_v.dat'
tt = 1
while(tt <= 492)
'set t ' tt
zz=1
while(zz<=27)
'set x 161 401'
'set y 361 441'
'set z ' zz
'd v'
zz = zz + 1
endwhile
tt = tt + 1
endwhile
'disable fwrite'
;
|
-
ifort编译器显示的错误
-
simply fortran显示的错误
|