utorak, 2. kolovoza 2011.

Installing the ncview for quick viewing of the netcdf files produced by POM

While there is quite some matlab support for viewing POM-generated netcdf data, this requires a lot of knowledge of the data itslef to employ. For a quick, easy-to-use interface for viewing POM files, ncview comes to mind. 

Paraview will also do the job, but you will have to slice the 3D data manually. 

In order to build and install ncview, you will neede yet another copy of hdf5 and netcdf, this time compiled with netcdf 4 support and built with the same compiler you plan to build  ncview with. 

You will need the latest version of hdf5 and netcdf 4.1.3; you can find the links in previous posts in this blog.

What you will need to do prior to building hdf5 is install the zlib library, also build it manually, also with the same compiler as all the other stuff.

There IS a trick to it to make it all work - you need to install all of these into a same folder. Yes, I know they're supposed to be linkable, but it doesn't work. There is actually an explanation online to why is that so, and why the --with- tags don't work in ./configure for this case, you can look for it if you're curious. 

I have chosen to dump everything into /usr/local/hdf5ncdf, you can use any folder you like and it doesn't have to be in /usr/local/, just put everything in the same one. 

Build zlib like this:

     ./configure --prefix=/usr/local/hdf5ncdf
     make 
     make check 
     make install

Then you build HDF5, specifying the location of the zlib library:

FC=gfortran CC=gcc CXX=g++ ./configure --with-zlib=/usr/local/hdf5ncdf --      prefix=/usr/local/hdf5ncdf --enable-fortran --enable-f77 --enable-f90
     make 
     make check 
     make install


After HDF5 is done, build netcdf, specifying the location of the HDF5, zlib, and (if built into HDF5) the szip header files and libraries in the CPPFLAGS and LDFLAGS environment variables.

export CPPFLAGS="-I/usr/local/hdf5ncdf/include"
export LDFLAGS="-L/usr/local/hdf5ncdf/lib"

 FC=gfortran CC=gcc CXX=g++ ./configure --prefix=/usr/local/hdf5ncdf --enable-fortran --enable-parallel --disable-shared --enable-f77 --enable-f90 --enable-netcdf-4 

     make 
     make check 
     make install



All of this done, you should have a working copy of netcdf 4.1.3 with netcdf-4 suport and zlib support, all built for gfortran, gcc and g++. Note that if you're using different compilers, you should invoke them instead of these three!

Installing ncview itself

What the ncview install data won't tell you, but thankfully the compiler in ubuntu will, is that you require the following libraries prior to a successful ncview installation:

  • Athena Widgets = XAW packages for ubuntu
  • libpng development packages



Go ahead and pick these up from the repositories. Note that I was using a KDE plasma desktop and sucked them off the kubuntu repos, but the ubuntu ones should be identical. 

Here is how you should run the configure script once you installed the libraries. Note (and adjust) the correct paths to your own netcdf / hdf5 installations:

sudo ./configure --with-netcdf_incdir=/usr/local/hdf5ncdf/include/ --with-netcdf_libname=/usr/local/hdf5ncdf/lib/ --with-netcdf_libdir=/usr/local/hdf5ncdf/bin/ --with-nc-config=/usr/local/hdf5ncdf/bin/nc-config

In my kubuntu, I need to run ncview from console, e.g. like this:

ncview /home/fireice/Documents/POM_materials/pom2k/pon2k.nc
Netcdf requirements for pom2k

To run pom2k, one also needs netcdf support which is quite different than the one needed for sbPOM. pom2k does not employ netcdf 4, so it is sufficient to install Netcdf version 3.6.3., as long as you compile it with gfortran compiler and add a few tweaks here and there. The compiler itself seems to be very important, because I have iterated a bit and tried various compilers and only gfortran managed to make peace between netcdf 3.6.3. and pom2k on my system (Ubuntu 11.10). 

Since this is a continuation from the last post on this blog, I'll start at:

4. Installing netcdf 3.6.3. libraries

Netcdf 3.6.3. can be downloaded from here, and, luckily, there's an option to either download the source code and build it, or download the pre-built version built by gfortran. Note that this is the only one that really worked for my system. Using netcdf and pom2k compiled by any other compiler (f77, f90, f95...) failed at recognizing and deploying nf_ functions in pom2k (you can and should check this during make check of the netvdf building process).

If you decide to build netcdf libraries, which I would strongly suggest since it's simple once you actually know what you need, and the software is relatively well behaved, here is the procedure:

LIBS='-L/usr/local/ncdfp/include -pnetcdf' FC=gfortran CC=gcc CXX=g++ ./configure --disab --enable-parallel-tests --prefix=/usr/local/ncd363f --disable-shared --enable-fortran --enable-f77 --enable-f90

In principle one can do quite nicely without pnetcdf here, I just wanted to play around and see if it'll build properly. Don't forget to make check before doing a make install, and make sure all the fortran functions (prefixed by nf_) have run correctly).

I have installed this version in /usr/local/ncd363f in order to be able to point pom2k at it without having any conflicts with other netcdf builds I will require.

5. Resolving pom2k bugs

Once I have pointed the pom2k.n file to /usr/local/ncd363f/netcdf.inc and uncommented the netcdf output in pom2k.f (it comes with the entire netcdf output modules commented out, for some reason - as a C++ programmer I had to go through several fortran manuals to realize that the subroutine file (pom2k.n) is actually included at the end of the pom2k.f file, but it still didn't work.

Considering gfortran compiler isn't all that helpful with errors inside included files, bluntly copy-pasting the whole of the .n file code into the .f file did the trick. Going through the code, it turned out someone forgot to comment out a line of code (and end-if) around 213th line of the pom2k.n file.