Index: trunk/ippTests/ippCheck/cammask.pro
===================================================================
--- trunk/ippTests/ippCheck/cammask.pro	(revision 42085)
+++ trunk/ippTests/ippCheck/cammask.pro	(revision 42114)
@@ -52,9 +52,22 @@
  $smfreal = `neb-locate -p $smffile`
  
+ # sets the list chipName:0 - chipName:n based on chipRun 
  get.chip.metadata $dbname $chipID
+
+ # set the list camMask:0 - camMask:n based on nebulous listing
+ # some cam-stage masks may be missing, these are set to NONE
+ # the number of entries in both lists is the same (chipName:n)
  get.chip.mask.files $camPath
  
+ # read in the PHU header
+ rd PHU $smfreal
+
+ # set the list chipNseq:0 - chipNseq:n based on smf entries.
+ # Some chips may be missing from the smf, these are set to -1
+ # $chipNseq:n = $chipName:n
+ get.chip.smf.Nseq $smfreal
+
  for i 0 $camMask:n
-   echo $chipName:$i $camMask:$i
+   echo $chipName:$i $chipNseq:$i $camMask:$i
  end
 
@@ -71,29 +84,23 @@
  set Nref = ramp(Rref)
 
- # read in the PHU header
- rd PHU $smfreal
-
- # create the chipName list from the smffile and calculate the index numbers.
- # NOTE: if a chip is missing from the smf, this may be inconsistent with chipMask:n
- # XXX for now, we fail is this happens
- list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//"
- for i 0 $chipsRaw:n
-  list word -splitbychar : $chipsRaw:$i
-  $chipNseq:$i = $word:0 - 3; # this number depends on the number of leading tables 
-  if ("$chipName:$i" != "$word:1")
-    echo "ERROR: missing chip from smffile: " $chipName:$i
-    break
-  end
- end
-
-  # delete any existing output vectors
-  foreach field $SMF_FIELDS_CAM $REF_FIELDS_CAM $XTR_FIELDS_CAM
-    delete -q $field\_out
-  end
+ # delete any existing output vectors
+ foreach field $SMF_FIELDS_CAM $REF_FIELDS_CAM $XTR_FIELDS_CAM
+   delete -q $field\_out
+ end
 
  # find matching entries in smf file 
  for i 0 $chipName:n
+   ## echo $chipName:$i $chipNseq:$i $camMask:$i
+
+   if ($chipNseq:$i < 0) continue
+
    get.chip.detect.stats $chipName:$i $chipNseq:$i
-   get.chip.mask.stats $camMask:$i
+
+   if ("$camMask:$i" == "NONE") 
+     # if the mask files are missing, all are masked or unmasked?
+     set Q1ref_onchp = zero(Xref_onchp) + 1.0
+   else
+     get.chip.mask.stats $camMask:$i
+   end
 
    foreach field $SMF_FIELDS_CAM
@@ -241,9 +248,16 @@
 
  # get the full list from nebulous (faster than getting each one at a time)
- list tmpName -x "neb-ls $pathbase.%.mk.fits"
+ list tmpName -x "neb-ls -c $pathbase.%.mk.fits"
 
  # the list of masks might not match the list of chips
+ # mark missing cam-stage masks with NONE
  $j = 0
+ echo "chipName:n $chipName:n"
  for i 0 $chipName:n
+   # if we get to the end of the list, assign the missing entries to NONE
+   if ($j >= $tmpName:n)
+    $camMask:$i = NONE
+    continue
+   end
    list word -splitbychar . $tmpName:$j
    $Nch = $word:n - 3
@@ -254,9 +268,47 @@
    end
    $camMask:$i = $tmpName:$j
-   if ($VERBOSE) echo "found chipMask $camMask:$i"
+   if ($VERBOSE) echo "found chipMask $camMask:$i ($chipName:$i) : $i $j $chipName:n $tmpName:n"
    if ($COPYMASKS) exec neb-copy $camMask:$i $OUTDIR
    $j ++
  end
  $camMask:n = $chipName:n
+end
+
+# get the file names of the chip mask files.
+# these are actually the masks from the camera stage which
+# has the dynamic masking applied
+macro get.chip.smf.Nseq
+ if ($0 != 2)
+  echo "USAGE: get.camera.smf.Nseq (smffile)"
+  echo " sets chipNseq:0 - chipNseq:n"
+  break
+ end
+
+ local i j smffile
+ $smffile = $1
+
+ # identify the chips in the smffile and calculate the index numbers.
+ # NOTE: if a chip is missing from the smf, set Nseq to -1
+ list chipsRaw -x "ftable -list $smfreal | grep -n hdr | prcol 1 | sed s/.hdr//"
+
+ $j = 0
+ for i 0 $chipName:n
+   # if we get to the end of the list, assign the missing entries to NONE
+   if ($j >= $chipsRaw:n)
+    $chipNseq:$i = -1
+    continue
+   end
+   list word -splitbychar : $chipsRaw:$j
+   $myNseq = $word:0 - 3; # this number depends on the number of leading tables 
+   $mychip = $word:1
+   if ($mychip != $chipName:$i) 
+    $chipNseq:$i = -1
+    continue
+   end
+   $chipNseq:$i = $myNseq
+   if ($VERBOSE) echo "found chip entry $chipNseq:$i ($chipName:$i) : $i $j $chipName:n $chipsRaw:n"
+   $j ++
+ end
+ $chipNseq:n = $chipName:n
 end
 
