#!C:\Perl\bin\perl -w
#
# smarts293f.pl
# version for the smarts_293f.exe
#------------------------------------------------------------------------------
# A script to generate the smarts2.INP file interactively,
# to run smarts2.exe and to display smarts2.OUT and smarts2.EXT
# if wanted.
# This script should be placed in the smarts2 directory!
#
# There are at least 3 possibilities to run the script under Windows:
# --------------------------------------------------------------------
# 1. switch to command-line mode, and type "perl smarts2.pl"
# 2. create a shortcut on the desktop like "C:\Perl\bin\perl.exe smarts2.pl"
#    and click on the shortcut
# 3. Associate the .pl extension to the PERL interpreter and click on "smarts2.pl"
#
# Tested with the free ACTIVEPERL under Win2000 Pro
# see http://aspn.activestate.com/ASPN/Downloads/ActivePerl
#
# The script needs an editor to output the smarts2.OUT and/or smarts2.EXT
# Here the standard notepad.exe is used;
# any other like notepad or wordpad will do ! Please change the last lines
# accordingly!
#
# Change the first line #!C:\Perl\bin\perl -w to your Perl directory!
#
#
# francis massen                                  francis.massen@education.lu
# http://meteo.lcd.lu
#
# version 1.00  25 Mar 2003
#               -first version with numerous choices fixed for the
#                Microtops user and meteoLCD location and usages
#         1.10  10 Apr 2003
#               -added subroutine to fill cards with blanks so that the comment
#                marks (!) are vertically aligned on column 40 for smarts2.INP
#               -added lists with references
#               -added all missing possibilities
#         1.20  12 Apr 2003
#               -corrected bug in water column card4 (section 2)
#               -corrected missing point [4] in card 17a (section 2)
#         1.21  15 April 2003
#               -slight changes to default directories
#         1.22  17 April 2003
#               -missing check for default azimuth in card17a corrected
#               -several other small errors
#         2.00  10 Nov 2003
#               implemented changes to respect the modifications introduced by
#               smarts_293f:
#               - card2a has a new variable $HEIGHT [km, above groundlevel]
#               - card7a has a new option [0] (Gueymard 2003 spectrum)
#               - card9/9a has a new variable $TAU550
#	  2.01  04 Nov 2007
#               added one comment that "smarts2" is default name for input file
#               default editor is C:\windows\system32\notepad.exe in C
#===============================================================================
# default directories (double back-slashes needed by Perl!)
# change these to your directories
#------------------------------------------------------------
#
# $VERSION = version of smarts2
$VERSION = "SMARTS_293f.exe";
#
# Any version of smarts2 can be used (normal or batch version)
# $SMARTS2 = path of smarts2.exe and executable
#
$SMARTS2   =  "D:\\meteolcd\\smarts2\\SMARTS_293f_PC\\smarts_293f.exe";
#
# $SMARTS2batch = path and executable batch version smarts_292
$SMARTS2batch = "D:\\meteolcd\\smarts2\\SMARTS_293_PC\\SMARTS_292_batch.exe";
#
# $DIR = directory of executable
$DIR = "D:\\meteolcd\\smarts2\\SMARTS_293f_PC";
#
# default editor
$EDIT = "C:\\windows\\system32\\notepad.exe";
#
#-------------------------------------------------------------------------------
#check if files exist. If they do, delete them
#
$smarts2inp = $DIR."\\smarts2.INP";
$smarts2out = $DIR."\\smarts2.OUT";
$smarts2ext = $DIR."\\smarts2.EXT";
$smarts2scn = $DIR."\\smarts2.SCN";
$smarts2new = $DIR."\\smarts2.NEW";
#
if (-e $smarts2inp) {
                     unlink("$smarts2inp");
                    }
if (-e $smarts2out) {
                     unlink("$smarts2out");
                    }
if (-e $smarts2ext) {
                     unlink("$smarts2ext");
                    }
if (-e $smarts2scn) {
                     unlink("$smarts2scn");
                    }
if (-e $smarts2new) {
                     unlink("$smarts2new");
                    }
#
#
#===============================================================================
# SUBROUTINES
#
#===============================================================================
# subroutine to align comment mark ! in smarts2.INP
# change variable $aligncolumn to your gusto...
#------------------------------------------------------------
#
# subroutine to align the comment marks in the card descriiptions
# to a fixed column --> gives a beautified smarts2.INP file
sub align
{
$aligncolumn = 40;
# length of string with variables
# if length < $aligncolumn, fill up with spaces
# else leave it as it is
$len = length($_[0]);
if ($len < $aligncolumn)
  {
   for ($i=1; $i <= ($aligncolumn-$len); $i++)
    {
     $_[0] = $_[0]." ";
    }
  }
return $_[0];
}
#------------------------------------------------------------
# picka
# subroutine to pick an answer (Y/N) from <STDIN> (=keyboard)
# and return the first character only or the "X" string
# if the <ENTER> key was hit when choosing a default
sub picka
{
 $_[0] = (<STDIN>);
 if (length($_[0]) == 1)
 {
  $_[0] = "X";
 }
 else
 {
 $_[0] = substr($_[0],0,1);
 }
 return $_[0];
}
#
#-----------------------------------------------------------
# pickn
# subroutine to pick a number from <STDIN> (=keyboard)
# and return the first character only or the "X" string
# if the <ENTER> key was hit when choosing a default
sub pickn
{
 $_[0] = (<STDIN>);
 if (length($_[0]) == 1)
 {
  $_[0] = "X";
 }
 chomp($_[0]);
 return $_[0];
}
#
#
#------------------------------------------------------------
# punits
# subroutine to print either ug/m3 or ppmV
sub punits
{
       if ($_[0] == 0 ) {
                         print "ppmV";
                        }
                   else {
                         print "ug/m3";
                        }
}
#==============================================================================
# SECTION 0
#
# Tables
# ------
#
# @refatmos = table of 10 reference atmospheres
#
@refatmos = ("'USSA'","'MLS'","'MLW'","'SAS'","'SAW'","'TRL'","'STS'","'STW'","'AS'","'AW'");
#
# Lists with default pollution types
# Order of the 10 gases is:
#                      Ý    Ý    Ý          Ý      Ý      Ý         Ý        Ý       Ý
#                 CH2O, CH4,  CO,   HNO2,     HNO3,    NO,     NO2,   NO3,     O3,     SO2
#                      Ý    Ý    Ý          Ý      Ý      Ý         Ý        Ý       Ý
#
# defaults for pristine atm.
@refpristine = (-0.003, 0,   -0.1,  -9.9E-4,  0,       0,      0,     -4.9E-4, -0.007, 0.00);
#
#
# default values light pollution (L) in ppmV
@reflight    = (0.001,  0.2,  0,    0.0005,   0.001,   0.075,  0.005,  1E-5,   0.023,  0.01);
#
#
# default values moderate pollution (M) in ppmV
@refmoderate = (0.007,  0.3,  0.35, 0.002,    0.005,   0.2,    0.02,   5E-5,   0.053,  0.05);
#
#
# default values severe pollution (S) in ppmV
@refsevere =   (0.007, 0.3,  0.35,0.002,    0.005,   0.2,    0.02,   5E-5,  0.053,  0.05);
#
#
# aerosol types
@aerosol = ("'S&F_RURAL'","'S&F_URBAN'","'S&F_MARIT'","'S&F_TROPO'", \
            "'SRA_CONTL'","'SRA_URBAN'","'SRA_MARIT'","'B&D_C'","'B&D_C1'","'USER'");
