#!/bin/csh
if ( ! $?OPENGGCMDIR ) then
  setenv OPENGGCMDIR $HOME/git/openggcm
endif
$OPENGGCMDIR/bin/script.runme `pwd` `basename $0` 0; exit
#....... template
#--------------------------------------------------------------
#  This is the magic file that makes global MHD runs happen.
#  Don't change the first two lines -- they do the magic.
#  Everything below here is input to the model; obviously,
#  lines that start with a '#' are comments and blank lines
#  are ignored.
#  Unified input -- JR, IGPP/UCLA  12/28/2000
#--------------------------------------------------------------

#runstring case-2000.11.06-ppulse-initial

#------------- some top level options ----------------------------
RUN             default      #  run id, default sets to current dir
DOSMF           1            #  switch to create parameter database
DOINP           1            #  switch to create input file
DOGRD           1            #  switch to create the grid
KEEPTMP         1            #  switch to keep tmp files for debugging
TARGET          local #zaphod-myri     #  prepare run for which machine? (UCLA-PBS,SDSC-SP2,NCSA-titan)
TARGETHOST      localhost
#TUSER           jraeder      #  user name on remote machine
RUNTIME         20:20        #  CPU limit, only for SDSC,NCSA
CLASS           long         #  batch class (plat:standarf|capability)
PRECISION       single
MHDCOORD        MHD

#------------- compiling, profiling and debugging ----------------

##### Use this for zaphod
#MPIF90_FLAGS    -g -fast
#MPIF77_FLAGS    -g -fast -Msave            #  options for compilaton #-g -v -O -fast -Msave -Wl -Bstatic -Mextend #-Mextend -fast -v
#LOCALF77        pgf77           #  the local f77 compiler

##### Use this on local machines
MPIF77_FLAGS    -g -fast         #  for PGI
LOCALF77        pgf77            #  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          ./target/ #default                  # where the output goes

#------------- the code input files ------------------------------
CONF_ARGS       { --enable-sse2 }
MHDC            false         #  true will turn on the r.h.s.  calculation in C.
MHD             c-test       # cgen (128*64*64), c-test
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
SATOUT          default      #   /home/jraeder/GGCM/OpenGGCM/src/mhd-satout.for
COTR1           default      #  ditto, coord. transf. and time routines
MACHS           default      #  ditto, machine dependent stuff
MINVA           default      #  ditto, minimum variance program
CTIM            none #1.0.10      #  ctim version (1.0.10) or "none" for sigaa2 sigma computation
RCMCODE         crcm         #  Ring Current Model implementation (options: none, rice, crcm)


#-------------- define the grid ------------------------------------
# ------ test coarse grid
npx               5
npy               2
npz               2 
nx                330   #522           #  number of cells in x
ny                150            #  number of cells in y
nz                150            #  number of cells in z
dy0               0.15           #  minimum cell size in y
dz0               0.15           #  minimum cell size in z
xx1               -24.01        #  sunward extension of box
xx2               650.01        #  anti-sunward extension of box 350.01 ! try 600
yy2               160.01         #  box size in +-y
zz2               160.01         #  box size in +-z

# high-resolution close to Earth
ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
ggx2              $v="-x1  -20     -x3 0.00     -dmm  16   -x5  030 "  
ggx3              $v="-h0  2.0     -hn    5     -hm 0.3    -hmm 0.30 "   
ggx4              $v="-b1  0.15    -b2  0.075   -b3  0.3 "

#(MCNG) medium resolution, no specific region emphasis - only the ggx part
#ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
#ggx2              $v="-x1  -26     -x3   40     -dmm  16   -x5  120 "    
#ggx3              $v="-h0  1.0     -hn    5     -hm 0.6    -hmm 0.60 "
#ggx4              $v="-b1  0.15    -b2  0.025   -b3  0.3 "


