Re: Problem reading a Netcdf file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 7 Jul 2006 07:48:16 -0600 (MDT)

I speculate that the netCDF file "wspd.mon.mean.nc" was created by
the Climate Diagnostics Center [CDC]. Typically, CDC files
contain variables of type "short". If you do

ncdump -h wspd.mon.mean.nc [or ncl_filedump wspd.mon.mean.nc]

The output would indicate something like ....

      short wspd(time, level, lat, lon)
      ^^^^^

The attributes of the variable wspd will include

      wspd: add_offset =
      wspd: scale_factor =

If this is the case, the way to import the variable is with

      wspd = short2flt( f->wspd )

If the above does not solve the problem, please
send the output from the "ncdump -h" command.

Cheers

> I have had some problems while trying to read a Netcdf file. The problem
> is:
>
> 1) First, I created a file to read NCEP dataset (windspeed:
> wspd.mon.mean.nc), calculate the monthly mean and create a Netcdf file
> with these results. I have done that to prepare the file to another
> person who is going to use it later. This worked perfectly! However,
> when I write "print(variable)", I get values such as : -19892.56, for
> example. But, when I open the output netcdf file, the values are ok,
> that is, for example, 5.2 m/s.
>
> 2) I have now used the same file to calculate the 97.5% percentile of
> the dataset. This time, both the print() command and the netcdf output
> file give me values like -19892.56.
>
>
> Perhaps there is some kind of scaling factor that is not
> 'activated/used' when I try to read the dataset. Even if I just try to
> read the data without any calculation, I get the same numbers. It is the
> first time this has happened. For example, my files start like this:
>
> ;*************************************************
> ; This file is for making NetCDF files
> ;************************************************
> 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" ; for the
> dim_avg_Wrap
>
> ;************************************************
> begin
> ;************************************************
> ; read in netCDF file
> ;************************************************
>
> a = addfile("wspd.mon.mean.nc","r")
>
> ;************************************************
> ; read the data
> ;************************************************
> wind = a->wspd(:,:,:)
> print(wind(1,1,1))
>
> ------------------------------------------------------------------------
> -----------
> The print command is just to check that it is reading properly, but it
> gives me the wrong value, in this case: -19676. Why is that?
>
> Thanks,
>
> --michel
>
> ---------------------------------------------------------------------
> Michel dos Santos Mesquita
> MSc. in Geophysics - Climatology
> University of Bergen - Norway
>
> URL: <http://www.geocities.com/mmeclimate/>
> http://www.geocities.com/mmeclimate/ (Check out the Blog link!)
>
> "If nature were not beautiful, it would not be worth studying it.
> And life would not be worth living." - Henry Poincare
> ---------------------------------------------------------------------
>
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jul 07 2006 - 07:48:16 MDT

This archive was generated by hypermail 2.2.0 : Mon Jul 10 2006 - 09:18:19 MDT