[ncl-talk] convert_to_netcdf
Kunal Bali
kunal.bali9 at gmail.com
Tue Nov 21 22:55:45 MST 2017
I tried to convert ascii format (attached previous mail) to netcdf by the
script given below.
The script is generating the netcdf file but the lat lon dimensions did not
correctly assign.
please let me know how to correct this script.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
nLatitude = 241
nLongitude = 291
data =
asciiread("/Users/Pushp/Desktop/COD_NEW/PM2.5/in.txt",(/nLatitude*nLongitude/),"float")
printVarSummary(data)
Latitude = data(:nLatitude-1)
Longitude = data(:nLongitude-1)
printVarSummary(Latitude )
printVarSummary(Longitude)
CF = data(:)
CF2D = onedtond(CF,(/nLatitude,nLongitude/))
printVarSummary(CF2D)
if (any(isnan_ieee(CF2D))) then
value = 1.e20
replace_ieeenan (CF2D, value, 0)
CF2D at _FillValue = value
end if
; printMinMax(Latitude,0)
; printMinMax(Longitude,0)
printMinMax(CF2D,0)
; Assign named dimensions
CF2D!0 = "lat"
CF2D!1 = "lon"
; Assign coordinate variables
CF2D&lat = Latitude
CF2D&lon = Longitude
CF2D&lat at units = "degrees_north"
CF2D&lon at units = "degrees_east"
printVarSummary(CF)
; delete existing netcdf file to create a new one
system("rm -rf test.nc")
ncdf = addfile("/Users/Pushp/Desktop/COD_NEW/PM2.5/test.nc","c")
; write data to netcdf file
ncdf->CF = CF2D
end
regards
Kunal Bali
On Tue, Nov 21, 2017 at 6:29 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:
> I tried to convert ascii to netcdf with the attached script, but not able
> to get the result.
>
>
> regards
> Kunal Bali
>
>
>
>
>
> On Mon, Nov 20, 2017 at 9:47 PM, Douglas Lowe <
> Douglas.Lowe at manchester.ac.uk> wrote:
>
>> Dear Kunal Bali,
>>
>> 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.
>>
>> 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.
>>
>> 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.
>>
>> Regards,
>> Doug
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Mon, 20 Nov 2017 21:13:08 +0530
>> From: Kunal Bali <kunal.bali9 at gmail.com>
>> To: "ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
>> Subject: [ncl-talk] convert_to_netcdf
>> Message-ID:
>> <CAOiHCtRKsHCjTnje+28ntzjMObLiVt5j9U5Xst3DUrVQDjyWQg at mail.
>> gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Dear NCL users,
>>
>> Is it possible to convert attached .asc file format to netcdf? It seems
>> like CDL format?
>>
>> Could anyone please let me know that?
>>
>>
>> regards
>> Kunal Bali
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/
>> 20171120/9d8be42d/attachment.html>
>> -------------- next part --------------
>> ncols 241
>> nrows 291
>> xllcenter 91.33
>> yllcenter 5.00
>> cellsize 0.1
>> NODATA_value -999
>> 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 ......
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> ------------------------------
>>
>> End of ncl-talk Digest, Vol 168, Issue 44
>> *****************************************
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171122/fbd64115/attachment.html>
More information about the ncl-talk
mailing list