[207] | 1 | #!/usr/bin/perl |
---|
| 2 | # |
---|
| 3 | # Configuration script for ARWpost 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_ldflags=""; |
---|
| 11 | $sw_compileflags=""; |
---|
| 12 | $sw_os = "ARCH" ; # ARCH will match any |
---|
| 13 | $sw_mach = "ARCH" ; # ARCH will match any |
---|
| 14 | |
---|
| 15 | while ( substr( $ARGV[0], 0, 1 ) eq "-" ) |
---|
| 16 | { |
---|
| 17 | if ( substr( $ARGV[0], 1, 5 ) eq "perl=" ) |
---|
| 18 | { |
---|
| 19 | $sw_perl_path = substr( $ARGV[0], 6 ) ; |
---|
| 20 | } |
---|
| 21 | if ( substr( $ARGV[0], 1, 7 ) eq "netcdf=" ) |
---|
| 22 | { |
---|
| 23 | $sw_netcdf_path = substr( $ARGV[0], 8 ) ; |
---|
| 24 | } |
---|
| 25 | if ( substr( $ARGV[0], 1, 3 ) eq "os=" ) |
---|
| 26 | { |
---|
| 27 | $sw_os = substr( $ARGV[0], 4 ) ; |
---|
| 28 | } |
---|
| 29 | if ( substr( $ARGV[0], 1, 5 ) eq "mach=" ) |
---|
| 30 | { |
---|
| 31 | $sw_mach = substr( $ARGV[0], 6 ) ; |
---|
| 32 | } |
---|
| 33 | if ( substr( $ARGV[0], 1, 8 ) eq "ldflags=" ) |
---|
| 34 | { |
---|
| 35 | $sw_ldflags = substr( $ARGV[0], 9 ) ; |
---|
| 36 | # multiple options separated by spaces are passed in from sh script |
---|
| 37 | # separated by ! instead. Replace with spaces here. |
---|
| 38 | $sw_ldflags =~ s/!/ /g ; |
---|
| 39 | } |
---|
| 40 | if ( substr( $ARGV[0], 1, 13 ) eq "compileflags=" ) |
---|
| 41 | { |
---|
| 42 | $sw_compileflags = substr( $ARGV[0], 14 ) ; |
---|
| 43 | $sw_compileflags =~ s/!/ /g ; |
---|
| 44 | } |
---|
| 45 | shift @ARGV ; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | # parse the configure.wps file |
---|
| 50 | |
---|
| 51 | $validresponse = 0 ; |
---|
| 52 | |
---|
| 53 | # Display the choices to the user and get selection |
---|
| 54 | until ( $validresponse ) { |
---|
| 55 | printf "------------------------------------------------------------------------\n" ; |
---|
| 56 | printf "Please select from among the following supported platforms.\n\n" ; |
---|
| 57 | |
---|
| 58 | $opt = 1 ; |
---|
| 59 | open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" |
---|
| 60 | or die "Cannot open ./arch/configure.defaults for reading" ; |
---|
| 61 | while ( <CONFIGURE_DEFAULTS> ) |
---|
| 62 | { |
---|
| 63 | if ( substr( $_, 0, 5 ) eq "#ARCH" && ( index( $_, $sw_os ) >= 0 ) && ( index( $_, $sw_mach ) >= 0 ) ) |
---|
| 64 | { |
---|
| 65 | $optstr[$opt] = substr($_,6) ; |
---|
| 66 | $optstr[$opt] =~ s/^[ ]*// ; |
---|
| 67 | if ( substr( $optstr[$opt], 0,4 ) ne "NULL" ) |
---|
| 68 | { |
---|
| 69 | printf " %2d. %s",$opt,$optstr[$opt] ; |
---|
| 70 | $opt++ ; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | close CONFIGURE_DEFAULTS ; |
---|
| 75 | |
---|
| 76 | $opt -- ; |
---|
| 77 | |
---|
| 78 | printf "\nEnter selection [%d-%d] : ",1,$opt ; |
---|
| 79 | $response = <STDIN> ; |
---|
| 80 | |
---|
| 81 | if ( $response == -1 ) { exit ; } |
---|
| 82 | |
---|
| 83 | if ( $response >= 1 && $response <= $opt ) |
---|
| 84 | { $validresponse = 1 ; } |
---|
| 85 | else |
---|
| 86 | { printf("\nInvalid response (%d)\n",$response);} |
---|
| 87 | } |
---|
| 88 | printf "------------------------------------------------------------------------\n" ; |
---|
| 89 | |
---|
| 90 | $optchoice = $response ; |
---|
| 91 | |
---|
| 92 | open CONFIGURE_DEFAULTS, "< ./arch/configure.defaults" |
---|
| 93 | or die "Cannot open ./arch/configure.defaults for reading" ; |
---|
| 94 | $latchon = 0 ; |
---|
| 95 | while ( <CONFIGURE_DEFAULTS> ) |
---|
| 96 | { |
---|
| 97 | if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 1 ) |
---|
| 98 | { |
---|
| 99 | $latchon = 0 ; |
---|
| 100 | } |
---|
| 101 | if ( $latchon == 1 ) |
---|
| 102 | { |
---|
| 103 | $_ =~ s/CONFIGURE_PERL_PATH/$sw_perl_path/g ; |
---|
| 104 | $_ =~ s/CONFIGURE_NETCDF_PATH/$sw_netcdf_path/g ; |
---|
| 105 | $_ =~ s/CONFIGURE_LDFLAGS/$sw_ldflags/g ; |
---|
| 106 | $_ =~ s/CONFIGURE_COMPILEFLAGS/$sw_compileflags/g ; |
---|
| 107 | if ( $sw_netcdf_path ) |
---|
| 108 | { $_ =~ s/CONFIGURE_WRFIO_NF/wrfio_nf/g ; |
---|
| 109 | $_ =~ s:CONFIGURE_NETCDF_FLAG:-DNETCDF: ; |
---|
| 110 | $_ =~ s:CONFIGURE_NETCDF_LIB_PATH:-L../external/io_netcdf -lwrfio_nf -L$sw_netcdf_path/lib -lnetcdf: ; |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { $_ =~ s/CONFIGURE_WRFIO_NF//g ; |
---|
| 114 | $_ =~ s:CONFIGURE_NETCDF_FLAG::g ; |
---|
| 115 | $_ =~ s:CONFIGURE_NETCDF_LIB_PATH::g ; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | @machopts = ( @machopts, $_ ) ; |
---|
| 120 | } |
---|
| 121 | if ( substr( $_, 0, 5 ) eq "#ARCH" && $latchon == 0 ) |
---|
| 122 | { |
---|
| 123 | $x=substr($_,6) ; |
---|
| 124 | $x=~s/^[ ]*// ; |
---|
| 125 | if ( $x eq $optstr[$optchoice] ) |
---|
| 126 | { |
---|
| 127 | $latchon = 1 ; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | close CONFIGURE_DEFAULTS ; |
---|
| 132 | |
---|
| 133 | #printf "------------------------------------------------------------------------\n" ; |
---|
| 134 | #foreach $f ( @machopts ) |
---|
| 135 | #{ |
---|
| 136 | # if ( substr( $f , 0 , 8 ) eq "external" ) { last ; } |
---|
| 137 | # print $f ; |
---|
| 138 | #} |
---|
| 139 | #printf "------------------------------------------------------------------------\n" ; |
---|
| 140 | #printf "\nYou have chosen: %s",$optstr[$optchoice] ; |
---|
| 141 | #printf "Listed above are the default options for this platform.\n" ; |
---|
| 142 | #printf "Settings are written to the file configure.wps here in the top-level\n" ; |
---|
| 143 | #printf "directory. If you wish to change settings, please edit that file.\n" ; |
---|
| 144 | #printf "If you wish to change the default options, edit the file:\n\n" ; |
---|
| 145 | #printf " arch/configure.defaults\n" ; |
---|
| 146 | #printf "\n" ; |
---|
| 147 | |
---|
| 148 | open CONFIGURE_WRF, "> configure.arwp" or die "cannot append configure.arwp" ; |
---|
| 149 | open ARCH_PREAMBLE, "< arch/preamble" or die "cannot open arch/preamble" ; |
---|
| 150 | my @preamble; |
---|
| 151 | # apply substitutions to the preamble... |
---|
| 152 | while ( <ARCH_PREAMBLE> ) |
---|
| 153 | { |
---|
| 154 | @preamble = ( @preamble, $_ ) ; |
---|
| 155 | } |
---|
| 156 | close ARCH_PREAMBLE ; |
---|
| 157 | print CONFIGURE_WRF @preamble ; |
---|
| 158 | close ARCH_PREAMBLE ; |
---|
| 159 | printf CONFIGURE_WRF "# Settings for %s", $optstr[$optchoice] ; |
---|
| 160 | print CONFIGURE_WRF @machopts ; |
---|
| 161 | open ARCH_POSTAMBLE, "< arch/postamble" or die "cannot open arch/postamble" ; |
---|
| 162 | while ( <ARCH_POSTAMBLE> ) { print CONFIGURE_WRF } ; |
---|
| 163 | close ARCH_POSTAMBLE ; |
---|
| 164 | close CONFIGURE_WRF ; |
---|
| 165 | |
---|
| 166 | printf "Configuration successful. To build the WPS, type: compile \n" ; |
---|
| 167 | printf "------------------------------------------------------------------------\n" ; |
---|
| 168 | |
---|
| 169 | |
---|