• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    C++
  • License
    Other
  • Created over 11 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official GitHub repository for netCDF-C++ libraries and utilities.

Build Status

netcdf-cxx4

Official GitHub repository for netCDF-4 C++ library.

Note: The latest release of the historic C++ libraries, netCDF-4.2, may be downloaded from the following page:

Introduction

Lynton Appel, of the Culham Centre for Fusion Energy (CCFE) in Oxfordshire, has developed and contributed a netCDF-4 C++ library that depends on an installed netCDF-4 C library. The netCDF-4 C++ API was developed for use in managing fusion research data from CCFE's innovative MAST (Mega Amp Spherical Tokamak) experiment.

Appel's C++ implementation is a complete read/write interface for netCDF-4, but can also be used as an alternative to the older netCDF-3 C++ interface, to write classic-format netCDF-3 files as well as netCDF-4 classic model files. The new API is implemented as a layer over the netCDF-4 C interface, which means bug fixes and performance enhancements in the C interface will be immediately available to C++ developers as well. It replaces a previous partial netCDF-4 C++ interface developed by Shanna Forbes.

The new API makes use of standard C++ features such as namespaces, exceptions, and templates, none of which were included in the first netCDF-3 C++ API developed in the mid-90's. The earlier netCDF-3 C++ API is still supported and available in the source distribution, but developers who are thinking of eventually upgrading to use of the enhanced data model should consider using Lynton's new API.

We're grateful for Appel's development and CCFE's contribution of the new open-source code for the netCDF-4 C++ API, and hope C++ developers in the netCDF community will find it useful! Feedback is appreciated, and should be directed to Lynton Appel.

Installation

The C++ interface requires the C library to have been build with the netCDF-4 API (this is the default in recent versions). You can check by running:

$ nc-config --has-nc4
yes

The simplest way to build the C++ interface is with CMake:

mkdir build
cd build
cmake ..
make
ctest
make install

Make sure that either nc-config is in your PATH, or that the location of netCDFConfig.cmake is in CMAKE_PREFIX_PATH.

There is also an autotools-based build system:

mkdir build
cd build
../configure
make
make check
make install

Note that the "configure" script must be generated using

autoreconf -if

To build the C++ interface guide, change to the cxx4 directory of the distribution and enter

doxygen

By default, HTML documentation will be installed in cxx4/doc/html; other options may be specified according to the settings contained in the file "Doxyfile" (details of alternative settings are documented at doxygen). Note that as a prerequisite for generating the documentation, the system will need to have doxygen and Graphviz installed.

Examples of usage

Here is an example of writing a 2D array to a file, and then reading it back in:

#include <iostream>
#include <netcdf>

// We are writing 2D data, a 6 x 12 grid
constexpr int nx = 6;
constexpr int ny = 12;

// Return this in event of a problem
constexpr int nc_err = 2;

int main() {
  // The default behavior of the C++ API is to throw an exception if
  // an error occurs
  try {
    // This is the data array we will write. It will just be filled
    // with a progression of numbers for this example.
    int dataOut[nx][ny];

    // Create some pretend data. If this wasn't an example program, we
    // would have some real data to write, for example, model output.
    for (int i = 0; i < nx; i++) {
      for (int j = 0; j < ny; j++) {
        dataOut[i][j] = i * ny + j;
      }
    }

    // Create the file. The Replace parameter tells netCDF to overwrite
    // this file, if it already exists.
    netCDF::NcFile dataFile("simple_xy.nc", netCDF::NcFile::replace);

    // Create netCDF dimensions
    auto xDim = dataFile.addDim("x", nx);
    auto yDim = dataFile.addDim("y", ny);

    // Define the variable. The type of the variable in this case is
    // ncInt (32-bit integer)
    auto data = dataFile.addVar("data", netCDF::ncInt, {xDim, yDim});

    // Write the data to the file. Although netCDF supports reading
    // and writing subsets of data, in this case we write all the data
    // in one operation.
    data.putVar(dataOut);

    // The file will be automatically close when the NcFile object goes
    // out of scope. This frees up any internal netCDF resources
    // associated with the file, and flushes any buffers.
  } catch (netCDF::exceptions::NcException &e) {
    std::cout << e.what() << std::endl;
    return nc_err;
  }

  // Now read the data back in
  try {
    // This is the array we will read into
    int dataIn[nx][ny];

    // Open the file for read access
    netCDF::NcFile dataFile("simple_xy.nc", netCDF::NcFile::read);

    // Retrieve the variable named "data"
    auto data = dataFile.getVar("data");
    if (data.isNull())
      return nc_err;
    data.getVar(dataIn);

    // Check the values.
    for (int i = 0; i < nx; i++) {
      for (int j = 0; j < ny; j++) {
        if (dataIn[i][j] != i * ny + j) {
          return nc_err;
        }
      }
    }
  } catch (netCDF::exceptions::NcException &e) {
    std::cout << e.what() << std::endl;
    return nc_err;
  }
}

