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

[netCDF #ZDR-128646]: Ncfile for cpp



> Thank you for your reply.
> The problem is solved. However, a new error occurred which is called 'linker
> error'.
> I think this maybe because of the improper installation of my NETCDF.
> Actually, I built netcdf on win32 and using DEV-C++ to edit and compile cpp
> program.
> I downloaded the precompiled win32 netcdf file. And now I think, for cpp, I
> have to build it myself again. However, I dunno how to build it my own.
> Therefore, I would be grateful whether you can send me a copy of precompiled
> netcdf or teach me how to build it my own.

The current status of the netCDF port to Windows is summarized in these two FAQ
entries for netCDF version 4 and version 4.1:

  http://www.unidata.ucar.edu/netcdf/docs/faq.html#windows_netcdf4
  http://www.unidata.ucar.edu/netcdf/docs/faq.html#windows_netcdf4_1

In short, building netCDF on Windows is not easy, and the easiest way to do it 
currently is with the Cygwin development environment, because with cygwin, you
can follow the same steps as for building netCDF on Unix.  The link below tells 
you
about building with cygwin, and also how to get prebuilt DLLs for earlier 
versions of 
netCDF, which are probably all you need if you want to read or write netCDF 
classic 
format files:

  
http://www.unidata.ucar.edu/netcdf/docs/netcdf-install/Building-on-Windows.html#Building-on-Windows

--Russ

> --------------------------------------------------
> From: "Unidata netCDF Support" <address@hidden>
> Sent: Wednesday, September 01, 2010 6:18 AM
> To: <address@hidden>
> Cc: <address@hidden>
> Subject: [netCDF #ZDR-128646]: Ncfile for cpp
> 
> > Hi Camilla,
> >
> >> I am writing a C++ program to read the data in a netcdf file. In the
> >> script, I use 'Ncfile' to read the .nc file. However, the compiler said
> >> that the function 'Ncfile' was not found. Would you please give me some
> >> advice?
> >>
> >> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> >>
> >> using namespace std;
> >> #include <iostream>        // This is a key C++ library
> >> #include "netcdfcpp.h"
> >>
> >> string dir ("G:/result/");
> >> string code ("us0000");
> >> const string path = dir + code;
> >> const string fil = path + "/" + "wrfout_" + code + ".nc";
> >>
> >> int main ()
> >> {
> >> NcFile file(fil, NcFile::ReadOnly);
> >> if ( !file->is_valid() ) {
> >> delete fil;
> >> exit(1);
> >> }
> >> NcVar* var = fil->get_var("P");
> >> if(var)
> >> printf("variable's name is %s/n", var->name());
> >> system("pause");
> >> return 0;
> >> }
> >
> > Yes, the netCDF C++ library was developed in the mid-1990's and is
> > showing its age (no use of Exceptions, Templates, or namespaces, for
> > example).  The netCDF Java API is much more up-to-date.  An experimental
> > new C++ API for netCDF-4, contributed by Lynton Appel, is available in
> > the 4.1.1 release and is built if you configure with --enable-cxx4, but
> > it still needs a little more work to support netCDF classic files.
> >
> > The current C++ API is just a thin wrapper layer on top of the C
> > library, so in particular, it takes C char* arguments instead of C++
> > string arguments where character strings are required.  So if you change
> > all the string declarations to the corresponding char* or char[]
> > declarations, things should work:
> >
> > using namespace std;
> > #include <iostream>        // This is a key C++ library
> > #include "netcdfcpp.h"
> > #include <strings.h>
> >
> > char dir[] = "G:/result/";
> > char code[] = "us0000";
> > const char *path = strcat(dir, code);
> > char fil[NC_MAX_NAME];
> >
> > int main ()
> > {
> >   sprintf(fil, "%s/wrfout_%s.nc", path, code);
> >   NcFile file(fil, NcFile::ReadOnly);
> >   if ( !file.is_valid() ) {
> >        delete fil;
> >        exit(1);
> >        }
> >        NcVar* var = file.get_var("P");
> >        if(var)
> >        printf("variable's name is %s/n", var->name());
> >   system("pause");
> >   return 0;
> > }
> >
> > --Russ
> >
> >
> > Russ Rew                                         UCAR Unidata Program
> > address@hidden                      http://www.unidata.ucar.edu
> >
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: ZDR-128646
> > Department: Support netCDF
> > Priority: Normal
> > Status: Closed
> >
> >
> 
> 

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: ZDR-128646
Department: Support netCDF
Priority: Normal
Status: Closed