#
#
#
#=============================================================================
# SECTION 1
#
# define the different cards as strings (with default values)
#==============================================================================
#
#
$COMNT = "";
$card1 =  " !card1,   comment line";
#-------------------------------------------------------------
# default $ISPR = 2 : latitude and altitude will be given
#
$ISPR = 2;
$card2  = " !card2,   subset of site press., latit., altit., height ";
#------
$LATIT = 50;
$ALTIT = 0.16;
$HEIGHT= 0.0;
$card2a = " !card2a,  latitude, altitude, height";
#------------------------------------------------------------
# default $IATMOS = 0 : Tair,RH,Season,AVGT will be given
#
$IATMOS = 0;
$card3  = " !card3,   reference or specific atmosphere (0 = specific)";
#------
$TAIR = 10;
$RH   = 60;
# default season is summer; beware the ' '
$SEASON = "'SUMMER'";
$TDAY = 10;
$card3a = " !card3a,  Tair RH Season avg_daily_Temp or ref.atm.";
#------------------------------------------------------------
# default $IH2O = 0 : water column will be given
#
$IH2O = 0;
$card4  = " !card4,   give water column? (0 = yes)";
#-----
$W = 1;
$card4a = " !card4a,  water column in cm <=12 ";
#------------------------------------------------------------
# default $IO3 = 0 : Total Ozone will be given
$IO3 = 0;
$card5  = " !card5,   give Total Ozone? ( 0 = yes)";
#-----
# default $IALT = 0 : No altitude correction for O3
$IALT = 0;
# default $AbO3 = 0.37 : default O3 column is 0.37 atm*cm = 370 DU
$AbO3 = 0.37;
$card5a = " !card5a,  altitude correction & O3 (0=none, 0.37atm*cm)";
#------------------------------------------------------------
# default $IGAS = 0 : pollution specifics may be given
$IGAS = 0;
$card6  = " !card6,   gas absorption and pollution specifics";
#-----
# default $ILOAD = 0 : give 10 gaz concentrations
$ILOAD = 0;
$card6a = " !card6a,  4 predefined atms or give 10 gases (0 = give 10 gases) ";
#------
$card6b = " !card6b,  Trace gases for (polluted) atm.";
# defaults for pristine atm.
# see @refpristine list
# default values light pollution
# see @reflight list
# default values moderate pollution
# see @refmoderate list
# default values severe pollution
# see @refsevere list
#-----------------------------------------------------------------------
# default $qCO2 = 370 ppmV =  CO2 at sea level
$qCO2 = 370;
$card7  = " !card7,   CO2 in ppmV ( = 370) ";
#-----
# default $ISPCTR = 0 : Gueymard 2003 extraterrestrial solar spectrum
$ISPCTR = 0;
$card7a = " !card7a,  choice of solar spectrum (0 = Gueymard2003)";
#-----------------------------------------------------------------------
# default $AEROS = Shettle & Fenn rural aerosol model
$AEROS = "'S&F_RURAL'";
$card8  = " !card8,   aerosol model (= rural) ";
$card8a = " !card8a,  aerosol parameters ";
#-----------------------------------------------------------------------
# default $ITURB = 1 : give Angstroem BETA = AOT at 1000nm
$ITURB =1;
$card9  = " !card9,   how to give aerosol specifics ( 1 = give Angstroem BETA)";
#-----
# typical BETA values for blue sky 0.08 ... 0.10 max.
# default $BETA = 0.08 = clear blue sky
$BETA = 0.08;
$card9a = " !card9a,  parameter defining aerosol";
#-----------------------------------------------------------------------
# default $IALBDX = 8 : bare soil albedo
$IALBDX = 8;
$card10 = " !card10,  type of albedo ( 8 = bare soil)";
#------
$RHOX = 0.5;
$card10a=" !card10a,  zonal broadband lambertian ground albedo ";
# default $ITILT = 0 : no tilted surfaces
$ITILT =  0;
$card10b=" !card10b, horizontal or tilted surface? (0 = horiz.)";
#------
# foreground albedo $IALBG, tilt $TILT  and surface azimuth $WAZIM
$IALBDG = 8;
$TILT = 45;
$WAZIM = 180;
$card10c= " !card10c, foreground albedo specs. ";
#-------
# local broadband foreground (L) albedo
$RHOG = 0.50;
$card10d= " !card10c, foreground zonal fixed albedo ";
#-----------------------------------------------------------------------
# default $WLMN = 280 : minimum wavelength for smarts2
$WLMN = 280;
# default $WLMX = 4000: max. wavelength for smarts2
$WLMX = 4000;
# default $SUNCOR = 1 : no correction for earth-sun distance
$SUNCOR  = 1;
# default solar constant
$SOLARC  = 1367;
$card11 = " !card11,  default spectral range and solar constant ";
#-----------------------------------------------------------------------
# default output will be broadband info only
$IPRT =  0;
$card12 = " !card12,  type of output (0 = broadband only) ";
# default lower and upper wavelength for output are the same
# as the global defaults
$WPMN = $WLMN;
$WPMX = $WLMX;
# default step for the output = 0.5nm
$INTVL = 0.5;
$card12a= " !card12a, min, max and step for output";
# default $IOTOT = 1 : one single variable will be outputted
$IOTOT = 1;
$card12b= " !card12b, total number of var. to output ( = 1)";
# default $IOUT = 4 : the output will be Global Horizontal Irradiance
$IOUT =  4;
$card12c= " !card12c, spectral variable to output (4 = global hor. irr.)";
#------------------------------------------------------------------------
# default $ICIRC = 0 : no circumsolar calculations
$ICIRC = 0;
$card13 = " !card13,  do circumsolar calculations? (0 = no) ";
#------
# default values for radiometer specs.
$SLOPE = 0;
$APERT = 0;
$LIMIT = 0;
$card13a= " !card13a, radiometer: slope, aperture,limit angles";
#------------------------------------------------------------------------
# default $ISCAN = 0 : no scanning/smoothing
$ISCAN = 0;
$card14 = " !card14,  do scanning and smoothing? (0 = no) ";
$card14a= " !card14a, radiometer specifics ";
#------------------------------------------------------------------------
# default $ILLUM = 0 : no illuminance calculations
$ILLUM = 0;
$card15 = " !card15,  do illuminance calculations? (0 = no) ";
#------------------------------------------------------------------------
# default $IUV = 1 : make UV calculations
$IUV =   1;
$card16 = " !card16,  do UV calculations? (0 = no)";
#------------------------------------------------------------------------
# default $IMASS = 0 : input SZA and Azimuth to define sun position
$IMASS = 0;
$card17 = " !card17,  how to enter sun position (0 = by SZA and Azimuth)";
# default $ZENIT = 30 : SZA = 30ø
$ZENIT = 30;
# default $SZA
# default $AZIM = 180 : sun is South
$AZIM = 180;
$card17a= " !card17a, parameters for sun position ";
#
#
#==============================================================================
# SECTION 2
#
# Interactive Input Section
#==============================================================================
#
#
print "\n\n\-----------------------------------------------------------------------\n";
print " Interactive SMARTS2 "."\n";
print "-----------------------------------------------------------------------\n\n";
$smarts2inp ="smarts2.INP";
open (OUT, "> $smarts2inp");
print "\n";
print "type the <ENTER> key to choose a default.... \n\n";
#----------------------------------------------------------------------
# card1
# COMMENT
#---------
print "Please give the comment (no blanks!)(max 20 chars.)...: ";
$COMNT = <STDIN>;
chomp($COMNT);
$tempcard = "'$COMNT'";
$tempcard = align($tempcard).$card1."\n";
#print $tempcard;
print (OUT $tempcard);
#
#----------------------------------------------------------------------
# card2 and card2a  $ISPR and $SPR,$ALTIT,$LATIT
# SURFACE PRESSURE, LATITUDE, ALTITUDE, HEIGHT
# options: 0 = give $SPR on card 2a
#          1 = give $SPR, $ALTIT and $HEIGHT on card 2a
#          2 = give $LATIT, $ALTIT and $HEIGHT on card 2a
#----------
print "\n";
print "Input the site pressure by \n";
print "   [0]... give surface pressure only \n";
print "   [1]... give surface pressure, altitude, height above groundlevel \n";
print "   [2]... give latitude, altitude, height (default)...: ";
picka($answer);
print "\n";
if ($answer eq "0")
    {
     $ISPR = $answer;
     align($ISPR);
     $tempcard = $ISPR.$card2."\n";
     print (OUT $tempcard);
     print "Give surface pressure [mb]............................. : ";
     pickn($SPR);
     align($SPR);
     $tempcard = align($SPR).$card2a."\n";
    }
