Skip to content

Commit ae4105c

Browse files
author
giannozz
committed
Wrappers for iargc, getarg, getenv used everywhere. Next step: replace them
with standard calls if accepted by all relevant compilers
1 parent bcb7340 commit ae4105c

File tree

7 files changed

+56
-73
lines changed

7 files changed

+56
-73
lines changed

Modules/command_line_options.f90

+9-15
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ MODULE command_line_options
4848
CONTAINS
4949
!
5050
SUBROUTINE get_command_line ( input_command_line )
51-
#if defined(__NAG)
52-
USE F90_UNIX_ENV, ONLY : iargc, getarg
53-
#endif
5451
IMPLICIT NONE
5552
CHARACTER(LEN=*), OPTIONAL :: input_command_line
5653
INTEGER :: narg
57-
#if !defined(__NAG)
58-
INTEGER :: iargc
59-
! Do not define iargc as external: gfortran doesn't like it
60-
#endif
6154
LOGICAL :: read_string
6255
CHARACTER(LEN=256) :: arg
6356
CHARACTER(LEN=6), EXTERNAL :: int_to_char
57+
INTEGER, EXTERNAL :: i_argc
6458
!
6559
command_line = ' '
6660
read_string = PRESENT ( input_command_line )
@@ -71,7 +65,7 @@ SUBROUTINE get_command_line ( input_command_line )
7165
IF (read_string) THEN
7266
nargs = my_iargc ( input_command_line )
7367
ELSE
74-
nargs = iargc()
68+
nargs = i_argc()
7569
ENDIF
7670
CALL mp_bcast ( nargs, root, world_comm )
7771
!
@@ -85,55 +79,55 @@ SUBROUTINE get_command_line ( input_command_line )
8579
IF (read_string) THEN
8680
CALL my_getarg ( input_command_line, narg, arg )
8781
ELSE
88-
CALL getarg ( narg, arg )
82+
CALL get_arg ( narg, arg )
8983
ENDIF
9084
narg = narg + 1
9185
SELECT CASE ( TRIM(arg) )
9286
CASE ( '-i', '-in', '-inp', '-input' )
9387
IF (read_string) THEN
9488
CALL my_getarg ( input_command_line, narg, input_file_ )
9589
ELSE
96-
CALL getarg ( narg, input_file_ )
90+
CALL get_arg ( narg, input_file_ )
9791
ENDIF
9892
IF ( TRIM (input_file_) == ' ' ) GO TO 15
9993
narg = narg + 1
10094
CASE ( '-ni', '-nimage', '-nimages' )
10195
IF (read_string) THEN
10296
CALL my_getarg ( input_command_line, narg, arg )
10397
ELSE
104-
CALL getarg ( narg, arg )
98+
CALL get_arg ( narg, arg )
10599
ENDIF
106100
READ ( arg, *, ERR = 15, END = 15) nimage_
107101
narg = narg + 1
108102
CASE ( '-nk', '-npool', '-npools')
109103
IF (read_string) THEN
110104
CALL my_getarg ( input_command_line, narg, arg )
111105
ELSE
112-
CALL getarg ( narg, arg )
106+
CALL get_arg ( narg, arg )
113107
ENDIF
114108
READ ( arg, *, ERR = 15, END = 15) npool_
115109
narg = narg + 1
116110
CASE ( '-nt', '-ntg', '-ntask_groups')
117111
IF (read_string) THEN
118112
CALL my_getarg ( input_command_line, narg, arg )
119113
ELSE
120-
CALL getarg ( narg, arg )
114+
CALL get_arg ( narg, arg )
121115
ENDIF
122116
READ ( arg, *, ERR = 15, END = 15) ntg_
123117
narg = narg + 1
124118
CASE ( '-nb', '-nband', '-nbgrp', '-nband_group')
125119
IF (read_string) THEN
126120
CALL my_getarg ( input_command_line, narg, arg )
127121
ELSE
128-
CALL getarg ( narg, arg )
122+
CALL get_arg ( narg, arg )
129123
ENDIF
130124
READ ( arg, *, ERR = 15, END = 15) nband_
131125
narg = narg + 1
132126
CASE ( '-nd', '-ndiag', '-northo', '-nproc_diag', '-nproc_ortho')
133127
IF (read_string) THEN
134128
CALL my_getarg ( input_command_line, narg, arg )
135129
ELSE
136-
CALL getarg ( narg, arg )
130+
CALL get_arg ( narg, arg )
137131
ENDIF
138132
READ ( arg, *, ERR = 15, END = 15) ndiag_
139133
narg = narg + 1

