NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
C++ interface to netcdf developed by Lynton Appel is a good addition to netcdf libraries. This allows us to write C++ style programs to read and write netcdf data with lightning speed and hence preferred in some situations. 1. To make it more customized and simple for our purpose, I have written a class "write_llt" that only writes a single variable (say rain) of the type rain(lat, lon, time) with unlimited time axis. This function takes care of several things like managing frame_number etc. I create an object of the class as follow write_llt ncout(with all the variable structure as arguments); 2. and then I call the wrapper function (called write_data(rain, frame_time)) to write a time-step at single time value. The write_data function used following function calls from netcdf interface. dataVar.putVar (startp, countp, rain); tVar.putVar (startt, frame_time); 3. When I finish writing all the time-steps, and goes out of the loop the files closes and objects are destroyed properly before the program stops. Check this link for useful discussion http://netcdf-group.1586084.n2.nabble.com/NcFile-close-member-function-td7574815.html This works without any issues with my class write_llt. 4. However, because, I am using my own class with pointer notations to ncFile class object, when I want to write several files in a loop. loop for all the N input files { write_llt ncout(Nth output file and its structure as arguments); loop for each time step { ncout.write_data(rain, frame_time) } //Here When I finish writing the current file, I want it to be closed properly so that I can //write the next file, so I need to have a manual close file function. } 5. When I run my code like this some time it writes a correct file but most often the file is written without any time axis. ncdump looks like this netcdf \200307_02_64bit { dimensions: latitude = 256 ; longitude = 256 ; time = UNLIMITED ; // (0 currently) variables: float latitude(latitude) ; latitude:units = "degrees_north" ; float longitude(longitude) ; longitude:units = "degrees_east" ; int64 time(time) ; time:units = "seconds since 1970-01-01 00:00:00 UTC" ; float rain(time, latitude, longitude) ; ..... ..... } The file has to be 22.1MB (when works properly) but it shows only 17.9 MB (always when it goes wrong). 6. As this works once in a while this looks like an issue of delay in flushing the memory to hard-disc. Because there is not 'close' function, when the outside loop closes my object ncout gets destroyed and all the data gets deleted with it, without being flushed. 7. I have tried calling the destructor ofile->~NcFile() from my write_llt class which gives segmentation fault. 8. I may have chosen a non-recommended way of using the libraries to begin with. If you are a netcdf C++ interface user, please share your experience and possibly a solution to my problem. The C++ interface is very useful and we can make it better with more feedbacks. Also, is there any chance of newer version of it? Is there any active team of researcher using and modifying it? I would like to share my WritingClass with others once I get it to work properly. Thanks and Cheers, -- Bhupendra Raut (Research Fellow) School of Earth, Atmosphere and Environment 9, Rainforest Walk Monash University Clayton 3800 Victoria, Australia PH: +61 3 9905 2269 FAX: +61 3 9905 4403 Website: www.baraut.info
netcdfgroup
archives: