Re: Changing variables/parameters of a file from double to float

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Fri Nov 29 2013 - 13:55:13 MST

Rashed,

It is not a legal operation to change the data type of an existing variable
in a Netcdf file. Netcdf user's guide, last comprehensive version, section
2.4:

   "... the netCDF interface provides no way to delete
  a variable or to change its type or shape."

http://www.unidata.ucar.edu/software/netcdf/docs/netcdf.html#Attributes

To accomplish what you want, you need to copy the original file to a new
file, and make the necessary changes in the middle of the copy while
variables are in NCL memory. This is non-trivial. There might be an
external utility program that can do this more easily, but I do not
currently know of one.

Instead of changing the data file, I recommend that you upgrade application
programs that read this file so that they can handle coordinates of any
numeric type. Use generic functions such as NCL's "todouble" or "tofloat"
to facilitate this. HTH.

--Dave

On Fri, Nov 29, 2013 at 12:21 PM, Rashed Mahmood <rashidcomsis@gmail.com>
wrote:
>
> Hi all,
>
> I am trying to change lon, lat and lev parameters of a file from double
to float. I have written simple ncl script that can run but the result is
not as desired, NCL is not replacing the actual parameters instead adding
three extra parameters named as ncl4, ncl5, ncl6 as can be seen in ncdump
of the modified file below. I am using NCL 6.1.2.
>
> Any suggestions?
>
> 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/contributed.ncl"
> begin
>
> a = addfile("/home/rrm/khan/airc_data/test_airc/test_3/
eclipse.mmrbc.2008.nc","w")
>
> lon1 = a->lon
> lon2=doubletofloat(lon1) ;for lon
>
> a->lon=lon2
>
> ;++++++++++++++++++++++++++++++
> lat1 = a->lat
> lat2=doubletofloat(lat1) ; for lat
>
> a->lat=lat2
> ;++++++++++++++++++++++++++++++
> lev1 = a->lev
> lev2=doubletofloat(lev1) ; for lev
>
> a->lev=lev2
>
> end
>
>
>
> rrm:lx25:Linux>ncdump -h eclipse.mmrbc.2008.nc
> netcdf eclipse.CanAM46.3hourly.mmrbc.2008 {
> dimensions:
> time = UNLIMITED ; // (2920 currently)
> lon = 128 ;
> lat = 64 ;
> lev = 49 ;
> ncl4 = 128 ;
> ncl5 = 64 ;
> ncl6 = 49 ;
>
> variables:
> double time(time) ;
> time:long_name = "time" ;
> time:units = "days since 1850-1-1" ;
> time:calendar = "365_day" ;
> double lon(lon) ;
> lon:long_name = "Longitude" ;
> lon:units = "degrees_east" ;
> lon:standard_name = "longitude" ;
> double lat(lat) ;
> lat:long_name = "Latitude" ;
> lat:units = "degrees_north" ;
> lat:standard_name = "latitude" ;
> double lev(lev) ;
> lev:long_name = "Hybrid Sigma Pressure Level" ;
> lev:units = "1" ;
> lev:standard_name =
"atmosphere_hybrid_sigma_pressure_coordinate" ;
> lev:positive = "down" ;
> lev:formula = "p = ap + b*ps" ;
> lev:formula_terms = "ap: ap b: b ps: ps" ;
> double ap(lev) ;
> double b(lev) ;
> double ps(time, lat, lon) ;
> ps:long_name = "Surface Pressure" ;
> ps:units = "Pa" ;
> ps:standard_name = "surface_air_pressure" ;
> float mmrbc(time, lev, lat, lon) ;
> mmrbc:long_name = "Mass Fraction of Black Carbon" ;
> mmrbc:standard_name =
"mass_fraction_of_black_carbon_dry_aerosol_in_air" ;
> mmrbc:units = "kg kg-1" ;
> mmrbc:_FillValue = 1.e+38f ;

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Nov 29 13:55:21 2013

This archive was generated by hypermail 2.1.8 : Wed Dec 04 2013 - 20:42:38 MST