The NcdfUtilities package: Difference between revisions

From Geos-chem
Jump to navigation Jump to search
Line 12: Line 12:
== NcdfUtilities as a standalone distribution ==
== NcdfUtilities as a standalone distribution ==


The following sections describe


=== Downloading the NcdfUtilities standalone package ===


The following sections describe
You can download a copy of the NcdfUtilities standalone package with the Git source code management system.  The master NcdfUtilities code repository is hosted on Bitbucket.org.  To download the code, type:
 
git clone <nowiki>https://bitbucket.org/gcst/ncdfutilities.git</nowiki> NcdfUtil
 
This will download the NcdfUtilities into a folder named <tt>NcdfUtil</tt> in your disk space.


=== ties Directory Structure:
=== Directory structure of the NcdfUtilities standalone package ===
=== Standalone directory structure ===


If you download the NcdfUtilities as a standalone package, the root-level directory will contain the following sub-directories:
If you download the NcdfUtilities as a standalone package, the root-level directory will contain the following sub-directories:
Line 101: Line 106:
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 18:43, 8 March 2017 (UTC)
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 18:43, 8 March 2017 (UTC)


=== Compiling the NcdfUtilities Library ===
=== Compiling the NcdfUtilities code ===


The NcdfUtilities/Code directory contains the Fortran source code modules
The <tt>NcdfUtilities/Code</tt> directory contains the Fortran source code modules as well as two Makefiles (named Makefile and Makefile_header.mk).   
as well as two Makefiles (named Makefile and Makefile_header.mk).   


The file "Makefile_header.mk" is a sub-makefile which is used to define the
The file <tt>Makefile_header.mk</tt> is a sub-makefile which is used to define the compilation options for different compilers.  At present, the [[Intel Fortran Compiler]], [[GNU Fortran compiler]], and [[PGI Fortran compiler]] are supported.
compilation options for different compilers.  At present, the ifort, gfortran,
and pgfortran compilers are supported.


Once you have set the proper environment variables for your system (as
Once you have set the proper environment variables for your system (as described above), you are ready to build the executable.  Make sure you are  
described above), you are ready to build the executable.  Make sure you are  
in the Code/ subdirectory and type:
in the Code/ subdirectory and type:


  make lib
make lib


This should start building the source code and create a library file
This should start building the source code and create a library file named <tt>libNcUtils.a</tt> in the lib/ subdirectory.   
named "libNcUtils.a" in the lib/ subdirectory.   
 
If you would like to build the NcdfUtilities for a HPC-environment, then type:
 
make lib HPC=yes
 
This will compile the code using the <tt>mpif90</tt> compiler wrapper rather than the underlying compilers themselves.  This will activate the various MPI settings.
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 18:55, 8 March 2017 (UTC)


=== Testing the NcdfUtilities Library ===
=== Testing the NcdfUtilities Library ===


Once the "libNcUtils.a" file has been created in the lib/ subdirectory, you
Once the "libNcUtils.a" file has been created in the lib/ subdirectory, you can test to see if the library was created (and can link to) the netCDF
can test to see if the library was created (and can link to) the netCDF
library correctly.  Type:
library correctly.  Type:


  make check
make check


This will create an executable file named "TestNcdfUtilities.x" in the
This will create an executable file named "TestNcdfUtilities.x" in the bin subdirectory, and will also execute the file.  If the libNcUtils.a  
bin subdirectory, and will also execute the file.  If the libNcUtils.a  
library was installed correctly you should see the following output:
library was installed correctly you should see the following output:


  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%  Testing libNcdfUtilities.a  %%%