elsif ($answer eq "1")
    {
     $ISPR = $answer;
     align($ISPR);
     $tempcard = $ISPR.$card2."\n";
       print (OUT $tempcard);
       print "Give surface pressure [mb].............................: ";
       pickn($SPR);
       print "Give altitude [km].....................................: ";
       pickn($ALTIT);
       print "Give height above groundlevel [km].....................: ";
       pickn($HEIGHT);
       $tempcard = align($SPR." ".$ALTIT." ".$HEIGHT).$card2a."\n";
    }
else
    {
     $tempcard = align($ISPR).$card2."\n";
     print (OUT $tempcard);
     $tempcard = align($LATIT." ".$ALTIT).$card2a."\n";
     printf "Accept default lat., alt., height [%.1f, %.1f, %.1f] ([Y]/N)..... : ", $LATIT, $ALTIT, $HEIGHT;
     picka($answer);
     if ($answer =~ /[Nn]/)
      {
       print "new latitude ..........................................: ";
       pickn($LATIT);
       print "new altitude [km]......................................: ";
       pickn($ALTIT);
       print "new height [km]  ......................................: ";
       pickn($HEIGHT);
      }
       $tempcard = align($LATIT." ".$ALTIT." ".$HEIGHT).$card2a."\n";

    }
print (OUT $tempcard);
#-------------------------------------------------------------------------
# card 3 and card3a
# AIRTEMP & MISC.
# options: 0 = define a non-reference atmosphere using card3a
#              $IO3 (card5) = 0, $IGAS (card6) = 0, $IH2O = 0 or 2
#          1 = select one of the 10 reference atmospheres given
#
#-----------
print "\n";
print "Select reference atmosphere ([Y]/N)....................: ";
picka($answer);
if ($answer =~ /[Nn]/)
  {
     $IATMOS = 0;
     $tempcard = align($IATMOS).$card3."\n";
     print (OUT $tempcard);
     $tempcard = align($TAIR." ".$RH." ".$SEASON." ".$TDAY." ").$card3a."\n";
     print "\n";
     print "Accept default AirTemp, RelativeHumidity, Season, \n";
     printf "AvgDailyGndTemp [%.1f ,%.1f ,%s ,%.1f] ..([Y]/N) : ", $TAIR,$RH,$SEASON,$TDAY;
     picka($answer);
      if ($answer =~/[Nn]/)
       {
        print "\n";
        print "new AirTemp ..........................................: ";
        pickn($TAIR);
        print "new RH ...............................................: ";
        pickn($RH);
        print "new season (W)inter or [S]ummer ......................: ";
        picka($SEASON);
        if ($SEASON =~ /[Ww]/) {
                                $SEASON = "'WINTER'";
                               }
        print "new average day temperature ..........................: ";
        pickn($TDAY);
        $tempcard = align($TAIR." ".$RH." ".$SEASON." ".$TDAY).$card3a."\n";
       }
  }
 else
  {
       $IATMOS = 1;
       $tempcard = align($IATMOS).$card3."\n";
       print (OUT $tempcard);
       print "Choose one of the following reference atmospheres :\n";
       print "   [0]... U.S. Standard Atmosphere (default) \n";
       print "   [1]... MidLatitude Summer \n";
       print "   [2]... MidLatitude Winter \n";
       print "   [3]... SubArctic Summer   \n";
       print "   [4]... SubArcticWinter    \n";
       print "   [5]... Tropical           \n";
       print "   [6]... SubTropical Summer \n";
       print "   [7]... SubTropical Winter \n";
       print "   [8]... Arctic Summer      \n";
       print "   [9]... Arctic Winter ...............................: ";
       picka($answer);
       if ($answer eq "X")
        {
         $ATMOS = $refatmos[0];
        }
       else
        {
         $ATMOS = $refatmos[$answer];
        }
        $tempcard = align($ATMOS).$card3a."\n";
  }
