RE: netcdf c++ implementation problem

Kurt, thank you very much, I think you hit the problem right on the head. 
Thanks for your valuable advice about debug build.

Fei
On Wed, 22 Feb 2006, Hanson, Kurt wrote:

> Fei --
> 
> The problem appears to be that "get(&x, 10, 10)" has an error (both times). 
> Those 10's mean you want a 10 by 10 chunk of data, but x only provides space 
> for a single value. 
> 
> If instead of
>     double x,y;
> You had
>     double x[10][10];
> you should be in the clear.
> 
> If you don't actually want a 10 x 10 chunk of data, and instead want the 
> value at indices i=10 and j=10, you'd do:
>     double x;
>     geolon_t->set_cur(10, 10);
>     geolon_t->get(&x, 1, 1)
> 
> Also, here's a general recommendation... The NetCDF library can easily be 
> built with debugging ("-g" for gcc and likely others) and you could then 
> inspect the core dump relatively easily, e.g.
> 
> gdb your_sample_exe core
> 
> and from within gdb issue commands like where, frame, and print.
> 
> Best of luck
> 
> Kurt Hanson
> 
> -----Original Message-----
> From: owner-netcdfgroup@xxxxxxxxxxxxxxxx
> [mailto:owner-netcdfgroup@xxxxxxxxxxxxxxxx]On Behalf Of Fei Liu
> Sent: Wednesday, February 22, 2006 10:18 AM
> To: netcdfgroup@xxxxxxxxxxxxxxxx
> Subject: netcdf c++ implementation problem
> 
> 
> 
> Hi, group, I am replying to a message I sent out a few days ago to another 
> email list:
> 
> >
> >NetCDF C++ library is compiled with:
> >
> >GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-85)
> >
> >Here is the sample code:
> >
> >#include <netcdfcpp.h>
> >#include <iostream>
> >
> >using namespace std;
> >
> >// g++ -o t testnccpp.cpp -lnetcdf_c++ -lnetcdf -L/usr/local/lib
> >
> >int main(void){
> >
> >  NcFile file("grid_spec.nc");
> >
> >  NcVar * geolon_t = file.get_var("geolon_t");
> >
> >  cout << "Type: " << geolon_t->type()<< endl;
> >  for(int i = 0; i < geolon_t->num_dims(); i ++)
> >    cout << i << ": " << geolon_t->get_dim(i)->size() << endl;
> >  double x,y;
> >
> >  if(geolon_t->get(&x, 10, 10))
> >    cout << x << endl;
> >  if(geolon_t->get(&x, 10, 10))
> >    cout << x << endl;
> >  file.close();
> >}
> >
> >The wierd part is the program core dumps after the 2nd call 
> >geolon_t->get(&x..., here is the output:
> >
> >Type: 6
> >0: 200
> >1: 360
> >-279.5
> >-279.5
> >Segmentation fault (core dumped)
> >
> >I am seeking any clue/simiar experience as why the program core 
> >dumps?....
> >
> >-- 
> >Fei Liu, PhD.                    phone: 609-4526551
> >RSIS/GFDL/NOAA                   fax:   609-9875063
> >P.O. Box 308, 201 Forrestal Rd.  http://www.gfdl.noaa.gov/~fil
> >Princeton, NJ 08542-0308         email: Fei.Liu@xxxxxxxx
> >
> >
> >
> 
> 
> 

-- 
Fei Liu, PhD.                    phone: 609-4526551
RSIS/GFDL/NOAA                   fax:   609-9875063
P.O. Box 308, 201 Forrestal Rd.  http://www.gfdl.noaa.gov/~fil
Princeton, NJ 08542-0308         email: Fei.Liu@xxxxxxxx