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