#!/bin/bash
#=====================================================================
#
# NAME 
#   xwplots
#
# PURPOSE
#   Run *ENLIL* with *WSA* data and specified *CONE* parameters, make all plots
#
# BACKGROUND
#   ENLIL heliospheric computations are driven by boundary values
#   calculated WSA and CME data for background solar wind and
#   CME-like transients, respectively.
#
#   Numerical computations are performed in the computational
#   region (parameter "reg") with numerical resolution (parameter
#   "res") for 1 or more computational blocks (parameter "nblk")
#   using processors in parallel (parameter "procs"). There are
#   two basic numerical models specified by prameter "numo"
#   - numo=mcp1um1: robust model but with numerical diffusion;
#   - numo=mcp1va2: less-robust model but with reduced diffusion.
#
#   Various "WSA" output are processed by wsa<xx>2bc codes specified
#   by parameter "wsacode" as follows:
#   - wsacode=wsafr2bc: WSA full-rotation single map;
#   - wsacode=wsadu2bc: WSA daily-updated single map;
#   - wsacode=wsadt2bc: WSA daily-updated sequence of maps.
#   Location of these maps is specified by parameters:
#   - cordir, cordata, corfile, crnum, crlon.
#   and boundary values are calculated with model free-parameters
#   listed below and labeled by "amb".
#
#   Transient disturbances are calculated from geometric and kinematic
#   parameters of CMEs fitted by Cone-model analytic formula (using
#   single-perspective observations) or determined by various iterative
#   tools (when multi-perspective observations are available). These
#   parameters are either explicitly listed (if ncmes>0) or given in
#   cmefile (if ncmes=-1); no distrubances are specified if ncmes=0.
#   Transient disturbances are calculated with model free-parameters
#   listed below and labeled by "cld".
#
# USAGE
#   xwplots [-<parameter> <value>]
#   xwplots make [-<parameter> <value>]
#   xwplots case [-<parameter> <value>]
#   xwplots plot_case [-<parameter> <value>]
#   xwplots run [-<parameter> <value>]
#   xwplots data_run [-<parameter> <value>]
#   xwplots plot_run [-<parameter> <value>]
#   xwplots clean [-<parameter> <value>]
#
# DESCRIPTION
#   make      - Set array dimensions and compile the codes
#   case      - Set input parameters and execute the case code
#   plot_case - Plot results of the case computation
#   run       - Set input parameters and execute the run code
#   data_run  - Data results of the run computation
#   plot_run  - Plot results of the run computation
#   clean     - Clean the project directory
#
# PARAMETERS - PROJECT
#   -project <char>   - Project name:
#                       wplots
#
# PARAMETERS - NUMERICAL MODEL
#   -numo <char>      - Numerical model setting:
#                       mcp1um1d | mcp1va2d
#
# PARAMETERS - COMPUTATIONAL REGION AND GRID
#   -nreg <int>       - Computational grid mode:
#                       1 | 2 | 3
#   -reg <int>        - Computational region (AU):
#                       1 | 2 | 3 | 6 | 12
#   -res <char>       - Numerical grid resolution:
#                       low | med | high
#
# PARAMETERS - COMPUTATIONAL PERIOD AND OUTPUT
#   -obsdate <char>   - Use observations at or up to this date:
#                       null | <yyyy-mm-ddThh>
#   -rundate <char>   - Start computation at this date:
#                       2012-03-05T00 | <yyyy-mm-ddThh>
#   -tstop <float>    - Stop computation at this time (h):
#                       168.
#   -tstep <float>    - Output with this step in time (h):
#                       24.
#
# PARAMETERS - BACKGROUND SOLAR WIND
#   -cordata <char>   - Coronal data sub-directory:
#                       wsa22 | wsa45 | wsa52 | wsada | wsafr
#   -corfile <char>   - Coronal data file (null if cordata/corymdh used):
#                       null | <name>
#   -cormode <char>   - Coronal data mode:
#                       single | multi
#   -corobs <char>    - Solar photospheric field observatory:
#                       gongb | gongz | mdi | mwo | nso
#   -correa <char>    - Realization of the WSADA coronal map:
#                       R000 | ...
#   -corymdh <char>   - Coronal data sub-sub-directory structure by date:
#                       yyyy/mm | yyyy/mm/dd | null
#   -crnum <char>     - Carrington Rotation number:
#                       null | <xxxx>
#   -crlon <char>     - Carrington Rotation leading longitude:
#                       null | <xxx>
#   -amb <char>       - Ambient wind conditions setting:
#                       a8b1 | a3b2 | a6b1
#   -bndrot <char>    - Rotation of the inner boundary:
#                       synodic | sidereal | null
#   -gamma <float>    - Ratio of specific heats:
#                       1.6666667
#   -xalpha <float>   - Fraction of alpha particles (rel. to protons)
#                       0.
#
# PARAMETERS - CME
#   -maxcmes <int>    - Maximum number of simulated CMEs (depends on system memory):
#                       30
#   -ncmes <int>      - Number of simulated CMEs:
#                       1 | n>1 | 0
#   -cld <char>       - Hydrodynamic cloud conditions setting:
#                       d4x1
#   -timramp <float>  - Transition from background to transient (h):
#                       0.25
#   -dates <char>     - Cloud leading edge at boundary at this date:
#                       0000-00-00T00:00 | <yyyy-mm-ddThh:mm>
#   -lat <float>      - Cone central axis latitude (deg):
#                       0.
#   -lon <float>      - Cone central axis longitude (deg):
#                       0.
#   -rmajor <float>   - Cone major radius (deg):
#                       40.
#   -rminor <float>   - Cone (ellipsoid) minot radius (deg):
#                       0.
#   -tilt <float>     - Cone (ellipsoid) tilt from equator (deg)
#                       0.
#   -dcld <float>     - Cloud density / fast stream density:
#                       4.
#   -dcld0 <float>    - Cloud background density (cm-3):
#                       0.
#   -tcld <float>     - Cloud temperature / fast stream temperature:
#                       1.
#   -tcld0 <float>    - Cloud background temperature (MK):
#                       0.
#   -vcld <float>     - Cloud velocity (km/s):
#                       900.
#   -xcld <float>     - Cloud trailing elongation over spherical shape:
#                       1.
#   -ncld <int>       - Cloud shape (1=piston, 2=sphesymbnd, 3=sphesymcen, 4=sphekincen):
#                       2 | 3 | 4 | 1
#   -dcav <float>     - Cavity density / fast stream density:
#                       1.
#   -tcav <float>     - Cavity temperature / fast stream temperature:
#                       4.
#   -xcav <float>     - Cavity radius / cloud radius:
#                       0.
#   -dtail <float>    - Tail density / fast stream density:
#                       0.
#   -ttail <float>    - Tail temperature / fast stream temperature:
#                       0.
#   -vtail <float>    - Tail velocity (km/s):
#                       0.
#   -xtail <float>    - Tail elongation over spherical shape:
#                       0.
#   -ntail <int>      - Tail temporal decline (0=none, 1=back, 2=half, 3=full):
#                       0 | 1 | 2 | 3
#
# PARAMETERS - RUN
#   -qheat <float>    - Volumetric heating factor
#                       0.3
#
# PARAMETERS - PLOT PROCEDURES
#   -pbnd <int>       - Plot_bnd if non-zero:
#                       0
#   -pbnd1 <int>      - Plot_bnd1 if non-zero:
#                       0
#   -pbnd2 <int>      - Plot_bnd2 if non-zero:
#                       0
#   -pbnd6 <int>      - Plot_bnd6 if non-zero:
#                       0
#   -pbndtim1 <int>   - Plot_bndtim1 if non-zero:
#                       0
#   -pevo10o1 <int>   - Plot_evo10o1 if non-zero:
#                       0
#   -pevo1o5 <int>    - Plot_evo1o5 if non-zero:
#                       0
#   -pevo5o1 <int>    - Plot_evo5o1 if non-zero:
#                       0
#   -plos1 <int>      - Plot_los1 with this step in output files:
#                       0
#   -plos1d <int>     - Plot_los1d with this step in output files:
#                       0
#   -plos2 <int>      - Plot_los2 with this step in output files:
#                       0
#   -plos2d <int>     - Plot_los2d with this step in output files:
#                       0
#   -plos3 <int>      - Plot_los3 with this step in output files:
#                       0
#   -plosmap1j <int>  - Plot_losmap1j with this step in output files:
#                       0
#   -plosmap1p <int>  - Plot_losmap1p with this step in output files:
#                       0
#   -prad1 <int>      - Plot_rad1 if non-zero:
#                       1
#   -pradevo1 <int>   - Plot_radevo1 with this step in output files:
#                       0
#   -pradsho1 <int>   - Plot_radsho1 with this step in output files:
#                       0
#   -ptim1 <int>      - Plot_tim1 with this step in output files:
#                       0
#   -ptim1e1 <int>    - Plot_tim1e1 with this step in output files:
#                       0
#   -ptim1e5 <int>    - Plot_tim1e5 with this step in output files:
#                       0
#   -ptim1o5 <int>    - Plot_tim1o5 with this step in output files:
#                       0
#   -ptim2 <int>      - Plot_tim2 with this step in output files:
#                       0
#   -ptim2e5 <int>    - Plot_tim2e5 with this step in output files:
#                       0
#   -ptim2z <int>     - Plot_tim2z with this step in output files:
#                       0
#   -ptim3 <int>      - Plot_tim3 with this step in output files:
#                       0
#   -ptim3e1 <int>    - Plot_tim3e1 with this step in output files:
#                       0
#
# PARAMETERS - PLOT OPTIONS
#   -fontsize <float> - Font size (1=small, 2=medium, 3=large):
#                       1.0
#   -info <int>       - Informative footnote (1=yes, 0=no, -1=ghost):
#                       1
#   -labitem <char>   - Label plot by item (optional, at top-left):
#                       DEMO
#
#   Note: The first value in the list is the default value.
#
# INSTALLATION
#   You have to edit in the ENLIL distribution:
#   - environment variables in env.inc script.
#   You have to edit in this script:
#   - project name and directory (where results will go);
#   - data directory (repository of coronal maps).
#
# NOTE
#   Default parameters correspond to a low-resolution computation
#   using the reference numerical model and ambient wind settings
#   for the 2015 August period with CMEs in a heliospheric region
#   between 0.1 and 2.1 AU for -336+168 h (-14+7 days).
#
# NOTE
#   It is assumed you are in the <mydir> directory path:
#   .../<HELIO>/src/<ENLIL>/scripts/<mydir>
#   <HELIO_DIR> contains: data, env, fcst, opt, proj, src
#   <ENLIL_DIR> contains: codes, data, scripts, vis
#
#---------------------------------------------------------------------
# SYSTEM DEPENDENT PARAMETERS
#---------------------------------------------------------------------
# Base directories

