[Thread Prev][Thread Next][Index]

Re: [ferret_users] How to check whether the attribute is defined in dataset or not, and how to save all global attributes in variable/array

Hi Akshay,

This sounds like a good topic for an FAQ.

The IS_ELEMENT_OF functions can help you here.  

yes? let attnames = var.attnames
yes? let gattnames = ..attanmes

yes? if `IS_ELEMENT_OF_STR(attnames, "the_att") NE 0` THEN


While I'm mentioning these functions, there are a couple of useful "element_index" functions as well for working with lists, either strings or not.

yes? show function element_index*



On Thu, May 11, 2017 at 5:51 AM, Akshay Hegde <akshay.k.hegde@xxxxxxxxx> wrote:
1. Is it possible to save the output of show attr/all . to some variable like let foo = ..varnames 
How to check whether the attribute is defined in dataset (Global attributes) or not.

For Example :

As you can see below attribute history exists in dataset, so it doesn't throw any exception, but say if I type list  ..someother_attr, I get error since it doesn't exist, so is there any way to check whether attribute exists in dataset.

yes? use coads_climatology;
yes? show d
     currently SET data sets:
    1> /usr/local/ferret/fer_dsets/data/coads_climatology.cdf  (default)
 name     title                             I         J         K         L         M         N
 SST      SEA SURFACE TEMPERATURE          1:180     1:90      ...       1:12      ...       ...
 AIRT     AIR TEMPERATURE                  1:180     1:90      ...       1:12      ...       ...
 SPEH     SPECIFIC HUMIDITY                1:180     1:90      ...       1:12      ...       ...
 WSPD     WIND SPEED                       1:180     1:90      ...       1:12      ...       ...
 UWND     ZONAL WIND                       1:180     1:90      ...       1:12      ...       ...
 VWND     MERIDIONAL WIND                  1:180     1:90      ...       1:12      ...       ...
 SLP      SEA LEVEL PRESSURE               1:180     1:90      ...       1:12      ...       ...
yes? show att/all .
     attributes for dataset: /usr/local/ferret/fer_dsets/data/coads_climatology.cdf
 ..history = FERRET V4.45 (GUI) 22-May-97
yes? list ..history
             VARIABLE : ..HISTORY
             FILENAME : coads_climatology.cdf
             FILEPATH : /usr/local/ferret/fer_dsets/data/
             X        : 1
        "FERRET V4.45 (GUI) 22-May-97"
yes? list ..someother_attr
 **ERROR: attribute undefined or invalid attribute name: ..SOMEOTHER_ATTR
          attribute SOMEOTHER_ATTR not found for dataset
 **ERROR: variable unknown or not in data set: ..SOMEOTHER_ATTR

I can check from outside using spawn like below

[akshay@localhost tmp]$  ncdump -h /usr/local/ferret/fer_dsets/data/coads_climatology.cdf | grep -q ':something'  && echo 'exists' || echo 'does not exist';
does not exist

[akshay@localhost tmp]$  ncdump -h /usr/local/ferret/fer_dsets/data/coads_climatology.cdf | grep -q ':history'  && echo 'exists' || echo 'does not exist';

Thank you.

Akshay Hegde,
Data and Information,

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement