- 积分
- 94
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2020-4-1
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 hpa666 于 2020-4-3 13:57 编辑
我的数据输出总是有问题,不知道该怎么正确的将数据输出到二进制文件中,我把自己的代码和grads错误贴出来,大佬们帮忙看一下。
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
目的是将9个变量输出为grd文件并用grads进行绘图,如下,是grads的错误
ga-> C:\opengrads\use\station_operation1.gs
Low Level I/O Error: Read error on data file
Data file name = D:/bysj/important/data/result/station_operation1.grd
Error reading 4 bytes at location -1637783320
Data Request Error: Error for variable 'ps'
Error ocurred at column 1
DISPLAY error: Invalid expression
Expression = ps
GXPRINT error: unsupported output format
这是ctl文件
DSET D:/bysj/important/data/result/station_operation1.grd
TITLE sation_operation1
UNDEF -9.9e30
XDEF 144 linear 73 0.223
YDEF 72 linear 26 0.194
ZDEF 1 levels 600
TDEF 18627 linear 00Z01JAN1957 1dy
VARS 9
sp 0 99 Surface_Pressure
Ta 0 99 averange_temperature
Tx 0 99 maximum_temperature
Tn 0 99 minimum_temperature
h 0 99 humidity
pr 0 99 prep
w 0 0 wind
ti 0 99 sun_time
z 1 99 height
ENDVARS
|
|