[Thread Prev][Thread Next][Index]

Re: [ferret_users] Query about string function



Hi,
Yes. You can do this using the "varnames" attribute keyword. 
http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/variables-xpressions/VARIABLES#_VPINDEXENTRY_attrib_keywords

This gets a list of the variable names in the current dataset:
yes? use my_data.nc
yes? let vnames = ..varnames

! Now vnames is a string variable containing the list of variable names in the dataset.
! Use IS_ELEMENT_OF_STR to determine whether a given variable is in the file:

yes? let has_foo1 = is_element_of_str (vnames, "Var_foo_1")
yes? let has_foo2 = is_element_of_str (vnames, "Var_foo_2")
yes? let has_foo3 = is_element_of_str (vnames, "Var_foo_3")

yes? if `has_foo1 EQ  1`  then
... commands using var_foo_1

Note that there are two versions of IS_ELEMENT_OF_STR;  one that matches the case of the names and a second that is case-insensitive:

yes? show functions is_element_of_str*


On 6/23/2013 6:10 AM, Akshay Hegde wrote:
Dear Developers

Is there any function to check variable name is exist  or not in Netcdf file ?

Assume 100 netcdf file are there in directory, each file contains 3 variables say

Var_foo_1
Var_foo_2
Var_foo_3

and you just want to list them using loop for that syntax would be something like below


let ii=0
repeat/range=1:100 ( let ii=`ii+1`; use file_`ii`; list/file=dummy Var_foo_1,Var_foo_2,Var_foo_3)

if suppose 95 file contains all 3 variable and 96th file contains only 2 variables then obviously you will receive error msg saying variable does not exist, in order to skip such files some provision is needed otherwise loop will not continue. please let me know if such string functions are available in ferret or any other alternate solution.


Akshay Hegde,
National Institute of Oceanography,
Dona Paula, Panjim, Goa
 


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

Privacy Policy | Disclaimer | Accessibility Statement