#!/bin/bash
#=====================================================================
#
# NAME 
#   xsb3cone
#
# PURPOSE
#   Run *ENLIL* computation using *ANA3D* and *CONE* parameters
#
# USAGE
#   xsb3cone [-<parameter> <value>]
#   xsb3cone make [-<parameter> <value>]
#   xsb3cone case [-<parameter> <value>]
#   xsb3cone plot_case [-<parameter> <value>]
#   xsb3cone run [-<parameter> <value>]
#   xsb3cone data_run [-<parameter> <value>]
#   xsb3cone plot_run [-<parameter> <value>]
#   xsb3cone 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:
#                       ana3d/sb3cone
#
# PARAMETERS - NUMERICAL MODEL
#   -energy <char>    - Energy equation:
#                       ethe | etot | etot1 | etot2
#   -scheme <char>    - Numerical scheme:
#                       tvdlf1 | tvdlf2
#   -upwind <char>    - Numerical upwinding:
#                       upwind | upwindp
#   -limiter <char>   - Slope limiter:
#                       minmod | albada
#   -flux <char>      - Numerical flux:
#                       llf | hll
#   -flxdif <char>    - Increased flux diffusion:
#                       noflxdif | flxdif
#   -vsdif <char>     - Increased signal speed:
#                       novsdif | vsdif
#   -bctim <char>     - Boundary condition:
#                       bctim1c | bctim1h | bctim1v
#   -cvetot <float>   - Compressive velocity threshold:
#                       1.1
#
# 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 | fine | super | ultra
#
# PARAMETERS - COMPUTATIONAL PERIOD AND OUTPUT
#   -tstop <float>    - Stop computation at this time (h):
#                       168.
#   -tstep <float>    - Output with this step in time (h):
#                       24.
#
# PARAMETERS - BACKGROUND SOLAR WIND
#   -sphi <float>     - Azimuthal shift of the streamer belt(deg):
#                       0.
#   -stilt <float>    - Inclination of the streamer belt (deg):
#                       40.
#   -swidth <float>   - Width of the streamer belt (deg):
#                       40.
#   -szone <float>    - Width of the streamer transition zone (deg):
#                       5.
#   -bfast <float>    - Radial magnetic field of the fast stream (nT):
#                       300.
#   -bslow <float>    - Radial magnetic field of the slow stream (nT):
#                       300.
#   -dfast <float>    - Number density of the fast stream (cm-3):
#                       300.
#   -dslow <float>    - Number density of the slow stream (cm-3):
#                       1200.
#   -tfast <float>    - Mean temperature of the fast stream (MK):
#                       1.2
#   -tslow <float>    - Mean temperature of the fast stream (MK):
#                       0.3
#   -vfast <float>    - Radial flow velocity of the fast stream (km/s):
#                       600.
#   -vslow <float>    - Radial flow velocity of the slow stream (km/s):
#                       300.
#   -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
#   -ncmes <int>      - Number of simulated CMEs:
#                       1 | 0
#   -timramp <float>  - Transition from background to transient (h):
#                       0.
#   -dates <char>     - Cloud leading edge at boundary at this date:
#                       null | <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):
#                       30.
#   -rminor <float>   - Cone (ellipsoid) minor radius (deg):
#                       0.
#   -tilt <float>     - Cone (if ellipsoid) tilt from equator (deg)
#                       0.
#   -dcld <float>     - Cloud density / fast stream density:
#                       4.
#   -tcld <float>     - Cloud temperature / fast stream temperature:
#                       1.
#   -vcld <float>     - Cloud velocity (km/s):
#                       900.
#   -xcld <float>     - Cloud trailing elongation over spherical shape:
#                       1.
#   -ncld <int>       - Cloud shape (2=sphesymbnd, 3=sphesymcen, 4=sphekincen):
#                       2
#
# PARAMETERS - RUN
#   -akcfl <float>    - CFL stability number (0.1 - 0.4):
#                       0.4
#   -cvetot <float>   - Compressive velocity threshold:
#                       1.1
#   -qheat <float>    - Volumetric heating coefficient (0 | ~ 0.05 | ~ 100000):
#                       0.3
#   -qtmin1au <float> - Full volumetric heating below this temperature (MK):
#                       0.2
#   -qtmax1au <float> - No volumetric heating above this temperature (MK):
#                       0.3
#   -nheat <int>      - Volumetric heating type (0 - 3):
#                       3
#   -tmax1au <float>  - Maximum allowed (shock) temperature (MK):
#                       10.
#   -ntmax <int>      - Maximum allowed (shock) temperature type (0 | 1):
#                       0 | 1
#
# PARAMETERS - PLOT PROCEDURES
#   -pbnd <int>       - Plot_bnd if non-zero:
#                       1
#   -pbnd2 <int>      - Plot_bnd2 if non-zero:
#                       0
#   -pbnd6 <int>      - Plot_bnd6 if non-zero:
#                       0
#   -pbndtim1 <int>   - Plot_bndtim1 if non-zero:
#                       0
#   -pevo1o5 <int>    - Plot_evo1o5 if non-zero:
#                       0
#   -pevo5o1 <int>    - Plot_evo5o1 if non-zero:
#                       1
#   -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 if non-zero:
#                       0
#   -plosmap1p <int>  - Plot_losmap1p if non-zero:
#                       0
#   -psho1 <int>      - Plot_sho1 with this step in output files:
#                       0
#   -psho1e5 <int>    - Plot_sho1e5 with this step in output files:
#                       0
#   -pshoevo1o5 <int> - Plot_shoevo1o5 if non-zero:
#                       0
#   -pshoevo5o1 <int> - Plot_shoevo5o1 if non-zero:
#                       0
#   -ptim1 <int>      - Plot_tim1 with this step in output files:
#                       0
#   -ptim1e5 <int>    - Plot_tim1e5 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:
#                       1
#
# PARAMETERS - PLOT OPTIONS
#   -info <int>       - Informative footnote (1=yes,  0=no, -1=ghost):
#                       1
#   -labitem <char>   - Label plot by item (optional, at top-left):
#                       SB3CONE
#   -losdmax <float>  - LOS+DEN image max density value
#                       30.
#   -loselon <float>  - LOS marker elongation
#                       0.
#   -losimax <float>  - LOS image max value
#                       2.
#   -loslat <float>   - LOS marker latitude
#                       0.
#   -losxy <int>      - LOS image in spherical (0) or Cartesian (1) coord
#                       0
#   -rmax <float>     - Plotting region (AU)
#                       2
#   -zoom <int>       - Zoom (0=none | 1=66% | 2=50% (or 33%)
#                       0
#
#   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 the results will go).
#
# NOTE
#   Default parameters correspond to low-resolution computation
#   using the reference numerical model and ambient wind settings
#   for the homogeneous solar wind in a heliospheric region
#   between 0.1 and 1.1 AU for -7+5 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 (by relative positions to this script location)

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 directory

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=idl             # Visualization software (gdl | idl)

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

project=ana3d/sb3cone  # Project name

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

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

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

energy=ethe         # Energy equation (ethe | etot | etot1 | etot2)
scheme=tvdlf2       # Numerical scheme (tvdlf1 | tvdlf2)
upwind=upwind       # Numerical upwinding (upwind | upwindp)
limiter=minmod      # Slope limiter (minmod | albada)
flux=llf            # Numerical flux (llf | hll)
flxdif=noflxdif     # Increased flux diffusion (noflxdif | flxdif)
vsdif=novsdif       # Increased signal speed (novsdif | vsdif)
difb=difb           # Div(B) diffusion treament (difb | dedner | nodifb)
difbb=nodifbb       # Magnetic field diffusion (difbc | difbb | nodifbb)
divb=nodivb         # Div(B) treament (jandif | povell | powell | nodivb)
bchalf=nobchalf     # Time-dependent boundary conditions at the half-step
bctim=bctim1c       # Boundary condition (bctim1c | bctim1h | bctim1v)

#---------------------------------------------------------------------
# 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
n2d=0               # Set 2D grid instead of 3D (0 | 1)
nblk=2              # Number of computational blocks
npos=1              # Number of latitudinal positions for evolutions

#---------------------------------------------------------------------
# Default computational period and output parameters

tstop=168.          # Stop computation at this time (h)
tstep=6.            # Output with this step in time (h)

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

