[Fortran] 纯文本查看 复制代码
Program main
use timer_supports
implicit none
Integer,parameter :: length=1000
integer i , f , idays
integer d
Character(LEN=length) A,B,Filename
Integer(kind=4)::Column, Row, K,L
integer , 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)!将数据转化为数组
call daysfromdate(1954,1,1,2007,12,31,0)
print *, idays
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