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

Re: NetCDF 3.5.0 / gcc-3.2 (patch)



>To: address@hidden
>From: 
>Subject: Re: 20020815: NetCDF 3.5.0 / gcc-3.2 (patch)
>Organization: NOAA/FSL
>Keywords: C++ iostream gcc-3 namespaces


Hi Mike,

>   We have been using netcdf-3.5.0 with the newer gcc-3 compilers here
> at FSL for a while and have found that the C++ interface and autoconf
> stuff needs a bit of tweaking.  I've attached a patch to netcdf 3.5.0
> which seems to give us a good netcdf library in this environment.
> 
>   The patch does the things you have listed on your know problems
> page.  And it also cleans up the C++ interface to work with the ISO
> C++ namespaces.  This mostly involves using <iostream> instead of
> <iostream.h> and putting std:: in front of things like cout, cerr.  It
> also replaces the depricated strstream class with the new stringstream
> class.
> 
>   Finally, it patches configure.in and aclocal.m4 to work with the
> newer autoconfig packages which are in redhat linux 7.2.  The
> autoconfig changes were needed since netcdf will not build with the
> shipped configure script.  The C++ tests in aclocal needed to be
> modified and the old ones included by the older autoconfig will not
> work with gcc-3.

Thanks very much for the patch.  I had fixed a few of these things in
the netCDF 3.5.1 beta release at

  ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-3.5.1-beta3.tar.Z

and in a later beta I haven't bundled up yet, but I hadn't gotten
around to testing it on the C++ compilers on all the platforms we have
access to.  I had trouble finding ways to conform to the C++ standard
and also compile on old C++ compilers that didn't conform, and had
decided to require (and test for in the configure script) a C++
compiler that handles namespaces correctly.

I really appreciate your patches to configure.in and aclocal.m4, since
I'm not good at autoconfig.  Maybe incorporating these patches will
finally give us the momentum needed to get the next release out.
Until I do finish merging these fixes into our beta release, I'll make
your patch available from the known-problems page.

Thanks again for making this patch available.

--Russ

