|
代码如下:
[Fortran] 纯文本查看 复制代码 program getdata
implicit none
integer::I,J,K,N,M
character(len=20)::fname
character(len=100)::path
real::hmax
real,dimension(30)::hh
real,dimension(30,730)::h,tub,tt
real,dimension(30)::ht,tubt,ttt
open(11,file="name.txt",status="old")
open(13,file="WT.csv")
open(14,file="TURB.csv")
hmax=0.0
do I=0,28
hh(I+1)=120.0+i*0.5
enddo
write(13,*)"天数","時間"
write(13,"(I5,',',I5,',',29(f5.1,','))")1,9,(hh(I),I=1,29)
write(14,*)"天数","時間"
write(14,"(I5,',',I5,',',29(f5.1,','))")2,9,(hh(I),I=1,29)
I=0
h=-999.0
tub=-999.0
tt=-999.0
ht=-999.0
tubt=-999.0
ttt=-999.0
do
read(11,*,end=30)fname
write(*,*)fname
path='mkinput\'//trim(fname)
write(*,*)trim(path)
! open(99,file=trim(fname) )
pause
open(12,file=trim(fname),status='old')
read(12,*)
I=I+1
J=0
do
J=J+1
read(12,*,end=20)ht(J),tubt(J),ttt(J)
if (hmax<ht(J)) hmax=ht(J)
if(J==1) then
if(ht(J)-float(floor(ht(J)))>0.25 .and.ht(J)-float(floor(ht(J)))<0.75) then
ht(J)=float(floor(ht(J)))+0.5
elseif(ht(J)-float(floor(ht(J)))>=0.75) then
ht(J)=float(floor(ht(J)))+1.0
else
ht(J)=-999.0
tubt(J)=-999.0
ttt(J)=-999.0
endif
endif
20 close(12)
enddo
lp1: do K=1,29
do N=1,29
if((hh(K)-ht(N))<0.001) then
h(K,I)=ht(N)
tub(K,I)=tubt(N)
tt(K,I)=ttt(N)
cycle lp1
endif
enddo
enddo lp1
write(13,*)fname(1:4),fname(5:6),fname(7:8),fname(9:10),(tt(N,I),N=1,29)
write(14,*)fname(1:4),fname(5:6),fname(7:8),fname(9:10),(tub(N,I),N=1,29)
enddo
30 write(*,*)"normal end"
end
在该文件夹下有个name.txt,内容如下
201401010910.csv
201401011610.csv
201401020910.csv
201401021610.csv
201401030910.csv
。。。
然后有对应的 201401010910.csv 等csv格式的文件
201401010910.csv 的内容如下
水面海抜値(EL.m): 127.93
127.43, 60.0, 8.7
127.00, 65.8, 8.7
126.50, 66.7, 8.7
126.00, 66.2, 8.7
125.50, 64.3, 8.7
125.00, 66.6, 8.7
124.50, 64.0, 8.7
124.00, 64.4, 8.7
123.50, 62.3, 8.7
123.00, 65.1, 8.7
122.50, 66.2, 8.7
122.00, 67.6, 8.7
121.50, 63.0, 8.7
121.00, 66.2, 8.7
120.50, 65.2, 8.7
120.00, 66.0, 8.7
我已经无语了,用
open(12,file="201401010910.csv",status="old") 可以打开
但是用 open(12,file=trim(fname),status='old') 怎么都打不开
经过测试,fname可以正确读入和输出
运行结果如下:
日文版的,错误提示是:没有找到文件,unit 12, 然后是file的路径
|
|