Hi Johanna, > Hi, > > I am trying to open netCDF files containing > 8*37*144*288 dimensional variables. But I keep getting segmentation fault. > I think this is because of the fact that the files are rather big and are > being put in the stack. I want to put them in the heap but I can't seem to > figure out how. Since NcVar is a private I can't use new. > > Do you know how my issue can be resolved? If you're going to try to read all the values of a netCDF variable on disk into memory, you need to allocate memory into which the values will be read. The code shown below just tries to read all the data into space pointed to by an uninitialized pointer. There are some example programs that use the netCDF C++ interface here: http://www.unidata.ucar.edu/netcdf/examples/programs/index.html I think the example that's closest to what you want is sfc_pres_temp_rd.cpp or pres_temp_4D_wr.cpp. I hope that helps. --Russ > I am trying to open the relative humidity, pressure levels and temperature > from these files: > > http://goldsmr3.sci.gsfc.nasa.gov/daac-bin/OTF/HTTP_services.cgi?FILENAME=%2Fdata%2Fs4pa%2FMERRA%2FMAI3CPASM.5.2.0%2F2011%2F11%2FMERRA300.prod.assim.inst3_3d_asm_Cp.20111130.hdf&FORMAT=TmV0Q0RGLw&BBOX=-90%2C-180%2C90%2C180&LABEL=MERRA300.prod.assim.inst3_3d_asm_Cp.20111130.SUB.nc&SHORTNAME=MAI3CPASM&SERVICE=SUBSET_LATS4D&LAYERS=LAYER_1000%2C250%2C975%2C200%2C950%2C150%2C925%2C100%2C900%2C70%2C875%2C50%2C850%2C40%2C825%2C30%2C800%2C20%2C775%2C10%2C750%2C7%2C725%2C5%2C700%2C4%2C650%2C3%2C600%2C2%2C550%2C1%2C500%2C450%2C400%2C350%2C300&VERSION=1.02&DATASET_VERSION=5.2.0&VARIABLES=h%2Crh%2Ct > > > Code fragment: > // Open the file. > NcFile dataFile("file1.nc", NcFile::ReadOnly); > > // Get pointers to the pressure and temperature variables. > NcVar *hVar, *tempVar, *rhVar; > if (!(hVar = dataFile.get_var("h"))) > return NC_ERR; > if (!(tempVar = dataFile.get_var("t"))) > return NC_ERR; > if (!(rhVar = dataFile.get_var("rh"))) > return NC_ERR; > > cout << "*** SUCCESS reading example file file1.nc!" << endl; > return 0; > > > Thank you! > > Sincerely > Johanna Juhl > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: XYH-561731 Department: Support netCDF Priority: Normal Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.