Index: trunk/doc/release.2015/ps1.calibration/fluxave.sh
===================================================================
--- trunk/doc/release.2015/ps1.calibration/fluxave.sh	(revision 40727)
+++ trunk/doc/release.2015/ps1.calibration/fluxave.sh	(revision 40727)
@@ -0,0 +1,82 @@
+
+# what is the difference in the weighted average magnitue vs weighted average flux?
+macro mag.or.flux
+
+  # generate 1000 measurements of a Gaussian distributed flux at the given average S/N
+  # measure the weigthed average flux
+  # convert the fluxes to mags
+  # measure the weighted average mag
+
+  if ($0 != 4)
+    echo "USAGE: mag.or.flux (S/N) (Nmeas) (Ntrial)"
+    break
+  end
+
+  local Nmeas SN
+  $SN = $1
+  $Nmeas = $2
+  $Ntrial = $3
+
+  $Flux = 100.0
+  $dFlux = $Flux / $SN
+
+  create n 0 $Nmeas
+
+  delete -q Fo Mo
+  for i 0 $Ntrial
+    gaussdev df $Nmeas 0.0 $dFlux
+    
+    set flux = $Flux + df
+    
+    set s1 = flux / $dFlux^2
+    set s2 = zero(flux) + 1 / $dFlux^2
+    
+    vstat -q s1
+    $S1 = $TOTAL
+    
+    vstat -q s2
+    $S2 = $TOTAL
+    
+    concat {$S1 / $S2} Fo
+
+    set mag = -2.5*log(flux)
+    $dMag = 1.086 * ($dFlux / $Flux)
+    
+    set s1 = mag / $dMag^2
+    set s2 = zero(mag) + 1 / $dMag^2
+    
+    vstat -q s1
+    $S1 = $TOTAL
+    
+    vstat -q s2
+    $S2 = $TOTAL
+    
+    concat {$S1 / $S2} Mo
+  end
+
+  clear -s
+
+  section a 0 0 1 0.5
+  vstat -q Fo
+  set N = ramp(Fo)
+  lim N Fo; box; plot N Fo
+  line -c red 0 $MEAN to $Ntrial $MEAN
+  line -c blue 0 {$MEAN - $SIGMA} to $Ntrial {$MEAN - $SIGMA}
+  line -c blue 0 {$MEAN + $SIGMA} to $Ntrial {$MEAN + $SIGMA}
+  # echo $MEAN +/- $SIGMA
+  $Fave = $MEAN
+  $dFave = $SIGMA
+
+  section b 0 0.5 1 0.5
+  vstat -q Mo
+  set N = ramp(Mo)
+  lim N Mo; box; plot N Mo
+  line -c red 0 $MEAN to $Ntrial $MEAN
+  line -c blue 0 {$MEAN - $SIGMA} to $Ntrial {$MEAN - $SIGMA}
+  line -c blue 0 {$MEAN + $SIGMA} to $Ntrial {$MEAN + $SIGMA}
+  # echo $MEAN +/- $SIGMA
+  $Mave = $MEAN
+  $dMave = $SIGMA
+
+  echo $Mave vs {-2.5*log($Fave)} : {$Mave + 2.5*log($Fave)}, $dMave vs {1.086 * $dFave / $Fave}
+end