sphi=0              # Streamer belt azimuthal shift (deg)
stilt=40            # Streamer belt tilt (deg)
swidth=40           # Streamer belt width (deg)
szone=5             # Streamer belt transition zone (deg)
bfast=300           # Radial magnetic field of the fast stream (nT)
bslow=300           # Radial magnetic field of the slow stream (nT)
dfast=300           # Number density of the fast stream (cm-3)
dslow=1200          # Number density of the slow stream (cm-3)
tfast=1.2           # Mean temperature of the fast stream (MK)
tslow=0.3           # Mean temperature of the fast stream (MK)
vfast=600           # Radial flow velocity of the fast stream (km/s)
vslow=300           # Radial flow velocity of the slow stream (km/s)
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

ncmes=1             # Number of simulated CMEs
cld=null            # Hydrodynamic cloud label
timramp=0.          # Transition from background to transient (h)
dates="null"        # Cloud leading edge at boundary at this date
                    # (yyyy-mm-ddThh:mm | null)
lat=0.              # 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=4.             # Cloud density / fast stream density
tcld=1.             # Cloud temperature / fast stream temperature
vcld=900.           # Cloud velocity (km/s)
xcld=1.             # Cloud trailing elongation over spherical shape
ncld=2              # Cloud shape (2=sphesymbnd, 3=sphesymcen, 4=sphekincen)

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

akcfl=0.4           # Targeted CFL stability number (< 0.5)
cdifb=0.2           # Div(B) diffusion coefficient
cdifbb=1.           # Div(B) diffusion coefficient
ceclip=0.01         # Clip the thermal energy below fraction of the total energy
cflxdif=0.          # Increase flux diffusion (0:1)
cvetot=1.01         # Compressive velocity threshold for Etot (if Ethe+Etot)
cvsdif=0.           # Increase signal speed (0:1)
qheat=0.3           # Volumetric heating coefficient (0 | ~ 0.05 | ~ 100000)
qtmin1au=1.         # Full volumetric heating below this temperature (MK)
qtmax1au=3.         # No volumetric heating above this temperature (MK)
nheat=3             # Volumetric heating type (0 - 3)
tmax1au=10.         # Maximum allowed (shock) temperature (MK)
ntmax=0             # Maximum allowed (shock) temperature type (0 | 1)

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

pbnd=1              # Plot_bnd if non-zero
pbnd2=0             # Plot_bnd2 if non-zero
pbnd6=0             # Plot_bnd6 if non-zero
pbndtim1=0          # Plot_bndtim1 if non-zero
pevo1o5=0           # Plot_evo1o5 if non-zero
pevo5o1=1           # 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
psho1=0             # Plot_sho1 with this step in output files
psho1e5=0           # Plot_sho1e5 with this step in output files
pshoevo1o5=0        # Plot_shoevo1o5 if non-zero
pshoevo5o1=0        # Plot_shoevo5o1 if non-zero
ptim1=0             # Plot_tim1 with this step in output files
ptim1e5=0           # Plot_tim1e5 with this step in output files
ptim3=0             # Plot_tim3 with this step in output files
ptim3e1=1           # Plot_tim3e1 with this step in output files

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