More Repositories

1

MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
Python
1,241
star
2

netcdf4-python

netcdf4-python: python/numpy interface to the netCDF C library
Cython
754
star
3

netcdf-c

Official GitHub repository for netCDF-C libraries and utilities.
C
501
star
4

thredds

THREDDS Data Server v4.6
265
star
5

netcdf-fortran

Official GitHub repository for netCDF-Fortran libraries, which depend on the netCDF C library. Install the netCDF C library first.
Fortran
231
star
6

siphon

Siphon - A collection of Python utilities for retrieving atmospheric and oceanic data from remote sources, focusing on being able to retrieve data from Unidata data technologies, such as the THREDDS data server.
Python
212
star
7

awips2

Weather forecasting display and analysis package developed by NWS/Raytheon, released as open source software by Unidata.
Java
171
star
8

python-workshop

A series of Jupyter Notebooks on exploring Unidata technology with Python. See website for more information.
Jupyter Notebook
148
star
9

netcdf-java

The Unidata netcdf-java library
Java
144
star
10

python-training

Notebooks teaching Python for use meteorology and atmospheric and climate sciences.
Jupyter Notebook
125
star
11

python-gallery

Repository of examples showing off the use of Python for meteorology.
Python
87
star
12

IDV

The Integrated Data Viewer (IDV) from Unidata is a framework for analyzing and displaying geoscience data.
Java
79
star
13

cftime

Time-handling functionality from netcdf4-python.
Python
75
star
14

gempak

Analysis and product generation for meteorological data.
C
69
star
15

tomcat-docker

Security-hardened Tomcat container for thredds-docker and ramadda-docker
Shell
65
star
16

tds

THREDDS Data Server
Java
63
star
17

UDUNITS-2

API and utility for arithmetic manipulation of units of physical quantities
C
60
star
18

online-python-training

Repo for materials associated with the Online Python Training (OPT) project
CSS
50
star
19

LDM

The Unidata Local Data Manager (LDM) system includes network client and server programs designed for event-driven data distribution, and is the fundamental component of the Unidata Internet Data Distribution (IDD) system.
C
43
star
20

python-awips

A framework for querying AWIPS meteorological datasets from an EDEX Data Server.
Python
40
star
21

thredds-docker

Dockerized THREDDS
Dockerfile
33
star
22

cloudstream

Docker-based framework for Application Streaming
Shell
29
star
23

science-gateway

Unidata Science Gateway on the NSF Jetstream2 Cloud
TeX
19
star
24

HurricaneTracker

Hurricane Track Visualization in Python
Python
19
star
25

rosetta

ρ΢ητα β‡’ rosetta
Java
17
star
26

pyCWT

Continuous Wavelet Transform Library for Python
Python
16
star
27

jj2000

Fork of jpeg2k code from https://code.google.com/p/jj2000/.
Java
16
star
28

compression

Provide a standard source set (and build) for various compression libraries
C
13
star
29

ldm-docker

Dockerized LDM
Tcl
12
star
30

ldm-alchemy

Python tools to handle LDM data feeds and convert to other formats.
Python
12
star
31

metpy-mondays

Jupyter Notebook
11
star
32

CloudAWIPS

AWIPS CAVE Streaming in a CentOS 7 Virtual Environment
Shell
11
star
33

git-recipes

Useful Git recipes
10
star
34

ttm

Provide a reference implementation for the TTM programming language.
C
9
star
35

ncWMS

Snapshots of ncWMS used by TDS
Java
8
star
36

FMTP

File Multicast Transfer Protocol
C++
8
star
37

unidata-users-workshop

Unidata Users Workshop
8
star
38

threddsIso

A THREDDS Data Server extension which generates NCML, a metadata rubric, and ISO 19115.
XSLT
7
star
39

yax

The goal of the yax project is to allow the use of YACC (Gnu Bison actually) to parse/process XML documents.
Python
7
star
40

EC-netCDF-CF

EarthCube: Advancing netCDF-CF Project
7
star
41

users-workshop-2023

Repo covering Jupyter Notebook resources for Unidata's 2023 triennial meeting held in Boulder, Colorado
Jupyter Notebook
7
star
42

station-lists

Lists of locations of weather stations for shared use by other projects.
C
6
star
43

netCDF-Decoders

Routines that encode meteorological data in netCDF format
C
6
star
44

netcdf

NetCDF Users Group (NUG)
Makefile
6
star
45

TdsConfig