Modules/plugin_arguments.f90

+3-8
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@ SUBROUTINE plugin_arguments()
1919
USE io_global, ONLY : stdout
2020
!
2121
USE plugin_flags
22-
#if defined(__NAG)
23-
USE F90_UNIX_ENV, ONLY : iargc, getarg
24-
#endif
2522
!
2623
IMPLICIT NONE
2724
!
28-
#if !defined(__NAG)
29-
INTEGER :: iargc
30-
#endif
25+
INTEGER, EXTERNAL :: i_argc
3126
INTEGER :: iiarg, nargs, i, i0
3227
CHARACTER (len=1), EXTERNAL :: lowercase
3328
CHARACTER (len=256) :: arg
3429
!
35-
nargs = iargc()
30+
nargs = i_argc()
3631
! add here more plugins
3732
use_plumed = .false.
3833
use_pw2casino = .false.
3934
use_environ = .false.
4035
!
4136
DO iiarg = 1, nargs
42-
CALL getarg( iiarg, plugin_name)
37+
CALL get_arg( iiarg, plugin_name)
4338
IF ( plugin_name(1:1) == '-') THEN
4439
i0 = 1
4540
IF ( plugin_name(2:2) == '-') i0 = 2

NEB/src/path_io_tools.f90

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,25 @@ FUNCTION input_images_getarg( ) RESULT(input_images)
1313
! return N (0 if not found)
1414
!
1515
USE kinds, ONLY : DP
16-
#if defined(__NAG)
17-
USE F90_UNIX_ENV, ONLY : iargc, getarg
18-
#endif
1916
!
2017
IMPLICIT NONE
2118
!
2219
INTEGER :: input_images
2320
CHARACTER(len=256) :: myname
24-
#if !defined(__NAG)
25-
INTEGER :: iargc
26-
#endif
21+
INTEGER, EXTERNAL :: i_argc
2722
INTEGER :: iiarg, nargs, i, i0
2823
!
29-
nargs = iargc()
24+
nargs = i_argc()
3025
input_images = 0
3126
!
3227
DO iiarg = 1, nargs
3328
!
34-
CALL getarg( iiarg, myname)
29+
CALL get_arg( iiarg, myname)
3530
!
3631
IF ( TRIM( myname ) == '-input_images' .OR. &
3732
TRIM( myname ) == '--input_images' ) THEN
3833
!
39-
CALL getarg( ( iiarg + 1 ) , myname )
34+
CALL get_arg( ( iiarg + 1 ) , myname )
4035
!
4136
READ(myname,*) input_images
4237
RETURN

PHonon/PH/q2qstar.f90

+4-9
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ PROGRAM Q2QSTAR
4747
USE io_dyn_mat, ONLY : read_dyn_mat_param, read_dyn_mat_header, &
4848
read_dyn_mat, read_dyn_mat_tail, &
4949
write_dyn_mat_header
50-
#if defined(__NAG)
51-
USE F90_UNIX_ENV, ONLY : iargc, getarg
52-
#endif
5350
!
5451
IMPLICIT NONE
5552
!
@@ -65,19 +62,17 @@ PROGRAM Q2QSTAR
6562
!
6663
COMPLEX(DP),ALLOCATABLE :: phi(:,:,:,:), d2(:,:)
6764
INTEGER :: i,j, icar,jcar, na,nb
68-
#if !defined(__NAG)
69-
INTEGER :: iargc ! intrinsic function
70-
#endif
65+
INTEGER, EXTERNAL :: i_argc ! wrapper for iargc
7166
!
7267
NAMELIST / input / fildyn
7368
!
7469
CALL mp_startup()
7570
CALL environment_start(CODE)
7671
!
77-
nargs = iargc()
72+
nargs = i_argc()
7873
IF(nargs < 1) CALL errore(CODE, 'Argument is missing! Syntax: "q2qstar dynfile [outfile]"', 1)
7974
!
80-
CALL getarg(1, fildyn)
75+
CALL get_arg(1, fildyn)
8176
CALL mp_bcast(fildyn, ionode_id,world_comm)
8277
!
8378
! check input
@@ -86,7 +81,7 @@ PROGRAM Q2QSTAR
8681
!
8782
! set up output
8883
IF (nargs > 1) THEN
89-
CALL getarg(2, filout)
84+
CALL get_arg(2, filout)
9085
ELSE
9186
filout = TRIM(fildyn)//".rot"
9287
ENDIF

