Update ungrib to properly handle the new (2017) GFS missing codes.
[WPS.git] / arch / Config.pl
blobfb04ed950d90e1184bbb1f0d6ec5940a374103c6
1 #!/usr/bin/perl
3 # Configuration script for WPS code
4 #
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!
9 $sw_perl_path = perl;
10 $sw_netcdf_path = "";
11 $sw_netcdff_lib = "";
12 $sw_phdf5_path = "";
13 $sw_jasperlib_path = "";
14 $sw_jasperinc_path = "";
15 $sw_ldflags = "";
16 $sw_compileflags = "";
17 $sw_os = "ARCH" ; # ARCH will match any
18 $sw_mach = "ARCH" ; # ARCH will match any
19 #$sw_compL = "";
20 #$sw_compI = "";
21 #$sw_fdefs = "";
22 #$sw_fc = "";
23 #$sw_cc = "";
24 #$sw_mpi = "";
26 while(substr( $ARGV[0], 0, 1 ) eq "-")
28 if(substr( $ARGV[0], 1, 5 ) eq "perl=")
30 $sw_perl_path = substr( $ARGV[0], 6);
32 if(substr( $ARGV[0], 1, 7 ) eq "netcdf=")
34 $sw_netcdf_path = substr( $ARGV[0], 8);
36 if(substr( $ARGV[0], 1, 8 ) eq "netcdff=")
38 $sw_netcdff_lib = substr( $ARGV[0], 9);
40 if(substr( $ARGV[0], 1, 6 ) eq "phdf5=")
42 $sw_phdf5_path = substr( $ARGV[0], 7);
44 if(substr( $ARGV[0], 1, 3 ) eq "os=")
46 $sw_os = substr( $ARGV[0], 4 );
48 if(substr( $ARGV[0], 1, 5 ) eq "mach=")
50 $sw_mach = substr( $ARGV[0], 6 );
52 if(substr( $ARGV[0], 1, 8 ) eq "ldflags=")
54 $sw_ldflags = substr( $ARGV[0], 9 );
55 # multiple options separated by spaces are passed in from sh script
56 # separated by ! instead. Replace with spaces here.
57 $sw_ldflags =~ s/!/ /g ;
59 shift @ARGV;
60 } # end while
62 # The jasper library is required to build Grib2 I/O. User must set
63 # environment variables JASPERLIB and JASPERINC to paths to library and
64 # include files to enable this feature prior to running configure.
65 if($ENV{JASPERLIB} && $ENV{JASPERINC})
67 printf "Found Jasper environment variables for GRIB2 support...\n";
68 printf(" \$JASPERLIB = %s\n",$ENV{JASPERLIB});
69 printf(" \$JASPERINC = %s\n",$ENV{JASPERINC});
70 $sw_jasperlib_path = "-L$ENV{JASPERLIB} -ljasper -lpng -lz";
71 $sw_jasperinc_path = "-I$ENV{JASPERINC}";
73 else
76 $tmp1 = '/usr/local/jasper';
77 if (-e $tmp1) {
78 $sw_jasperlib_path = '-L/usr/local/jasper/lib -ljasper -L/usr/local/libpng -lpng12 -lpng -L/usr/local/zlib/lib -lz' ;
79 $sw_jasperinc_path = '-I/usr/local/zlib/include -I/usr/local/jasper/include -I/usr/local/libpng/' ;
80 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /usr/local for library paths...\n";
82 else {
83 $tmp1 = '/opt/local/lib';
84 if (-e $tmp1) {
85 $sw_jasperlib_path = '-L/opt/local/lib -ljasper -lpng -lz';
86 $sw_jasperinc_path = '-I/opt/local/include';
87 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using /opt/local for library paths...\n";
89 else {
90 $sw_jasperlib_path = '-L/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/lib -ljasper -lpng -lz';
91 $sw_jasperinc_path = '-I/glade/u/home/wrfhelp/UNGRIB_LIBRARIES/include';
92 printf "\$JASPERLIB or \$JASPERINC not found in environment. Using default values for library paths...\n";
97 $validresponse = 0 ;
98 # added this from the WRF Config.pl by John M.
99 @platforms = ('serial', 'serial_NO_GRIB2', 'dmpar', 'dmpar_NO_GRIB2');
100 # Display the choices to the user and get selection
101 until ($validresponse)
103 printf "------------------------------------------------------------------------\n";
104 printf "Please select from among the following supported platforms.\n\n";
106 $opt = 1;
107 # Read configure.defaults
108 open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults"
109 || die "Cannot open ./arch/configure.defaults for reading";
110 # first read through the .defaults, user select and a read of all appropriate parms is not done here
111 while(<CONFIGURE_DEFAULTS>)
113 for $paropt (@platforms)
115 # read all the System/OS/Compiler appropriate selections and present same to user
116 if(substr($_, 0, 5) eq "#ARCH" && (index($_, $sw_os) >= 0) && (index($_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
118 $optstr[$opt] = substr($_,6);
119 $optstr[$opt] =~ s/^[ ]*//;
120 $optstr[$opt] =~ s/#.*$//g;
121 chomp($optstr[$opt]);
122 $optstr[$opt] = $optstr[$opt]." (".$paropt.")";
123 if(substr($optstr[$opt], 0, 4) ne "NULL")
125 printf " %2d. %s\n", $opt, $optstr[$opt];
126 $opt++;
131 close CONFIGURE_DEFAULTS;
133 $opt --;
135 printf "\nEnter selection [%d-%d] : ", 1, $opt;
136 $response = <STDIN>;
137 if($response == -1) {exit;}
138 if($response >= 1 && $response <= $opt)
140 $validresponse = 1;
142 else
144 printf("\nInvalid response (%d)\n",$response);
148 printf "------------------------------------------------------------------------\n";
149 # save user input
150 $optchoice = $response;
152 # this HAS to be opened in 'cat' mode... why?
153 open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" || die "cannot Open for writing... configure.defaults: \n";
154 $latchon = 0;
155 while(<CONFIGURE_DEFAULTS>)
157 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 1)
159 $latchon = 0;
161 if($latchon == 1)
163 $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g;
164 $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g;
165 $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g;
166 $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g;
167 $_ =~ s/CONFIGURE_COMP_L/$sw_compL/g;
168 $_ =~ s/CONFIGURE_COMP_I/$sw_compI/g;
169 $_ =~ s/CONFIGURE_FDEFS/$sw_fdefs/g;
170 $_ =~ s/CONFIGURE_FC/$sw_fc/g;
171 $_ =~ s/CONFIGURE_CC/$sw_cc/g;
172 $_ =~ s/CONFIGURE_MPI/$sw_mpi/g;
174 # Load the read in parameters from the configure.defaults file
175 if(!(substr($_, 0, 5) eq "#ARCH"))
177 @machopts = (@machopts, $_);
179 } # end if latchon == 1
181 #-----------------------------------------------------------------------------------------------
182 # added for the unified WPS build
183 # init the following for the configure.wps write
186 # now loop through the .defaults again and read the parameters to be written into the configure.wps
187 for $paropt (@platforms)
189 if(substr($_, 0, 5) eq "#ARCH" && $latchon == 0 && (index( $_, $sw_os) >= 0) && (index( $_, $sw_mach) >= 0) && (index($_, $paropt) >= 0))
191 # after #ARCH the following reads the rest of the line in the configure.defaults
192 $x=substr($_,6);
193 $x=~s/^[ ]*//;
194 $x =~ s/#.*$//g;
195 chomp($x);
196 $x = $x." (".$paropt.")" ;
198 if($x eq $optstr[$optchoice])
200 $latchon = 1;
202 if($latchon == 1)
204 if($paropt eq 'serial')
206 if($ENV{JASPERLIB} && $ENV{JASPERINC})
208 $sw_compL = $sw_jasperlib_path;
209 $sw_compI = $sw_jasperinc_path;
211 else
213 $sw_compL = $sw_jasperlib_path;
214 $sw_compI = $sw_jasperinc_path;
215 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
216 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
218 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
219 $sw_fc = "\$(SFC)";
220 $sw_cc = "\$(SCC)";
221 $sw_mpi = "";
223 if($paropt eq 'serial_NO_GRIB2')
225 $sw_compL = "";
226 $sw_compI = "";
227 $sw_fdefs = "";
228 $sw_fc = "\$(SFC)";
229 $sw_cc = "\$(SCC)";
230 $sw_mpi = "";
232 if($paropt eq 'dmpar')
234 if($ENV{JASPERLIB} && $ENV{JASPERINC})
236 $sw_compL = $sw_jasperlib_path;
237 $sw_compI = $sw_jasperinc_path;
239 else
241 $sw_compL = $sw_jasperlib_path;
242 $sw_compI = $sw_jasperinc_path;
243 # $sw_compL = "-L/contrib/jasper/lib -L/opt/freeware/lib -ljasper -lpng -lz";
244 # $sw_compI = "-I/contrib/libpng/include -I/contrib/zlib/include -I/contrib/jasper/include";
246 $sw_fdefs = "-DUSE_JPEG2000 -DUSE_PNG";
247 $sw_fc = "\$(DM_FC)";
248 $sw_cc = "\$(DM_CC)";
249 $sw_mpi = "-D_MPI";
251 if($paropt eq 'dmpar_NO_GRIB2')
253 $sw_compL = "";
254 $sw_compI = "";
255 $sw_fdefs = "";
256 $sw_fc = "\$(DM_FC)";
257 $sw_cc = "\$(DM_CC)";
258 $sw_mpi = "-D_MPI";
261 #####################################################################################
262 } # end if latchon == 1
263 } # end if
264 } # end for
266 close CONFIGURE_DEFAULTS ;
268 #printf "\n------------------------------------------------------------------------\n";
269 #foreach $f (@machopts)
271 # if(substr($f , 0 , 8) eq "external")
272 # {
273 # last ;
275 # print $f;
277 #printf "--------------------------------------------------------------------------\n";
278 #printf "\nYou have chosen: %s\n",$optstr[$optchoice];
279 #printf "Listed above are the default options for this platform.\n";
280 #printf "Settings are written to the file configure.wps here in the top-level\n";
281 #printf "directory. If you wish to change settings, please edit that file.\n";
282 #printf "If you wish to change the default options, edit the file:\n\n";
283 #printf " arch/configure.defaults\n";
284 #printf "\n";
285 #printf "------------------------------------------------------------------------\n";
287 open CONFIGURE_WRF, "> configure.wps" || die "cannot Open for writing... configure.wps: \n";
288 open ARCH_PREAMBLE, "< arch/preamble" || die "cannot Open for reading... arch/preamble: \n";
289 my @preamble;
290 # apply substitutions to the preamble...
291 while (<ARCH_PREAMBLE>)
293 if($sw_os eq "CYGWIN_NT")
295 $_ =~ s/^WRF_DIR.*$/COMPILING_ON_CYGWIN_NT = yes/; # will get from environment
298 $_ =~ s:CONFIGURE_NETCDFF_LIB:$sw_netcdff_lib:g;
299 @preamble = ( @preamble, $_ ) ;
301 close ARCH_PREAMBLE;
304 print CONFIGURE_WRF @preamble;
305 close ARCH_PREAMBLE;
306 printf CONFIGURE_WRF "#\n";
307 printf CONFIGURE_WRF "# Settings for %s \n", $optstr[$optchoice];
308 printf CONFIGURE_WRF "#\n";
309 print CONFIGURE_WRF @machopts;
311 open ARCH_POSTAMBLE, "< arch/postamble" || die "cannot open arch/postamble: \n";
312 while(<ARCH_POSTAMBLE>)
314 $_ =~ s:CONFIGURE_NETCDFF_LIB:$sw_netcdff_lib:g;
315 print CONFIGURE_WRF;
318 close ARCH_POSTAMBLE;
319 close CONFIGURE_WPS;
321 printf "Configuration successful. To build the WPS, type: compile\n";
322 printf "------------------------------------------------------------------------\n";