NetCDF: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
(Mention PnetCDF)
(Marked this version for translation)
Line 2: Line 2:


<translate>
<translate>
<!--T:1-->
[[Category:Software]]
[[Category:Software]]


= General =
= General = <!--T:2-->


<!--T:3-->
NetCDF (Network Common Data Form) is:
NetCDF (Network Common Data Form) is:
* an interface for array-oriented data access, and  
* an interface for array-oriented data access, and  
Line 11: Line 13:
The NetCDF library also defines a machine-independent format for representing scientific data. Together, the interface, library, and format support the creation, access, and sharing of scientific data.
The NetCDF library also defines a machine-independent format for representing scientific data. Together, the interface, library, and format support the creation, access, and sharing of scientific data.


<!--T:4-->
There were significant changes to the library with the release of version 4.0. NetCDF 4.x is backwards compatible - it can read files produced by an earlier version but the opposite isn't true. Since 4.0 was released in 2008, we will not discuss earlier versions here.
There were significant changes to the library with the release of version 4.0. NetCDF 4.x is backwards compatible - it can read files produced by an earlier version but the opposite isn't true. Since 4.0 was released in 2008, we will not discuss earlier versions here.


<!--T:5-->
* Project web site : https://www.unidata.ucar.edu/software/netcdf
* Project web site : https://www.unidata.ucar.edu/software/netcdf
* Manual: https://www.unidata.ucar.edu/software/netcdf/docs
* Manual: https://www.unidata.ucar.edu/software/netcdf/docs
Line 18: Line 22:
* FAQ: https://www.unidata.ucar.edu/software/netcdf/docs/faq.html
* FAQ: https://www.unidata.ucar.edu/software/netcdf/docs/faq.html


