#!/usr/bin/env bash
# Ammended from txsmall (extra small 2 proc test)

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${script_dir}

if [ ! -d "${OPENGGCMDIR}" ]; then
  export OPENGGCMDIR=${script_dir}/../..
fi

has_git=$(which git &> /dev/null; echo "$?")
if [ "${has_git}" -eq 0 ]; then
  gitinfo="gitinfo.txt"
  echo "git status:" > ${gitinfo}
  echo "$(cd ${OPENGGCMDIR} && git status)" >> ${gitinfo}
  echo "" >> ${gitinfo}
  echo "git branch:" >> ${gitinfo}
  echo "$(cd ${OPENGGCMDIR} && git branch -v)" >> ${gitinfo}
  echo "" >> ${gitinfo}
  echo "git log:" >> ${gitinfo}
  echo "$(cd ${OPENGGCMDIR} && git log -n20)" >> ${gitinfo}
fi

if [ "`uname`" == "Darwin" ]; then
  export GGCM_TEST_TARGET="macbook"
else
  export GGCM_TEST_TARGET="local"
fi

$OPENGGCMDIR/bin/script.runme $(pwd) $(basename $0) 0; exit

#runstring testcase-const-southIMF-sm-ion

#------------- some top level options ----------------------------
RUN             default      #  run id, default sets to current dir
DOSMF           0            #  switch to create parameter database
DOINP           1            #  switch to create input file
DOGRD           1            #  switch to create the grid
KEEPTMP         0            #  switch to keep tmp files for debugging
TARGET          {$ENV{"GGCM_TEST_TARGET"}}
TARGETHOST      localhost
TUSER           kmaynard     #  user name on remote machine
RUNTIME         00:10:00     #  CPU limit, only for SDSC,NCSA
CLASS           normal       #  batch class (plat:standarf|capability)
MHDCOORD        MHD
MHDC            true  # DEPRECATED
MHD             fortran
DO_LIMIT2       false
DO_LIMIT3       false
DO_LEGACY       false
TIMELO          50.

#-------- this is a good place for libmrc options ----------------
checkpoint             -1 # uses outtime syntax (negative for cadence)
restart                 0
ggcm_mhd_diag_fields    rr:pp:v:b:j:e_cc:divb
assert_clean            false
class_info_verb         diff

#------------- compiling, profiling and debugging ----------------
# MPIF77          openmpif77
MPIF77_FLAGS    -g -O1
# MPIF90          openmpif90
MPIF90_FLAGS    -g -O1
# MPICC           openmpicc
MPICC_FLAGS     -g -O1
# CONF_ARGS       --enable-sse2
# TARGETPREP      {module load hdf5}
LOCALF77        gfortran         #  the local f77 compiler
check_mhdvar    false            #  check mhd variables for sane values every step
CHECKSUMS       false            #  write checksums to compare code changes

#------------- directories ---------------------------------------
GGCMDIR         default                  # base directory for the code
OUTDIR          default                  # where the output goes

#------------- the code input files ------------------------------
GLOBU           default      #  code input (utilities), default: latest
GRIDA           default      #  ditto, grid/x-grid generation
GRIDB           default      #  ditto, grid/partitioning
GRIDC           default      #  ditto, grid/mapping coefficients
MHDSC           default      #  ditto, constants and definitions
MHDCA           default                        #  ditto, MHD core code
MHDMI           default  #  ditto, MI coupling code/sigmas/CTIM interf.
IOSOL           default      #  ditto, ionosphere potential solver
IOPOS           default      #  ditto, ionosphere variables post-prpcessing
COTR1           default      #  ditto, coord. transf. and time routines
MACHS           default      #  ditto, machine dependent stuff
MINVA           default      #  ditto, minimum variance program
CTIM            none       #  ctim version (1.0.10) or "none" for sigaa2 sigma computation
#RCMCODE    rice

#-------------- define the grid ------------------------------------

#---------------------------------------------------------------
#------  grid definition for 'tail1'
#---------------------------------------------------------------
npx               1
npy               1
npz               2
nx                128
ny                64
nz                64
dy0               0.1
dz0               0.1
xx1              -30.
xx2              300.
yy2               50.
zz2               50.

ggcm_mhd_crds_gen_type fortran
ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
ggx2              $v="-x1  -24     -x3  -8.5     -dmm  3    -x5   50 "
ggx3              $v="-h0  12.0    -hn  100     -hm 3    -hmm 0.140625 "
ggx4              $v="-b1  0.28125     -b2  0.05   -b3  0.5 "

