tags: netcdf read c++
Transfer from: http://blog.sina.com.cn/s/blog_687960370101hiks.html
1. First download the c++ interface version of netcdf, download address: https://www.unidata.ucar.edu/downloads/netcdf/netcdf-cxx/index.jsp
2. Download the C language version of netcdf, download address: https://www.unidata.ucar.edu/software/netcdf/docs/winbin.html (note 32-bit and 64-bit, this version is exe version, install it directly Generate include, lib and bin files)
Instructions:
1. Unzip the compressed package of netcdf-cxx, you will get cxx, example, m4, man4 and several configuration files;
2. Change config.h.in in the configuration file to config.h;
3. We need to use five files config.h, ncvalues.h, netcdfcpp.h, ncvalues.cpp and netcdf.cpp in total;
4. Put these five files in your project directory, add them to the project header file and source file, in the VS project properties-VC++ directory-include directory, add config.h, netcdfcpp.h, ncvalues.h and netcdf The location of the .h header file;
5. Add netcdf's c language header file netcdf.h, dynamic link library netcdf.dll and library file netcdf.lib to VS, project properties in VS-linker-general-additional library directory, add here The path of netcdf.dll in your bin file. Although I added it here, the netcdf.dll file is missing during runtime. You can put it in the corresponding folder of the project exe. The project properties in VS—linker—input— —Additional dependencies, add the netcdf.lib library file here, project properties in VS-VC++ directory-include directory, add the location of the netcdf.h header file, project properties in VS-VC++ directory-library directory, add netcdf The location of the .lib library file.
This completes the configuration of the netcdf library under c++.
You can use the following code to test
This is to write data, if the operation is successful, the corresponding nc data will be generated in the project directory
#include <iostream>
#include <netcdfcpp.h>
using namespace std;
static const int NX = 6;
static const int NY = 12;
static const int NC_ERR = 2;
int main(void)
{
int dataOut[NX][NY];
for(int i = 0; i < NX; i++)
for(int j = 0; j < NY; j++)
dataOut[i][j] = i * NY + j;
NcFile dataFile("simple_xy.nc", NcFile::Replace);
if (!dataFile.is_valid())
{
cout << "Couldn't open file!\n";
return NC_ERR;
}
NcDim* xDim = dataFile.add_dim("x", NX);
NcDim* yDim = dataFile.add_dim("y", NY);
NcVar *data = dataFile.add_var("data", ncInt, xDim, yDim);
data->put(&dataOut[0][0], NX, NY);
cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
return 0;
}
#include <iostream>
#include <netcdfcpp.h>
using namespace std;
static const int NX = 6;
static const int NY = 12;
static const int NC_ERR = 2;
int main(void)
{
int dataIn[NX][NY];
NcFile dataFile("simple_xy.nc", NcFile::ReadOnly);
if (!dataFile.is_valid())
{
cout << "Couldn't open file!\n";
return NC_ERR;
}
NcVar *data = dataFile.get_var("data");
data->get(&dataIn[0][0], NX, NY);
for (int i = 0; i < NX; i++)
for (int j = 0; j < NY; j++)
{
if (dataIn[i][j] != i * NY + j)
return NC_ERR;
cout<<dataIn[i][j]<<endl;
}
cout << "*** SUCCESS reading example file simple_xy.nc!" << endl;
system("pause");
return 0;
}
Show the contents of the NetCDF file. Read the data from the 'RAINF_F_TAVG' variable. Drawing Complete code Article reference MATLAB help documentation imports Netcdf files and OpenDAP data...
Static storage variables are usually assigned to storage units at the time of variable definition and remain unchanged until the end of the entire program. The dynamic storage variable is allocated du...
The previous blog introduced how to use C++ to implement sequential stacks. You can check the following link: Like linear tables, the stack also has a chain storage structure, referred to as:Chain sta...
C# program simply realizes data storage through txt text The function will be realized by a simple winform program under the .net platform: The main window interface is as follows The winform program ...
Reference book: "Data Structure" C language version (2nd version)...
Reference to Yan Weimin's "Data Structure" (C language version) The queue is a special linear table. The rules are the data that enters the queue first. The tip of this article points to a s...
A program written for students, the purpose is to merge many NC data together, and the variable name of each .nc data is the same. I usually read more .nc data, less involved writing. I used IDL first...
As we all know, GeoServer is a geographic server that provides management pages for service publishing, styles, slicing, layer previews and a series of operations, but manual page configuration someti...
.•NetCDFFull namenetwork Common Data Format, Chinese translation is "network common data format"; •netcdfThe purpose of the document was to store data in meteorological science and...