PP/src/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pw_export.x : pw_export.o libpp.a $(MODULES) $(LIBOBJS)
169169
- ( cd ../../bin ; ln -fs ../PP/src/$@ . )
170170

171171
sumpdos.x : sumpdos.o
172-
$(LD) $(LDFLAGS) -o $@ sumpdos.o
172+
$(LD) $(LDFLAGS) -o $@ sumpdos.o $(MODULES) $(LIBOBJS) $(LIBS)
173173
- ( cd ../../bin ; ln -fs ../PP/src/$@ . )
174174

175175
epsilon.x : epsilon.o libpp.a $(MODULES) $(LIBOBJS)

PP/src/sumpdos.f90

+5-11
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
!
88
PROGRAM sumpdos
99
!
10-
#if defined(__NAG)
11-
USE F90_UNIX_ENV, ONLY : iargc, getarg
12-
#endif
13-
!
1410
IMPLICIT NONE
1511
!
1612
! AUTHOR: Andrea Ferretti
@@ -21,9 +17,7 @@ PROGRAM sumpdos
2117
! file names are read from stdin
2218
! USAGE: sumpdos <file1> ... <fileN>
2319
!
24-
#if !defined(__NAG)
25-
INTEGER :: iargc ! function giving no of arguments
26-
#endif
20+
INTEGER, EXTERNAL :: i_argc ! function giving no of arguments
2721
INTEGER :: ngrid ! dimension of the energy grid
2822
INTEGER :: nfile ! number of files to sum
2923
INTEGER :: nspin ! number of spin_component
@@ -52,13 +46,13 @@ PROGRAM sumpdos
5246
!
5347
! get the number of arguments (i.e. the number of files)
5448
!
55-
nfile = iargc ()
49+
nfile = i_argc ()
5650
IF ( nfile == 0 ) THEN
5751
WRITE(0,"( 'No file to sum' )")
5852
STOP
5953
ENDIF
6054

61-
CALL getarg ( 1, str1 )
55+
CALL get_arg ( 1, str1 )
6256
!
6357
SELECT CASE ( trim(str1) )
6458
CASE ( "-h" )
@@ -79,7 +73,7 @@ PROGRAM sumpdos
7973
!
8074
! read file names from file
8175
!
82-
CALL getarg ( 2, filein )
76+
CALL get_arg ( 2, filein )
8377
IF ( len_trim(filein) == 0 ) CALL errore('sumpdos','provide filein name',2)
8478

8579
INQUIRE( FILE=trim(filein), EXIST=exist )
@@ -126,7 +120,7 @@ PROGRAM sumpdos
126120
ALLOCATE( file(nfile), STAT=ierr )
127121
IF (ierr/=0) CALL errore('sumpdos','allocating FILE',abs(ierr))
128122
DO iarg = 1, nfile
129-
CALL getarg ( iarg, file(iarg) )
123+
CALL get_arg ( iarg, file(iarg) )
130124
ENDDO
131125

132126
END SELECT

flib/inpfile.f90

