<div dir="ltr"><div><div>How closely did you look at your ascii data file?<br><br></div>Did you look at the values? <br><br></div>Really, How is anybody going to determine what you are doing? It is just a bunch of numbers. Here is a start for *you* <br><div><br></div><div>=== data file<br></div><div>ncols 241<br>nrows 291<br>xllcenter 91.33<br>yllcenter 5.00<br>cellsize 0.1<br>NODATA_value -999<br>133.0 136.0 138.0 .....<br><br>===<br><br> data = asciiread("/home/kunal/20040101.asc", -1,"float")<br> nData= dimsizes(data)<br> printVarSummary(data)<br> print("nData="+nData)<br> print("---")<br><br> nCols = toint(data(0)) ; ncols<br> nRows= toint(data(1)) ; nrows<br> nPts = nCols*nRows<br> print("nCols="+nCols+" nRows="+nRows+" nPts="+nPts)<br> print("---")<br><br> xllcenter = data(2)<br> yllcenter = data(3)<br> cellsize = data(4)<br> data@_FillValue = data(5)<br> values = data(6:) ; lat and lon mixed???? <br> print(values)<br> printMinMax(values,0)<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 21, 2017 at 10:55 PM, Kunal Bali <span dir="ltr"><<a href="mailto:kunal.bali9@gmail.com" target="_blank">kunal.bali9@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I tried to convert ascii format (attached previous mail) to netcdf by the script given below. <br></div>The script is generating the netcdf file but the lat lon dimensions did not correctly assign. <br><br><br></div>please let me know how to correct this script. <br><div><br><br>load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_code.ncl"<br>load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_csm.ncl"<br>load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/shea_util.ncl" <br>load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/contributed.<wbr>ncl" <br><br>begin<br><br> nLatitude = 241 <br> nLongitude = 291<br> <br> data = asciiread("/Users/Pushp/<wbr>Desktop/COD_NEW/PM2.5/in.txt",<wbr>(/nLatitude*nLongitude/),"<wbr>float")<br> printVarSummary(data)<br><br> Latitude = data(:nLatitude-1) <br> Longitude = data(:nLongitude-1)<br> printVarSummary(Latitude )<br> printVarSummary(Longitude)<br> <br> CF = data(:) <br> CF2D = onedtond(CF,(/nLatitude,<wbr>nLongitude/))<br><br> printVarSummary(CF2D)<br><br> if (any(isnan_ieee(CF2D))) then<br> value = 1.e20<br> replace_ieeenan (CF2D, value, 0)<br> CF2D@_FillValue = value<br> end if<br><br> ; printMinMax(Latitude,0)<br>; printMinMax(Longitude,0)<br> printMinMax(CF2D,0)<br><br>; Assign named dimensions <br><br> CF2D!0 = "lat"<br> CF2D!1 = "lon"<br><br>; Assign coordinate variables<br><br> CF2D&lat = Latitude<br> CF2D&lon = Longitude<br><br> CF2D&lat@units = "degrees_north"<br> CF2D&lon@units = "degrees_east"<br> <br> printVarSummary(CF)<br>; delete existing netcdf file to create a new one<br> system("rm -rf <a href="http://test.nc" target="_blank">test.nc</a>")<br> ncdf = addfile("/Users/Pushp/Desktop/<wbr>COD_NEW/PM2.5/<a href="http://test.nc" target="_blank">test.nc</a>","c")<br><br>; write data to netcdf file<br><br> ncdf->CF = CF2D<br><br>end<br> <br><div><div><div><br><br><br><br><div class="gmail_extra">regards<span class="HOEnZb"><font color="#888888"><br clear="all"></font></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><div><div class="m_-4707042885433198598gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Kunal Bali<br></div><br><div><br></div><div><br></div><div><br></div><div><p style="margin:0px;border-collapse:collapse;font-family:Tahoma,Verdana;font-size:12px"><font color="#1F497D"><br></font></p></div></div></div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Tue, Nov 21, 2017 at 6:29 PM, Kunal Bali <span dir="ltr"><<a href="mailto:kunal.bali9@gmail.com" target="_blank">kunal.bali9@gmail.com</a>></span> wrote:<br><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">I tried to convert ascii to netcdf with the attached script, but not able to get the result. <div><br></div><div><br></div><div class="gmail_extra">regards<span class="m_-4707042885433198598gmail-HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_-4707042885433198598gmail-m_-8087913670056175393gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Kunal Bali</div><div><br></div><div><br></div><div><br></div><div><p style="margin:0px;border-collapse:collapse;font-family:Tahoma,Verdana;font-size:12px"><font color="#1F497D"><br></font></p></div></div></div></div></div></div>
<br></font></span><div class="gmail_quote"><span class="m_-4707042885433198598gmail-">On Mon, Nov 20, 2017 at 9:47 PM, Douglas Lowe <span dir="ltr"><<a href="mailto:Douglas.Lowe@manchester.ac.uk" target="_blank">Douglas.Lowe@manchester.ac.uk</a><wbr>></span> wrote:<br></span><div><div class="m_-4707042885433198598gmail-h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear Kunal Bali,<br>
<br>
It is definitely possible - the UK nation emissions data is provided in a similar csv text format to the file you attached, and I have previously converted this to netcdf format using NCL.<br>
<br>
You need to use the readAsciiHead function to read the header, and then the readAsciiTable function to read the table (using the parameters that you have gained from reading the header information). Once you have the data in a 2D array then it can be written into a netcdf file, after you've defined the file.<br>
<br>
My scripts wont be directly applicable to your task (as they also conversion of BNG coordinates to longitude & latitude coordinates), but if you would like to use them as a template to guide you in writing your scripts then email me, and I'd be happy to send you a copy.<br>
<br>
Regards,<br>
Doug<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Mon, 20 Nov 2017 21:13:08 +0530<br>
From: Kunal Bali <<a href="mailto:kunal.bali9@gmail.com" target="_blank">kunal.bali9@gmail.com</a>><br>
To: "<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>" <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br>
Subject: [ncl-talk] convert_to_netcdf<br>
Message-ID:<br>
<<a href="mailto:CAOiHCtRKsHCjTnje%2B28ntzjMObLiVt5j9U5Xst3DUrVQDjyWQg@mail.gmail.com" target="_blank">CAOiHCtRKsHCjTnje+28ntzjMObLi<wbr>Vt5j9U5Xst3DUrVQDjyWQg@mail.gm<wbr>ail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<div><div class="m_-4707042885433198598gmail-m_-8087913670056175393h5"><br>
Dear NCL users,<br>
<br>
Is it possible to convert attached .asc file format to netcdf? It seems<br>
like CDL format?<br>
<br>
Could anyone please let me know that?<br>
<br>
<br>
regards<br>
Kunal Bali<br>
</div></div>-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171120/9d8be42d/attachment.html" rel="noreferrer" target="_blank">http://mailman.ucar.edu/piper<wbr>mail/ncl-talk/attachments/2017<wbr>1120/9d8be42d/attachment.html</a>><br>
-------------- next part --------------<br>
ncols 241<br>
nrows 291<br>
xllcenter 91.33<br>
yllcenter 5.00<br>
cellsize 0.1<br>
NODATA_value -999<br>
133.0 136.0 138.0 141.0 144.0 147.0 150.0 152.0 155.0 157.0 159.0 162.0 164.0 167.0 159.0 147.0 135.0 123.0 111.0 98.0 86.0 84.0 81.0 79.0 76.0 74.0 71.0 70.0 70.0 70.0 71.0 71.0 72.0 72.0 84.0 101.0 118.0 134.0 151.0 168.0 185.0 197.0 209.0 222.0 234.0 246.0 258.0 266.0 266.0 266.0 266.0 265.0 265.0 265.0 254.0 237.0 221.0 204.0 188.0 171.0 155.0 156.0 158.0 160.0 161.0 163.0 164.0 165.0 162.0 159.0 156.0 153.0 150.0 147.0 144.0 140.0 137.0 133.0 130.0 126.0 123.0 120.0 117.0 114.0 111.0 ......<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br>
<br>
------------------------------<br>
<br>
End of ncl-talk Digest, Vol 168, Issue 44<br>
******************************<wbr>***********<br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div></div></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>