Index: branches/eam_branches/ipp-20230313/tools/eam/phosim/dvo.sh
===================================================================
--- branches/eam_branches/ipp-20230313/tools/eam/phosim/dvo.sh	(revision 42689)
+++ branches/eam_branches/ipp-20230313/tools/eam/phosim/dvo.sh	(revision 42689)
@@ -0,0 +1,310 @@
+
+macro load.Biprism.field.defocus
+
+  # 3 images:
+  # out/Biprism.focus.v3.01/Biprism.focus.v3.02_a_F02_f0_ch00_ch1_E000.fits : Mz = 2249.19
+  # out/Biprism.focus.v3.02/Biprism.focus.v3.03_a_F03_f0_ch00_ch1_E000.fits : Mz = 2249.24
+  # out/Biprism.focus.v3.03/Biprism.focus.v3.04_a_F04_f0_ch00_ch1_E000.fits : Mz = 2249.29
+
+  # rd i1 out/Biprism.focus.v3.02/Biprism.focus.v3.02_a_F02_f0_ch00_ch1_E000.fits
+  # rd i2 out/Biprism.focus.v3.03/Biprism.focus.v3.03_a_F03_f0_ch00_ch1_E000.fits
+  # rd i3 out/Biprism.focus.v3.04/Biprism.focus.v3.04_a_F04_f0_ch00_ch1_E000.fits
+
+  rd i1 out/Biprism.focus.v4.04/Biprism.focus.v4.04_a_F04_f0_ch00_ch1_E000.fits
+  rd i2 out/Biprism.focus.v4.05/Biprism.focus.v4.05_a_F05_f0_ch00_ch1_E000.fits
+  rd i3 out/Biprism.focus.v4.06/Biprism.focus.v4.06_a_F06_f0_ch00_ch1_E000.fits
+
+  for i 1 4
+    set li$i = log(i$i)
+  end
+end
+
+macro show.Biprism.field.defocus
+
+  dev -n tv
+  clear -s
+  section default -imtool none
+  resize {3*700+20} {3*400+20}
+
+  # focus.v4:
+  #  757 4144 -- -15 arcmin 
+  # 4244 4144
+  # 5642 4144 -- +6 arcmin (M2tilt moves images off FOV)
+
+  # focus.v3:
+  #  727 4143
+  # 4215 4143
+  # 7006 4143
+
+  section a00 0.000 0.000 0.333 0.333; section a00 -imtool none; tv li1 2.95 0.5; center  757 4144 6
+  section a10 0.333 0.000 0.333 0.333; section a10 -imtool none; tv li1 2.95 0.5; center 4244 4144 6
+  section a20 0.666 0.000 0.333 0.333; section a20 -imtool none; tv li1 2.95 0.5; center 5642 4144 6
+				   	     		    
+  section a01 0.000 0.333 0.333 0.333; section a01 -imtool none; tv li2 2.95 0.5; center  757 4144 6
+  section a11 0.333 0.333 0.333 0.333; section a11 -imtool none; tv li2 2.95 0.5; center 4244 4144 6
+  section a21 0.666 0.333 0.333 0.333; section a21 -imtool none; tv li2 2.95 0.5; center 5642 4144 6
+				   	     		    
+  section a02 0.000 0.666 0.333 0.333; section a02 -imtool none; tv li3 2.95 0.5; center  757 4144 6
+  section a12 0.333 0.666 0.333 0.333; section a12 -imtool none; tv li3 2.95 0.5; center 4244 4144 6
+  section a22 0.666 0.666 0.333 0.333; section a22 -imtool none; tv li3 2.95 0.5; center 5642 4144 6
+end
+
+macro load.LASF9.field.defocus
+
+  # 3 images:
+  # out/LASF9.focus.v3.v03/LASF9.focus.v3.v03_a_F03_f0_ch00_ch1_E000.fits : Mz = 2248.50
+  # out/LASF9.focus.v3.v04/LASF9.focus.v3.v04_a_F04_f0_ch00_ch1_E000.fits : Mz = 2248.55
+  # out/LASF9.focus.v3.v05/LASF9.focus.v3.v05_a_F05_f0_ch00_ch1_E000.fits : Mz = 2248.60
+
+  rd i1 out/LASF9.focus.v3.v03/LASF9.focus.v3.v03_a_F03_f0_ch00_ch1_E000.fits
+  rd i2 out/LASF9.focus.v3.v04/LASF9.focus.v3.v04_a_F04_f0_ch00_ch1_E000.fits
+  rd i3 out/LASF9.focus.v3.v05/LASF9.focus.v3.v05_a_F05_f0_ch00_ch1_E000.fits
+
+  for i 1 4
+    set li$i = log(i$i)
+  end
+end
+
+macro show.LASF9.field.defocus
+
+  dev -n tv
+  clear -s
+  section default -imtool none
+  resize {3*700+20} {3*400+20}
+
+  section a00 0.000 0.000 0.333 0.333; section a00 -imtool none; tv li1 2.95 0.5; center  665 4143 6
+  section a10 0.333 0.000 0.333 0.333; section a10 -imtool none; tv li1 2.95 0.5; center 4154 4143 6
+  section a20 0.666 0.000 0.333 0.333; section a20 -imtool none; tv li1 2.95 0.5; center 6947 4143 6
+				   	     		    
+  section a01 0.000 0.333 0.333 0.333; section a01 -imtool none; tv li2 2.95 0.5; center  665 4143 6
+  section a11 0.333 0.333 0.333 0.333; section a11 -imtool none; tv li2 2.95 0.5; center 4154 4143 6
+  section a21 0.666 0.333 0.333 0.333; section a21 -imtool none; tv li2 2.95 0.5; center 6947 4143 6
+				   	     		    
+  section a02 0.000 0.666 0.333 0.333; section a02 -imtool none; tv li3 2.95 0.5; center  665 4143 6
+  section a12 0.333 0.666 0.333 0.333; section a12 -imtool none; tv li3 2.95 0.5; center 4154 4143 6
+  section a22 0.666 0.666 0.333 0.333; section a22 -imtool none; tv li3 2.95 0.5; center 6947 4143 6
+end
+
+macro show.image
+  if ($0 != 2)
+    echo "USAGE: show.image (filename)"
+    break
+  end
+
+  dev -n sky
+  region 0 0 0.5
+  imbox -c blue -lw 2 $1
+
+  dev -n tv
+  rd im $1
+  tv im 900 500
+end
+
+macro make.filter
+  if ($0 != 4)
+    echo "USAGE: make.filter (output) (Wo) (dW)"
+    break
+  end
+
+  local Wmin Wmax
+  $Wmin = $2 - 0.5*$3
+  $Wmax = $2 + 0.5*$3
+
+  create w 0.2 1.0 0.001
+  set t = zero(w) + 1.0*((w > $Wmin) && (w < $Wmax))
+  set r = 1.0 - t
+  set a = zero(w)
+
+  write $1 a w t r
+end
+
+macro make.3band.filter
+  if ($0 != 2)
+    echo "USAGE: make.3band.filter (output)"
+    break
+  end
+
+  local Wmin Wmax
+  $W1min = 0.400
+  $W1max = 0.450
+  $W2min = 0.550
+  $W2max = 0.600
+  $W3min = 0.700
+  $W3max = 0.750
+
+  create w 0.2 1.0 0.001
+  set t = zero(w) + 1.0*((w > $W1min) && (w < $W1max)) + 1.0*((w > $W2min) && (w < $W2max)) + 1.0*((w > $W3min) && (w < $W3max))
+  set r = 1.0 - t
+  set a = zero(w)
+
+  write $1 a w t r
+end
+
+macro make.4band.filter
+  if ($0 != 2)
+    echo "USAGE: make.4band.filter (output)"
+    break
+  end
+
+  local Wmin Wmax
+  $W0min = 0.400
+  $W0max = 0.420
+  $W1min = 0.440
+  $W1max = 0.460
+  $W2min = 0.550
+  $W2max = 0.600
+  $W3min = 0.700
+  $W3max = 0.750
+
+  create w 0.2 1.0 0.001
+  set f0 = ((w > $W0min) && (w < $W0max))
+  set f1 = ((w > $W1min) && (w < $W1max))
+  set f2 = ((w > $W2min) && (w < $W2max))
+  set f3 = ((w > $W3min) && (w < $W3max))
+  set t = zero(w) + f0 + f1 + f2 + f3
+  set r = 1.0 - t
+  set a = zero(w)
+
+  write $1 a w t r
+end
+
+macro make.comb.filter
+  if ($0 != 2)
+    echo "USAGE: make.comb.filter (output)"
+    break
+  end
+
+  create w 0.2 1.01 0.0001
+
+  set t = zero(w)
+  for Wmin 0.30 1.01 0.10 -incl
+    set df = (w > $Wmin) && (w < $Wmin + 0.002)
+    set t = t + df
+  end
+  set r = 1.0 - t
+  set a = zero(w)
+
+  write $1 a w t r
+end
+
+macro get.comb
+ if ($0 != 2)
+  echo "USAGE: get.comb (dlambda)"
+  break
+ end
+
+ local dW
+ $dW = $1
+
+ # buffers are named i$dW 
+
+ $Fthresh = 15000
+
+ cut i$dW xc fc x 4070 4136 250 15
+
+ lim -n gr xc fc; clear; box; plot -x hist xc fc
+ line -c blue 4000 $Fthresh to 6000 $Fthresh
+
+ vpeaks fc xp_raw fp $Fthresh
+ set xp = xp_raw + xc[0]
+
+ plot -c red -pt ocir xp fp
+
+ set wp = 300 + $dW*ramp(xp) 
+
+ lim -n gw xp wp; clear; box; plot -pt cir -sz 2 -c red xp wp
+
+ # the first peak is the same wavelength for all
+ # there may be shifts, but all should have the same dispersion
+ set xp$dW = xp - xp[0]
+ set wp$dW = wp
+end
+
+macro get.disp
+
+  if (0)
+    get.comb 20
+    get.comb 50
+    get.comb 100
+  end
+
+  lim -n gw xp100 wp100; clear; box;
+  plot -pt cir -sz 2 -op 0.4 -c blue xp20 wp20
+  plot -pt cir -sz 2 -op 0.4 -c indigo xp50 wp50 
+  plot -pt cir -sz 2 -op 0.4 -c red xp100 wp100
+
+  subset xp20s = xp20 where (xp20 < 90)
+  subset wp20s = wp20 where (xp20 < 90)
+
+  subset xp50s = xp50 where (xp50 < 190)
+  subset wp50s = wp50 where (xp50 < 190)
+
+  delete -q xp_all wp_all
+  
+  concat xp20s xp_all
+  concat xp50s xp_all
+  concat xp100 xp_all
+
+  concat wp20s wp_all
+  concat wp50s wp_all
+  concat wp100 wp_all
+
+  plot -pt plus -c black -sz 2 xp_all wp_all
+
+  spline create disp xp_all wp_all
+  create xr 0 212
+  spline apply disp xr wr
+  plot -x line -c black xr wr
+
+  set wr_p = wr
+  set xr_p = xr
+  vroll wr_p
+  vroll xr_p
+  set dw = wr_p - wr
+  set dx = xr_p - xr
+  
+  set R = wr / (4 * dw / dx)
+end
+
+macro load.comb
+
+  rd i20 out/Biprism.comb.t1/Biprism.comb.t1_a_F05_f0_ch00_ch1_E000.fits
+  rd i50 out/Biprism.comb.t2/Biprism.comb.t2_a_F05_f0_ch00_ch1_E000.fits 
+  rd i100 out/Biprism.comb.t3/Biprism.comb.t3_a_F05_f0_ch00_ch1_E000.fits 
+
+  stat -q i20;   i20[4115][4139] = $MEDIAN
+  stat -q i50;   i50[4115][4139] = $MEDIAN
+  stat -q i100; i100[4115][4139] = $MEDIAN
+end
+
+# clean steps would be:
+# 300 -  400 :  20nm
+# 400 -  600 :  50nm
+# 600 - 1000 : 100nm
+
+macro make.newcomb.filter
+  if ($0 != 2)
+    echo "USAGE: make.newcomb.filter (output)"
+    break
+  end
+
+  create w 0.2 1.01 0.0001
+
+  set t = zero(w)
+  for Wmin 0.30 0.40 0.02 -incl
+    set df = (w > $Wmin) && (w < $Wmin + 0.002)
+    set t = t + df
+  end
+  for Wmin 0.45 0.65 0.05 -incl
+    set df = (w > $Wmin) && (w < $Wmin + 0.002)
+    set t = t + df
+  end
+  for Wmin 0.70 1.01 0.10 -incl
+    set df = (w > $Wmin) && (w < $Wmin + 0.002)
+    set t = t + df
+  end
+  set r = 1.0 - t
+  set a = zero(w)
+
+  write $1 a w t r
+end
Index: branches/eam_branches/ipp-20230313/tools/eam/phosim/run.phosim
===================================================================
--- branches/eam_branches/ipp-20230313/tools/eam/phosim/run.phosim	(revision 42689)
+++ branches/eam_branches/ipp-20230313/tools/eam/phosim/run.phosim	(revision 42689)
@@ -0,0 +1,90 @@
+#!/bin/csh
+
+psconfig phosim
+
+set obsinst = instance-grid
+
+if ($#argv != 15) then
+  echo "USAGE: run.phosim (outdir) (obsid) (inst) (M2a-z) (L1a-z) (F2coat) (F2material) (F2aTilt) (F2bTilt) (F3coat) (F3material) (F3aTilt) (F3bTilt) (M2tip) (M2tilt)"
+  exit 2
+endif
+  
+set outdir = $1
+set obsid  = $2
+set instr  = $3
+
+set Mz     = $4
+set Lz     = $5
+
+set F2c    = $6	
+set F2m    = $7	
+set F2aT   = $8	
+set F2bT   = $9	
+set F3c    = $10
+set F3m    = $11
+set F3aT   = $12
+set F3bT   = $13
+set M2Tip  = $14
+set M2Tilt = $15
+
+if (-e $outdir) then
+  echo "ERROR: $outdir exists, exiting"
+  exit 2
+endif
+
+mkdir -p $outdir
+rsync -auv data/pan-base/ $outdir/
+
+set camdir = `basename $outdir`
+ln -s `pwd`/$outdir data/$camdir
+
+echo "obsid $obsid" >> $outdir/$obsinst
+
+rm -f $outdir/focalplanelayout.txt
+rm -f $outdir/segmentation.txt
+
+ln -s focalplanelayout.$instr.txt $outdir/focalplanelayout.txt
+ln -s segmentation.$instr.txt $outdir/segmentation.txt
+
+cat $outdir/optics_raw.txt | sed s/@Mz@/$Mz/ | sed s/@Lz@/$Lz/ | sed s/@F2coat@/$F2c/ | sed s/@F3coat@/$F3c/ | sed s/@F2mat@/$F2m/ | sed s/@F3mat@/$F3m/ > $outdir/optics_0.txt
+
+rm -f $outdir/perturbation.txt
+set dF2aT = `echo "($F2aT   > 0.00001) || ($F2aT   < -0.00001)" | bc`
+set dF2bT = `echo "($F2bT   > 0.00001) || ($F2bT   < -0.00001)" | bc`
+set dF3aT = `echo "($F3aT   > 0.00001) || ($F3aT   < -0.00001)" | bc`
+set dF3bT = `echo "($F3bT   > 0.00001) || ($F3bT   < -0.00001)" | bc`
+set dM2Tx = `echo "($M2Tip  > 0.00001) || ($M2Tip  < -0.00001)" | bc`
+set dM2Ty = `echo "($M2Tilt > 0.00001) || ($M2Tilt < -0.00001)" | bc`
+
+if ($dM2Tx) then
+  grep M2_tip $outdir/perturbation_raw.txt | sed s/@M2Tip@/$M2Tip/ >> $outdir/perturbation.txt
+endif
+if ($dM2Ty) then
+  grep M2_tilt $outdir/perturbation_raw.txt | sed s/@M2Tilt@/$M2Tilt/ >> $outdir/perturbation.txt
+endif
+if ($dF2aT) then
+  grep prism_F2a $outdir/perturbation_raw.txt | sed s/@F2aTilt@/$F2aT/ >> $outdir/perturbation.txt
+endif
+if ($dF2bT) then
+  grep prism_F2b $outdir/perturbation_raw.txt | sed s/@F2bTilt@/$F2bT/ >> $outdir/perturbation.txt
+endif
+if ($dF3aT) then
+  grep prism_F3a $outdir/perturbation_raw.txt | sed s/@F3aTilt@/$F3aT/ >> $outdir/perturbation.txt
+endif
+if ($dF3bT) then
+  grep prism_F3b $outdir/perturbation_raw.txt | sed s/@F3bTilt@/$F3bT/ >> $outdir/perturbation.txt
+endif
+
+echo $obsid $Mz $Lz $F2c $F2m $F2aT $F2bT $F3c $F3m $F3aT $F3bT > $outdir/params.txt
+
+if (0) then
+  echo ./phosim $outdir/$obsinst -c $outdir/noseeing -i $camdir -o $outdir > $outdir/phosim.log
+  ./phosim $outdir/$obsinst -c $outdir/noseeing -i $camdir -o $outdir >>& $outdir/phosim.log
+else 
+  echo ./phosim $outdir/$obsinst -c $outdir/quickbck-noseeing -i $camdir -o $outdir > $outdir/phosim.log
+  ./phosim $outdir/$obsinst -c $outdir/quickbck-noseeing -i $camdir -o $outdir >>& $outdir/phosim.log
+endif
+
+gunzip $outdir/*_a_*.gz
+rm $outdir/*_e_*.gz
+rm data/$camdir
Index: branches/eam_branches/ipp-20230313/tools/eam/phosim/run.sequence.sh
===================================================================
--- branches/eam_branches/ipp-20230313/tools/eam/phosim/run.sequence.sh	(revision 42689)
+++ branches/eam_branches/ipp-20230313/tools/eam/phosim/run.sequence.sh	(revision 42689)
@@ -0,0 +1,372 @@
+#!/usr/bin/env mana
+
+$RUN_SCRIPT = focus.Biprism.v4
+
+# the M2 tilt sequence seems to be best for a tilt of 0.002 rad
+# now I want to scan the focus around that tilt
+macro focus.Biprism.v4
+
+ $tilt = 0.05
+ $M2tilt = 0.002
+
+ $dz = 0.01
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $i = 0
+ for noff -5 5 1 -incl
+    $Mz = $Mo + $noff*$dz
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Biprism.focus.v4.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid 8k $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0 0.0 $M2tilt
+    exec ./run.phosim $outdir $obsid 8k $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0 0.0 $M2tilt
+    $i ++
+  end
+end
+
+# difficult to judge the best focus
+# highest central core: 2249.24
+macro M2tilt.Biprism.v1
+
+ # prism wedge angle:
+ $tilt = 0.05
+
+ $dz = 0.05
+
+ # the best focus for the biprism is $Mo = 2249.24
+
+ # run a sequence with 0.5 mm of defocus:
+ $Mo = 2249.74
+ $dLM = 66.816
+
+ $i = 0
+ $dM2 = 0.001
+ for M2tilt 0.0 0.010 $dM2
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Biprism.M2tilt.v1.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid 8k $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0 0.0 $M2tilt 
+    exec ./run.phosim $outdir $obsid 8k $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0 0.0 $M2tilt
+    $i ++
+  end
+end
+
+# difficult to judge the best focus
+# highest central core: 2249.24
+macro focus.Biprism.v3
+
+ $tilt = 0.05
+
+ $dz = 0.05
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $i = 0
+ for noff -3 3 1 -incl
+    $Mz = $Mo + $noff*$dz
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Biprism.focus.v3.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro focus.LASF9.v3
+
+ $tilt = 0.02
+ $dz = 0.01
+ $Mo = 2248.60
+ $dLM = 66.816
+
+ $i = 31
+ for noff -4 5 1 -incl
+    $Mz = $Mo + $noff*$dz
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/LASF9.focus.v3.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.4band.txt LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.4band.txt LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro focus.LASF9.v2
+
+ $tilt = 0.05
+ $dz = 0.05
+ $Mo = 2248.5
+ $dLM = 66.816
+
+ for n 0 10
+    $Mz = $Mo + $n*$dz
+    $Lz = $dLM - $Mz
+
+    $i = $n + 20
+    sprintf outdir out/LASF9.focus.v2.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.4band.txt LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.4band.txt LASF9.txt $tilt 0.0
+  end
+end
+
+# best was: 2249.24
+macro disp.Biprism.v2
+
+ $tilt = 0.05
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $Mz = $Mo
+ $Lz = $dLM - $Mz
+
+ echo ./run.phosim out/Biprism.v2.4band.v00 F01 $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+ exec ./run.phosim out/Biprism.v2.4band.v00 F01 $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+end
+
+# difficult to judge the best focus
+# highest central core: 2249.24
+macro focus.Biprism.v2
+
+ $tilt = 0.05
+
+ $dz = 0.01
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $i = 30
+ for zoff -0.05 +0.05 $dz -incl
+    $Mz = $Mo + $zoff
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Biprism.focus.v2.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro tilt.Both.v2
+
+ $dt = 0.005
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $i = 0
+ for tilt 0.02 0.05 $dt -incl
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Both.tilt.v2.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+# best was: 2249.24
+macro disp.Biprism
+
+ $tilt = 0.02
+ $Mo = 2249.24
+ $dLM = 66.816
+
+ $Mz = $Mo
+ $Lz = $dLM - $Mz
+
+#echo ./run.phosim out/Biprism.3band F00 $Mz $Lz filt.3band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+#echo ./run.phosim out/Biprism.4band.v01 F01 $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+ echo ./run.phosim out/Biprism.4band.v02 F01 $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+ exec ./run.phosim out/Biprism.4band.v01 F01 $Mz $Lz filt.4band.txt BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+end
+
+# best was: 2249.24
+macro focus.Biprism
+
+ $tilt = 0.02
+
+ $dz = 0.01
+ $Mo = 2249.25
+ $dLM = 66.816
+
+ $i = 0
+ for zoff -0.05 +0.05 $dz -incl
+    $Mz = $Mo + $zoff
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Biprism.focus.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro tilt.Both
+
+ $dt = 0.005
+ $Mo = 2249.25
+ $dLM = 66.816
+
+ $i = 0
+ for tilt 0.0 0.02 $dt -incl
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/Both.tilt.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 $tilt none LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro focus.Both
+
+ $dz = 0.05
+ $Mo = 2249.2
+ $dLM = 66.816
+
+ $Noff = 5
+
+  for n {-$Noff} $Noff -incl
+    $Mz = $Mo + $n*$dz
+    $Lz = $dLM - $Mz
+
+    $i = $n + $Noff
+    sprintf outdir out/Both.focus.v2.%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 0.0 none LASF9.txt 0.0 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none BK7.txt 0.0 0.0 none LASF9.txt 0.0 0.0
+  end
+end
+
+macro tilt.LASF9.v2
+
+ $dt = 0.002
+ $Mo = 2248.6
+ $dLM = 66.816
+
+ $i = 0
+ for tilt 0.00 0.02 $dt -incl
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    # tilt the lower interface, what happens?
+    sprintf outdir out/LASF9.tilt.stars.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none LASF9.txt 0.0 $tilt
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none LASF9.txt 0.0 $tilt
+    $i ++
+  end
+end
+
+macro tilt.LASF9.v1
+
+ $dt = 0.005
+ $Mo = 2248.6
+ $dLM = 66.816
+
+ $i = 0
+ for tilt -0.02 0.02 $dt -incl
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    # tilt the lower interface, what happens?
+    sprintf outdir out/LASF9.tilt.F3b.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.750nm.txt LASF9.txt 0.0 $tilt
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.750nm.txt LASF9.txt 0.0 $tilt
+    $i ++
+  end
+end
+
+macro tilt.LASF9.v0
+
+ $dt = 0.005
+ $Mo = 2248.6
+ $dLM = 66.816
+
+ $i = 0
+ for tilt -0.02 0.02 $dt -incl
+    $Mz = $Mo
+    $Lz = $dLM - $Mz
+
+    # tilt the upper interface
+    sprintf outdir out/LASF9.tilt.F3a.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.750nm.txt LASF9.txt $tilt 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 filt.750nm.txt LASF9.txt $tilt 0.0
+    $i ++
+  end
+end
+
+macro focus.BK7
+
+ $dz = 0.1
+ $Mo = 2248.5
+ $dLM = 66.816
+
+ $Noff = 7
+
+  for n {-$Noff} $Noff -incl
+    $Mz = $Mo + $n*$dz
+    $Lz = $dLM - $Mz
+
+    $i = $n + $Noff
+    sprintf outdir out/BK7.focus.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none BK7.txt 0.0 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none BK7.txt 0.0 0.0
+  end
+end
+
+macro focus.LASF9
+
+ $dz = 0.1
+ $Mo = 2248.5
+ $dLM = 66.816
+
+ $Noff = 5
+
+  for n {-$Noff} $Noff -incl
+    $Mz = $Mo + $n*$dz
+    $Lz = $dLM - $Mz
+
+    $i = $n + $Noff
+    sprintf outdir out/LASF9.focus.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none LASF9.txt 0.0 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none LASF9.txt 0.0 0.0
+  end
+end
+
+macro focus.silica
+
+ $dz = 0.005
+ $Mo = 2248.2840
+ $dLM = 66.816
+
+  for i -3 3 -incl
+    $Mz = $Mo + $i*$dz
+    $Lz = $dLM - $Mz
+
+    sprintf outdir out/silica.focus.v%02d $i
+    sprintf obsid F%02d $i
+    echo ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none silica_dispersion.txt 0.0 0.0
+    exec ./run.phosim $outdir $obsid $Mz $Lz none air 0.0 0.0 none silica_dispersion.txt 0.0 0.0
+  end
+end
+
+if ($SCRIPT)
+  $RUN_SCRIPT  
+end
