爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: 黄小仙儿

把NCL算出来的值写入txt文件

[复制链接]

新浪微博达人勋

发表于 2014-4-23 18:56:38 | 显示全部楼层
黄小仙儿 发表于 2014-4-23 15:07
因为太菜了,什么都做不好啊~

同时弄这么多已经很不错了。就不要总说自己菜了。
话说楼主42个主题,40个是在提问求助,剩下2个分享也不是原创。
这么多的问题大家都帮你解决了,有空记得总结总结给大家分享一下。
原创可是有很多加分的。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-4-23 19:19:47 | 显示全部楼层
lqouc 发表于 2014-4-23 18:56
同时弄这么多已经很不错了。就不要总说自己菜了。
话说楼主42个主题,40个是在提问求助,剩下2个分享也 ...

恩,好的。等有时间总结一下回馈家园~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-4-23 19:22:38 | 显示全部楼层
longlivehj 发表于 2014-4-23 18:38
不客气。
想跟你说,其实可以用wrf_user_getvar一次性把数据全部取出,然后用dim_max_n直接生成最大值系 ...

刚去查了下,是不是这样xMaxTime = dim_max_n( x, 0 )
就可以得到最大值及其时间序列了?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-23 19:25:31 | 显示全部楼层
黄小仙儿 发表于 2014-4-23 19:22
刚去查了下,是不是这样xMaxTime = dim_max_n( x, 0 )
就可以得到最大值及其时间序列了?

,是的是的!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-4-26 15:09:39 | 显示全部楼层

longlive大神,我自己编了个画闪电的程序,能帮我看看不。感觉我对字符的理解有误~~
这是我的程序的思路,把闪电发生的经度,维度,强度弄成三列放到txt文件里,一共2163行。然后一行一行读取,用gsn_add_text在地图上特定的位置画“+”“-”,强度是正就画正号,负的就画符号。

提示一下:下面程序中中间部分读取冰粒子重要目的是获取模式的经纬度范围,为了更好的对比。这些时间和层数其实没有冰粒子的,画不出来的,就是为了获取底图
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/wrf/WRFUserARW.ncl"

begin
;
; The WRF ARW input file.  
; This needs to have a ".nc" appended, so just do it.
; We generate plots, but what kind do we prefer?
  type = "pdf"
; type = "pdf"
; type = "ps"
; type = "ncgm"
  wks = gsn_open_wks(type,"lightning")
  gsn_define_colormap(wks,"precip_11lev")

a = addfile("/home/Huanglei/data/d032"+".nc","r")      

  res = True
  res@MainTitle = "REAL-TIME WRF"
; res@gsnDraw      =  False                  
  ;res@gsnFrame     =  False

  mpres  = True  ; Map resources
  mpres@mpOutlineOn = False  ; Turn off map outlines
  mpres@mpFillOn    = False  ; Turn off map fill
  mpres@mpGridAndLimbOn = True
  pltres = True ; Plot resources
  pltres@PanelPlot  = True   ; Tells wrf_map_overlays not to remove overlays

times = wrf_user_getvar(a,"times",-1)  ; get all times in the file
  ntimes = dimsizes(times)         ; number of times in the file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  it =1       ; TIME LOOP

    print("Working on time: " + times(it) )
    res@TimeLabel = times(it)   ; Set Valid time to use on plots
    print(it)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; First get the variables we will need        
    if(isfilevar(a,"QICE"))
      qi = wrf_user_getvar(a,"QICE",it)
      qi = qi*1000.
      qi@units = "g/kg"   
    end if

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    level = 1      ; LOOP OVER LEVELS

      opts = res
      opts@cnFillOn         = True
      opts@gsnSpreadColors  = False
      opts@ContourParameters       = (/ 0.02, 0.5, 0.05 /)
          opts@gsnDraw      =  False                  
      opts@gsnFrame     =  False


      if (isvar("qi"))
        qis  = qi(level,:,:)
        contour = wrf_contour(a,wks,qis,opts)
        plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres)

        delete(contour)
      end if
;>============================================================<
;                      add China map
;>------------------------------------------------------------<

     
  shp_name1    = "/home/Huanglei/map/China/diquJie_polyline.shp"

  lnres                  = True
  lnres@gsLineColor      = "gray25"
  lnres@gsLineThicknessF = 0.5   