== Strengths ==
== Strengths == <!--T:6-->
* The data are independent of the processor architecture ([https://en.wikipedia.org/wiki/Endianness endianness]).
* The data are independent of the processor architecture ([https://en.wikipedia.org/wiki/Endianness endianness]).
* The data are structured in a way that keeps track of all the pertinent information, e.g. physical units.
* The data are structured in a way that keeps track of all the pertinent information, e.g. physical units.
Line 26: Line 30:
* It's free software for most platforms.
* It's free software for most platforms.


== Weak points ==
== Weak points == <!--T:7-->
* The Python interface doesn't support parallelism (version 1.0.5)
* The Python interface doesn't support parallelism (version 1.0.5)
* Certain files produced with [[HDF5]] cannot be read using NetCDF
* Certain files produced with [[HDF5]] cannot be read using NetCDF


= Quickstart guide =
= Quickstart guide = <!--T:8-->
This section summarizes configuration details.
This section summarizes configuration details.


== Environment modules ==
== Environment modules == <!--T:9-->


<!--T:10-->
The following [[Utiliser des modules/en|modules]] providing NetCDF are available on Compute Canada systems via CVMFS:
The following [[Utiliser des modules/en|modules]] providing NetCDF are available on Compute Canada systems via CVMFS:
* '''netcdf'''
* '''netcdf'''
Line 43: Line 48:
** for linking with programs containing Fortran instructions
** for linking with programs containing Fortran instructions


<!--T:11-->
There is also a set of NetCDF modules compiled with [[MPI]] support for parallel I/O:
There is also a set of NetCDF modules compiled with [[MPI]] support for parallel I/O:
* '''netcdf-mpi'''
* '''netcdf-mpi'''
Line 51: Line 57:
** for linking with programs containing Fortran instructions and calling MPI
** for linking with programs containing Fortran instructions and calling MPI


<!--T:12-->
Run <code>module avail netcdf</code> to see what versions are currently available with the compiler and MPI modules you have loaded. For a comprehensive list of NetCDF modules, run <code>module -r spider '.*netcdf.*'</code>.
Run <code>module avail netcdf</code> to see what versions are currently available with the compiler and MPI modules you have loaded. For a comprehensive list of NetCDF modules, run <code>module -r spider '.*netcdf.*'</code>.


<!--T:13-->
Use <code>module load netcdf/version</code> to set your environment to use your chosen version. For example, to load the NetCDF version 4.1.3 C-based library, do:
Use <code>module load netcdf/version</code> to set your environment to use your chosen version. For example, to load the NetCDF version 4.1.3 C-based library, do:


<!--T:14-->
{{Command|module load netcdf/4.1.3}}
{{Command|module load netcdf/4.1.3}}


== Submission scripts ==
== Submission scripts == <!--T:15-->
Please refer to the page "[[Running_jobs|Running jobs]]" for examples of job scripts for the Slurm workload manager. We recommend you include the <code>module load ...</code> command in your job script.
Please refer to the page "[[Running_jobs|Running jobs]]" for examples of job scripts for the Slurm workload manager. We recommend you include the <code>module load ...</code> command in your job script.


== Linking code to NetCDF libraries ==
== Linking code to NetCDF libraries == <!--T:16-->
Below are a few examples showing how to link NetCDF libraries to C and Fortran code:
Below are a few examples showing how to link NetCDF libraries to C and Fortran code:


=== Serial NetCDF ===
=== Serial NetCDF === <!--T:17-->
For C code,
For C code,
{{Commands
{{Commands
Line 70: Line 79:
}}
}}


<!--T:18-->
For Fortran code, notice that two libraries are required and their order matters:
For Fortran code, notice that two libraries are required and their order matters:
{{Commands
{{Commands
Line 76: Line 86:
}}
}}


=== Parallel NetCDF ===
=== Parallel NetCDF === <!--T:19-->
For C code which calls MPI,
For C code which calls MPI,
{{Commands
{{Commands
Line 83: Line 93:
}}
}}


=== Example ===
=== Example === <!--T:20-->
An example demonstrating the use of the NetCDF can be found at the following [https://www.unidata.ucar.edu/software/netcdf/netcdf-4/newdocs/netcdf-tutorial/simple_005fxy_005fwr_002ec.html#simple_005fxy_005fwr_002ec link]. The example program creates a NetCDF file containing a single two-dimensional variable called "data", and labels the two dimensions "x" and "y".  
An example demonstrating the use of the NetCDF can be found at the following [https://www.unidata.ucar.edu/software/netcdf/netcdf-4/newdocs/netcdf-tutorial/simple_005fxy_005fwr_002ec.html#simple_005fxy_005fwr_002ec link]. The example program creates a NetCDF file containing a single two-dimensional variable called "data", and labels the two dimensions "x" and "y".  
   
   
Line 92: Line 102:
}}
}}


== NetCDF utilities ==
== NetCDF utilities == <!--T:21-->
There are several utilities that read or write files in different formats.
There are several utilities that read or write files in different formats.
* ncdump
* ncdump
Line 101: Line 111:
: Copies a netCDF file and can change binary format, chunk sizes, compression, and other storage settings. See [https://www.unidata.ucar.edu/software/netcdf/workshops/2011/utilities/Nccopy.html nccopy] for more.
: Copies a netCDF file and can change binary format, chunk sizes, compression, and other storage settings. See [https://www.unidata.ucar.edu/software/netcdf/workshops/2011/utilities/Nccopy.html nccopy] for more.


= PnetCDF =
= PnetCDF = <!--T:22-->


<!--T:23-->
PnetCDF is another library for reading and writing NetCDF-format files. It uses different procedure names than NetCDF and provides non-blocking procedures. See the [https://trac.mcs.anl.gov/projects/parallel-netcdf PnetCDF web site] for a detailed discussion.
PnetCDF is another library for reading and writing NetCDF-format files. It uses different procedure names than NetCDF and provides non-blocking procedures. See the [https://trac.mcs.anl.gov/projects/parallel-netcdf PnetCDF web site] for a detailed discussion.


</translate>
</translate>

Revision as of 13:29, 22 March 2018

Other languages:

General[edit]

NetCDF (Network Common Data Form) is:

  • an interface for array-oriented data access, and
  • a library that provides an implementation of the interface.

The NetCDF library also defines a machine-independent format for representing scientific data. Together, the interface, library, and format support the creation, access, and sharing of scientific data.

There were significant changes to the library with the release of version 4.0. NetCDF 4.x is backwards compatible - it can read files produced by an earlier version but the opposite isn't true. Since 4.0 was released in 2008, we will not discuss earlier versions here.

Strengths[edit]

  • The data are independent of the processor architecture (endianness).
  • The data are structured in a way that keeps track of all the pertinent information, e.g. physical units.
  • NetCDF4 can read and write in parallel, if it is built using a parallel version of HDF5.
  • Data can be compressed as it is written.
  • A simpler interface than HDF5.
  • It's free software for most platforms.

Weak points[edit]

  • The Python interface doesn't support parallelism (version 1.0.5)
  • Certain files produced with HDF5 cannot be read using NetCDF

Quickstart guide[edit]

This section summarizes configuration details.

Environment modules[edit]

The following modules providing NetCDF are available on Compute Canada systems via CVMFS:

  • netcdf
    • for linking with programs containing C instructions only
  • netcdf-c++
    • for linking with programs containing both C and C++ instructions
  • netcdf-fortran
    • for linking with programs containing Fortran instructions

There is also a set of NetCDF modules compiled with MPI support for parallel I/O:

  • netcdf-mpi
    • for linking with programs containing C instructions and calling MPI libraries
  • netcdf-c++-mpi
    • for linking with programs containing both C and C++ instructions and calling MPI
  • netcdf-fortran-mpi
    • for linking with programs containing Fortran instructions and calling MPI

Run module avail netcdf to see what versions are currently available with the compiler and MPI modules you have loaded. For a comprehensive list of NetCDF modules, run module -r spider '.*netcdf.*'.

Use module load netcdf/version to set your environment to use your chosen version. For example, to load the NetCDF version 4.1.3 C-based library, do:

Question.png
[name@server ~]$ module load netcdf/4.1.3

Submission scripts[edit]

Please refer to the page "Running jobs" for examples of job scripts for the Slurm workload manager. We recommend you include the module load ... command in your job script.

Linking code to NetCDF libraries[edit]

Below are a few examples showing how to link NetCDF libraries to C and Fortran code:

Serial NetCDF[edit]

For C code,

[name@server ~]$ module load netcdf/4.4.1
[name@server ~]$ gcc example.c -lnetcdf


For Fortran code, notice that two libraries are required and their order matters:

[name@server ~]$ module load netcdf-fortran
[name@server ~]$ gfortran example.f90 -lnetcdf -lnetcdff


Parallel NetCDF[edit]

For C code which calls MPI,

[name@server ~]$ module load netcdf-mpi
[name@server ~]$ gcc example.c -lnetcdf


Example[edit]

An example demonstrating the use of the NetCDF can be found at the following link. The example program creates a NetCDF file containing a single two-dimensional variable called "data", and labels the two dimensions "x" and "y".

To compile the example:

[name@server ~]$ module load netcdf
[name@server ~]$ gcc ex_netcdf4.c -lnetcdf


NetCDF utilities[edit]

There are several utilities that read or write files in different formats.

  • ncdump
"The ncdump tool generates the CDL text representation of a netCDF dataset on standard output, optionally excluding some or all of the variable data in the output. The output from ncdump is intended to be acceptable as input to ncgen. Thus ncdump and ncgen can be used as inverses to transform data representation between binary and text representation." See ncdump on the UCAR site for more.
  • ncgen
This utility takes an input file in CDL format and creates a binary netCDF file. It is the reverse of ncdump. See ncgen for more.
  • nccopy
Copies a netCDF file and can change binary format, chunk sizes, compression, and other storage settings. See nccopy for more.

PnetCDF[edit]

PnetCDF is another library for reading and writing NetCDF-format files. It uses different procedure names than NetCDF and provides non-blocking procedures. See the PnetCDF web site for a detailed discussion.