プログラム: sonde_vpt.f90
program sonde_vpt! Description:!! Host: aofd165.fish.nagasaki-u.ac.jp! Directory: /work2/kunoki/to_manda_sensei/Tools!! Revision history:! This file is created by /usr/local/mybin/nff.sh at 14:41 on 10-13-2014. character(len=1000)::strm character(len=500)::infle,ofle real,allocatable,dimension(:)::z,t,p,rh real,allocatable,dimension(:)::vpt, dvptdz real,parameter::rmiss=-999.9 namelist /para/infle,ofle read(*,nml=para) open(11,file=infle,action="read") read(11,*) read(11,'(A)'),strm is=index(strm,"=")+1 read(strm(is:),*)nd print *,'nd=',nd allocate(z(nd),t(nd),p(nd),rh(nd),vpt(nd)) do i=1,nd read(11,*)z(i),t(i),p(i),rh(i) enddo !i close(11) vpt(:)=rmiss do i=1,nd tk=t(i)+273.15 call virtual_potential_temperature(vpt(i), tk, p, rh) enddo !i dvptdz(:)=rmiss do i=2,nd-1 dvptdz(i)=(vpt(i+1)-vpt(i-1))/(z(i+1)-z(i-1)) enddo !i open(21,file=ofle) write(21,'(A,A)')'# Input: ',trim(infle) write(21,'(A)')'# z[m], T[degC], p[hPa], RH[%], VPT[K], dVPTdz[K/m]' do i=1,nd write(21,'(f8.1,2f10.2,f7.1,f9.2)')&& z(i),t(i),p(i),RH(i),VPT(i),dvptdz(i) enddo !i write(*,'(A,A)')'Input : ',trim(infle) write(*,'(A,A)')'Output: ',trim(ofle)end program sonde_vptsubroutine virtual_potential_temperature(vpt, tk, p, rh)! implicit none real,intent(out)::vpt! pt: virtual potential temperature (kelvin) real,intent(in)::tk,p,rh! tk: absolute temperature (kelvin)! p : pressure (hPa)! rh: Relative Humidity (%) real,parameter:: kappa=287.0/1004.0! Rd=287 J K-1 kg-1! Cp=1004 J K-1 kg-1 real,parameter::p0=1000.0! p0: pressue (hPa) real pt !Potential Temp. real tc !air temp. in Celsius real es !saturated water vapor pressure real e !water vapor pressure real w !Mixing Ratio pt=tk*(p0/p)**kappa! saturated water vapor pressure by Tetens (1930)'s formulae tc=tk-273.15 es=611.0/100.*10**((7.5*tc)/(237.3+tc)) ![hPa] e=rh/100*es! water vapor mixing ratio in kg/kg w=0.622*e/(p-e) vpt=pt*(1.0 + 0.61*w)end subroutine virtual_potential_temperature実行用シェルスクリプト:sonde_vpt.run.sh
#!/bin/bash# Description:## Host: aofd165.fish.nagasaki-u.ac.jp# Directory: /work2/kunoki/to_manda_sensei/Tools/Sonde.Prof.Thermo## Revision history:# This file is created by /usr/local/mybin/nbscr.sh at 15:18 on 10-13-2014.echo "Shell script, $(basename $0) starts."echoexe=sonde_vptnamelist=$exe.namelist.txtindir=proc1odir=outputmkdir -vp $indirmkdir -vp $odiri=1n=19while [ $i -le $n ]; dono=$(printf %02d $i)cat <<EOF >$namelist¶infle="${indir}/stn${no}.raw.T.P.RH.txt"ofle="${odir}/stn${no}.vpt.txt"&endEOF${exe} < $namelisti=$(expr $i + 1)done #iecho "Done $0"echoコンパイル時に、-tracebackオプションをつける(ifortの場合)
$ sonde_vpt.run.sh
forrtl: 致命的なエラー (174): SIGSEGV、segmentation fault occurred
Image PC Routine Line Source
sonde_vpt 0000000000403B2C MAIN__ 48 sonde_vpt.f90
sonde_vpt 0000000000402E7C Unknown Unknown Unknown
libc.so.6 0000003E8241D9F4 Unknown Unknown Unknown
sonde_vpt 0000000000402D89 Unknown Unknown Unknown
alloc_test: エラーとなる例
alloc_test2: 正常に動作する例
program alloc_test! Description:!! Author: aym!! Host: aofd30! Directory: /work1/aym/11.Work10/15.HeatBudjet/51.jcope2/32.NCEP_FLUX/11.test_read_flux/src!! Revision history:! 2011-02-24 16:13! Initial Version! use! implicit none real,allocatable :: var(:,:) write(*,'(a)')'Program alloc_test starts.'! write(*,*)'' call sub(var) write(*,'(a)')'Done program alloc_test.' write(*,*)end program alloc_testsubroutine sub(var) real,allocatable :: var(:,:) allocate(var(2,2))end subroutine sub$ ifort -CB -traceback -o alloc_test alloc_test.f90
$ alloc_test
Program alloc_test starts.
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
alloc_test 0000000000402B75 MAIN__ 20 alloc_test.f90
alloc_test 0000000000402ACC Unknown Unknown Unknown
libc.so.6 0000003F6241D994 Unknown Unknown Unknown
alloc_test 00000000004029D9 Unknown Unknown Unknown
program alloc_test2! Description:!! Author: aym!! Host: aofd30! Directory: /work1/aym/11.Work10/15.HeatBudjet/51.jcope2/32.NCEP_FLUX/11.test_read_flux/src!! Revision history:! 2011-02-24 16:13! Initial Version! use! implicit none real,allocatable :: var(:,:) write(*,'(a)')'Program alloc_test starts.'! write(*,*)'' allocate(var(2,2)) call sub(var) write(*,'(a)')'Done program alloc_test.' write(*,*)end program alloc_test2subroutine sub(var) real var(:,:)end subroutine sub$ ifort -CB -traceback -o alloc_test2 alloc_test2.f90
$ alloc_test2
Program alloc_test starts.
Done program alloc_test.