id = gsn_add_shapefile_polylines(wks,plot,shp_name1,lnres)
  shp_name2    = "/home/Huanglei/map/China/cnmap/cnhimap.shp"

  prres=True
  prres@gsLineThicknessF = 2.0      
  prres@gsLineColor = "black"
  plotcn3 = gsn_add_shapefile_polylines(wks,plot,shp_name2,prres)

      
  ascii_filename = "/home/Huanglei/data/7241600_20.txt"
  seismic = asciiread(ascii_filename,(/2163,3/),"float")   
  
    x = seismic(:,0)  ; Column 1 of file contains X values.
    y = seismic(:,1)  ; Column 2 of file contains Y values.
    z = seismic(:,2)  ; Column 3 of file contains Z values.
do lt=0, 2162
  
   lon=x(lt)
   lat=y(lt)

   if z(lt)>0
    str="+"
        end if

  if z(lt)<0
    str="-"
        end if
   txres2  = True
   txres2@txFont  = 2
   txres2@txFontHeightF =0.01
   txres2@txFontColor = "Red"
   txdum1 =gsn_add_text(wks, plot, str, lon,lat, txres2)

  draw(plot)       ; This will draw the map and the shapefile outlines.
  frame(wks)
   delete(opts)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   end do        
end


提示我的if有错,对于这个我没怎么看懂

fatal:Conditional statements (if and do while) require SCALAR logical values, see all and any functions
fatal:["Execute.c":8567]:Execute: Error occurred at or near line 105 in file /home/Huanglei/shandian.ncl

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-26 20:21:06 | 显示全部楼层
黄小仙儿 发表于 2014-4-26 15:09
longlive大神,我自己编了个画闪电的程序,能帮我看看不。感觉我对字符的理解有误~~
这是我的程序的思路 ...

ncl里面>符号范围两者中的大值,而if后需要True或者False,所以代码最好的>和<符号要分别改为.gt.和.lt.。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-4-27 15:18:03 | 显示全部楼层
longlivehj 发表于 2014-4-26 20:21
ncl里面>符号范围两者中的大值,而if后需要True或者False,所以代码最好的>和

哦。原来是这样。
我改了后运行,没有提示任何错误,但是现在还在运行,没有提示错误,已经运行了三个多小时了。我不知道是出错了,还是数据太多,正在运行。
QQ图片20140427151433.jpg
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-27 15:19:35 | 显示全部楼层
黄小仙儿 发表于 2014-4-27 15:18
哦。原来是这样。
我改了后运行,没有提示任何错误,但是现在还在运行,没有提示错误,已经运行了三个多 ...

NCL的缺点就是慢~~~尤其是循环多了以后更慢~~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2014-4-27 15:42:07 | 显示全部楼层
andrewsoong 发表于 2014-4-27 15:19
NCL的缺点就是慢~~~尤其是循环多了以后更慢~~~

哦,知道了
想问一下大神一个有关wrf的问题
垂直分层设置的是默认的27层,但是用NCL画图,插值后底层气压数据缺失。不知道这是正常现象,还是有错。
原始的pressure是27层,最底层是从700hpa开始的
请问你知不知道这是什么原因
description : Pressure
  units :       hPa
  _FillValue :  9.96921e+36
(0)     9.96921e+36
(1)     9.96921e+36
(2)     9.96921e+36
(3)     9.96921e+36
(4)     9.96921e+36
(5)     9.96921e+36
(6)     9.96921e+36
(7)     9.96921e+36
(8)     9.96921e+36
(9)     9.96921e+36
(10)    9.96921e+36
(11)    9.96921e+36
(12)    9.96921e+36
(13)    9.96921e+36
(14)    9.96921e+36
(15)    9.96921e+36
(16)    9.96921e+36
(17)    9.96921e+36
(18)    9.96921e+36
(19)    9.96921e+36
(20)    9.96921e+36
(21)    9.96921e+36
(22)    9.96921e+36
(23)    740
(24)    730
(25)    720
(26)    710
(27)    700
(28)    690
(29)    680
(30)    670
(31)    660
(32)    650
(33)    640
(34)    630
(35)    620
(36)    610
(37)    600
(38)    590
(39)    580
(40)    570
(41)    560
(42)    550
(43)    540
(44)    530
(45)    520
(46)    510
(47)    500
(48)    490
(49)    480
(50)    470
(51)    460
(52)    450
(53)    440
(54)    430
(55)    420
(56)    410
(57)    400
(58)    390
(59)    380
(60)    370
(61)    360
(62)    350
(63)    340
(64)    330

原始的p是27层,从700hpa多开始,(为什么不是100hpa)
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-4-27 15:59:46 | 显示全部楼层
黄小仙儿 发表于 2014-4-27 15:42
哦,知道了
想问一下大神一个有关wrf的问题
垂直分层设置的是默认的27层,但是用NCL画图,插值后底层气 ...

高原地区应该是的~~~
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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