diff --git a/cmake/DetectOptions.cmake b/cmake/DetectOptions.cmake index 0c7b2a8691..ca449feeee 100644 --- a/cmake/DetectOptions.cmake +++ b/cmake/DetectOptions.cmake @@ -142,6 +142,28 @@ endif() if(CMAKE_Fortran_COMPILER_LOADED) set(ADIOS2_HAVE_Fortran TRUE) list(APPEND mpi_find_components Fortran) + + include(CheckFortranSourceCompiles) + check_fortran_source_compiles(" + program testargs + integer :: n + character(len=256) :: v + n = command_argument_count() + call get_command_argument(0, v) + end program testargs" + ADIOS2_HAVE_FORTRAN_F03_ARGS + SRC_EXT F90 + ) + check_fortran_source_compiles(" + program testargs + integer :: n + character(len=256) :: v + n = iargc() + call getarg(0, v) + end program testargs" + ADIOS2_HAVE_FORTRAN_GNU_ARGS + SRC_EXT F90 + ) endif() # MPI diff --git a/examples/hello/insituMPI/CMakeLists.txt b/examples/hello/insituMPI/CMakeLists.txt index 36d6cbea6f..5168c8f048 100644 --- a/examples/hello/insituMPI/CMakeLists.txt +++ b/examples/hello/insituMPI/CMakeLists.txt @@ -5,6 +5,10 @@ if(ADIOS2_HAVE_Fortran) add_library(helloInsituArgs OBJECT helloInsituArgs.F90) + target_compile_definitions(helloInsituArgs PRIVATE + $<$:ADIOS2_HAVE_FORTRAN_F03_ARGS> + $<$:ADIOS2_HAVE_FORTRAN_GNU_ARGS> + ) add_executable(hello_insituMPIWriter_f helloInsituMPIWriter.f90 diff --git a/examples/hello/insituMPI/helloInsituArgs.F90 b/examples/hello/insituMPI/helloInsituArgs.F90 index cf6275f526..59a00c2667 100644 --- a/examples/hello/insituMPI/helloInsituArgs.F90 +++ b/examples/hello/insituMPI/helloInsituArgs.F90 @@ -35,11 +35,15 @@ end subroutine usage !!*************************** subroutine processArgs(rank, nproc, isWriter) -#if defined(_CRAYFTN) || !defined(__GFORTRAN__) && !defined(__GNUC__) - interface - integer function iargc() - end function iargc - end interface +#if defined(ADIOS2_HAVE_FORTRAN_F03_ARGS) +# define ADIOS2_ARGC() command_argument_count() +# define ADIOS2_ARGV(i, v) call get_command_argument(i, v) +#elif defined(ADIOS2_HAVE_FORTRAN_GNU_ARGS) +# define ADIOS2_ARGC() iargc() +# define ADIOS2_ARGV(i, v) call getarg(i, v) +#else +# define ADIOS2_ARGC() 1 +# define ADIOS2_ARGV(i, v) #endif integer, intent(in) :: rank @@ -57,20 +61,20 @@ end function iargc endif !! process arguments - numargs = iargc() + numargs = ADIOS2_ARGC() !print *,"Number of arguments:",numargs if ( numargs < expargs ) then call usage(isWriter) call exit(1) endif - call getarg(1, xmlfile) - call getarg(2, npx_str) - call getarg(3, npy_str) + ADIOS2_ARGV(1, xmlfile) + ADIOS2_ARGV(2, npx_str) + ADIOS2_ARGV(3, npy_str) if (isWriter) then - call getarg(4, ndx_str) - call getarg(5, ndy_str) - call getarg(6, steps_str) - call getarg(7, time_str) + ADIOS2_ARGV(4, ndx_str) + ADIOS2_ARGV(5, ndy_str) + ADIOS2_ARGV(6, steps_str) + ADIOS2_ARGV(7, time_str) endif read (npx_str,'(i5)') npx read (npy_str,'(i5)') npy diff --git a/testing/adios2/engine/staging-common/CMakeLists.txt b/testing/adios2/engine/staging-common/CMakeLists.txt index 656b590b76..05cbb222ef 100644 --- a/testing/adios2/engine/staging-common/CMakeLists.txt +++ b/testing/adios2/engine/staging-common/CMakeLists.txt @@ -54,9 +54,17 @@ if(ADIOS2_HAVE_Fortran) TestCommonReadF.F90 $ ) + target_compile_definitions(TestCommonRead_f PRIVATE + $<$:ADIOS2_HAVE_FORTRAN_F03_ARGS> + $<$:ADIOS2_HAVE_FORTRAN_GNU_ARGS> + ) set_target_properties(TestCommonWrite_f TestCommonRead_f PROPERTIES LINKER_LANGUAGE Fortran ) + target_compile_definitions(TestCommonWrite_f PRIVATE + $<$:ADIOS2_HAVE_FORTRAN_F03_ARGS> + $<$:ADIOS2_HAVE_FORTRAN_GNU_ARGS> + ) if(ADIOS2_HAVE_MPI) target_link_libraries(TestCommonWrite_f adios2_fortran_mpi MPI::MPI_Fortran) target_link_libraries(TestCommonRead_f adios2_fortran_mpi MPI::MPI_Fortran) diff --git a/testing/adios2/engine/staging-common/TestCommonReadF.F90 b/testing/adios2/engine/staging-common/TestCommonReadF.F90 index 15cade8e61..1956d4d98c 100644 --- a/testing/adios2/engine/staging-common/TestCommonReadF.F90 +++ b/testing/adios2/engine/staging-common/TestCommonReadF.F90 @@ -12,13 +12,15 @@ program TestSstRead use adios2 implicit none -#ifndef __GFORTRAN__ -#ifndef __GNUC__ - interface - integer function iargc() - end function iargc - end interface -#endif +#if defined(ADIOS2_HAVE_FORTRAN_F03_ARGS) +# define ADIOS2_ARGC() command_argument_count() +# define ADIOS2_ARGV(i, v) call get_command_argument(i, v) +#elif defined(ADIOS2_HAVE_FORTRAN_GNU_ARGS) +# define ADIOS2_ARGC() iargc() +# define ADIOS2_ARGV(i, v) call getarg(i, v) +#else +# define ADIOS2_ARGC() 1 +# define ADIOS2_ARGV(i, v) #endif integer :: numargs @@ -43,7 +45,7 @@ end function iargc integer(kind = 8), dimension(:), allocatable::shape_in integer::key, color - numargs = iargc() + numargs = ADIOS2_ARGC() if ( numargs < 2 ) then call usage() @@ -51,10 +53,10 @@ end function iargc endif - call getarg(1, engine) - call getarg(2, filename) + ADIOS2_ARGV(1, engine) + ADIOS2_ARGV(2, filename) if ( numargs > 2 ) then - call getarg(3, params) + ADIOS2_ARGV(3, params) endif insteps = 0; diff --git a/testing/adios2/engine/staging-common/TestCommonWriteF.F90 b/testing/adios2/engine/staging-common/TestCommonWriteF.F90 index 622aa018ed..9739302db6 100644 --- a/testing/adios2/engine/staging-common/TestCommonWriteF.F90 +++ b/testing/adios2/engine/staging-common/TestCommonWriteF.F90 @@ -11,13 +11,15 @@ program TestSstWrite use adios2 implicit none -#ifndef __GFORTRAN__ -#ifndef __GNUC__ - interface - integer function iargc() - end function iargc - end interface -#endif +#if defined(ADIOS2_HAVE_FORTRAN_F03_ARGS) +# define ADIOS2_ARGC() command_argument_count() +# define ADIOS2_ARGV(i, v) call get_command_argument(i, v) +#elif defined(ADIOS2_HAVE_FORTRAN_GNU_ARGS) +# define ADIOS2_ARGC() iargc() +# define ADIOS2_ARGV(i, v) call getarg(i, v) +#else +# define ADIOS2_ARGC() 1 +# define ADIOS2_ARGV(i, v) #endif integer :: numargs @@ -42,17 +44,17 @@ end function iargc integer(kind = 8)::localtime integer::color, key, testComm - numargs = iargc() + numargs = ADIOS2_ARGC() if ( numargs < 2 ) then call usage() call exit(1) endif - call getarg(1, engine) - call getarg(2, filename) + ADIOS2_ARGV(1, engine) + ADIOS2_ARGV(2, filename) if ( numargs > 2 ) then - call getarg(3, params) + ADIOS2_ARGV(3, params) endif #if ADIOS2_USE_MPI @@ -184,8 +186,10 @@ end function iargc call adios2_put(sstWriter, variables(6), data_R64, ierr) call adios2_put(sstWriter, variables(7), data_R64_2d, ierr) call adios2_put(sstWriter, variables(8), data_R64_2d_rev, ierr) +#if !defined(_CRAYFTN) localtime = 0 ! should be time(), but non-portable and value is unused call adios2_put(sstWriter, variables(9), loc(localtime), ierr) +#endif call adios2_put(sstWriter, variables(10), data_C32, ierr) call adios2_put(sstWriter, variables(11), data_C64, ierr) call adios2_end_step(sstWriter, ierr)