[Fortran] 纯文本查看 复制代码
Program main
use timer_supports
use shuzu
implicit none
Integer,parameter :: length=1000
character(len=10)::g(18627,14)
integer i , f , idays , m , n , o , p , q , r , s , t
integer d
Character(LEN=length) A,B,Filename
Integer(kind=4)::Column, Row, K,L
real , allocatable :: c( : , : )
idays = 0
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)!将数据转化为数组
do n = 7,10
do m = 1,18627
c(n,m) = c(n,m) * 0.1
end do
end do
p = 12
do o = 1,18627
if(c(p,o)>=32000) then
c(p,o) = (c(p,o)-32000) * 0.1
else if (c(p,o)>=31000) then
c(p,o) = (c(p,o)-31000) * 0.1
else if (c(p,o)>=30000) then
c(p,o) = (c(p,o)-30000) * 0.1
else
c(p,o) = c(p,o) * 0.1
end if
write(*,"(F10.5)") c(p,o)
end do
do q = 13 ,14
do r = 1 , 18627
c(q,r) = c(q,r) * 0.1
end do
end do
write(g,'(A)') c
do s = 1,14
do t = 1,18627
if(g(s,t) == '74.40000' .or. g(s,t) == '76.60000' .or. g(s,t) == '70.00000') then
cycle
end if
e(s,t) = g(s,t)
end do
end do
call daysfromdate(1957,1,1,2007,12,31,idays)
print *, idays
call indexit(1)
print *, e
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