[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #CEZ-194696]: segmentation fault while allocating 4darray in cpp



Greetings Nils,

The issues is that you are allocating the array T_2M_AV one row at a time, 
which means that the overall array is not necessarily going to be in a 
contiguous in memory (which is required by netCDF). The tricky part is the 
dynamic nature of the problem. You may want to check out this thread for some 
pointers:

http://www.daniweb.com/software-development/cpp/threads/127068

Cheers!

Sean

> Greetings Nils,
> 
> Is there a copy of the file you are trying to read on the web somewhere? If 
> not, would it be possible to get a copy?
> 
> Thanks!
> 
> Sean
> 
> > Dear help team
> >
> > attached is a file to read a netcdf file with unknown dimension size.
> > it fails to allocate the size of the multidimension arrays:
> >
> >
> > T_2M_AV = new float***[timelength];
> > for (i = 0; i < timelength; ++i){
> > T_2M_AV[i] = new float**[heightlenght];
> > for (j = 0; j< heightlenght; ++j)
> > T_2M_AV[i][j] = new float*[latlength];
> > for (k = 0; k < latlength; ++k)
> > T_2M_AV[i][j][k] = new float[lonlength];
> > }
> >
> > ncdump gives:
> > ...
> > float T_2M_AV(time, height_2m, lat, lon) ;
> > ...
> >
> > compiling the code with
> > g++ -c readdynamic.cpp
> > g++ -o readdynamic readdynamic.cpp -lnetcdf_c++ -lnetcdf
> >
> >
> > I will be very happy if you have any advice.
> >
> > best regrades
> >
> > Nils
> >
> >
> 


Ticket Details
===================
Ticket ID: CEZ-194696
Department: Support netCDF
Priority: Normal
Status: Open