print (OUT $tempcard);
#exit;
#--------------------------------------------------------------------------
# card4    $IH2O
# PRECIPITABLE WATER COLUMN
# options: 0 = input $W on card4a
#          1 = take it from reference atmosphere and site altitude if $IATMOS = 1
#              (or from USSA atmosphere if $IATMOS = 0)
#          2 = calculate it from $TAIR and $RH ($IATMOS = 0)
#---------------------------
print "\n";
print "Input the Water Vapor data\n";
print "   [0]... give water vapour column \n";
if ($IATMOS == 1)
      {
       print "   [1]... compute from choosen ref.atm. (default)..... : ";
      }
if ($IATMOS == 0)
      {
       print "   [2]... compute it from air temp. & humid .(default) : ";
      }
pickn($IH2O);
if ($IH2O eq "X")
        {
         $IH2O = 2 - $IATMOS;
        }
print "\n";
$tempcard = align($IH2O).$card4."\n";
print (OUT $tempcard);
#-------
# card4a   $W
#-------
if ($IH2O == 0)
{
  $tempcard = align($W).$card4a."\n";
       printf "Accept default water column [%2d cm] .......... ([Y]/N) : ",$W;
  picka($answer);
  if ($answer =~ /[Nn]/)
   {
       print "Precipitable watercolumn in cm ........................: ";
    pickn($W);
    $tempcard = align($W).$card4a."\n";
    print "\n\n";
   }
 print (OUT $tempcard);
}
#----------------------------------------------------------------------------
# card5    $IO3
# TOTAL OZONE COLUMN
# options: 0 = give $IO3 abd $AbO3 on card5a
#          1 = use default value from reference atmosphere
#              If $IATMOS<>1, USSA atmosphere will be taken
#---------------------
print "\n";
$IO3 = 1;
if ($IATMOS == 0)
        {
         $IO3 = 0;
        }
$tempcard = align($IO3).$card5."\n";
print (OUT $tempcard);
#-------
# card5a    $AbO3,$IALT
#-------
if ($IO3 == 0)
{
       printf "Accept default TOC [%.3f atm-cm] ............ ([Y]/N) : ", $AbO3;
       picka($answer);
       if ($answer =~ /[Nn]/)
      {
       print "new total ozone column in atm-cm (=DU/1000) .......... : ";
       pickn($AbO3);
       print "Bypass TOC altitude correction ............... ([Y]/N) : ";
       picka($answer);
       if ($answer =~ /[Nn]/)
        {
         $IALT = 1;
        }
      }
       $tempcard = align($IALT." ".$AbO3).$card5a."\n";
       print (OUT $tempcard);
}
#exit;
#-----------------------------------------------------------------------------
# card6    $IGAS
# TRACE GASES
# options: 0 = read $ILOAD from card6a (mandatory if $IATMOS = 0)
#          1 = take them from reference atmosphere
#-------------
print "\n";
if ($IATMOS == 0)
        {
         $IGAS = 0;    # see page 6 of the manual
        }
else {                 # $IATMOS = 1, $IGAS may take any value
       print "Define the trace gases: \n";
       print "   [0]... take from choosen ref. atmosphere (default). : \n";
       print "   [1]... give pollution specific details ............ : ";
       pickn($IGAS);
       if ($IGAS eq "X")
        {
         $IGAS = 0;
        }
        # toggle values (see manual: from ref. atm -> $IGAS = 1, else 0)
         $IGAS = abs($IGAS-1);

     }
