|
Re: Retrieving variables from a subroutine [message #52615 is a reply to message #52612] |
Tue, 20 February 2007 08:51  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Andy Heaps wrote:
>
> I've written some IDL code to retrieve all the variables from a NetCDF
> file. This takes the form of:
> ncopen, 'file.nc'
> @ncread
>
> where the ncopen routine opens up the NetCDF file and writes all the
> variable information into a set of system strings in a !variable. The
> batch file statement @ncread then accesses these strings to read the
> data so all the variables are available from within the calling routine.
>
> This process is the only way I could think of to get the variables to
> appear in the calling procedure without having the NetCDF code directly
> in the user's program. Although this works, I cannot help thinking this
> is not the most elegant way of doing the job. I'd certainly like to
> just have one command to do the job, rather than two, if at all possible.
>
> As this program is for the use of undergrad students I don't want to use
> structures as they'll think IDL is very complicated and we all know that
> that isn't the case ;-) One of the ideas I had was to somehow get the
> returning ncopen procedure to call @ncread but I cannot think of a way
> to do that.
>
> Does anyone know of any IDL magic that could be used to have a single
> procedural (or other) call, and then somehow end up with the NetCDF
> variables extracted back in the the calling procedure?
I have a function to read netcdf files. See:
http://tinyurl.com/3apa9f
cheers,
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
|
|
|
Re: Retrieving variables from a subroutine [message #52629 is a reply to message #52615] |
Mon, 19 February 2007 07:22  |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <ercbpk$res$1@south.jnrs.ja.net>,
Andy Heaps <a.j.heaps@reading.ac.uk> wrote:
> Does anyone know of any IDL magic that could be used to have a single
> procedural (or other) call, and then somehow end up with the NetCDF
> variables extracted back in the the calling procedure?
I think structures really are the best way to do this. I generally
use a function rather than a procedure, so it is called like this
data = READ_SAT_DAT(input)
where input is a file name or date, depending on the application.
READ_SAT_DATA packages all of the info from the file into an
anonymous structure.
It is not too difficult to get undergrads to understand, for example,
that
data.longitude
contains the longitudes of the satellite fields of view,
data.values
contains the radiances or retrieved quantities, etc.
The structure makes it easy to include the data and all of the
ancillary information (units, long names, etc.) in a single package.
Ken Bowman
|
|
|
Re: Retrieving variables from a subroutine [message #52631 is a reply to message #52629] |
Mon, 19 February 2007 07:23  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Andy Heaps writes:
> Does anyone know of any IDL magic that could be used to have a single
> procedural (or other) call, and then somehow end up with the NetCDF
> variables extracted back in the the calling procedure?
Well, SCOPE_VARFETCH is always magic if you can figure
out the crappy documentation. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|