[Thread Prev][Thread Next][Index]

Re: query for variable presence in a dataset




Keith Lindsay wrote:

> Hello,
>
> Is there a way in ferret to determine if a variable is present or absent
> in a dataset? I am building a journal script to automatically generate a
> suite of plots from model output. However, sometimes diagnostic XYZ is
> present and sometimes it is not. I'd like to have the journal script do
> something like "if var_present(XYZ) then plot XYZ". Is this possible?
>
> Thanks, Keith

Hi Keith,

Below is a way to achieve this.  Ferret V5.5 will offer this capability much
more directly as the string variables will be extended to embrace attributes
(as per netCDF) and variable names.

The method uses the fact that LET/D defines a default variable -- a
definition to be used only when another ("real") definition is not
available.  Here is a sample session which should run on your system:

     yes? use coads_climatology   ! has variable "SST" but not "SST2"
     yes? let/d sst2 = 0
     yes? let/d sst = 0
     yes? define symbol sst_exists `sst,return=shape`
      !-> define symbol sst_exists XYT
     yes? define symbol sst2_exists `sst2,return=shape`
      !-> define symbol sst2_exists POINT
     yes? if ($sst2_exists"|POINT>0|*>1") then say yup else say nope
      !-> if 0 then say yup else say nope
     nope
     yes? if ($sst_exists"|POINT>0|*>1") then say yup else say nope
      !-> if 1 then say yup else say nope
     yup

    - steve




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement