#!/bin/csh -f

set catdir_3pi = /data/ipp064.0/eugene/3pi.20111229/catdir.20111229
set REALRUN = 1

alias run.relastro \
  'echo -n "--- starting relastro $catdir_3pi ---"; date; \
   echo          relastro $options $region -D CATDIR $catdir_3pi; \
   if ($REALRUN) relastro $options $region -D CATDIR $catdir_3pi'

## NOTE (2012.09.12, pt 1) : I previously ran relastro including all
## photcodes.  For reasons I don't yet understand, the SCO data is
## really messed up (bad dR,dD values), and messed up the mean
## positions for lots of objects.  I am re-running update-objects with
## only gpc1 and 2MASS data, and I will figure out how to fix SCO
## later.

## NOTE (2012.09.12, pt 2) : I used the default statmode previously:
## this is bad since it results in different rejections and thus
## inconsistent ChiSq values for ChiSqPos and ChiSqPM.  In this
## re-run, explicitly used the weighted version

# run update-objects on the whole sky
if (1) then
  # for a test, only run -pm
  set options = "-update-objects -pmpar"
  # set options = "-update-objects -pm"
  set options = "$options -D PM_DT_MIN 1.0"
  set options = "$options -D PAR_FACTOR_MIN 0.25"
  set options = "$options -statmode WTMEAN"
  set options = "$options +photcode g,r,i,z,y,J,H,K"
  set options = "$options -update"
  set options = "$options -parallel"
  set options = "$options -reset"
  set options = "$options -v"

  # set region = "-region 180 190 30 40"
  set region = "-region 0 360 -60 90"
  
  # run relastro -update-objects
  run.relastro
endif

# try 2000 meas per deg^2, but if memory if available, go to more
if (0) then
  set options = "-update-chips"
  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
  set options = "$options -nloop 6"
  set options = "$options -basic-image-search"
  set options = "$options -reset"
  set options = "$options -update"
  set options = "$options -parallel"
  set options = "$options -max-density 2000"
  set options = "$options -threads 4"
  set options = "$options -v"

  # run relastro -update-chips
  set ra_min = 0
  while ($ra_min < 360) 
    set ra_max = $ra_min
    @ ra_max += 35
  
    if (($ra_min == 240) || ($ra_min == 270)) then 
      set region = "-region $ra_min $ra_max -60 0"
      run.relastro 

      set region = "-region $ra_min $ra_max -5 60"
      run.relastro

      @ ra_min += 30
      continue
    endif

    set region = "-region $ra_min $ra_max -60 60"
    run.relastro

    @ ra_min += 30
  end

  # pole region 
  set region = "-region 0 360 55 90"
  run.relastro
endif

echo -n "--- done with relastro ---"; date
