Re: About netcdf output

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 25 2014 - 18:09:42 MST

Guilong,

We found a bug related to setfileoption("nc", "format", "NetCDF4").
We have fixed it, and the new fix will be in the new release.

Please try make changes indicated below, and let us know is there is any problem.
(The code below may actually with "NetCDF4" as well).

Thanks,

Wei

-------

Please try replace your code start from:

lev = …

To:

  ilev = (/3, 6, 12, 24, 36, 48 /)
  klev = dimsizes(ilev)
  prc@_FillValue = default_fillvalue(typeof(prc))
  spi = new((/klev,ntim,nlat,mlon/) ,float,prc@_FillValue)

  do k=0,klev-1
     spi(k,:,:,:) = dim_spi_n(prc, ilev(k), False, 0)
  end do

 ;printVarSummary(ilev)
  copy_VarCoords(prc,spi(0,:,:,:))

  lev = todouble(ilev)
  lev@long_name = "Levels"
  lev@units = "None"
  lev@axis = "Z"

  lev!0 = "lev"
  lev&lev = lev

  spi@long_name = "SPI"
  spi!0 = "lev"
  spi&lev = lev
  spi!1 = "time"
  spi&time = time
  spi!2 = "lat"
  spi&lat = lat
  spi!3 = "lon"
  spi&lon = lon
  printVarSummary(spi)
  print("spi(0, 0, 0, 0)=" + spi(0, 0, 0, 0))

  setfileoption("nc","Format","NetCDF4Classic")
  system("rm -rf out1.nc")
  fout = addfile("out1.nc","c")
 ;fout->time = time ; time(time)
 ;fout->lev = lev ; levels(lev)
 ;fout->lon = lon ; longitude(lon)
 ;fout->lat = lat ; latitude(lat)
  fout->spi = spi ; spi(lev,time,lat,lon)

  fin = addfile("out1.nc","r")
  intime = fin->time
  inlon = fin->lon
  inlat = fin->lat
  inlev = fin->lev
  inspi = fin->spi

  print("outtime(0) = " + time(0) + ", intime = " + intime(0))
  print("outlon(0) = " + lon(0) + ", inlon = " + inlon(0))
  print("outlat(0) = " + lat(0) + ", inlat = " + inlat(0))
  print("outlev(0) = " + lev(0) + ", inlev = " + inlev(0))
  print("outspi(0) = " + spi(0,0,0,0) + ", inspi = " + inspi(0,0,0,0))

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

On Feb 25, 2014, at 4:51 PM, Wei Huang <huangwei@ucar.edu> wrote:

> Guilong,
>
> We'll take a look at this and get back to you.
>
> Thanks,
>
> Wei
>
> huangwei@ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
>
>
>
>
> On Feb 25, 2014, at 3:27 PM, "Li,Guilong [Ontario]" <Guilong.Li@ec.gc.ca> wrote:
>
>> Hi,
>>
>> I am using ncl to calculate standardized precipitation index, and I want
>> to output the result in netcdf format which can be read be some graph
>> software, such as GrADS. I use the following program but it seems I have
>> something wrong on the program
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> f = addfile("pr_mon.nc", "r")
>> prc = f->pr ; PREC(time,lat,lon)
>> lon = f->lon ; Longitude(lon)
>> lat = f->lat ; Latitude(lat)
>> time = f->time ; Time(time)
>> printVarSummary(prc)
>>
>> dimp = dimsizes(prc) ; # monthly precipitation values
>> ntim = dimp(0)
>> nlat = dimp(1)
>> mlon = dimp(2)
>>
>> lev = (/3, 6, 12, 24, 36, 48 /)
>> klev = dimsizes(lev)
>> spi = new((/klev,ntim,nlat,mlon/) ,float,prc@_FillValue)
>>
>> do k=0,klev-1
>> spi(k,:,:,:) = dim_spi_n(prc, lev(k), False, 0)
>> end do
>>
>> printVarSummary(lev)
>> copy_VarCoords(prc,spi(0,:,:,:))
>> spi@long_name = "SPI"
>> lev@long_name = "Levels"
>> lev@units = "months"
>> lev@axis = "Z"
>> spi!0 = "lev"
>> spi&lev = lev
>> spi!1 = "time"
>> spi&time = time
>> spi!2 = "lat"
>> spi&lat = lat
>> spi!3 = "lon"
>> spi&lon = lon
>> printVarSummary(spi)
>>
>> setfileoption("nc","Format","NetCDF4")
>> fout = addfile("out1.nc","c")
>> fout->spi = spi ; spi(lev,time,lat,lon)
>> fout->lon = lon ; longitude(lon)
>> fout->lat = lat ; latitude(lat)
>> fout->lev = lev ; levels(lev)
>> fout->time = time ; time(time)
>>
>> As I am new in ncl group, I just wonder whether someone can help me on
>> this problem. If I don't output the lon, lat, lev, and time, I can write
>> a control file to read the output. But I still want to know how to write
>> it in netcdf format which can be read by GrADS directly.
>>
>> Thanks,
>>
>> Guilong
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Feb 25 18:09:57 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 03 2014 - 14:26:18 MST