info=1              # Informative footnote (1=yes, 0=no, -1=ghost)
labitem=AMB3CONE    # Label plot by item (optional, at top left)
losdmax=40.         # LOS+DEN image max density value
loselon=0           # LOS marker elongation
losimax=1.          # LOS image max value
loslat=0            # LOS marker latitude
losxy=0             # LOS image in spherical (0) or Cartesian (1) coord
rmax=-1.5           # Plotting region (AU)
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  ;;
    -procs)      procs=$2       ; shift ;;
    -projdir)    projdir=$2     ; shift ;;
    -project)    project=$2     ; shift ;;
    -energy)     energy=$2      ; shift ;;
    -scheme)     scheme=$2      ; shift ;;
    -upwind)     upwind=$2      ; shift ;;
    -limiter)    limiter=$2     ; shift ;;
    -flux)       flux=$2        ; shift ;;
    -flxdif)     flxdif=$2      ; shift ;;
    -vsdif)      vsdif=$2       ; shift ;;
    -difb)       difb=$2        ; shift ;;
    -difbb)      difbb=$2       ; shift ;;
    -divb)       divb=$2        ; shift ;;
    -bchalf)     bchalf=$2      ; shift ;;
    -bctim)      bctim=$2       ; shift ;;
    -nreg)       nreg=$2        ; shift ;;
    -reg)        reg=$2         ; shift ;;
    -res)        res=$2         ; shift ;;
    -res23)      res23=$2       ; shift ;;
    -n2d)        n2d=$2         ; shift ;;
    -nblk)       nblk=$2        ; shift ;;
    -npos)       npos=$2        ; shift ;;
    -tstop)      tstop=$2       ; shift ;;
    -tstep)      tstep=$2       ; shift ;;
    -sphi)       sphi=$2        ; shift ;;
    -stilt)      stilt=$2       ; shift ;;
    -swidth)     swidth=$2      ; shift ;;
    -szone)      szone=$2       ; shift ;;
    -bfast)      bfast=$2       ; shift ;;
    -bslow)      bslow=$2       ; shift ;;
    -dfast)      dfast=$2       ; shift ;;
    -dslow)      dslow=$2       ; shift ;;
    -tfast)      tfast=$2       ; shift ;;
    -tslow)      tslow=$2       ; shift ;;
    -vfast)      vfast=$2       ; shift ;;
    -vslow)      vslow=$2       ; shift ;;
    -bndrot)     bndrot=$2      ; shift ;;
    -gamma)      gamma=$2       ; shift ;;
    -xalpha)     xalpha=$2      ; shift ;;
    -ncmes)      ncmes=$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 ;;
    -tcld)       tcld=$2        ; shift ;;
    -vcld)       vcld=$2        ; shift ;;
    -xcld)       xcld=$2        ; shift ;;
    -ncld)       ncld=$2        ; shift ;;
    -par)        par=$2         ; shift ;;
    -akcfl)      akcfl=$2       ; shift ;;
    -cdifb)      cdifb=$2       ; shift ;;
    -cdifbb)     cdifbb=$2      ; shift ;;
    -ceclip)     ceclip=$2      ; shift ;;
    -cflxdif)    cflxdif=$2     ; shift ;;
    -cvetot)     cvetot=$2      ; shift ;;
    -cvsdif)     cvsdif=$2      ; shift ;;
    -qheat)      qheat=$2       ; shift ;;
    -qtmax1au)   qtmax1au=$2    ; shift ;;
    -qtmin1au)   qtmin1au=$2    ; shift ;;
    -nheat)      nheat=$2       ; shift ;;
    -tmax1au)    tmax1au=$2     ; shift ;;
    -ntmax)      ntmax=$2       ; shift ;;
    -pbnd)       pbnd=$2        ; shift ;;
    -pbnd2)      pbnd2=$2       ; shift ;;
    -pbnd6)      pbnd6=$2       ; shift ;;
    -pbndtim1)   pbndtim1=$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 ;;
    -psho1)      psho1=$2       ; shift ;;
    -psho1e5)    psho1e5=$2     ; shift ;;
    -pshoevo1o5) pshoevo1o5=$2  ; shift ;;
    -pshoevo5o1) pshoevo5o1=$2  ; shift ;;
    -ptim1)      ptim1=$2       ; shift ;;
    -ptim1e5)    ptim1e5=$2     ; shift ;;
    -ptim3)      ptim3=$2       ; shift ;;
    -ptim3e1)    ptim3e1=$2     ; shift ;;
    -info)       info=$2        ; shift ;;
    -labitem)    labitem=$2     ; shift ;;
    -losdmax)    losdmax=$2     ; shift ;;
    -loselon)    loselon=$2     ; shift ;;
    -losimax)    losimax=$2     ; shift ;;
    -loslat)     loslat=$2      ; shift ;;
    -losxy)      losxy=$2       ; shift ;;
    -rmax)       rmax=$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=ana3d2bc

