Computational Cluster Programs

How to Use the netCDF Library on ATS-Hosted Clusters

Installed location:

  • netCDF is installed in: /u/local/apps/netcdf/current.

How to run netCDF from a C program

In your program include the appropriate netCDF header file

#include <netcdf.h>
and call the appropriate netCDF functions.

To compile and link enter:

CC pgm.c -I$NETCDF_HOME/include -L$NETCDF_HOME/lib -lnetcdf -lm -o pgm
Replace CC with either gcc or icc depending on which compiler you want to use. Replace pgm.c with the name of the file containing your source code and pgm with the name of the executable to be created.

Set NETCDF_HOME to be: /u/local/apps/netcdf/current. You can either set an environment variable or replace $NETCDF_HOME in the command shown above.

How to run netCDF from a C++ program

In your program include the appropriate netCDF header file

#include <netcdfcpp.h>
and call the appropriate netCDF functions.

To compile and link enter:

CC pgm.cpp -I$NETCDF_HOME/include -L$NETCDF_HOME/lib -lnetcdf_c++ -lnetcdf -lm -o pgm
Replace CC with either g++ or icpc depending on which compiler you want to use. Replace pgm.cpp with the name of the file containing your source code and pgm with the name of the executable to be created.

Set NETCDF_HOME to be: /u/local/apps/netcdf/current. You can either set an environment variable or replace $NETCDF_HOME in the command shown above.

How to run netCDF from a Fortran 77 program

In your program include the appropriate netCDF header file

include 'netcdf.inc'
and call the appropriate netCDF functions.

To compile and link enter:

ifort pgm.f -I$NETCDF_HOME/include -L$NETCDF_HOME/lib -lnetcdf -o pgm
Replace pgm.f with the name of the file containing your source code and pgm with the name of the executable to be created.

Set NETCDF_HOME to be: /u/local/apps/netcdf/current. You can either set an environment variable or replace $NETCDF_HOME in the command shown above.

How to run netCDF from a Fortran 90 program

In your program include the appropriate netCDF module

use netcdf
and call the appropriate netCDF functions.

To compile and link enter:

ifort pgm.f90 -I$NETCDF_HOME/include -L$NETCDF_HOME/lib -lnetcdf -o pgm
Replace pgm.f90 with the name of the file containing your source code and pgm with the name of the executable to be created.

Set NETCDF_HOME to be: /u/local/apps/netcdf/current. You can either set an environment variable or replace $NETCDF_HOME in the command shown above.