Hello:
I am trying to read a netCDF file into a ROOT Ttree and have a problem.
I am converting a library called ancio, written by Jason Cristy at
the Pacific Northwest National Laboratory. The original library
opened a netCDF file and read the contents into a struct. The sample
netCDF file I have is from Jonathan Katz and Joerg Hau, included with
their program comspari.
I have removed many functions that acted on the data, and changed the
C struct to C++ class. I thought I could then use
Case B
======
TBranch *branch = tree->Branch(branchname,className,object, bufsize, splitlevel)
object is the address of a pointer to an existing object (derived from TObject).
to create the branch, with the type of the data being recognised.
After many hours of trying the file will compile with out warnings and run.
But I get the error:
“# g++ -Wall -o 4 -I. -lnetcdf root-config --libs
mycode.c
[root@blue exp]# ./4
put tree here
Error in TTree::Bronch: Cannot find class:_ncData”
(I assume that ‘Bronch’ is to be ‘Branch’.)
[At this time, the included files will produce this result. I have commented the changes I made that resulted in the errors listed below.]
I thought it was because calloc was being used as the memory manager, but not quite understanding how to change all malloc et. al. calls to ‘new’ I tried one at the end. This works, as demonstrated by uncommenting “else print_ncdata(data);” which prints the dim, var, and att data in the file.
Reading the ROOT manual, I realised I needed to have ClassDef at the bottom of the class declarations.
That results in the file no longer compiling, exiting with the following errors:
g++ -Wall -o 3 -I. -lnetcdf root-config --libs
mycode.c
/tmp/ccwJ63eP.o: In function _ncData::_ncData()': mycode.c:(.text._ZN7_ncDataC1Ev[_ncData::_ncData()]+0x12): undefined reference to
vtable for _ncData’
/tmp/ccwJ63eP.o: In function TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int)': mycode.c:(.text._ZN5TTree6BranchI7_ncDataEEP7TBranchPKcS5_PPT_ii[TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int)]+0x14): undefined reference to
typeinfo for _ncData’
collect2: ld returned 1 exit status
[root@blue exp]# g++ -Wall -o 3 -I. -lnetcdf root-config --libs
mycode.c
/tmp/ccoLjLMH.o: In function _ncData::_ncData()': mycode.c:(.text._ZN7_ncDataC1Ev[_ncData::_ncData()]+0x12): undefined reference to
vtable for _ncData’
/tmp/ccoLjLMH.o: In function TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int)': mycode.c:(.text._ZN5TTree6BranchI7_ncDataEEP7TBranchPKcS5_PPT_ii[TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int)]+0x14): undefined reference to
typeinfo for _ncData’
collect2: ld returned 1 exit status
I think from the manual I need to use rootcint but that results in this error:
rootcint code.cxx -c mycode.h
Error: Too many ‘}’ /usr/include/netcdf.h:587:
Segmentation fault
This code depends on the netcdf library, which I compiled myself but is available as an rpm.
I am using Fedora 8
uname -a
Linux blue 2.6.22.18-co-0.8.0 #1 PREEMPT Sun Nov 23 20:33:36 UTC 2008 i686 i686 i386 GNU/Linux
and the default Fedora 8 g++ compiler
g++ -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: …/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
I compiled ROOT myself
root
-
*
-
W E L C O M E to R O O T *
-
*
- Version 5.22/00 17 December 2008 *
-
*
- You are welcome to visit our Web site *
-
[root.cern.ch](http://root.cern.ch) *
-
*
ROOT 5.22/00 (trunk@26997, Jan 26 2009, 22:17:00 on linux)
Am I failing to include a header file?
tree2.root is created when the
Error in TTree::Bronch: Cannot find class:_ncData
is received. Also, three non-compilable files
were created by the rootcint error. Or, how am I to compile
and then link them?