> Thank you, I just have on more problem with it. When I try to save down my > new variable using put it > saves down the variable and the variable works with nc_dump but it does a > system exit after. > > refVar->set_cur(0,0,0,0); > if (!refVar->put(ref_out,NREC,NLVL,NLAT,NLON)); > return NC_ERR; > //Never gets here > delete  ref_out; > cout << "*** SUCCESS writing example file ref_4D.nc!" << endl; > > Do you know why that could be? Yes, it's that little semicolon you have at the end of the line if (!refVar->put(ref_out,NREC,NLVL,NLAT,NLON)); If you remove that, then the "return NC_ERR;" will be included as part of the if statement, as it should be. Otherwise, the return statement is returning from your main program to the parent process, which is just the shell running your program. --Russ > 2012/3/13 Unidata netCDF Support <address@hidden> > > > Johanna, > > > > > Would I create a new NcVar to read in the data? Or how do I get it to put > > > it on the heap? > > > > As the examples show, you typically allocate memory in the calling program > > in which to read the data. Also, the data for netCDF variables is > > typically > > larger than you need to keep in memory all at one time, or is read in > > slices > > that require less memory than the whole variable. However, if you have > > enough memory, you can read all the values of a variable into one big chunk > > of contiguous memory, allocated with a single "new" constructor, or > > declared > > statically. > > > > For example, in the netCDF-3 C++ API you are using, to read all the > > data in at once from: > > > > float h(time, levels, latitude, longitude) ; > > > > where the sizes of the dimensions are > > > > time = UNLIMITED ; // (8 currently) > > levels = 37 ; > > longitude = 288 ; > > latitude = 144 ; > > > > you could allocate a multidimensional array using something like > > > > float h_vals; > > > > or > > > > h_vals = new float; > > > > and then read in all the values at once into the h_vals array using > > something like: > > > > NcVar *hVar = dataFile.get_var("h"); > > boolean ret = hVar.get(&h_vals, 8, 37, 288, 144); > > > > following the documenation of the NcVar::get method here: > > > > http://www.unidata.ucar.edu/netcdf/docs/netcdf-cxx.html#Class-NcVar > > > > But you could also use the same get method to just read the data from > > one time with each call, using something like > > > > float h_vals; > > > > or > > > > h_vals = new float; > > > > and then read in all the values for the fourth time into the h_vals array > > using > > something like: > > > > int time = 3; // the first time is time 0 > > NcVar *hVar = dataFile.get_var("h"); > > hVar.setcur(time, 0, 0, 0); > > boolean ret = hVar.get(&h_vals, 37, 288, 144); > > > > You should check the return value from these method calls to make sure > > you catch any errors ... > > > > --Russ 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.