# Get the full directory name where this script is located
# (it can be called from other locations)
dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

ENLIL_DIR=${dir%/*/*}     # ENLIL source directory
HELIO_DIR=${dir%/*/*/*/*} # HELIO-WEATHER system directory

echo ENLIL_DIR=$ENLIL_DIR
echo HELIO_DIR=$HELIO_DIR

sname=$(realpath "$0")       # Script full-path name
sdir=$(dirname $sname)       # Directory where the script is located

ENLIL_DIR=${sdir%/*/*}     # ENLIL source directory
HELIO_DIR=${sdir%/*/*/*/*} # HELIO-WEATHER system directory

echo ENLIL_DIR=$ENLIL_DIR
echo HELIO_DIR=$HELIO_DIR

#---------------------------------------------------------------------
# Project and data directories

echo source $HELIO_DIR/env/dirs.inc
     source $HELIO_DIR/env/dirs.inc

#---------------------------------------------------------------------
# Operating system

system=linux        # Operating system (linux | aix)
batch=no            # Submit run to batch queue (no | yes)
binsrc=src          # Numerical code (bin | src)
vis=gdl             # Visualization software (idl | gdl)

#---------------------------------------------------------------------
# PROJECT DEFAULT PARAMETERS
#---------------------------------------------------------------------
# Default project parameters

project=wplots      # Project name

#---------------------------------------------------------------------
# Data sub-directory

heldata=helioweb    # Heliospheric data sub-directory

#---------------------------------------------------------------------
# Default code parameters

procs=16            # No. of processors (1 | 2 | 4 | 8 | 16 | 32 | 64)
check=nocheck       # Compile with diagnostic checks (nocheck | check)
outlog=outlog       # Output log file (outlog | noutlog)

#---------------------------------------------------------------------
# Default numerical model parameters

numo=mcp1va2d       # Numerical model setting (mcp1um1d | mcp1va2d)

#---------------------------------------------------------------------
# Default computational region and grid parameters

nreg=1              # Computational grid mode (1 | 2 | 3)
reg=2               # Computational region (AU)
res=low             # Numerical grid resolution
res23=1             # Numerical grid resolution - finer in x2+x3
nblk=2              # Number of computational blocks
npos=5              # Number of positions for evolutions (1 | 3 | 5)

#---------------------------------------------------------------------
# Default computational period and output parameters (relative to "rundate")

obsdate=null        # Use observations up to this date (null | yyyy-mm-ddThh)
rundate=2010-04-03  # Start computation at this date (yyyy-mm-ddThh)
tstop=120.          # Stop computation at this time (h)
tstep=1.            # Output with this step in time (h)

#---------------------------------------------------------------------
# Default ambient solar wind parameters

# Input data
cordata=wsa22       # Coronal data sub-directory (wsa22 | wsa45 | wsa52 | wsada | wsafr)
corfile=null        # Coronal data file (null if cordata/corymdh used)
cormode=multi       # Coronal data mode (single | multi)
corobs=gongz        # Observatory name (gongb | gongz | mdi | mwo | nso)
correa=null         # Realization of the WSA-ADAPT coronal map (R000 | ...)
corymdh=yyyy/mm     # Coronal data sub-sub-directory structure by date (yyyy/mm | yyyy/mm/dd | null)
crnum=null          # Carrington Rotation number (null | xxxx)
crlon=null          # Carrington Rotation leading longitude (null | xxx)

# Model parameters
amb=a6b1            # Ambient solar wind conditions setting (a8b1 | a3b2 | a6b1 | ace3a)
bndrot=synodic      # Rotation of the inner boundary (null | sidereal | synodic)
gamma=1.6666667     # Ratio of specific heats
xalpha=0.           # Fraction of alpha particles (rel. to protons)

#---------------------------------------------------------------------
# Default hydrodynamic cloud parameters

# Input data
maxcmes=30          # Maximum number of simulated CMEs (depends on system memory)
ncmes=1             # Number of simulated CMEs (-1 | 0 | >0)

# Model parameters
cld=null            # Hydrodynamic cloud label
timramp=0.25        # Transition from background to transient (h)
dates=2010-04-03T12:28 # Cloud leading edge at boundary at this date
                       # <yyyy-mm-ddThh:mm>
lat=20.             # Cone central axis latitude (deg)
lon=0.              # Cone central axis longitude (deg)
rmajor=30.          # Cone major radius (deg)
rminor=0.           # Cone (ellipsoid) minot radius (deg):
tilt=0.             # Cone (ellipsoid) tilt from equator (deg)
dcld=12             # Cloud density / fast stream density
dcld0=0.            # Cloud background density (cm-3)
tcld=1.             # Cloud temperature / fast stream temperature
tcld0=0.            # Cloud background temperature (MK)
vcld=1889.           # Cloud velocity (km/s)
xcld=1.             # Cloud trailing elongation over spherical shape
ncld=2              # Cloud shape (1=piston, 2=sphesymbnd, 3=sphesymcen, 4=sphekincen)
dcav=1.             # Cavity density / fast stream density
tcav=4.             # Cavity temperature / fast stream temperature
xcav=0.             # Cavity radius / cloud radius
dtail=0.            # Tail density / fast stream density
ttail=0.            # Tail temperature / fast stream temperature
vtail=0.            # Tail velocity (km/s)
xtail=0.            # Tail elongation over spherical shape
ntail=0             # Tail temporal decline (0=none, 1=back, 2=half, 3=full)

#---------------------------------------------------------------------
# Default run parameters

cdifb=0.2           # Div(B) diffusion coefficient
qheat=0.3           # Volumetric heating factor

#---------------------------------------------------------------------
# Default plot procedures

pbnd=0              # Plot_bnd if non-zero
pbnd1=0             # Plot_bnd1 if non-zero
pbnd2=0             # Plot_bnd2 if non-zero
pbnd6=0             # Plot_bnd6 if non-zero
pbndtim1=0          # Plot_bndtim1 if non-zero
pevo10o1=0          # Plot_evo1o5 if non-zero
pevo1o5=0           # Plot_evo1o5 if non-zero
pevo5o1=0           # Plot_evo5o1 if non-zero
plos1=0             # Plot_los1 with this step in output files
plos1d=0            # Plot_los1d with this step in output files
plos2=0             # Plot_los2 with this step in output files
plos2d=0            # Plot_los2d with this step in output files
plos3=0             # Plot_los3 with this step in output files
plosmap1j=0         # Plot_losmap1j with this step in output files
plosmap1p=0         # Plot_losmap1p with this step in output files
prad1=0             # Plot_rad1 if non-zero
pradevo1=0          # Plot_radevo1 with this step in output files
pradsho1=0          # Plot_radsho1 with this step in output files
psho1=0             # Plot_sho1 with this step in output files
psho1e5=0           # Plot_sho1e5 with this step in output files
psho1o5=0           # Plot_sho1o5 with this step in output files
psho2e1=0           # Plot_sho2e1 with this step in output files
psho2z=0            # Plot_sho2z with this step in output files
pshoevo1o5=0        # Plot_shoevo1e5 with this step in output files
pshoevo5o1=0        # Plot_shoevo5o1 with this step in output files
ptim1=0             # Plot_tim1 with this step in output files
ptim1e1=0           # Plot_tim1e1 with this step in output files
ptim1e5=0           # Plot_tim1e5 with this step in output files
ptim1o5=0           # Plot_tim1o5 with this step in output files
ptim2=0             # Plot_tim2 with this step in output files
ptim2e1=0           # Plot_tim2e1 with this step in output files
ptim2e5=0           # Plot_tim2e5 with this step in output files
ptim2z=0            # Plot_tim2z with this step in output files
ptim3=0             # Plot_tim3 with this step in output files
ptim3e1=0           # Plot_tim3e1 with this step in output files

#---------------------------------------------------------------------
# Default plot options

fontsize=1.0        # Font size (1=small, 2=medium, 3=large)
info=1              # Informative footnote (1=yes, 0=no, -1=ghost)
lospalat='pa'
losxy=0
rmax=1.7            # Plotting region (AU)
size=1              # Size (0=720, 1=960, 2=1440, 3=1920, 4=3840)
wide=0              # Width aspect ratio (0=1:1, 1=1.5:1, 2=2:1 ,3=3:1)
xtslide=0           # Sliding plot window (h)
zoom=0              # Zoom (0=none | 1=66% | 2=50% (or 33%)

#---------------------------------------------------------------------
# YOU SHOULD NOT EDIT BELOW
#---------------------------------------------------------------------
# Modify default parameters by input arguments

make=no
case=no
plot_case=no
run=no
data_run=no
plot_run=no
clean=no
all=no

while [ $# -ge 1 ]; do
  case $1 in
    make)           make=yes         ;;
    case)           case=yes         ;;
    plot_case)      plot_case=yes    ;;
    run)            run=yes          ;;
    data_run)       data_run=yes     ;;
    plot_run)       plot_run=yes     ;;
    clean)          clean=yes        ;;
    all)            all=yes          ;;
    check)          check=check      ;;
    outlog)         outlog=outlog    ;;
    -binsrc)        binsrc=$2        ; shift ;;
    -procs)         procs=$2         ; shift ;;
    -cordir)        cordir=$2        ; shift ;;
    -heldir)        heldir=$2        ; shift ;;
    -obsdir)        obsdir=$2        ; shift ;;
    -projdir)       projdir=$2       ; shift ;;
    -project)       project=$2       ; shift ;;
    -numo)          numo=$2          ; shift ;;
    -nreg)          nreg=$2          ; shift ;;
    -reg)           reg=$2           ; shift ;;
    -res)           res=$2           ; shift ;;
    -res23)         res23=$2         ; shift ;;
    -nblk)          nblk=$2          ; shift ;;
    -npos)          npos=$2          ; shift ;;
    -obsdate)       obsdate=$2       ; shift ;;
    -rundate)       rundate=$2       ; shift ;;
    -tstop)         tstop=$2         ; shift ;;
    -tstep)         tstep=$2         ; shift ;;
    -cordata)       cordata=$2       ; shift ;;
    -corfile)       corfile=$2       ; shift ;;
    -cormode)       cormode=$2       ; shift ;;
    -corobs)        corobs=$2        ; shift ;;
    -correa)        correa=$2        ; shift ;;
    -corymdh)       corymdh=$2       ; shift ;;
    -crnum)         crnum=$2         ; shift ;;
    -crlon)         crlon=$2         ; shift ;;
    -amb)           amb=$2           ; shift ;;
    -bndrot)        bndrot=$2        ; shift ;;
    -gamma)         gamma=$2         ; shift ;;
    -xalpha)        xalpha=$2        ; shift ;;
    -maxcmes)       maxcmes=$2       ; shift ;;
    -ncmes)         ncmes=$2         ; shift ;;
    -cld)           cld=$2           ; shift ;;
    -timramp)       timramp=$2       ; shift ;;
    -dates)         dates=$2         ; shift ;;
    -lat)           lat=$2           ; shift ;;
    -lon)           lon=$2           ; shift ;;
    -rmajor)        rmajor=$2        ; shift ;;
    -rminor)        rminor=$2        ; shift ;;
    -tilt)          tilt=$2          ; shift ;;
    -dcld)          dcld=$2          ; shift ;;
    -dcld0)         dcld0=$2         ; shift ;;
    -tcld)          tcld=$2          ; shift ;;
    -tcld0)         tcld0=$2         ; shift ;;
    -vcld)          vcld=$2          ; shift ;;
    -xcld)          xcld=$2          ; shift ;;
    -ncld)          ncld=$2          ; shift ;;
    -dcav)          dcav=$2          ; shift ;;
    -tcav)          tcav=$2          ; shift ;;
    -xcav)          xcav=$2          ; shift ;;
    -dtail)         dtail=$2         ; shift ;;
    -ttail)         ttail=$2         ; shift ;;
    -vtail)         vtail=$2         ; shift ;;
    -xtail)         xtail=$2         ; shift ;;
    -ntail)         ntail=$2         ; shift ;;
    -cdifb)         cdifb=$2         ; shift ;;
    -qheat)         qheat=$2         ; shift ;;
    -pbnd)          pbnd=$2          ; shift ;;
    -pbnd1)         pbnd1=$2         ; shift ;;
    -pbnd2)         pbnd2=$2         ; shift ;;
    -pbnd6)         pbnd6=$2         ; shift ;;
    -pbndtim1)      pbndtim1=$2      ; shift ;;
    -pevo10o1)      pevo10o1=$2      ; shift ;;
    -pevo1o5)       pevo1o5=$2       ; shift ;;
    -pevo5o1)       pevo5o1=$2       ; shift ;;
    -plos1)         plos1=$2         ; shift ;;
    -plos1d)        plos1d=$2        ; shift ;;
    -plos2)         plos2=$2         ; shift ;;
    -plos2d)        plos2d=$2        ; shift ;;
    -plos3)         plos3=$2         ; shift ;;
    -plosmap1j)     plosmap1j=$2     ; shift ;;
    -plosmap1p)     plosmap1p=$2     ; shift ;;
    -prad1)         prad1=$2         ; shift ;;
    -pradevo1)      pradevo1=$2      ; shift ;;
    -pradsho1)      pradsho1=$2      ; shift ;;
    -psho1)         psho1=$2         ; shift ;;
    -psho1e5)       psho1e5=$2       ; shift ;;
    -psho1o5)       psho1o5=$2       ; shift ;;
    -psho2e1)       psho2e1=$2       ; shift ;;
    -psho2z)        psho2z=$2        ; shift ;;
    -pshoevo1o5)    pshoevo1o5=$2    ; shift ;;
    -pshoevo5o1)    pshoevo5o1=$2    ; shift ;;
    -ptim1)         ptim1=$2         ; shift ;;
    -ptim1e1)       ptim1e1=$2       ; shift ;;
    -ptim1e5)       ptim1e5=$2       ; shift ;;
    -ptim1o5)       ptim1o5=$2       ; shift ;;
    -ptim2)         ptim2=$2         ; shift ;;
    -ptim2e1)       ptim2e1=$2       ; shift ;;
    -ptim2e5)       ptim2e5=$2       ; shift ;;
    -ptim2z)        ptim2z=$2        ; shift ;;
    -ptim3)         ptim3=$2         ; shift ;;
    -ptim3e1)       ptim3e1=$2       ; shift ;;
    -fontsize)      fontsize=$2      ; shift ;;
    -info)          info=$2          ; shift ;;
    -lospalat)      lospalat=$2      ; shift ;;
    -losxy)         losxy=$2         ; shift ;;
    -rmax)          rmax=$2          ; shift ;;
    -size)          size=$2          ; shift ;;
    -wide)          wide=$2          ; shift ;;
    -xtslide)       xtslide=$2       ; shift ;;
    -zoom)          zoom=$2          ; shift ;;
  esac
  shift
done

if [ $make == no ] && [ $case == no ] && [ $plot_case == no ] && \
   [ $run == no ] && [ $data_run == no ] && [ $plot_run == no ] && \
   [ $clean == no ] ; then
  make=yes
  case=yes
  plot_case=yes
  run=yes
  data_run=yes
  plot_run=yes
fi

#---------------------------------------------------------------------
# Environment variables

echo source $HELIO_DIR/env/env.inc
     source $HELIO_DIR/env/env.inc

#---------------------------------------------------------------------
# Case codes

casecode=cone2bc
grdcode=reg2grd
ambcode=wsa2bc

evocode=out2evo
fldshocode=out2fldsho
loscode=out2los

#---------------------------------------------------------------------
# Numerical model

# Default values (numo=mcp1um1d)
scheme=tvdlf2       # Numerical scheme (tvdlf1 | tvdlf2)
flxdif=noflxdif     # Increased flux diffusion (noflxdif | flxdif)
vsdif=novsdif       # Increased signal speed (novsdif | vsdif)
bchalf=nobchalf     # Time-dependent boundary conditions at the half-step
bctim=bctim1c       # Boundary condition (bctim1c | bctim1h | bctim1v)
difb=difb           # Div(B) diffusion treament (difb | dedner | nodifb)
divb=nodivb         # Div(B) treament (jandif | povell | powell | nodivb)
energy=ethe         # Energy equation (ethe | etot | etot2)
flux=llf            # Numerical flux (llf | hll)
limiter=minmod      # Slope limiter (minmod | albada)
heat=vheat          # Global heating (vheat | hheat | noheat)
mftrace=mfrk4       # IMF line tracing (mfeuler | mfrk4)
upwind=upwind       # Numerical upwinding

# Modification by input argument "numo"
if [ $numo == mcp1va2d ] ; then
  upwind=upwindp      # Numerical upwinding
  limiter=albada      # Slope limiter (minmod | albada)
  flux=hll            # Numerical flux (llf | hll)
fi
if [ $numo == mcp2um1d ] ; then
  energy=etot         # Energy equation (ethe | etot | etot2)
fi
if [ $numo == mcp2va2d ] ; then
  energy=etot         # Energy equation (ethe | etot | etot2)
  upwind=upwindp      # Numerical upwinding
  limiter=albada      # Slope limiter (minmod | albada)
  flux=hll            # Numerical flux (llf | hll)
fi
if [ $numo == mcp3um1d ] ; then
  energy=etot2        # Energy equation (ethe | etot | etot2)
fi
if [ $numo == mcp3va2d ] ; then
  energy=etot2        # Energy equation (ethe | etot | etot2)
  upwind=upwindp      # Numerical upwinding
  limiter=albada      # Slope limiter (minmod | albada)
  flux=hll            # Numerical flux (llf | hll)
fi

# Label the numerical model by "bchalf"
if [ $bchalf == bchalf ] ; then
  numo=$numo'h'
fi

#---------------------------------------------------------------------
# Computational region and grid parameters

# Default values (reg=1, res=low)
x1l=0.1             # Inner boundary (AU)
x1r=1.1             # Outer boundary (AU)
x2l=30.             # Minimum co-latitude (deg)
x2r=150.            # Maximum co-latitude (deg)
n1=128              # No. of basic X1-grid points
n2=30               # No. of basic X2-grid points
n3=90               # No. of basic X3-grid points

# Modification by input argument "nreg"
if [ $nreg == 2 ] ; then
  n1=144              # No. of basic X1-grid points
fi
if [ $nreg == 3 ] ; then
  n1=96               # No. of basic X1-grid points
fi

# Modification by input arguments "reg" and "nreg"
if [ $nreg != 2 ] ; then
  if [ $reg -gt 1 ] ; then
    x1r=$reg'.1'        # Outer boundary (AU)
    let n1=n1*reg       # No. of basic X1-grid points
  fi
else
  x1r=1.225           # Outer boundary (AU)
  if [ $reg == 2 ] ; then
    x1r=2.35
  fi
  if [ $reg == 3 ] ; then
    x1r=3.475
  fi
  if [ $reg == 4 ] ; then
    x1r=4.6
  fi
  if [ $reg == 5 ] ; then
    x1r=5.725
  fi
  if [ $reg == 6 ] ; then
    x1r=6.85
  fi
  if [ $reg == 7 ] ; then
    x1r=7.975
  fi
  if [ $reg == 8 ] ; then
    x1r=9.1
  fi
  if [ $reg == 9 ] ; then
    x1r=10.225
  fi
  if [ $reg == 10 ] ; then
    x1r=11.35
  fi
  let n1=n1*reg       # No. of basic X1-grid points
fi

# Modification by input argument "res"
nx=1                # Grid resolution factor
if [ $res == med ] ; then
  nx=2                # Grid resolution factor
fi
if [ $res == high ] ; then
  nx=4                # Grid resolution factor
fi
if [ $res == fine ] ; then
  nx=8                # Grid resolution factor
fi
if [ $nx != 1 ] ; then
  let n1=n1*nx
  let n2=n2*nx
  let n3=n3*nx
fi

# Modification by input argument "res23"
if [ $res23 != 1 ] ; then
  let n2=n2*res23     # Refinement of the X2-grid
  let n3=n3*res23     # Refinement of the X3-grid
fi

# Label the grid by "nreg", "reg", "res", "nblk", and "npos"
grd=reg
if [ $nreg == 1 ] ; then
  grd=ra
fi
if [ $nreg == 2 ] ; then
  grd=rb
fi
if [ $nreg == 3 ] ; then
  grd=rc
fi
grd=$grd$reg$res$nblk
if [ $res23 != 1 ] ; then
  grd=$grd'r'$res23
fi
if [ $npos != 1 ] ; then
  grd=$grd'p'$npos
fi

#---------------------------------------------------------------------
# Computational period and output parameters (relative to "rundate")

# Default values (reg=1)
vutime=3600.        # Time unit scale factor (s)
tstart=-168.        # Start computation at this time (h)
tfrom=0.            # Output from this time (h)

# Derived parameters
tto=$tstop          # Output to this time (h)
tfstep=$tstep       # FLD output with this step in time (h)
t1step=$tstep       # X1 output with this step in time (h)
t2step=0.           # SLC2 output with this step in time (h)
ttstep=$tstep       # TIM output with this step in time (h)

# Modification by input argument "reg"
itstart=${tstart%.*}    # Integer part of "tstart"
let itstart=itstart*reg # Adjust *itstart* for computational domain
tstart=$itstart'.'      # Start computation at this time (h)

tfirst=$tstart      # First input data (h)
tlast=$tstop        # Last input data (h)

#---------------------------------------------------------------------
# Coronal data sub-directory for a WSA maps specified by Carrington
# rotation with a syntax (original WSA approach):
# - <cordir>/<cordata>/vel_<crnum>_<crlon>.00_01_<corobs>.fits
# read by "wsa2bc" code.
# NOTE: WSA full-rotation maps have <crlon>=000.
#
# WSA maps specified by calendar date have syntax by <cordata>:
# (1) <cordata>=wsadu (renamed WSA_v2.* files)renamed by DO and used at CCMC:
# - <cordir>/wsadu/<corobs>/<yyyy>/<mm>/wsadu_<corobs>_<yyyymmddThhmm>.fits
# (2) <cordata>=wsadv (WSA_v2.* files by SWPC):
# - <cordir>/wsadw/<corobs>/<yyyy>/<mm>/<dd>/wsa_vel_21.5rs_<yyyymmddhhmm>_gong.fits
# (3) <cordata>=wsadw (WSA_v4.* files):
# - <cordir>/wsada/<corobs>/<yyyy>/<mm>/vel_<yyyymmddhhmmss>R000_<corobs>.fits
# (4) <cordata>=wsada (WSA-ADAPT files):
# - <cordir>/wsada/<corobs>/<yyyy>/<mm>/vel_<yyyymmddhhmmss><correa>_<corobs>.fits
# - where <correa>=R000-R011 is for the map realization.
# read by "wsa2bc" code.
#

cordata0=${cordata%/*}  # Get the first directory in cordata
if [ $crnum != null ] ; then
  if [ $corobs == gong ] ; then
    cordata='WSA_VEL/GONG/CARR/2.5deg/L72R21.5'
  fi
  if [ $corobs == gongb ] ; then
    cordata='WSA_VEL/GONG/CARR/2.5deg/L72R21.5'
  fi
  if [ $corobs == mdi ] ; then
    cordata='WSA_VEL/MDI/CARR/2.5deg/L72R21.5'
  fi
  if [ $corobs == mwo ] ; then
    cordata='WSA_VEL/MWO/CARR/2.5deg/L72R21.5'
  fi
  if [ $corobs == nso ] ; then
    cordata='WSA_VEL/NSO/CARR/2.5deg/L72R21.5'
  fi
  if [ $cordata0 == wsafr ] ; then
    corfile='vel_'$crnum'_000.00_01_'$corobs'.fits'
  fi
fi

#---------------------------------------------------------------------
# Ambient solar wind parameters

# Default values (amb=a8b1)
bfast=500.          # Radial magnetic field of fast stream (nT)
bslow=0.            # Radial magnetic field of slow stream (nT)
bamb=350.           # Radial magnetic field of mean stream (nT)
if [ ${corobs:0:4} == gong ] ; then
  bscl=5.             # Magnetic field scaling factor
else
  bscl=2.             # Magnetic field scaling factor
fi
dfast=300.          # Number density of fast stream (cm-3)
dslow=5000.         # Number density of slow stream (cm-3)
damb=500.           # Number density of mean stream (cm-3)
dscl=1.             # Number density scaling factor
tfast=1.2           # Mean temperature of fast stream (MK)
tslow=0.1           # Mean temperature of slow stream (MK)
tamb=0.3            # Mean temperature of mean stream (MK)
tscl=1.             # Mean temperature scaling factor
vfast=700.          # Radial flow velocity of fast stream (km/s)
vslow=200.          # Radial flow velocity of slow stream (km/s)
vamb=450.           # Radial flow velocity of mean stream (km/s)
vrfast=20.          # Reduction of the maximum flow velocity (km/s)
vrslow=50.          # Reduction of the minimum flow velocity (km/s)
shift=8.            # Azimuthal shift at the inner boundary (deg)
nshift=1            # Azimuthal shift at the inner boundary (0,1,2,3)
xalpha=0.05         # Fraction of alpha particles (rel. to protons)
dvexp=2.            # Exponent in N*V^dvexp=const condition
nptot=0             # = 0 (1) if P_the (P_tot) balance at boundary
nbrad=1             # Magnetic field correction
nbndace=0           # Adjust WSA values by measured values at ACE (0-3)

# Modification by input argument "amb"
if [ $amb == a3b2 ] ; then
  bfast=300.          # Radial magnetic field of fast stream (nT)
  bslow=0.            # Radial magnetic field of slow stream (nT)
  bamb=0.             # Radial magnetic field of mean stream (nT)
  if [ ${corobs:0:4} == gong ] ; then
    bscl=4.             # Magnetic field scaling factor
  else
    bscl=2.             # Magnetic field scaling factor
  fi
  dfast=200.          # Number density of fast stream (cm-3)
  dslow=2000.         # Number density of slow stream (cm-3)
  damb=0.             # Number density of mean stream (cm-3)
  dscl=1.             # Number density scaling factor
  tfast=0.8           # Mean temperature of fast stream (MK)
  tslow=0.1           # Mean temperature of slow stream (MK)
  tamb=0.             # Mean temperature of mean stream (MK)
  tscl=1.             # Mean temperature scaling factor
  vfast=675.          # Radial flow velocity of fast stream (km/s)
  vslow=225.          # Radial flow velocity of slow stream (km/s)
  vamb=0.             # Radial flow velocity of mean stream (km/s)
  vrfast=25.          # Reduction of the maximum flow velocity (km/s)
  vrslow=25.          # Reduction of the minimum flow velocity (km/s)
  shift=8.            # Azimuthal shift at the inner boundary (deg)
  nshift=1            # Azimuthal shift at the inner boundary (0,1,2,3)
  xalpha=0.05         # Fraction of alpha particles (rel. to protons)
  dvexp=2.            # Exponent in N*V^dvexp=const condition
  nptot=1             # = 0 (1) if P_the (P_tot) balance at boundary
  nbrad=3             # Magnetic field correction
  nbndace=0           # Adjust WSA values by measured values at ACE (0-3)
fi
if [ $amb == a6b1 ] ; then
  bfast=350.          # Radial magnetic field of fast stream (nT)
  bslow=300.          # Radial magnetic field of slow stream (nT)
  bamb=0.             # Radial magnetic field of mean stream (nT)
  if [ ${corobs:0:4} == gong ] ; then
    bscl=4.             # Magnetic field scaling factor
  else
    bscl=2.             # Magnetic field scaling factor
  fi
  dfast=125.          # Number density of fast stream (cm-3)
  dslow=2000.         # Number density of slow stream (cm-3)
  damb=0.             # Number density of mean stream (cm-3)
  dscl=1.             # Number density scaling factor
  tfast=1.5           # Mean temperature of fast stream (MK)
  tslow=0.1           # Mean temperature of slow stream (MK)
  tamb=0.             # Mean temperature of mean stream (MK)
  tscl=1.             # Mean temperature scaling factor
  vfast=700.          # Radial flow velocity of fast stream (km/s)
  vslow=200.          # Radial flow velocity of slow stream (km/s)
  vamb=0.             # Radial flow velocity of mean stream (km/s)
  vrfast=25.          # Reduction of the maximum flow velocity (km/s)
  vrslow=75.          # Reduction of the minimum flow velocity (km/s)
  shift=8.            # Azimuthal shift at the inner boundary (deg)
  nshift=1            # Azimuthal shift at the inner boundary (0,1,2,3)
  xalpha=0.05         # Fraction of alpha particles (rel. to protons)
  dvexp=2.            # Exponent in N*V^dvexp=const condition
  nptot=0             # = 0 (1) if P_the (P_tot) balance at boundary
  nbrad=1             # Magnetic field correction
  nbndace=0           # Adjust WSA values by measured values at ACE (0-3)
fi
if [ $amb == a7b1 ] ; then
  bfast=500.          # Radial magnetic field of fast stream (nT)
  bslow=0.            # Radial magnetic field of slow stream (nT)
  bamb=400.           # Radial magnetic field of mean stream (nT)
  if [ ${corobs:0:4} == gong ] ; then
    bscl=5.             # Magnetic field scaling factor
  else
    bscl=2.             # Magnetic field scaling factor
  fi
  dfast=300.          # Number density of fast stream (cm-3)
  dslow=5000.         # Number density of slow stream (cm-3)
  damb=500.           # Number density of mean stream (cm-3)
  dscl=1.             # Number density scaling factor
  tfast=1.2           # Mean temperature of fast stream (MK)
  tslow=0.1           # Mean temperature of slow stream (MK)
  tamb=0.3            # Mean temperature of mean stream (MK)
  tscl=1.             # Mean temperature scaling factor
  vfast=700.          # Radial flow velocity of fast stream (km/s)
  vslow=200.          # Radial flow velocity of slow stream (km/s)
  vamb=450.           # Radial flow velocity of mean stream (km/s)
  vrfast=20.          # Reduction of the maximum flow velocity (km/s)
  vrslow=50.          # Reduction of the minimum flow velocity (km/s)
  shift=8.            # Azimuthal shift at the inner boundary (deg)
  nshift=1            # Azimuthal shift at the inner boundary (0,1,2,3)
  xalpha=0.05         # Fraction of alpha particles (rel. to protons)
  dvexp=2.            # Exponent in N*V^dvexp=const condition
  nptot=0             # = 0 (1) if P_the (P_tot) balance at boundary
  nbrad=1             # Magnetic field correction
  nbndace=0           # Adjust WSA values by measured values at ACE (0-3)
fi
if [ $amb == ace3a ] ; then
  bfast=500.          # Radial magnetic field of fast stream (nT)
  bslow=0.            # Radial magnetic field of slow stream (nT)
  bamb=0.             # Radial magnetic field of mean stream (nT)
  bscl=0.6            # Magnetic field scaling factor
  dfast=100.          # Number density of fast stream (cm-3)
  dslow=2000.         # Number density of slow stream (cm-3)
  damb=500.           # Number density of mean stream (cm-3)
  dscl=1.             # Number density scaling factor
  tfast=2.            # Mean temperature of fast stream (MK)
  tslow=0.1           # Mean temperature of slow stream (MK)
  tamb=0.6            # Mean temperature of mean stream (MK)
  tscl=1.             # Mean temperature scaling factor
  vfast=700.          # Radial flow velocity of fast stream (km/s)
  vslow=200.          # Radial flow velocity of slow stream (km/s)
  vamb=0.             # Radial flow velocity of mean stream (km/s)
  vrfast=0.           # Reduction of the maximum flow velocity (km/s)
  vrslow=50.          # Reduction of the minimum flow velocity (km/s)
  nbndace=3           # Adjust WSA values by measured values at ACE (0-3)
fi

# Label the ambient solar wind parameters by "gamma"
if [ $gamma == 1.6666667 ] ; then
  amb=$amb'-g53'
else
  zgamma=${gamma//.}
  amb=$amb'-g'${zgamma:0:2}
fi

# Label the ambient solar wind parameters by "xalpha"
if [ $xalpha == 0. ] ; then
  amb=$amb'x00'
else
  zxalpha=${xalpha//.}
  amb=$amb'x'${zxalpha:1:2}
fi

# Label the ambient solar wind parameters by "bndrot"
if [ $bndrot == sidereal ] ; then
  amb=$amb'r'
fi

# Label the coronal data by "cordata"
if [ $cordata0 == wsafr ] ; then
  cor='fr'
else
  if [ $cormode == single ] ; then
    cor='d'
  else
    cor='t'
  fi
  lcorvers=${cordata0: -2}   # Get the last two characters from cordata
  cor=$cor$lcorvers
fi

# Label the coronal data by "corobs"
lcorobs=${corobs: -1}    # Get the last character from corobs
cor=$cor$lcorobs

# Label the coronal data by "correa"
if [ $correa != null ] ; then
  cor=$cor$correa
fi

# Label the boundary conditions
bnd=$cor'-'$amb

#---------------------------------------------------------------------
# Transient disturbances

# Default values (cld=d4x1=sa1a)
maxcld=20           # Maximum no. of CMEs
maxslc=15           # Maximum no. of CMEs

# Applicable for the non-relaxation runs

if [ $cld != null ] ; then
# Modification by input argument "cld"
  if [ $cld == d2x1 ] ; then
    dcld=2.             # Cloud density / fast stream density
  fi 
  if [ $cld == d2x2 ] ; then
    dcld=2.             # Cloud density / fast stream density
    xcld=2.             # Cloud trailing elongation over spherical shape
  fi 
else
  # Label the disturbance by cone parameters
  if [ ${ncld:0:1} == '-' ] ; then
    np='n'${ncld:1:1}
  else
    np='p'$ncld
  fi
  cld='d'${dcld//.}'t'${tcld//.}'v'${vcld//.}'r'${rmajor//.}$np
  if [ ${xcld//.} != 1 ] ; then
    cld=$cld'x'${xcld//.}
  fi
  if [ ${xtail//.} != 0 ] ; then
    cld=$cld'y'${xtail//.}
  fi
  if [ $ntail != 0 ] ; then
    cld=$cld'n'$ntail
  fi

  # Label the disturbance by "timramp"
  if [ $timramp == 0.125 ] ; then
    cld=$cld'o'
  fi
  if [ $timramp == 0.25 ] ; then
    cld=$cld'q'
  fi
  if [ $timramp == 0.5 ] ; then
    cld=$cld'h'
  fi
fi

# Update the boundary-conditions label
bnd=$bnd'-'$cld

#---------------------------------------------------------------------
# Run parameters

# Default values (runpar=g53h10)
ceclip=0.01         # Clip the thermal energy below fraction of the total energy
cflxdif=0.          # Increase flux diffusion (0:1)
cvetot=0.           # Compressive velocity threshold for Etot2 (if Ethe+Etot)
cvsdif=0.           # Increase signal speed (0:1)
nheat=3             # Volumetric heating type
npla=1              # Evolution at planets (0 | 1)
nspa=1              # Evolution at spacecraft (0 | 1)
nfld=3              # Tracing of field lines (0,1,2,3 for none, helio, bnd, helio+bnd)

# Label the run parameters by "nheat" and "qheat"
if [ $nheat == 0 ] ; then
  runpar='q0'
fi
if [ $nheat == 1 ] ; then
  runpar='q'${qheat//.}
fi
if [ $nheat == 2 ] ; then
  runpar='h'${qheat//.}
fi
if [ $nheat == 3 ] ; then
  runpar='t'${qheat//.}
fi

# Label the run parameters by "cvetot"
if [ $energy == etot2 ] ; then
  cvetot=-1.          # Compressive velocity threshold for Etot2 (if Ethe+Etot)
  zzz=${cvetot//.}
  if [ $zzz -lt 0 ] ; then
    zzz='w'${zzz//-}
  else
    zzz='v'$zzz
  fi
  runpar=$runpar$zzz
fi

# Label the run parameters - numerical coefficients
if [ $cdifb != 0. ] ; then
  runpar=$runpar'd'${cdifb//.}
fi
if [ $cvetot == -1.0 ] ; then
  runpar=$runpar'w00'
fi

#---------------------------------------------------------------------
# Compose the plot labels

# Plot label - case-observatory
if [ $corobs == gongb ] ; then
 obs=GONGb
else
  if [ $corobs == gongj ] ; then
    obs=GONGj
  else
    if [ $corobs == gongz ] ; then
      obs=GONGz
    else
      obs=${corobs^^}
    fi
  fi
fi
if [ $correa != null ] ; then
  obs=$obs$correa
fi

# Plot label - case-data
if [ ${cordata0:0:3} == wsa ] ; then
  wsa='WSA'$lcorvers
  if [ $cormode == single ] ; then
    wsa=$wsa'd'
  else
    wsa=$wsa't'
  fi
else
  wsa=${cordata0^^}
fi

# Plot label - case & run
if [ $ncmes == 0 ] ; then
  labcase=$obs'-'$wsa' / '$amb' / '$res
  labrun=$obs'-'$wsa' / '$amb' / '$numo' / '$runpar' / '$res
else
  labcase=$obs'-'$wsa' + Cone / '$amb' / '$cld' / '$res
  labrun=$obs'-'$wsa' + Cone / '$amb' / '$cld' / '$numo' / '$runpar' / '$res
fi

# Plot label - computed at center
labcen='null'
labuser='null'

# Figure name prefix and suffix
namfiga=$bnd
namfigz_case=$res
namfigz_run=$numo'_'$res

#---------------------------------------------------------------------
# Export global parameters

export system batch binsrc vis
export ENLIL_DIR HELIO_DIR
export cordir heldir obsdir
export projdir project numo procs
export casecode grdcode ambcode evocode fldshocode loscode
export grd reg res n1 n2 n3 nblk npos maxcld maxslc
export obsdate rundate bnd runpar

#---------------------------------------------------------------------
# Compile the codes

if [ $make == yes ] && [ $clean == no ] ; then

  bash $ENLIL_DIR/codes/enlil/scripts/make.sh\
    -check $check -outlog $outlog\
    -energy $energy -heat $heat -bchalf $bchalf -bctim $bctim\
    -scheme $scheme -upwind $upwind -limiter $limiter -flux $flux\
    -flxdif $flxdif -vsdif $vsdif -difb $difb -divb $divb\
    -mftrace $mftrace

fi

#---------------------------------------------------------------------
# Generate boundary conditions

if [ $case == yes ] && [ $clean == no ] ; then

  bash $ENLIL_DIR/codes/enlil/scripts/case.sh\
    -x1l $x1l -x1r $x1r -x2l $x2l -x2r $x2r\
    -vutime $vutime -tfirst $tfirst -tlast $tlast\
    -cordata $cordata -cormode $cormode -corobs $corobs -correa $correa\
    -corymdh $corymdh -corfile $corfile -crnum $crnum -crlon $crlon\
    -bndrot $bndrot -shift $shift -nshift $nshift\
    -bfast $bfast -bslow $bslow -bamb $bamb -bscl $bscl\
    -dfast $dfast -dslow $dslow -damb $damb -dscl $dscl\
    -tfast $tfast -tslow $tslow -tamb $tamb -tscl $tscl\
    -vfast $vfast -vslow $vslow -vamb $vamb -vrfast $vrfast -vrslow $vrslow\
    -xalpha $xalpha -dvexp $dvexp -nptot $nptot -nbrad $nbrad\
    -nbndace $nbndace\
    -ncmes $ncmes -timramp $timramp -dates $dates\
    -lat $lat -lon $lon -rmajor $rmajor -rminor $rminor -tilt $tilt\
    -dcld $dcld -dcld0 $dcld0 -tcld $tcld -tcld0 $tcld0 -vcld $vcld\
    -xcld $xcld -ncld $ncld\
    -dcav $dcav -tcav $tcav -xcav $xcav\
    -dtail $dtail -ttail $ttail -vtail $vtail -xtail $xtail -ntail $ntail

fi

#---------------------------------------------------------------------
# Plot boundary conditions

if [ $plot_case == yes ] && [ $clean == no ] ; then

  if [ $pbnd != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bcnt 800 -dcnt 4000 -tcnt 2 -vcnt [200,1600]\
      -bevo 800 -devo 2000 -tevo 2 -vevo [200,800]\
      -heldata $heldata -planets -1 -spacecraft 2\
      -fontsize $fontsize -size $size +png\
      +plot_bnd
  fi

  if [ $pbnd1 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND1" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namobs "earth"\
      -namcnt ["brad","bthe","bphi","btot","den","tem","vrad","vcdif"]\
      -bcnt 800 -dcnt 4000 -tcnt 2 -vcnt [200,1600] -vcdifcnt 100\
      -lonplot "obs" +ecliptic\
      -heldata $heldata -planets -1 -spacecraft 2\
      +hcld +hcs\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_bnd1
  fi

  if [ $pbnd2 != 0 ] ; then
# Portrait mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND2" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namobs "earth"\
      -bradcnt 800 -bphicnt 80 -dcnt 4000 -vcnt [200,1600]\
      -lonplot "obs" +ecliptic\
      -heldata $heldata -planets -1 -spacecraft 2\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 0 -zoom $zoom +png\
      +plot_bnd2
# Landscape mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND2" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namobs "earth"\
      -bradcnt 800 -bphicnt 80 -dcnt 4000 -vcnt [200,1600]\
      -lonplot "obs" +ecliptic\
      -heldata $heldata -planets -1 -spacecraft 2\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 1 -zoom $zoom +png\
      +plot_bnd2
  fi

  if [ $pbnd6 != 0 ] ; then
# Portrait mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND6" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namobs "earth"\
      -bradcnt 800 -bthecnt 80 -bphicnt 80 -dcnt 4000 -tcnt 2 -vcnt [200,1600]\
      -lonplot "obs" +ecliptic\
      -heldata $heldata -planets -1 -spacecraft 2\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 0 -zoom $zoom +png\
      +plot_bnd6
# Landscape mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BND6" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namobs "earth"\
      -bradcnt 800 -bthecnt 80 -bphicnt 80 -dcnt 4000 -tcnt 2 -vcnt [200,1600]\
      -lonplot "obs" +ecliptic\
      -heldata $heldata -planets -1 -spacecraft 2\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 1 -zoom $zoom +png\
      +plot_bnd6
  fi

  if [ $pbndtim1 != 0 ] ; then
# All quantities, wide=1, zoom=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BNDTIM1" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namcnt ["vrad"]\
      -bcnt 800 -dcnt 4000 -tcnt 2 -vcnt [200,1600] -vcdifcnt 100\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 0 -zoom 1 +png\
      +plot_bndtim1
   #  -namcnt ["brad","bphi","btot","den","tem","vrad","vcdif"]\

# All quantities, wide=2, zoom=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "BNDTIM1" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namcnt ["brad","bphi","btot","den","tem","vrad","vcdif"]\
      -bcnt 800 -dcnt 4000 -tcnt 2 -vcnt [200,1600] -vcdifcnt 100\
      +hcld +hcs\
      -fontsize $fontsize -size $size -wide 0 -zoom 1 +png\
      +plot_bndtim1
  fi

fi

#---------------------------------------------------------------------
# Run heliospheric computation

if [ $run == yes ] && [ $clean == no ] ; then

  bash $ENLIL_DIR/codes/enlil/scripts/run.sh\
    -vutime $vutime -tstart $tstart -tstop $tstop\
    -tffrom $tfrom -tfto $tto -tfstep $tfstep\
    -t1from $tfrom -t1to $tto -t1step $t1step\
    -t2from $tfrom -t2to $tto -t2step $t2step\
    -ttfrom $tfrom -ttto $tto -ttstep $ttstep\
    -bndrot $bndrot\
    -cdifb $cdifb -cvetot $cvetot -cflxdif $cflxdif -cvsdif $cvsdif\
    -gamma $gamma -xalpha $xalpha\
    -qheat $qheat -nheat $nheat\
    -heldata $heldata -npla $npla -nspa $nspa -nfld $nfld

fi

#---------------------------------------------------------------------
# Process heliospheric computation

if [ $data_run == yes ] && [ $clean == no ] ; then

  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -vutime $vutime -xtplot [0.,$tstop]\
    +data_evo

  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "earth" -loscen 3\
    +data_los
  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "stereoa" -loscen 1\
    +data_los
  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "stereob" -loscen 2\
    +data_los

  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "earth"\
    +data_fldsho
  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "stereoa"\
    +data_fldsho
  bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
    -namobs "stereob"\
    +data_fldsho

fi

#---------------------------------------------------------------------
# Plot heliospheric computation

if [ $plot_run == yes ] && [ $clean == no ] ; then

  if [ $pevo10o1 != 0 ] ; then
# evo10o1 - portrait mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO10O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth"\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 10 -btevo 20 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_evo10o1
# evo10o1 - landscape mode
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO10O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth"\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 10 -btevo 20 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_evo10o1
  fi

  if [ $pevo1o5 != 0 ] ; then
# evo1o5 - observers=3, wide=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO1O5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth","stereoa","stereob"]\
      -namevo ["vr"]\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 8 -btevo 8 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_evo1o5
# evo1o5 - observers=2, wide=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO1O5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth","mars"]\
      -namevo ["vr"]\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 8 -btevo 8 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_evo1o5
  fi

  if [ $pevo5o1 != 0 ] ; then
# evo5o1 - evolutions=4, wide=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO5O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr","den","tem","btot"]\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 8 -btevo 8 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_evo5o1
# evo5o1 - evolutions=2, wide=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO5O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr","den"]\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 8 -btevo 8 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_evo5o1
# evo5o1 - evolutions=1, wide=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "EVO5O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr"]\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -bevo 20 -brevo 20 -bnevo 8 -btevo 8 -ddifevo 20 -devo 20\
      -pramevo 10 -tevo 1 -vdifevo 400 -vevo [200,1000]\
      -vrevo [200,1000] -vnevo 100 -vtevo 100\
      +evohcld +evopos +evosho -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 2 +png\
      +plot_evo5o1
  fi

  if [ $plos1 != 0 ] ; then
# los1 - lospalat="pa", losxy=0, wide=0, zoom=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "stereoa"\
      -namfov "stereoa" -namlos ["tvale"]\
      -loscen 1 -losdif 2 -losimax 1 -losimin 0 -lospalat "pa" -losxy 0\
      -lonplot "obs" -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1\
      -fontsize $fontsize -size $size -wide 0 -zoom 1 +png\
      +plot_los1
# los1 - lospalat="pa", losxy=0, wide=0, zoom=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "stereob"\
      -namfov "stereob" -namlos ["tvale"]\
      -loscen 2 -losdif 2 -losimax 1 -losimin 0 -lospalat "pa" -losxy 0\
      -lonplot "obs" -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1\
      -fontsize $fontsize -size $size -wide 0 -zoom 2 +png\
      +plot_los1
  fi

  if [ $plos1d != 0 ] ; then
# los1d - lospalat="pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS1D" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "stereoa"\
      -namfov "stereoa" -namlos ["tvale"]\
      -loscen 1 -losdif 2 -losdmax 30 -losimax 1 -losimin 0 -losxy $losxy\
      -lonplot "obs" -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1d\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_los1d
# los1d - lospalat="pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS1D" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "stereob"\
      -namfov "stereob" -namlos ["tvale"]\
      -loscen 2 -losdif 2 -losdmax 30 -losimax 1 -losimin 0 -losxy $losxy\
      -lonplot "obs" -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1d\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_los1d
  fi

  if [ $plos2 != 0 ] ; then
# los2 - lospalat "pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS2" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -nam2obs ["earth","earth"] -namlos ["tvale"]\
      -los2cen [1,2] -losdif 2 -losimax 1 -losimin 0 -losxy $losxy\
      -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos2\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_los2
  fi

  if [ $plos2d != 0 ] ; then
# los2d - lospalat "pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS2D" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -nam2obs ["earth","earth"] -namlos ["tvale"]\
      -los2cen [1,2] -losdif 2 -losdmax 30 -losimax 1 -losimin 0 -losxy $losxy\
      -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos2d\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_los2d
  fi

  if [ $plos3 != 0 ] ; then
# los3 - lospalat "pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOS3" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namfov "stereoa" -namlos ["tvale"]\
      -loscen 1 -losdif 2 -losimax 1 -losimin 0 -losxy $losxy\
      -lonplot "obs" -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos3\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_los3
  fi

  if [ $plosmap1j != 0 ] ; then
# losmap1j - lospalat "pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOSMAP1J" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namfov "stereoa" -namlos ["pidif","tvale"]\
      -loscen 1 -losdif 2 -losimax 1 -losimin 0\
      -loselon 20 -loslat 0 -losilev 0.5\
      -vutime $vutime -xtplot [0,48]\
      -fontsize $fontsize -size $size -wide 2 -zoom $zoom +png\
      +plot_losmap1j
  fi

  if [ $plosmap1p != 0 ] ; then
# losmap1p - lospalat "pa", losxy=0, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "LOSMAP1P" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namfov "stereoa" -namlos ["pidif","tvale"]\
      -loscen 1 -losdif 2 -losimax 1 -losimin 0\
      -loselon 20 -loslat 0 -losilev 0.5\
      -vutime $vutime -xtplot [0,48]\
      -fontsize $fontsize -size $size -wide 2 -zoom $zoom +png\
      +plot_losmap1p
  fi

  if [ $prad1 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RAD1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,1000] -devo 300 -tevo 1.0 -bevo 300\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $prad1\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_rad1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RAD1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,1000] -devo 300 -tevo 1.0 -bevo 300\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $prad1\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_rad1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RAD1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,1000] -devo 300 -tevo 1.0 -bevo 300\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $prad1\
      -fontsize $fontsize -size $size -wide 2 +png\
      +plot_rad1
  fi

  if [ $pradevo1 != 0 ] ; then
# radevo1 - wide=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADEVO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namcnt ["den"] -dcnt 160 -tcnt 2 -vradcnt [200,1600]\
      +hcld -rmax 2.1\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_radevo1
# radevo1 - wide=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADEVO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namcnt ["tem"] -dcnt 160 -tcnt 2 -vradcnt [200,1600]\
      +hcld -rmax 2.1\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_radevo1
# radevo1 - wide=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADEVO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -namcnt ["vrad"] -dcnt 160 -tcnt 2 -vradcnt [200,1600]\
      +hcld -rmax 2.1\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -fontsize $fontsize -size $size -wide 2 +png\
      +plot_radevo1
  fi

  if [ $pradsho1 != 0 ] ; then
# radsho1 - nsmoothv 0, wide=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADSHO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -rsho 2 -vsho [200,1800] -nsmoothv 0\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      +hcld -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 0 +png\
      +plot_radsho1
# radsho1 - nsmoothv 2, wide=1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADSHO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -rsho 2 -vsho [200,1800] -nsmoothv 2\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      +hcld -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_radsho1
# radsho1 - nsmoothv 4, wide=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "RADSHO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth"]\
      -rsho 2 -vsho [200,1800] -nsmoothv 4\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      +hcld -xpsho 1.2\
      -fontsize $fontsize -size $size -wide 2 +png\
      +plot_radsho1
  fi

  if [ $psho1 != 0 ] ; then
# sho1 - rmax 2, wide=0, zoom=0
##  bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
##    -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
##    -labitem "SHO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
##    -namobs "earth" -lonplot "obs"\
##    -namfld ["earth","stereoa","stereob"]\
##    -rmax 2 -planets -1 -spacecraft 2 +equatorial\
##    -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1\
##    -fontsize $fontsize -size $size -wide 0 -zoom 0 +png\
##    +plot_sho1
# sho1 - rmax -1.5, wide=1, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHO1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth" -lonplot "obs"\
      -namfld ["earth","stereoa","stereob"]\
      -rmax -1.5 -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1\
      -fontsize $fontsize -size $size -wide 1 -zoom 0 +png\
      +plot_sho1
  fi

  if [ $psho1e5 != 0 ] ; then
# sho1e5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHO1E5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth" -lonplot "obs"\
      -namfld ["earth"]\
      -namsho ["rsho","ssho","vsho"] -rsho 2 -ssho 2000 -vsho 8\
      -nsmooth 1\
      -rmax $rmax -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -xtslide $xtslide -istep $psho1e5\
      -fontsize $fontsize -size $size -wide $wide -zoom $zoom +png\
      +plot_sho1e5
  fi

  if [ $psho1o5 != 0 ] ; then
# sho1o5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHO1O5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth","stereoa","stereob"] -lonplot "obs"\
      -namfld ["earth","stereoa","stereob"]\
      -namsho "rsho" -rsho 2\
      -nsmooth 1\
      -rmax $rmax -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -xtslide $xtslide -istep $psho1o5\
      -fontsize $fontsize -size $size -wide $wide -zoom $zoom +png\
      +plot_sho1o5
  fi

  if [ $psho2e1 != 0 ] ; then
# sho2e1 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHO2E1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth" -lonplot "obs"\
      -namfld ["earth"]\
      -namsho ["rsho","ssho","vsho"] -rsho 2 -ssho 2000 -vsho 8\
      -nsmooth 1\
      -rmax $rmax -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -xtslide $xtslide -istep $psho2e1\
      -fontsize $fontsize -size $size -wide $wide -zoom $zoom +png\
      +plot_sho2e1
  fi

  if [ $psho2z != 0 ] ; then
# sho2z - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHO2Z" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth" -lonplot "obs"\
      -namfld ["earth","stereoa"]\
      -rmax $rmax -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho2z\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_sho2z
  fi

  if [ $pshoevo1o5 != 0 ] ; then
# shoevo1o5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHOEVO1O5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["earth","stereoa","stereob"]\
      -namsho ["rsho"] -rsho 2\
      -nsmooth 1\
      -reg $reg\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_shoevo1o5
  fi

  if [ $pshoevo5o1 != 0 ] ; then
# shoevo5o1 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "SHOEVO5O1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "earth" -lonplot "obs"\
      -namsho ["rsho","ssho","dsho"] -rsho 2 -ssho 2000 -dsho 8\
      -nsmooth 1\
      -reg $reg\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -fontsize $fontsize -size $size -wide 1 +png\
      +plot_shoevo5o1
  fi

  if [ $ptim1 != 0 ] ; then
# tim1 - rmax=2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["den","vrad"]\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth","stereoa"] -lonplot "obs"\
      +hcld +hcs -rmax 2 -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim1\
      -fontsize $fontsize -size $size -wide 0 -zoom 0 +png\
      +plot_tim1
# tim1 - rmax=-1.5, wide=1, zoom=2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["den","vrad"]\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth","stereoa"] -lonplot "obs"\
      +hcld +hcs -rmax -1.5 -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim1\
      -fontsize $fontsize -size $size -wide 1 -zoom 2 +png\
      +plot_tim1
  fi

  if [ $ptim1e1 != 0 ] ; then
# tim1e1 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM1E5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,1600] -devo 40 -bevo 20\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
        -xtslide $xtslide  -istep $ptim1e1\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim1e1
  fi

  if [ $ptim1e5 != 0 ] ; then
# tim1e5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM1E5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,800] -devo 40 -bevo 20\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
        -xtslide $xtslide  -istep $ptim1e5\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim1e5
  fi

  if [ $ptim1o5 != 0 ] ; then
# tim1o5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM1O5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,800] -devo 40 -bevo 20\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth","stereoa"] -lonplot "obs" \
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
        -xtslide $xtslide  -istep $ptim1o5\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim1o5
  fi

  if [ $ptim2 != 0 ] ; then
# tim2 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim2\
      -fontsize $fontsize -size $size -zoom 3 +png\
      +plot_tim2
exit 0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim2\
      -fontsize $fontsize -size $size -zoom 1 +png\
      +plot_tim2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim2\
      -fontsize $fontsize -size $size -zoom 2 +png\
      +plot_tim2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim2\
      -fontsize $fontsize -size $size -zoom 3 +png\
      +plot_tim2
  fi

  if [ $ptim2e1 != 0 ] ; then
# tim2e1 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2E1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,2000] -devo 40 -bevo 20\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
        -xtslide $xtslide -istep $ptim2e1\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim2e1
  fi

  if [ $ptim2e5 != 0 ] ; then
# tim2e5 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2E5" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,800] -devo 40 -bevo 20\
      -namfld ["earth","stereoa","stereob"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
        -xtslide $xtslide -istep $ptim2e5\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim2e5
  fi

  if [ $ptim2z != 0 ] ; then
# tim2z - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM2Z" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namfld ["earth","stereoa","stereob"]\
      -namfov ["stereoa"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax 2.1 -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto] -istep $ptim2z\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim2z
  fi

  if [ $ptim3 != 0 ] ; then
# tim3 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM3" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vcnt [200,1600] -dcnt 80\
      -namfld ["earth"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim3\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim3
  fi

  if [ $ptim3e1 != 0 ] ; then
# tim3e1 - rmax 2, wide=0, zoom=0
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "TIM3E1" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad"] -vcnt [200,1600] -vrevo [200,800]\
      -namfld ["earth"]\
      -namobs ["earth"] -lonplot "obs"\
      +hcld +hcs -rmax $rmax -planets -1 -spacecraft 2 +ecliptic\
      +evohcld +evopos +evosho -xpsho 1.2\
      -vutime $vutime -xtobs [$tfrom,$tto] -xtplot [$tfrom,$tto]\
      -xtslide $xtslide -istep $ptim3e1\
      -fontsize $fontsize -size $size -zoom $zoom +png\
      +plot_tim3e1
  fi

fi

#---------------------------------------------------------------------
# Remove non-critical files

if [ $clean == yes ] ; then

  bash $ENLIL_DIR/codes/enlil/scripts/clean.sh\
    -make $make -case $case -run $run -all $all

fi

#---------------------------------------------------------------------
exit 0
