Re: [netcdfgroup] Subsetting data with C++ API calls

  • To: Pedro Vicente <pvicente@xxxxxxx>
  • Subject: Re: [netcdfgroup] Subsetting data with C++ API calls
  • From: Dennis Heimbigner <dmh@xxxxxxxxxxxxxxxx>
  • Date: Fri, 08 Mar 2013 10:11:39 -0700
I must disagree. Writing libraries in C is a far
better solution than C++ primarily because
almost all programming languages systems
(Java, Python, etc) can access C functions
but few can access C++ because of the name mangling
issues.

=Dennis Heimbigner
 Unidata

Pedro Vicente wrote:

Hi

It is an excellent suggestion, that I also follow.

Both netCDF and HDF5 are written in C, and both have C++ "wrappers", that are just C++ classes that call the C API.

Over the years I have written programs that use the netCDF/HDF5 libraries, either in C, like h5diff, or C++, like h5merge. h5merge re-does much of h5diff in a C++ way.

h5diff was written in 2003, and at the time it did not occur to me (and probably to nobody else at the then NCSA HDF Group), that it might
as well be written in C++.

Advantages of writing a C++ program that uses the C APIs:

1) C++ is a much more powerful language than C.

2) It has libraries like STL (Standard Template Libraries), that provide data structures like vectors, lists, maps.

http://www.cplusplus.com/reference/stl/


3) The C++ "wrappers" just add another layer of functions with the same name as the underlying API.

If what they only do is to call the C API, why not do that myself in my program, avoiding that extra layer of functions that I don't need?

4) The C++ wrappers offer only a subset of the C API. Some functions that are sometimes needed are not available.



Pedro

------
Pedro Vicente, Earth System Science
University of California, Irvine
http://www.ess.uci.edu/



----- Original Message ----- From: Taylor Binnington
To: Lynnes, Christopher S. (GSFC-6102)
Cc: netcdfgroup
Sent: Thursday, March 07, 2013 6:31 PM
Subject: Re: [netcdfgroup] Subsetting data with C++ API calls


Thank you, that's an excellent suggestion Christopher. I've spent the past few days using the regular C libraries with much more success, and minimal bandwidth usage. I didn't really realize how simple that could be until I tried: I had just assumed that if I wanted to program C++, I would have to use those libraries.
Thanks again!



----- Original Message ----- From: "Lynnes, Christopher S. (GSFC-6102)" <christopher.s.lynnes@xxxxxxxx>
To: "Taylor Binnington" <tbinnington@xxxxxxxxx>
Cc: "netcdfgroup" <netcdfgroup@xxxxxxxxxxxxxxxx>
Sent: Sunday, March 03, 2013 4:18 PM
Subject: Re: [netcdfgroup] Subsetting data with C++ API calls


Taylor,
I can't help thinking that the C++ library you are using seems a little more brittle than the C route at this phase in its evolution. Have you considered making calls to the C API from your C++ call? THe methods for extracting subsets of variables are quite clear in the C API...

On Mar 3, 2013, at 4:34 PM, Taylor Binnington <tbinnington@xxxxxxxxx> wrote:

Hello,

I'm attempting to read only certain parts (specific indices of specific variable arrays), remotely, from a MERRA HDFEOS file.

I've recently upgraded to NetCDF 4.2.1.1, using Lynton's C++ library. At first, I was using trying to subset the data directly from an OPeNDAP URL supplied to NcFile, but it's been suggested to me, by an earlier post in the OPeNDAP forums, that this is not a good way to go. Instead, I should use NetCDF API calls.

I have carefully read through the C++ interface guide, including this example:

http://www.unidata.ucar.edu/software/netcdf/docs/cxx4/test_var_8cpp-example.html

but am struggling to understand how to do this. A push in the right direction would be very appreciated. The example (I don't fully understand it, but was trying to emulate some of the example that I linked above)

#include <iostream>
#include <netcdf>
int main() {
NcFile dataFile("http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1991/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19910101.hdf";, NcFile::read);
NcGroup grouptest(dataFile.addGroup("Dataset"));
}

gives me the error:

terminate called after throwing an instance of 'netCDF::exceptions::NcNotNc4'
  what():  NcNotNc4: Attempting netcdf-4 operation on netcdf-3 file.
file: ncGroup.cpp  line:265
Aborted

This is not surprising, since the file is not a NetCDF-3 file.

Thank you in advance.
Taylor

--
Taylor Binnington
e. tbinnington@xxxxxxxxx

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/

--
Dr. Christopher Lynnes, NASA/GSFC, ph: 301-614-5185



_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



  • 2013 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: