Index: /trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfile.c	(revision 19004)
+++ /trunk/psModules/src/camera/pmFPAfile.c	(revision 19005)
@@ -22,5 +22,5 @@
 {
     if (!file) {
-	return;
+        return;
     }
 
@@ -38,5 +38,5 @@
 
     if (file->fits != NULL) {
-	psFitsClose (file->fits);
+        psFitsClose (file->fits);
     }
     psFree(file->compression);
@@ -113,10 +113,10 @@
     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     if (file == NULL) {
-	return NULL;
+        return NULL;
     }
 
     // internal files have the readout as a separate element:
     if (file->mode == PM_FPA_MODE_INTERNAL) {
-	return file->readout;
+        return file->readout;
     }
 
@@ -137,10 +137,10 @@
     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     if (file == NULL) {
-	return NULL;
+        return NULL;
     }
 
     // internal files have the readout as a separate element:
     if (file->mode == PM_FPA_MODE_INTERNAL) {
-	return NULL;
+        return NULL;
     }
 
@@ -161,10 +161,10 @@
     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
     if (file == NULL) {
-	return NULL;
+        return NULL;
     }
 
     // internal files have the readout as a separate element:
     if (file->mode == PM_FPA_MODE_INTERNAL) {
-	return NULL;
+        return NULL;
     }
 
@@ -183,114 +183,133 @@
 
     if (strstr (newName, "{FPA.OBS}") != NULL) {
-	char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.OBS");
-	if (name != NULL) {
-	    psStringSubstitute(&newName, name, "{FPA.OBS}");
-	}
+        char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.OBS");
+        if (name != NULL) {
+            psStringSubstitute(&newName, name, "{FPA.OBS}");
+        }
     }
     if (strstr (newName, "{FPA.NAME}") != NULL) {
-	char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.NAME");
-	if (name != NULL) {
-	    psStringSubstitute(&newName, name, "{FPA.NAME}");
-	}
+        char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.NAME");
+        if (name != NULL) {
+            psStringSubstitute(&newName, name, "{FPA.NAME}");
+        }
     }
     if (strstr (newName, "{CHIP.NAME}") != NULL) {
-	pmChip *chip = pmFPAviewThisChip (view, fpa);
-	if (chip != NULL) {
-	    char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
-	    if (name != NULL) {
-		psStringSubstitute(&newName, name, "{CHIP.NAME}");
-	    }
-	}
+        pmChip *chip = pmFPAviewThisChip (view, fpa);
+        if (chip != NULL) {
+            char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME");
+            if (name != NULL) {
+                psStringSubstitute(&newName, name, "{CHIP.NAME}");
+            }
+        }
     }
     if (strstr (newName, "{CHIP.ID}") != NULL) {
-	pmChip *chip = pmFPAviewThisChip (view, fpa);
-	if (chip != NULL) {
-	    char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.ID");
-	    if (name != NULL) {
-		psStringSubstitute(&newName, name, "{CHIP.ID}");
-	    }
-	}
+        pmChip *chip = pmFPAviewThisChip (view, fpa);
+        if (chip != NULL) {
+            char *name = psMetadataLookupStr (NULL, chip->concepts, "CHIP.ID");
+            if (name != NULL) {
+                psStringSubstitute(&newName, name, "{CHIP.ID}");
+            }
+        }
     }
     if (strstr (newName, "{CHIP.N}") != NULL) {
-	char *name = NULL;
-	if (view->chip < 0) {
-	    psStringAppend (&name, "XX");
-	} else {
-	    psStringAppend (&name, "%02d", view->chip);
-	}
-	psStringSubstitute(&newName, name, "{CHIP.N}");
-	psFree (name);
+        char *name = NULL;
+        if (view->chip < 0) {
+            psStringAppend (&name, "XX");
+        } else {
+            psStringAppend (&name, "%02d", view->chip);
+        }
+        psStringSubstitute(&newName, name, "{CHIP.N}");
+        psFree (name);
+    }
+    if (strstr (newName, "{CHIP.NUM}") != NULL) {
+        char *name = NULL;
+        if (view->chip < 0) {
+            psStringAppend (&name, "XX");
+        } else {
+            psStringAppend (&name, "%d", view->chip);
+        }
+        psStringSubstitute(&newName, name, "{CHIP.NUM}");
+        psFree (name);
     }
     if (strstr (newName, "{CELL.NAME}") != NULL) {
-	pmCell *cell = pmFPAviewThisCell (view, fpa);
-	if (cell != NULL) {
-	    char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME");
-	    if (name != NULL) {
-		psStringSubstitute(&newName, name, "{CELL.NAME}");
-	    }
-	}
+        pmCell *cell = pmFPAviewThisCell (view, fpa);
+        if (cell != NULL) {
+            char *name = psMetadataLookupStr (NULL, cell->concepts, "CELL.NAME");
+            if (name != NULL) {
+                psStringSubstitute(&newName, name, "{CELL.NAME}");
+            }
+        }
     }
     if (strstr (newName, "{CELL.N}") != NULL) {
-	char *name = NULL;
-	if (view->cell < 0) {
-	    psStringAppend (&name, "XX");
-	} else {
-	    psStringAppend (&name, "%02d", view->cell);
-	}
-	psStringSubstitute(&newName, name, "{CELL.N}");
+        char *name = NULL;
+        if (view->cell < 0) {
+            psStringAppend (&name, "XX");
+        } else {
+            psStringAppend (&name, "%02d", view->cell);
+        }
+        psStringSubstitute(&newName, name, "{CELL.N}");
+    }
+    if (strstr (newName, "{CELL.NUM}") != NULL) {
+        char *name = NULL;
+        if (view->cell < 0) {
+            psStringAppend (&name, "XX");
+        } else {
+            psStringAppend (&name, "%d", view->cell);
+        }
+        psStringSubstitute(&newName, name, "{CELL.NUM}");
     }
     if (strstr (newName, "{EXTNAME}") != NULL) {
-	pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
-	if (hdu->extname && *hdu->extname) {
-	    psStringSubstitute(&newName, hdu->extname, "{EXTNAME}");
-	}
+        pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
+        if (hdu->extname && *hdu->extname) {
+            psStringSubstitute(&newName, hdu->extname, "{EXTNAME}");
+        }
     }
     if (strstr (newName, "{FILTER}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTER");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{FILTER}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTER");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{FILTER}");
+            }
+        }
     }
     if (strstr (newName, "{FILTER.ID}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTERID");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{FILTER.ID}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.FILTERID");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{FILTER.ID}");
+            }
+        }
     }
     if (strstr (newName, "{CAMERA}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{CAMERA}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{CAMERA}");
+            }
+        }
     }
     if (strstr (newName, "{INSTRUMENT}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{INSTRUMENT}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.INSTRUMENT");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{INSTRUMENT}");
+            }
+        }
     }
     if (strstr (newName, "{DETECTOR}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.DETECTOR");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{DETECTOR}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.DETECTOR");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{DETECTOR}");
+            }
+        }
     }
     if (strstr (newName, "{TELESCOPE}") != NULL) {
-	if (fpa != NULL) {
-	    char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.TELESCOPE");
-	    if (name && *name) {
-		psStringSubstitute(&newName, name, "{TELESCOPE}");
-	    }
-	}
+        if (fpa != NULL) {
+            char *name = psMetadataLookupStr (NULL, fpa->concepts, "FPA.TELESCOPE");
+            if (name && *name) {
+                psStringSubstitute(&newName, name, "{TELESCOPE}");
+            }
+        }
     }
     return newName;
@@ -309,8 +328,8 @@
 
     if (strstr(newRule, "{OUTPUT}") != NULL) {
-	char *name = psMetadataLookupStr(NULL, file->names, "OUTPUT");
-	if (name) {
-	    psStringSubstitute(&newRule, name, "{OUTPUT}");
-	}
+        char *name = psMetadataLookupStr(NULL, file->names, "OUTPUT");
+        if (name) {
+            psStringSubstitute(&newRule, name, "{OUTPUT}");
+        }
     }
 
@@ -331,10 +350,10 @@
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
-	pmFPACopy (out, in);
-	return true;
+        pmFPACopy (out, in);
+        return true;
     }
     if (view->chip >= in->chips->n) {
-	psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %ld", view->chip, in->chips->n);
-	return false;
+        psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %ld", view->chip, in->chips->n);
+        return false;
     }
     pmChip *inChip = in->chips->data[view->chip];
@@ -342,11 +361,11 @@
 
     if (view->cell == -1) {
-	pmChipCopy (outChip, inChip);
-	return true;
+        pmChipCopy (outChip, inChip);
+        return true;
     }
     if (view->cell >= inChip->cells->n) {
-	psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
-		view->cell, inChip->cells->n);
-	return false;
+        psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
+                view->cell, inChip->cells->n);
+        return false;
     }
     pmCell *inCell = inChip->cells->data[view->cell];
@@ -354,6 +373,6 @@
 
     if (view->readout == -1) {
-	pmCellCopy (outCell, inCell);
-	return true;
+        pmCellCopy (outCell, inCell);
+        return true;
     }
     psError(PS_ERR_UNKNOWN, true, "Returning false");
@@ -378,10 +397,10 @@
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
-	status = pmFPACopyStructure (out, in, xBin, yBin);
-	return status;
+        status = pmFPACopyStructure (out, in, xBin, yBin);
+        return status;
     }
     if (view->chip >= in->chips->n) {
-	psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %ld", view->chip, in->chips->n);
-	return false;
+        psError(PS_ERR_IO, true, "Requested chip == %d >= in->chips->n == %ld", view->chip, in->chips->n);
+        return false;
     }
     pmChip *inChip = in->chips->data[view->chip];
@@ -389,11 +408,11 @@
 
     if (view->cell == -1) {
-	status = pmChipCopyStructure (outChip, inChip, xBin, yBin);
-	return status;
+        status = pmChipCopyStructure (outChip, inChip, xBin, yBin);
+        return status;
     }
     if (view->cell >= inChip->cells->n) {
-	psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
-		view->cell, inChip->cells->n);
-	return false;
+        psError(PS_ERR_IO, true, "Requested cell == %d>= inChip->cells->n == %ld",
+                view->cell, inChip->cells->n);
+        return false;
     }
     pmCell *inCell = inChip->cells->data[view->cell];
@@ -409,54 +428,54 @@
 
     if (!strcasecmp (type, "SX"))     {
-	return PM_FPA_FILE_SX;
+        return PM_FPA_FILE_SX;
     }
     if (!strcasecmp (type, "OBJ"))     {
-	return PM_FPA_FILE_OBJ;
+        return PM_FPA_FILE_OBJ;
     }
     if (!strcasecmp (type, "CMP"))     {
-	return PM_FPA_FILE_CMP;
+        return PM_FPA_FILE_CMP;
     }
     if (!strcasecmp (type, "CMF"))     {
-	return PM_FPA_FILE_CMF;
+        return PM_FPA_FILE_CMF;
     }
     if (!strcasecmp (type, "RAW"))     {
-	return PM_FPA_FILE_RAW;
+        return PM_FPA_FILE_RAW;
     }
     if (!strcasecmp (type, "IMAGE"))     {
-	return PM_FPA_FILE_IMAGE;
+        return PM_FPA_FILE_IMAGE;
     }
     if (!strcasecmp (type, "PSF"))     {
-	return PM_FPA_FILE_PSF;
+        return PM_FPA_FILE_PSF;
     }
     if (!strcasecmp (type, "JPEG"))     {
-	return PM_FPA_FILE_JPEG;
+        return PM_FPA_FILE_JPEG;
     }
     if (!strcasecmp (type, "KAPA"))     {
-	return PM_FPA_FILE_KAPA;
+        return PM_FPA_FILE_KAPA;
     }
     if (!strcasecmp (type, "MASK"))     {
-	return PM_FPA_FILE_MASK;
+        return PM_FPA_FILE_MASK;
     }
     if (!strcasecmp (type, "WEIGHT"))     {
-	return PM_FPA_FILE_WEIGHT;
+        return PM_FPA_FILE_WEIGHT;
     }
     if (!strcasecmp (type, "FRINGE")) {
-	return PM_FPA_FILE_FRINGE;
+        return PM_FPA_FILE_FRINGE;
     }
     if (!strcasecmp (type, "DARK"))     {
-	return PM_FPA_FILE_DARK;
+        return PM_FPA_FILE_DARK;
     }
     if (!strcasecmp (type, "HEADER"))     {
-	return PM_FPA_FILE_HEADER;
+        return PM_FPA_FILE_HEADER;
     }
     // deprecate this?
     if (!strcasecmp (type, "ASTROM"))     {
-	return PM_FPA_FILE_ASTROM_MODEL;
+        return PM_FPA_FILE_ASTROM_MODEL;
     }
     if (!strcasecmp (type, "ASTROM.MODEL"))     {
-	return PM_FPA_FILE_ASTROM_MODEL;
+        return PM_FPA_FILE_ASTROM_MODEL;
     }
     if (!strcasecmp (type, "ASTROM.REFSTARS"))     {
-	return PM_FPA_FILE_ASTROM_REFSTARS;
+        return PM_FPA_FILE_ASTROM_REFSTARS;
     }
 
@@ -468,37 +487,37 @@
     switch (type) {
       case PM_FPA_FILE_SX:
-	return ("SX");
+        return ("SX");
       case PM_FPA_FILE_OBJ:
-	return ("OBJ");
+        return ("OBJ");
       case PM_FPA_FILE_CMP:
-	return ("CMP");
+        return ("CMP");
       case PM_FPA_FILE_CMF:
-	return ("CMF");
+        return ("CMF");
       case PM_FPA_FILE_RAW:
-	return ("RAW");
+        return ("RAW");
       case PM_FPA_FILE_IMAGE:
-	return ("IMAGE");
+        return ("IMAGE");
       case PM_FPA_FILE_PSF:
-	return ("PSF");
+        return ("PSF");
       case PM_FPA_FILE_JPEG:
-	return ("JPEG");
+        return ("JPEG");
       case PM_FPA_FILE_KAPA:
-	return ("KAPA");
+        return ("KAPA");
       case PM_FPA_FILE_MASK:
-	return ("MASK");
+        return ("MASK");
       case PM_FPA_FILE_WEIGHT:
-	return ("WEIGHT");
+        return ("WEIGHT");
       case PM_FPA_FILE_FRINGE:
-	return ("FRINGE");
+        return ("FRINGE");
       case PM_FPA_FILE_DARK:
-	return("DARK");
+        return("DARK");
       case PM_FPA_FILE_HEADER:
-	return ("HEADER");
+        return ("HEADER");
       case PM_FPA_FILE_ASTROM_MODEL:
-	return ("ASTROM.MODEL");
+        return ("ASTROM.MODEL");
       case PM_FPA_FILE_ASTROM_REFSTARS:
-	return ("ASTROM.REFSTARS");
+        return ("ASTROM.REFSTARS");
       default:
-	return ("NONE");
+        return ("NONE");
     }
     return ("NONE");
