Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38539)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38540)
@@ -266,5 +266,5 @@
 // Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
 
-// int        ReadXradFITS           PROTO((FILE *f, Header *theader, Stars *stars, unsigned int Nstars));
+int        ReadXradFITS           PROTO((FILE *f, Header *theader, Catalog *catalog));
 
 double     scat_subpix            PROTO((double x, double y));
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/FilterStars.c	(revision 38539)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/FilterStars.c	(revision 38540)
@@ -27,4 +27,7 @@
   Catalog *outcat = addstar_catalog_init (newcat->Nmeasure);
   ALLOCATE (outcat->average, Average, newcat->Nmeasure);
+  if (newcat->lensing) {
+    ALLOCATE (outcat->lensing, Lensing, newcat->Nlensing);
+  }
   
   for (N = j = 0; j < newcat->Nmeasure; j++) {
@@ -42,4 +45,10 @@
     dvo_average_init (&outcat->average[N]);
     outcat->measure[N] = newcat->measure[j];
+
+    if (newcat->lensing) {
+      outcat->lensing[N] = newcat->lensing[j];
+      outcat->average[N].Nlensing = 1;
+      outcat->average[N].lensingOffset = N;
+    }
 
     outcat->average[N].Nmeasure = 1;
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38539)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38540)
@@ -88,5 +88,4 @@
     images[0][Nvalid].nstar = newcat->Nmeasure;
 
-# if (0)
     // XRAD : if we want to read the xrad table, skip to that table here:
     if (headerSets[i].extnum_xrad != -1) {
@@ -98,9 +97,8 @@
       fseeko (f, Nskip, SEEK_SET); 
       
-      if (!ReadXradFITS (f, headers[Nxrad], &catalog[ncatalog], images[0][Nvalid].nstar)) {
+      if (!ReadXradFITS (f, headers[Nxrad], newcat)) {
 	fprintf (stderr, "problem reading the radial flux data for %s\n", headerSets[i].extdata);
       }
     }
-# endif
 
     // replace full input catalog newcat with subset version
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 38539)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 38540)
@@ -1205,16 +1205,6 @@
     catalog->lensing[i].E2_psf      = ps1data[i].E2_psf;
 
-    // catalog->lensing[i].F_ApR5    = ps1data[i].F_ApR5;
-    // catalog->lensing[i].dF_ApR5   = ps1data[i].dF_ApR5;
-    // catalog->lensing[i].sF_ApR5   = ps1data[i].sF_ApR5;
-    // catalog->lensing[i].fF_ApR5   = ps1data[i].fF_ApR5;
-    // 
-    // catalog->lensing[i].F_ApR6    = ps1data[i].F_ApR6;
-    // catalog->lensing[i].dF_ApR6   = ps1data[i].dF_ApR6;
-    // catalog->lensing[i].sF_ApR6   = ps1data[i].sF_ApR6;
-    // catalog->lensing[i].fF_ApR6   = ps1data[i].fF_ApR6;
-
-    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
-    catalog->lensing[i].detID      = ps1data[i].detID; 
+    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
+    catalog->lensing[i].detID       = ps1data[i].detID; 
 
     // the Average fields and the following Measure fields are set in FilterStars after
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadXradFITS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadXradFITS.c	(revision 38539)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadXradFITS.c	(revision 38540)
@@ -3,5 +3,5 @@
 // given a file with the pointer at the start of the table block and the 
 // corresponding image header, load the xrad data from the table
-int ReadXradFITS (FILE *f, Header *theader, Stars *stars, unsigned int Nstars) {
+int ReadXradFITS (FILE *f, Header *theader, Catalog *catalog) {
 
   FTable table;
@@ -51,24 +51,25 @@
   myAssert (Nrow == NrowAlt, "column mismatch?");
 
-  if (Nrow > Nstars) {
+  if (Nrow > catalog->Nmeasure) {
     myAbort("more radial measurements than stars?  seems like a bug\n");
   }
 
+  myAssert (catalog->lensing, "lensing is not allocated");
+  // we could allocate here, or just insist this is an error?
+  // if (!catalog->lensing) {
+  //   ALLOCATE (catalog->lensing, Lensing, catalog->Nmeasure);
+  // }
+
   int i;
   int Nap = 0;
-  for (i = 0; i < Nstars; i++) {
-    if (stars[i].measure.detID < RadID[Nap]) {
-      continue; // this star does not have an aperture
+  for (i = 0; i < catalog->Nmeasure; i++) {
+    if (catalog->measure[i].detID < RadID[Nap]) {
+      myAbort("star without radial aperture, seems like a bug"); // this star does not have an aperture
     }
-    if (stars[i].measure.detID > RadID[Nap]) {
+    if (catalog->measure[i].detID > RadID[Nap]) {
       myAbort("radial apertures out of order?  seems like a bug\n");
     }
 
-    // we could allocate here, or just insist this is an error?
-    if (!stars[i].lensing) {
-      fprintf (stderr, "!");
-      ALLOCATE (stars[i].lensing, Lensing, 1);
-      dvo_lensing_init (stars[i].lensing);
-    }
+    // we assumed we have already set up lensing in ReadStarsFITS.c
 
     // XXX this is all hard-wired and should make use of the headers. 
@@ -77,20 +78,28 @@
     // SDSS  3, 4, 5, 6, 7
 
-    stars[i].lensing-> F_ApR5 = AperFlux   [Nap*Ncol + 2];
-    stars[i].lensing->dF_ApR5 = AperFluxErr[Nap*Ncol + 2];
-    stars[i].lensing->sF_ApR5 = AperFluxStd[Nap*Ncol + 2];
-    stars[i].lensing->fF_ApR5 = AperFill   [Nap*Ncol + 2];
+    catalog->lensing[i]. F_ApR5 = AperFlux   [Nap*Ncol + 2];
+    catalog->lensing[i].dF_ApR5 = AperFluxErr[Nap*Ncol + 2];
+    catalog->lensing[i].sF_ApR5 = AperFluxStd[Nap*Ncol + 2];
+    catalog->lensing[i].fF_ApR5 = AperFill   [Nap*Ncol + 2];
 
-    stars[i].lensing-> F_ApR6 = AperFlux   [Nap*Ncol + 3];
-    stars[i].lensing->dF_ApR6 = AperFluxErr[Nap*Ncol + 3];
-    stars[i].lensing->sF_ApR6 = AperFluxStd[Nap*Ncol + 3];
-    stars[i].lensing->fF_ApR6 = AperFill   [Nap*Ncol + 3];
+    catalog->lensing[i]. F_ApR6 = AperFlux   [Nap*Ncol + 3];
+    catalog->lensing[i].dF_ApR6 = AperFluxErr[Nap*Ncol + 3];
+    catalog->lensing[i].sF_ApR6 = AperFluxStd[Nap*Ncol + 3];
+    catalog->lensing[i].fF_ApR6 = AperFill   [Nap*Ncol + 3];
 
-    stars[i].lensing-> F_ApR7 = AperFlux   [Nap*Ncol + 4];
-    stars[i].lensing->dF_ApR7 = AperFluxErr[Nap*Ncol + 4];
-    stars[i].lensing->sF_ApR7 = AperFluxStd[Nap*Ncol + 4];
-    stars[i].lensing->fF_ApR7 = AperFill   [Nap*Ncol + 4];
+    catalog->lensing[i]. F_ApR7 = AperFlux   [Nap*Ncol + 4];
+    catalog->lensing[i].dF_ApR7 = AperFluxErr[Nap*Ncol + 4];
+    catalog->lensing[i].sF_ApR7 = AperFluxStd[Nap*Ncol + 4];
+    catalog->lensing[i].fF_ApR7 = AperFill   [Nap*Ncol + 4];
     Nap ++;
   }
+  catalog->Nlensing = Nap;
+
+  gfits_free_table (&table);
+  free (AperFlux);
+  free (AperFluxErr);
+  free (AperFluxStd);
+  free (AperFill);
+  free (RadID);
 
   return TRUE;
