<div dir="ltr"><div>1. Grads wants CF time coordinates, like "days since ..." as Dennis said.</div><div><br></div><div>2. Also I agree that NCO operators would be the quickest solution to make this subset file, if you do not need some extra calculation within NCL. However there is a typo in Dennis's command, an extra dash near the beginning. I think this is correct:</div><br>ncks -d lat,12.0,33.0 -d lon,30.0,60.0 -O <a href="http://precip.mon.total.v7.nc">precip.mon.total.v7.nc</a> <a href="http://prc_3mon.nc">prc_3mon.nc</a><br><br>3. The source file name tells me that this is probably GPCC precip, downloaded from NOAA/ESRL/PSD. If so, then you already have Grads compatible time coordinates in the source file. Therefore the easiest path is to copy the existing time coordinates, not try to generate new ones.<div><br></div>This is easy if you skip the type conversion from float to double with "flt2dble". Here is a trimmed example. If you read prc in directly like this, it will include an attached time coordinate that is already Grads and CF compatible:<br><br> fili = "<a href="http://precip.mon.total.v7.nc">precip.mon.total.v7.nc</a>"<br><div> f = addfile(fili, "r")<br> prc = f->precip(:,{12:33},{30:60})<div> printVarSummary (prc)<br><br> ncdf = addfile("<a href="http://prc_3mon.nc">prc_3mon.nc</a>", "c")<br><br>; Make time an UNLIMITED dimension; recommended for most applications.<div>; This step is OPTIONAL if you do not care about unlimited.<br><br> filedimdef(ncdf,"time",-1,True)<br><br>; Output variable directly. Coordinates and attributes will be included.</div><div><br> ncdf->prc = prc ; 3D<br><br>--Dave<br><br><br><div><div class="gmail_extra"><div class="gmail_quote">On Thu, Nov 30, 2017 at 7:38 AM, Dennis Shea <span dir="ltr"><<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>I don't know GrADS and how it handles 'time'<br><br>===<br></div>My speculation is that <br> <font color="#ff0000">prc&time = (/ yyyymm /)<br></font></div><font color="#ff0000"><font color="#000000">is the source of the problem.<br> Likely, GrADS expects 'time' to have units like 'seconds/minutes/hours/days since ...."<br><br></font></font></div><font color="#ff0000"><font color="#000000">I would eliminate the above line .....ALso, not sure why you are 'promoting' the float variable to a double.<br><br></font></font></div><font color="#ff0000"><font color="#000000">GrADS questions should be sent to the GrADS support group.<br></font></font><div><div><div><font color="#ff0000"><font color="#000000">=======================<br></font></font><br><font color="#ff0000"><font color="#000000"><font color="#ff0000"> diri = "./"</font></font></font><div><font color="#ff0000"> fili = "<a href="http://precip.mon.total.v7.nc" target="_blank">precip.mon.total.v7.nc</a>"</font></div><div><font color="#ff0000"> f = addfile(diri+fili, "r")</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> prc = flt2dble(f->precip(:,{<span class="gmail-m_-1914307647958184978gmail-aBn"><span class="gmail-m_-1914307647958184978gmail-aQJ">12:33</span></span>},{<wbr>30:60}))</font></div><div><font color="#ff0000"> pmsg = prc@_FillValue ; convenience</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000">;write to nc file</font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>=====</font></div><div><br></div><font color="#ff0000">prc = flt2dble(f->precip(:,{<span class="gmail-m_-1914307647958184978gmail-aBn"><span class="gmail-m_-1914307647958184978gmail-aQJ">12:33</span></span>},{<wbr>30:60})) ; <<< ??why are you promoting to double?<br><br><span style="color:rgb(0,0,0)">====</span><br><br></font></div><div><font color="#ff0000">Actually, the netCDF Operators could be used<br><br></font></div><div><font color="#ff0000">%> ncks -</font><font color="#ff0000">-d lat,12.0,33.0 -d lon,30.0,60.0 -O</font><font color="#ff0000"><font color="#ff0000"><a href="http://precip.mon.total.v7.nc" target="_blank"><font color="#ff0000"> </font>precip.mon.total.v7.nc </a></font></font><font color="#ff0000"><font color="#ff0000"><font color="#ff0000"><a href="http://prc_3mon.nc" target="_blank"><font color="#ff0000"></font>prc_3mon.nc</a></font></font></font></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 30, 2017 at 2:17 AM, Dr. Muhammad Afzaal <span dir="ltr"><<a href="mailto:afzaalkarori@gmail.com" target="_blank">afzaalkarori@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)">in continuation to my previous email, following is the defined variable summary</div><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)"><br></div><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)"><div>Variable: prcp</div><div>Type: double</div><div>Total Size: 27336960 bytes</div><div> 3417120 values</div><div>Number of Dimensions: 3</div><div>Dimensions and sizes: [time | 1356] x [lat | 42] x [lon | 60]</div><div>Coordinates:</div><div> time: [190101..201312]</div><div> lat: [12.25..32.75]</div><div> lon: [30.25..59.75]</div><div>Number Of Attributes: 3</div><div> units : (mm)</div><div> long_name : </div><div> _FillValue : -9.969209968386869e+36</div><div><br></div><div>Please read the second last line of my code as ncdf->prcp = prcp</div><div><br></div><div>Thanks </div><div><br></div></div><div class="gmail_extra"><span><div><div class="gmail-m_-1914307647958184978m_3512487935546376823gmail_signature"><div dir="ltr"><div><div dir="ltr"><i>Dr. MUHAMMAD AFZAAL KARORI</i><br>Pakistan Meteorological Department<br>Sector H-8/2, Pitras Bukhari Road,<br>Islamabad - 44000<br>Pakistan <br><br></div></div></div></div></div>
<br></span><div><div class="gmail-m_-1914307647958184978h5"><div class="gmail_quote">On Thu, Nov 30, 2017 at 12:06 PM, Dr. Muhammad Afzaal <span dir="ltr"><<a href="mailto:afzaalkarori@gmail.com" target="_blank">afzaalkarori@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)">Dear NCL users</div><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)"><br></div><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)">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;</div><div style="font-family:georgia,serif;font-size:small;color:rgb(0,0,0)"><br></div><div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small">Time values set: 2320:6:25:0 2320:6:25:0</div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small"> </div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small">while the variable has the time from 190101 to 201312</div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small"><br></div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small">Can someone please help me how can add time dim as that attached with the define variable? My code is given below</div><div style="color:rgb(0,0,0);font-family:georgia,serif;font-size:small"><br></div><div><div><font color="#ff0000">;=============================<wbr>=======================</font></div><div><font color="#ff0000">begin</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> diri = "./"</font></div><div><font color="#ff0000"> fili = "<a href="http://precip.mon.total.v7.nc" target="_blank">precip.mon.total.v7.nc</a>"</font></div><div><font color="#ff0000"> f = addfile(diri+fili, "r")</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> prc = flt2dble(f->precip(:,{12:33},{<wbr>30:60}))</font></div><div><font color="#ff0000"> pmsg = prc@_FillValue ; convenience</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;*****************************<wbr>****</font></div><div><font color="#ff0000">; plot parameters</font></div><div><font color="#ff0000">;*****************************<wbr>****</font></div><div><font color="#ff0000"> dimprc = dimsizes(prc)</font></div><div><font color="#ff0000"> ntim = dimprc(0)</font></div><div><font color="#ff0000"> nlat = dimprc(1)</font></div><div><font color="#ff0000"> mlon = dimprc(2)</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> tim = f->time</font></div><div><font color="#ff0000"> utc_date = cd_calendar(tim, 0) </font></div><div><font color="#ff0000"> year = tointeger(utc_date(:,0))</font></div><div><font color="#ff0000"> yrStrt = year(0)</font></div><div><font color="#ff0000"> yrLast = year(ntim-1)</font></div><div><font color="#ff0000"> nyear = yrLast-yrStrt+1</font></div><div><font color="#ff0000">;print(year + " " + yrStrt + " "+ yrLast +" "+ nyear)</font></div><div><font color="#ff0000"> yyyymm = yyyymm_time(yrStrt, yrLast, "integer") </font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> yrfrac = (/ yyyymm_to_yyyyfrac(yyyymm, 0.0) /)</font></div><div><span style="white-space:pre-wrap"><font color="#ff0000"> </font></span></div><div><font color="#ff0000"> prc&time = (/ yyyymm /)</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000">;write to nc file</font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>=====</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> system("/bin/rm -f <a href="http://prc_3mon.nc" target="_blank">prc_3mon.nc</a>") ;remove any pre-existing file</font></div><div><font color="#ff0000"> ncdf = addfile("<a href="http://prc_3mon.nc" target="_blank">prc_3mon.nc</a>" ,"c") ; open output netCDF file</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000">; create global attributes of the file (optional)</font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>=====</font></div><div><font color="#ff0000"> fAtt = True ; assign file attributes</font></div><div><font color="#ff0000"> fAtt@title = "GPCC Rainfall"</font></div><div><font color="#ff0000"> fAtt@source_file = "<a href="http://precip.mon.total.v7.nc" target="_blank">precip.mon.total.v7.nc</a>"</font></div><div><font color="#ff0000"> fAtt@Conventions = "None"</font></div><div><font color="#ff0000"> fAtt@creation_date = systemfunc ("date")</font></div><div><font color="#ff0000"> fileattdef( ncdf, fAtt ) ; copy file attributes</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000">; make time an UNLIMITED dimension;recommended for most applications</font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000"> filedimdef(ncdf,"time",-1,Tru<wbr>e) </font></div><div><font color="#ff0000"><br></font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000">; output variables directly; NCL will call appropriate functions</font></div><div><font color="#ff0000">; to write the meta data associated with each variable</font></div><div><font color="#ff0000">;=============================<wbr>==============================<wbr>====</font></div><div><font color="#ff0000"> ncdf->spi = spi ; 3D </font></div><div><font color="#ff0000">end</font></div></div><div><br></div><div><br></div><div>Regards</div></div><div><div class="gmail-m_-1914307647958184978m_3512487935546376823gmail-m_-3285677477193680377gmail_signature"><div dir="ltr"><div><div dir="ltr"><i>Dr. MUHAMMAD AFZAAL KARORI</i><br>Pakistan Meteorological Department<br>Sector H-8/2, Pitras Bukhari Road,<br>Islamabad - 44000<br>Pakistan <br></div></div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div></div></blockquote></div></div></div></div></div></div></div>