+30-20
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,64 @@
55
! in the root directory of the present distribution,
66
! or http://www.gnu.org/copyleft/gpl.txt .
77
!
8-
SUBROUTINE get_env ( variable_name, variable_value )
9-
!
10-
! Wrapper for intrinsic getenv - all machine-dependent stuff here
8+
! Wrappers for intrinsic iargc, getarg, getenv - machine-dependent stuff here
9+
!
10+
INTEGER FUNCTION i_argc ( )
11+
#if defined(__NAG)
12+
USE F90_UNIX_ENV, ONLY : iargc
13+
#else
14+
! do not declare it external: gfortran doesn't like it
15+
INTEGER :: iargc
16+
#endif
17+
i_argc = iargc ( )
18+
END FUNCTION i_argc
1119
!
20+
SUBROUTINE get_env ( variable_name, variable_value )
1221
#if defined(__NAG)
1322
USE F90_UNIX_ENV, ONLY : getenv
1423
#endif
1524
CHARACTER (LEN=*) :: variable_name, variable_value
16-
!
1725
CALL getenv ( variable_name, variable_value)
18-
!
1926
END SUBROUTINE get_env
27+
!
28+
SUBROUTINE get_arg ( iarg, arg )
29+
#if defined(__NAG)
30+
USE F90_UNIX_ENV, ONLY : getarg
31+
#endif
32+
INTEGER, INTENT(IN) :: iarg
33+
CHARACTER (LEN=*), INTENT(OUT) :: arg
34+
CALL getarg ( iarg, arg )
35+
END SUBROUTINE get_arg
36+
!
2037
!----------------------------------------------------------------------------
2138
SUBROUTINE input_from_file( )
2239
!
2340
! This subroutine checks command-line arguments for -i[nput] "file name"
2441
! if "file name" is present, attach input unit 5 to the specified file
2542
!
26-
#if defined(__NAG)
27-
USE F90_UNIX_ENV, ONLY : iargc, getarg
28-
#endif
29-
!
3043
IMPLICIT NONE
3144
!
3245
INTEGER :: stdin = 5, stderr = 6, ierr = 0
3346
CHARACTER (LEN=256) :: input_file
3447
LOGICAL :: found
3548
!
36-
#if !defined(__NAG)
37-
INTEGER :: iargc
38-
! Do not define iargc as external: gfortran doesn't like it
39-
#endif
49+
INTEGER, EXTERNAL :: i_argc
4050
INTEGER :: iiarg, nargs
4151
!
42-
nargs = iargc()
52+
nargs = i_argc()
4353
found = .FALSE.
4454
input_file = ' '
4555
!
4656
DO iiarg = 1, ( nargs - 1 )
4757
!
48-
CALL getarg( iiarg, input_file )
58+
CALL get_arg( iiarg, input_file )
4959
!
5060
IF ( TRIM( input_file ) == '-i' .OR. &
5161
TRIM( input_file ) == '-in' .OR. &
5262
TRIM( input_file ) == '-inp' .OR. &
5363
TRIM( input_file ) == '-input' ) THEN
5464
!
55-
CALL getarg( ( iiarg + 1 ) , input_file )
65+
CALL get_arg( ( iiarg + 1 ) , input_file )
5666
found =.TRUE.
5767
EXIT
5868
!
@@ -94,11 +104,11 @@ SUBROUTINE get_file( input_file )
94104
!
95105
CHARACTER (LEN=256) :: prgname
96106
INTEGER :: nargs
97-
INTEGER :: iargc
98107
LOGICAL :: exst
108+
INTEGER, EXTERNAL :: i_argc
99109
!
100-
nargs = iargc()
101-
CALL getarg (0,prgname)
110+
nargs = i_argc()
111+
CALL get_arg (0,prgname)
102112
!
103113
IF ( nargs == 0 ) THEN
104114
10 PRINT '("Input file > ",$)'
@@ -110,7 +120,7 @@ SUBROUTINE get_file( input_file )
110120
GO TO 10
111121
END IF
112122
ELSE IF ( nargs == 1 ) then
113-
CALL getarg (1,input_file)
123+
CALL get_arg (1,input_file)
114124
ELSE
115125
PRINT '(A,": too many arguments ",i4)', TRIM(prgname), nargs
116126
END IF

0 commit comments

Comments
 (0)