[netcdfgroup] Problems when configuring netcdf, , C++ library in eclipse

Dear Netcdfgroup community,



As a beginner for netcdf programming within Linux environment. I am trying to configure netcdf

C++ library in eclipse. After the following steps:

(1) download NetCDF-4 C++ 4.3.0 from https://www.unidata.ucar.edu/downloads/netcdf/index.jsp

(2) install the NetCDF-4 C++ 4.3.0 to the dir /usr/local/lib/netcdf-cxx4-4.2/ through make install

(3) set in ECLIPSE include path, library path, and library as attached screenshots.


I found the errors as bellow:

g++ -I/usr/local/lib/netcdf/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ReadWriteNETCDF.d" -MT"src/ReadWriteNETCDF.o" -o "src/ReadWriteNETCDF.o" "../src/ReadWriteNETCDF.cpp"

../src/ReadWriteNETCDF.cpp:14:17: error: ‘netCDF’ is not a namespace-name

using namespace netCDF;

^~~~~~

../src/ReadWriteNETCDF.cpp:14:23: error: expected namespace-name before ‘;’ token

using namespace netCDF;

^

../src/ReadWriteNETCDF.cpp:15:17: error: ‘netCDF’ has not been declared

using namespace netCDF::exceptions;


…


Would you kindly point out where might be the problem? Thanks very much.


Best regards,


Liang

// ReadWriteNETCDF.cpp : ¶¨Òå¿ØÖÆ̨ӦÓóÌÐòµÄÈë¿Úµã¡£
//

#include "stdafx.h"

#include <iostream>
#include <netcdf.h>
using namespace std;
using namespace netCDF;
using namespace netCDF::exceptions;

// We are writing 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2
// timesteps of data.
static const int NLVL = 2;
static const int NLAT = 6;
static const int NLON = 12;
static const int NREC = 2;

// These are used to construct some example data. 
static const float SAMPLE_PRESSURE = 900.0;
static const float SAMPLE_TEMP = 9.0;
static const float START_LAT = 25.0;
static const float START_LON = -125.0; 


// Return this code to the OS in case of failure.
static const int NC_ERR = 2;

int _tmain(int argc, _TCHAR* argv[])
{
        // These arrays will store the latitude and longitude values.
        float lats[NLAT], lons[NLON];

        // These arrays will hold the data we will read in. We will only
        // need enough space to hold one timestep of data; one record.
        float pres_in[NLVL][NLAT][NLON];
        float temp_in[NLVL][NLAT][NLON];

        try
        {
                // Open the file.
                NcFile dataFile("pres_temp_4D.nc", NcFile::read);

                // Get the latitude and longitude variables and read data.
                NcVar latVar, lonVar;
                latVar = dataFile.getVar("latitude");
                if(latVar.isNull()) return NC_ERR;
                lonVar = dataFile.getVar("longitude");
                if(lonVar.isNull()) return NC_ERR;
                lonVar.getVar(lons);
                latVar.getVar(lats);

                // Check the coordinate variable data. 
                for (int lat = 0; lat < NLAT; lat++)
                        if (lats[lat] != START_LAT + 5. * lat)
                                return NC_ERR;

                for (int lon = 0; lon < NLON; lon++)
                        if (lons[lon] != START_LON + 5. * lon)
                                return NC_ERR;

                // Get the pressure and temperature variables and read data one 
time step at a time
                NcVar presVar, tempVar;
                presVar = dataFile.getVar("pressure");
                if(presVar.isNull()) return NC_ERR;
                tempVar = dataFile.getVar("temperature");
                if(tempVar.isNull()) return NC_ERR;

                vector<size_t> startp,countp;
                startp.push_back(0);
                startp.push_back(0);
                startp.push_back(0);
                startp.push_back(0);
                countp.push_back(1);
                countp.push_back(NLVL);
                countp.push_back(NLAT);
                countp.push_back(NLON);
                for (size_t rec = 0; rec < NREC; rec++)
                {
                        // Read the data one record at a time.
                        startp[0]=rec;
                        presVar.getVar(startp,countp,pres_in);
                        tempVar.getVar(startp,countp,temp_in);

                        int i=0;  //used in the data generation loop
                        for (int lvl = 0; lvl < NLVL; lvl++)
                                for (int lat = 0; lat < NLAT; lat++)
                                        for (int lon = 0; lon < NLON; lon++)
                                        {
                                                if(pres_in[lvl][lat][lon] != 
(float) (SAMPLE_PRESSURE + i)) return NC_ERR;
                                                if(temp_in[lvl][lat][lon] != 
(float)(SAMPLE_TEMP + i++)) return NC_ERR;
                                        }

                } // next record 

                // The file is automatically closed by the destructor. This 
frees
                // up any internal netCDF resources associated with the file, 
and
                // flushes any buffers.

                // cout << "*** SUCCESS reading example file pres_temp_4D.nc!" 
<< endl;
                return 0;

        }
        catch(NcException& e)
        {
                e.what();
                cout<<"FAILURE**************************"<<endl;
                return NC_ERR;
        }

        return 0;
}

Attachment: Screenshot from 2019-03-10 20-31-28.png
Description: PNG image

Attachment: Screenshot from 2019-03-10 20-31-33.png
Description: PNG image

Attachment: Screenshot from 2019-03-10 20-31-36.png
Description: PNG image

