/* This is part of the netCDF package. Copyright 2006 University Corporation for Atmospheric Research/Unidata. See COPYRIGHT file for conditions of use. This is an example which reads some surface pressure and temperatures. The data file read by this program is produced companion program sfc_pres_temp_wr.cxx. It is intended to illustrate the use of the netCDF C++ API. This program is part of the netCDF tutorial: http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial Full documentation of the netCDF C++ API can be found at: http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-cxx $Id: sfc_pres_temp_rd.cpp,v 1.6 2010/02/11 22:36:42 russ Exp $ */ #include #include #include using namespace std; using namespace netCDF; using namespace netCDF::exceptions; // We are reading 2D data, a 6 x 12 lat-lon grid. static const int NLAT = 6; static const int NLON = 12; // These are used to calculate the values we expect to find. static const float SAMPLE_PRESSURE = 900; 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 main(void) { // These will hold our pressure and temperature data. float presIn[NLAT][NLON]; float tempIn[NLAT][NLON]; // These will hold our latitudes and longitudes. float latsIn[NLAT]; float lonsIn[NLON]; try { // Open the file and check to make sure it's valid. NcFile dataFile("sfc_pres_temp.nc", NcFile::read); // There are a number of inquiry functions in netCDF which can be // used to learn about an unknown netCDF file. In this case we know // that there are 2 netCDF dimensions, 4 netCDF variables, no // global attributes, and no unlimited dimension. //cout<<"there are "<