[Fortran] 纯文本查看 复制代码
Program main
use timer_supports
use station_operation1
implicit none
Integer,parameter :: length=1000
real :: i14(14)
integer i , f , irec
integer d , m , n
real :: h(18627,9)
Character(LEN=length) A,B,Filename
Integer(kind=4)::Column, Row, K,L
real , allocatable :: c( : , : )
Column=0;Row=0;K=0;L=1;filename="ztzl-1.txt"
Open (55,file=Filename)
Read(55,'(a1000)') A
column=GetDataN(A)!//改成这个函数,具体实现在下面的代码
CLOSE(55)
Open (55,file=Filename)
Do
Read(55,*,iostat=k) B
If( k /= 0 ) Exit
Row = Row + 1
End Do
Write(*,"(A5,I6,5X,A7,I2)") "Row=",Row,"Column=",Column!读取行数
allocate(c(column-1,row))
rewind(55)
Do i = 1,Row
read(55,*) d,c(:,i)!//1改成 i
End Do
Close(55)!将数据转化为数组
allocate(tem_max(row))
allocate(tem_min(row))
allocate(tem_ave(row))
allocate(pres(row))
allocate(wind(row))
allocate(sun_time(row))
allocate(high(row))
allocate(hum(row))
allocate(prep(row))
allocate(ymd(row,3))
do f = 1 , row
ymd(f,1) = INT(c(4,f))
ymd(f,2) = INT(c(5,f))
ymd(f,3) = INT(c(6,f))
call indexit(ymd(f,1),ymd(f,2),ymd(f,3))
i14 = c(:,f)
e(f,1) = i14(1)
e(f,2) = i14(2)
if(i14(3) >= 100000 ) then
e(f,3) = (i14(3)-100000) * 0.1
else
e(f,3) = i14(3) * 0.1
end if
high(g) = e(f,3)
h(f,9) = e(f,3)
e(f,4) = i14(4)
e(f,5) = i14(5)
e(f,6) = i14(6)
e(f,7) = i14(7) * 0.1
h(f,1) = e(f,7)
pres(g) = e(f,7)
if(i14(8)<=400 .and. i14(8)>= -400) then
e(f,8) = i14(8) * 0.1
end if
tem_ave(g) = e(f,8)
h(f,2) = e(f,8)
if(i14(9)<=400 .and. i14(9)>= -400) then
e(f,9) = i14(9) * 0.1
end if
tem_max(g) = e(f,9)
h(f,3) = e(f,9)
if(i14(10)<=400 .and. i14(10)>= -400) then
e(f,10) = i14(10) * 0.1
end if
tem_min(g) = e(f,10)
h(f,4) = e(f,10)
e(f,11) = i14(11)
hum(g) = e(f,11)
h(f,5) = e(f,11)
if(i14(12)==32744 .or. i14(12)==32766 .or. i14(12)==32700) then
e(f,12) = undefined
else if (i14(12)>=32000) then
e(f,12) = (i14(12)-32000) * 0.1
else if (i14(12)>=31000) then
e(f,12) = (i14(12)-31000) * 0.1
else if (i14(12)>=30000) then
e(f,12) = (i14(12)-30000) * 0.1
else
e(f,12) = i14(12) * 0.1
end if
prep(g) = e(f,12)
h(f,6) = e(f,12)
e(f,13) = i14(13) * 0.1
wind(g) = e(f,13)
h(f,7) = e(f,13)
e(f,14) = i14(14) * 0.1
sun_time(g) = e(f,14)
h(f,8) = e(f,14)
end do
open(12,file='station_operation1.grd',access='direct',status='replace',form='unformatted',recl=18627*9*4)
irec = 1
do m=1,13
write(12,rec=irec) (h(n,m),n=1,18627)
irec = irec + 1
end do
close(12)
!//重点在这里!!!!!!
contains
Integer Function GetDataN( cStr )
Character( Len = * ) , Intent( IN ) :: cStr
Integer :: i
Logical :: bIsSeparator , bIsQuote
GetDataN = 0
bIsSeparator = .TRUE.
bIsQuote = .FALSE.
Do i = 1 , Len_Trim( cStr )
Select Case( cStr(i:i) )
Case( '"' , "'" ) !// 如果遇到引号
If ( .Not.bIsQuote ) GetDataN = GetDataN + 1 !//如果不在引号中,则增加一个数据
bIsQuote = .Not.bIsQuote !// 引号结束或开始
bIsSeparator = .FALSE.
Case( " " , "," , char(9) ) !// 如果遇到分隔符
If ( .Not.bIsQuote ) then !// 分隔符如果不在引号中
bIsSeparator = .TRUE.
End If
Case Default
If ( bIsSeparator ) then
GetDataN = GetDataN + 1
End If
bIsSeparator = .FALSE.
End Select
End Do
End Function GetDataN
End Program Main