Only in netcdf-3.5.0.orig/src: MANIFEST
Only in netcdf-3.5.0.orig/src: Makefile
diff -b -r -c netcdf-3.5.0.orig/src/aclocal.m4 netcdf-3.5.0/src/aclocal.m4
*** netcdf-3.5.0.orig/src/aclocal.m4    Thu Mar 22 14:43:11 2001
--- netcdf-3.5.0/src/aclocal.m4 Thu Aug 15 15:57:08 2002
***************
*** 173,181 ****
                        AC_MSG_CHECKING(C++ compiler \"$CXX\")
                        AC_TRY_RUN(
                            [
!                               #include <iostream.h>
                                int main() {
!                                   cout << "";
                                    return 0;
                                }
                            ],
--- 173,181 ----
                        AC_MSG_CHECKING(C++ compiler \"$CXX\")
                        AC_TRY_RUN(
                            [
!                               #include <iostream>
                                int main() {
!                                   std::cout << "";
                                    return 0;
                                }
                            ],
***************
*** 1141,1147 ****
      echo "running [\$]{CONFIG_SHELL-/bin/sh} [$]0 [$]ac_configure_args 
--no-create --no-recursion"
      exec [\$]{CONFIG_SHELL-/bin/sh} [$]0 [$]ac_configure_args --no-create 
--no-recursion ;;
    -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
!     echo "$CONFIG_STATUS generated by autoconf version AC_ACVERSION"
      exit 0 ;;
    -help | --help | --hel | --he | --h)
      echo "[\$]ac_cs_usage"; exit 0 ;;
--- 1141,1147 ----
      echo "running [\$]{CONFIG_SHELL-/bin/sh} [$]0 [$]ac_configure_args 
--no-create --no-recursion"
      exec [\$]{CONFIG_SHELL-/bin/sh} [$]0 [$]ac_configure_args --no-create 
--no-recursion ;;
    -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
!     echo "$CONFIG_STATUS generated by autoconf version ?unknown?"
      exit 0 ;;
    -help | --help | --hel | --he | --h)
      echo "[\$]ac_cs_usage"; exit 0 ;;
Only in netcdf-3.5.0/src: aclocal.m4~
Only in netcdf-3.5.0/src: autom4te.cache
diff -b -r -c netcdf-3.5.0.orig/src/configure.in netcdf-3.5.0/src/configure.in
*** netcdf-3.5.0.orig/src/configure.in  Thu Mar 22 14:43:13 2001
--- netcdf-3.5.0/src/configure.in       Thu Aug 15 14:51:17 2002
***************
*** 3,15 ****
  dnl Process this file with GNU autoconf(1) to produce a configure script.
  dnl
  
  dnl Defaults:
  CPPFLAGS=${CPPFLAGS--DNDEBUG}
  CFLAGS=${CFLAGS--O}
  FPPFLAGS=${FPPFLAGS-}
  FFLAGS=${FFLAGS-}
- 
- AC_INIT(libsrc/ncconfig.in)
  UD_SRCDIR
  AC_PREFIX_DEFAULT(`(cd ..; pwd)`)
  AC_CONFIG_HEADER(
--- 3,17 ----
  dnl Process this file with GNU autoconf(1) to produce a configure script.
  dnl
  
+ AC_INIT(netcdf, 3.5.0)
+ dnl AC_INIT(libsrc/ncconfig.in)
+ 
+ 
  dnl Defaults:
  CPPFLAGS=${CPPFLAGS--DNDEBUG}
  CFLAGS=${CFLAGS--O}
  FPPFLAGS=${FPPFLAGS-}
  FFLAGS=${FFLAGS-}
  UD_SRCDIR
  AC_PREFIX_DEFAULT(`(cd ..; pwd)`)
  AC_CONFIG_HEADER(
***************
*** 55,58 ****
  UD_CHECK_SIZEOF(size_t)
  UD_MAKEWHATIS
  UD_FTPBINDIR
! UD_OUTPUT(macros.make)
--- 57,60 ----
  UD_CHECK_SIZEOF(size_t)
  UD_MAKEWHATIS
  UD_FTPBINDIR
! AC_OUTPUT(macros.make)
diff -b -r -c netcdf-3.5.0.orig/src/cxx/nctst.cpp netcdf-3.5.0/src/cxx/nctst.cpp
*** netcdf-3.5.0.orig/src/cxx/nctst.cpp Fri Sep 17 11:21:23 1999
--- netcdf-3.5.0/src/cxx/nctst.cpp      Thu Aug 15 15:40:14 2002
***************
*** 1,4 ****
! #include <iostream.h>
  #include <string.h>
  #include "netcdfcpp.h"
  
--- 1,4 ----
! #include <iostream>
  #include <string.h>
  #include "netcdfcpp.h"
  
***************
*** 8,14 ****
  
      // Check if the file was opened successfully
      if (! nc.is_valid()) {
!       cerr << "can't create netCDF file " << path << "\n";
        return;
      }
  
--- 8,14 ----
  
      // Check if the file was opened successfully
      if (! nc.is_valid()) {
!       std::cerr << "can't create netCDF file " << path << "\n";
        return;
      }
  
***************
*** 124,135 ****
  
      for (int n=0; n < num_dims(); n++) {
        NcDim* dim = get_dim(n);
!       cout << "\t" << dim->name() << " = " ;
        if (dim->is_unlimited())
!         cout << "UNLIMITED" << " ;\t " << "// " << dim->size() <<
            " currently\n";
        else
!         cout << dim->size() << " ;\n";
      }
  }
  
--- 124,135 ----
  
      for (int n=0; n < num_dims(); n++) {
        NcDim* dim = get_dim(n);
!       std::cout << "\t" << dim->name() << " = " ;
        if (dim->is_unlimited())
!         std::cout << "UNLIMITED" << " ;\t " << "// " << dim->size() <<
            " currently\n";
        else
!         std::cout << dim->size() << " ;\n";
      }
  }
  
***************
*** 137,146 ****
  {
      NcToken vname = var.name();
      NcAtt* ap;
!     for(int n = 0; ap = var.get_att(n); n++) {
!       cout << "\t\t" << vname << ":" << ap->name() << " = " ;
        NcValues* vals = ap->values();
!       cout << *vals << " ;" << endl ;
        delete ap;
        delete vals;
      }
--- 137,146 ----
  {
      NcToken vname = var.name();
      NcAtt* ap;
!     for(int n = 0; (ap = var.get_att(n)); n++) {
!       std::cout << "\t\t" << vname << ":" << ap->name() << " = " ;
        NcValues* vals = ap->values();
!       std::cout << *vals << " ;" << std::endl ;
        delete ap;
        delete vals;
      }
***************
*** 153,172 ****
        {"","byte","char","short","long","float","double"};
      NcVar* vp;
  
!     for(n = 0; vp = get_var(n); n++) {
!       cout << "\t" << types[vp->type()] << " " << vp->name() ;
  
        if (vp->num_dims() > 0) {
!           cout << "(";
            for (int d = 0; d < vp->num_dims(); d++) {
                NcDim* dim = vp->get_dim(d);
!               cout << dim->name();
                if (d < vp->num_dims()-1)
!                 cout << ", ";           
            }
!           cout << ")";
        }
!       cout << " ;\n";
        // now dump each of this variable's attributes
        dumpatts(*vp);
      }
--- 153,172 ----
        {"","byte","char","short","long","float","double"};
      NcVar* vp;
  
!     for(n = 0; (vp = get_var(n)); n++) {
!       std::cout << "\t" << types[vp->type()] << " " << vp->name() ;
  
        if (vp->num_dims() > 0) {
!           std::cout << "(";
            for (int d = 0; d < vp->num_dims(); d++) {
                NcDim* dim = vp->get_dim(d);
!               std::cout << dim->name();
                if (d < vp->num_dims()-1)
!                 std::cout << ", ";
            }
!           std::cout << ")";
        }
!       std::cout << " ;\n";
        // now dump each of this variable's attributes
        dumpatts(*vp);
      }
***************
*** 175,184 ****
  void DumpableNcFile::dumpgatts( void )
  {
      NcAtt* ap;
!     for(int n = 0; ap = get_att(n); n++) {
!       cout << "\t\t" << ":" << ap->name() << " = " ;
        NcValues* vals = ap->values();
!       cout << *vals << " ;" << endl ;
        delete vals;
        delete ap;
      }
--- 175,184 ----
  void DumpableNcFile::dumpgatts( void )
  {
      NcAtt* ap;
!     for(int n = 0; (ap = get_att(n)); n++) {
!       std::cout << "\t\t" << ":" << ap->name() << " = " ;
        NcValues* vals = ap->values();
!       std::cout << *vals << " ;" << std::endl ;
        delete vals;
        delete ap;
      }
***************
*** 187,196 ****
  void DumpableNcFile::dumpdata( )
  {
      NcVar* vp;
!     for (int n = 0; vp = get_var(n); n++) {
!       cout << " " << vp->name() << " = ";
        NcValues* vals = vp->values();
!       cout << *vals << " ;" << endl ;
        delete vals;
      }
  }
--- 187,196 ----
  void DumpableNcFile::dumpdata( )
  {
      NcVar* vp;
!     for (int n = 0; (vp = get_var(n)); n++) {
!       std::cout << " " << vp->name() << " = ";
        NcValues* vals = vp->values();
!       std::cout << *vals << " ;" << std::endl ;
        delete vals;
      }
  }
***************
*** 199,223 ****
  {
      DumpableNcFile nc(path);  // default is open in read-only mode
  
!     cout << "netcdf " << cdl_name(path) << " {" << endl <<
!           "dimensions:" << endl ;
  
      nc.dumpdims();
  
!     cout << "variables:" << endl;
  
      nc.dumpvars();
  
      if (nc.num_atts() > 0)
!       cout << "// global attributes" << endl ;
  
      nc.dumpgatts();
  
!     cout << "data:" << endl;
  
      nc.dumpdata();
  
!     cout << "}" << endl;
  }
  
  
--- 199,223 ----
  {
      DumpableNcFile nc(path);  // default is open in read-only mode
  
!     std::cout << "netcdf " << cdl_name(path) << " {" << std::endl <<
!           "dimensions:" << std::endl ;
  
      nc.dumpdims();
  
!     std::cout << "variables:" << std::endl;
  
      nc.dumpvars();
  
      if (nc.num_atts() > 0)
!       std::cout << "// global attributes" << std::endl ;
  
      nc.dumpgatts();
  
!     std::cout << "data:" << std::endl;
  
      nc.dumpdata();
  
!     std::cout << "}" << std::endl;
  }
  
  
diff -b -r -c netcdf-3.5.0.orig/src/cxx/ncvalues.cpp 
netcdf-3.5.0/src/cxx/ncvalues.cpp
*** netcdf-3.5.0.orig/src/cxx/ncvalues.cpp      Tue Dec 22 11:21:49 1998
--- netcdf-3.5.0/src/cxx/ncvalues.cpp   Thu Aug 15 15:36:06 2002
***************
*** 7,13 ****
   *   $Header: /upc/share/CVS/netcdf-3/cxx/ncvalues.cpp,v 1.3 1998/12/22 
18:21:49 russ Exp $
   *********************************************************************/
  
! #include <iostream.h>         // for debugging
  #include "ncvalues.h"
  
  NcValues::NcValues( void ) : the_number(0), the_type(ncNoType)
--- 7,13 ----
   *   $Header: /upc/share/CVS/netcdf-3/cxx/ncvalues.cpp,v 1.3 1998/12/22 
18:21:49 russ Exp $
   *********************************************************************/
  
! #include <iostream>           // for debugging
  #include "ncvalues.h"
  
  NcValues::NcValues( void ) : the_number(0), the_type(ncNoType)
***************
*** 25,31 ****
      return the_number;
  }    
  
! ostream& operator<< (ostream& os, const NcValues& vals)
  {
      return vals.print(os);
  }
--- 25,31 ----
      return the_number;
  }
  
! std::ostream& operator<< (std::ostream& os, const NcValues& vals)
  {
      return vals.print(os);
  }
***************
*** 244,250 ****
      return s;
  }
  
! ostream& NcValues_short::print(ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 244,250 ----
      return s;
  }
  
! std::ostream& NcValues_short::print(std::ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 253,259 ****
      return os;
  }
  
! ostream& NcValues_int::print(ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 253,259 ----
      return os;
  }
  
! std::ostream& NcValues_int::print(std::ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 262,268 ****
      return os;
  }
  
! ostream& NcValues_nclong::print(ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 262,268 ----
      return os;
  }
  
! std::ostream& NcValues_nclong::print(std::ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 271,277 ****
      return os;
  }
  
! ostream& NcValues_long::print(ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 271,277 ----
      return os;
  }
  
! std::ostream& NcValues_long::print(std::ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 280,286 ****
      return os;
  }
  
! ostream& NcValues_ncbyte::print(ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 280,286 ----
      return os;
  }
  
! std::ostream& NcValues_ncbyte::print(std::ostream& os) const
  {
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 289,295 ****
      return os;
  }
  
! ostream& NcValues_char::print(ostream& os) const
  {
      os << '"';
      long len = the_number;
--- 289,295 ----
      return os;
  }
  
! std::ostream& NcValues_char::print(std::ostream& os) const
  {
      os << '"';
      long len = the_number;
***************
*** 302,310 ****
      return os;
  }
  
! ostream& NcValues_float::print(ostream& os) const
  {
!     long save=os.flags();
      os.precision(7);
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 302,310 ----
      return os;
  }
  
! std::ostream& NcValues_float::print(std::ostream& os) const
  {
!     std::ostream::fmtflags save=os.flags();
      os.precision(7);
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
***************
*** 314,322 ****
      return os;
  }
  
! ostream& NcValues_double::print(ostream& os) const
  {
!     long save=os.flags();
      os.precision(15);
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
--- 314,322 ----
      return os;
  }
  
! std::ostream& NcValues_double::print(std::ostream& os) const
  {
!     std::ostream::fmtflags save=os.flags();
      os.precision(15);
      for(int i = 0; i < the_number - 1; i++)
        os << the_values[i] << ", ";
diff -b -r -c netcdf-3.5.0.orig/src/cxx/ncvalues.h 
netcdf-3.5.0/src/cxx/ncvalues.h
*** netcdf-3.5.0.orig/src/cxx/ncvalues.h        Wed Oct 28 10:10:16 1998
--- netcdf-3.5.0/src/cxx/ncvalues.h     Thu Aug 15 15:33:41 2002
***************
*** 10,20 ****
  #ifndef Ncvalues_def
  #define Ncvalues_def
  
! #include <iostream.h>
  #ifdef STRSTREAM_H_SPEC
  #   include STRSTREAM_H_SPEC
  #else
! #   include <strstream.h>
  #endif
  #include <limits.h>
  #include <string.h>
--- 10,20 ----
  #ifndef Ncvalues_def
  #define Ncvalues_def
  
! #include <iostream>
  #ifdef STRSTREAM_H_SPEC
  #   include STRSTREAM_H_SPEC
  #else
! #   include <sstream>
  #endif
  #include <limits.h>
  #include <string.h>
***************
*** 82,88 ****
      virtual int invalid( void ) const;                                        
      \
    private:                                                                  \
      TYPE* the_values;                                                       \
!     ostream& print(ostream&) const;                                         \
  };
  
  #define NcTypeEnum(TYPE) makename2(_nc__,TYPE)
--- 82,88 ----
      virtual int invalid( void ) const;                                        
      \
    private:                                                                  \
      TYPE* the_values;                                                       \
!     std::ostream& print(std::ostream&) const;                               \
  };
  
  #define NcTypeEnum(TYPE) makename2(_nc__,TYPE)
***************
*** 219,227 ****
  #define as_string_implement(TYPE)                                           \
  char* NcVal(TYPE)::as_string( long n ) const                                \
  {                                                                           \
!     char* s = new char[32];                                                 \
!     ostrstream ostr(s, sizeof(s));                                            
\
!     ostr << the_values[n] << ends;                                          \
      return s;                                                               \
  }
  
--- 219,229 ----
  #define as_string_implement(TYPE)                                           \
  char* NcVal(TYPE)::as_string( long n ) const                                \
  {                                                                           \
!     std::ostringstream ostr;                                                  
\
!     ostr << the_values[n] << std::ends;                                     \
!     std::string str(ostr.str());                                              
\
!     char *s = new char[str.size()];                                           
\
!     str.copy(s, str.size());                                                  
\
      return s;                                                               \
  }
  
***************
*** 232,238 ****
      NcValues(NcType, long);
      virtual ~NcValues( void );
      virtual long num( void );
!     virtual ostream& print(ostream&) const = 0;
      virtual void* base( void ) const = 0;
      virtual int bytes_for_one( void ) const = 0;
  
--- 234,240 ----
      NcValues(NcType, long);
      virtual ~NcValues( void );
      virtual long num( void );
!     virtual std::ostream& print(std::ostream&) const = 0;
      virtual void* base( void ) const = 0;
      virtual int bytes_for_one( void ) const = 0;
  
***************
*** 250,258 ****
      virtual char* as_string( long n ) const = 0;  // value as string
      
    protected:
-     NcType the_type;
      long the_number;
!     friend ostream& operator<< (ostream&, const NcValues&);
  };
  
  declare(NcValues,ncbyte)
--- 252,260 ----
      virtual char* as_string( long n ) const = 0;  // value as string
  
    protected:
      long the_number;
!     NcType the_type;
!     friend std::ostream& operator<< (std::ostream&, const NcValues&);
  };
  
  declare(NcValues,ncbyte)
