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@long_name = "Latitude"
lat@units = "degrees_north"
lon@long_name = "Longitude"
lon@units = "degrees_east"
pwv@long_name = "temperature"
pwv@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@ucar.edu>
To: Mark Chan <cym263@yahoo.com>
Cc: 李嘉鹏 <lijpbasin@126.com>; NCL Helpline <ncl-talk@ucar.edu>
Sent: Tuesday, March 20, 2012 4:50 PM
Subject: Re: 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", "c")
lat!0 = "npts"
lon!0 = "npts"
pwv!0 = "npts"
lat@long_name = "Latitude"
lat@units = "degrees_north"
lon@long_name = "Longitude"
lon@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
Received on Wed Mar 21 02:29:19 2012
This archive was generated by hypermail 2.1.8 : Tue Mar 27 2012 - 08:50:24 MDT