Re: [netcdfgroup] Reading MERRA HDF-EOS data with NetCDF C++ libraries

  • To: Taylor Binnington <tbinnington@xxxxxxxxx>
  • Subject: Re: [netcdfgroup] Reading MERRA HDF-EOS data with NetCDF C++ libraries
  • From: Roy Mendelssohn - NOAA Federal <roy.mendelssohn@xxxxxxxx>
  • Date: Sat, 19 Jan 2013 09:41:05 -0800
Hi Taylor:

When you go to the Hyrax server you mentioned, there are different services 
that are provided.  One is called the "http" service, which literally downloads 
the listed file.  That service downloads an hdf file that we have already 
determined can't be read by the netcdf libraries.

The second service is the OpeNDAP service.  That is the service used by the 
netcdf libraries for remote access of a dataset, and which through the OpeNDAP 
service makes the remote file "look" like a netcdf file, even though it isn't.  
To access the file through this service, the URL must be that of the OPeNDAP 
service.  If you are unsure of the URL for the service, if you go to the html 
page that I pointed you to, at the top is a box that gives you the base URL for 
the OPeNDAP service.  I did not point you there because you had to go there 
everytime, but for you to put the correct URL.  In fact, if you want a subset, 
you can select that in HTML page, but instead of downloading the file copy the 
URL and use it in your program.

The key point is the URL I sent is the base URL for the OPeNDaP service, while 
the URL you are using is the base URL for the http service.  If you want to use 
remote access in the netcdf libraries, you need to use the OPeNDAP URL.  That 
access will in fact download anOPeNDAP binary, but that is irrelevant - with 
the proper calls you program will act as if the file were a netcdf file on your 
computer. 

You are trying to use a number of technologies that do take some time and 
effort to learn and to learn how they interact with one another.  The netcdf 
libraries and the netcdf docs have some examples of using OPeNDAP to access 
remote files, and you might go through those, make certain you have code that 
works with those, and that you understand what is going on in the code.  

-Roy

On Jan 19, 2013, at 9:01 AM, Taylor Binnington <tbinnington@xxxxxxxxx> wrote:

> Thank you very much Roy. Let me see if I understand you correctly.
> 
> You are proposing that I insert the hyrax/ directory into the URL for an 
> OPeNDAP response. If I point my browser to either of the following URLs
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf
> 
> then the HDF file is downloaded. I understand that appending .html takes me 
> to a page where I can specify some options, subset, click on 'Get as NetCDF' 
> (equivalent to appending .nc instead of .html, I believe) or 'Binary (DAP) 
> Object (equivalent to appending .dods), etc. I could also bypass this step by 
> incorporating my constraint into the URL, for example
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf?XDim_EOSGRID[10:20]
> 
> gets me some arbitrary subset of the data, in HDF format, stored on my 
> computer.
> 
> But I would like to know if I can remotely open such a file for reading (with 
> or without including subsetting constraints in the URL itself) using my 
> simple test.cpp script, included in my initial post. None of the three URLs 
> included here are successful (meaning that my little test.cpp returns 
> "Failed" in each case). I get the same "Failed" when I append .nc or .dods to 
> the URL, with or without including the hyrax/ subdirectory in the path.
> 
> Can I modify the line in test.cpp,
> 
> NcFile dataFile 
> ("http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf";,
>  NcFile::ReadOnly);
> 
> to achieve what I am trying to do? Thank you in advance.
> Taylor
> 
> 
> On Fri, Jan 18, 2013 at 7:50 PM, Roy Mendelssohn - NOAA Federal 
> <roy.mendelssohn@xxxxxxxx> wrote:
> Hi Taylor:
> 
> Having a reproducible example helps.  I believe the URL you are using will 
> use the http service, which will indeed downlaod the HDF file.  For the 
> OpeNDAP response using instead  (i didn't check that we are pointing at the 
> same file):
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf
> 
> The way I got this is from:
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1979/01/contents.html
> 
> I asked for the html response, which takes me to a page that will show be the 
> URL for an OPeNDAP request among other things, that is to the page:
> 
> http://goldsmr2.sci.gsfc.nasa.gov/opendap/hyrax/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf.html
> 
> If you only want part of the file, you can include the constraints in the URL.
> 
> HTH.
> 
> -Roy
> On Jan 18, 2013, at 3:59 PM, Taylor Binnington <tbinnington@xxxxxxxxx> wrote:
> 
> > Hello (again),
> > I have netcdf-4.2.1-13.2 libraries installed on my openSUSE 12.1 machine. I 
> > am trying to open a MERRA data file from within a C++ program, using 
> > OPeNDAP.
> >
> > A sample test.cpp program is below, which I compile using g++ test.cpp 
> > -lnetcdf_c++ ,
> >
> > #include<iostream>
> > #include<netcdfcpp.h>
> > int main()
> > {
> >    NcFile dataFile 
> > ("http://goldsmr2.sci.gsfc.nasa.gov/opendap/MERRA/MAT1NXSLV.5.2.0/1979/01/MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf";,
> >  NcFile::ReadOnly);
> >
> >    if(!dataFile.is_valid()){
> >       cout << "Failed" << endl;
> >       return 2;}
> >    cout << "Okay" << endl;
> >    return 0;
> > }
> >
> > returns "Failed". Opening the local file 
> > MERRA100.prod.assim.tavg1_2d_slv_Nx.19790101.hdf.nc (obtained by converting 
> > to *.nc from the same OPeNDAP server, as was recommended to me in this 
> > post: 
> > https://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2013/msg00008.html)
> >  returns "Okay". Material here 
> > (http://www.hdfeos.org/workshops/ws13/presentations/day3/PRACTICAL_METHODS_FOR_MAKING_HDF_DATA_USABLE.pdf,
> >  beginning on page 24) leads me to believe that I simply can not use NetCDF 
> > libraries to open MERRA files with OPeNDAP.
> >
> > How, if possible, can I modify test.cpp to remotely open a MERRA data file, 
> > without having to first download it to my computer? Thank you for any help.
> >
> > P.S. Please do not think that I have ignored earlier replies (I appreciate 
> > them!), I've spent quite a lot of time on this recently.
> >
> >
> >
> > --
> > Taylor Binnington
> > e. tbinnington@xxxxxxxxx
> >
> > _______________________________________________
> > netcdfgroup mailing list
> > netcdfgroup@xxxxxxxxxxxxxxxx
> > For list information or to unsubscribe,  visit: 
> > http://www.unidata.ucar.edu/mailing_lists/
> 
> **********************
> "The contents of this message do not reflect any position of the U.S. 
> Government or NOAA."
> **********************
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> 1352 Lighthouse Avenue
> Pacific Grove, CA 93950-2097
> 
> e-mail: Roy.Mendelssohn@xxxxxxxx (Note new e-mail address)
> voice: (831)-648-9029
> fax: (831)-648-8440
> www: http://www.pfeg.noaa.gov/
> 
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
> 
> 
> 
> 
> -- 
> Taylor Binnington
> e. tbinnington@xxxxxxxxx
> 

**********************
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn@xxxxxxxx (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.



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