#---------------------------------------------------------------
#------  grid definition for 'substorm 
#---------------------------------------------------------------
#npx               5             #  number of processors in x
#npy               1             #  number of processors in y
#npz               1             #  number of processors in z
#nx                630           #  number of cells in x
#ny                200           #  number of cells in y
#nz                300           #  number of cells in z
#dy0               0.25          #  minimum cell size in y
#dz0               0.16          #  minimum cell size in z
#xx1               -20.01        #  sunward extension of box
#xx2               500.01        #  anti-sunward extension of box
#yy2               36.01         #  box size in +-y
#zz2               36.01         #  box size in +-z
##.... how the x-grid is defined
##     f = fak*(hm + (h0-hm)*tanhm(b1*(x-x1)) + (hn-hm)*tanhp(b2*(x-x5))
##    *  - (hm-hmm)*(#one-tanhm(b3*(x-(x3-dmm)))-tanhp(b3*(x-(x3+dmm)))) )
##ggx1              $v="-n  $NX  -x0 $XX1  -xn $XX2 "    #  definition and constants for x-grid
##ggx2              $v="-x1  -26  -x3  -4  -dmm  8 -x5   50 "
##ggx3              $v="-h0  2.0  -hn  43  -hm 1.7  -hmm 0.35 "
##ggx4              $v="-b1  0.15 -b2 0.025  -b3  0.3 "
##.... for tail:
##ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
##ggx2              $v="-x1  -26     -x3   40     -dmm  16    -x5   120 "
##ggx3              $v="-h0  1.0     -hn   5      -hm 0.60   -hmm 0.60 "
##ggx4              $v="-b1  0.15    -b2  0.025   -b3  0.3 "
##.... for substorm:
#ggx1              $v="-n   $NX     -x0 $XX1     -xn $XX2 "
#ggx2              $v="-x1  -26     -x3   -10     -dmm  8    -x5   80 "
#ggx3              $v="-h0  2.0     -hn   43      -hm 1.0   -hmm 1.00 "
#ggx4              $v="-b1  0.15    -b2  0.100   -b3  0.3 "
#-------------- resistivity ----------------------------------------
MAGDIFFU        nl1            # resistivity model res1/nl1
diffthreshold   0.75           # resistivity threshold
diffconstant    0.01           # resistivity constant  

#-------------- output control -------------------------------------
# ':' seperated lists, unit is seconds, +val is only that step, -val is modulus
outputmode      combined       # single/combined (use single only for jobs with many procs on SP2)
outtimerun      -1200000          # frequency for runtime graphics, 0 if not wanted
outtime2d       -60
outtimeio       -60
outtime3d       -60
outtimeex       1080000:1080000:60
outplanex       7                      # output plane location in RE
outplaney       0
outplanez       -4:0
etajout         true
ORBITFILE       orbits.txt
orbit_dt        10
modtty          1              # output line to log file every modtty

#-------------- 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.40           # cfl time step factor
modnewstep      10              # recalculate cfl limit every 'modnewstep' step

#-------------- Times, Solar Wind / IMF ----------------------------
##.. UT times, use DIPOLTIME "1967:01:01:00:00:0.0" for generic runs with no dipole tilt
STARTTIME  2009:07:22:00:10:0.000    # UT when the run starts
ENDTIME    2009:07:23:23:50:0.000
DIPOLTIME  2009:07:22:12:00:0.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   0.1         #  set Bx to fixed value, or "none"
INPAVE     30           #  averaging interval for input files, seconds
IDATA      ./event-data            # where the sw/imf data reside
#f107       {`tser_getval $IDATA/noaa.f107 $DIPOLTIME | awk '{printf "%s",\$1;}' `}
#MOX        {`tser_getval $IDATA/${SWMON}.xgse $DIPOLTIME | awk '{printf "%s",\$1;}' `}
#MOY        {`tser_getval $IDATA/${SWMON}.ygse $DIPOLTIME | awk '{printf "%s",\$1;}' `}
#MOZ        {`tser_getval $IDATA/${SWMON}.zgse $DIPOLTIME | awk '{printf "%s",\$1;}' `}
#
##...... 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
#beginfile ./swdata
#  -999.0     0.00   0.00    -10.000  -450.00   0.00    0.00    6.00   6.00  -1 0 0
#    40.0     0.00  7.0711   -7.0711  -450.00   0.00    0.00    6.00   6.00  -1 0 0
#   120.0     0.00  7.0711   -7.0711  -450.00   0.00    0.00    6.00   6.00  -1 0 0
#   999.0     0.00  7.0711   -7.0711  -450.00   0.00    0.00    6.00   6.00  -1 0 0
#endfile

