NetCDF: Difference between revisions

Jump to navigation Jump to search
210 bytes added ,  6 years ago
no edit summary
No edit summary
No edit summary
Line 3: Line 3:
= General =
= General =


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.
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 this version was released in 2008, this is the one we will focus our attention on.
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.


* Project web site : https://www.unidata.ucar.edu/software/netcdf
* Project web site : https://www.unidata.ucar.edu/software/netcdf
Line 14: Line 17:
== Strengths ==
== Strengths ==
* 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.
* NetCDF4 can read and write in parallel, if it is built using a parallel version of [[HDF5]].
* 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.
* Data can be compressed as it is written.
Line 29: Line 32:
== Environment modules ==
== Environment modules ==


The following 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'''
** for linking with the codes containing C instructions only  
** for linking with programs containing C instructions only  
* '''netcdf-c++'''
* '''netcdf-c++'''
** for linking with the codes containing both C and C++ instructions
** for linking with programs containing both C and C++ instructions
* '''netcdf-fortran'''
* '''netcdf-fortran'''
** for linking with the codes containing Fortran instructions
** for linking with programs containing Fortran instructions


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'''
** for linking with the codes containing C instructions within the MPI environment
** for linking with programs containing C instructions and calling MPI libraries
* '''netcdf-c++-mpi'''  
* '''netcdf-c++-mpi'''  
** for linking with the codes containing both C and C++ instructions within the MPI environment
** for linking with programs containing both C and C++ instructions and calling MPI
* '''netcdf-fortran-mpi'''
* '''netcdf-fortran-mpi'''
** for linking with the codes containing Fortran instructions within the MPI environment
** for linking with programs containing Fortran instructions and calling MPI


The versions available: 4.1.3, 4.2.0, 4.3.0, 4.4.1, 4.4.4
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>.


== Version selection ==
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:
'''module load netcdf/version'''


For example, in order to load the NetCDF C-based library of version 4.1.3 do the following:
{{Command|module load netcdf/4.1.3}}
 
'''module load netcdf/4.1.3'''


== Submission scripts ==
== Submission scripts ==
Please refer to the page "[[Running_jobs|Running jobs]]" for help on using the SLURM workload manager.
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 the NetCDF libraries ==
== Linking code to NetCDF libraries ==
Below are the few example showing how to link the NetCDF libraries in serial and parallel mode for both C and Fortran:
Below are a few examples showing how to link NetCDF libraries to C and Fortran code:


=== Serial NetCDF ===
=== Serial NetCDF ===
Using netcdf
For C code,
{{Commands
{{Commands
|module load netcdf/4.4.1
|module load netcdf/4.4.1
Line 67: Line 67:
}}
}}


Using netcdf-fortran
For Fortran code, notice that two libraries are required and their order matters:
{{Commands
{{Commands
|module load netcdf-fortran
|module load netcdf-fortran
Line 74: Line 74:


=== Parallel NetCDF ===
=== Parallel NetCDF ===
Using netcdf-mpi
For C code which calls MPI,
{{Commands
{{Commands
|module load netcdf-mpi
|module load netcdf-mpi
Line 81: Line 81:


=== Example ===
=== Example ===
There is a relatively simple example demonstrating the use of the NetCDF which 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]. In that example the code writes a 2D netCDF variable (called "data") and fills it
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".  
with sample data.  It has two dimensions, "x" and "y".
   
   
In order to compile that code you need to have the NetCDF4 library set in your environment (in your LD_LIBRARY_PATH to be precisely) :
To compile the example:
{{Command
{{Commands
|module load netcdf
|gcc ex_netcdf4.c -lnetcdf
|gcc ex_netcdf4.c -lnetcdf
}}
}}
Bureaucrats, cc_docs_admin, cc_staff
2,879

edits

Navigation menu