[ncl-talk] Time dimension in output to NetCDF
Dr. Muhammad Afzaal
afzaalkarori at gmail.com
Thu Nov 30 02:17:48 MST 2017
in continuation to my previous email, following is the defined variable
summary
Variable: prcp
Type: double
Total Size: 27336960 bytes
3417120 values
Number of Dimensions: 3
Dimensions and sizes: [time | 1356] x [lat | 42] x [lon | 60]
Coordinates:
time: [190101..201312]
lat: [12.25..32.75]
lon: [30.25..59.75]
Number Of Attributes: 3
units : (mm)
long_name :
_FillValue : -9.969209968386869e+36
Please read the second last line of my code as ncdf->prcp = prcp
Thanks
*Dr. MUHAMMAD AFZAAL KARORI*
Pakistan Meteorological Department
Sector H-8/2, Pitras Bukhari Road,
Islamabad - 44000
Pakistan
On Thu, Nov 30, 2017 at 12:06 PM, Dr. Muhammad Afzaal <
afzaalkarori at gmail.com> wrote:
> Dear NCL users
>
> I am using NCL 6.4.0 on ubuntu. I need to write a variable to netcdf file.
> I did it successfully using Method 1 given on ncl homepage. I have little
> problem that when I open nc file in grads, the time is not realistic. I
> mean its like;
>
> Time values set: 2320:6:25:0 2320:6:25:0
>
> while the variable has the time from 190101 to 201312
>
> Can someone please help me how can add time dim as that attached with the
> define variable? My code is given below
>
> ;====================================================
> begin
>
> diri = "./"
> fili = "precip.mon.total.v7.nc"
> f = addfile(diri+fili, "r")
>
> prc = flt2dble(f->precip(:,{12:33},{30:60}))
> pmsg = prc at _FillValue ; convenience
>
> ;*********************************
> ; plot parameters
> ;*********************************
> dimprc = dimsizes(prc)
> ntim = dimprc(0)
> nlat = dimprc(1)
> mlon = dimprc(2)
>
> tim = f->time
> utc_date = cd_calendar(tim, 0)
> year = tointeger(utc_date(:,0))
> yrStrt = year(0)
> yrLast = year(ntim-1)
> nyear = yrLast-yrStrt+1
> ;print(year + " " + yrStrt + " "+ yrLast +" "+ nyear)
> yyyymm = yyyymm_time(yrStrt, yrLast, "integer")
>
> yrfrac = (/ yyyymm_to_yyyyfrac(yyyymm, 0.0) /)
> prc&time = (/ yyyymm /)
>
> ;===============================================================
> ;write to nc file
> ;================================================================
>
> system("/bin/rm -f prc_3mon.nc") ;remove any pre-existing file
> ncdf = addfile("prc_3mon.nc" ,"c") ; open output netCDF file
>
> ;===============================================================
> ; create global attributes of the file (optional)
> ;================================================================
> fAtt = True ; assign file attributes
> fAtt at title = "GPCC Rainfall"
> fAtt at source_file = "precip.mon.total.v7.nc"
> fAtt at Conventions = "None"
> fAtt at creation_date = systemfunc ("date")
> fileattdef( ncdf, fAtt ) ; copy file attributes
>
> ;===============================================================
> ; make time an UNLIMITED dimension;recommended for most applications
> ;===============================================================
>
> filedimdef(ncdf,"time",-1,True)
>
> ;===============================================================
> ; output variables directly; NCL will call appropriate functions
> ; to write the meta data associated with each variable
> ;===============================================================
> ncdf->spi = spi ; 3D
> end
>
>
> Regards
> *Dr. MUHAMMAD AFZAAL KARORI*
> Pakistan Meteorological Department
> Sector H-8/2, Pitras Bukhari Road,
> Islamabad - 44000
> Pakistan
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171130/d6f7334c/attachment.html>
More information about the ncl-talk
mailing list