20:15:38 **** Incremental Build of configuration Debug for project 
ReadWriteNETCDF ****
make all 
Building file: ../src/ReadWriteNETCDF.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/lib/netcdf/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD 
-MP -MF"src/ReadWriteNETCDF.d" -MT"src/ReadWriteNETCDF.o" -o 
"src/ReadWriteNETCDF.o" "../src/ReadWriteNETCDF.cpp"
../src/ReadWriteNETCDF.cpp:14:17: error: ‘netCDF’ is not a namespace-name
 using namespace netCDF;
                 ^~~~~~
../src/ReadWriteNETCDF.cpp:14:23: error: expected namespace-name before ‘;’ 
token
 using namespace netCDF;
                       ^
../src/ReadWriteNETCDF.cpp:15:17: error: ‘netCDF’ has not been declared
 using namespace netCDF::exceptions;
                 ^~~~~~
../src/ReadWriteNETCDF.cpp:15:25: error: ‘exceptions’ is not a namespace-name
 using namespace netCDF::exceptions;
                         ^~~~~~~~~~
../src/ReadWriteNETCDF.cpp:15:35: error: expected namespace-name before ‘;’ 
token
 using namespace netCDF::exceptions;
                                   ^
../src/ReadWriteNETCDF.cpp: In function ‘int main()’:
../src/ReadWriteNETCDF.cpp:48:3: error: ‘NcFile’ was not declared in this scope
   NcFile dataFile("pres_temp_4D.nc", NcFile::read);
   ^~~~~~
../src/ReadWriteNETCDF.cpp:48:3: note: suggested alternative: ‘ctime’
   NcFile dataFile("pres_temp_4D.nc", NcFile::read);
   ^~~~~~
   ctime
../src/ReadWriteNETCDF.cpp:51:3: error: ‘NcVar’ was not declared in this scope
   NcVar latVar, lonVar;
   ^~~~~
../src/ReadWriteNETCDF.cpp:51:3: note: suggested alternative: ‘char’
   NcVar latVar, lonVar;
   ^~~~~
   char
../src/ReadWriteNETCDF.cpp:52:3: error: ‘latVar’ was not declared in this scope
   latVar = dataFile.getVar("latitude");
   ^~~~~~
../src/ReadWriteNETCDF.cpp:52:3: note: suggested alternative: ‘lats’
   latVar = dataFile.getVar("latitude");
   ^~~~~~
   lats
../src/ReadWriteNETCDF.cpp:52:12: error: ‘dataFile’ was not declared in this 
scope
   latVar = dataFile.getVar("latitude");
            ^~~~~~~~
../src/ReadWriteNETCDF.cpp:52:12: note: suggested alternative: ‘mutable’
   latVar = dataFile.getVar("latitude");
            ^~~~~~~~
            mutable
../src/ReadWriteNETCDF.cpp:54:3: error: ‘lonVar’ was not declared in this scope
   lonVar = dataFile.getVar("longitude");
   ^~~~~~
../src/ReadWriteNETCDF.cpp:54:3: note: suggested alternative: ‘lons’
   lonVar = dataFile.getVar("longitude");
   ^~~~~~
   lons
../src/ReadWriteNETCDF.cpp:69:9: error: expected ‘;’ before ‘presVar’
   NcVar presVar, tempVar;
         ^~~~~~~
../src/ReadWriteNETCDF.cpp:70:3: error: ‘presVar’ was not declared in this scope
   presVar = dataFile.getVar("pressure");
   ^~~~~~~
../src/ReadWriteNETCDF.cpp:70:3: note: suggested alternative: ‘pres_in’
   presVar = dataFile.getVar("pressure");
   ^~~~~~~
   pres_in
../src/ReadWriteNETCDF.cpp:72:3: error: ‘tempVar’ was not declared in this scope
   tempVar = dataFile.getVar("temperature");
   ^~~~~~~
../src/ReadWriteNETCDF.cpp:72:3: note: suggested alternative: ‘tempnam’
   tempVar = dataFile.getVar("temperature");
   ^~~~~~~
   tempnam
../src/ReadWriteNETCDF.cpp:75:3: error: ‘vector’ was not declared in this scope
   vector<size_t> startp,countp;
   ^~~~~~
../src/ReadWriteNETCDF.cpp:75:3: note: suggested alternative: ‘perror’
   vector<size_t> startp,countp;
   ^~~~~~
   perror
../src/ReadWriteNETCDF.cpp:75:16: error: expected primary-expression before ‘>’ 
token
   vector<size_t> startp,countp;
                ^
../src/ReadWriteNETCDF.cpp:75:18: error: ‘startp’ was not declared in this scope
   vector<size_t> startp,countp;
                  ^~~~~~
../src/ReadWriteNETCDF.cpp:75:18: note: suggested alternative: ‘strtoq’
   vector<size_t> startp,countp;
                  ^~~~~~
                  strtoq
../src/ReadWriteNETCDF.cpp:75:25: error: ‘countp’ was not declared in this scope
   vector<size_t> startp,countp;
                         ^~~~~~
../src/ReadWriteNETCDF.cpp:110:8: error: ‘NcException’ does not name a type
  catch(NcException& e)
        ^~~~~~~~~~~
../src/ReadWriteNETCDF.cpp:112:3: error: ‘e’ was not declared in this scope
   e.what();
   ^
src/subdir.mk:18: recipe for target 'src/ReadWriteNETCDF.o' failed
make: *** [src/ReadWriteNETCDF.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.

20:15:38 Build Failed. 21 errors, 0 warnings. (took 414ms)


Attachment: Screenshot from 2019-03-10 20-45-48.png
Description: PNG image

  • 2019 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: