Skip to content

Commit

Permalink
Merge pull request ESMCI#1559 from NCAR/ejh_ncint_fortran
Browse files Browse the repository at this point in the history
netcdf integration for Fortran
  • Loading branch information
edhartnett authored Jul 12, 2019
2 parents 213084b + 70a219c commit f9a064e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ AC_OUTPUT(Makefile
tests/Makefile
tests/cunit/Makefile
tests/ncint/Makefile
tests/fncint/Makefile
tests/unit/Makefile
tests/general/Makefile
tests/general/util/Makefile
Expand Down
3 changes: 3 additions & 0 deletions src/flib/pio.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module pio
! nf_init_intracom, &
!#endif
pio_set_rearr_opts
! #ifdef NETCDF_INTEGRATION
! nf_init_intracom, &
! #endif

use pio_types, only : io_desc_t, file_desc_t, var_desc_t, iosystem_desc_t, &
pio_rearr_opt_t, pio_rearr_comm_fc_opt_t, pio_rearr_comm_fc_2d_enable,&
Expand Down
1 change: 1 addition & 0 deletions src/flib/piolib_mod.F90
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define __PIO_FILE__ "piolib_mod.f90"
#include "config.h"
!>
!! @file
!! Initialization Routines for PIO.
Expand Down
5 changes: 4 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ endif # BUILD_FORTRAN
# Are we building with netCDF integration?
if BUILD_NCINT
NCINT = ncint
if BUILD_FORTRAN
FNCINT = fncint
endif # BUILD_FORTRAN
endif # BUILD_NCINT

# Build in these subdirs.
SUBDIRS = cunit ${UNIT} ${NCINT} ${GENERAL} ${PERFORMANCE}
SUBDIRS = cunit ${UNIT} ${NCINT} ${GENERAL} ${PERFORMANCE} ${FNCINT}

EXTRA_DIST = CMakeLists.txt
28 changes: 28 additions & 0 deletions tests/fncint/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## This is the automake file for building the netCDF integration layer
## tests.

# Ed Hartnett 7/3/19

# Link to the PIO Fortran and C libraries.
LDADD = ${top_builddir}/src/flib/libpiof.la ${top_builddir}/src/clib/libpioc.la

# Link to the netCDF fortran library.
LDADD += -lnetcdff

# Find the pio.mod file.
AM_FCFLAGS = -I${top_builddir}/src/flib ${CPPFLAGS}

# Build the test for make check.
check_PROGRAMS = ftst_pio
ftst_pio_SOURCES = ftst_pio.f90

if RUN_TESTS
# Tests will run from a bash script.
TESTS = run_tests.sh
endif # RUN_TESTS

# Distribute the test script.
EXTRA_DIST = run_tests.sh

# Clean up files produced during testing.
CLEANFILES = *.nc *.log
35 changes: 35 additions & 0 deletions tests/fncint/ftst_pio.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
!> This is a test program for the Fortran API use of the netCDF
!! integration layer.

program ftst_pio
use pio
implicit none
include 'mpif.h'
include 'netcdf.inc'

integer :: myRank, ntasks
type(iosystem_desc_t) :: ioSystem
integer :: niotasks = 1, numAggregator = 0, stride = 1, base = 0
integer :: ncid
character*(*) FILE_NAME
parameter (FILE_NAME='ftst_pio.nc')
integer :: ierr

call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, myRank, ierr)
call MPI_Comm_size(MPI_COMM_WORLD, ntasks, ierr)

ierr = pio_set_log_level(2)
ierr = nf_set_log_level(2)
call nf_init_intracom(myRank, MPI_COMM_WORLD, niotasks, numAggregator, &
stride, PIO_rearr_subset, ioSystem, base)

ierr = nf_create(FILE_NAME, 64, ncid)
ierr = nf_close(ncid)

call PIO_finalize(ioSystem, ierr)
call MPI_Finalize(ierr)
if (myRank .eq. 0) then
print *, '*** SUCCESS running ftst_pio!'
endif
end program ftst_pio
30 changes: 30 additions & 0 deletions tests/fncint/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
# This is a test script for PIO.
# Ed Hartnett

# Stop execution of script if error is returned.
set -e

# Stop loop if ctrl-c is pressed.
trap exit INT TERM

printf 'running Fortran tests for PIO netCDF integration...\n'

PIO_TESTS='ftst_pio'

success1=true
for TEST in $PIO_TESTS
do
success1=false
echo "running ${TEST}"
mpiexec -n 4 ./${TEST} && success1=true
if test $success1 = false; then
break
fi
done

# Did we succeed?
if test x$success1 = xtrue; then
exit 0
fi
exit 1

0 comments on commit f9a064e

Please sign in to comment.