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