3 # Configuration script for WPS code
5 # Be sure to run as ./configure (to avoid getting a system configure command by mistake)
10 $sw_netcdff_lib = "" ;
12 $sw_jasperlib_path="";
13 $sw_jasperinc_path="";
19 $sw_os = "ARCH" ; # ARCH will match any
20 $sw_mach = "ARCH" ; # ARCH will match any
22 while ( substr( $ARGV[0], 0, 1 ) eq "-" )
24 if ( substr( $ARGV[0], 1, 5 ) eq "perl=" )
26 $sw_perl_path = substr( $ARGV[0], 6 ) ;
28 if ( substr( $ARGV[0], 1, 7 ) eq "netcdf=" )
30 $sw_netcdf_path = substr( $ARGV[0], 8 ) ;
32 if ( substr( $ARGV[0], 1, 8 ) eq "netcdff=" )
34 $sw_netcdff_lib = substr( $ARGV[0], 9 ) ;
36 if ( substr( $ARGV[0], 1, 6 ) eq "phdf5=" )
38 $sw_phdf5_path = substr( $ARGV[0], 7 ) ;
40 if ( substr( $ARGV[0], 1, 3 ) eq "os=" )
42 $sw_os = substr( $ARGV[0], 4 ) ;
44 if ( substr( $ARGV[0], 1, 5 ) eq "mach=" )
46 $sw_mach = substr( $ARGV[0], 6 ) ;
48 if ( substr( $ARGV[0], 1, 8 ) eq "ldflags=" )
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 ;
55 if ( substr( $ARGV[0], 1, 13 ) eq "compileflags=" )
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 )
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
} )
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
};
86 printf "\$JASPERLIB or \$JASPERINC not found in environment, configuring to build without grib2 I/O...\n" ;
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
} )
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
};
107 # parse the configure.wps file
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" ;
117 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults"
118 or die "Cannot open ./arch/configure.defaults for reading" ;
119 while ( <CONFIGURE_DEFAULTS
> )
121 if ( substr( $_, 0, 5 ) eq "#ARCH" && ( index( $_, $sw_os ) >= 0 ) && ( index( $_, $sw_mach ) >= 0 ) )
123 $optstr[$opt] = substr($_,6) ;
124 $optstr[$opt] =~ s/^[ ]*// ;
125 if ( substr( $optstr[$opt], 0,4 ) ne "NULL" )
127 printf " %2d. %s",$opt,$optstr[$opt] ;
132 close CONFIGURE_DEFAULTS
;
136 printf "\nEnter selection [%d-%d] : ",1,$opt ;
137 $response = <STDIN
> ;
139 if ( $response == -1 ) { exit ; }
141 if ( $response >= 1 && $response <= $opt )
142 { $validresponse = 1 ; }
144 { printf("\nInvalid response (%d)\n",$response);}
146 printf "------------------------------------------------------------------------\n" ;
148 $optchoice = $response ;
150 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults"
151 or die "Cannot open ./arch/configure.defaults for reading" ;
153 while ( <CONFIGURE_DEFAULTS
> )
155 if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 1 )
161 $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g ;
162 $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g ;
163 $_ =~ s/CONFIGURE_PHDF5_PATH/$sw_phdf5_path/g ;
164 $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g ;
165 $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g ;
166 if ( $sw_netcdf_path )
167 { $_ =~ s/CONFIGURE_WRFIO_NF/wrfio_nf/g ;
168 $_ =~ s
:CONFIGURE_NETCDF_FLAG
:-DNETCDF
: ;
169 $_ =~ s
:CONFIGURE_NETCDF_LIB_PATH
:-L
../external/io_netcdf
-lwrfio_nf
-L
$sw_netcdf_path/lib
-lnetcdf
: ;
172 { $_ =~ s/CONFIGURE_WRFIO_NF//g ;
173 $_ =~ s
:CONFIGURE_NETCDF_FLAG
::g
;
174 $_ =~ s
:CONFIGURE_NETCDF_LIB_PATH
::g
;
177 if ( $sw_phdf5_path )
179 { $_ =~ s/CONFIGURE_WRFIO_PHDF5/wrfio_phdf5/g ;
180 $_ =~ s
:CONFIGURE_PHDF5_FLAG
:-DPHDF5
: ;
181 $_ =~ s
:CONFIGURE_PHDF5_LIB_PATH
:-L
../external/io_phdf
5 -lwrfio_phdf5
-L
$sw_phdf5_path/lib -lhdf5_fortran -lhdf5 -lm -lz -L$sw_phdf5_path/lib
-lsz
: ;
184 { $_ =~ s/CONFIGURE_WRFIO_PHDF5//g ;
185 $_ =~ s
:CONFIGURE_PHDF5_FLAG
::g
;
186 $_ =~ s
:CONFIGURE_PHDF5_LIB_PATH
::g
;
189 if ( $sw_jasperlib_path && $sw_jasperinc_path )
190 { $_ =~ s/CONFIGURE_WRFIO_GRIB2/wrfio_grib2/g ;
191 $_ =~ s
:CONFIGURE_GRIB2_FLAG
:-DGRIB2
:g
;
192 $_ =~ s
:CONFIGURE_GRIB2_INC
:-I
$sw_jasperinc_path:g
;
193 $_ =~ s
:CONFIGURE_GRIB2_LIB
:-L
../external/io_grib
2 -lio_grib2
-L
$sw_jasperlib_path -ljasper
:g
;
196 { $_ =~ s/CONFIGURE_WRFIO_GRIB2//g ;
197 $_ =~ s
:CONFIGURE_GRIB2_FLAG
::g
;
198 $_ =~ s
:CONFIGURE_GRIB2_INC
::g
;
199 $_ =~ s
:CONFIGURE_GRIB2_LIB
::g
;
203 # ESMF substitutions in configure.defaults
204 if ( $sw_esmflib_path && $sw_esmfinc_path )
206 $_ =~ s
:ESMFIOLIB
:-L
$sw_esmflib_path -lesmf
-L
../external/io_esmf
-lwrfio_esmf \
$\
(ESMF_LIB_FLAGS\
):g
;
207 $_ =~ s
:ESMFIOEXTLIB
:-L
$sw_esmflib_path -lesmf
-L
../../external
/io_esmf
-lwrfio_esmf \
$\
(ESMF_LIB_FLAGS\
):g
;
211 $_ =~ s
:ESMFIOLIB
:-L
../external/esmf_time_f90
-lesmf_time
:g
;
212 $_ =~ s
:ESMFIOEXTLIB
:-L
../../external
/esmf_time_f90
-lesmf_time
:g
;
215 @machopts = ( @machopts, $_ ) ;
216 if ( substr( $_, 0, 10 ) eq "ENVCOMPDEF" )
218 @machopts = ( @machopts, "WRF_CHEM\t=\t$WRFCHEM \n" ) ;
221 if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 0 )
225 if ( $x eq $optstr[$optchoice] )
231 close CONFIGURE_DEFAULTS
;
233 #printf "------------------------------------------------------------------------\n" ;
234 #foreach $f ( @machopts )
236 # if ( substr( $f , 0 , 8 ) eq "external" ) { last ; }
239 #printf "------------------------------------------------------------------------\n" ;
240 #printf "\nYou have chosen: %s",$optstr[$optchoice] ;
241 #printf "Listed above are the default options for this platform.\n" ;
242 #printf "Settings are written to the file configure.wps here in the top-level\n" ;
243 #printf "directory. If you wish to change settings, please edit that file.\n" ;
244 #printf "If you wish to change the default options, edit the file:\n\n" ;
245 #printf " arch/configure.defaults\n" ;
248 open CONFIGURE_WRF
, "> configure.wps" or die "cannot append configure.wps" ;
249 open ARCH_PREAMBLE
, "< arch/preamble" or die "cannot open arch/preamble" ;
251 # apply substitutions to the preamble...
252 while ( <ARCH_PREAMBLE
> )
254 if ( $sw_os eq "CYGWIN_NT" ) {
255 $_ =~ s/^WRF_DIR.*$/COMPILING_ON_CYGWIN_NT = yes/ ; # will get from environment
257 # ESMF substitutions in preamble
258 if ( $sw_esmflib_path && $sw_esmfinc_path )
260 $_ =~ s/ESMFCOUPLING/1/g ;
261 $_ =~ s
:ESMFMODDEPENDENCE
:../external/io_esmf
/module_utility
.o
:g
;
262 $_ =~ s
:ESMFMODINC
:-I
$sw_esmfinc_path -I
../main
:g
;
263 $_ =~ s
:ESMFIOINC
:-I
../external/io_esmf
:g
;
264 $_ =~ s
:ESMFIODEFS
:-DESMFIO
:g
;
265 $_ =~ s
:ESMFTARGET
:wrfio_esmf
:g
;
269 $_ =~ s/ESMFCOUPLING/0/g ;
270 $_ =~ s
:ESMFMODDEPENDENCE
:../external/esmf_time_f90
/module_utility
.o
:g
;
271 $_ =~ s
:ESMFMODINC
::g
;
272 $_ =~ s
:ESMFIOINC
:-I
../external/esmf_time_f90
:g
;
273 $_ =~ s
:ESMFIODEFS
::g
;
274 $_ =~ s
:ESMFTARGET
:esmf_time
:g
;
276 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
277 @preamble = ( @preamble, $_ ) ;
279 close ARCH_PREAMBLE
;
280 print CONFIGURE_WRF
@preamble ;
281 close ARCH_PREAMBLE
;
282 printf CONFIGURE_WRF
"# Settings for %s", $optstr[$optchoice] ;
283 print CONFIGURE_WRF
@machopts ;
284 open ARCH_POSTAMBLE
, "< arch/postamble" or die "cannot open arch/postamble" ;
285 while ( <ARCH_POSTAMBLE
> ) {
286 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
287 print CONFIGURE_WRF
;
289 close ARCH_POSTAMBLE
;
290 close CONFIGURE_WRF
;
292 printf "Configuration successful. To build the WPS, type: compile \n" ;
293 printf "------------------------------------------------------------------------\n" ;