# ggcm_mhd_crds_gen_type mrc
# runmegen_mrc_crds 0
# crds_gen_x_type   ggcm_x_tanh
# ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
# ggx2              $v="-x1  -24     -x3  -8.5     -dmm  3    -x5   50 "
# ggx3              $v="-h0  12.0    -hn  100     -hm 3    -hmm 0.140625 "
# ggx4              $v="-b1  0.28125     -b2  0.05   -b3  0.5 "

# ggcm_mhd_crds_gen_type mrc
# runmegen_mrc_crds 0
# crds_gen_x_type   ggcm_x_cubic
# crds_gen_x_w0     1.0
# crds_gen_x_w1     150.0
# crds_gen_x_a1     4.0
# crds_gen_x_b1     400.0
# crds_gen_x_w2     2.0
# crds_gen_x_a2     -8.0
# crds_gen_x_b2     -30.0

crds_gen_y_type   ggcm_yz
crds_gen_z_type   ggcm_yz

#-------------- resistivity ----------------------------------------
MAGDIFFU        const          # resistivity model res1/nl1
diffthreshold   0.75           # resistivity threshold
diffconstant    1e2            # resistivity constant
d_i             0.0

#-------------- output control -------------------------------------
# ':' seperated lists, unit is seconds, +val is only that step, -val is modulus
diags           diagsc
diagsc_srv      cache
outputmode      xdmf_serial
hdf5_dir        default  # {{ $ENV{'HDF5_DIR'} }}
outtimerun      -1200000          # frequency for runtime graphics, 0 if not wanted
outtime2d       -1
outtimeio       -1
outtime3d       -1
outtimeex       1800:1080000:4
outplanex       10000          # none
outplaney       0
outplanez       10000          # none
modtty          1              # output line to log file every modtty
#etajout         true           # E on edge centers, B on face centers

#-------------- time step control ----------------------------------
RRMIN           0.10           # minimum permitted number density in cm**-3
SPEEDLIMIT      1500.0         # maximum permitted Alfven speed in km/s
thx             0.4           # cfl time step factor
modnewstep      50              # recalculate cfl limit every 'modnewstep' step
# modrestart      0       #DEPRECATED  # write restart every soso steps

#-------------- Times, Solar Wind / IMF ----------------------------
##.. UT times, use DIPOLTIME "1967:01:01:00:00:0.0" for generic runs with no dipole tilt
STARTTIME  1967:01:01:00:00:00.000  #UT when the run starts
ENDTIME    1967:01:01:00:00:03.000
DIPOLTIME  1967:01:01:00:00:00.000  # time for dipole orientation
alphafak   1.10                 # density factor to account for SW alphas
##
###...... automatic SW file generation (comment section out if not used)
SWMON      ac           # solar wind monitor sc (wi/ac/i8/ge/fi), use 'fi' if none
SWFILE     minvar       # file with SW/IMF, can be auto/minvar
SETIMFBX   none         #  set Bx to fixed value, or "none"
INPAVE     30           #  averaging interval for input files, seconds
IDATA      ./            # where the sw/imf data reside
##...... SW/IMF input by hand (comment section out if not used)
#SWMON      fi                    # solar wind monitor sc (wi/ac/i8/ge/fi), use 'fi' if none
##...  T(min)  bx by bz vx vy vz N(cc) P(pP) Nx Ny Nz
#  10 nT,  0 deg south
SWFILE   swdata

f107       150      # F10.7 solar flux
MOX        220.0    # solar wind monitor position (GSE)
MOY        0.00
MOZ        0.00
swturb1    false    # solar wind turbulence (true/false)
swturb_rr  0.0      # solar wind trbulence random perturbation for density in 1/cc
swturb_vv  0.0      # solar wind trbulence random perturbation for velocity in km/sec

#-------------- MI coupling and ionosphere -------------------------
ISPHERE       3.0       # inner boundary radius (RE)
io_shield_lat 50.0       # ionosphere shielding latitude
BND_IO_RR     1.0       # density at inner boundary in cc
BND_IO_TT     400       # temperature at inner bndry in eV
NTHETA        181       # ionosphere grid latitude points
NPHI          61        # ionosphere grid longitude points
NIOX          24        # no of panels in theta for one hemisphere
NIOY          6         # no of modes in phi
NIOGO         4         # order of gauss legendre integration
njslide       2         # fac sliding time averages
modiono       20        #DEPRECATED  # recalc ionosphere every soso step
sigmatrans    3000      # after which timestep begin transition to s-c sigma
sig_const     5.00
sigmafak      1.0       # factor to multiply all ionosphere conductances
mape1         1.0       # MI coupling factor for mapped E
fac_filt      2         # how often to spatially filter FAC
sig_floor     0.5       # minimum sigmas
fak_fac_dyn   1.0       # factor for dynamo currents (only w/ctim)
sig_smooth    2         # spatially smoothing sigmas
sig_h_back    0.3
sig_p_back    0.5       # nightside H/P background conductances
sigfac_fak    2.00      # fudge factor for discrete e-flux
sigdif_fak    2.00      # fudge factor for diffuse  e-flux

