Re: [netcdfgroup] How can I get the Fortran-interface for NetCDF-4.7.3 on Win10-PC with Intel-19.0.5 Ftn-compiler?

On Mon, 2 Mar 2020 at 04:39 Michael Rachner <Michael.Rachner@xxxxxx> wrote:

> What is needed under Win10 is a script running directly on the Windows
> command shell (analogously as it exists under Linux), where the User
> only has to provide the names of the desired (already installed)
> C-compiler and Fortran-compiler, finally resulting in an
> NETCDF-installation for running application programs compiled with these
> compilers on Windows.
>
> NETCDF provides a data exchange tool between machines on different
> platforms. However, the intended universality of data exchange between
> machines on different platforms remains limited, if the installation of
> NETCDF on popular platforms is difficult or actually (as here) not
> supported. NETCDF claims: "The Unidata Program Center supports and
> maintains netCDF programming interfaces for C, C++, Java, and Fortran."
> So far, this is not fulfilled for Fortran95 applications under Win10.

While better support for Windows would be nice, this is still fairly 
straightforward using CMake. I recently added a patch for MPI support on 
Windows which fixes a longstanding issue with building netCDF-Fortran 
with a netCDF-C shared library. Just take it one step at a time and 
build all dependencies yourself. Trying to use pre-compiled binaries is 
likely to be more trouble than it's worth. If you use vcpkg and their 
default options work for you, it's super easy and you only need to 
manually build netCDF-Fortran: 

```
.\vcpkg install msmpi
.\vcpkg install hdf5[parallel]
.\vcpkg install netcdf-c
```

That said, I'll show how it's done the "hard way" using just CMake. Here 
is an example shared netCDF build with a shared MSVC runtime (/MD) 
starting from scratch. I'm leaving DAP disabled for this example since 
it requires libcurl, but it's easy to enable (exercise for the reader). 

All of the following steps should be done in the appropriate developer
command prompt. For HDF5 and netCDF-C builds you will use something like
"x64 Native Tools Command Prompt for VS 2017", and for netCDF-Fortran,
"Compiler 19.1 for Intel 64 Visual Studio 2017 environment".

Change the "E:\lib" paths below to match your directory structure.

---------------------
STEP 1: Install MSMPI
---------------------

Download the latest release:

https://github.com/microsoft/Microsoft-MPI/releases

Install and update your path:

```
set %PATH%=%PROGRAMFILES(X86)%\Microsoft SDKs\MPI\Lib\x64;%PATH%
```

---------------------
STEP 2: Install HDF5
--------------------

Download the CMake version of the source code archive:

https://www.hdfgroup.org/downloads/hdf5/source-code/

Edit "build-VS2017-64.bat" to enable MPI:

... BUILD_GENERATOR=VS201764,MPI=ON ...

Compile as follows:

```
cd /D "E:\lib\CMake-hdf5-1.10.6"
.\build-VS2017-64.bat
```

It will generate a zip file with the installation. Extract it for use
in the following steps.

------------------------
STEP 3: Compile netCDF-C
------------------------

For netCDF-C 4.7.3, you will need to patch CMakeLists.txt to fix HDF5
support. Delete these lines:

```
CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY_hdf5} H5Z_SZIP "" USE_SZIP)
IF(USE_SZIP)
...
ENDIF()
```

Replace with the following:

```
SET(USE_SZIP ${HDF5_ENABLE_SZIP_SUPPORT})
IF(USE_SZIP)
  SET(HAVE_H5Z_SZIP 1)
ENDIF()
```

SZip is included in INTERFACE_LINK_LIBRARIES by the HDF5 package
configuration file so it will still link properly.

Compile as follows, changing options as needed for your configuration.
I've included most of the common ones below. In this example I'm
compiling netCDF-C as a shared library but statically linking to HDF5
(NC_FIND_SHARED_LIBS=OFF).

```
cd /D "E:\lib\netcdf-c-4.7.3-build"
cmake -G Ninja^
 -DCMAKE_BUILD_TYPE=RELEASE^
 -DCMAKE_INSTALL_PREFIX="E:/lib/netcdf-c-4.7.3-md-x64"^
 -DNC_USE_STATIC_CRT=OFF^
 -DNC_FIND_SHARED_LIBS=OFF^
 -DHDF5_DIR="E:/lib/hdf5-1.10.6-md-x64/cmake/hdf5"^
 -DBUILD_SHARED_LIBS=ON^
 -DBUILD_UTILITIES=ON^
 -DENABLE_V2_API=OFF^
 -DENABLE_CDF5=ON^
 -DENABLE_NETCDF_4=ON^
 -DENABLE_HDF4=OFF^
 -DENABLE_PARALLEL4=ON^
 -DENABLE_DAP=OFF^
 -DENABLE_DAP4=OFF^
 -DENABLE_TESTS=ON^
 -DENABLE_EXTRA_TESTS=OFF^
 -DENABLE_PARALLEL_TESTS=ON^
 -DENABLE_FILTER_TESTING=OFF^
 -DENABLE_EXAMPLES=ON^
 "E:\lib\netcdf-c-4.7.3"
ninja
ninja install
```

Try running the examples and tests with your shiny new netCDF-C DLL.

------------------------------
STEP 3: Compile netCDF-Fortran
------------------------------

For netCDF-Fortran 4.5.2, you will need to patch CMakeLists.txt to fix
MPI support. Delete these lines:

```
CHECK_FUNCTION_EXISTS(MPI_File_open HAVE_MPI_IO)
IF(NOT HAVE_MPI_IO)
...
ENDIF(NOT HAVE_MPI_IO)
```

Replace with the following:

```
FIND_PACKAGE(MPI REQUIRED COMPONENTS C Fortran)
INCLUDE_DIRECTORIES(${MPI_Fortran_INCLUDE_PATH})
```

Make sure you are in an Intel Fortran command prompt. To compile:

```
cd /D "E:\lib\netcdf-fortran-4.5.2-build"
cmake -G"NMake Makefiles"^
 -DCMAKE_PREFIX_PATH="%PROGRAMFILES(X86)%\Microsoft SDKs\MPI\Lib\x64"^
 -DCMAKE_BUILD_TYPE=RELEASE^
 -DCMAKE_INSTALL_PREFIX="E:/lib/netcdf-fortran-4.5.2-x64"^
 -DNETCDF_C_LIBRARY="E:/lib/netcdf-c-4.7.3-md-x64/lib/netcdf.lib"^
 -DNETCDF_INCLUDE_DIR="E:/lib/netcdf-c-4.7.3-md-x64/include"^
 -DNC_EXTRA_DEPS="msmpi msmpifec"^
 -DENABLE_DOXYGEN=OFF^
 -DENABLE_TESTS=OFF^
 -DENABLE_PARALLEL_TESTS=ON^
 -DBUILD_SHARED_LIBS=OFF^
 -DBUILD_V2=OFF^
 -DBUILD_F90=ON^
 -DBUILD_F03=ON^
 -DBUILD_EXAMPLES=ON^
 "E:\lib\netcdf-fortran-4.5.2"
nmake
nmake install
```

Try running some examples:

```
mpiexec -n 4 .\simple_xy_par_wr.exe
 *** SUCCESS writing example file simple_xy_par.nc!

mpiexec -n 4 .\simple_xy_par_rd.exe
 *** SUCCESS reading example file simple_xy_par.nc!
```

----------------
STEP 4: Optional
----------------

If you use C++, try my new ncpp library and provide feedback :)

https://github.com/jbuonagurio/ncpp

---
John Buonagurio
  • 2020 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: