Re: write station data into netCDF

From: Mark Chan <cym263_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 21 2012 - 15:08:39 MDT

Dear Dennis, The cdo developer suggested something as: ncatted -a coordinates,pwv,c,c,"lon lat" pw.nc Then cdo works fine for the pw.nc as: -------------cdo message------------------- -1 : Date Time Param Level Size Miss : Minimum Mean Maximum 1 : 0000-00-00 00:00:00 -1 0 32 0 : 22.400 41.981 50.400 cdo info: Processed 32 values from 1 variable over 1 timestep. ( 0.00s ) I used "ncdump" to compare data info before and after using "ncatted", nothing really changed, so I don't know what the "ncatted" did for the data file (pw.nc). I still wonder whether NCL can directly write in some info as "ncatted" did here. Thanks a lot! Mark ________________________________ From: Dennis Shea <shea_at_ucar.edu> To: Mark Chan <cym263_at_yahoo.com> Cc: NCL Helpline <ncl-talk_at_ucar.edu> Sent: Wednesday, March 21, 2012 2:05 PM Subject: Re: [ncl-talk] write station data into netCDF The netCDF file is a "correct" netCDF file. The reason why it 'still cannot be checked by "cdo"' is a CDO issue not an NCL issue. I think it would be best to send a question to the CDO help list. +++++++++++++++++++++++++++++++++++ I did add a Conventions attribute in the code appended. I checked for CF compliance at     http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl The file is CF-1.0 compliant. OUTPUT: File name:      pw.nc Output of CF-Checker follows... CHECKING NetCDF FILE: /tmp/19672.nc ===================== Using CF Checker Version 2.0.3 Using Standard Name Table Version 18 (2011-07-22T10:58:54Z) ------------------ Checking variable: lat ------------------ ------------------ Checking variable: pwv ------------------ ------------------ Checking variable: lon ------------------ ERRORS detected: 0 WARNINGS given: 0 INFORMATION messages: 0 ++++++++++++++++++++++++++++++++++++++++++++++++ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"   fname = "pw.dat"   lines = asciiread(fname,-1,"string")   id    = tochar(str_get_field(lines(1:),1," "))   id_dims = dimsizes(id)   id_len  = id_dims(1)   lat  = tofloat(str_get_field(lines(1:),2," "))   lon  = tofloat(str_get_field(lines(1:),3," "))   pwv  = tofloat(str_get_field(lines(1:),4," "))   delete(lines)   system("/bin/rm -f pw.nc")    ; rm any pre-exiting file   f_out = addfile("pw.nc", "c")   f_out_at_Conventions = "CF-1.0"   lat!0 = "npts"   lon!0 = "npts"   pwv!0 = "npts"   lat_at_long_name = "Latitude"   lat_at_units    = "degrees_north"   lon_at_long_name = "Longitude"   lon_at_units    = "degrees_east"   pwv_at_long_name = "temperature"   pwv_at_units    = "degC"   f_out->lat = lat   f_out->lon = lon   f_out->pwv = pwv On 3/21/12 2:29 AM, Mark Chan wrote: > Dear Mary, > > The below is the ncl script and data file. The created netCDF file > "pw.nc" still cannot be checked by "cdo". I think the data is the > typical station data (lat lon data_value). Can you give more suggestion > for making the correct netCDF file? > > Thanks a lot! > Mark > > ----------NCL script------------------- > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" > begin > fname = "pw.dat" > lines = asciiread(fname,-1,"string") > id = stringtochar(str_get_field(lines(1:),1," ")) > id_dims = dimsizes(id) > id_len = id_dims(1) > lat = stringtofloat(str_get_field(lines(1:),2," ")) > lon = stringtofloat(str_get_field(lines(1:),3," ")) > pwv = stringtofloat(str_get_field(lines(1:),4," ")) > delete(lines) > f_out = addfile("pw.nc", "c") > lat!0 = "npts" > lon!0 = "npts" > pwv!0 = "npts" > lat_at_long_name = "Latitude" > lat_at_units = "degrees_north" > lon_at_long_name = "Longitude" > lon_at_units = "degrees_east" > pwv_at_long_name = "temperature" > pwv_at_units = "degC" > f_out->lat = lat > f_out->lon = lon > f_out->pwv = pwv > end > > ----------data file "pw.dat"-------------- > ID LAT LON PW > BLAC 36.75 -97.25 48.00 > BREC 36.41 -97.69 46.30 > BURB 36.63 -96.81 49.80 > DQUA 34.11 -94.29 45.00 > FBYN 40.08 -97.31 38.20 > GUTH 35.85 -97.48 46.60 > HBRK 38.31 -97.29 34.30 > HKLO 35.68 -95.86 50.20 > JTNT 33.02 -100.98 39.80 > LMNO 36.69 -97.48 47.10 > LTHM 39.58 -94.17 40.40 > MEDF 36.79 -97.75 46.70 > NDS1 37.30 -95.60 39.90 > OILT 36.03 -96.50 48.80 > PRCO 34.98 -97.52 46.50 > REDR 36.36 -97.15 50.40 > RWDN 40.09 -100.65 26.40 > SA14 36.56 -100.61 22.40 > SG01 36.60 -97.49 49.00 > SG09 36.43 -98.28 43.20 > SG10 36.88 -98.29 41.40 > SG11 37.33 -99.31 33.60 > SG12 38.20 -99.32 33.90 > SG13 38.12 -97.51 36.30 > SG14 37.84 -97.02 40.20 > SG15 38.20 -95.59 31.70 > SG16 37.38 -96.18 42.80 > SG18 34.88 -98.20 45.90 > SG19 35.36 -98.98 45.30 > SG20 35.56 -98.02 47.90 > SG22 35.26 -97.48 46.80 > VCIO 36.07 -99.22 38.60 > > ----------cdo message --------------- > cdo info: Open failed on >pw.nc< > Unsupported file structure > > ----------ncdump message------------ > netcdf pw { > dimensions: > npts = 32 ; > variables: > float lat(npts) ; > lat:units = "degrees_north" ; > lat:long_name = "Latitude" ; > float lon(npts) ; > lon:units = "degrees_east" ; > lon:long_name = "Longitude" ; > float pwv(npts) ; > pwv:units = "degC" ; > pwv:long_name = "temperature" ; > data: > > lat = 36.75, 36.41, 36.63, 34.11, 40.08, 35.85, 38.31, 35.68, 33.02, 36.69, > 39.58, 36.79, 37.3, 36.03, 34.98, 36.36, 40.09, 36.56, 36.6, 36.43, > 36.88, 37.33, 38.2, 38.12, 37.84, 38.2, 37.38, 34.88, 35.36, 35.56, > 35.26, 36.07 ; > > lon = -97.25, -97.69, -96.81, -94.29, -97.31, -97.48, -97.29, -95.86, > -100.98, -97.48, -94.17, -97.75, -95.6, -96.5, -97.52, -97.15, -100.65, > -100.61, -97.49, -98.28, -98.29, -99.31, -99.32, -97.51, -97.02, -95.59, > -96.18, -98.2, -98.98, -98.02, -97.48, -99.22 ; > > pwv = 48, 46.3, 49.8, 45, 38.2, 46.6, 34.3, 50.2, 39.8, 47.1, 40.4, 46.7, > 39.9, 48.8, 46.5, 50.4, 26.4, 22.4, 49, 43.2, 41.4, 33.6, 33.9, 36.3, > 40.2, 31.7, 42.8, 45.9, 45.3, 47.9, 46.8, 38.6 ; > > > > ------------------------------------------------------------------------ > *From:* Mary Haley <haley_at_ucar.edu> > *To:* Mark Chan <cym263_at_yahoo.com> > *Cc:* 李嘉鹏 <lijpbasin_at_126.com>; NCL Helpline <ncl-talk_at_ucar.edu> > *Sent:* Tuesday, March 20, 2012 4:50 PM > *Subject:* Re: [ncl-talk] write station data into netCDF > > Mark, > > You are trying to write your variables out as if lat and lon are > coordinate arrays of "pwv". If pwv were 2-dimensional, say 64 x 128, and > you had a latitude array that was 64 elements, and a longitude array > that was 128, *then* you could write out "pwv" with coordinate arrays > "lat" and "lon". > > What you have, however, is 1-dimensional data, each with the same number > of points. This is an unstructured grid, and can't be represented by > coordinate arrays. > > You could write out the values with something like: > > f_out = addfile("pw.nc <http://pw.nc>", "c") > lat!0 = "npts" > lon!0 = "npts" > pwv!0 = "npts" > > lat_at_long_name = "Latitude" > lat_at_units = "degrees_north" > lon_at_long_name = "Longitude" > lon_at_units = "degrees_east" > > f_out->lat = lat > f_out->lon = lon > f_out->pwv = pwv > > > Note that you should also add "long_name" and "units" to "pwv" to > provide more information about this variable. > > --Mary > > > > > > _______________________________________________ > ncl-talk mailing list > List instructions, subscriber options, unsubscribe: > http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 21 15:08:50 2012

This archive was generated by hypermail 2.1.8 : Tue Mar 27 2012 - 08:50:24 MDT