BIGDIM        20000000   # global memory

#-------------- CTIM inputs ----------------------------------------
ctim_potfak       0.6   # factor for driving ctim potential
#CTIM_IN           ./
CTIM_IN           /home/ggcm/ctim
ctim_f_prsxxxx    {"$CTIM_IN/inp_ctim.fields.20000921000.asc"}
ctim_f_mmmxxxx    {"$CTIM_IN/inp_ctim.mmm20000921000"}
ctim_f_velxxxx    {"$CTIM_IN/inp_ctim.vel20000921000"}
ctim_f_bmagfld    {"$CTIM_IN/inp_ctim.bmagfld"}
ctim_f_substorm   {"$CTIM_IN/inp_ctim.substorm"}
ctim_f_cormag     {"$CTIM_IN/inp_ctim.cormag"}
ctim_f_datam      {"$CTIM_IN/inp_ctim.datam"}
ctim_f_levpi      {"$CTIM_IN/inp_ctim.levpi"}
ctim_f_gwatts     {"$CTIM_IN/inp_ctim.gwatts"}
ctim_f_cpcpd      {"$CTIM_IN/inp_ctim.cpcpd"}
ctim_f_ionprof    {"$CTIM_IN/inp_ctim.ionprof"}
ctim_f_prof2      {"$CTIM_IN/inp_ctim.prof2"}
ctim_f_dmsp       {"$CTIM_IN/inp_ctim.dmsp"}
ctim_f_holt       {"$CTIM_IN/inp_ctim.holt"}
ctim_f_dmspmod    {"$CTIM_IN/inp_ctim.dmspmod"}
ctim_f_rice91     {"$CTIM_IN/inp_ctim.rice91"}
ctim_f_riceprof   {"$CTIM_IN/inp_ctim.riceprof"}
ctim_f_hprof      {"$CTIM_IN/inp_ctim.hprof"}
ctim_f_hough      {"$CTIM_IN/inp_ctim.hough"}
ctim_f_inshaun    {"$CTIM_IN/inp_ctim.d1d2"}
ctim_i10          5       # I10 is the smothing frequency.
ctim_i5           1       #  i5 is mwt calling frequency.
ctim_i8           6       #  i8 is shaun frequency.
ctim_windmx       1000.0  # maximum wind
ctim_tmpmin       130.0   # minimum temperature
ctim_ampl22       608.0   # amplitudes of the tidal model
ctim_ampl23       500.0
ctim_ampl24       138.0
ctim_ampl25       138.0
ctim_ampl11       200.0
ctim_phase22      9.6     #  phases of tidal model.
ctim_phase23      4.6
ctim_phase24      1.2
ctim_phase25      2.2
ctim_phase11      12.0
ctim_kp           3   #  kp index
ctim_xx           91  #  global setting???
ctim_amp          1.3 #  ratio of E foster field to real E field.
ctim_switch_1    default    #  ctim boolean switches
ctim_switch_2    default
ctim_switch_3    default
ctim_switch_4    default
ctim_switch_5    default
ctim_switch_6    default
ctim_switch_7    default
ctim_switch_8    default
ctim_switch_9    default
ctim_switch_10   default
ctim_switch_11   default
ctim_switch_12   default
ctim_switch_13   default
ctim_switch_14   default
ctim_switch_15   default
ctim_switch_16   default
ctim_switch_17   default
ctim_switch_18   default
ctim_switch_19   default
ctim_switch_20   default
ctim_switch_21   default
ctim_switch_22   default
ctim_switch_23   default
ctim_switch_24   default
ctim_switch_25   default
ctim_switch_26   default
ctim_switch_27   default
ctim_switch_28   default
ctim_switch_30   default
ctim_switch_31   default
ctim_switch_32   default
ctim_switch_33   default
ctim_switch_34   default
ctim_switch_35   default
ctim_switch_37   default
#-------------------------- The End ------------------------------------

SATOUT          default      #  /home/ggcm/GGCM/OpenGGCM_v3.0/src/mhd-satout.for
orbitfile       orbits.txt
orbit_dt        5