diff -b -r -c netcdf-3.5.0.orig/src/cxx/netcdfcpp.h 
netcdf-3.5.0/src/cxx/netcdfcpp.h
*** netcdf-3.5.0.orig/src/cxx/netcdfcpp.h       Mon Feb  5 13:29:12 2001
--- netcdf-3.5.0/src/cxx/netcdfcpp.h    Thu Aug 15 15:31:45 2002
***************
*** 154,160 ****
      virtual ~NcDim( void );
      
      // to construct dimensions, since constructor is private
!     friend NcFile;
  };
  
  
--- 154,160 ----
      virtual ~NcDim( void );
  
      // to construct dimensions, since constructor is private
!     friend class NcFile;
  };
  
  
***************
*** 357,363 ****
      void init_cur( void );
  
      // to make variables, since constructor is private
!   friend NcFile;
  };
  
  
--- 357,363 ----
      void init_cur( void );
  
      // to make variables, since constructor is private
!   friend class NcFile;
  };
  
  
***************
*** 388,394 ****
      NcAtt( NcFile*, NcToken); // global attribute
      
      // To make attributes, since constructor is private
!   friend NcFile;
    friend NcAtt* NcVar::get_att( NcToken ) const;
  };
  
--- 388,394 ----
      NcAtt( NcFile*, NcToken); // global attribute
  
      // To make attributes, since constructor is private
!   friend class NcFile;
    friend NcAtt* NcVar::get_att( NcToken ) const;
  };
  
Only in netcdf-3.5.0/src/nctest: testfile.nc
Only in netcdf-3.5.0/src/nf_test: test.nc