3 # Configuration script for WPS code
5 # Be sure to run as ./configure (to avoid getting a system configure command by mistake)
6 # There are two (2) reads of the configure.defaults one to present the user with
7 # the appropriate options for the type of machine, and the OS, and the compiler!
10 $sw_wrf_path = "<SET ME>";
14 $sw_jasperlib_path = "";
15 $sw_jasperinc_path = "";
17 $sw_compileflags = "";
18 $sw_os = "ARCH" ; # ARCH will match any
19 $sw_mach = "ARCH" ; # ARCH will match any
27 while(substr( $ARGV[0], 0, 1 ) eq "-")
29 if(substr( $ARGV[0], 1, 5 ) eq "perl=")
31 $sw_perl_path = substr( $ARGV[0], 6);
33 if(substr( $ARGV[0], 1, 7 ) eq "wrfdir=")
35 $sw_wrf_path = substr( $ARGV[0], 8);
37 if(substr( $ARGV[0], 1, 7 ) eq "netcdf=")
39 $sw_netcdf_path = substr( $ARGV[0], 8);
41 if(substr( $ARGV[0], 1, 8 ) eq "netcdff=")
43 $sw_netcdff_lib = substr( $ARGV[0], 9);
45 if(substr( $ARGV[0], 1, 6 ) eq "phdf5=")
47 $sw_phdf5_path = substr( $ARGV[0], 7);
49 if(substr( $ARGV[0], 1, 3 ) eq "os=")
51 $sw_os = substr( $ARGV[0], 4 );
53 if(substr( $ARGV[0], 1, 5 ) eq "mach=")
55 $sw_mach = substr( $ARGV[0], 6 );
57 if(substr( $ARGV[0], 1, 8 ) eq "ldflags=")
59 $sw_ldflags = substr( $ARGV[0], 9 );
60 # multiple options separated by spaces are passed in from sh script
61 # separated by ! instead. Replace with spaces here.
62 $sw_ldflags =~ s/!/ /g ;
67 # The jasper library is required to build Grib2 I/O. User must set
68 # environment variables JASPERLIB and JASPERINC to paths to library and
69 # include files to enable this feature prior to running configure.
70 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
72 printf "Found Jasper environment variables for GRIB2 support...\n";
73 printf(" \$JASPERLIB = %s\n",$ENV{JASPERLIB
});
74 printf(" \$JASPERINC = %s\n",$ENV{JASPERINC
});
75 $sw_jasperlib_path = "-L$ENV{JASPERLIB} -ljasper -lpng -lz";
76 $sw_jasperinc_path = "-I$ENV{JASPERINC}";
81 $tmp1 = '/usr/local/jasper';
83 $sw_jasperlib_path = '-L/usr/local/jasper/lib -ljasper -L/usr/local/libpng -lpng12 -lpng -L/usr/local/zlib/lib -lz' ;
84 $sw_jasperinc_path = '-I/usr/local/zlib/include -I/usr/local/jasper/include -I/usr/local/libpng/' ;
85 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /usr/local for library paths...\n";
88 $tmp1 = '/opt/local/lib';
90 $sw_jasperlib_path = '-L/opt/local/lib -ljasper -lpng -lz';
91 $sw_jasperinc_path = '-I/opt/local/include';
92 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /opt/local for library paths...\n";
95 $sw_jasperlib_path = '-L/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/lib -ljasper -lpng -lz';
96 $sw_jasperinc_path = '-I/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/include';
97 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using default values for library paths...\n";
103 # added this from the WRF Config.pl by John M.
104 @platforms = ('serial', 'serial_NO_GRIB2', 'dmpar', 'dmpar_NO_GRIB2');
105 # Display the choices to the user and get selection
106 until ($validresponse)
108 printf "------------------------------------------------------------------------\n";
109 printf "Please select from among the following supported platforms.\n\n";
112 # Read configure.defaults
113 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults"
114 || die "Cannot open ./arch/configure.defaults for reading";
115 # first read through the .defaults, user select and a read of all appropriate parms is not done here
116 while(<CONFIGURE_DEFAULTS
>)
118 for $paropt (@platforms)
120 # read all the System/OS/Compiler appropriate selections and present same to user
121 if(substr($_, 0, 5) eq "#ARCH" && (index($_, $sw_os) >= 0) && (index($_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
123 $optstr[$opt] = substr($_,6);
124 $optstr[$opt] =~ s/^[ ]*//;
125 $optstr[$opt] =~ s/#.*$//g;
126 chomp($optstr[$opt]);
127 $optstr[$opt] = $optstr[$opt]." (".$paropt.")";
128 if(substr($optstr[$opt], 0, 4) ne "NULL")
130 printf " %2d. %s\n", $opt, $optstr[$opt];
136 close CONFIGURE_DEFAULTS
;
140 printf "\nEnter selection [%d-%d] : ", 1, $opt;
142 if($response == -1) {exit;}
143 if($response >= 1 && $response <= $opt)
149 printf("\nInvalid response (%d)\n",$response);
153 printf "------------------------------------------------------------------------\n";
155 $optchoice = $response;
157 # this HAS to be opened in 'cat' mode... why?
158 open CONFIGURE_DEFAULTS
, "< ./arch/configure.defaults" || die "cannot Open for writing... configure.defaults: \n";
160 while(<CONFIGURE_DEFAULTS
>)
162 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 1)
168 $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g;
169 $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g;
170 $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g;
171 $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g;
172 $_ =~ s/CONFIGURE_COMP_L/$sw_compL/g;
173 $_ =~ s/CONFIGURE_COMP_I/$sw_compI/g;
174 $_ =~ s/CONFIGURE_FDEFS/$sw_fdefs/g;
175 $_ =~ s/CONFIGURE_FC/$sw_fc/g;
176 $_ =~ s/CONFIGURE_CC/$sw_cc/g;
177 $_ =~ s/CONFIGURE_MPI/$sw_mpi/g;
179 # Load the read in parameters from the configure.defaults file
180 if(!(substr($_, 0, 5) eq "#ARCH"))
182 @machopts = (@machopts, $_);
184 } # end if latchon == 1
186 #-----------------------------------------------------------------------------------------------
187 # added for the unified WPS build
188 # init the following for the configure.wps write
191 # now loop through the .defaults again and read the parameters to be written into the configure.wps
192 for $paropt (@platforms)
194 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 0 && (index( $_, $sw_os) >= 0) && (index( $_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
196 # after #ARCH the following reads the rest of the line in the configure.defaults
201 $x = $x." (".$paropt.")" ;
203 if($x eq $optstr[$optchoice])
209 if($paropt eq 'serial')
211 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
213 $sw_compL = $sw_jasperlib_path;
214 $sw_compI = $sw_jasperinc_path;
218 $sw_compL = $sw_jasperlib_path;
219 $sw_compI = $sw_jasperinc_path;
220 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
221 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
223 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
228 if($paropt eq 'serial_NO_GRIB2')
237 if($paropt eq 'dmpar')
239 if($ENV{JASPERLIB
} && $ENV{JASPERINC
})
241 $sw_compL = $sw_jasperlib_path;
242 $sw_compI = $sw_jasperinc_path;
246 $sw_compL = $sw_jasperlib_path;
247 $sw_compI = $sw_jasperinc_path;
248 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
249 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
251 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
252 $sw_fc = "\$(DM_FC)";
253 $sw_cc = "\$(DM_CC)";
256 if($paropt eq 'dmpar_NO_GRIB2')
261 $sw_fc = "\$(DM_FC)";
262 $sw_cc = "\$(DM_CC)";
266 #####################################################################################
267 } # end if latchon == 1
271 close CONFIGURE_DEFAULTS
;
273 #printf "\n------------------------------------------------------------------------\n";
274 #foreach $f (@machopts)
276 # if(substr($f , 0 , 8) eq "external")
282 #printf "--------------------------------------------------------------------------\n";
283 #printf "\nYou have chosen: %s\n",$optstr[$optchoice];
284 #printf "Listed above are the default options for this platform.\n";
285 #printf "Settings are written to the file configure.wps here in the top-level\n";
286 #printf "directory. If you wish to change settings, please edit that file.\n";
287 #printf "If you wish to change the default options, edit the file:\n\n";
288 #printf " arch/configure.defaults\n";
290 #printf "------------------------------------------------------------------------\n";
292 open CONFIGURE_WRF
, "> configure.wps" || die "cannot Open for writing... configure.wps: \n";
293 open ARCH_PREAMBLE
, "< arch/preamble" || die "cannot Open for reading... arch/preamble: \n";
295 # apply substitutions to the preamble...
296 while (<ARCH_PREAMBLE
>)
298 if($sw_os eq "CYGWIN_NT")
300 $_ =~ s/^WRF_DIR.*$/COMPILING_ON_CYGWIN_NT = yes/; # will get from environment
303 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
304 $_ =~ s
:CONFIGURE_WRF_PATH
:$sw_wrf_path:g
;
305 @preamble = ( @preamble, $_ ) ;
310 print CONFIGURE_WRF
@preamble;
312 printf CONFIGURE_WRF
"#\n";
313 printf CONFIGURE_WRF
"# Settings for %s \n", $optstr[$optchoice];
314 printf CONFIGURE_WRF
"#\n";
315 print CONFIGURE_WRF
@machopts;
317 open ARCH_POSTAMBLE
, "< arch/postamble" || die "cannot open arch/postamble: \n";
318 while(<ARCH_POSTAMBLE
>)
320 $_ =~ s
:CONFIGURE_NETCDFF_LIB
:$sw_netcdff_lib:g
;
324 close ARCH_POSTAMBLE
;
327 printf "Configuration successful. To build the WPS, type: compile\n";
328 printf "------------------------------------------------------------------------\n";