爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8944|回复: 5

ncl处理站点数据条件语句出错

[复制链接]
发表于 2017-4-25 10:50:54 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
    各位大神,在用ncl处理站点数据时写了条件语句,但是出了错,请教原因。
脚本如下:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"


fname = ".../out.txt"
  data  = asciiread(fname,-1,"string")
  ;print(data)

; Count the number of fields, just to show it can be done.
  nfields = str_fields_count(data(1)," ")
  print("number of fields = " + nfields)
  print("step1")

;
; Skip first row of "data" because it's just a header line.
;
; Use a space (" ") as a delimiter in str_get_field. The first
; field is field=1 (unlike str_get_cols, in which the first column
; is column=0).
;


    mas= str_get_field(data(2::), 14," ")
    fst= str_get_field(data(2::), 9," ")
    print("step2")


  if(mas.eq."FULL" .and. fst.eq."TMP" ) then
  lat = stringtofloat(str_get_field(data(1::), 25," "))
  lon = stringtofloat(str_get_field(data(1::), 26," "))
  tfct = stringtofloat(str_get_field(data(1::), 29," "))
  tobs = stringtofloat(str_get_field(data(1::), 30," "))
  tb=tfct-tobs
  alist = [/lat, lon, tb/]

  write_table("out1.txt", "w", alist, "%16.2f %16.2f %16.2f")

end if


错误信息如下:
Copyright (C) 1995-2014 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 6.2.1
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
(0)        number of fields = 31
(0)        step1
(0)        step2
fatal:Conditional statements (if and do while) require SCALAR logical values, see all and any functions


fatal:["Execute.c":8578]:Execute: Error occurred at or near line 48 in file minus.ncl

密码修改失败请联系微信:mofangbao
发表于 2020-4-17 22:40:40 | 显示全部楼层
if(any(mas.eq."FULL" .and. fst.eq."TMP" ) )then
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

发表于 2017-4-25 11:00:05 | 显示全部楼层
  lat = stringtofloat(str_get_field(data(1::), 25," "))
你这样不就又相当于读了头文件吗?
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2017-4-25 11:09:25 | 显示全部楼层
yeah... 发表于 2017-4-25 11:00
lat = stringtofloat(str_get_field(data(1::), 25," "))
你这样不就又相当于读了头文件吗?

那该怎么写呢
密码修改失败请联系微信:mofangbao
发表于 2017-4-25 11:27:08 | 显示全部楼层

你的头文件是几行啊?我感觉你对头文件的处理就有些奇怪啊 行应该是从0开始计数的呀
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2017-4-25 15:01:09 | 显示全部楼层
yeah... 发表于 2017-4-25 11:27
你的头文件是几行啊?我感觉你对头文件的处理就有些奇怪啊 行应该是从0开始计数的呀

头有标题的
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

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