$tempcard = align($IGAS).$card6."\n";
print (OUT $tempcard);
#------
#card6a  $ILOAD
#------
if ($IGAS == 0 )
{
 print "\n";
 print "Predefined atmosphere loads : \n";
 print "   [0]... give all 10 pollutants \n";
 print "   [1]... pristine......... atmosphere \n";
 print "   [2]... light polluted... atmosphere \n";
 print "   [3]... moderate polluted atmosphere \n";
 print "   [4]... severe polluted.. atmosphere \n";
 print "   [5]... choose atmosphere but give own O3 and NOx \n";
 print "--------------------------------------------------------------\n";
 print "Give your atmosphere load type   (default = [2]).......: ";
 pickn($ILOAD);
 if ($ILOAD eq "X")
        {
        $ILOAD = 2;
        }
 # set $card6a to 0 if $ILOAD = 5
  if ($ILOAD == 5)
        {
         $ILOAD1 = 0;
         $tempcard = align($ILOAD1).$card6a."\n";
         }
  else
        {
         $tempcard = align($ILOAD).$card6a."\n";
         }
 print (OUT $tempcard);
}
#--------
# card 6b
#--------
# secondary options: 0 = give the concentration of 10 pollutants
#                    1 = select pristine atm.
#                    2 = select light polluted atm.
#                    3 = select moderate polluted atm.
#                    4 = select severe polluted atm.
#
#
if (($IGAS == 0) and ($ILOAD == 0))
{
                                                             # give the 10 pollutants
                                                             # defaults are from light polluted atm.
        # gas 1------------
        $ApCH2O = $reflight[0];
        print "Accept formaldehyde at ($reflight[0])........ ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give formaldehyde CH2O in ppmV ............... : ";
           pickn($ApCH2O);
         }
        # gas 2------------
        $ApCH4 = $reflight[1];
        print "Accept methane at ($reflight[1])............... ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give methane CH4 in ppmV ..................... : ";
           pickn($ApCH4);
         }
        # gas 3-----------
        $ApCO = $reflight[2];
        print "Accept CO at ($reflight[2])...................... ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give CO in ppmV .............................. : ";
           pickn($ApCO);
         }
        # gas 4-----------
        $ApHNO2 = $reflight[3];
        print "Accept HNO2 at ($reflight[3])............... ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give HNO2 in ppmV ............................ : ";
           pickn($ApHNO2);
         }
        # gas 5----------
        $ApHNO3 = $reflight[4];
        print "Accept HNO3 at ($reflight[4])................ ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give HNO3 in ppmV ............................ : ";
           pickn($ApHNO3);
         }
        # gas 6----------
        $ApNO = $reflight[5];
        print "Accept NO at ($reflight[5]).................. ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give NO in ppmV .............................. : ";
           pickn($ApNO);
         }
        # gas 7---------
        $ApNO2 = $reflight[6];
        print "Accept NO2 at ($reflight[6])................. ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give NO2 in ppmV ............................. : ";
           pickn($ApNO2);
         }
        # gas 8---------
        $ApNO3 = $reflight[7];
        print "Accept NO3 at ($reflight[7])................ ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give NO3 in ppmV ............................. : ";
           pickn($ApNO3);
         }
        # gas 9---------
        $ApO3 = $reflight[8];
        print "Accept O3 at ($reflight[8]).................. ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give O3 in ppmV .............................. : ";
           pickn($ApO3);
         }
        # gas 10-------
        $ApSO2 = $reflight[9];
        print "Accept SO2 at ($reflight[9]).................. ([Y]/N) : ";
        picka($answer);
         if ($answer =~ /[Nn]/)
         {
           print "Give SO2 in ppmV ............................. : ";
           pickn($ApSO2);
         }

            $tempcard = $ApCH2O." ".$ApCH4." ".$ApCO." ".$ApHNO2." ".$ApHNO3;
            $tempcard = $tempcard." ".$ApNO." ".$ApNO2." ".$ApNO3." ".$ApO3." ".$ApSO2;
            $tempcard = align($tempcard).$card6b."\n";
            print (OUT $tempcard);
}
elsif (($IGAS == 0) and ($ILOAD == 5 ))
{

        # give only O3, NO and NO2 and take the rest from one
        # of the 4 reference polluted atmospheres
       print "\nGround O3, NO and NO2 will be given...! \n\n";
       print "What type of default atm. [1..4] (default = 2)........ : ";
       pickn($polltype);
       if ($polltype eq "X")
        {
         $polltype = 2;
        }
       print "What units ([0]=ppmV, [1]=ug/m3 (default) )........... : ";
       pickn($units);
       if ($units eq "X")
        {
         $units = 1;
        }
       print "Give the tropospheric [O3] in ";
       punits($units);
       print "................... : ";
       pickn($ApO3);
       $ApO3 = (((0.022414/48)**$units)*$ApO3);      # convert to ppmV and round to 1 decimal
       $ApO3 = sprintf("%.1f",$ApO3);
       print "Give the [NO] ............ in ";
       punits($units);
       print "................... : ";
       pickn($ApNO);
       $ApNO = (((0.022414/30)**$units)*$ApNO);      # convert to ppmV and round to 5 decimals
       $ApNO = sprintf("%.5f",$ApNO);
       print "Give the [NO2]............ in ";
       punits($units);
       print "................... : ";
       pickn($ApNO2);
       $ApNO2 = (((0.022414/46)**$units)*$ApNO2);    # convert to ppmV and round to 5 decimals
       $ApNO2 = sprintf("%.5f",$ApNO2);

          if ($polltype == 1)
           {
            $tempcard = "$refpristine[0]"." "."$refpristine[1]"." "."$refpristine[2]"." "."$refpristine[3]"." "."$refpristine[4]";
            $tempcard = $tempcard." ".$ApNO." ".$ApNO2." "."$refpristine[7]"." ".$ApO3." "."$refpristine[9]";
           }
          if ($polltype == 2)
           {
            $tempcard = "$reflight[0]"." "."$reflight[1]"." "."$reflight[2]"." "."$reflight[3]"." "."$reflight[4]";
            $tempcard = $tempcard." ".$ApNO." ".$ApNO2." "."$reflight[7]"." ".$ApO3." "."$reflight[9]";
           }
          if ($polltype == 3)
           {
            $tempcard = "$refmoderate[0]"." "."$refmoderate[1]"." "."$refmoderate[2]"." "."$refmoderate[3]"." "."$refmoderate[4]";
            $tempcard = $tempcard." ".$ApNO." ".$ApNO2." "."$refmoderate[7]"." ".$ApO3." "."$refmoderate[9]";
           }
          if ($polltype == 4)
           {
            $tempcard = "$refsevere[0]"." "."$refsevere[1]"." "."$refsevere[2]"." "."$refsevere[3]"." "."$refsevere[4]";
            $tempcard = $tempcard." ".$ApNO." ".$ApNO2." "."$refsevere[7]"." ".$ApO3." "."$refsevere[9]";
           }

         $tempcard = align($tempcard).$card6b."\n";
         print (OUT $tempcard);
}
#exit;
#-----------------------------------------------------------------------------
# card7  $qCO2
# CO2 at ground level
# options: none
#
#---------------------
$tempcard = align("$qCO2").$card7."\n";   # transform $qCO2 into string to align properly
print "\n";
printf "Accept default CO2 concentration [%3d] ....... ([Y]/N) : ", $qCO2;
picka($answer);
if ($answer =~ /[Nn]/)
   {
       print "Give [CO2] in ppmV ....................................: ";
       pickn($qCO2);
       $tempcard = align("$qCO2").$card7."\n";
   }
print (OUT $tempcard);
#-------
# card7a   $ISPCTR
#-------
# Select extraterrestial spectrum (Gueymard2003 spectrum is default)
# secondary options: 0..7  = one of 8 solar extraterrestrial solar spectra
#-------
$tempcard = align($ISPCTR).$card7a."\n";
print "\n";
print "Select one of the following spectra: \n";
print "   [0]... Gueymard2003           1366.10 Wm-2 (default) \n";
print "   [1]... Gueymard               1367.00 Wm-2 \n";
print "   [2]... Cebula/Chance/Kurucz   1362.12 Wm-2 \n";
print "   [3]... Chance/Kurucz          1359.75 Wm-2 \n";
print "   [4]... Kurucz, new            1368.00 Wm-2 \n";
print "   [5]... Kurucz, old            1373.16 Wm-2 \n";
print "   [6]... Thuillier/Kurucz       1376.23 Wm-2 \n";
print "   [7]... Wehrli/WRC/WMO         1367.00 Wm-2 ........ : ";
picka($ISPCTR);
if ($ISPCTR eq "X") {
                     $ISPCTR = 0;
                    }
$tempcard = align($ISPCTR).$card7a."\n";
print (OUT $tempcard);
#---------------------------------------------------------------------------
# card8  $AEROS
# Select AEROSOL type
# options: one of 9 predefined types, or 'user'
#---------
print "\n";
print "Select one of the following aerosol types: \n";
print "   [0]... Shettle&Fenn rural (default) \n";
print "   [1]... Shettle&Fenn urban \n";
print "   [2]... Shettle&Fenn maritime \n";
print "   [3]... Shettle&Fenn tropospheric \n";
print "   [4]... IAMAP continental \n";
print "   [5]... IAMAP urban \n";
print "   [6]... IAMAP maritime \n";
print "   [7]... Braslau&Dave C \n";
print "   [8]... Braslau&Dave C1 \n";
print "   [9]... User defined aerosol type .................. : ";
picka($atype);
    if ($atype eq "X")
        { $atype = 0;
        }
$AEROS = $aerosol[$atype];
$tempcard = align($AEROS).$card8."\n";
print (OUT $tempcard);
#exit;
#--------
# card8a   $ALPHA1,$ALPHA2,$OMEGL,$GG
#--------
if ($atype == 9)
 {
       print "Give Angstroem alpha for <500nm....................... : ";
       pickn($ALPHA1);

       print "Give Angstroem alpha for >500nm....................... : ";
       pickn($ALPHA2);
       print "Give aerosol single scattering albedo................. : ";
       pickn($OMEGL);
       print "Give aerosol assymmetry parameter..................... : ";
       pickn($GG);
       $tempcard = align($ALPHA1." ".$ALPHA2." ".$OMEGL." ".$GG).$card8a."\n";
       print (OUT $tempcard);
 }
