MinGW binaries of NetCDF 3.6.2

netCDF (network Common Data Form) is a set of software libraries and machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data”. On its homepage you’ll find a lot of precompiled libraries for Unix derivates but only a binary of netCDF 3.6.1 compiled with Visual C++. It’s possible to use this binary in MinGW also, but I prefer to use libraries compiled with the same compiler toolkit I’m working with. There are no makefiles for the MinGW compiler but it is possible to compile the netCDF library in the MSys development ennvironment. I wrote a bash little script which downloads the netCDF source package (with the help of curl), untars the package, compiles the source and assembles the binaries and necessary files for development in a tar.gz package. Curl needs to be in the path or in the same directory as the script. The script will create a netcdf_mingw directory where the source package is downloaded to and all compilation steps will take place. The tar.gz package will be created in netcdf_mingw/package. Below you can download the binary package of netCDF 3.6.2 for the MinGW compiler toolset (to be used in MSys and in native Windows CLI) and the script I wrote to compile netCDF in MSys yourself if you want.

netCDF 3.6.2 Binary for MinGW 3.4.5: Download (rename the file to netcdf-3.6.2_mingw.tar.gz)

The script will create a directory netcdf_mingw in the same directory where the script is run. Before the scripts starts downloading the netCDF package, it shows some informations and waits for user input.

#######################################################################
# This batch file will download, compile and make a package of
# the netcdf library for the MinGW compiler. You need to have Msys
# and MinGW already installed.
#
# You need curl.exe and 7za.exe for this script to work
# correctly:
#   - curl 7.18.0 no SSL download location:
# http://curl.haxx.se/download/curl-7.18.0-win32-nossl-sspi.zip
#   - 7-zip 4.57 command line version:
# http://downloads.sourceforge.net/sevenzip/7za457.zip
#######################################################################

#######################################################################
# determine directories
# source package will be downloaded into and compiled in $MAINDIR
# binary package will be created in $PACKAGEDIR
#######################################################################
export ROOTDIR=`pwd`
export MAINDIR=$ROOTDIR/netcdf_mingw
export BUILDDIR=$MAINDIR/netcdf-3.6.2
export PACKAGEDIR=$MAINDIR/package

#######################################################################
# show user the settings and ask if he wants to continue
#######################################################################
echo
echo ==============================================================
echo == Please check the settings
echo ==============================================================
echo
echo Directories
echo ===========
echo ROOTDIR=$ROOTDIR
echo MAINDIR=$MAINDIR
echo BUILDDIR=$BUILDDIR
echo PACKAGEDIR=$PACKAGEDIR
echo
echo Type y to continue!

read -n 1 ANSWER
if [ $ANSWER != "y" ]
then
exit -1;
fi

#######################################################################
# remove and create directories
#######################################################################
mkdir $MAINDIR
mkdir $PACKAGEDIR

#######################################################################
# download and unpack netcdf-3.6.2 package
#######################################################################
echo +++ Downloading netcdf library from http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-3.6.2.tar.gz +++
curl http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-3.6.2.tar.gz -o $MAINDIR/netcdf-3.6.2.tar.gz
pushd $MAINDIR
tar xzf netcdf-3.6.2.tar.gz
popd

#######################################################################
# configure and build library
#######################################################################
pushd $BUILDDIR
./configure --enable-shared --disable-separate-fortram --disable-cxx --disable-f90
make

#######################################################################
# make package for website
#######################################################################
if [ 1 == 1 ]
then
echo 'This netCDF DLL was generated using MingW/Msys.' > $PACKAGEDIR/README_DLL.txt
echo '' >> $PACKAGEDIR/README_DLL.txt
echo './configure --enable-shared --disable-separate-fortram --disable-cxx --disable-f90' >> $PACKAGEDIRREADME_DLL.txt
echo 'To use the DLL from C, include netcdf.h.' >> $PACKAGEDIR/README_DLL.txt
echo 'To use the DLL from Fortran, include netcdf.inc.' >> $PACKAGEDIR/README_DLL.txt
cp libsrc/.libs/libnetcdf.a $PACKAGEDIR
cp libsrc/.libs/libnetcdf.dll.a $PACKAGEDIR
cp libsrc/.libs/libnetcdf-4.dll $PACKAGEDIR
cp libsrc/netcdf.h $PACKAGEDIR
cp fortran/netcdf.inc $PACKAGEDIR
cp ncgen/.libs/ncgen.exe $PACKAGEDIR
cp ncdump/.libs/ncdump.exe $PACKAGEDIR
pushd $PACKAGEDIR
tar -cf netcdf-3.6.2_mingw.tar netcdf.h libnetcdf.a libnetcdf.dll.a libnetcdf-4.dll README_DLL.txt netcdf.inc ncgen.exe ncdump.exe
gzip netcdf-3.6.2_mingw.tar
popd
fi

popd

exit 1

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.