[ncl-talk] Saving Output SPI Scripts to NetCDF file

misnawati misna misna39 at yahoo.com
Sun Dec 13 20:35:11 MST 2015


Dear NCL User,
I was run SPI scripts as below and it worked, but I want the output this script is netCDF or csv, does anyone know how to do this? Please help me.

Thank you very much,

Misna

;----------------------------- ------------------------------ -----------
; spi_2.ncl
;
; Concepts illustrated:
;   - Computing the Standardized Precipitation Index (SPI)
;   - Reading data from the GPCP (Global Precipitation Climatology Project)
;----------------------------- ------------------------------ -----------
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   = "V22_GPCP.1979-2010.nc"
  f      = addfile(diri+fili, "r")

  prc    = flt2dble(f->PREC)
  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 = f->date
  yyyymm = yyyymm/100
  
  year    = yyyymm/100
  yrStrt  = year(0)
  yrLast  = year(ntim-1)
  nyear   = yrLast-yrStrt+1
  yyyymm  = yyyymm_time(yrStrt, yrLast, "integer") 
  yrfrac  = (/ yyyymm_to_yyyyfrac(yyyymm, 0.0) /)

  prc&time = (/ yyyymm /)

;============================= ====

  wks          = gsn_open_wks ("ps","spi")
  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 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: 1979-2010 (GPCP)"  ; 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({201012})
    plot(1) = gsn_csm_contour_map_ce(wks, spi({200612},:,:), res) 

    gsn_panel(wks,plot,(/2,1/), resP)          ; now draw as one plot
  end do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151214/2140b7a4/attachment.html 


More information about the ncl-talk mailing list