open (unit=7, file='psea.txt', position='append', form='FORMATTED')
position='append'を書けばOK
ふつうは、status='UNKNOWN'
でよいはずなのだが・・・・
それか、linux系だから
a.out>>output
として、outputに書かせる方法もあり!
#! /bin/tcsh -f
##make pmin.txt
#type yyyymmddhhhh start and end time
: ${start:=199201020000}
: ${end:=199201050000}
year=`echo ${start} | cut -c 1-4`
month=`echo ${start} | cut -c 5-6`
day=`echo ${start} | cut -c 7-8`
hour=`echo ${start} |cut -c 9-10`
h=00
echo start time ${year} ${month} ${day} ${hour} ${h}
echo end time ${end}
: ${time:=${start}}
#timestep
timestep=12
time_step=0
i=0
while [ ${time} -le ${end} ]
do
time_step=`expr ${timestep} \* ${i}`
echo time_step ${time_step}
##decide m
if [ ${month} -eq 01 ]; then
m=JAN
elif [ ${month} -eq 02 ]; then
m=FEB
elif [ ${month} -eq 03 ]; then
m=MAR
elif [ ${month} -eq 04 ]; then
m=APR
elif [ ${month} -eq 05 ]; then
m=MAY
elif [ ${month} -eq 06 ]; then
m=JUN
elif [ ${month} -eq 07 ]; then
m=JUL
elif [ ${month} -eq 08 ]; then
m=AUG
elif [ ${month} -eq 09 ]; then
m=SEP
elif [ ${month} -eq 10 ]; then
m=OCT
elif [ ${month} -eq 11 ]; then
m=NOV
elif [ ${month} -eq 12 ]; then
m=DEC
fi
##decide m
#echo $hour
time=${year}${month}${day}${hour}${h}
#echo yoshiyoshi
echo time $time
echo month $m
t=`expr ${day} \* 4 - 3`
t=`expr ${hour} / 6 + ${t}`
: ${prefix:=anl_p} #want data
cat > data.gs <<EOF
'reinit'
'open _NHMMRPPFCSVSTD1_${time}.ctl'
'set gxout fwrite'
'set undef dfile'
'set fwrite p1.grd'
*'set t ${t}'
'set x 1 400'
'set y 1 300'
'd psea'
'disable fwrite'
'c'
*'set gxout fwrite'
*'set undef dfile'
*'set fwrite u1.grd'
**'set t ${t}'
*'set x 1 288'
*'set y 1 145'
*'d ugrdsfc'
*'disable fwrite'
*'c'
*'set gxout fwrite'
*'set undef dfile'
*'set fwrite v1.grd'
*'set t ${t}'
**'set x 1 288'
*'set y 1 145'
*'d vgrdsfc'
*'disable fwrite'
*'c'
*'set gxout fwrite'
*'set undef dfile'
*'set fwrite rv.grd'
*'set t ${t}'
*'set x 1 288'
*'set y 1 145'
*'a=hcurl(ugrdprs,vgrdprs)'
*'d a'
*'disable fwrite'
*'c'
'quit'
#157
EOF
grads -blc data.gs
####program read_data###################
if [ ${time} -eq ${start} ]; then
##start file content
cat <<EOF > start.f90
program start
implicit none
open (unit=7, file='psea.txt', form='FORMATTED')
write(7,*) 'time_step mini_psea xgrid ygrid lon lat'
write(*,*) 'time_step mini_psea xgrid ygrid lon lat'
close(7)
end program start
EOF
##output data.txt by f90
f90 -o start.out start.f90
./start.out
##start
fi
####find min psea
cat <<EOF > f_find_pmin.f90
program find_pmin
implicit none
integer, parameter :: xgrid=400, ygrid=300
integer :: n, i, j, kx, ky
real(kind=4), dimension(xgrid,ygrid) :: p_d
real(kind=4) :: p, lon, lat
open (unit=17,file='p1.grd',form='unformatted',access='direct',recl=xgrid*ygrid*4)
read (unit=17,rec=1) p_d
open (unit=7, file='psea.txt', position='append', form='FORMATTED')
p=2000
do i = 1, xgrid
do j = 1, ygrid
if (p_d(i,j) < p) then
kx=i
ky=j
p=p_d(i,j)
write(*,*) n, ${time_step}, i, j, p
! write(7,*) n, ${time_step}, i, j, p
endif
n=n+1
enddo
enddo
lon=kx*20*0.18+130
lat=ky*20*0.18-30
write(*,*) ${time_step}, p, kx, ky, lon, lat
write(7,*) ${time_step}, p, kx, ky, lon, lat
close(7)
close(17)
end program find_pmin
EOF
##output data.txt by f90
f90 -o output.out f_find_pmin.f90
./output.out
#echo ${day}
#echo "yoshiyoshi"
i=`expr $i + 1`
#echo $i
#hour=`expr $hour + 1`
hour=`expr $hour + $timestep`
hour=`echo ${hour} | awk '{printf("%02d",$1)}'`
if [ $hour -eq 24 ]; then
hour=00
# day=`expr $day + 1`
day=`echo ${day} | awk '{printf("%02d",$1+1)}'`
if [ $day -ge 32 ];then
day=01
# month=`expr $month + 1`
month=`echo ${month} | awk '{printf("%02d",$1+1)}'`
if [ $month -ge 13 ];then
month=01
year=`expr $year + 1`
fi
fi
fi
time=${year}${month}${day}${hour}${h}
done
0 件のコメント:
コメントを投稿