<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>CDO is not an NCAR product. Hence, not much experience with its expectations.</div><div><br></div><div>I speculate that <b>time</b> should be something like: "days since 1900-01-01 00:00:00"</div><div><br></div><div>;---Define time period<br><br> yrStrt = 1920<br> yrLast = 2014<br> yyyymm = <a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/yyyymm_time.shtml"><b>yyyymm_time</b></a>(yrStrt,yrLast,"integer") ; yyyymm(time) <br> ntim = <b>dimsizes</b>(yyyymm) ; all years & months<br> <b>printVarSummary</b>(yyyymm)<br> <b>print</b>("---")<br><br></div><div>; Create time for netCDF<br><br> yyyy = yyyymm/100<br> mm = yyyymm - yyyy*100<br> dd = <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/conform.shtml"><b>conform</b></a>(yyyy, 1, -1)<br> hh = <b>conform</b>(yyyy, 0, -1)<br> mn = <b>conform</b>(yyyy, 0, -1)<br> sc = <b>conform</b>(yyyy, 0, -1)<br> tunits = "days since 1900-01-01 00:00:00"<br><br> time = <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/cd_inv_calendar.shtml"><b>cd_inv_calendar</b></a>(yyyy,mm,dd,hh,mn,sc,tunits, 0)<br> time!0 = "time"<br> time&time = time<br> time@units= tunits<br><br> yyyymm!0 = "time"<br> yyyymm&time := time</div><div><br></div><div>See attached</div><div><br></div><div>D<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 21, 2019 at 3:01 AM Appo derbetini <<a href="mailto:appopson4@gmail.com">appopson4@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="4">Dear Adam,</font></div><div><font size="4">With the script you send, i am able to read and write data into netcdf file. <br></font></div><div><font size="4">But when i am trying to use cdo to select specific year with this command</font></div><div><font size="4"><br></font></div><div><font size="4"><span style="color:rgb(255,0,0)">cdo selyear,2000 NC131.nc <a href="http://aaa.nc" target="_blank">aaa.nc</a> </span><br></font></div><div><font size="4"><br></font></div><div><font size="4">this error appears</font></div><div><font size="4"><span style="color:rgb(255,0,0)">Warning (cdf_set_dim): Inconsistent dimension definition for lat! dimid = 0; type = 1; newtype = 2<br>Warning (cdf_set_dim): Inconsistent dimension definition for lon! dimid = 0; type = 2; newtype = 1<br>cdo selyear (Warning): Year 2000 not found!<br>cdo selyear (Abort): No timesteps selected!</span><br><br></font></div><div><font size="4">Here below the script used.</font></div><div><font size="4"><br></font></div><div><font size="4">Regards Appo<br></font></div><div><font size="4"><br></font></div><div dir="ltr"><span style="color:rgb(0,0,255)"><font size="4">begin<br> yrStrt = 1920<br> yrLast = 2014<br> file_name = "Rain_estimate_2.5DegGrid.txt"<br> rain = asciiread(file_name, -1, "string")<br><br>lat = fspan(-23.75, 11.25, 15) <br>lat@units = "degrees_north"<br>lat@standard_name = "latitude" ;<br>lat!0 = "lat"<br>lat&lat = lat<br>lat@axis = "X" <br>lat@standard_name = "latitude" ;<br>lat@long_name = "latitude" ;<br><br>;print(lat)<br><br>lon = fspan(6.25, 43.75, 16)<br>lon@units = "degrees_east"<br>lon@standard_name = "longitude" ;<br>lon!0 = "lon"<br>lon&lon = lon<br>lon@axis = "Y" <br>lon@standard_name = "longitude" ;<br>lon@long_name = "longitude" ;<br><br><br><br> time = yyyymm_time(yrStrt, yrLast, "integer")<br><br> time@long_name = "time" ;<br> time@standard_name = "time" ;<br> time@units = "days since 1900-01-01 00:00:0.0"<br> time@calendar = "gregorian" ;<br> time@axis = "T" <br> <br> <br> <br>mod_data = new((/(yrLast-yrStrt+1)*12, dimsizes(lat), dimsizes(lon)/), float) ;Set up master array that will be filled in. <br>mod_data!0 = "time"<br>mod_data&time = time<br>mod_data!1 = "lat"<br>mod_data&lat = lat<br>mod_data!2 = "lon"<br>mod_data&lon = lon<br>mod_data@long_name = "precipitation" ; assign attributes <br>mod_data@units = "mm" ;<br>mod_data@missing_value = mod_data@_FillValue<br><br>nrow = dimsizes(rain)<br><br><br>do gg = 0, nrow-2, 100 ; Run a do loop over each 100 row segment<br> temp = rain(gg:gg+99)<br> coords = str_split(temp(1), " ")<br> ;print(coords) ; examine results of text split<br> lat_coord = tofloat(coords(2))<br> lon_coord = tofloat(coords(5)) <br> ii = 0<br> do hh = 5,99 ; operate on rows 5-99 of temp <br> data = tofloat(str_split(temp(hh), " ")) <br> <br> mod_data({data(0)*100+1:data(0)*100+12}, {lat_coord}, {lon_coord}) = (/ data(1:) /)<br> <br> delete(data)<br> end do<br> delete(temp)<br> ;print("Now done with lat="+lat_coord+", lon="+lon_coord) <br>end do<br><br><br>; Save to netcdf<br> ;=================================================================== <br> ntim = dimsizes(time) ; get dimension sizes <br> nlat = dimsizes(lat) <br> nlon = dimsizes(lon) <br><br> diro = "./" ; Output directory<br> filo = "NC131.nc" ; Output file<br> system("/bin/rm -f " + diro + filo) ; remove if exists<br> fout = addfile (diro + filo, "c") ; open output file<br><br> ;===================================================================<br> ; explicitly declare file definition mode. Improve efficiency.<br> ;===================================================================<br> setfileoption(fout,"DefineMode",True)<br><br> ;===================================================================<br> ; create global attributes of the file<br> ;===================================================================<br> fAtt = True ; assign file attributes<br> fAtt@title = "NC131" <br> fAtt@source_file = "Nicholson SE, Klotter D, Dezfuli AK, Zhou L (2018b) New rainfall datasets for the Congo Basin and surrounding regions. J Hydrometeorol 19:1379–1396"<br> fAtt@Conventions = "None" <br> fAtt@creation_date = systemfunc ("date") <br> fileattdef( fout, fAtt ) ; copy file attributes <br><br> ;===================================================================<br> ; predefine the coordinate variables and their dimensionality<br> ; Note: to get an UNLIMITED record dimension, we set the dimensionality<br> ; to -1 (or the actual size) and set the dimension name to True.<br> ;===================================================================<br> dimNames = (/"time", "lat", "lon"/) <br> dimSizes = (/ -1 , nlat, nlon /) <br> dimUnlim = (/ True , False, False/) <br> filedimdef(fout, dimNames, dimSizes, dimUnlim)<br><br> ;===================================================================<br> ; predefine the the dimensionality of the variables to be written out<br> ;===================================================================<br> <br> <br> filevardef(fout, "time" ,typeof(time), getvardims(time)) <br> filevardef(fout, "lat" ,typeof(lat), getvardims(lat)) <br> filevardef(fout, "lon" ,typeof(lon), getvardims(lon)) <br> filevardef(fout, "pr" ,typeof(mod_data), getvardims(mod_data)) <br> <br> ; different from name on script<br> ;===================================================================<br> ; Copy attributes associated with each variable to the file<br> ; All attributes associated with each variable will be copied.<br> ;====================================================================<br> filevarattdef(fout,"time" ,time) ; copy time attributes<br> filevarattdef(fout,"lat" ,lat) ; copy lat attributes<br> filevarattdef(fout,"lon" ,lon) ; copy lon attributes<br> filevarattdef(fout,"pr" ,mod_data) ; copy PS attributes<br><br> ;===================================================================<br> ; explicitly exit file definition mode. **NOT REQUIRED**<br> ;===================================================================<br> setfileoption(fout,"DefineMode",False)<br><br> ;===================================================================<br> ; output only the data values since the dimensionality and such have<br> ; been predefined. The "(/", "/)" syntax tells NCL to only output the<br> ; data values to the predefined locations on the file.<br> ;====================================================================<br> fout->time = (/time/) <br> fout->lat = (/lat/)<br> fout->lon = (/lon/) <br> fout->pr = (/mod_data/)<br><br><br>end</font></span><br><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 20 févr. 2019 à 13:42, Appo derbetini <<a href="mailto:appopson4@gmail.com" target="_blank">appopson4@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><font size="4">Hi Adam,</font></div><div><font size="4">After multiple checking i found that error is coming from the fact that l"at" and "lon" were inverted here <br></font></div><div><font size="4"><br></font></div><div><div><span style="color:rgb(0,0,255)"><font size="4">lat = fspan(6.25,43.75,16)</font></span></div><div><div><span style="color:rgb(0,0,255)"><font size="4">lon = fspan(-23.75, 11.25,15)</font></span></div><div><font size="4"><br></font></div><div><font size="4">instead of</font></div><div><font size="4"><br></font></div><div><span style="color:rgb(255,0,255)"><font size="4"><font size="4">lat = fspan( <font size="4">-23.75, 11.25,15</font>)</font></font></span></div><div><span style="color:rgb(255,0,255)"><font size="4"><font size="4"><font size="4">lon = fspan(<font size="4">6.25,43.75,16)</font></font></font></font></span></div><div><font size="4"><font size="4"><font size="4"><font size="4"><br></font></font></font></font></div><div><font size="4"><font size="4"><font size="4"><font size="4">Best regards</font></font></font></font></div><div><font size="4"><font size="4"><font size="4"><font size="4"><br></font></font></font></font></div><div><font size="4"><font size="4"><font size="4"><font size="4">Appo<br></font></font></font></font></div><div><font size="4"><br></font></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 20 févr. 2019 à 12:44, Appo derbetini <<a href="mailto:appopson4@gmail.com" target="_blank">appopson4@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><font size="4">Dear Adam,</font></div><div><font size="4">Thank you for your kind help<br></font></div><div><font size="4">The script proposed by you is very clear and optimized. <br></font></div><div><font size="4">But there is an error appearing at this line <br></font></div><div><span style="color:rgb(255,0,0)"><font size="4">mod_data({data(0)*100+1:data(</font></span><span style="color:rgb(255,0,0)"><font size="4">0)*100+12},{lat_coord},{lon_</font></span><span style="color:rgb(255,0,0)"><font size="4">coord}) = (/ data(1:) /)</font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><br></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><span style="color:rgb(0,0,0)">Telling</span> <br></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><br></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4">fatal:NclOneDValGetClosestIndex: finish coordinate index out of range, can't continue<br>fatal:Could not obtain coordinate indexes, unable to perform subscript<br>fatal:["Execute.c":8637]:Execute: Error occurred at or near line 48 in file read_NCwrite_NC131_Adam.ncl<br></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><br></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><font color="#000000">Since a hour I am looking how to correct it without success</font></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><font color="#000000"><br></font></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><font color="#000000">Thanks again</font></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><font color="#000000"><br></font></font></span></div><div><span style="color:rgb(255,0,0)"><font size="4"><font color="#000000">Appo<br></font></font></span></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 19 févr. 2019 à 21:54, Adam Phillips <<a href="mailto:asphilli@ucar.edu" target="_blank">asphilli@ucar.edu</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Appo,<div>The nice aspect of your ascii file is that it is regular: Each grid point's data is given over 100 rows, and each is monthly running from 1920-2014. I would strongly recommend developing a new script that operates on each 100 row chunk of data, and that uses coordinate subscripting to put the data in the proper place in your final data array. One negative to this method is the possibility exists that multiple nearby data points get assigned to the same grid point, but this can be countered by setting your master array grid appropriately. An example:</div><div><br></div><div>; Untested! Review the code below.</div><div><div> yrStrt = 1920</div><div> yrLast = 2014</div></div><div><div> file_name = "Rain_estimate_2.5DegGrid.txt"</div><div> rain = asciiread(file_name, -1, "string")</div></div><div><br></div><div>lat = fspan(6.25,43.75,16)</div><div>lat@units = "degrees_north"</div><div>lat!0 = "lat"</div><div>lat&lat = lat</div><div><div>lon = fspan(-23.75, 11.25,15)</div><div>lon@units = "degrees_east"</div><div>lon!0 = "lon"</div><div>lon&lon = lon</div></div><div>time = yyyymm_time(yrStrt,yrLast,"integer")</div><div>mod_data = new((/(yrLast-yrStrt+1)*12,dimsizes(lat),dimsizes(lon)/),float,-999.) ;Set up master array that will be filled in. </div><div>mod_data!0 = "time"</div><div>mod_data&time = time</div><div>mod_data!1 = "lat"</div><div>mod_data&lat = lat</div><div>mod_data!2 = "lon"</div><div>mod_data&lon = lon</div><div><br></div><div>nrow = numAsciiRow("file_name")</div><div><br></div><div>do gg = 0,nrow-1,100 ; Run a do loop over each 100 row segment</div><div> temp = rain(gg:gg+99)</div><div> coords = str_split(temp(1)," ")</div><div> print(coords) ; examine results of text split</div><div> lat_coord = tofloat(coords(2))</div><div> lon_coord = tofloat(coords(5)) </div><div> do hh = 5,99 ; operate on rows 5-99 of temp </div><div> data = tofloat(str_split(temp(hh)," "))</div><div> mod_data({data(0)*100+1:data(0)*100+12},{lat_coord},{lon_coord}) = (/ data(1:) /)</div><div> delete(data)</div><div> end do</div><div> delete(temp)</div><div> print("Now done with lat="+lat_coord+", lon="+lon_coord) </div><div>end do</div><div><br></div><div>The above should at least get you going. If further changes need to be made to the above you will need to make them. If you have any further questions let ncl-talk know. </div><div>Adam</div><div><br></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 19, 2019 at 8:27 AM Appo derbetini <<a href="mailto:appopson4@gmail.com" target="_blank">appopson4@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Dear NCL users,</div><div><br></div><div>Here a script that i am using to read rainfall data. <br></div><div>Data are given for each grid point. <br></div><div>But points are not regularly distributed. <br></div><div>for some grid point there is no data</div><div><br></div><div>I want to construct regular matrix (lat, lon) where point without data will be created and filled by missing value (-999.0 in the script). <br></div><div><br></div><div>My script is giving wrong result !!!<br></div><div><br></div><div>Any help will be appreciated<br></div><div><br></div><div><br></div><div>Regards<br></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_8120936019596861029gmail-m_2585550274059082260gmail-m_8114217393696375215gmail-m_5712938886382667916gmail-m_-7481751364549875121gmail-m_-2755428772392260587gmail-m_6588817634466662453gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist, </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br></font></span></div></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a> </font></span><span><font color="#888888">303-497-1726 </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>