evocode=out2evo
loscode=out2los
shocode=out2sho

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

# Default values
numo=mcp            # Numerical model setting label
heat=vheat          # Global heating (vheat | hheat | noheat)
vc=vc_max           # Char. speed at cell interfaces (vc_avr | vc_max)
vs=vs_mmax          # Signal speed at cell interfaces
mftrace=mfrk4       # IMF line tracing (mfeuler | mfrk4)

# Label the numerical model by "energy"
if [ $energy == ethe ] ; then
if [ $scheme == tvdlf2 ] ; then
  numo=$numo'1'
else
  numo=$numo'10'
fi
fi
if [ $energy == etot ] ; then
if [ $scheme == tvdlf2 ] ; then
  numo=$numo'2'
else
  numo=$numo'20'
fi
fi
if [ $energy == etot1 ] ; then
if [ $scheme == tvdlf2 ] ; then
  numo=$numo'3'
else
  numo=$numo'30'
fi
fi
if [ $energy == etot2 ] ; then
if [ $scheme == tvdlf2 ] ; then
  numo=$numo'4'
else
  numo=$numo'40'
fi
fi

# Label the numerical model by "upwind"
if [ $upwind == upwind ] ; then
  numo=$numo'u'
fi
if [ $upwind == upwindp ] ; then
  numo=$numo'v'
fi

# Label the numerical model by "limiter"
if [ $limiter == minmod ] ; then
  numo=$numo'm'
fi
if [ $limiter == albada ] ; then
  numo=$numo'a'
fi

# Label the numerical model by "flux" and "flxdif"
if [ $flux == llf ] ; then
if [ $flxdif == flxdif ] ; then
  numo=$numo'11'
else
  numo=$numo'1'
fi
fi
if [ $flux == hll ] ; then
if [ $flxdif == flxdif ] ; then
  numo=$numo'22'
else
  numo=$numo'2'
fi
fi

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

# Label the numerical model by "bctim"
if [ $bctim == bctim1c ] ; then
  numo=$numo'c'
fi
if [ $bctim == bctim1h ] ; then
  numo=$numo'h'
fi
if [ $bctim == bctim1v ] ; then
  numo=$numo'v'
fi

# Label the numerical model by "difb"
if [ $difb == difb ] ; then
  numo=$numo'd'
fi
if [ $difb == dedner ] ; then
  numo=$numo'e'
fi

# Label the numerical model by "difbb"
if [ $difbb == difba ] ; then
  numo=$numo'a'
fi
if [ $difbb == difbb ] ; then
  numo=$numo'b'
fi
if [ $difbb == difbc ] ; then
  numo=$numo'c'
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 [ $res == super ] ; then
  nx=16               # Grid resolution factor
fi
if [ $res == ultra ] ; then
  nx=32               # 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" and "n2d"
if [ $res23 != 1 ] ; then
  let n2=n2*res23     # Refinement of the X2-grid
  let n3=n3*res23     # Refinement of the X3-grid
fi
if [ $n2d == 1 ] ; then
  n2=1                # Ensure 2D computations
fi

# Auxiliary label by "res" and "res23"
if [ $res23 == 1 ] ; then
  rres=$res
else
  rres=$res$res23
fi

# Label the grid by "nreg", "reg", "res", "nblk", "res23", 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

# Default values (reg=1)
rundate=null        # Start computation at this date (null | yyyy-mm-ddThh)
vutime=3600.        # Time unit scale factor (s)
tstart=-168.        # Start computation at this time (h)
tfrom=0.            # Output from this 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)

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

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

# Default values
nbrad=1             # Magnetic field correction

# Label the ambient solar wind parameters
if [ $bfast == 0 ] || [ $bfast== 0. ] ; then
  amb='b00'
else
  amb='b'${bfast:0:2}
fi
if [ $bslow == 0 ] || [ $bslow== 0. ] ; then
  amb='b00'
else
  amb='b'${bslow:0:2}
fi
if [ $dfast -lt 1000 ] ; then
  amb=$amb'd0'${dfast:0:2}
