program ZWD_gamit
implicit none
integer :: stat,stat2,stat3,stat4,yr,dayofyear,hr
character :: filename_ztd*12,filename_zhd*12,filename_zwd*12,first*1
real :: time_all_ztd,time_all_zhd,ztd_m,zhd_mm,ztd_mm,zwd_mm
open(11,file="list.txt")
close(11,status="delete")
open(22,file="list2.txt")
close(22,status="delete")
call system('for %f in (*_all.ztd) do echo %f >> list.txt')
call system('for %f in (*_all.zhd) do echo %f >> list2.txt')
open (11,file="list.txt")
open (22,file="list2.txt")
stat=0
stat2=0
do while (stat==0 .and. stat2==0)
read (11,"(a12)",iostat=stat) filename_ztd
read (22,"(a12)",iostat=stat2) filename_zhd
if (stat/=0 .and. stat2/=0) exit
open (33,file=filename_ztd)
open (44,file=filename_zhd)
filename_zwd=filename_ztd(1:8)//".zwd"
open (55,file=filename_zwd)
stat3=0
do while (stat3==0)
read (33,50,iostat=stat3) time_all_ztd,ztd_m,yr,dayofyear,hr
50 format (f12.7,4x,f6.1,3x,i4,3x,i3.3,3x,i2.2)
if (stat3/=0) exit
stat4=0
do while (stat4==0)
read (44,100,iostat=stat4) time_all_zhd,zhd_mm
100 format (f12.7,4x,f6.1)
if (stat4/=0) exit
if (time_all_ztd==time_all_zhd) then
read (zhd_mm(1:1),"(a1)") first
if( first/="*") then
ztd_mm = ztd_m*1000D0
zwd_mm = ztd_mm - zhd_mm
write (55,150) time_all_ztd,zwd_mm,yr,dayofyear,hr
150 format (f12.7,3x,f12.7,3x,i4,3x,i3.3,3x,i2.2)
end if
end if
end do
rewind(44)
end do
close(33)
close(44)
close(55)
end do
close(11)
close(22)
end program
851 Bytes, 下载次数: 1
測試文件
楚香饭 发表于 2014-10-16 12:17
如果没有数值,是 **** 的话,那么 stat4 就不会是 0,就会 exit 了。
character( len = 30 ) c_zhd_mm !// c_zhd_mm 定义为字符型
do while (stat4==0)
read (44,*,iostat=stat4) time_all_zhd,c_zhd_mm !// 通常 * 就足够 read 了
if (stat4/=0) exit
if (time_all_ztd==time_all_zhd) then
!read (zhd_mm(1:1),"(a1)") first !//这句去掉
if( c_zhd_mm(1:1) /= "*") then
read( c_zhd_mm , * ) zhd_mm !// 如果有数值,再从 c_zhd_mm 中读取 zhd_mm
ztd_mm = ztd_m*1000D0
zwd_mm = ztd_mm - zhd_mm
楚香饭 发表于 2014-10-16 17:56
[mw_shl_code=fortran,true]character( len = 30 ) c_zhd_mm !// c_zhd_mm 定义为字符型
do while (stat4== ...
楚香饭 发表于 2014-10-17 08:12
从 real 转换成 character 用 write 既可
write( character , * ) real
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |