[ncl-talk] Writing SPI to netCDF files

misnawati misna misna39 at yahoo.com
Fri Jan 1 23:26:24 MST 2016


Dear NCL Supoort,
I was run SPI scripts as below and it's work, but I try to save the output of SPI to netCDF file, and  I got the results but all values of SPI are -9999, anyone can help me to fix it?

Thank you very much,

Misna
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"
  diri   = "./"  fili   = "UCSB_CHIRPS_v2p0_mo8114_indo.nc"  f      = addfile(diri+fili, "r")
  prc    = f->precipitation(0:407,:,:)  ;print(prc)  pmsg   = prc at _FillValue      ; convenience
  printVarSummary(prc)  printMinMax(prc,0)
  runlen = (/ 12, 24 /)     nrun   = dimsizes(runlen);*********************************; plot parameters;*********************************  dimprc = dimsizes(prc)  ntim   = dimprc(0)  nlat   = dimprc(1)  mlon   = dimprc(2)
  yyyymm = cd_calendar(f->T(0:407), -1)  ;print(yyyymm)  ;yyyymm = yyyymm/100    year    = yyyymm/100  ;print(year)  nyear   = dimsizes(year)  ;print(nyear)  yrStrt  = year(0)  ;print(yrStrt)  yrLast  = year(ntim-1)  ;print(yrLast)  nyear   = yrLast-yrStrt+1  yyyymm  = yyyymm_time(yrStrt, yrLast, "integer")   yrfrac  = (/ yyyymm_to_yyyyfrac(yyyymm, 0.0) /)
  prc&T = (/ yyyymm /)
  ;=================================
  wks          = gsn_open_wks ("png","spiprojectindo1")    gsn_define_colormap(wks,"BlueWhiteOrangeRed")  gsn_reverse_colormap(wks)           ; Reverse the color map.
  res          = True                     res at gsnDraw          = False              ; don't draw  res at gsnFrame         = False              ; don't advance frame  res at gsnSpreadColors  = True               res at mpMinLonF = 90  ;koordinat indonesia  res at mpMaxLonF = 145  res at mpMinLatF = -11  res at mpMaxLatF = 6 res at gsnAddCyclic = False  res at cnFillOn         = True               ; color Fill   res at cnFillMode       = "RasterFill"       ; Raster Mode  res at cnLinesOn        =  False             ; Turn off contour lines  res at cnLevelSelectionMode = "ManualLevels" ; set manual contour levels  res at cnMinLevelValF   = -3.0               ; set min contour level  res at cnMaxLevelValF   =  3.0               ; set max contour level  res at cnLevelSpacingF  =  0.5               ; set contour spacing  res at lbLabelBarOn     = False              ; turn off individual cb's
  resP                 = True               ; panel resources  resP at txString        = "SPI: 1981-2014 (CHIRPS)"  ; add center string  resP at gsnPanelLabelBar= True               ; add common colorbar
  plot = new ( 2, "graphic")
  do nr=0,nrun-1    spi    = dim_spi_n(prc, runlen(nr), False, 0)
    spi at long_name = "SPI"    spi at units = "run="+runlen(nr)    copy_VarCoords(prc, spi)
 res at gsnCenterString  = yyyymm({200007})    plot(0) = gsn_csm_contour_map_ce(wks,spi({200007},:,:), res) 
    res at gsnCenterString  = yyyymm({200612})    plot(1) = gsn_csm_contour_map_ce(wks,spi({200612},:,:), res)  
    gsn_panel(wks,plot,(/2,1/),resP)           end do

dimprc = dimsizes(prc) ntim   = dimprc(0) nlat   = dimprc(1) mlon   = dimprc(2)  ;ntime=time ;nlat=lat ;mlon=lon  diro = "./"                      ; Output directory    filo = "IndeksKekeringan.nc"             ; Output file system("/bin/rm -f " + diro + filo)    ; remove if exists fout  = addfile (diro + filo, "c")  ; open output file;print(fout)      setfileoption(fout,"DefineMode",True)    fAtt               = True            ; assign file attributes fAtt at title         = "NCL Efficient Approach to netCDF Creation"   fAtt at source_file   = "UCSB_JawaTengah.nc" fAtt at Conventions   = "None"    fAtt at creation_date = systemfunc ("date")         fileattdef( fout, fAtt )            ; copy file attributes    dimNames = (/"T", "Y", "X"/)   dimSizes = (/ ntim   ,  nlat,  mlon/)  dimUnlim = (/ False , False, False/)    filedimdef(fout,dimNames,dimSizes,dimUnlim) print(dimNames) print(dimSizes) print(dimUnlim)  filevardef(fout, "time" ,typeof(spi&T),getvardims(spi&T))              filevardef(fout, "lat"  ,typeof(spi&Y),getvardims(spi&Y))                              filevardef(fout, "lon"  ,typeof(spi&X),getvardims(spi&X))                              filevardef(fout, "SPI"   ,typeof(spi),getvardims(spi))           filevarattdef(fout,"SPI",spi)                     ; copy T attributes    filevarattdef(fout,"time" ,spi&T)                    ; copy time attributes    filevarattdef(fout,"lat"  ,spi&Y)                     ; copy lat attributes    filevarattdef(fout,"lon"  ,spi&X)                     ; copy lon attributes        setfileoption(fout,"DefineMode",False)     fout->T    = (/spi&T/)         fout->lat    = (/spi&Y/)    fout->lon    = (/spi&X/)   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160102/e2b2d699/attachment.html 


More information about the ncl-talk mailing list