[ncl-talk] Time dimension in output to NetCDF
Dr. Muhammad Afzaal
afzaalkarori at gmail.com
Sat Dec 2 23:05:47 MST 2017
Thank you Dannis and Dave for your suggestion/corrections, which really
helped me understand the issue.
*Dr. MUHAMMAD AFZAAL KARORI*
Pakistan Meteorological Department
Sector H-8/2, Pitras Bukhari Road,
Islamabad - 44000
Pakistan
On Thu, Nov 30, 2017 at 5:38 PM, Dennis Shea <shea at ucar.edu> wrote:
> I don't know GrADS and how it handles 'time'
>
> ===
> My speculation is that
> prc&time = (/ yyyymm /)
> is the source of the problem.
> Likely, GrADS expects 'time' to have units like
> 'seconds/minutes/hours/days since ...."
>
> I would eliminate the above line .....ALso, not sure why you are
> 'promoting' the float variable to a double.
>
> GrADS questions should be sent to the GrADS support group.
> =======================
>
> 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
>
> ;===============================================================
> ;write to nc file
> ;================================================================
>
>
> prc = flt2dble(f->precip(:,{12:33},{30:60})) ; <<< ??why are you
> promoting to double?
>
> ====
>
> Actually, the netCDF Operators could be used
>
> %> ncks --d lat,12.0,33.0 -d lon,30.0,60.0 -O precip.mon.total.v7.nc
> <http://precip.mon.total.v7.nc>prc_3mon.nc
>
> On Thu, Nov 30, 2017 at 2:17 AM, Dr. Muhammad Afzaal <
> afzaalkarori at gmail.com> wrote:
>
>> 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
>>>
>>>
>>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171203/655ea3ce/attachment.html>
More information about the ncl-talk
mailing list