#exit;
#---------------------------------------------------------------------------
# card9 and card9a  $TAU5,$BETA,$BCHUEP,$RANGR,$VISI,$TAU550
# Select AOT : enter beta = AOT1000 = Microtops AOT1020 approx.
# options: 0 = give $TAU5 = AOT500
#          1 = give $BETA = AOT1000
#          2 = give $BCHUEP = Schuepps B
#          3 = give $RANGE = meteorological range Vr in [km]
#          4 = give $VISI  = visibility in [km]
#          5 = give $TAU550= AOT550
#------------------------------------------------------
print "\n";
print "Please enter the turbidity description parameter... \n";
print "   [0]... enter AOT at  500nm \n";
print "   [1]... enter AOT at 1000nm (default) \n";
print "   [2]... enter Schuepps B \n";
print "   [3]... enter meteorological range  in km \n";
print "   [4]... enter prevailing visibility in km \n";
print "   [5]... enter AOT at 550nm ......................... :";
picka($answer);
if ($answer eq "X")
        {
         $answer = "1";
        }
if ($answer eq "0")
 {
       $ITURB = 0;
       print "Give AOT500 (Tau5).................................... : ";
       pickn($TAU5);
       $tempcard1= align($TAU5).$card9a."\n";
 }
if ($answer eq "1")
 {
       $ITURB = 1;
       printf "Accept default AOT1000 [%.3f] . ..............([Y]/N) : ", $BETA;
       picka($answer1);
       if ($answer1 =~ /[Nn]/)
      {
       print "Give AOT1000 (beta) .................................. : ";
       pickn($BETA);
      }
       $tempcard1= align($BETA).$card9a."\n";
 }
if ($answer eq "2")
 {
       $ITURB = 2;
       print "Give Schuepp's B ..................................... : ";
       pickn($BCHUEP);
       $tempcard1 = align($BCHUEP).$card9a."\n";
 }
if ($answer eq "3")
 {
       $ITURB = 3;
       print "Give meterological range in km ....................... : ";
       pickn($RANGE);
       $tempcard1 = align($RANGE).$card9a."\n";
 }
if ($answer eq "4")
 {
       $ITURB = 4;
       print "Give prevailing visibility in km ..................... : ";
       pickn($VISI);
       $tempcard1 = align($VISI).$card9a."\n";
 }
if ($answer eq "5")
 {
       $ITURB = 0;
       print "Give AOT550 (Tau550).................................. : ";
       pickn($TAU550);
       $tempcard1= align($TAU550).$card9a."\n";
 }
$tempcard = align($ITURB).$card9."\n";
print (OUT $tempcard);
#
# if answer was not in 0...5 range and not <ENTER> pick the default $BETA
#if (!$answer =~ /[012345]/)
# {
#  $tempcard1 = align($BETA).$card9a."\n";
# }
print (OUT $tempcard1);
#exit;
#-----------------------------------------------------------------------------
# card10   $IALBDX,$RHOX
# CHOOSE ALBEDO (default is bare soil = no.8)
# options: -1    = one single broadband albedo number
#          0..38 = one predefined albedo file
#          0 and 1 are user defined files
#----------------------------------------------
print "\n";
printf "Accept default ALBEDO [%.0f] .................... ([Y]/N) : ", $IALBDX;
picka($answer);
if ($answer =~ /[Nn]/)
   {
       print "\n";
       print " The choices for the albedo are: \n";
       print "- one of 38 predefined ( 2 = calculated) spectral reflectance files (2..38), \n";
       print "- one of 2 user defined files (0 = Lambertian, 1 = non Lambertion)  \n";
       print "- one fixed broad-band albedo to input \n";
       print "Use fixed broad-band albedo................... ([Y]/N) : ";
       picka($answer1);
       if ($answer1 =~ /[YyX]/)
        {
         print "Give fixed broad-band albedo...........................: ";
         $IALBDX = -1;
         pickn($RHOX);
         $tempcard1 = align($RHOX).$card10a."\n";
        }
        else
        {
         print "Give number of ALBEDO file [0...38] ...................: ";
         pickn($IALBDX);
        }
   }
$tempcard = align($IALBDX).$card10."\n";
print (OUT $tempcard);
if ($IALBDX == -1)
        {
         print (OUT $tempcard1);
        }
#---------
# card10b  $ITILT,$WAZIM,$IALBDG,$RHOG
# CHOOSE TILTED or HORIZONTAL
# options: 0 = no tilt: surface is horizontal (default)
#          1 = make calculations for tilted surface
#-----------------------------------------------------
print "\n";
print "Make calculations for horizontal surface only  ([Y]/N) : ";
picka($answer);
if ($answer =~ /[YyX]/)
   {
     $tempcard = align($ITILT).$card10b."\n";
     print (OUT $tempcard);
   }
else
   {
       print "\n";
       $ITILT = 1;
       $tempcard = align($ITILT).$card10b."\n";
       print (OUT $tempcard);
       print "Give tilt angle ........................................: ";
       pickn($TILT);
       print "Give surface azimuth....................................: ";
       pickn($WAZIM);
       print "Use fixed broad-band foreground albedo........  ([Y]/N) : ";
       picka($answer1);
       if ($answer1 =~ /[YyX]/)
      {
       $IALDBG = -1;
       $tempcard = align($IALDBG." ".$TILT." ".$WAZIM).$card10c."\n";
       print (OUT $tempcard);
       print "Give fixed broad-band foreground albedo.................: ";
         pickn($RHOG);
         $tempcard1 = align($RHOG).$card10d."\n";
         print (OUT $tempcard1);
      }
        else
      {
       print "Give number of ALBEDO file [0...38] ....................: ";
         picka($IALBDG);
         $tempcard = align($IALBDG." ".$TILT." ".$WAZIM).$card10c."\n";
         print (OUT $tempcard);
      }
   }
#exit;
#------------------------------------------------------------------------------
# card11  $WLMN,$WLMX,$SOLARC,$SUNCOR
# CHOOSE SPECTRAL RANGE (default is 280nm ...4000 nm]
# options: none
#
#-----------------------------------------------------
print "\n";
printf "Accept default spectral range [%.0f, %.0f] .... ([Y]/N) : ",$WLMN,$WLMX;
picka($answer);
if ($answer =~ /[Nn]/)
 {
       print "minimum wavelength ....................................: ";
       pickn($WLMN);
       print "maximum wavelenght ....................................: ";
       pickn($WLMX);
 }
printf "Accept default solar constant [%.2f ]...... ([Y]/N) : ", $SOLARC;
picka($answer1);
if ($answer1 =~ /[Nn]/)
 {
       print "Give solar constant ...................................: ";
       pickn($SOLARC);
 }