f107       68.0      # F10.7 solar flux
MOX        232.00    # solar wind monitor position (GSE)
MOY        38.00
MOZ        17.80 
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       2.5       # inner boundary radius (RE)
io_shield_lat 54        # 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        361       # ionosphere grid latitude points
NPHI          121       # ionosphere grid longitude points
NIOX          40        # no of panels in theta for one hemisphere
NIOY          8         # no of modes in phi
NIOGO         4         # order of gauss legendre integration
njslide       2         # fac sliding time averages
modiono       20        # recalc ionosphere every soso step
sigmatrans    30000000  # after which timestep begin transition to s-c sigma
sig_const     4.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        370000000   # global memory

#---------------------------------------------------------------
#---- Comprehensive Ring Current Model (CRCM) specific inputs --
#---------------------------------------------------------------
crcm_species                   2       # 1=electrons; 2=protons
crcm_time_init_cond     172800.0       # [sec] until that time artificial potential Volland-Stern will be used (or mixed - see crcm_mixed_potential)
crcm_start_time              0.0       # [sec] when to actually start CRCM (no need to change it)
crcm_delta_t               120.0       # [sec] how often to call CRCM
crcm_write_time              1.0       # [sec] the time interval defined approximately as (crcm_write_time) x (crcm_delta_t) at which to write down the CRCM flux, etc...
crcm_iono                  120.0       # [km] ionosphere in km in CRCM
crcm_pp_rr_feedback          yes       # {yes,no} pressure and density feedback
crcm_fb_kickin_time        300.0       # [sec] at this time feedback starts to kick in in case crcm_pp_rr_feedback=yes
# --- at least one of the two 'make_new_fac' options should be 'no'. Otherwise the 'rc' option will simply add/overwrite
crcm_make_new_fac_w_pc       yes       # {yes,no} FAC feedback overwrite MHD FAC with MHD integrated parallel FAC
crcm_make_new_fac_w_rc        no       # {yes,no} FAC feedback overwrite MHD FAC with CRCM FAC if CRCM FAC is not zero
crcm_new_fac_smooth            2       # [integer] average the new FAC (CRCM's/integrated + MHD's) over this number of grid cells - basic smoothing. Zero does nothing.
crcm_intgrd_fac_smooth         4       # [integer] average the integrated parallel FAC over this number of grid cells - basic smoothing. Matters if crcm_make_new_fac_pc=yes
crcm_crcm_fac_smooth           4       # [integer] average the CRCM FAC over this number of grid cells - basic smoothing. Matters if crcm_make_new_fac_rc=yes
crcm_mixed_potential         yes       # {yes,no} create mixed half MHD half VS potential for the specified crcm_time_init_cond (> 0)
crcm_mixed_pot_factor        1.0       # factor multiplier for the mixed potential (if yes)
crcm_lowbndry_condition      yes       # set lower boundary density, temperature, potential for CRCM
crcm_fac_lowbnd_lat         54.0       # [deg] lower boundary condition latitude if crcm_lowbndry_condition is yes
crcm_makefac_lowbnd_lat     63.0       # [deg] lower boundary condition (merging FACs control) latitude if crcm_lowbndry_condition is yes
crcm_null_isphere_vars       yes       # set CRCM feedback pressure and density zero inside ISPHERE (otherwise stability issues?)
# --- Factoring of the Input/Output stuff for CRCM and MHD------
crcm_mhd_pot_factor          1.0       # factor the mhd potential before input in crcm if wanted
crcm_mhd_dens_factor         1.0       # factor the mhd density before input in crcm if wanted
crcm_mhd_temp_factor         1.0       # factor the mhd temperature before input in crcm if wanted
crcm_to_mhd_pres_factor      1.0       # factor the crcm pressure before feedback in mhd if wanted
crcm_to_mhd_dens_factor      1.0       # factor the crcm density before feedback in mhd if wanted
crcm_pp_rr_scale_length      0.5       # [RE] scale the pressure and density from 0 at ishpere to 1 at isphere+crcm_pp_rr_scale_length with a sin^2 to reduce the gradient jump before passing them to the MHD grid
crcm_pp_out_smooth             0       # [integer] smooth CRCM output pressure before passing it to the MHD grid. No smoothing if zero
crcm_rr_out_smooth             0       # [integer] smooth CRCM output density before passing it to the MHD grid. No smoothing if zero
# --- Field-line tracer stuff for CRCM -------------------------
crcm_max_lat_grid_limit   69.458       # [degrees] max latutide on the crcm ionosphere grid - 69.458 degrees is default - do not go less that that. Go only higher than that.
crcm_rflmax               1000.0       # [RE] max allowed field line length
crcm_rmax                    7.0       # [RE] field line is considered open if farther than this - this basically controls how far is the outer CRCM boudary in the equatorial plane
crcm_rmin_dip_mhd_blend      2.5       # [RE] lower boundary for dipole-mhd blend - below this is only dipole
crcm_rmax_dip_mhd_blend      8.0       # [RE] upper boundary for dipole-mhd blend - beyond this is only mhd
# --- the next two (new) variables are for CTIM, but we have put them here, because their values affect CRCM - CRCM and CTIM have a conflict running together depending on their respective start times and delta_times (AEV). The new variables are used in mhd-misig.for
ctim_start_time            300.0       # [seconds] CTIM start time
ctim_delta_t                20.0       # [seconds] CTIM calling frequency
# --- debug
crcm_debug                    no       # [yes,no] write more output for debug
# --- bruteforce workaround for dtmin errors
dtmin                  0.0000002       # [sec] change the default dtmin in mhd-corea.for in case dtmin goes below 0.0002 and the run crashes - hopefully this will help the code the "hop over" the "bad" CFL condition

