Index: trunk/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- trunk/psModules/src/objects/pmSourceFitModel.c	(revision 10198)
+++ trunk/psModules/src/objects/pmSourceFitModel.c	(revision 10199)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-11-24 20:55:48 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-26 22:26:51 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -207,14 +207,11 @@
 
     // get the Gauss-Newton distance for fixed model parameters
-    // XXX I need to hold the fitted parameters fixed!
+    // hold the fitted parameters fixed; mask sky which is not fitted at all
     if (paramMask != NULL) {
         psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64);
         psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);
-        for (int i = 0; i < dparams->n; i++) {
-            if (paramMask->data.U8[i]) {
-                altmask->data.U8[i] = 0;
-            } else {
-                altmask->data.U8[i] = 1;
-            }
+        altmask->data.U8[0] = 1;
+        for (int i = 1; i < dparams->n; i++) {
+            altmask->data.U8[i] = (paramMask->data.U8[i]) ? 0 : 1;
         }
         psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, modelFunc);
@@ -222,5 +219,8 @@
             if (!paramMask->data.U8[i])
                 continue;
-            dparams->data.F32[i] = delta->data.F64[i];
+            // note that delta is the value *subtracted* from the parameter
+            // to get the new guess.  for dparams to represent the direction
+            // of motion, we need to take -delta
+            dparams->data.F32[i] = -delta->data.F64[i];
         }
         psFree (delta);
@@ -535,11 +535,20 @@
     if (constrain->paramMask != NULL) {
         psVector *delta = psVectorAlloc (params->n, PS_TYPE_F64);
-        psMinimizeGaussNewtonDelta(delta, params, NULL, x, y, yErr, pmModelFitSet);
+        psVector *altmask = psVectorAlloc (params->n, PS_TYPE_U8);
+        altmask->data.U8[0] = 1;
+        for (int i = 1; i < dparams->n; i++) {
+            altmask->data.U8[i] = (constrain->paramMask->data.U8[i]) ? 0 : 1;
+        }
+        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmModelFitSet);
         for (int i = 0; i < dparams->n; i++) {
             if (!constrain->paramMask->data.U8[i])
                 continue;
-            dparams->data.F32[i] = delta->data.F64[i];
+            // note that delta is the value *subtracted* from the parameter
+            // to get the new guess.  for dparams to represent the direction
+            // of motion, we need to take -delta
+            dparams->data.F32[i] = -delta->data.F64[i];
         }
         psFree (delta);
+        psFree (altmask);
     }
 
