Fortran Coder

查看: 7365|回复: 3

[绘图界面库] 有没有使用grads的大佬帮忙看一下

[复制链接]

57

帖子

15

主题

0

精华

熟手

F 币
242 元
贡献
166 点
发表于 2020-4-2 10:40:22 | 显示全部楼层 |阅读模式
本帖最后由 kyra 于 2020-4-5 11:08 编辑

我的数据输出总是有问题,不知道该怎么正确的将数据输出到二进制文件中,我把自己的代码和grads错误贴出来,大佬们帮忙看一下。
[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

目的是将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

1

帖子

0

主题

0

精华

新人

F 币
21 元
贡献
3 点
发表于 2020-8-19 21:00:04 | 显示全部楼层
你好,我的grads也出现了同类报错,这报错原因是指我的数据输出 有问题吗?楼主最后是怎么解决的呢?谢谢

213

帖子

2

主题

0

精华

宗师

F 币
2126 元
贡献
875 点

规矩勋章

发表于 2020-8-20 08:30:08 | 显示全部楼层
看上去错误出现在module station_operation1.在你的程序中没有对station_operation1.grd的读语句。

130

帖子

10

主题

0

精华

大师

F 币
617 元
贡献
372 点

贡献勋章管理勋章帅哥勋章元老勋章星光勋章规矩勋章

发表于 2020-8-20 12:58:21 | 显示全部楼层
1. "recl=18627*9*4" 是不對的
2. 應該是 "recl=18627*4", for "write(12,rec=irec) (h(n,m),n=1,18627)",  "real :: h(18627,9)", default REAL is4-byte
3. 這樣仍是"compiler dependent"
4. 請參考如下"compiler independent"的寫法
[Fortran] 纯文本查看 复制代码
PROGRAM test                                                                                       
  IMPLICIT NONE                                                                                    
                                                                                                   
  REAL:: h(18627,9)                                                                                
                                                                                                   
  INTEGER :: m, n, RecLength                                                                       
                                                                                                   
  !-------                                                                                         
                                                                                                   
  m = 1                                                                                            
                                                                                                   
  ! Inquire the I/O Length of Unformatted Record in the Direct Access File                         
  INQUIRE( IOLENGTH=RecLength ) (h(n,m),n=1,18627)                                                 
  WRITE(*,*) RecLength ! 18672 for Intel/Compaq, 74508 for Absoft/Lahey/PGI/NAG/GNU/G95            
                                                                                                   
  !---> Value of "RecLength" is compiler dependent                                                 
                                                                                                   
 !OPEN(UNIT=..., FILE=..., FORM='UNFORMATTED' ACCESS='DIRECT', RECL=RecLength)                     
                                                                                                   
END PROGRAM test                                                                                   
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-3-28 17:08

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表