printf "Accept default sun correction factor [%.2f] .. ([Y]/N) : ", $SUNCOR;
picka($answer2);
if ($answer2 =~ /[Nn]/)
 {
       print "Give sun correction factor ............................: ";
       pickn($SUNCOR);
 }
$tempcard = align($WLMN." ".$WLMX." ".$SUNCOR." ".$SOLARC).$card11."\n";
print (OUT $tempcard);
#------------------------------------------------------------------------------
# card12
# CHOOSE TYPE OF PRINTOUT (default is broadband only smarts2.OUT)   $IPRT
# If $IPRT = 0, there are no cards 12a, 12b, 12c !!!
# options: 0 = only broadband infofile smarts2.OUT is given
#          1 = broadband info followed  by spectrum both in file smarts2.OUT
#          2 = same as above with spectrum also in file smarts2.EXT
#          3 = broadband info in file smarts2.OUT, spectrum in file smarts2.EXT
#
#-----------------------------------------------------------------
print "\n";
print "You have the following choices for the output: \n";
print "   [0]... broadband info smarts2.OUT only (default) \n";
print "   [1]... broadband info and spectrum both in file smarts2.OUT \n";
print "   [2]... same as above plus spectrum also in file smarts2.EXT \n";
print "   [3]... broadband info in file smarts2.out, \n";
print "          spectrum in file smarts2.EXT.................: ";
  picka($answer);
  if ($answer eq "X")
  {
   $IPRT = 0;
  }
  else
  {
   $IPRT = $answer;
  }
$tempcard = align($IPRT).$card12."\n";
print (OUT $tempcard);
#exit;
#----------
# card12a    $WPMN,$WPMX,$INTVL
# Spectral range for output files
# lower and higher limts same as above, only step given
#--------------------------------
if ($IPRT >= 1)
 {
  $WPMN = $WLMN;
  print "Accept default min. wavelength for output..... ([Y]/N) : ";
  picka($answer);
  if ($answer =~ /[Nn]/)
       {
        print "Give min. wavelength in nm ...: ";
        pickn($WPMN);
       }
  $WPMX = $WLMX;
  print "Accept default max. wavelength for output..... ([Y]/N) : ";
  picka($answer);
  if ($answer =~ /[Nn]/)
       {
        print "Give max. wavelength in nm ...: ";
        pickn($WPMX);
       }

  $INTVL = 0.5;
  print "Accept default wavelength step [0.5nm]........ ([Y]/N) : ";
  picka($answer);
  if ($answer =~ /[Nn]/)
       {
        print "Give step in nm ...: ";
        pickn($INTVL);
       }
  $tempcard = align($WLMN." ".$WLMX." ".$INTVL).$card12a."\n";
  print (OUT $tempcard);
 }
#-----------
# card 12b   $IPRT
# Total number of variables to output (default is 1)
# options: 1..32 variables to output
#--------------------------
if (($IPRT >= 2) and ($IPRT <= 3))
 {
    print "Accept default number of variables for OUTPUT [$IOTOT].. ([Y]/N) : ";
  picka($answer);
  if ($answer =~ /[Nn]/)
   {
    print "How many variables to output [1..24] ............................: ";
    pickn($IOTOT);
   }
  $tempcard = align($IOTOT).$card12b."\n";
  print (OUT $tempcard);
  }
#----------
# card12c  $IOUT
# OUTPUT variable codes (default 4 = global horiz. irradiance)
# options: list of 1 to 32 variables
#----------------------
if (($IPRT >= 2) and ($IPRT <= 3))
 {
    print "Accept default OUTPUT [global horiz. irradiance] ....... ([Y]/N) : ";
   picka($answer);
   if ($answer =~ /[Nn]/)
    {
     $tempcard ="";
     for ($i=1; $i <=$IOTOT; $i++)
        {
        print "give variable $i ...: ";
        picka($answer);
        $tempcard = $tempcard.$answer." ";
        }
      $tempcard = align($tempcard).$card12c."\n";
      print (OUT $tempcard);
     }
     else
     {
      $tempcard = align($IOUT).$card12c."\n";
     }
     print (OUT $tempcard);
 }
#
#----------------------------------------------------------------
# card13   $ICIRC
# Circumsolar calculations
# options: 0 = none
#          1 = simulate a radiometer
#--------------------------
print "\n";
print "Bypass circumsolar calculations .............. ([Y]/N) : ";
picka($answer);
if ($answer =~ /[Nn]/)
 {
   $ICIRC = 1;
   $tempcard = align($ICIRC).$card13."\n";
   print "Attention: slope < aperture < limit ! \n";
   print "Give slope angle (0 if unknown)....................... : ";
   pickn($SLOPE);
   print "Give aperture    (0 if unknown)....................... : ";
   pickn($APERT);
   print "Give limit angle (0 if unknown)....................... : ";
   pickn($LIMIT);
   $tempcard1 = align($SLOPE." ".$APERT." ".$LIMIT).$card13a."\n";
   print (OUT $tempcard1);

 }
 else
 {
  $tempcard = align($ICIRC).$card13."\n";
  print (OUT $tempcard);
 }
#----------------------------------------------------------------
# card14 and card14a  $ISCAN and $WV1,$WV2,$STEP,$FWHM
# options: 0 = No scanning/smoothing file
#          1 = output scanning routine to smarts2.SCN
#-------------------------
#print "\n";
print "Bypass scanning/smoothing calculations........ ([Y]/N) : ";
picka($answer);
if ($answer =~ /[Nn]/)
 {
    $ISCAN = 1;
    $tempcard = align($ISCAN).$card14."\n";
    print (OUT $tempcard);
    print "\n";
    print "Transmittance shape is 0 for triangular, 1 for Gaussian shape \n";
    print "Give transmittance shape...............................: ";
    pickn($IFILT);
    print "Give min. wavelength for output file...................: ";
    pickn($WV1);
    print "Give max. wavelength for output file...................: ";
    pickn($WV2);
    print "Give step of output....................................: ";
    pickn($STEP);
    $MAXFWHM = sprintf("%.0f", 0.5*($WV2-$WV1));
    print "Give FWHM (full width at half max.: < $MAXFWHM ! ).  .....: ";
    pickn($FWHM);
    $tempcard = align("$IFILT"." ".$WV1." ".$WV2." ".$STEP." ".$FWHM).$card14a."\n";
    print (OUT $tempcard);
  }

 else
 {
  $tempcard = align($ISCAN).$card14."\n";
  print (OUT $tempcard);
 }
