comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » how to search if a variable exists in a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: how to search if a variable exists in a file [message #92006 is a reply to message #92003] Tue, 29 September 2015 12:05 Go to previous messageGo to previous message
Xiaohua Pan is currently offline  Xiaohua Pan
Messages: 2
Registered: September 2015
Junior Member
On Monday, September 28, 2015 at 7:25:32 PM UTC-4, David Fanning wrote:
> Xiaohua Pan writes:
>
>> I am dealing with a set of stations which unfortunately contain
> different variables (netcdf formate). For example, Some stations have
> the variables, say 'temperature' and 'pressure', while some stations
> only have 'temperature'. When I read data with DO loop the stations, I
> would like to search the variable first, so I can skip those variables
> not existing to avoid the crash of program. I found a function of
> file_search(), but can't find a similar function for a variable. Is
> there anyone know how to do it? Thanks.
>>
>> DO i_station = 0, n-1 do begin
>> DO i_var = 0, 1 do begin
>> ; How to skip the variable if it doesn't exit ????
>> ENDFOR
>> ENDFOR
>
> If you were to use the netCDF programs in the Coyote Library to work
> with your netCDF files, you could use the method HasVar to tell you if a
> file contains a variable with a particular name:
>
> http://www.idlcoyote.com/fileio_tips/ncdf_browser.html
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Hi David,
It works. Thank you so much!
Xiaohua

For those who may need this information as well,
here is an example:

filename = 'data.nc'
var_name = 'sst'
ncdfObj = Obj_New('NCDF_FILE', filename)
hasVar = ncdfObj -> HasVar(var_name, OBJECT=varObj)
IF hasVar THEN BEGIN
print, ' find the variable ' + var_name
ENDIF ELSE BEGIN
print, " Can't find the variable "+var_name
ENDELSE
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PLOT and LEGEND Function Graphic
Next Topic: Job Posting: Computer Research Specialist / Research Software Engineer / University of Florida

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:12:51 PDT 2025

Total time taken to generate the page: 0.00420 seconds