Index: /trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1664)
+++ /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1665)
@@ -8,6 +8,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-14 01:51:11 $
+*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-01 00:57:48 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -50,17 +50,12 @@
 /*****************************************************************************/
 
-void p_psGrommitFree(psGrommit* grommit)
-{
-    psFree(grommit);
-}
-
 /*****************************************************************************
-p_psCheckValidImageCoords(): this is a private function which simply
+checkValidImageCoords(): this is a private function which simply
 determines if the supplied x,y coordinates are in the range for the supplied
 psImage.
  *****************************************************************************/
-int p_psCheckValidImageCoords(double x,
-                              double y,
-                              psImage* tmpImage)
+static int checkValidImageCoords(double x,
+                                 double y,
+                                 psImage* tmpImage)
 {
     if (tmpImage == NULL) {
@@ -79,9 +74,9 @@
 
 /*****************************************************************************
-p_psIsProjectionLinear(): this is a private function which simply determines
+isProjectionLinear(): this is a private function which simply determines
 if the supplied psPlaneTransform transform is linear: if any of the
 cooefficients of order 2 are higher are non-zero, then it is not linear.
  *****************************************************************************/
-int p_psIsProjectionLinear(psPlaneTransform *transform)
+static int isProjectionLinear(psPlaneTransform *transform)
 {
     int i = 0;
@@ -116,5 +111,5 @@
 
 /*****************************************************************************
-p_psInvertPlaneTransform(transform): : this is a private function which
+invertPlaneTransform(transform): : this is a private function which
 simply inverts the supplied psPlaneTransform transform.  It assumes that
 "transform" is linear.
@@ -134,5 +129,5 @@
              (Y2 * (1.0 / (F - ((C*E)/B))));
  *****************************************************************************/
-psPlaneTransform *p_psInvertPlaneTransform(psPlaneTransform *transform)
+static psPlaneTransform *invertPlaneTransform(psPlaneTransform *transform)
 {
     double A = transform->x->coeff[0][0];
@@ -158,7 +153,57 @@
 }
 
+static void FPAFree(psFPA* fpa)
+{
+    if (fpa != NULL) {
+        psFree(fpa->chips);
+        psFree(fpa->grommit);
+        psFree((psExposure*)fpa->exposure);
+        psFree(fpa->metadata);
+        psFree(fpa->fromTangentPlane);
+        psFree(fpa->toTangentPlane);
+        psFree(fpa->pattern);
+        psFree(fpa->colorPlus);
+        psFree(fpa->colorMinus);
+        psFree(fpa->projection);
+    }
+}
+
+static void chipFree(psChip* chip)
+{
+    if (chip != NULL) {
+        psFree(chip->cells);
+        psFree(chip->parent);
+        psFree(chip->metadata);
+        psFree(chip->toFPA);
+        psFree(chip->fromFPA);
+    }
+}
+
+static void cellFree(psCell* cell)
+{
+    if (cell != NULL) {
+        psFree(cell->readouts);
+        psFree(cell->metadata);
+        psFree(cell->toChip);
+        psFree(cell->fromChip);
+        psFree(cell->toFPA);
+        psFree(cell->toTP);
+        psFree(cell->parent);
+    }
+}
+
+static void readoutFree(psReadout* readout)
+{
+    if (readout != NULL) {
+        psFree(readout->image);
+        psFree(readout->objects);
+        psFree(readout->metadata);
+    }
+}
+
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
+
 psExposure* psExposureAlloc(double ra, double dec, double hourAngle,
                             double zenith, double azimuth, double localTime, float date,
@@ -183,4 +228,119 @@
     return exp;
 }
+
+/*
+ * psFPA constructor
+ */
+psFPA* psFPAAlloc(int nChips,
+                  const psExposure* exp)
+{
+    psFPA* newFPA = psAlloc(sizeof(psFPA));
+
+    // create array of NULL chips of the size nChips
+    newFPA->chips = psArrayAlloc(nChips);
+    void** chips = newFPA->chips->data;
+    for (int i=0;i<nChips;i++) {
+        chips[i] = NULL;
+    }
+
+    newFPA->metadata = NULL;
+    newFPA->fromTangentPlane = NULL;
+    newFPA->toTangentPlane = NULL;
+    newFPA->pattern = NULL;
+    newFPA->exposure = psMemIncrRefCounter((psExposure*)exp);
+    newFPA->grommit = psGrommitAlloc(exp);
+
+    newFPA->colorPlus = NULL;
+    newFPA->colorMinus = NULL;
+    newFPA->projection = NULL;
+
+    newFPA->rmsX = 0.0f;
+    newFPA->rmsY = 0.0f;
+    newFPA->chi2 = 0.0f;
+
+    p_psMemSetDeallocator(newFPA,(psFreeFcn)FPAFree);
+
+    return newFPA;
+}
+
+/*
+ * psChip constructor
+ */
+psChip* psChipAlloc(int nCells,
+                    psFPA *parentFPA)
+{
+    psChip* chip = psAlloc(sizeof(psChip));
+
+    // create array of NULL psCells
+    chip->cells = psArrayAlloc(nCells);
+    void** cells = chip->cells->data;
+    for (int i=0;i<nCells;i++) {
+        cells[i] = NULL;
+    }
+
+    chip->metadata = NULL;
+
+    chip->toFPA = NULL;
+    chip->fromFPA = NULL;
+
+    chip->parent = psMemIncrRefCounter(parentFPA);
+
+    p_psMemSetDeallocator(chip,(psFreeFcn)chipFree);
+
+    return chip;
+
+}
+
+/*
+ * psCell constructor
+ */
+psCell* psCellAlloc(int nReadouts,
+                    psChip* parentChip)
+{
+    psCell* cell = psAlloc(sizeof(psCell));
+
+    // create array of NULL psReadouts
+    cell->readouts = psArrayAlloc(nReadouts);
+    void** readouts = cell->readouts->data;
+    for (int i=0;i<nReadouts;i++) {
+        readouts[i] = NULL;
+    }
+
+    cell->metadata = NULL;
+
+    cell->toChip = NULL;
+    cell->fromChip = NULL;
+    cell->toFPA = NULL;
+    cell->toTP = NULL;
+
+    cell->parent = psMemIncrRefCounter(parentChip);
+
+    p_psMemSetDeallocator(cell,(psFreeFcn)cellFree);
+
+    return cell;
+
+
+}
+
+psReadout* psReadoutAlloc(int col0,
+                          int row0,
+                          const psImage* image)
+{
+    psReadout* readout = psAlloc(sizeof(psReadout));
+
+    *(unsigned int*)&readout->colBins = 1;
+    *(unsigned int*)&readout->rowBins = 1;
+    *(int*)&readout->col0 = col0;
+    *(int*)&readout->row0 = row0;
+
+    readout->image = psMemIncrRefCounter((psImage*)image);
+    readout->objects = NULL;
+    readout->metadata = NULL;
+
+    p_psMemSetDeallocator(readout,(psFreeFcn)readoutFree);
+
+    return readout;
+}
+
 #define TBD 0.0
 /*****************************************************************************
@@ -194,10 +354,10 @@
     }
 
-    double date = TBD;  // "mjd" in psExposure will become a psTime
+    double date = TBD;  // XXX: "mjd" in psExposure will become a psTime
     // from which it will be possible to get UTC.
     double dut = 0.0;
-    double elongm = TBD;
-    double phim = TBD;
-    double hm = TBD;
+    double elongm = TBD; // XXX
+    double phim = TBD;   // XXX
+    double hm = TBD;     // XXX
     double xp = 0.0;
     double yp = 0.0;
@@ -206,5 +366,5 @@
     double rh = exp->humidity;
     double wl = exp->wavelength;
-    double tlr = TBD;
+    double tlr = TBD;    // XXX
     double *AOPRMS = NULL;
 
@@ -329,7 +489,7 @@
                                                   chipCoord);
 
-                if (p_psCheckValidImageCoords(cellCoord->x,
-                                              cellCoord->y,
-                                              tmpReadout->image)) {
+                if (checkValidImageCoords(cellCoord->x,
+                                          cellCoord->y,
+                                          tmpReadout->image)) {
                     psFree(cellCoord);
                     return (tmpCell);
@@ -651,9 +811,9 @@
 
     // generate an error if cell->toTP is not linear.
-    if (0 == p_psIsProjectionLinear(cell->toTP)) {
+    if (0 == isProjectionLinear(cell->toTP)) {
         psAbort(__func__, "the cell->toTP transfrom is not linear.\n");
     }
 
-    TPtoCell = p_psInvertPlaneTransform(cell->toTP);
+    TPtoCell = invertPlaneTransform(cell->toTP);
     cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord);
 
Index: /trunk/psLib/src/astronomy/psAstrometry.h
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1664)
+++ /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1665)
@@ -8,6 +8,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-13 22:41:24 $
+*  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-01 00:57:48 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -239,4 +239,57 @@
 );
 
+/** Allocator for psFPA
+ *
+ *  This function shall make an empty psFPA, with the nChips allocated 
+ *  pointers to psChips being set to NULL; all other pointers in the structure 
+ *  shall be initialized to NULL, apart from the grommit, which shall be 
+ *  constructed on the basis of the exp parameter.
+ *
+ *  @return psFPA*    a newly allocated psFPA
+ */
+psFPA* psFPAAlloc(
+    int nChips,                        ///< number of chips in the FPA
+    const psExposure* exp              ///< the exposure information
+);
+
+/** Allocates a psChip
+ *
+ *  This allocator shall make an empty psChip, with the nCells allocated 
+ *  pointers to psCells being set to NULL; all other pointers in the structure
+ *  shall be initialized to NULL.
+ *
+ *  @return psChip*    newly allocated psChip
+ */
+psChip* psChipAlloc(
+    int nCells,                        ///< number of cells in Chip
+    psFPA* parentFPA                   ///< parent FPA
+);
+
+/** Allocates a psCell
+ *
+ *  The constructor shall make an empty psCell, with the nReadouts allocated 
+ *  pointers to psReadouts being set to NULL; all other pointers in the 
+ *  structure shall be initialized to NULL.
+ *
+ *  @return psCell*    newly allocated psCell
+ */
+psCell* psCellAlloc(
+    int nReadouts,                     ///< number of readouts in cell
+    psChip* parentChip                 ///< parent Chip
+);
+
+/** Allocates a psReadout
+ *
+ *  All pointers in the structure other than the image shall be initialized 
+ *  to NULL.
+ *
+ *  @return psReadout*    newly allocated psReadout
+ */
+psReadout* psReadoutAlloc(
+    int col0,                          ///< offset from the left of the cell
+    int row0,                          ///< offset from the bottom of the cell
+    const psImage* image               ///< image of the readout
+);
+
 /** Allocates a Wallace's Grommit structure.
  *
@@ -246,7 +299,4 @@
  *  @return psGrommit* New grommit structure.
  */
-psGrommit* psGrommitAlloc(const psExposure* exp        ///< the cooresponding exposure structure.
-                         );
-void p_psGrommitFree(psGrommit *grommit);
 psGrommit* psGrommitAlloc(
     const psExposure* exp              ///< the cooresponding exposure structure.
