Re: Why Ncl can not deal with these variable names?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue, 26 Dec 2006 15:23:54 -0700 (MST)

> Hi,
> I'm dealing with a .cdf file from NOAA ftp(attached to this
> mail) which contain some
> variables. The names of variables are just like
> "Pac_ssta_coral.ssta","Pac_ssta_tree.ssta",
> and it seem that NCL can not work well with them. Another
> software,Grads, also can not
> work on these variables. And I think that it is caused by the
> variable names.
> Can NCl modify these variable names to some shorter ones? If
> not, Which software
> can do that in a simple way? Thanks!
> Lin

   [Note: the original posting of this message didn't make it to
    ncl-talk because there was too large of an attachment. However, I'm
    sending the response back to the group so they can benefit.]

Hi Lin,

As you pointed out, NCL can't deal with the variable name
"Pac_ssta_tree.ssta", and this is because there's a period in the
name. Unfortunately, a period is one of those characters you can't
have in an NCL variable name, see:

However, there is a way around this when dealing with variable names
on a supported file. You can assign the name of the netCDF variable
to a NCL local variable, and then use a combination of the $...$
syntax and the local variable to retrieve the data:

   a = addfile("data.cdf","r")
   s = "Pac_ssta_tree.ssta"
   x = a->$s$

You can also use this in conjunction with "getfilevarnames":

   a = addfile("data.cdf","r")
   vars = getfilevarnames()
   nvars = dimsizes(vars)

   do i=0,nvars-1
     x = a->$s(i)$
     ...maybe do stuff with x...
   end do


ncl-talk mailing list
Received on Tue Dec 26 2006 - 15:23:54 MST

This archive was generated by hypermail 2.2.0 : Thu Dec 28 2006 - 09:40:18 MST