| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # Configuration script for WPS code |
|---|
| 4 | # |
|---|
| 5 | # Be sure to run as ./configure (to avoid getting a system configure command by mistake) |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | $sw_perl_path = perl ; |
|---|
| 9 | $sw_netcdf_path = "" ; |
|---|
| 10 | $sw_phdf5_path=""; |
|---|
| 11 | $sw_jasperlib_path=""; |
|---|
| 12 | $sw_jasperinc_path=""; |
|---|
| 13 | $sw_esmflib_path=""; |
|---|
| 14 | $sw_esmfinc_path=""; |
|---|
| 15 | $sw_ldflags=""; |
|---|
| 16 | $sw_compileflags=""; |
|---|
| 17 | $WRFCHEM = 0 ; |
|---|
| 18 | $sw_os = "ARCH" ; # ARCH will match any |
|---|
| 19 | $sw_mach = "ARCH" ; # ARCH will match any |
|---|
| 20 | |
|---|
| 21 | while ( substr( $ARGV[0], 0, 1 ) eq "-" ) |
|---|
| 22 | { |
|---|
| 23 | if ( substr( $ARGV[0], 1, 5 ) eq "perl=" ) |
|---|
| 24 | { |
|---|
| 25 | $sw_perl_path = substr( $ARGV[0], 6 ) ; |
|---|
| 26 | } |
|---|
| 27 | if ( substr( $ARGV[0], 1, 7 ) eq "netcdf=" ) |
|---|
| 28 | { |
|---|
| 29 | $sw_netcdf_path = substr( $ARGV[0], 8 ) ; |
|---|
| 30 | } |
|---|
| 31 | if ( substr( $ARGV[0], 1, 6 ) eq "phdf5=" ) |
|---|
| 32 | { |
|---|
| 33 | $sw_phdf5_path = substr( $ARGV[0], 7 ) ; |
|---|
| 34 | } |
|---|
| 35 | if ( substr( $ARGV[0], 1, 3 ) eq "os=" ) |
|---|
| 36 | { |
|---|
| 37 | $sw_os = substr( $ARGV[0], 4 ) ; |
|---|
| 38 | } |
|---|
| 39 | if ( substr( $ARGV[0], 1, 5 ) eq "mach=" ) |
|---|
| 40 | { |
|---|
| 41 | $sw_mach = substr( $ARGV[0], 6 ) ; |
|---|
| 42 | } |
|---|
| 43 | if ( substr( $ARGV[0], 1, 8 ) eq "ldflags=" ) |
|---|
| 44 | { |
|---|
| 45 | $sw_ldflags = substr( $ARGV[0], 9 ) ; |
|---|
| 46 | # multiple options separated by spaces are passed in from sh script |
|---|
| 47 | # separated by ! instead. Replace with spaces here. |
|---|
| 48 | $sw_ldflags =~ s/!/ /g ; |
|---|
| 49 | } |
|---|
| 50 | if ( substr( $ARGV[0], 1, 13 ) eq "compileflags=" ) |
|---|
| 51 | { |
|---|
| 52 | $sw_compileflags = substr( $ARGV[0], 14 ) ; |
|---|
| 53 | $sw_compileflags =~ s/!/ /g ; |
|---|
| 54 | # look for each known option |
|---|
| 55 | $where_index = index ( $sw_compileflags , "-DWRF_CHEM" ) ; |
|---|
| 56 | if ( $where_index eq -1 ) |
|---|
| 57 | { |
|---|
| 58 | $WRFCHEM = 0 ; |
|---|
| 59 | } |
|---|
| 60 | else |
|---|
| 61 | { |
|---|
| 62 | $WRFCHEM = 1 ; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | shift @ARGV ; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | # The jasper library is required to build Grib2 I/O. User must set |
|---|
| 69 | # environment variables JASPERLIB and JASPERINC to paths to library and |
|---|
| 70 | # include files to enable this feature prior to running configure. |
|---|
| 71 | if ( $ENV{JASPERLIB} && $ENV{JASPERINC} ) |
|---|
| 72 | { |
|---|
| 73 | printf "Configuring to use jasper library to build Grib2 I/O...\n" ; |
|---|
| 74 | printf(" \$JASPERLIB = %s\n",$ENV{JASPERLIB}); |
|---|
| 75 | printf(" \$JASPERINC = %s\n",$ENV{JASPERINC}); |
|---|
| 76 | $sw_jasperlib_path = $ENV{JASPERLIB}; |
|---|
| 77 | $sw_jasperinc_path = $ENV{JASPERINC}; |
|---|
| 78 | } |
|---|
| 79 | else |
|---|
| 80 | { |
|---|
| 81 | printf "\$JASPERLIB or \$JASPERINC not found in environment, configuring to build without grib2 I/O...\n" ; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | # A separately-installed ESMF library is required to build the ESMF |
|---|
| 85 | # implementation of WRF IOAPI in external/io_esmf. This is needed |
|---|
| 86 | # to couple WRF with other ESMF components. User must set environment |
|---|
| 87 | # variables ESMFLIB and ESMFINC to paths ESMF to library and include |
|---|
| 88 | # files to enable this feature prior to running configure. |
|---|
| 89 | if ( $ENV{ESMFLIB} && $ENV{ESMFINC} ) |
|---|
| 90 | { |
|---|
| 91 | printf "Configuring to use ESMF library to build WRF...\n" ; |
|---|
| 92 | printf "WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING\n" ; |
|---|
| 93 | printf "WARNING: THIS IS AN EXPERIMENTAL CONFIGURATION\n" ; |
|---|
| 94 | printf "WARNING: IT DOES NOT WORK WITH NESTING\n" ; |
|---|
| 95 | printf "WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING\n" ; |
|---|
| 96 | printf(" \$ESMFLIB = %s\n",$ENV{ESMFLIB}); |
|---|
| 97 | printf(" \$ESMFINC = %s\n",$ENV{ESMFINC}); |
|---|
| 98 | $sw_esmflib_path = $ENV{ESMFLIB}; |
|---|
| 99 | $sw_esmfinc_path = $ENV{ESMFINC}; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | # parse the configure.wps file |
|---|
| 103 | |
|---|
| 104 | $validresponse = 0 ; |
|---|
| 105 | |
|---|
| 106 | # Display the choices to the user and get selection |
|---|
| 107 | until ( $validresponse ) { |
|---|
| 108 | printf "------------------------------------------------------------------------\n" ; |
|---|
| 109 | printf "Please select from among the following supported platforms.\n\n" ; |
|---|
| 110 | |
|---|
| 111 | $opt = 1 ; |
|---|
| 112 | open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" |
|---|
| 113 | or die "Cannot open ./arch/configure.defaults for reading" ; |
|---|
| 114 | while ( <CONFIGURE_DEFAULTS> ) |
|---|
| 115 | { |
|---|
| 116 | if ( substr( $_, 0, 5 ) eq "#ARCH" && ( index( $_, $sw_os ) >= 0 ) && ( index( $_, $sw_mach ) >= 0 ) ) |
|---|
| 117 | { |
|---|
| 118 | $optstr[$opt] = substr($_,6) ; |
|---|
| 119 | $optstr[$opt] =~ s/^[ ]*// ; |
|---|
| 120 | if ( substr( $optstr[$opt], 0,4 ) ne "NULL" ) |
|---|
| 121 | { |
|---|
| 122 | printf " %2d. %s",$opt,$optstr[$opt] ; |
|---|
| 123 | $opt++ ; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | close CONFIGURE_DEFAULTS ; |
|---|
| 128 | |
|---|
| 129 | $opt -- ; |
|---|
| 130 | |
|---|
| 131 | printf "\nEnter selection [%d-%d] : ",1,$opt ; |
|---|
| 132 | $response = <STDIN> ; |
|---|
| 133 | |
|---|
| 134 | if ( $response == -1 ) { exit ; } |
|---|
| 135 | |
|---|
| 136 | if ( $response >= 1 && $response <= $opt ) |
|---|
| 137 | { $validresponse = 1 ; } |
|---|
| 138 | else |
|---|
| 139 | { printf("\nInvalid response (%d)\n",$response);} |
|---|
| 140 | } |
|---|
| 141 | printf "------------------------------------------------------------------------\n" ; |
|---|
| 142 | |
|---|
| 143 | $optchoice = $response ; |
|---|
| 144 | |
|---|
| 145 | open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" |
|---|
| 146 | or die "Cannot open ./arch/configure.defaults for reading" ; |
|---|
| 147 | $latchon = 0 ; |
|---|
| 148 | while ( <CONFIGURE_DEFAULTS> ) |
|---|
| 149 | { |
|---|
| 150 | if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 1 ) |
|---|
| 151 | { |
|---|
| 152 | $latchon = 0 ; |
|---|
| 153 | } |
|---|
| 154 | if ( $latchon == 1 ) |
|---|
| 155 | { |
|---|
| 156 | $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g ; |
|---|
| 157 | $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g ; |
|---|
| 158 | $_ =~ s/CONFIGURE_PHDF5_PATH/$sw_phdf5_path/g ; |
|---|
| 159 | $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g ; |
|---|
| 160 | $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g ; |
|---|
| 161 | if ( $sw_netcdf_path ) |
|---|
| 162 | { $_ =~ s/CONFIGURE_WRFIO_NF/wrfio_nf/g ; |
|---|
| 163 | $_ =~ s:CONFIGURE_NETCDF_FLAG:-DNETCDF: ; |
|---|
| 164 | $_ =~ s:CONFIGURE_NETCDF_LIB_PATH:-L../external/io_netcdf -lwrfio_nf -L$sw_netcdf_path/lib -lnetcdf: ; |
|---|
| 165 | } |
|---|
| 166 | else |
|---|
| 167 | { $_ =~ s/CONFIGURE_WRFIO_NF//g ; |
|---|
| 168 | $_ =~ s:CONFIGURE_NETCDF_FLAG::g ; |
|---|
| 169 | $_ =~ s:CONFIGURE_NETCDF_LIB_PATH::g ; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | if ( $sw_phdf5_path ) |
|---|
| 173 | |
|---|
| 174 | { $_ =~ s/CONFIGURE_WRFIO_PHDF5/wrfio_phdf5/g ; |
|---|
| 175 | $_ =~ s:CONFIGURE_PHDF5_FLAG:-DPHDF5: ; |
|---|
| 176 | $_ =~ s:CONFIGURE_PHDF5_LIB_PATH:-L../external/io_phdf5 -lwrfio_phdf5 -L$sw_phdf5_path/lib -lhdf5_fortran -lhdf5 -lm -lz -L$sw_phdf5_path/lib -lsz: ; |
|---|
| 177 | } |
|---|
| 178 | else |
|---|
| 179 | { $_ =~ s/CONFIGURE_WRFIO_PHDF5//g ; |
|---|
| 180 | $_ =~ s:CONFIGURE_PHDF5_FLAG::g ; |
|---|
| 181 | $_ =~ s:CONFIGURE_PHDF5_LIB_PATH::g ; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | if ( $sw_jasperlib_path && $sw_jasperinc_path ) |
|---|
| 185 | { $_ =~ s/CONFIGURE_WRFIO_GRIB2/wrfio_grib2/g ; |
|---|
| 186 | $_ =~ s:CONFIGURE_GRIB2_FLAG:-DGRIB2:g ; |
|---|
| 187 | $_ =~ s:CONFIGURE_GRIB2_INC:-I$sw_jasperinc_path:g ; |
|---|
| 188 | $_ =~ s:CONFIGURE_GRIB2_LIB:-L../external/io_grib2 -lio_grib2 -L$sw_jasperlib_path -ljasper:g ; |
|---|
| 189 | } |
|---|
| 190 | else |
|---|
| 191 | { $_ =~ s/CONFIGURE_WRFIO_GRIB2//g ; |
|---|
| 192 | $_ =~ s:CONFIGURE_GRIB2_FLAG::g ; |
|---|
| 193 | $_ =~ s:CONFIGURE_GRIB2_INC::g ; |
|---|
| 194 | $_ =~ s:CONFIGURE_GRIB2_LIB::g ; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | # ESMF substitutions in configure.defaults |
|---|
| 199 | if ( $sw_esmflib_path && $sw_esmfinc_path ) |
|---|
| 200 | { |
|---|
| 201 | $_ =~ s:ESMFIOLIB:-L$sw_esmflib_path -lesmf -L../external/io_esmf -lwrfio_esmf \$\(ESMF_LIB_FLAGS\):g ; |
|---|
| 202 | $_ =~ s:ESMFIOEXTLIB:-L$sw_esmflib_path -lesmf -L../../external/io_esmf -lwrfio_esmf \$\(ESMF_LIB_FLAGS\):g ; |
|---|
| 203 | } |
|---|
| 204 | else |
|---|
| 205 | { |
|---|
| 206 | $_ =~ s:ESMFIOLIB:-L../external/esmf_time_f90 -lesmf_time:g ; |
|---|
| 207 | $_ =~ s:ESMFIOEXTLIB:-L../../external/esmf_time_f90 -lesmf_time:g ; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | @machopts = ( @machopts, $_ ) ; |
|---|
| 211 | if ( substr( $_, 0, 10 ) eq "ENVCOMPDEF" ) |
|---|
| 212 | { |
|---|
| 213 | @machopts = ( @machopts, "WRF_CHEM\t=\t$WRFCHEM \n" ) ; |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 0 ) |
|---|
| 217 | { |
|---|
| 218 | $x=substr($_,6) ; |
|---|
| 219 | $x=~s/^[ ]*// ; |
|---|
| 220 | if ( $x eq $optstr[$optchoice] ) |
|---|
| 221 | { |
|---|
| 222 | $latchon = 1 ; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | close CONFIGURE_DEFAULTS ; |
|---|
| 227 | |
|---|
| 228 | #printf "------------------------------------------------------------------------\n" ; |
|---|
| 229 | #foreach $f ( @machopts ) |
|---|
| 230 | #{ |
|---|
| 231 | # if ( substr( $f , 0 , 8 ) eq "external" ) { last ; } |
|---|
| 232 | # print $f ; |
|---|
| 233 | #} |
|---|
| 234 | #printf "------------------------------------------------------------------------\n" ; |
|---|
| 235 | #printf "\nYou have chosen: %s",$optstr[$optchoice] ; |
|---|
| 236 | #printf "Listed above are the default options for this platform.\n" ; |
|---|
| 237 | #printf "Settings are written to the file configure.wps here in the top-level\n" ; |
|---|
| 238 | #printf "directory. If you wish to change settings, please edit that file.\n" ; |
|---|
| 239 | #printf "If you wish to change the default options, edit the file:\n\n" ; |
|---|
| 240 | #printf " arch/configure.defaults\n" ; |
|---|
| 241 | #printf "\n" ; |
|---|
| 242 | |
|---|
| 243 | open CONFIGURE_WRF, "> configure.wps" or die "cannot append configure.wps" ; |
|---|
| 244 | open ARCH_PREAMBLE, "< arch/preamble" or die "cannot open arch/preamble" ; |
|---|
| 245 | my @preamble; |
|---|
| 246 | # apply substitutions to the preamble... |
|---|
| 247 | while ( <ARCH_PREAMBLE> ) |
|---|
| 248 | { |
|---|
| 249 | # ESMF substitutions in preamble |
|---|
| 250 | if ( $sw_esmflib_path && $sw_esmfinc_path ) |
|---|
| 251 | { |
|---|
| 252 | $_ =~ s/ESMFCOUPLING/1/g ; |
|---|
| 253 | $_ =~ s:ESMFMODDEPENDENCE:../external/io_esmf/module_utility.o:g ; |
|---|
| 254 | $_ =~ s:ESMFMODINC:-I$sw_esmfinc_path -I../main:g ; |
|---|
| 255 | $_ =~ s:ESMFIOINC:-I../external/io_esmf:g ; |
|---|
| 256 | $_ =~ s:ESMFIODEFS:-DESMFIO:g ; |
|---|
| 257 | $_ =~ s:ESMFTARGET:wrfio_esmf:g ; |
|---|
| 258 | } |
|---|
| 259 | else |
|---|
| 260 | { |
|---|
| 261 | $_ =~ s/ESMFCOUPLING/0/g ; |
|---|
| 262 | $_ =~ s:ESMFMODDEPENDENCE:../external/esmf_time_f90/module_utility.o:g ; |
|---|
| 263 | $_ =~ s:ESMFMODINC::g ; |
|---|
| 264 | $_ =~ s:ESMFIOINC:-I../external/esmf_time_f90:g ; |
|---|
| 265 | $_ =~ s:ESMFIODEFS::g ; |
|---|
| 266 | $_ =~ s:ESMFTARGET:esmf_time:g ; |
|---|
| 267 | } |
|---|
| 268 | @preamble = ( @preamble, $_ ) ; |
|---|
| 269 | } |
|---|
| 270 | close ARCH_PREAMBLE ; |
|---|
| 271 | print CONFIGURE_WRF @preamble ; |
|---|
| 272 | close ARCH_PREAMBLE ; |
|---|
| 273 | printf CONFIGURE_WRF "# Settings for %s", $optstr[$optchoice] ; |
|---|
| 274 | print CONFIGURE_WRF @machopts ; |
|---|
| 275 | open ARCH_POSTAMBLE, "< arch/postamble" or die "cannot open arch/postamble" ; |
|---|
| 276 | while ( <ARCH_POSTAMBLE> ) { print CONFIGURE_WRF } ; |
|---|
| 277 | close ARCH_POSTAMBLE ; |
|---|
| 278 | close CONFIGURE_WRF ; |
|---|
| 279 | |
|---|
| 280 | printf "Configuration successful. To build the WPS, type: compile \n" ; |
|---|
| 281 | printf "------------------------------------------------------------------------\n" ; |
|---|
| 282 | |
|---|
| 283 | |
|---|