This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Camilla, > I have built netcdf on cygwin. However, there are still some errors. Would > you please help me to have a look whether the errors are from installation > or my script? > > In cygwin, I typed 'g++ test.cpp' > The log file is called 'log.test1' You have to also tell g++ where to look for the netcdf_c++ library and the netcdf library that it calls. For example, if they were both installed in the directory "/usr/local/lib", and if the include files netcdfcpp.h and netcdf.h were installed in "/usr/local/include" you would need to use something like g++ -I/usr/local/include test.cpp -L/usr/local/lib -lnetcdf_c++ -lnetcdf Also, I think you'll need to allocate space for the file name you want to store in "f", rather than just declaring it to be a "char *" pointer that's unitialized. So, it would be better to use something like #define MAX_PATH_LENGTH 100 char f[MAX_PATH_LENGTH]; or use the appropriate const for your operating system, instead of just char *f; --Russ > -------------------------------------------------- > From: "Unidata netCDF Support" <address@hidden> > Sent: Wednesday, September 01, 2010 10:33 AM > To: <address@hidden> > Cc: <address@hidden> > Subject: [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 > > > > > 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