我的代码如下
program homework
implicit none
integer :: ios, read_unit = 99
integer :: n, i,J
character(len=200) :: line
character(len=200), allocatable :: timestamp(:), b(:,:)
open(unit=read_unit, file='data.dat', iostat=ios)
if (ios /= 0) then
stop "Error opening file data.dat"
endif
n = 0
do
read(read_unit, '(A)', iostat=ios) line
if (ios /= 0) exit
n = n + 1
end do
print*, "File contains ", n, " commands"
allocate(b(n,18))
allocate(timestamp(n))
rewind(read_unit)
do j=1,18
do i=1,n
read(read_unit, *) b(i,j)
timestamp(i)=b(i,1)
end do
end do
close(read_unit)
open(1, file='timestamp.dat', status='new')
do i=1,n
write(1,*) timestamp(i)
end do
close(1)
deallocate(timestamp)
deallocate(b)
end program homework
文件前五行如下:
"TIMESTAMP","RECORD","TRIME_VWC(1)","TRIME_VWC(2)","TRIME_VWC(3)","TRIME_VWC(4)","TRIME_VWC(5)","TRIME_VWC(6)","TRIME_VWC(7)","TRIME_VWC(8)","TRIME_Temp(1)","TRIME_Temp(2)","TRIME_Temp(3)","TRIME_Temp(4)","TRIME_Temp(5)","TRIME_Temp(6)","TRIME_Temp(7)","TRIME_Temp(8)"
"2021-08-01 04:19:15",1920380,0.048,0.042,0.044,0.031,0.002,0.02,0.001,-0.001,30.39,30.69,30.27,30.27,31.73,30.91,31.21,31.21
"2021-08-01 04:19:30",1920381,0.048,0.042,0.044,0.032,0.002,0.02,0.001,-0.001,30.39,30.61,30.39,30.27,31.73,30.95,31.06,31.14
"2021-08-01 04:19:45",1920382,0.048,0.042,0.044,0.032,0.002,0.019,0.001,-0.001,30.39,30.84,30.31,30.27,31.7,30.8,31.06,31.21
"2021-08-01 04:20:00",1920383,0.048,0.042,0.044,0.031,0.002,0.019,0.001,-0.001,30.38,30.68,30.31,30.27,31.73,30.83,31.21,31.13
"2021-08-01 04:20:15",1920384,0.048,0.042,0.044,0.032,0.002,0.02,0.001,-0.001,30.23,30.83,30.31,30.31,31.73,30.8,31.06,31.21
program homework
implicit none
integer :: ios, read_unit = 99
integer :: n, i,J
character(len=200) :: line
character(len=200), allocatable :: timestamp(:), b(:,:)
open(unit=read_unit, file='data.dat', iostat=ios)
if (ios /= 0) then
stop "Error opening file data.dat"
endif
n = 0
do
read(read_unit, '(A)', iostat=ios) line
if (ios /= 0) exit
n = n + 1
end do
print*, "File contains ", n, " commands"
allocate(b(n,18))
allocate(timestamp(n))
rewind(read_unit)
do j=1,18
do i=1,n
read(read_unit, *) b(i,j)
timestamp(i)=b(i,1)
end do
end do
close(read_unit)
open(1, file='timestamp.dat', status='new')
do i=1,n
write(1,*) timestamp(i)
end do
close(1)
deallocate(timestamp)
deallocate(b)
end program homework
文件前五行如下:
"TIMESTAMP","RECORD","TRIME_VWC(1)","TRIME_VWC(2)","TRIME_VWC(3)","TRIME_VWC(4)","TRIME_VWC(5)","TRIME_VWC(6)","TRIME_VWC(7)","TRIME_VWC(8)","TRIME_Temp(1)","TRIME_Temp(2)","TRIME_Temp(3)","TRIME_Temp(4)","TRIME_Temp(5)","TRIME_Temp(6)","TRIME_Temp(7)","TRIME_Temp(8)"
"2021-08-01 04:19:15",1920380,0.048,0.042,0.044,0.031,0.002,0.02,0.001,-0.001,30.39,30.69,30.27,30.27,31.73,30.91,31.21,31.21
"2021-08-01 04:19:30",1920381,0.048,0.042,0.044,0.032,0.002,0.02,0.001,-0.001,30.39,30.61,30.39,30.27,31.73,30.95,31.06,31.14
"2021-08-01 04:19:45",1920382,0.048,0.042,0.044,0.032,0.002,0.019,0.001,-0.001,30.39,30.84,30.31,30.27,31.7,30.8,31.06,31.21
"2021-08-01 04:20:00",1920383,0.048,0.042,0.044,0.031,0.002,0.019,0.001,-0.001,30.38,30.68,30.31,30.27,31.73,30.83,31.21,31.13
"2021-08-01 04:20:15",1920384,0.048,0.042,0.044,0.032,0.002,0.02,0.001,-0.001,30.23,30.83,30.31,30.31,31.73,30.8,31.06,31.21