#----------------------------------------------------------------
# card15   $ILLUM
# options: 0 = No illuminance and luminous eff. calculation
#         -2 = use revised CIE photopic curve for illuminance calculations
#         -1 = use CIE photopic curve for illuminance calculations
#          1 = same as -1 but add luminance eff. calculations
#          2 = same as -2 but add luminance eff. calculations
#----------------------------------------------
#print "\n";
print "Bypass illuminance calculations .............. ([Y]/N) : ";
picka($answer);
if ($answer =~ /[Nn]/)
 {
       print "\n";
       print "Use CIE [1] or revised CIE (2) photopic curve .........: ";
       pickn($ILLUM);
       if ($ILLUM eq "X")
        {
         $ILLUM = 1;
        }
       print "Omit luminance efficiency calculations.......  ([Y]/N) : ";
       picka($answer);
       if ($answer =~ /[Nn]/)
        {
         $ILLUM = -$ILLUM;
        }
  }
  $tempcard = align($ILLUM).$card15."\n";
  print (OUT $tempcard);
#-----------------------------------------------------------------
# card16   $IUV
# options: 0 = Do no broadband (e.g. UVI and MED) calculations
#          1 = Do them
#-----------------------------------------------
print "\n";
print "Do you want to make UVI and MED calculations.  ([Y]/N) : ";
picka($answer);
if ($answer =~ /[Nn]/)
 {
  $IUV = 0;
  }
$tempcard = align($IUV).$card16."\n";
print (OUT $tempcard);
#exit;
#-----------------------------------------------------------------
# card17    $IMASS
# options:  CHOOSE of time input : solar position or date  (azimuth only when tilted surface)
#------------------------------------------------
print "\n";
print "How do you want to input the time for the calculation  :  \n";
print "   [0]... SZA only (default) \n";
print "   [1]... ELEVATION and AZIMUTH \n";
print "   [2]... AIRMASS [1... 38.2] \n";
print "   [3]... year month day hour lat. long. zone (GMT=1) \n";
print "   [4]... month, lat., time-step for daily calculation :";
pickn($IMASS);
if ($IMASS eq "X")
        {
         $IMASS = "0";
         }
$tempcard = align($IMASS).$card17."\n";
print (OUT $tempcard);
#--------
# card17a   $ZENITH,$AZIM,$AMASS,$YEAR,$MONTH,$DAY,$LATIT,$LONGIT,$ZONE,$DSTEP
# Attention: an unlimited number of card17a's may be stacked!
#--------
print "\n";
print "How many TIME-INFO cards will you use (default = 1)... : ";
pickn($STACK17A);
if ($STACK17A eq "X")
        {
        $STACK17A = 1;
        }
#
# main card17a entry loop
#
for ($j = 1; $j <= $STACK17A; $j++)
{
$tempcard = "";
print "\n";
print "-----------------------------------------\n";
print "Time-information for run no. $j \n";
print "-----------------------------------------\n";
print "\n";
$tempcard = align($ZENIT." ".$AZIM).$card17a."\n";
if ($IMASS == 0 )
 {
       $defZENIT = sprintf("%.0f",$ZENIT);
       print "Give SZA  [$defZENIT]............: ";
       pickn($ZENIT);
       if ($ZENIT eq "X")
          {
           $ZENIT = $defZENIT;
          }
       $AZIM = 180;                # arbitrary azim if $ITILT = 0
       if ($ITILT == 1)
        {
       $defAZIM = sprintf("%.0f",$AZIM);
       print "Give AZIMUTH [$defAZIM]........: ";
       pickn($AZIM);
       if ($AZIM eq "X")
          {
           $AZIM = $defAZIM;
          }
        }
       $tempcard = align($ZENIT." ".$AZIM).$card17a."\n";
 }
elsif ($IMASS == 1)
 {
       print "Give ELEVATION ......: ";
       pickn($ELEV);
       $AZIM = 180;                # arbitrary azim if $ITILT = 0
       if ($ITILT == 1)
        {
       $defAZIM = sprintf("%.0f",$AZIM);
       print "Give AZIMUTH [$defAZIM]........: ";
       pickn($AZIM);
         if ($AZIM eq "X")
          {
           $AZIM = $defAZIM;
          }
        }
       $tempcard = align($ELEV." ".$AZIM).$card17a."\n";
 }
elsif ($IMASS == 2)
 {
        print "Give Airmass .......: ";
        pickn($AMASS);
        $tempcard = align($AMASS).$card17a."\n";
 }
elsif ($IMASS == 3)
 {
        print "Give year (yyyy) ..... : ";
        pickn($YEAR);
        print "Give month (1..12) ... : ";
        pickn($MONTH);
        print "Give day (1..31)...... : ";
        pickn($DAY);
        print "Give hour (LST, no DST): ";
        pickn($HOUR);
        print "Give latitude (North+) : ";
        pickn($LATIT);
        print "Give longitude (East+) : ";
        pickn($LONGIT);
        print "Give GMT zone (East+)  : ";
        pickn($ZONE);
        $tempcard = align($YEAR." ".$MONTH." ".$DAY." ".$HOUR." ".$LATIT." ".$LONGIT." ".$ZONE).$card17a."\n";
 }
elsif ($IMASS == 4)
 {
        print "Give month (1..12) ....: ";
        pickn($MONTH);
        print "Give latitude (North+) : ";
        pickn($LATIT);
        print "The option DSTEP gives only broadband results for a sequence of calculations \n";
        print "made for a single day. DSTEP (in minutes) must be a divisor of 60 ! \n";
        print "Give DSTEP increment   : ";
        pickn($DSTEP);
        if (60%$DSTEP != 0 )   # $DSTEP not a divider of 60, take 30 by default
                {
                 $DSTEP = 30;
                 }
        $tempcard = align($MONTH." ".$LATIT." ".$DSTEP).$card17a."\n";
 }
print (OUT $tempcard);
}       # end of for loop
#
#-----------------------------------------------------------------
# interactive entry job done!
#
close (OUT);
#
#
#=================================================================
# SECTION 3
#
# Program execution
#=================================================================
#
#
print "\n\n\a";
print "**********************************\n";
print "*   smarts2.INP is created !     *\n";
print "**********************************\n";
#
# now execute smarts2 program
system("$SMARTS2");
#system("$SMARTS2batch");
# and display the smarts2.INP and smarts2.OUT file
print "\n\n";
print "Do you want to inspect the smarts2.INP file .. ([Y]/N) : ";
picka($answer);
if ($answer =~ /[YyX]/)
 {
  system("$EDIT $DIR\\smarts2.INP");
 }
print "\n\n";
print "Do you want to inspect the smarts2.OUT file .. ([Y]/N) : ";
picka($answer);
if ($answer =~ /[YyX]/)
 {
  system("$EDIT $DIR\\smarts2.OUT");
 }
print "\n\n";
print "   ... end of interactive input ! \n\n ";
exit;
#============================= eof ==========================================================================
