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.
JongKwan Kim wrote:
Hello guys, I have a problem with netCDF C++ Library. I am using the "molloc" to assign the memory like below. *float **snow_we; snow_we = FloatMatrix(tcount,npix); -> this is to assign the memory using "molloc". * And, save the data into snow_we like below. *for (int j = 0; j < npix; j++) { snow_we[count-1][j] = we_val[j]; } * Then, using the netCDF c++ library, create the netCDF file. However, the data does not saved properly, because I think the "snow_we[0][0]" in the red line is made by "molloc". If I use "float snow[100][100]" instead of "molloc" when I was assigning teh memory, it is saved properly. But, I must use "molloc" because of lots of iteration. So, do you guys know how can I solve this problem?
The matrix has to be "continuous." If you allocate like: ---- snow_we = malloc(NELEMS * sizeof(float *)); for (i = 0; i < NELEMS; i++) snow_we[i] = malloc(NELEMS2 * sizeof(float)); ---- then your matrix is not "continuous," but is just a list of list. do a: ---- snow_we = malloc(NELEMS * sizeof(float *)); float *snow_we_data = malloc(NELEMS * NELEMS2 * sizeof(float)); for (i = 0; i < NELEMS; i++) snow_we[i] = snow_we_data + i * NELEMS2; ---- And pass &snow_we[0][0] in your data->put as you do now. Hope that helps (if that's the problem you face...)
netcdfgroup
archives: