From 90665b462b8440d80f72910ea76e43e7cf52b991 Mon Sep 17 00:00:00 2001
From: Antoine Cyril David Hoffmann <ahoffman@spcpc606.epfl.ch>
Date: Mon, 4 Oct 2021 14:35:22 +0200
Subject: [PATCH] inputfile+jobid e.g. fort_00.90. the id is set as first or
 third arg

---
 src/basic_mod.F90 | 25 ++++++++++++++++++++++++-
 src/ppinit.F90    |  8 ++------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/basic_mod.F90 b/src/basic_mod.F90
index b5234057..ecda6e4a 100644
--- a/src/basic_mod.F90
+++ b/src/basic_mod.F90
@@ -58,7 +58,6 @@ MODULE basic
   END INTERFACE allocate_array
 
 CONTAINS
-
   !================================================================================
   SUBROUTINE basic_data
     !   Read basic data for input file
@@ -66,6 +65,8 @@ CONTAINS
     use prec_const
     IMPLICIT NONE
 
+    CALL find_input_file
+
     NAMELIST /BASIC/  nrun, dt, tmax, maxruntime
 
     READ(lu_in,basic)
@@ -76,6 +77,28 @@ CONTAINS
 
   END SUBROUTINE basic_data
   !================================================================================
+  SUBROUTINE find_input_file
+    IMPLICIT NONE
+    CHARACTER(len=32) :: str, input_file
+    INTEGER :: nargs, fileid, l
+    LOGICAL :: mlexist
+    nargs = COMMAND_ARGUMENT_COUNT()
+    IF((nargs .EQ. 1) .OR. (nargs .EQ. 3)) THEN
+      CALL GET_COMMAND_ARGUMENT(nargs, str, l, ierr)
+      READ(str(1:l),'(i3)')  fileid
+      WRITE(input_file,'(a,a1,i2.2,a3)') 'fort','_',fileid,'.90'
+
+      INQUIRE(file=input_file, exist=mlexist)
+      IF( mlexist ) THEN
+        IF(my_id.EQ.0) write(*,*) 'Reading input ', input_file,'...'
+        OPEN(lu_in, file=input_file)
+      ELSE
+        IF(my_id.EQ.0) write(*,*) 'Reading input fort.90...'
+        OPEN(lu_in, file='fort.90')
+      ENDIF
+    ENDIF
+  END SUBROUTINE find_input_file
+  !================================================================================
   SUBROUTINE daytim(str)
     !   Print date and time
 
diff --git a/src/ppinit.F90 b/src/ppinit.F90
index 9b8382b6..c9418310 100644
--- a/src/ppinit.F90
+++ b/src/ppinit.F90
@@ -19,13 +19,9 @@ SUBROUTINE ppinit
   CALL MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
 
   nargs = COMMAND_ARGUMENT_COUNT()
-  IF( nargs .NE. 0 .AND. nargs .NE. ndims ) THEN
-     IF(my_id .EQ. 0) WRITE(*, '(a,i4,a)') 'Number of arguments not equal to NDIMS =', ndims, '!'
-     CALL MPI_ABORT(MPI_COMM_WORLD, -1, ierr)
-  END IF
   !
-  IF( nargs .NE. 0 ) THEN
-     DO i=1,nargs
+  IF( nargs .GT. 1 ) THEN
+     DO i=1,ndims
         CALL GET_COMMAND_ARGUMENT(i, str, l, ierr)
         READ(str(1:l),'(i3)')  dims(i)
      END DO
-- 
GitLab