#-------------- CTIM inputs ----------------------------------------
ctim_potfak       0.6   # factor for driving ctim potential
CTIM_IN           ctim-indata
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

#---------------------------------------------------------------
#--------- Rice Convection Model (RCM) specific inputs ---------
#---------------------------------------------------------------

rcm_iono                  120.0       # [km] ionosphere in km in RCM
rcm_idt1                  120.0       # [sec] how often to call RCM
rcm_idt2                  120.0       # [sec] what is this
rcm_idt3                   60.0       # [sec] what is this

rcm_pp_rr_feedback          yes       # {yes,no} pressure and density feedback
rcm_fb_kickin_time        300.0       # [sec] at this time feedback starts to kick in
rcm_null_isphere_vars       yes       # set RCM feedback pressure and density zero inside ISPHERE (otherwise stability issues?)
rcm_make_new_fac             no       # RCM birk variable is crap 'yes' not working. {yes,no} FAC feedback overwrite MHD FAC with RCM FAC if RCM FAC is not zero

# --- Field-line tracer stuff for RCM -------------------------
rcm_rflmax               1000.0       # [RE] max allowed field line length
rcm_rmax                   20.0       # [RE] field line is considered open if farther than this
rcm_rmin_dip_mhd_blend      2.5       # [RE] lower boundary for dipole-mhd blend - below this is only dipole
rcm_rmax_dip_mhd_blend      7.0       # [RE] upper boundary for dipole-mhd blend - beyond this is only mhd
# --- debug
rcm_debug                 false

# -------------------------the end----------------

