Re: netcdf to ascii

Hi,

short is a signed two byte (16 bit) integer. Notice however that you have got 
two
attributes called scale_factor and offset. To convert your integer data to a
floating point number you will need to do this:

OLR=data/100. + 327.65

eg. a data value of -10000 will covert to an OLR of 227.65 W/m^2

The reason for doing this is so that a floating point number can be represented 
as
a two byte integer (taking up half the space it would have taken if a four byte
float was used instead).

Slightly off the topic, I have attached a small script which makes use
of the NetCDF operators to quickly dump NetCDF data in ASCII format (it
also requires the GNU version of sed). You could use the program to
decode you data by doing something like this:

nctext -v OLR datafile.nc | awk \
 '{printf("%s\t%f\n",$0,$NF/100.+327.65)}' > datafile.txt

Tim.

On Wed, 23 Feb 2005 15:24:05 -0800
araligin@xxxxxxxxxxxxx wrote:

> 
> Hi,
> 
>   I am writing a fortran program to convert netcdf data to ASCII.
> my netcdf description for olr
>         short olr(time, lat, lon) ;
>                 olr:long_name = "Daily OLR" ;
>                 olr:valid_range = 0.f, 500.f ;
>                 olr:actual_range = 64.75f, 344.5f ;
>                 olr:units = "W/m^2" ;
>                 olr:add_offset = 327.65f ;
>                 olr:scale_factor = 0.01f ;
>                 olr:missing_value = 32766s ;
>                 olr:var_desc = "Outgoing Longwave Radiation" ;
>                 olr:precision = 2s ;
>                 olr:dataset = "NOAA Interpolated OLR" ;
>                 olr:level_desc = "Other" ;
>                 olr:statistic = "Mean" ;
>                 olr:parent_stat = "Individual Obs" ;
> 
> So I should read the olr values as integer (is that right). What does the 
> short
> mean? And also what does the precision = 2s mean. Because when i read i get 
> -ve
> values for the olr, but the valid range is 0.0 - 500.0.
> 
> Thanking you,
> Nilesh
> 


----Attachment: script to convert NetCDF data to an ASCII table -----
#!/bin/ksh
#
# This script prints a NetCDF variable in tabular format.
#
# Tim Hume.
# 31 August 2004.

export PATH=/bin:/usr/bin:/usr/local/bin:/arm/tph/bin

file=""
var=""

while [[ ${#*} -gt 0 ]]
do
        if [[ "${1}" == "-v" ]] || [[ "${1}" == "-V" ]]
        then
                var="${2:-""}"
                shift; shift
        else
                file="${1}"
                shift
        fi
done

if [[ "${file}" == "" ]] || [[ "$var}" == "" ]]
then
        echo "E: ${0##*/}> Must enter a file name and variable"
        exit 1
fi

if [[ ! -f ${file} ]]
then
        echo "E: ${0##*/}> No such file ${file}"
        exit 1
fi

ncks -H -C -v "${var}" "${file}" | sed -r \
        -e 's/\<[[:alnum:]][[:alnum:]_]*\[[[:digit:]]+\]=//g' \
        -e 's/[[:space:]]+/\t/g' -e '/^[[:space:]]*$/d'

  • 2005 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: