Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.c	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.c	(revision 30705)
@@ -41,4 +41,5 @@
     psFree(tmp->params);
     psFree(tmp->dparams);
+    psFree(tmp->covar);
     psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
 }
@@ -71,4 +72,5 @@
     tmp->flags = PM_MODEL_STATUS_NONE;
     tmp->residuals = NULL;              // do not free: the model does not own this memory
+    tmp->covar = NULL;
     tmp->isPCM = false;
 
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.h
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.h	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmModel.h	(revision 30705)
@@ -33,4 +33,5 @@
     psVector *params;                   ///< Paramater values.
     psVector *dparams;                  ///< Parameter errors.
+    psImage *covar;                     ///< Optional covariance matrix
     float chisq;                        ///< Fit chi-squared.
     float chisqNorm;                    ///< re-normalized fit chi-squared.
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.c	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.c	(revision 30705)
@@ -55,4 +55,5 @@
     psFree(radial->flux);
     psFree(radial->fluxErr);
+    psFree(radial->fluxStdev);
     psFree(radial->fill);
 }
@@ -65,4 +66,5 @@
     radial->flux = NULL;
     radial->fluxErr = NULL;
+    radial->fluxStdev = NULL;
     radial->fill = NULL;
     return radial;
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.h
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.h	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceExtendedPars.h	(revision 30705)
@@ -23,4 +23,5 @@
 typedef struct {
     psVector *flux;			// fluxes measured at above radii
+    psVector *fluxStdev;		// scatter (standard deviation) of flux
     psVector *fluxErr;			// formal error on the fluxes (sqrt\sum(variance))
     psVector *fill;			// angles corresponding to above radial profiles
@@ -63,4 +64,5 @@
     float petrosianR50;
     float petrosianR50Err;
+    float petrosianFill;
 } pmSourceExtendedPars;
 
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.c	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.c	(revision 30705)
@@ -59,4 +59,5 @@
     opt->maxChisqDOF = NAN;
     opt->poissonErrors = true;
+    opt->saveCovariance = false;
 
     return opt;
@@ -231,4 +232,7 @@
         psTrace ("psModules.objects", 4, "%f +/- %f", params->data.F32[i], dparams->data.F32[i]);
     }
+    if (options->saveCovariance) {
+	model->covar = psMemIncrRefCounter(covar);
+    }
     psTrace ("psModules.objects", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
 
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.h
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.h	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitModel.h	(revision 30705)
@@ -32,4 +32,5 @@
     float weight;			///< use this weight for constant-weight fits
     bool poissonErrors;			///< use poisson errors for fits?
+    bool saveCovariance;
 } pmSourceFitOptions;
 
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitPCM.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitPCM.c	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitPCM.c	(revision 30705)
@@ -69,4 +69,7 @@
         dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);
         psTrace ("psModules.objects", 4, "%f +/- %f", params->data.F32[i], dparams->data.F32[i]);
+    }
+    if (fitOptions->saveCovariance) {
+	pcm->modelConv->covar = psMemIncrRefCounter(covar);
     }
     psTrace ("psphot", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value);
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.c	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.c	(revision 30705)
@@ -296,7 +296,8 @@
 
 // set the model parameters for this fit set
-bool pmSourceFitSetValues (pmSourceFitSetData *set, const psVector *dparam,
-                           const psVector *param, pmSource *source,
-                           psMinimization *myMin, int nPix, bool fitStatus)
+bool pmSourceFitSetValues (pmSourceFitSetData *set, 
+			   const psVector *dparam, const psVector *param, const psImage *covar, 
+			   pmSource *source, psMinimization *myMin, int nPix, 
+			   bool fitStatus, bool saveCovariance)
 {
     PS_ASSERT_PTR_NON_NULL(set, false);
@@ -311,4 +312,5 @@
 
     int n = 0;
+    int nStart = 0;
     for (int i = 0; i < set->paramSet->n; i++) {
 
@@ -320,4 +322,14 @@
             psTrace ("psModules.objects", 4, "%f +/- %f", param->data.F32[n], dparam->data.F32[n]);
         }
+	if (saveCovariance) {
+	    // we only save the covar matrix for this object with itself (ignore cross terms between objects)
+	    model->covar = psImageAlloc(model->params->n, model->params->n, PS_TYPE_F32);
+	    for (int ix = 0; ix < model->params->n; ix++) {
+		for (int iy = 0; iy < model->params->n; iy++) {
+		    model->covar->data.F32[iy][ix] = covar->data.F32[nStart+iy][nStart+ix];
+		}
+	    }
+	}
+	nStart += model->params->n;
         psTrace ("psModules.objects", 4, " src %d", i);
 
@@ -550,5 +562,5 @@
     }
 
-// parameter errors from the covariance matrix
+    // parameter errors from the covariance matrix
     psVector *dparams = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32);
     for (int i = 0; i < dparams->n; i++) {
@@ -558,5 +570,5 @@
     }
 
-// get the Gauss-Newton distance for fixed model parameters
+    // get the Gauss-Newton distance for fixed model parameters
     if (constraint->paramMask != NULL) {
 	psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);
@@ -580,5 +592,5 @@
     }
 
-    pmSourceFitSetValues (thisSet, dparams, params, source, myMin, y->n, fitStatus);
+    pmSourceFitSetValues (thisSet, dparams, params, covar, source, myMin, y->n, fitStatus, options->saveCovariance);
     psTrace ("psModules.objects", 5, "onPic: %d, fitStatus: %d, nIter: %d, chisq: %f, nPix: %ld\n", onPic, fitStatus, myMin->iter, myMin->value, y->n);
 
Index: /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.h
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.h	(revision 30704)
+++ /branches/eam_branches/ipp-20110213/psModules/src/objects/pmSourceFitSet.h	(revision 30705)
@@ -40,5 +40,9 @@
 bool pmSourceFitSetJoin (psVector *deriv, psVector *param, pmSourceFitSetData *set);
 bool pmSourceFitSetSplit (pmSourceFitSetData *set, const psVector *deriv, const psVector *param);
-bool pmSourceFitSetValues (pmSourceFitSetData *set, const psVector *dparam, const psVector *param, pmSource *source, psMinimization *myMin, int nPix, bool fitStatus);
+
+bool pmSourceFitSetValues (pmSourceFitSetData *set, 
+			   const psVector *dparam, const psVector *param, const psImage *covar, 
+			   pmSource *source, psMinimization *myMin, int nPix, 
+			   bool fitStatus, bool saveCovariance);
 
 psF32 pmSourceFitSetFunction(psVector *deriv, const psVector *param, const psVector *x);
@@ -57,5 +61,5 @@
     psArray *modelSet,                  ///< model to be fitted
     pmSourceFitOptions *options,	///< define options for fitting process
-    psImageMaskType maskVal             ///< Vale to mask
+    psImageMaskType maskVal             ///< Value to mask
 
 );
