|
4 | 4 | # by UCAR, "as is", without charge, subject to all terms of use at
|
5 | 5 | # http://www.image.ucar.edu/DAReS/DART/DART_download
|
6 | 6 | #
|
7 |
| -# $Id$ |
8 |
| - |
9 |
| -# usage: fixsystem [ your_fortran_command_name | -help ] |
10 |
| -# (e.g. ifort, pgf90, gfortran, g95, xlf90, etc) |
| 7 | +# |
| 8 | +# usage: fixsystem your_fortran_command_name [ files to change ] |
| 9 | +# fortran names such as: ifort, pgf90, gfortran, g95, xlf90, etc |
| 10 | +# default filenames are mpi_utilities_mod.f90 and null_mpi_utilities_mod.f90 |
| 11 | +# other filenames can be given instead |
11 | 12 | #
|
12 | 13 | # this script updates the mpi source files for any compiler-dependent
|
13 |
| -# changes needed before building. |
| 14 | +# changes needed before building. these changes should be handled |
| 15 | +# by the compiler preprocessor, except that on systems with |
| 16 | +# case-insensitive filesystems (e.g. macs with OSX), bob.F90 |
| 17 | +# and bob.f90 are the same file and the preprocessor bombs. |
14 | 18 | #
|
15 |
| -# at the moment the only compiler-dependent code is the declaration |
16 |
| -# of the "system()" function in a fortran interface block. |
17 |
| -# the code uses this function to run a shell script or command and |
18 |
| -# wait for the command exit code, e.g.: rc = system("/bin/date") |
| 19 | +# there are currently two code blocks of interest: 1) the fortran |
| 20 | +# interface block declaring the system() function, and 2) some |
| 21 | +# NAG-specific external use lines. |
19 | 22 | #
|
| 23 | +# the DART code uses system() to run a shell script or command and |
| 24 | +# wait for the command exit code, e.g.: rc = system("/bin/date") |
20 | 25 | # for all compilers, except gfortran, an interface block is required
|
21 | 26 | # to define the integer return from the system function. however
|
22 | 27 | # the gfortran compiler gives an error if this block is defined.
|
23 |
| -# this script enables and disables this interface block by |
| 28 | +# |
| 29 | +# this script enables and disables these interface blocks by |
24 | 30 | # looking for a pair of specially formatted comment lines and
|
25 | 31 | # commenting in (or out) all the lines between those comment
|
26 | 32 | # delimiter lines.
|
27 | 33 | #
|
28 |
| -# the original usage of this script was without any arguments. |
29 |
| -# the backwards compatibility remains for now, but is deprecated. |
30 |
| -# usage now is to give it a single argument - the name that the |
| 34 | +# this script requires at least one argument - the name the |
31 | 35 | # fortran compiler is invoked with, e.g. ifort, xlf90, pgf90, etc.
|
32 |
| -# it will ensure that any required changes to the source will be |
33 |
| -# made here before compilation. |
| 36 | +# by default mpi_utilities_mod.f90 and null_mpi_utilities_mod.f90 |
| 37 | +# will be examined and changed if needed. other filenames can be |
| 38 | +# given instead and they will be processed instead of these. |
| 39 | +# |
| 40 | + |
| 41 | +# default file list, and both marker strings must exist in these files |
| 42 | +export FLIST="mpi_utilities_mod.f90 null_mpi_utilities_mod.f90" |
| 43 | +export STRINGS_REQUIRED=1 |
| 44 | + |
| 45 | +# compiler name required. additional filenames optional. |
| 46 | +# if filenames are given, they replace the defaults |
| 47 | +if [ $# = 0 ]; then |
| 48 | + echo invalid usage, 1 argument required by $0 |
| 49 | + echo "usage: $0 your_fortran_command_name [ filenames to modify ]" |
| 50 | + echo " e.g. $0 gfortran" |
| 51 | + echo " or $0 ifort " |
| 52 | + echo " or $0 pgf90 " |
| 53 | + echo " etc." |
| 54 | + exit 1 |
| 55 | +elif [ $# = 1 ]; then |
| 56 | + # first arg: the name of your fortran compiler command |
| 57 | + export COMPILER=$1 |
| 58 | + shift |
| 59 | +else |
| 60 | + # first arg: the name of your fortran compiler command |
| 61 | + # additional args: list of filenames to process |
| 62 | + # not a fatal error if files don't contain marker strings |
| 63 | + export COMPILER=$1 |
| 64 | + shift |
| 65 | + export FLIST="$*" |
| 66 | + export STRINGS_REQUIRED=0 |
| 67 | +fi |
| 68 | + |
34 | 69 |
|
| 70 | +# based on the compiler, what needs doing? |
| 71 | +# "out" means comment the code block out |
| 72 | +# "in" means remove comment character so the |
| 73 | +# code will be compiled. |
| 74 | +# currently there are two different code blocks |
| 75 | +# that need to be handled. |
35 | 76 |
|
36 |
| -for f in mpi_utilities_mod.f90 null_mpi_utilities_mod.f90 |
| 77 | +if [ "$COMPILER" = gfortran ]; then |
| 78 | + export todo1=out |
| 79 | + export todo2=out |
| 80 | +elif [ "$COMPILER" = nagfor ]; then |
| 81 | + export todo1=out |
| 82 | + export todo2=in |
| 83 | +else |
| 84 | + export todo1=in |
| 85 | + export todo2=out |
| 86 | +fi |
| 87 | + |
| 88 | +# check each file in the list |
| 89 | + |
| 90 | +for f in $FLIST |
37 | 91 | do
|
38 | 92 |
|
39 | 93 | # figure out what state the source file is in before we start
|
|
43 | 97 | elif [ "`echo $bline1 | grep COMMENTED_IN`" != "" ]; then
|
44 | 98 | export before1=in
|
45 | 99 | else
|
46 |
| - echo ${f} not found, or does not have the right comment string to |
47 |
| - echo automatically change the system interface block via script. |
48 |
| - echo Please restore original file from the subversion repository |
49 |
| - echo and try again. |
50 |
| - exit 1 |
| 100 | + if [ $STRINGS_REQUIRED = 0 ]; then |
| 101 | + before1=none |
| 102 | + else |
| 103 | + echo ${f} not found, or does not have the right comment string to |
| 104 | + echo automatically change the system interface block via script. |
| 105 | + echo Please restore original file from the repository |
| 106 | + echo and try again. |
| 107 | + exit 1 |
| 108 | + fi |
51 | 109 | fi
|
52 | 110 |
|
53 | 111 | # NAG sections have both in and out - but NAG_BLOCK_EDIT is key
|
|
57 | 115 | elif [ "`echo $bline2 | grep COMMENTED_IN`" != "" ]; then
|
58 | 116 | export before2=in
|
59 | 117 | else
|
60 |
| - echo ${f} not found, or does not have the right comment string to |
61 |
| - echo automatically change the system interface block via script. |
62 |
| - echo Please restore original file from the subversion repository |
63 |
| - echo and try again. |
64 |
| - exit 1 |
65 |
| - fi |
66 |
| - |
67 |
| - # no args given - error. required now. |
68 |
| - if [ $# = 0 ]; then |
69 |
| - echo invalid usage, 1 argument required by $0 |
70 |
| - echo "usage: $0 [ your_fortran_command_name | -help ]" |
71 |
| - echo " e.g. $0 gfortran" |
72 |
| - echo " or $0 ifort " |
73 |
| - echo " or $0 pgf90 " |
74 |
| - echo " etc." |
75 |
| - exit 1 |
76 |
| - elif [ $# = 1 ]; then |
77 |
| - # single arg: the name of your fortran compiler command |
78 |
| - if ([ "$1" = help ] || [ "$1" = -help ] || [ "$1" = --help ]); then |
79 |
| - echo "usage: $0 [ your_fortran_command_name | -help ]" |
80 |
| - echo " e.g. $0 gfortran" |
81 |
| - echo " or $0 ifort " |
82 |
| - echo " or $0 pgf90 " |
83 |
| - echo " etc." |
84 |
| - exit 1 |
85 |
| - elif ([ "$1" = gfortran ] || [ "$1" = nagfor ]); then |
86 |
| - export todo1=out |
87 |
| - export todo2=out |
88 |
| - elif [ "$1" = nagfor ]; then |
89 |
| - export todo1=out |
90 |
| - export todo2=in |
| 118 | + if [ $STRINGS_REQUIRED = 0 ]; then |
| 119 | + before2=none |
91 | 120 | else
|
92 |
| - export todo1=in |
93 |
| - export todo2=out |
| 121 | + echo ${f} not found, or does not have the right comment string to |
| 122 | + echo automatically change the NAG interface block via script. |
| 123 | + echo Please restore original file from the repository |
| 124 | + echo and try again. |
| 125 | + exit 1 |
94 | 126 | fi
|
95 |
| - export compiler=$1 |
96 |
| - |
97 |
| - else |
98 |
| - # too many arguments, give an error message and exit |
99 |
| - echo invalid usage, more than 1 argument given to $0 |
100 |
| - echo "usage: $0 [ your_fortran_command_name | -help ]" |
101 |
| - echo " e.g. $0 gfortran" |
102 |
| - echo " or $0 ifort " |
103 |
| - echo " or $0 pgf90 " |
104 |
| - echo " etc." |
105 |
| - exit 1 |
106 | 127 | fi
|
107 |
| - |
| 128 | + |
| 129 | + # if neither marker string is found, loop without complaint. |
| 130 | + if ([ $before1 = none ] && [ $before2 = none ]); then continue; fi |
| 131 | + |
108 | 132 | # if we are already in the right state, loop to next file
|
109 | 133 | if ([ $before1 = $todo1 ] && [ $before2 = $todo2 ]); then continue; fi
|
110 | 134 |
|
|
115 | 139 |
|
116 | 140 | # say what compiler we are doing this for, and move the existing
|
117 | 141 | # code into a temporary file so the sed command does not overwrite it.
|
118 |
| - echo Setting for $compiler compiler in ${f} |
| 142 | + echo Setting for $COMPILER compiler in ${f} |
119 | 143 | mv ${f} tempfile
|
120 | 144 |
|
121 | 145 | # removing comment chars, enabling interface block code
|
|
132 | 156 | mv ${f} tempfile
|
133 | 157 | fi
|
134 | 158 |
|
135 |
| - # changing comment chars, enabling NAG specific block code |
| 159 | + # removing comment chars, enabling NAG specific block code |
136 | 160 | # non-nag section headers cannot match nag headers.
|
137 | 161 | if [ $todo2 = in ]; then
|
138 | 162 | sed -e '/NAG_BLOCK_EDIT START COMMENTED_OUT/,/NAG_BLOCK_EDIT END COMMENTED_OUT/s/^!//' \
|
|
141 | 165 | -e '/\(OTHER_BLOCK_EDIT [A-Z][A-Z]*\) COMMENTED_IN/s//\1 COMMENTED_OUT/' tempfile > ${f}
|
142 | 166 | fi
|
143 | 167 |
|
144 |
| - # changing comment chars, disabling NAG specific block code |
| 168 | + # adding comment chars, disabling NAG specific block code |
145 | 169 | if [ $todo2 = out ]; then
|
146 | 170 | sed -e '/NAG_BLOCK_EDIT START COMMENTED_IN/,/NAG_BLOCK_EDIT END COMMENTED_IN/s/^/!/' \
|
147 | 171 | -e '/\(NAG_BLOCK_EDIT [A-Z][A-Z]*\) COMMENTED_IN/s//\1 COMMENTED_OUT/' \
|
|
155 | 179 |
|
156 | 180 | exit 0
|
157 | 181 |
|
158 |
| -# <next few lines under version control, do not edit> |
159 |
| -# $URL$ |
160 |
| -# $Revision$ |
161 |
| -# $Date$ |
|
0 commit comments