#!/bin/csh
#=====================================================================
# helio_cr: Run heliospheric model.
#
# Usage: helio_cr <Carrington rotation> <resolution>
#---------------------------------------------------------------------

# Set parameters
  set crnum = $1
  set resolution = $2

# Set environment variables
  setenv CORHEL_DIR "$CORHEL_ROOT"
  setenv CORHEL_BIN "$CORHEL_ROOT/bin"
  setenv CORHEL_RUN "$CORHEL_ROOT/run/cr$crnum-$resolution"

  pushd $CORHEL_DIR/tools/helio > /dev/null
  source ./set.sh run
  popd > /dev/null

# Set free parameters
  set bnd = a1b2       # Name (<= 8 chars)
  set dfast = 150      # Number density at the innner boundary (cm-3)
  set tfast = 0.6      # Mean temperature at the inner boundary (MK)
  set dvexp = 2        # Exponent in N*V^dvexp=const condition
  set nptot = 0        # = 0 (1) if P_the (P_tot) balance at boundary
  set gamma = 1.5      # Ratio of specfic heats
  set tstop = 30       # Stop computations at this time (days)
  set ttstep = 27.2753 # Frequency of 3-D data output (days)

#=====================================================================
# YOU SHOULD NOT EDIT BELOW
#---------------------------------------------------------------------
# Additional parameters

# Numerical model and code names
  set numo = mp3m
  set enlil = enlil
  set amb2bc = mas2bc

# Grid resolution
  if ($resolution == 'low') then 
    set n1 = 128
    set n2 = 30
    set n3 = 90
  endif
  if ($resolution == 'medium') then 
    set n1 = 256
    set n2 = 60
    set n3 = 180
  endif

# Grid name
  set grd = $n1'x'$n2'x'$n3

# Parallel and multi-grid computations
  set procs = 1
  set levels = 1
  set nblk = 1
  set n1x = $n1/$procs

# Computational region
  set x1l = 0.14
  set x1r = 1.07
  set x2l = 30
  set x2r = 150
  set x3l = 0
  set x3r = 360
  set lx2grd = uniform

# Ambient solar wind parameters
  set data = mas
  set dfast = 150
  set tfast = 0.6
  set vfast = 650
  set bfast = 170
  set xalpha = 0
  set shift = 0
  set nbrad = 2

# Run parameters
  set par = par1
  set vutime = 86400
  set tstart = -6
  set ttfrom = 0
  set ttto = $tstop

#---------------------------------------------------------------------
# Run the heliospheric codes

# Change directory
  cd $CORHEL_RUN/helio

# Directory with data (output from MAS)
  set data_dir = "$CORHEL_RUN"
  set data = "helio_bc"

# Generate input parameters file for MAS2BC
  source $ENLIL_DIR/aux/$amb2bc.in.sh

# Boundary conditions by MAS2BC
  $ENLIL_BIN/$amb2bc.$grd < $amb2bc.in

# Generate input parameters file for ENLIL
  setenv project null
  source $ENLIL_DIR/aux/enlil.in.csh

# Heliospheric computations by ENLIL
  $ENLIL_BIN/$enlil.$grd < $enlil.in

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