[netcdfgroup] netCDF C++ Library : writing in loop

 Hi all,

I have a trouble in my code below.
When I run this code, I have a segmentation fault in front of red line, even
though the code is running until 4 times.
That is, when the icall = 0, 1, 2, 3, the code is running well, but icall =
4, I have a segmentation fault.

I guess the problem might be creating the netCDF files.

Do you guys have any ideas to solve this problem...
please let me know that.

Thanks a lot.



for (int icall=0; icall<20000; i++)
{// for
int iseed =1, tcount=14608, npix=108, error=2, count=0;
float **snow_we, **soil_uztwc;
snow_we = FloatMatrix2(tcount,npix);
soil_uztwc = FloatMatrix2(tcount,npix);

vector< float > we_val( npix );
vector< float > soil_val( npix );

*while ( currentTime <= 14608)
{//while
count++;
error = retrieve_value( allPixels, "we", we_val );
error = retrieve_value( allPixels, "real_soil", soil_val );

for (int j = 0; j < npix; j++) {
   snow_we[count-1][j] = we_val[j];
   soil_uztwc[count-1][j] = soil_val[j];
}
}//while
*
char snowfname[50] = {0, };
sprintf(snowfname,"snow_scem_iseed%d_iter%d.nc",iseed,icall);
NcFile dataFile(snowfname, NcFile::Replace);
if (!dataFile.is_valid()) {
   cout << "Could not open the netcdf snow file ! \n " << endl;
}
NcDim* xDim = dataFile.add_dim("x",tcount);
NcDim* yDim = dataFile.add_dim("y",npix);
NcVar *data = dataFile.add_var("data",ncFloat,xDim,yDim);
*data->put(&snow_we[0][0],tcount,npix);*

char uztwcfname[50] = {0, };
sprintf(uztwcfname,"uztwc_scem_iseed%d_iter%d.nc",iseed,icall);
NcFile dataFile2(uztwcfname, NcFile::Replace);
if (!dataFile2.is_valid()) {
   cout << "Could not open the netcdf uztwc file ! \n " << endl;
}
NcDim* xDim2 = dataFile2.add_dim("x",tcount);
NcDim* yDim2 = dataFile2.add_dim("y",npix);
NcVar *data2 = dataFile2.add_var("data",ncFloat,xDim2,yDim2);
data2->put(&soil_uztwc[0][0],tcount,npix);

FreeFloatMatrix2 (snow_we,tcount);
FreeFloatMatrix2 (soil_uztwc,tcount);

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