Contents of TDS configuration directories for several variants including a TDS serving all Unidata IDD data
XSLT
6
star
46

metpy-analysis

Materials for the 2-day course on MetPy for Quantitative Analysis of Meteorological Data
Jupyter Notebook
6
star
47

metpy-ams-2023

Materials for the 2023 AMS short course "MetPy for your Data Analyzing Meteorological Observations in Python"
Jupyter Notebook
5
star
48

cloudidv

Repository for the Cloud-Based IDV
Python
5
star
49

pyaos-ams-2021

Jupyter Notebook
5
star
50

netCDF-Perl

Perl interface to the (deprecated) netCDF 2 API
M4
5
star
51

docker-nctests

Docker configuration files for building netCDF regression testing containers.
Shell
5
star
52

pyaos-ams-2020

Unidata AMS 2020 Student Conference PyAOS Workshop
Jupyter Notebook
5
star
53

Unidata-Dockerfiles

Unidata Dockerfiles
HTML
4
star
54

WorldWeatherSymbol_font

Building a TTF font from WMO weather symbols in SVG format
4
star
55

tdm-docker

Dockerized TDM
Shell
4
star
56

sruth

Java
4
star
57

awips2-core

Java
3
star
58

Garp

GARP (GEMPAK Analysis and Rendering Program)
C
3
star
59

awips2-ncep

Java
3
star
60

drilsdown

Drawing Rich Integrated Lat-lon- time Samples from Datasets Online into Working Notebooks
Jupyter Notebook
3
star
61

jpattern

The goal of the jpattern project is to provide a reference Java implementation of the Snobol4 primitives as implemented by Robert Dewar in Ada.
Java
3
star
62

nexus-tools

A set of shell scripts to manage publications within raw repositories on the Unidata nexus artifacts server.
Shell
2
star
63

GEMPAK-Tables

Makefile
2
star
64

UnidataRadarApp

Unidata Radar App
Java
2
star
65

awips-ml

Python
2
star
66

uncc-workshop-2020

Supporting materials for the 2020 Unidata workshop at UNC Charlotte
Jupyter Notebook
2
star
67

cloudcontrol

CloudControl is a web-based dashboard which provides administrative controls to deploy and manage Docker images in the cloud.
Java
2
star
68

ucar-intern-pdws

Materials from teaching the UCAR Summer Intern Professional Development Workshop Series event on Python
Jupyter Notebook
2
star
69

awips2-goesr

AWIPS GOES-R Plugins
Java
2
star
70

python-readiness

Materials for Unidata's Python Readiness workshop series equipping students with skills for their coursework and research.
Jupyter Notebook
2
star
71

metpy-bams-2022

Scripts used to generate images for the MetPy 2022 BAMS publication
Jupyter Notebook
2
star
72

rtstats

Unidata rtstats revamp
Python
2
star
73

Wave

Weather Analysis and Visualization Environment
Python
2
star
74

awips2-gemlibs

GEMPAK and NSHARP libraries for AWIPS II
C
2
star
75

github-utils

Utility scripts using GitHub's REST API.
Python
2
star
76

bison.py

The goal of this project is allow the use of ''Bison'' to generate parsers for Python.
Shell
1
star
77

awips2-hazards

AWIPS Hazard Services Plugins
Java
1
star
78

dcredbook-util

C Shell scripts to output NWS Redbook graphics to GIF, PostScript and Vector Graphic files.
Shell
1
star
79

awips2-tools

AWIPS II Automation Tools provided by the National Weather Service
Shell
1
star
80

pygcdm

Python
1
star
81

thredds-test-data

PowerShell
1
star
82

awips2-drawing

AWIPS Drawing Tool
Java
1
star
83

awips2-data-delivery

Java
1
star
84

awips2-gsd

GSD AWIPS Plugins
Java
1
star
85

unidata-gempak-workshop

Scripts made available for the Unidata GEMPAK training workshop
Shell
1
star
86

awips2-rpm

HTML
1
star
87

unidata.github.io

Basic gh-pages site to point users to our main website
HTML
1
star
88

awips2-ogc

OGC AWIPS Plugins
Java
1
star
89

pyaos-ams-2023

Materials for the AMS 2023 Student Conference Python Workshop.
Jupyter Notebook
1
star
90

ou-workshop-2020

Supporting materials for Unidata 2020 workshop at OU.
Jupyter Notebook
1
star
91

ast.obsolete

The goal of the ast system is provide a pure Java implementation of the Google protobuf system.
Shell
1
star
92

awips2-swpc

SWPC AWIPS Plugins
Java
1
star
93

MLscratchpad

Jupyter Notebook
1
star
94

thredds-performance-tests

Python
1
star