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

[netCDF #XCE-832540]: Netcdf help



> Dear users,
>
> I'm trying to read, for each year, 12 monthly fields of temperature from a
netcdf defined in such way:
>
> Dimensions:
> NLON = 160 ;
> NLAT = 150 ;
> Time = 1224 ;
> Variables:
> Float Lon(lat, Lon) ;
> Float lat(lat, Lon) ;
> Double time(time) ;
> Float temperature(time, lat, Lon) ;
>
> For this purpose, I defined a variable "vals" of 12*NLON*NLAT points and I
used this netcdf function to get data:
>
> if((status = nc_get_vara_float (ncid, temperatureid,start, count, vals)))
> handle_error(status);
>
> Where,
>
> Start[1] = 0;
> Count[1] = NLON;
> Start[2] = 0;
> Count[2] = NLAT;
> Start[0] = (year - 1901) * 12;
> Count[0] = start[0] + 12 - 1;
>
> and year vary from 1901 to 2003. Unfortunately I get a segmentation fault. I
put the stdoutput and the error coming from a debugger.
>
> Year: 1901
> READING TEMPERATURE:  0 11 0 148 0 158
> Year: 1902
> READING TEMPER 12 23 0 148 0 158
> Segmentation fault (core dumped)
>
> Program terminated with signal 11, Segmentation fault.
> #0  swapn4b (DST=<value optimized out>, src=<value optimized out>, nn=1024)
at ncx.c:159
> 159                     op[0] = ip[3];
>
> Could anyone help me to read properly these data?
> Thank you in advance for your help,
>
> Cheers,
>
> Alessandro
>
>

I think your problem is that you should not be adding Start[0] to Count[0]:
Count[0] = start[0] + 12 - 1;

should perhaps be:
Count[0] = 12;

The count is the count from the given start, not the count plus the start. That
is, count is how many values you want read, not the absolute index of the last
item to be read. It is relative to start.

But what is funny is that this should not segfault. It should instead return an
error for nc_get_vara_float.

Are you sure it is not giving you an error?

Thanks,

Ed

Ticket Details
===================
Ticket ID: XCE-832540
Department: Support netCDF
Priority: Normal
Status: Open