Hi Colleen,
Mary talked about how you could call C or Fortran from NCL, but since
you say you have an 'overarching'
C program, presumably you are more interested in calling NCL from C.
For the purpose you describe,
ingesting data from a NetCDF file, there are several options:
1) There is a C API for NCL that allows you to submit NCL commands from
a C program. It would be
possible to do exactly what you want to do with it: read data directly
from an NetCDF file into your C program.
You may find that the interface is somewhat intimidating, but if you
persevere you could make it work.
It is documented at
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclApi.shtml
It requires that you link with libnclapi.a, which I believe is included
with the standard NCL distribution.
2) Use a 'system' call to invoke NCL with an appropriate script that
would read the NetCDF file and write the data
you are interested in to an intermediate ascii or binary file. Then
you could use C standard file I/O calls to
read the data from the intermediate file. You would probably need to
pass some arguments to your NCL script,
such as the NetCDF file name and the names and shapes of the variables
you want to extract. The newest,
not-yet-released version of NCL would let you do this directly via
command line arguments. Otherwise, you
can use a wrapper shell script to pass the arguments as environment
variables to NCL. Let Mary Haley know if
you would like to try the new version of NCL with the command line
arguments.
3) Use the NetCDF library calls directly: although this would require
learning something about the NetCDF
interface, this might actually be the simplest solution for your
situation.
Hope this helps,
-dave
On Sep 13, 2005, at 9:47 AM, Mary Haley wrote:
>
> On Tue, 13 Sep 2005, Colleen Henry wrote:
>
>> How do I use NCL code in a C program or vice versa? I have an
>> overarching C program to manipulate data, but I want to use NCL to
>> pull data from a netcdf file. Any help on how to "communicate"
>> between NCL and C either way would be appreciated.
>
> Hi Colleen,
>
> You can call C subroutines from NCL. It's not a trivial process, but
> there is an example at:
>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/
> NclExtend.shtml#Example_6
>
> The process is much easier if you have a Fortran program, because then
> you can add a couple of comment lines to your Fortran code, run WRAPIT,
> and you're set to go. So, if you have a Fortran equivalent of your
> code,
> I recommend this route. :-)
>
> Otherwise, if you have trouble with the above, drop me a personal
> email and I'll try to help.
>
> --Mary
>
>> ********************
>> Colleen Henry
>> Graduate Student
>> Department of Earth and Atmospheric Sciences
>> 550 Stadium Mall Dr.
>> Purdue University
>> West Lafayette, IN 47906
>> chenry@purdue.edu
> _______________________________________________
> ncl-talk mailing list
> ncl-talk@ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2b29 : Tue Sep 13 2005 - 15:15:19 MDT