%%%  Testing libNcdfUtilities.a  %%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  === Begin netCDF file creation test ===
=== Begin netCDF file creation test ===
  Writing XDim (# lons)  to netCDF file
Writing time  (dim    ) to netCDF file
  Writing YDim (# lats)  to netCDF file
Writing lev   (dim    ) to netCDF file
  Writing ZDim (# alts)   to netCDF file
Writing lat  (dim    ) to netCDF file
  Writing LON (1D array) to netCDF file
Writing lon   (dim    ) to netCDF file
  Writing LAT (1D array) to netCDF file
Writing cdim1 (dim    ) to netCDF file
  Writing PLEV (1D array) to netCDF file
Writing cdim2 (dim    ) to netCDF file
  Writing PS   (2D array) to netCDF file
Testing re-opening of define mode
  Writing T   (3D array) to netCDF file
  Writing lon  (1D array) to netCDF file
  === End netCDF file creation test ===
Writing lat  (1D array) to netCDF file
  === Begin netCDF file reading test ===
  Writing lev  (1D array) to netCDF file
  Reading XDim back from netCDF file...........PASSED
Writing time  (1D array) to netCDF file
  Reading YDim back read from netCDF...........PASSED
Writing PS   (3D array) to netCDF file
  Reading ZDim back from netCDF file...........PASSED
Writing T     (4D array) to netCDF file
  Reading LON back from netCDF file...........PASSED
Writing DESC  (2D char ) to netCDF file
  Reading LAT back from netCDF file...........PASSED
=== End netCDF file creation test ===
  Reading PLEV back from netCDF file...........PASSED
=== Begin netCDF file reading test ===
  Reading PS  back from netCDF file...........PASSED
Reading lon  (dim  )  back from netCDF file...........PASSED
   Reading T   back from netCDF file...........PASSED
Reading lat  (dim  )  back from netCDF file...........PASSED
  === End of netCDF file read test! ===
Reading lev  (dim  )  back from netCDF file...........PASSED
 
Reading time  (dim  )  back from netCDF file...........PASSED
If all of the tests return with "PASSED" then the libNcUtils.a file was
Reading cdim1 (dim  )  back from netCDF file...........PASSED
created correctly and you have
Reading cdim2 (dim  )  back from netCDF file...........PASSED
Reading lon  (array)  back from netCDF file...........PASSED
Reading lat  (array)  back from netCDF file...........PASSED
Reading lev  (array) back from netCDF file...........PASSED
Reading time  (array)  back from netCDF file...........PASSED
  Reading PS            back from netCDF file...........PASSED
Reading PS:units      back from netCDF file...........PASSED
Reading PS:long_name   back from netCDF file...........PASSED
Reading PS:_FillValue  back from netCDF file...........PASSED
Reading PS:valid_range back from netCDF file...........PASSED
Reading T              back from netCDF file...........PASSED
Reading T:units        back from netCDF file...........PASSED
Reading T:long_name   back from netCDF file...........PASSED
Reading T:_FillValue  back from netCDF file...........PASSED
Reading T:valid_range  back from netCDF file...........PASSED
Reading DESC          back from netCDF file...........PASSED
Reading DESC:units    back from netCDF file...........PASSED
Reading DESC:long_name back from netCDF file...........PASSED
Reading title          back from netCDF file...........PASSED
Reading start_date    back from netCDF file...........PASSED
Reading start_time    back from netCDF file...........PASSED
=== End of netCDF file read test! ===


If all of the tests return with "PASSED" then the <tt>libNcUtils.a</tt> file was created correctly.


Building the NcdfUtilities Reference Documentation:
=== Generating reference documentation for the standalone NcdfUtilities package ===
=== Building ===


The NcdfUtilities Fortran source code and Makefiles use the ProTeX automatic documentation system.  This enables you to create reference documents in <tt>*.pdf</tt> and <tt>*.ps</tt> format from the comments in the subroutine headers.
The NcdfUtilities Fortran source code and Makefiles use the ProTeX automatic documentation system.  This enables you to create reference documents in <tt>*.pdf</tt> and <tt>*.ps</tt> format from the comments in the subroutine headers.

Revision as of 18:55, 8 March 2017

The NcdfUtilities package contains Fortran modules that you can use to write data to and read data from netCDF files. This package is contained within GEOS-Chem (in the NcdfUtil/ folder, but may also be downloaded as a separate standalone package.

List of modules

NcdfUtilities within GEOS-Chem

Setting environment variables for GEOS-Chem

NcdfUtilities as a standalone distribution

The following sections describe

Downloading the NcdfUtilities standalone package

You can download a copy of the NcdfUtilities standalone package with the Git source code management system. The master NcdfUtilities code repository is hosted on Bitbucket.org. To download the code, type:

git clone https://bitbucket.org/gcst/ncdfutilities.git NcdfUtil

This will download the NcdfUtilities into a folder named NcdfUtil in your disk space.

Directory structure of the NcdfUtilities standalone package

If you download the NcdfUtilities as a standalone package, the root-level directory will contain the following sub-directories:

Sub-directory Description
Code/ The Fortran source code files (*.F *.F90) reside here.
bin/ The TestNcdfUtilities.x executable will be created here.
doc/ The NcdfUtilities documentation will be created here.
lib/ The NetCdfUtilities library file (libNcUtils.a) will be created here.
mod/ Compiled module files (*.mod) will be created here.
perl/ Several perl scripts that can be useful in creating netCDF files are contained here.

System requirements for using NcdfUtilities

  1. In order to use NcdfUtilities, you will first have to check to see if the netCDF library is installed on your system. You may find that there are several netCDF library versions to select from. Or you can ask your IT staff to build you a version.

  2. In order to build the reference documents (described below), you must have the LaTeX utilities (i.e. latex, dvips, dvipdf) installed on your system.

Setting enviroment variables for the standalone NcdfUtilities package

The NcdfUtilities library requires that you set the following environment variables listed below in your system startup file (e.g. .bashrc or .cshrc).

NOTE: If you load a netCDF library into your Unix environment with the module command, then very often the root path to the netCDF library will be automatically set for you. Then you can use this to define the variables listed below. Ask your IT staff for more information.

Variable Description
NETCDF_BIN The bin/ folder of the netCDF installation, where utilities such as nc-config, ncdump, etc. are stored.
NETCDF_INCLUDE The include/ folder of the netCDF installation, where the netcdf.inc and netcdf_mod.F90 are found.
NETCDF_LIB The lib/ or lib64/ folder of the netCDF installation, where the netCDF library files (e.g. libnetcdf.a) are found.

NOTE: In netCDF-4.2 and higher versions, the netCDF Fortran libraries are built from a separate distribution. If on your system, the netCDF-Fortran libraries have been installed into a different folder than the rest of the netCDF libaries, you will also need to set these environment variables in your system startup file:

Variable Description
NETCDF_FORTRAN_BIN The bin/ folder of the netCDF-Fortran installation, where utilities such as nf-config is stored.
NETCDF_FORTRAN_INCLUDE The include/ folder of the netCDF-Fortran installation, where the netcdf.inc and netcdf_mod.F90 are found.
NETCDF_FORTRAN_LIB The lib/ or lib64/ folder of the netCDF-Fortran installation, where the netCDF-Fortran library files (e.g. libnetcdff.a) are found.

--Bob Yantosca (talk) 18:43, 8 March 2017 (UTC)

Compiling the NcdfUtilities code

The NcdfUtilities/Code directory contains the Fortran source code modules as well as two Makefiles (named Makefile and Makefile_header.mk).

The file Makefile_header.mk is a sub-makefile which is used to define the compilation options for different compilers. At present, the Intel Fortran Compiler, GNU Fortran compiler, and PGI Fortran compiler are supported.

Once you have set the proper environment variables for your system (as described above), you are ready to build the executable. Make sure you are in the Code/ subdirectory and type:

make lib

This should start building the source code and create a library file named libNcUtils.a in the lib/ subdirectory.

If you would like to build the NcdfUtilities for a HPC-environment, then type:

make lib HPC=yes

This will compile the code using the mpif90 compiler wrapper rather than the underlying compilers themselves. This will activate the various MPI settings.

--Bob Yantosca (talk) 18:55, 8 March 2017 (UTC)

Testing the NcdfUtilities Library

Once the "libNcUtils.a" file has been created in the lib/ subdirectory, you can test to see if the library was created (and can link to) the netCDF library correctly. Type:

make check

This will create an executable file named "TestNcdfUtilities.x" in the bin subdirectory, and will also execute the file. If the libNcUtils.a library was installed correctly you should see the following output:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%  Testing libNcdfUtilities.a  %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=== Begin netCDF file creation test ===
Writing time  (dim     ) to netCDF file
Writing lev   (dim     ) to netCDF file
Writing lat   (dim     ) to netCDF file
Writing lon   (dim     ) to netCDF file
Writing cdim1 (dim     ) to netCDF file
Writing cdim2 (dim     ) to netCDF file
Testing re-opening of define mode
Writing lon   (1D array) to netCDF file
Writing lat   (1D array) to netCDF file
Writing lev   (1D array) to netCDF file
Writing time  (1D array) to netCDF file
Writing PS    (3D array) to netCDF file
Writing T     (4D array) to netCDF file
Writing DESC  (2D char ) to netCDF file
=== End netCDF file creation test ===
=== Begin netCDF file reading test ===
Reading lon   (dim  )  back from netCDF file...........PASSED
Reading lat   (dim  )  back from netCDF file...........PASSED
Reading lev   (dim  )  back from netCDF file...........PASSED
Reading time  (dim  )  back from netCDF file...........PASSED
Reading cdim1 (dim  )  back from netCDF file...........PASSED
Reading cdim2 (dim  )  back from netCDF file...........PASSED
Reading lon   (array)  back from netCDF file...........PASSED
Reading lat   (array)  back from netCDF file...........PASSED
Reading lev   (array)  back from netCDF file...........PASSED
Reading time  (array)  back from netCDF file...........PASSED
Reading PS             back from netCDF file...........PASSED
Reading PS:units       back from netCDF file...........PASSED
Reading PS:long_name   back from netCDF file...........PASSED
Reading PS:_FillValue  back from netCDF file...........PASSED
Reading PS:valid_range back from netCDF file...........PASSED
Reading T              back from netCDF file...........PASSED
Reading T:units        back from netCDF file...........PASSED
Reading T:long_name    back from netCDF file...........PASSED
Reading T:_FillValue   back from netCDF file...........PASSED
Reading T:valid_range  back from netCDF file...........PASSED
Reading DESC           back from netCDF file...........PASSED
Reading DESC:units     back from netCDF file...........PASSED
Reading DESC:long_name back from netCDF file...........PASSED
Reading title          back from netCDF file...........PASSED
Reading start_date     back from netCDF file...........PASSED
Reading start_time     back from netCDF file...........PASSED
=== End of netCDF file read test! ===

If all of the tests return with "PASSED" then the libNcUtils.a file was created correctly.

Generating reference documentation for the standalone NcdfUtilities package

The NcdfUtilities Fortran source code and Makefiles use the ProTeX automatic documentation system. This enables you to create reference documents in *.pdf and *.ps format from the comments in the subroutine headers.

To build the reference documents, make sure you are in the doc/ subdirectory, then type:

  make doc

This will create the following documents in the doc/ subdirectory:

  NcdfUtilities.pdf               
  NcdfUtilities.ps
  NcdfUtilities.tex

-- Reference document for the NcdfUtilities Fortran code

          in *.pdf, *.ps, and LaTeX formats


  NcdfUtilities_Makefiles.pdf
  NcdfUtilities_Makefiles.ps
  NcdfUtilities_Makefiles.tex

-- Reference document for the NcdfUtilities Makefiles

          in *.pdf, *.ps, and LaTeX formats


The reference documents contain a description of each subroutine and function, the variables that are passed to it as input & output arguments, and the revision history. The Makefile reference document displays the full text of the Makefiles. These documents will come in handy if you need to modify or update the Fortran code or Makefiles.

If you wish to remove the NcdfUtilities reference documentation files, then make sure you are in the doc directory and type:

  make clean

--Bob Yantosca (talk) 18:45, 8 March 2017 (UTC)

Cleaning up

To remove all of the *.o, *.mod and executable file in the Code/ subdirectory only, type:

  make clean

However, if you wish to also remove the contents of the bin/ and lib/ subdirectories (as well as removing the *.ps, *.pdf, and *.txt files from the doc/ subdirectory), then type:

  make realclean

--Bob Yantosca (talk) 18:46, 8 March 2017 (UTC)