Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/SEDops.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/SEDops.c	(revision 35598)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/SEDops.c	(revision 35599)
@@ -86,5 +86,5 @@
 int SEDfitInit (SEDtable *table) {
 
-  Xgraph = KiiOpen ("kapa", "sedstar");
+  Xgraph = KapaOpen ("kapa", "sedstar");
   KapaInitGraph (&graphdata);
   SetLimitsRaw (table[0].wavecode, NULL, table[0].Nfilter, &graphdata);
@@ -114,5 +114,5 @@
   free (fitmags);
   free (fiterrs);
-  KiiClose (Xgraph);
+  KapaClose (Xgraph);
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/airmass.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/airmass.c	(revision 35598)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/airmass.c	(revision 35599)
@@ -6,4 +6,6 @@
   AirmassQuality = quality;
 }
+
+static int Nbad_airmass = 0;
 
 float airmass (float secz_image, double ra, double dec, double st, double latitude) {
@@ -23,4 +25,18 @@
   cosz = sin (rdec) * sin (rlat) + cos (rdec) * cos (RAD_DEG*hour) * cos (rlat);
   secz = 1.000 / cosz;
+  
+  if (!isfinite(secz)) {
+    Nbad_airmass ++;
+  }
+  if (Nbad_airmass > 1) {
+    fprintf (stderr, "*** WARNING *** NaN airmass for detection\n");
+    fprintf (stderr, "*** ra, dec : %f, %f | st : %f | lat : %f | cosz : %f\n", ra, dec, st, latitude, cosz);
+  }
+  if (Nbad_airmass > 10) {
+    fprintf (stderr, "*** ERROR *** more than 10 NaN airmass values for detections, giving up\n");
+    fprintf (stderr, " (use -quick-airmass to use image airmass)\n");
+    exit (2);
+  }
+
   return (secz);
 }
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/mkcmf.c	(revision 35598)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/mkcmf.c	(revision 35599)
@@ -184,4 +184,12 @@
   }
 
+  // init the random seed
+  { 
+    struct timeval now;
+    gettimeofday (&now, NULL);
+    long A = now.tv_sec + now.tv_usec * 1000000;
+    srand48(A);
+  }
+    
   /* bore site center guess */
   strcpy (coords.ctype, "DEC--TAN");
@@ -379,5 +387,4 @@
  
   int i;
-  long A, B;
   double val, x, dx, dx1, dx2, dx3, df;
   double mean, sigma;
@@ -386,9 +393,9 @@
   if (Ngaussint == Nbin) return;
 
-  A = time(NULL);
-  // XXX this is expensive if called a lot (1 sec min)
-  // for (B = 0; A == time(NULL); B++);
-  B = A + 10000;
-  srand48(B);
+  // A = time(NULL);
+  // // XXX this is expensive if called a lot (1 sec min)
+  // // for (B = 0; A == time(NULL); B++);
+  // B = A + 10000;
+  // srand48(B);
  
   Ngaussint = Nbin;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/test/relphot.dvo
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/test/relphot.dvo	(revision 35598)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/test/relphot.dvo	(revision 35599)
@@ -38,7 +38,8 @@
     mkinput $offset:$i
     exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
-    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
+    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
   end
 
+  echo relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0
   exec relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0 >& /dev/null
 
@@ -52,6 +53,6 @@
   end
 
-  exec rm test.cmf test.in.txt
-  exec rm -r catdir.test
+  #exec rm test.cmf test.in.txt
+  #exec rm -r catdir.test
 
   tapDONE