else
  amb=$amb'd'${dfast:0:3}
fi
if [ $dslow -lt 1000 ] ; then
  amb=$amb'd0'${dslow:0:2}
else
  amb=$amb'd'${dslow:0:3}
fi
amb=$amb't'${tfast//.}
amb=$amb't'${tslow//.}
amb=$amb'v'${vfast:0:2}
amb=$amb'v'${vslow:0:2}

# Add label for streamer belt (if present)
if [ $swidth != 0 ] ; then
  amb=$amb'-s'$swidth't'$stilt
  if [ ${sphi:0:1} == '-' ] ; then
    zsphi='e'${sphi#*-}  # Get all characters after first "-"
  else
    zsphi='w'$sphi
  fi
  amb=$amb$zsphi
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 boundary conditions
bnd=$amb

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

# Default values
maxcld=20           # Maximum no. of CMEs
maxslc=15           # Maximum no. of CMEs

if [ $ncmes != 0 ]  ; then

  # Label the disturbance
  if [ $cld == null ] ; then

    # Label the disturbance by cone parameters
    cld='d'${dcld//.}'t'${tcld//.}'v'${vcld//.}'r'${rmajor//.}
    if [ $xcld != 1 ] && [ $xcld != 1. ] ; then
      xxx='x'${xcld//.}
    fi
    if [ ${ncld:0:1} == '-' ] ; then
      nnn='n'${ncld:1:1}
    else
      nnn='p'$ncld
    fi
    cld=$cld$xxx$nnn

    # 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

fi

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

# Default values
x1hel=0.25,0.5,1,1,1,2        # X1-position of the observing point(s) in heliosphere
x2hel=90,90,90,90,90,90       # X2-position of the observing point(s) in heliosphere
x3hel=180,180,180,240,120,180 # X3-position of the observing point(s) in heliosphere
nhel=6                        # Number of heliospheric observing points (0 - 20)
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 "tmax1au"
if [ $ntmax != 0 ] ; then
  runpar=$runpar't'${tmax1au//.}
fi

# Label the run parameters by "akcfl"
if [ $akcfl != 0.4 ] ; then
  runpar=$runpar'a'${akcfl//.}
fi

# Label the run parameters by "cflxdif"
zzz=${cflxdif//.}
if [ $zzz -gt 0 ] ; then
  runpar=$runpar'f'${cflxdif//.}
fi

# Label the run parameters by "cvsdif"
zzz=${cvsdif//.}
if [ $zzz -gt 0 ] ; then
  vsdif=vsdif
  runpar=$runpar's'${cvsdif//.}
else
  vsdif=novsdif
fi

# Label the run parameters by "cvetot"
if [ $energy == etot1 ] || [ $energy == etot2 ] ; then
  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. ] && [ $difb != nodifb ] ; then
  runpar=$runpar'b'${cdifb//.}
fi
if [ $cdifbb != 0. ] && [ $difbb != nodifbb ] ; then
  runpar=$runpar'bb'${cdifbb//.}
fi
if [ $cvetot == -1.0 ] ; then
  runpar=$runpar'w00'
fi

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

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

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

# Figure name prefix and suffix
namfiga=$bnd
if [ $n2d == 1 ] ; then
  namfiga=$namfiga'2d'
fi
namfigz_case=$runpar'_'$res
namfigz_run=$numo'_'$runpar'_'$res

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

export system batch binsrc vis
export ENLIL_DIR HELIO_DIR
export projdir project numo procs
export casecode grdcode ambcode evocode loscode shocode
export grd reg res n1 n2 n3 nblk npos maxcld maxslc
export 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 -vc $vc -vs $vs -vsdif $vsdif\
    -mftrace $mftrace -difb $difb -difbb $difbb -divb $divb

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\
    -bndrot $bndrot\
    -sphi $sphi -stilt $stilt -swidth $swidth -szone $szone\
    -bfast $bfast -dfast $dfast -tfast $tfast -vfast $vfast\
    -bslow $bslow -dslow $dslow -tslow $tslow -vslow $vslow\
    -xalpha $xalpha -nbrad $nbrad\
    -ncmes $ncmes -timramp $timramp -dates $dates\
    -lat $lat -lon $lon -rmajor $rmajor -rminor $rminor -tilt $tilt\
    -dcld $dcld -tcld $tcld -vcld $vcld -xcld $xcld -ncld $ncld

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 "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bcnt 600 -dcnt 5000 -tcnt 2 -vcnt [200,1600]\
      -bevo 600 -devo 5000 -tevo 2 -vevo [200,1200]\
      -fontsize 1 -size 1 +png\
      -framerate 10 +mp4\
      +plot_bnd
  fi

  if [ $pbnd2 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bradcnt 600 -bphicnt 60 -dcnt 5000 -vradcnt [200,1600]\
      +hcld +hcs\
      -fontsize 1 -size 1 -wide 0 -zoom 1 +png\
      -framerate 10 +mp4\
      +plot_bnd2
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bradcnt 600 -bphicnt 60 -dcnt 5000 -vradcnt [200,1600]\
      +hcld +hcs\
      -fontsize 1 -size 1 -wide 0 -zoom 1 +png\
      -framerate 10 +mp4\
      +plot_bnd2
  fi

  if [ $pbnd6 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bradcnt 600 -bphicnt 60 -bthecnt 60 -dcnt 5000 -tcnt 2 -vradcnt [200,1600]\
      +hcld +hcs\
      -fontsize 1 -size 1 -wide 0 -zoom 1 +png\
      -framerate 10 +mp4\
      +plot_bnd6
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -bradcnt 600 -bphicnt 60 -bthecnt 60 -dcnt 5000 -tcnt 2 -vradcnt [200,1600]\
      +hcld +hcs\
      -fontsize 1 -size 1 -wide 1 -zoom 1 +png\
      -framerate 10 +mp4\
      +plot_bnd6
  fi

  if [ $pbndtim1 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_case.sh\
      -info $info -labcase "$labcase" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_case"\
      -namcnt ["den","tem","vrad"]\
      -dcnt 5000 -tcnt 2 -vradcnt [200,1600]\
      +hcld\
      -fontsize 1 -size 1 -zoom $zoom +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\
    -tfstep $tfstep -ttstep $ttstep -t1step $t1step\
    -bndrot $bndrot\
    -akcfl $akcfl -cdifb $cdifb -cdifbb $cdifbb\
    -ceclip $ceclip -cvetot $cvetot -cflxdif $cflxdif -cvsdif $cvsdif\
    -gamma $gamma -xalpha $xalpha\
    -qheat $qheat -qtmin1au $qtmin1au -qtmax1au $qtmax1au -nheat $nheat\
    -tmax1au $tmax1au -ntmax $ntmax\
    -nhel $nhel -x1hel $x1hel -x2hel $x2hel -x3hel $x3hel\
    -npla 0 -nspa 0 -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 -xtmin 0. -xtmax $tstop\
    +data_evo

  if [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p03" -loscen 3\
      +data_los
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p04" -loscen 1\
      +data_los
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p05" -loscen 2\
      +data_los
  fi

  if [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p03"\
      +data_sho
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p04"\
      +data_sho
    bash $ENLIL_DIR/vis/idl-gdl/scripts/data_run.sh\
      -namobs "p05"\
      +data_sho
  fi

fi

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

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

  if [ $pevo5o1 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p01"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,1000] -devo 1600 -tevo 1 -bevo 100\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 +png\
      +plot_evo5o1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p02"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,1000] -devo 600 -tevo 1 -bevo 80\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 +png\
      +plot_evo5o1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p03"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,800] -devo 80 -tevo 1 -bevo 20\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 +png\
      +plot_evo5o1
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p06"]\
      -namevo ["vr","den","tem","btot"]\
      -vrevo [200,800] -devo 8 -tevo 0.6 -bevo 4\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 +png\
      +plot_evo5o1
  fi

  if [ $plos1 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p05"] -namlos ["absv","elpv","pidif"]\
      -loscen 2 -loselon $loselon -losimax $losimax -losimin 0\
      -loslat $loslat -lospalat "pa" -losrundif 1 -losxy $losxy\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1\
      -rmax -1.5 -size 1 -zoom 2 +png\
      -framerate 20 +mp4\
      +plot_los1
  fi

  if [ $plos1d != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p05"] -namlos ["absv","elpv","pidif"]\
      -loscen 2 -losdmax 40 -loselon $loselon -losimax $losimax -losimin 0\
      -loslat $loslat -lospalat "pa" -losrundif 1 -losxy $losxy +thomson\
      -lonplot "obs" -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $plos1d\
      -rmax -1.5 -size 1 -zoom 2 +png\
      -framerate 20 +mp4\
      +plot_los1d
  fi

  if [ $plosmap1j != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p05"] -namlos ["absv","elpv","pidif"]\
      -loscen 2 -loselon $loselon -losilev 0.5 -losimax $losimax -losimin 0\
      -loslat $loslat -lospalat "pa" -losrundif 1\
      -lonplot "obs" -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 -zoom 2 +png\
      +plot_losmap1j
  fi

  if [ $plosmap1p != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p05"] -namlos ["absv","elpv","pidif"]\
      -loscen 2 -loselon $loselon -losilev 0.5 -losimax $losimax -losimin 0\
      -loslat $loslat -lospalat "pa" -losrundif 1\
      -lonplot "obs" -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto]\
      -size 1 -wide 1 -zoom 2 +png\
      +plot_losmap1p
  fi

  if [ $psho1 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namfld ["p03"]\
      -namobs "p03"\
      -rmax $rmax -lonplot "obs" -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1e5\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +plot_sho1
  fi

  if [ $psho1e5 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namfld ["p03"]\
      -namobs "p03"\
      -namsho ["rsho","ssho","dsho"]\
      -rsho 2 -ssho 1200 -dsho 8\
      -rmax $rmax -lonplot "obs" -planets -1 -spacecraft 2 +equatorial\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1e5\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +plot_sho1e5
  fi

  if [ $pshoevo1o5 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs "p03"\
      -namsho ["rsho","ssho","dsho"]\
      -rsho 2 -ssho 1200 -dsho 8\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1e5\
      -size 1 -wide 1 +png\
      +plot_shoevo1o5
  fi

  if [ $pshoevo5o1 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namobs ["p05","p03","p04"]\
      -namsho ["rsho","ssho","dsho"]\
      -rsho 2 -ssho 1200 -dsho 8\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $psho1e5\
      -size 1 -wide 1 +png\
      +plot_shoevo5o1
  fi

  if [ $ptim1 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vradcnt [200,1600] -dcnt 80\
      -namfld "p03"\
      -namobs "p03"\
      +equatorial +hcld -rmax $rmax\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim1\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +plot_tim1
  fi

  if [ $ptim1e5 != 0 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vradcnt [200,1600] -dcnt 80\
      -namevo ["vr","den","btot"] -vrevo [200,800] -devo 80 -bevo 20\
      -namfld "p03"\
      -namobs "p03"\
      +equatorial +hcld -rmax $rmax\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim1e5\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +plot_tim1e5
  fi

  if [ $ptim3 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vradcnt [200,1600] -dcnt 80\
      -namfld "p03"\
      -namobs "p03"\
      +equatorial +hcld -rmax $rmax\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim3\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +plot_tim3
  fi

  if [ $ptim3e1 != 0 ] && [ $n2d != 1 ] ; then
    bash $ENLIL_DIR/vis/idl-gdl/scripts/plot_run.sh\
      -info $info -labrun "$labrun" -labcen "$labcen" -labuser "$labuser"\
      -labitem "$labitem" -namfiga "$namfiga" -namfigz "$namfigz_run"\
      -namcnt ["vrad","den"] -vradcnt [200,1600] -dcnt 80 -vrevo [200,800] -devo 80\
      -namfld "p03"\
      -namobs "p03"\
      +equatorial +hcld -rmax $rmax\
      +evohcld +evosho -xpsho 1.2\
      -vutime $vutime -xtplot [$tfrom,$tto] -istep $ptim3e1\
      -fontsize 1 -size 1 -zoom $zoom +png\
      -framerate 20 +mp4\
      +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
