IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30118


Ignore:
Timestamp:
Dec 20, 2010, 2:30:45 PM (15 years ago)
Author:
watersc1
Message:

Attempting to bring branch in sync with trunk

Location:
branches/czw_branch/20101203
Files:
16 deleted
246 edited
39 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/Ohana/src/addstar/Makefile

    r27582 r30118  
    7272$(SRC)/replace_match.$(ARCH).o \
    7373$(SRC)/resort_catalog.$(ARCH).o \
     74$(SRC)/resort_threaded.$(ARCH).o \
     75$(SRC)/resort_unthreaded.$(ARCH).o \
    7476$(SRC)/StarOps.$(ARCH).o \
    7577$(SRC)/ReadStarsFITS.$(ARCH).o \
  • branches/czw_branch/20101203/Ohana/src/addstar/include/addstar.h

    r29541 r30118  
    125125float   ZPT_ERR_PHU;
    126126
     127int     OLD_RESORT;
     128
    127129// carries the mosaic into gstars
    128130
     
    135137double MIN_FWHM_X;
    136138double MIN_FWHM_Y;
     139int    NTHREADS;
    137140
    138141/* modify server behavior (make this an addstar cleanup mode?) */
     
    207210Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
    208211int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
     212int        resort_threaded        PROTO((AddstarClientOptions *options, SkyTable *sky));
     213int        resort_unthreaded      PROTO((AddstarClientOptions *options, SkyTable *sky));
    209214void       resort_catalog         PROTO((Catalog *catalog));
     215void       resort_catalog_old     PROTO((Catalog *catalog));
    210216Stars     *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader, unsigned int *nstars));
    211217Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
  • branches/czw_branch/20101203/Ohana/src/addstar/src/ReadStarsFITS.c

    r29541 r30118  
    2222
    2323  /* load the table data */
    24   if (!gfits_fread_ftable_data (f, &table)) {
     24  if (!gfits_fread_ftable_data (f, &table, FALSE)) {
    2525    fprintf (stderr, "ERROR: can't read table header\n");
    2626    exit (1);
  • branches/czw_branch/20101203/Ohana/src/addstar/src/ReadStarsSDSS.c

    r28939 r30118  
    6060
    6161  /* load the table data */
    62   if (!gfits_fread_ftable_data (f, &table)) {
     62  if (!gfits_fread_ftable_data (f, &table, FALSE)) {
    6363    fprintf (stderr, "ERROR: can't read table header\n");
    6464    exit (1);
  • branches/czw_branch/20101203/Ohana/src/addstar/src/addstar.c

    r28241 r30118  
    3434  SkyTableSetFilenames (sky, CATDIR, "cpt");
    3535 
     36  if (options.mode == M_RESORT) {
     37    if (NTHREADS == 0) {
     38      resort_unthreaded (&options, sky);
     39    } else {
     40      resort_threaded (&options, sky);
     41    }
     42    exit (0);
     43  }
     44
    3645  stars = NULL;
    3746
     
    157166        }
    158167
    159         resort_catalog (&catalog);
     168        if (OLD_RESORT) {
     169          resort_catalog_old (&catalog);
     170        } else {
     171          resort_catalog (&catalog);
     172        }
    160173        Nsubset = 1;
    161174        break;
  • branches/czw_branch/20101203/Ohana/src/addstar/src/args.c

    r27392 r30118  
    3434    remove_argument (N, &argc, argv);
    3535  }
     36  OLD_RESORT = FALSE;
     37  if ((N = get_argument (argc, argv, "-old-resort"))) {
     38    remove_argument (N, &argc, argv);
     39    OLD_RESORT = TRUE;
     40  }
    3641  if ((N = get_argument (argc, argv, "-fakeimage"))) {
    3742    options.mode = M_FAKEIMAGE;
     
    6267    remove_argument (N, &argc, argv);
    6368    PMM_CCD_TABLE = strcreate (argv[N]);
     69    remove_argument (N, &argc, argv);
     70  }
     71
     72  // number of worker threads for resort (must have at least one worker thread)
     73  NTHREADS = 0;
     74  if ((N = get_argument (argc, argv, "-threads"))) {
     75    remove_argument (N, &argc, argv);
     76    NTHREADS = MAX(0, atoi (argv[N]));
    6477    remove_argument (N, &argc, argv);
    6578  }
  • branches/czw_branch/20101203/Ohana/src/addstar/src/resort_catalog.c

    r27435 r30118  
    11# include "addstar.h"
    22
    3 void resort_catalog (Catalog *catalog) {
     3void resort_catalog_old (Catalog *catalog) {
    44
    55  off_t *next_meas;
     
    2828  return;
    2929}
     30
     31# define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); }
     32# define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }
     33
     34// sort the measure Sequence based on the average Sequence entries
     35void SortAveMeasMatch (off_t *MEAS, off_t *AVE, off_t N) {
     36
     37# define SWAPFUNC(A,B){ off_t tmp_meas; off_t tmp_ave;  \
     38    tmp_meas = MEAS[A]; MEAS[A] = MEAS[B]; MEAS[B] = tmp_meas;          \
     39    tmp_ave  = AVE[A];  AVE[A]  = AVE[B];  AVE[B]  = tmp_ave;           \
     40  }
     41# define COMPARE(A,B)(MEAS[A] < MEAS[B])
     42  OHANA_SORT (N, COMPARE, SWAPFUNC);
     43# undef SWAPFUNC
     44# undef COMPARE
     45}
     46
     47# define MARKTIME(MSG,...) { \
     48  float dtime; \
     49  gettimeofday (&stop, (void *) NULL); \
     50  dtime = DTIME (stop, start); start = stop; \
     51  fprintf (stderr, MSG, __VA_ARGS__); }
     52
     53// XXX : where is the time going?  perhaps the ALLOCATE?
     54// XXX : I don't thnk his is getting the right answer yet.
     55
     56void resort_catalog (Catalog *catalog) {
     57
     58  off_t Naverage, Nmeasure;
     59  Measure *measure;
     60  Average *average;
     61  off_t i, j, N, currentAve;
     62
     63  off_t *measureSeq = NULL;
     64  off_t *averageSeq = NULL;
     65  Measure *measureTMP = NULL;
     66
     67  if (catalog[0].sorted == TRUE) return;
     68
     69  // struct timeval start, stop;
     70  // gettimeofday (&start, NULL);
     71
     72  /* internal counters */
     73  Nmeasure = catalog[0].Nmeasure;
     74  Naverage = catalog[0].Naverage;
     75
     76  measure = catalog[0].measure;
     77  average = catalog[0].average;
     78 
     79  // we have a table of average objects and an unsorted table of measurements.  each measurement
     80  // has a reference to the average object sequence (as well as an ID)
     81  // measure[i].averef -> average[averef]
     82  // measure[i].objID = average[averef].objID
     83  // measure[i].catID = average[averef].catID
     84
     85  // we want a sorted measure array with all averef entries in sequence
     86
     87  ALLOCATE (measureSeq, off_t,   Nmeasure);
     88  ALLOCATE (averageSeq, off_t,   Nmeasure);
     89
     90  for (i = 0; i < Nmeasure; i++) {
     91    measureSeq[i] = i;
     92    averageSeq[i] = measure[i].averef;
     93   
     94    myAssert(average[averageSeq[i]].objID == measure[measureSeq[i]].objID, "object / detection mismatch");
     95    myAssert(average[averageSeq[i]].catID == measure[measureSeq[i]].catID, "object / detection mismatch");
     96  }
     97 
     98  SortAveMeasMatch(measureSeq, averageSeq, Nmeasure);
     99  // MARKTIME("sort : %f sec\n", dtime);
     100
     101  // copy the measurements in the sorted order
     102  ALLOCATE (measureTMP, Measure, Nmeasure);
     103  for (i = 0; i < Nmeasure; i++) {
     104    j = measureSeq[i];
     105    measureTMP[i] = measure[j];
     106  }
     107  // MARKTIME("assign measure : %f sec\n", dtime);
     108
     109  // update the values of average.measureOffset and average.Nmeasure
     110  FREE(measure);
     111  catalog[0].measure = measureTMP;
     112
     113  N = 0;
     114  currentAve = averageSeq[0];
     115  average[currentAve].measureOffset = 0;
     116  for (i = 0; i < Nmeasure; i++) {
     117    if (averageSeq[i] != currentAve) {
     118      average[currentAve].Nmeasure = N;
     119      N = 0;
     120      currentAve = averageSeq[i];
     121      average[currentAve].measureOffset = i;
     122    }
     123    N++;
     124  }
     125  N++;
     126  average[currentAve].Nmeasure = N;
     127  // MARKTIME("update Nmeasure : %f sec\n", dtime);
     128
     129  // MARKTIME("  match time %9.4f sec for %7lld measures, %6lld average\n", dtime, (long long) Nmeasure, (long long) Naverage);
     130
     131  FREE (measureSeq);
     132  FREE (averageSeq);
     133
     134  return;
     135}
     136
  • branches/czw_branch/20101203/Ohana/src/addstar/test/dvomerge.dvo

    r29001 r30118  
    44
    55# create 2 populated catdirs, each with a couple of cmf files
    6 macro test.dvomerge.update
     6macro test.dvomerge.continue
    77
    88  tapPLAN 51
     
    1616
    1717  mkinput
     18  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec 10.0 20.0
     19  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     20
     21  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec 10.0 20.0
     22  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     23
     24  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec 9.9 20.0
     25  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     26
     27  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec 9.9 20.0
     28  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     29
     30  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 05:00:00 -radec 10.0 19.9
     31  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     32
     33  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 06:00:00 -radec 10.0 19.9
     34  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     35
     36  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 07:00:00 -radec 9.9 19.9
     37  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     38
     39  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 08:00:00 -radec 9.9 19.9
     40  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     41
     42  break
     43
     44  exec rsync -auc catdir.test2/ catdir.test3/
     45
     46  date -var t1 -seconds -reftime 1276000000
     47  exec dvomerge catdir.test1 into catdir.test3
     48  date -var t2 -seconds -reftime 1276000000
     49  echo "merge time: {$t2 - $t1}"
     50
     51  catdir catdir.test3
     52  skyregion {$RA-1} {$RA+1} {$DEC-1} {$DEC+1}
     53  mextract ra dec mag
     54  create n 0 ra[]
     55  subset r0 = ra if (n % 4 == 0)
     56  subset r1 = ra if (n % 4 == 1)
     57  subset r2 = ra if (n % 4 == 2)
     58  subset r3 = ra if (n % 4 == 3)
     59
     60  catdir catdir.test1/
     61  mextract RA DEC MAG
     62  create N 0 RA[]
     63  subset R0 = RA if (N % 2 == 0)
     64  subset R1 = RA if (N % 2 == 1)
     65
     66  set dr0 = r0 - R0
     67  vstat -q dr0
     68  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
     69  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
     70
     71  set dr1 = r1 - R1
     72  vstat -q dr1
     73  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
     74  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
     75
     76  catdir catdir.test2/
     77  mextract RA DEC MAG
     78  create N 0 RA[]
     79  subset R2 = RA if (N % 2 == 0)
     80  subset R3 = RA if (N % 2 == 1)
     81
     82  set dr2 = r2 - R2
     83  vstat -q dr2
     84  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
     85  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
     86
     87  set dr3 = r3 - R3
     88  vstat -q dr3
     89  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
     90  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
     91
     92  # check on updates to imageID
     93  catdir catdir.test3
     94  imextract imageID
     95  sort imageID
     96  tapOK {imageID[]  == 4} "image IDs exist"
     97  tapOK {imageID[0] == 1} "updated image IDs"
     98  tapOK {imageID[1] == 2} "updated image IDs"
     99  tapOK {imageID[2] == 3} "updated image IDs"
     100  tapOK {imageID[3] == 4} "updated image IDs"
     101
     102  catdir catdir.test3
     103  mextract imageID, time
     104  set id = imageID
     105  set t = time
     106  imextract imageID, time
     107
     108  for i 0 time[]
     109    subset T = t if (id == imageID[$i])
     110    set dT = T - time[$i]
     111    vstat dT
     112    tapOK {abs($MEAN)  < 0.00001} "time for measure ID $i (MEAN)"
     113    tapOK {abs($SIGMA) < 0.00001} "time for measure ID $i (SIGMA)"
     114  end
     115
     116  # exec rm test.in.txt test.cmf
     117  # exec rm -rf catdir.test1
     118  # exec rm -rf catdir.test2
     119  # exec rm -rf catdir.test3
     120
     121  tapDONE
     122end
     123
     124# create 2 populated catdirs, each with a couple of cmf files
     125macro test.dvomerge.update
     126
     127  tapPLAN 51
     128
     129  exec rm -rf catdir.test1
     130  exec rm -rf catdir.test2
     131  exec rm -rf catdir.test3
     132
     133  $RA = 10.0
     134  $DEC = 20.0
     135
     136  mkinput
    18137  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
    19138  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
     
    27146  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
    28147  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
     148
     149  break
    29150
    30151  exec rsync -auc catdir.test2/ catdir.test3/
  • branches/czw_branch/20101203/Ohana/src/dvomerge/Makefile

    r29001 r30118  
    2222all: dvomerge dvoconvert dvosecfilt
    2323
     24#  $(SRC)/dvomergeContinue.$(ARCH).o
     25
    2426DVOMERGE = \
    2527$(SRC)/dvomerge.$(ARCH).o \
    2628$(SRC)/dvomergeUpdate.$(ARCH).o \
    2729$(SRC)/dvomergeCreate.$(ARCH).o \
     30$(SRC)/dvomergeUpdate_threaded.$(ARCH).o \
     31$(SRC)/dvomergeFromList.$(ARCH).o \
     32$(SRC)/dvomergeImageIDs.$(ARCH).o \
    2833$(SRC)/dvo_image_merge_dbs.$(ARCH).o \
    2934$(SRC)/SetSignals.$(ARCH).o \
     
    7075$(BIN)/dvosecfilt.$(ARCH) : $(DVOSECFILT)
    7176
    72 INSTALL = dvomerge dvoconvert dvosecfilt
     77DVOREPAIR = \
     78$(SRC)/dvorepair.$(ARCH).o \
     79$(SRC)/dvorepairFixCPT.$(ARCH).o \
     80$(SRC)/dvorepairImagesVsMeasures.$(ARCH).o \
     81$(SRC)/dvorepairDeleteImageList.$(ARCH).o \
     82$(SRC)/dvorepairFixImages.$(ARCH).o \
     83$(SRC)/psps_ids.$(ARCH).o \
     84$(SRC)/LoadImages.$(ARCH).o \
     85$(SRC)/ReadDeleteList.$(ARCH).o \
     86$(SRC)/match_image.$(ARCH).o \
     87$(SRC)/help.$(ARCH).o \
     88$(SRC)/ImageOps.$(ARCH).o
     89
     90$(DVOREPAIR)  : $(INC)/dvomerge.h
     91
     92$(BIN)/dvorepair.$(ARCH) : $(DVOREPAIR)
     93
     94DVOVERIFY = \
     95$(SRC)/dvoverify.$(ARCH).o
     96
     97$(DVOVERIFY)  : $(INC)/dvomerge.h
     98
     99$(BIN)/dvoverify.$(ARCH) : $(DVOVERIFY)
     100
     101INSTALL = dvomerge dvoconvert dvosecfilt dvorepair dvoverify
    73102
    74103# dependancy rules for binary code #########################
  • branches/czw_branch/20101203/Ohana/src/dvomerge/include/dvomerge.h

    r29001 r30118  
    1717# include <glob.h>
    1818
     19# define myAbort(MSG) { fprintf (stderr, "%s\n", MSG); abort(); }
     20# define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }
     21
    1922int    VERBOSE;
    2023char   CATDIR[256];
     
    2528float  RADIUS;
    2629int    SKY_DEPTH;
     30int    NTHREADS;
    2731char   *ALTERNATE_PHOTCODE_FILE;
    2832
     
    6569SkyList   *SkyTablePopulatedList_old  PROTO((SkyTable *sky, off_t Ns, off_t Ne));
    6670
    67 int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode));
     71int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt));
    6872
    6973int        merge_catalogs_new     PROTO((SkyRegion *region, Catalog *output, Catalog *input, int *secflitMap));
     
    8690off_t      dvo_map_image_ID       PROTO((IDmapType *IDmap, off_t oldID));
    8791int        dvo_update_image_IDs   PROTO((IDmapType *IDmap, Catalog *catalog));
     92
     93// dvorepair prototypes
     94Image     *LoadImages             PROTO((FITS_DB *db, char *filename, off_t *Nimage));
     95Image     *MatchImage             PROTO((Image *image, off_t Nimage, unsigned int time, short int source, unsigned int imageID));
     96off_t      match_image            PROTO((Image *image, off_t Nimage, unsigned int T, short int S));
     97
     98int        SaveImages             PROTO((FITS_DB *oldDB, char *filename, Image *imagesOut, off_t Nout));
     99
     100int        dvorepairFixCPT        PROTO((int argc, char **argv));
     101int        dvorepairImagesVsMeasures PROTO((int argc, char **argv));
     102int        dvorepairDeleteImageList PROTO((int argc, char **argv));
     103int        dvorepairFixImages     PROTO((int argc, char **argv));
     104
     105int       *ReadDeleteList         PROTO((char *filename, int *nindex));
     106int        RepairTableCPT         PROTO((char *cptFilenameSrc, char *cptFilenameTgt, char *cpsFilenameSrc, char *cpsFilenameTgt, Measure *measure, off_t Nmeasure, Image *image, off_t Nimage, char catformat));
     107void       dvorepair_help         PROTO((int argc, char **argv));
     108
     109off_t      getTgtIndex            PROTO((e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt));
     110void       SortTgtByTimes         PROTO((e_time *S, off_t *I, short *C, off_t N));
     111int        dvo_image_match_dbs    PROTO((IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src));
     112int        dvomergeImagesGetMap   PROTO((IDmapType *IDmap, char *input, char *output));
     113int        dvomergeFromList       PROTO((int argc, char **argv));
     114int        dvomergeUpdate_threaded PROTO((int argc, char **argv));
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/LoadCatalog.c

    r28329 r30118  
    11# include "dvomerge.h"
    22
    3 int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode) {
     3int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt) {
    44
    55    // set the parameters which guide catalog open/load/create
    66    catalog[0].filename  = filename;
    7     catalog[0].Nsecfilt  = GetPhotcodeNsecfilt ();
     7    catalog[0].Nsecfilt  = Nsecfilt;
    88
    99    // always load all of the data (if any exists)
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/args.c

    r29001 r30118  
    1515    remove_argument (N, argc, argv);
    1616    ALTERNATE_PHOTCODE_FILE = strdup(argv[N]);
     17    remove_argument (N, argc, argv);
     18  }
     19
     20  NTHREADS = 0;
     21  if ((N = get_argument (*argc, argv, "-threads"))) {
     22    remove_argument (N, argc, argv);
     23    NTHREADS = MAX(0, atoi(argv[N]));
    1724    remove_argument (N, argc, argv);
    1825  }
     
    3643  }
    3744
    38   if ((*argc != 6) && (*argc != 4)) dvomerge_usage();
     45  if ((*argc < 4) || (*argc > 6)) dvomerge_usage();
    3946  return TRUE;
    4047}
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r29001 r30118  
    22
    33void sort_IDmap (IDmapType *IDmap);
     4
     5off_t getTgtIndex (e_time start, e_time stop, short photcode, off_t *TgtIndex, e_time *TgtTimes, short *TgtCodes, off_t NimagesTgt) {
     6
     7  // use bisection to find the starting entry by time
     8
     9  off_t Nlo, Nhi, N;
     10
     11  // find the last TGT before start
     12  Nlo = 0; Nhi = NimagesTgt;
     13  while (Nhi - Nlo > 10) {
     14    N = 0.5*(Nlo + Nhi);
     15    if (TgtTimes[N] < start) {
     16      Nlo = MAX(N, 0);
     17    } else {
     18      Nhi = MIN(N + 1, NimagesTgt);
     19    }
     20  }
     21
     22  // check for the matched mosaic starting from Nlo
     23  // we may have to go much beyond Nlo since stop is not sorted
     24  // can we use a sorted version of stop to check when we are beyond the valid range??
     25  for (N = Nlo; N < NimagesTgt; N++) {
     26    if (TgtTimes[N] < start) continue;
     27    if (TgtTimes[N] > stop) return (-1);
     28    if (TgtCodes[N] != photcode) continue;
     29    return (TgtIndex[N]);
     30  }
     31  return (-1);
     32}
     33
     34// sort two times vectors and an index by first time vector
     35void SortTgtByTimes (e_time *S, off_t *I, short *C, off_t N) {
     36
     37# define SWAPFUNC(A,B){ e_time tmp_t; off_t tmp_i; short tmp_c;         \
     38  tmp_t = S[A]; S[A] = S[B]; S[B] = tmp_t; \
     39  tmp_i = I[A]; I[A] = I[B]; I[B] = tmp_i; \
     40  tmp_c = C[A]; C[A] = C[B]; C[B] = tmp_c; \
     41}
     42# define COMPARE(A,B)(S[A] < S[B])
     43
     44  OHANA_SORT (N, COMPARE, SWAPFUNC);
     45
     46# undef SWAPFUNC
     47# undef COMPARE
     48
     49}
     50
     51// we have two tables; 'tgt' contains some exposures from 'src' : find them and match a map
     52int dvo_image_match_dbs (IDmapType *IDmap, FITS_DB *tgt, FITS_DB *src) {
     53
     54  Image *imagesSrc, *imagesTgt;
     55  off_t NimagesSrc, NimagesTgt;
     56  off_t iSrc, iTgt;
     57  off_t  *TgtIndex;
     58  e_time *TgtTimes;
     59  short  *TgtCodes;
     60 
     61  imagesSrc = gfits_table_get_Image (&src[0].ftable, &NimagesSrc, &src[0].swapped);
     62  if (!imagesSrc) {
     63    fprintf (stderr, "ERROR: failed to read images from src\n");
     64    exit (2);
     65  }
     66
     67  imagesTgt = gfits_table_get_Image (&tgt[0].ftable, &NimagesTgt, &tgt[0].swapped);
     68  if (!imagesTgt) {
     69    fprintf (stderr, "ERROR: failed to read images from tgt\n");
     70    exit (2);
     71  }
     72
     73  ALLOCATE (IDmap->old, off_t, NimagesSrc);
     74  ALLOCATE (IDmap->new, off_t, NimagesSrc);
     75  IDmap->Nmap = NimagesSrc;
     76
     77  // match by time and photcode
     78  ALLOCATE (TgtIndex, off_t,  NimagesTgt);
     79  ALLOCATE (TgtTimes, e_time, NimagesTgt);
     80  ALLOCATE (TgtCodes, short,  NimagesTgt);
     81
     82  // save the Index, Times, Codes for all TGT images
     83  for (iTgt = 0; iTgt < NimagesTgt; iTgt++) {
     84    TgtIndex[iTgt] = iTgt;
     85    TgtTimes[iTgt] = imagesTgt[iTgt].tzero;
     86    TgtCodes[iTgt] = imagesTgt[iTgt].photcode;
     87  }
     88
     89  // sort the index, start, and stop by the start times:
     90  SortTgtByTimes (TgtTimes, TgtIndex, TgtCodes, NimagesTgt);
     91
     92  for (iSrc = 0; iSrc < NimagesSrc; iSrc++) {
     93    iTgt = getTgtIndex (imagesSrc[iSrc].tzero, imagesSrc[iSrc].tzero + (int) imagesSrc[iSrc].exptime, imagesSrc[iSrc].photcode, TgtIndex, TgtTimes, TgtCodes, NimagesTgt);
     94    if (iTgt < 0) Shutdown ("failure to match images: %s\n", imagesSrc[iSrc].name);
     95    IDmap[0].old[iSrc] = imagesSrc[iSrc].imageID;
     96    IDmap[0].new[iSrc] = imagesTgt[iTgt].imageID;
     97  }
     98
     99  FREE(TgtIndex);
     100  FREE(TgtTimes);
     101  FREE(TgtCodes);
     102
     103  // sort IDmap->old,new on the basis of IDmap->old:
     104  sort_IDmap (IDmap);
     105
     106  return TRUE;
     107}
    4108
    5109// merge db2 into db1
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvoconvert.c

    r29001 r30118  
    66  char filename[256], *input, *output;
    77
    8   int depth;
     8  int depth, Nsecfilt;
    99  off_t i, j, Ns, Ne;
    1010  SkyTable *outsky, *insky;
     
    3232      exit (1);
    3333    }
     34    Nsecfilt = GetPhotcodeNsecfilt();
     35
    3436    // save the photcodes in the output catdir
    3537    sprintf (filename, "%s/Photcodes.dat", output);
     
    6769
    6870    // load / create output catalog
    69     LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
     71    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", Nsecfilt);
    7072
    7173    // combine only tables at equal or larger depth
     
    7779
    7880      // load input catalog
    79       LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
     81      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", Nsecfilt);
    8082
    8183      // skip empty input catalogs
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvomerge.c

    r28327 r30118  
    88  dvomerge_args (&argc, argv);
    99
    10   // XXX require both inputs to be sorted?
    11 
    12   if (argc == 6) dvomergeCreate (argc, argv);
    13   if (argc == 4) dvomergeUpdate (argc, argv);
     10  if (argc == 6) {
     11    if (!strcasecmp (argv[2], "and")) {
     12      dvomergeCreate (argc, argv);
     13    } else {
     14      dvomergeFromList (argc, argv);
     15    }
     16  }
     17  if ((argc == 4) || (argc == 5)) {
     18    if (NTHREADS) {
     19      dvomergeUpdate_threaded (argc, argv);
     20    } else {
     21      dvomergeUpdate (argc, argv);
     22    }
     23  }
    1424  dvomerge_usage();
    1525  exit (2); // cannot reach here.
     
    1828/* we have two possible modes of operation:
    1929
    20    Create : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs
    21    Update : dvomerge (in) into (out)          -- merge a new db into an existing db
     30   Create   : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs
     31   Update   : dvomerge (in) into (out)          -- merge a new db into an existing db
     32   Continue : dvomerge (in) into (out) continue -- merge a new db into an existing db
    2233
    2334*/
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvomergeCreate.c

    r28855 r30118  
    1515  char *input1, *input2, *output;
    1616  IDmapType IDmap1, IDmap2;
     17  int NsecfiltInput1, NsecfiltInput2, NsecfiltOutput;
    1718
    1819  if (strcasecmp (argv[2], "and")) dvomerge_usage();
     
    3940  }
    4041  input1Photcodes = GetPhotcodeTable();
     42  NsecfiltInput1 = GetPhotcodeNsecfilt();
    4143
    4244  // Read the input2 photcodes
     
    4850  }
    4951  input2Photcodes = GetPhotcodeTable();
     52  NsecfiltInput2 = GetPhotcodeNsecfilt();
    5053
    5154  if (ALTERNATE_PHOTCODE_FILE) {
     
    6063    }
    6164    outputPhotcodes = GetPhotcodeTable();
     65    NsecfiltOutput = GetPhotcodeNsecfilt();
    6266
    6367    secfiltMap1 = GetSecFiltMap(outputPhotcodes, input1Photcodes);
     
    7478    outputPhotcodes = input1Photcodes;
    7579    codesFilename = filename1;
     80    NsecfiltOutput = NsecfiltInput1;
    7681    // secfitMap1 can remain NULL since input1 defines the set of codes
    7782  }
     
    8489  }
    8590
     91  // trigger any dependencies, if any
     92  SetPhotcodeTable(NULL);
     93
    8694  // save the output photcodes in the output catdir
    87   SetPhotcodeTable(outputPhotcodes);
     95  // SetPhotcodeTable(outputPhotcodes);
    8896  sprintf (filename, "%s/Photcodes.dat", output);
    8997  if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) {
     
    121129    if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
    122130
    123     if (outputPhotcodes) {
    124         SetPhotcodeTable(outputPhotcodes);
    125     }
     131    // if (outputPhotcodes) {
     132    //     SetPhotcodeTable(outputPhotcodes);
     133    // }
    126134    // load / create output catalog
    127     LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
    128 
    129     if (input1Photcodes) {
    130         SetPhotcodeTable(input1Photcodes);
    131     }
     135    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", NsecfiltOutput);
     136
     137    // if (input1Photcodes) {
     138    // SetPhotcodeTable(input1Photcodes);
     139    // }
    132140    // combine only tables at equal or larger depth
    133141     
     
    138146
    139147      // load input catalog (1)
    140       LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
     148      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput1);
    141149
    142150      // skip empty input catalogs
     
    153161    SkyListFree (inlist);
    154162
    155     if (input2Photcodes) {
    156       SetPhotcodeTable(input2Photcodes);
    157     }
     163    // if (input2Photcodes) {
     164    //   SetPhotcodeTable(input2Photcodes);
     165    // }
    158166
    159167    // load in all of the tables from input2 for this region
     
    163171
    164172      // load input catalog (2)
    165       LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
     173      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput2);
    166174
    167175      // skip empty input catalogs
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r29001 r30118  
    33int dvomergeUpdate (int argc, char **argv) {
    44
    5   int depth;
     5  int depth, CONTINUE;
    66  off_t i, j, Ns, Ne;
    77  SkyTable *outsky, *insky;
     
    1313  PhotCodeData *outputPhotcodes;
    1414  int *secfiltMap = NULL;
     15  int NsecfiltInput, NsecfiltOutput;
    1516
     17  double dtime;
     18  struct timeval start, stop;
     19  gettimeofday (&start, NULL);
     20
     21  CONTINUE = FALSE;
    1622  if (strcasecmp (argv[2], "into")) dvomerge_usage();
     23  if (argc == 5) {
     24    if (strcasecmp (argv[4], "continue")) dvomerge_usage();
     25    CONTINUE = TRUE;
     26  }
    1727
    1828  input  = argv[1];
     
    3141  }     
    3242  inputPhotcodes = GetPhotcodeTable();
     43  NsecfiltInput = GetPhotcodeNsecfilt();
    3344
    3445  // since we are merging the input db into the output db, the output defines the photcode
     
    4152
    4253    outputPhotcodes = GetPhotcodeTable();
     54    NsecfiltOutput = GetPhotcodeNsecfilt();
    4355
    4456    secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes);
     
    5062    fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input);
    5163    outputPhotcodes = inputPhotcodes;
     64    NsecfiltOutput = NsecfiltInput;
     65
    5266    if (!check_dir_access (output, VERBOSE)) {
    5367      fprintf (stderr, "error creating output database directory %s\n", output);
     
    6175  }
    6276
    63   dvomergeImagesUpdate (&IDmap, input, output);
     77  if (CONTINUE) {
     78    // need to determine the mapping from the input to the output images
     79    dvomergeImagesGetMap (&IDmap, input, output);
     80  } else {
     81    dvomergeImagesUpdate (&IDmap, input, output);
     82  }
    6483
    6584  // load the sky table for the existing database
     
    85104  depth = inlist[0].regions[Ns][0].depth;
    86105 
     106  SetPhotcodeTable(NULL);
     107
    87108  // loop over the populated input regions
    88109  for (i = 0; i < inlist[0].Nregions; i++) {
     
    90111    if (VERBOSE) fprintf (stderr, "input: %s\n", inlist[0].regions[i][0].name);
    91112
    92     SetPhotcodeTable(inputPhotcodes);
    93113    // load / create output catalog (if catalog does not exist, it will be created)
    94     LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r");
     114    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput);
    95115    // skip empty input catalogs
    96116    if (!incatalog.Naves_disk) {
     
    111131
    112132      // load input catalog
    113       SetPhotcodeTable(outputPhotcodes);
    114       LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w");
     133      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w", NsecfiltOutput);
    115134
    116135      dvo_update_image_IDs (&IDmap, &incatalog);
     
    121140      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    122141      SetProtect (TRUE);
    123       dvo_catalog_save (&outcatalog, VERBOSE);
     142      if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
     143        fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]);
     144        exit (1);
     145      }
    124146      SetProtect (FALSE);
    125147
     
    143165  }
    144166
     167  gettimeofday (&stop, NULL);
     168  dtime = DTIME (stop, start);
     169  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
     170
    145171  exit (0);
    146172}
    147 
    148 /*** update the image table ***/
    149 int dvomergeImagesUpdate (IDmapType *IDmap, char *input, char *output) {
    150 
    151   FITS_DB inDB;
    152   FITS_DB outDB;
    153   int    status;
    154 
    155   /*** load input1/Images.dat ***/
    156   sprintf (ImageCat, "%s/Images.dat", input);
    157   inDB.mode   = dvo_catalog_catmode (CATMODE);
    158   inDB.format = dvo_catalog_catformat (CATFORMAT);
    159   status       = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
    160   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);
    161 
    162   // load the image table
    163   if (inDB.dbstate == LCK_EMPTY) {
    164     // Shutdown ("can't find input image catalog %s", inDB.filename);
    165     IDmap->Nmap = 0;
    166     return TRUE;
    167   }
    168   if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {
    169     Shutdown ("can't read input image catalog %s", inDB.filename);
    170   }
    171 
    172   /*** load output/Images.dat ***/
    173   sprintf (ImageCat, "%s/Images.dat", output);
    174   outDB.mode   = dvo_catalog_catmode (CATMODE);
    175   outDB.format = dvo_catalog_catformat (CATFORMAT);
    176   status       = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
    177   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename);
    178 
    179   /* load the image table */
    180   if (outDB.dbstate == LCK_EMPTY) {
    181     dvo_image_create (&outDB, GetZeroPoint());
    182   } else {
    183     if (!dvo_image_load (&outDB, VERBOSE, TRUE)) {
    184       Shutdown ("can't read output image catalog %s", outDB.filename);
    185     }
    186   }
    187 
    188   // convert database table to internal structure & add to output image db
    189   dvo_image_merge_dbs(IDmap, &outDB, &inDB);
    190   dvo_image_unlock (&inDB); // unlock input
    191 
    192   SetProtect (TRUE);
    193   dvo_image_save (&outDB, VERBOSE);
    194   SetProtect (FALSE);
    195   dvo_image_unlock (&outDB); // unlock output
    196 
    197   return TRUE;
    198 }
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/dvoverify.c

    r29001 r30118  
    88*/
    99
     10int VerifyTableFile (char *filename);
     11
     12# define DEBUG 0
     13
    1014int main (int argc, char **argv) {
    1115
    12   char filename[256], *input, *output;
    13 
    14   int depth;
    15   off_t i, j, Ns, Ne;
    16   SkyTable *outsky, *insky;
     16  char filename[1024];
     17
     18  int N, Nbad;
     19  off_t i;
     20  SkyTable *insky;
    1721  SkyList *inlist;
    18   Catalog incatalog, outcatalog;
    19 
    20   SetSignals ();
    21   dvoconvert_help (argc, argv);
    22   ConfigInit (&argc, argv);
    23   dvoconvert_args (&argc, argv);
    24 
    25   if (strcasecmp (argv[2], "to")) dvoconvert_usage();
    26   input = argv[1];
    27   output = argv[3];
    28 
    29   // load input images, save to output images
    30   dvoConvert_copy_images (input, output);
    31 
    32   // copy photcode table
    33   {
    34     // the first input defines the photcode table & db layout
    35     sprintf (filename, "%s/Photcodes.dat", input);
    36     if (!LoadPhotcodes (filename, NULL, FALSE)) {
    37       fprintf (stderr, "error loading photcode table %s\n", filename);
    38       exit (1);
    39     }
    40     // save the photcodes in the output catdir
    41     sprintf (filename, "%s/Photcodes.dat", output);
    42     if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) {
    43       fprintf (stderr, "error creating output catdir %s\n", output);
    44       exit (1);
    45     }
    46     if (!SavePhotcodesFITS (filename)) {
    47       fprintf (stderr, "error saving photcode table %s\n", filename);
    48       exit (1);
    49     }
    50   }
    51 
    52   // copy skytable
    53   {
    54     // load the sky table for the existing database
    55     insky = SkyTableLoadOptimal (input, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
    56     SkyTableSetFilenames (insky, input, "cpt");
    57 
    58     // generate an output table populated at the desired depth
    59     // XXX force this to match the input?
    60     outsky = SkyTableLoadOptimal (output, NULL, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
    61     SkyTableSetFilenames (outsky, output, "cpt");
    62 
    63     SkyTablePopulatedRange (&Ns, &Ne, insky, 0);
    64     depth = insky[0].regions[Ns].depth;
    65     // XXX this seems to imply that insky is a uniform depth...
    66   }
    67 
    68   // loop over all input catalogs, save to output catalogs
    69   // loop over the populatable output regions
    70   for (i = 0; i < outsky[0].Nregions; i++) {
    71     if (!outsky[0].regions[i].table) continue;
    72     if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
    73 
    74     // load / create output catalog
    75     LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
    76 
    77     // combine only tables at equal or larger depth
    78      
    79     // load in all of the tables from input for this region
    80     inlist = SkyListByBounds (insky, depth, outsky[0].regions[i].Rmin, outsky[0].regions[i].Rmax, outsky[0].regions[i].Dmin, outsky[0].regions[i].Dmax);
    81     for (j = 0; j < inlist[0].Nregions; j++) {
    82       if (VERBOSE) fprintf (stderr, "input : %s\n", inlist[0].regions[j][0].name);
    83 
    84       // load input catalog
    85       LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
    86 
    87       // skip empty input catalogs
    88       if (!incatalog.Naves_disk) {
    89         dvo_catalog_unlock (&incatalog);
    90         dvo_catalog_free (&incatalog);
    91         continue;
    92       }
    93       merge_catalogs_new (&outsky[0].regions[i], &outcatalog, &incatalog);
    94       dvo_catalog_unlock (&incatalog);
    95       dvo_catalog_free (&incatalog);
    96     }
    97     SkyListFree (inlist);
    98 
    99     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    100     dvo_catalog_save (&outcatalog, VERBOSE);
    101     dvo_catalog_unlock (&outcatalog);
    102     dvo_catalog_free (&outcatalog);
    103   }
    104 
    105   // save the output sky table copy
    106   sprintf (filename, "%s/SkyTable.fits", output);
    107   check_file_access (filename, TRUE, TRUE, VERBOSE);
    108   if (!SkyTableSave (outsky, filename)) {
    109     fprintf (stderr, "ERROR: failed to save sky table for %s\n", output);
     22  SkyRegion UserPatch;
     23  // Catalog catalog;
     24
     25  // restrict to a portion of the sky
     26  UserPatch.Rmin = 0;
     27  UserPatch.Rmax = 360;
     28  UserPatch.Dmin = -90;
     29  UserPatch.Dmax = +90;
     30  if ((N = get_argument (argc, argv, "-region"))) {
     31    remove_argument (N, &argc, argv);
     32    UserPatch.Rmin = atof (argv[N]);
     33    remove_argument (N, &argc, argv);
     34    UserPatch.Rmax = atof (argv[N]);
     35    remove_argument (N, &argc, argv);
     36    UserPatch.Dmin = atof (argv[N]);
     37    remove_argument (N, &argc, argv);
     38    UserPatch.Dmax = atof (argv[N]);
     39    remove_argument (N, &argc, argv);
     40  }
     41
     42  if (argc != 2) {
     43    fprintf (stderr, "USAGE: dvoverify (catdir) [-region Rmin Rmax Dmin Dmax]\n");
     44    fprintf (stderr, "  catdir : database of interest\n");
     45    exit (2);
     46  }
     47
     48  char *catdir = argv[1];
     49
     50  Nbad = 0;
     51
     52  // XXX make this step optional
     53  if (1) {
     54    // check the photcode table
     55    sprintf (filename, "%s/Photcodes.dat", catdir);
     56    if (!VerifyTableFile (filename)) {
     57      Nbad ++;
     58    }
     59
     60    // check the skytable
     61    sprintf (filename, "%s/SkyTable.fits", catdir);
     62    if (!VerifyTableFile (filename)) {
     63      Nbad ++;
     64    }
     65
     66    // check the image table
     67    sprintf (filename, "%s/Images.dat", catdir);
     68    if (!VerifyTableFile (filename)) {
     69      Nbad ++;
     70    }
     71  }
     72
     73  // load the sky table for the existing database
     74  insky = SkyTableLoadOptimal (catdir, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
     75  myAssert(insky, "can't read SkyTable");
     76  SkyTableSetFilenames (insky, catdir, "cpt");
     77  inlist = SkyListByPatch (insky, -1, &UserPatch);
     78 
     79  // loop over all catalogs, save to output catalogs
     80  for (i = 0; i < inlist[0].Nregions; i++) {
     81    if (!inlist[0].regions[i][0].table) continue;
     82
     83    if (i % 1000 == 0) fprintf (stderr, ".");
     84
     85    sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);
     86    if (!VerifyTableFile (filename)) {
     87      Nbad ++;
     88    }
     89
     90    sprintf (filename, "%s/%s.cps", catdir, inlist[0].regions[i][0].name);
     91    if (!VerifyTableFile (filename)) {
     92      Nbad ++;
     93    }
     94
     95    sprintf (filename, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name);
     96    if (!VerifyTableFile (filename)) {
     97      Nbad ++;
     98    }
     99  }
     100
     101  if (Nbad > 0) {
     102    fprintf (stderr, "ERROR: %d files are bad\n", Nbad);
    110103    exit (1);
    111104  }
    112105
     106  fprintf (stderr, "SUCCESS: no files are bad\n");
    113107  exit (0);
    114108}
    115109
    116 int dvoConvert_copy_images (char *input, char *output) {
    117 
    118   FITS_DB inDB;
    119   FITS_DB outDB;
    120   int    status;
    121 
    122   Image *images;
    123   off_t Nimages;
    124   off_t ID;
    125 
    126   /*** load output/Images.dat ***/
    127   sprintf (ImageCat, "%s/Images.dat", output);
    128   outDB.mode   = dvo_catalog_catmode (CATMODE);
    129   outDB.format = dvo_catalog_catformat (CATFORMAT);
    130   status       = dvo_image_lock (&outDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
    131   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", outDB.filename);
    132 
    133   // output image table should not already exist
    134   if (outDB.dbstate != LCK_EMPTY) {
    135     Shutdown ("ERROR: image table %s already exists", outDB.filename);
    136   }
    137   dvo_image_create (&outDB, GetZeroPoint());
    138 
    139   /*** load input/Images.dat ***/
    140   sprintf (ImageCat, "%s/Images.dat", input);
    141   // inDB.mode   = dvo_catalog_catmode (CATMODE);
    142   // inDB.format = dvo_catalog_catformat (CATFORMAT);
    143   status       = dvo_image_lock (&inDB, ImageCat, 3600.0, LCK_XCLD);  // shorter timeout?
    144   if (!status) Shutdown ("ERROR: failure to lock image catalog %s", inDB.filename);
    145 
    146   // load the image table
    147   if (inDB.dbstate == LCK_EMPTY) {
    148     Shutdown ("can't find input image catalog %s", inDB.filename);
    149   }
    150   if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {
    151     Shutdown ("can't read input image catalog %s", inDB.filename);
    152   }
    153 
    154   // convert the raw image table to Image type (byteswap if needed)
    155   images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped);
    156   if (!images) {
    157     fprintf (stderr, "ERROR: failed to read images\n");
    158     exit (2);
    159   }
    160 
    161   // update additional metadata
    162   gfits_scan (&inDB.header, "IMAGEID", OFF_T_FMT, 1,  &ID);
    163   gfits_modify (&outDB.header, "NIMAGES", OFF_T_FMT, 1,  Nimages);
    164   gfits_modify (&outDB.header, "IMAGEID", OFF_T_FMT, 1,  ID);
    165 
    166   // copy input rows to output table
    167   gfits_add_rows (&outDB.ftable, (char *) images, Nimages, sizeof(Image));
    168 
    169   // write out the image table to disk
    170   SetProtect (TRUE);
    171   dvo_image_save (&outDB, VERBOSE);
    172   SetProtect (FALSE);
    173   dvo_image_unlock (&outDB); // unlock output
    174   dvo_image_unlock (&inDB); // unlock input1
    175 
     110// is this file a consistent FITS file?
     111int VerifyTableFile (char *filename) {
     112
     113  int status;
     114  off_t Nbytes;
     115  Header header;
     116
     117  struct stat fileStats;
     118  FILE *file;
     119
     120  // does the file exist?
     121  status = stat (filename, &fileStats);
     122  if (status) {
     123    // some error accessing the file.  there is only one acceptable error: file not found
     124    switch (errno) {
     125      case ENOENT:
     126        if (DEBUG) fprintf (stderr, "file does not exist, skipping %s\n", filename);
     127        return TRUE;
     128      case ENOMEM:
     129        fprintf (stderr, "Out of memory: %s\n", filename);
     130        return TRUE;
     131      case EACCES:
     132        fprintf (stderr, "Permission error on %s\n", filename);
     133        return FALSE;
     134      case EFAULT:
     135        fprintf (stderr, "Bad address: %s\n", filename);
     136        return FALSE;
     137      case ELOOP:
     138        fprintf (stderr, "Too many symbolic links encountered while traversing the path: %s\n", filename);
     139        return FALSE;
     140      case ENAMETOOLONG:
     141        fprintf (stderr, "File name too long: %s\n", filename);
     142        return FALSE;
     143      case ENOTDIR:
     144        fprintf (stderr, "A component of the path is not a directory: %s\n", filename);
     145        return FALSE;
     146      case EOVERFLOW:
     147        fprintf (stderr, "file too large for program version: %s\n", filename);
     148        return FALSE;
     149      default:
     150        fprintf (stderr, "unknown error: %s\n", filename);
     151        return FALSE;
     152    }
     153  }
     154
     155  // does it have any data?
     156  if (fileStats.st_size == 0) {
     157    fprintf (stderr, "file is empty: %s\n", filename);
     158    return FALSE;
     159  }
     160
     161  // can we open it?
     162  file = fopen(filename, "r");
     163  if (!file) {
     164    fprintf (stderr, "unable to open valid file: %s\n", filename);
     165    return FALSE;
     166  }
     167
     168  // scan all extentions
     169  Nbytes = 0;
     170  if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size);
     171  while (Nbytes < fileStats.st_size) {
     172
     173    // Check on the PHU
     174    if (!gfits_fread_header (file, &header)) {
     175      fprintf (stderr, "unable to read PHU header for %s\n", filename);
     176      fclose(file);
     177      return (FALSE);
     178    }
     179
     180    // move to TBL header
     181    Nbytes += header.datasize + gfits_data_size (&header);
     182    if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size);
     183    if (Nbytes > fileStats.st_size) {
     184      fprintf (stderr, "file is short ("OFF_T_FMT" vs "OFF_T_FMT"): %s\n", Nbytes, fileStats.st_size, filename);
     185      gfits_free_header(&header);
     186      fclose (file);
     187      return FALSE;
     188    }
     189    gfits_free_header(&header);
     190
     191    status = fseeko (file, Nbytes, SEEK_SET);
     192    if (status) {
     193      switch (errno) {
     194        case EBADF:
     195          fprintf (stderr, "something wrong with file handle: %s\n", filename);
     196          fclose (file);
     197          return FALSE;
     198        case EINVAL:
     199          fprintf (stderr, "invalid offset: %s\n", filename);
     200          fclose (file);
     201          return FALSE;
     202        default:
     203          fprintf (stderr, "other error in fseeko: %s\n", filename);
     204          fclose (file);
     205          return FALSE;
     206      }
     207    }
     208  }
     209  if (DEBUG) fprintf (stderr, "file is good: %s\n", filename);
     210  fclose (file);
    176211  return TRUE;
    177212}
     213
     214  // gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
     215  // gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows);
     216   
     217 
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/help.c

    r29001 r30118  
    44  fprintf (stderr, "USAGE: dvomerge (input1) and (input2) to (output)\n");
    55  fprintf (stderr, "   OR: dvomerge (input) into (output)\n");
     6  fprintf (stderr, "   OR: dvomerge (input) into (output) continue\n");
     7  fprintf (stderr, "   OR: dvomerge (input) into (output) from (list)\n");
    68  fprintf (stderr, "   [-region Rmin Rmax Dmin Dmax]\n");
    79  exit (2);
     
    1719void dvosecfilt_usage(void) {
    1820
    19   fprintf (stderr, "USAGE: dvosecfilt (input) -photcodes (photcodes.txt)\n");
     21  fprintf (stderr, "USAGE: dvosecfilt (catdir) (Nsecfilt)\n");
    2022
    2123  exit (2);
     
    3335  fprintf (stderr, "USAGE\n");
    3436  fprintf (stderr, "  dvomerge (input1) and (input2) to (output)\n");
    35   fprintf (stderr, "  dvomerge (input) into (output)\n\n");
     37  fprintf (stderr, "  dvomerge (input) into (output)\n");
     38  fprintf (stderr, "  dvomerge (input) into (output) continue\n\n");
     39  fprintf (stderr, "  dvomerge (input) into (output) from (list)\n\n");
    3640  fprintf (stderr, "  merge DVO databases\n");
    3741  fprintf (stderr, "  optional flags:\n");
     
    3943  fprintf (stderr, "  -help                       : this list\n");
    4044  fprintf (stderr, "  -h                          : this list\n\n");
     45  fprintf (stderr, "  -region Rmin Rmax Dmin Dmax : region to merge\n\n");
    4146  exit (2);
    4247}
     
    7580
    7681  fprintf (stderr, "USAGE\n");
    77   fprintf (stderr, "  dvosecfilt (input) (Nsecfilt)\n\n");
     82  fprintf (stderr, "  dvosecfilt (catdir) (Nsecfilt)\n\n");
    7883
    79   fprintf (stderr, "  change number of secfilt entries in photcode table (updates secfilt tables only)\n");
     84  fprintf (stderr, "  change number of secfilt entries in photcode table (updates secfilt tables (cps), NSECFILT in cpt files)\n");
     85  fprintf (stderr, "  NOTE: the user must change the photcode table to reflect the change (use photcode-table -export / -import)\n");
    8086 
    8187  fprintf (stderr, "  optional flags:\n");
     
    8692}
    8793
     94void dvorepair_help (int argc, char **argv) {
     95
     96  /* check for help request */
     97  if (!argv) goto show_help;
     98  if (get_argument (argc, argv, "-help")) goto show_help;
     99  if (get_argument (argc, argv, "-h"))    goto show_help;
     100  if (argc < 2) goto show_help;
     101  return;
     102
     103show_help:
     104
     105  fprintf (stderr, "USAGE\n");
     106  fprintf (stderr, "  dvorepair -fix-cpt (images) (rootlist) - regenerate cpt & cps files from the cpm files\n");
     107  fprintf (stderr, "  dvorepair -images-vs-measures (catdir) (Ntol) - find images with too many missing detections\n");
     108  fprintf (stderr, "  dvorepair -delete-image-list (catdir) (deleteList) - delete a set of images based on image IDs (output from -images-vs-measures)\n");
     109  fprintf (stderr, "  dvorepair -fix-images (catdir) (deleteList) - delete a set of images based on image IDs (output from -images-vs-measures)\n");
     110  fprintf (stderr, "\n");
     111
     112  fprintf (stderr, "  optional flags:\n");
     113  fprintf (stderr, "  -help                       : this list\n");
     114  fprintf (stderr, "  -h                          : this list\n\n");
     115  exit (2);
     116}
     117
  • branches/czw_branch/20101203/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r29181 r30118  
    2828  unsigned int objID, catID;
    2929  Coords tcoords;
    30 
     30 
    3131  // struct timeval start, stop;
    3232  // gettimeofday (&start, (void *) NULL);
     
    240240    } else {
    241241      for (k = 0; k < NsecfiltIn; k++) {
     242        if (secfiltMap[k] < 0) continue;  // skip secfilt entries from input that are not in the output
     243
    242244        // index for this entry in output's secfilt list
    243245        int outputIndex = n * NsecfiltOut + secfiltMap[k];
     
    254256    i++;
    255257  }
    256   // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars\n", dtime, Nstars, Nave);
     258  // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeas);
    257259
    258260  /** incorporate unmatched image stars, if this star is in field of this catalog **/
  • branches/czw_branch/20101203/Ohana/src/imregister/imphot/rfits.c

    r7080 r30118  
    1717    return (FALSE);
    1818  }
    19   if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable)) {
     19  if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable, FALSE)) {
    2020    fprintf (stderr, "can't read table data");
    2121    return (FALSE);
  • branches/czw_branch/20101203/Ohana/src/kapa2/Makefile

    r25757 r30118  
    4242$(SRC)/bDrawObjects.$(ARCH).o             $(SRC)/bDrawFrame.$(ARCH).o         \
    4343$(SRC)/bDrawLabels.$(ARCH).o              $(SRC)/bDrawIt.$(ARCH).o            \
     44$(SRC)/bDrawImage.$(ARCH).o               \
    4445$(SRC)/PNGit.$(ARCH).o                    $(SRC)/PPMit.$(ARCH).o              \
    4546$(SRC)/PSit.$(ARCH).o                     $(SRC)/CrossHairs.$(ARCH).o         \
  • branches/czw_branch/20101203/Ohana/src/kapa2/include/prototypes.h

    r29539 r30118  
    4040void          DrawYErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    4141void          DrawTick            PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
    42 void          AxisTickScale       PROTO((Axis *axis, double *major, double *minor));
     42void          AxisTickScale       PROTO((Axis *axis, double *major, double *minor, int *nsignif));
    4343TickMarkData *CreateAxisTicks     PROTO((Axis *axis, int *nticks));
    44 int           PrintTick           PROTO((char *string, double value, double min, double max));
     44int           PrintTick           PROTO((char *string, double value, double min, double max, int nsignif));
    4545
    4646/* EventLoop */
    4747int           PScommand           PROTO((int sock));
     48int           PNGcommand          PROTO((int sock));
    4849int           CheckPipe           PROTO((void));
    4950int           Reconfig            PROTO((XEvent *event));
     
    5253
    5354/* CheckPipe */
    54 int           PNGit               PROTO((int sock));
     55int           PNGit               PROTO((char *filename));
    5556int           PPMit               PROTO((int sock));
    5657int           LoadFrame           PROTO((int sock));
     
    6768int           MoveSection         PROTO((int sock));
    6869int           DefineSection       PROTO((int sock));
     70int           DefineSectionByImage PROTO((int sock));
    6971int           SetFont             PROTO((int sock));
    7072int           EraseCurrentPlot    PROTO((void));
     
    126128
    127129/* kapa bDraw Functions */
    128 int           bDrawFrame          PROTO((KapaGraphWidget *graph));
    129 int           bDrawObjects        PROTO((KapaGraphWidget *graph));
    130 void          bDrawLabels         PROTO((KapaGraphWidget *graph));
    131 void          bDrawTextlines      PROTO((KapaGraphWidget *graph));
    132 void          bDrawConnect        PROTO((KapaGraphWidget *graph, Gobjects *object));
    133 void          bDrawHistogram      PROTO((KapaGraphWidget *graph, Gobjects *object));
    134 void          bDrawPoints         PROTO((KapaGraphWidget *graph, Gobjects *object));
    135 void          bDrawXErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    136 void          bDrawYErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    137 void          bDrawTick           PROTO((Axis *axis, int P, TickMarkData *tick, int naxis));
    138 void          bDrawClipLine       PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0));
    139 bDrawBuffer  *bDrawIt             PROTO((void));
    140 void          bDrawGraph          PROTO((KapaGraphWidget *graph));
     130int           bDrawFrame          PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     131int           bDrawObjects        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     132void          bDrawLabels         PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     133void          bDrawTextlines      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     134void          bDrawConnect        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     135void          bDrawHistogram      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     136void          bDrawPoints         PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     137void          bDrawXErrors        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     138void          bDrawYErrors        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     139void          bDrawTick           PROTO((bDrawBuffer *buffer, Axis *axis, int P, TickMarkData *tick, int naxis));
     140void          bDrawClipLine       PROTO((bDrawBuffer *buffer, double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0));
     141void          bDrawGraph          PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     142int           bDrawImage          PROTO((bDrawBuffer *buffer, KapaImageWidget *image, Graphic *graphic));
     143bDrawBuffer  *bDrawIt             PROTO((png_color *palette, int Npalette, int Nbyte));
    141144
    142145/* misc support */
     
    212215int           Overlay3            PROTO((Graphic *graphic, KapaImageWidget *image));
    213216int           PSfunction          PROTO((Graphic *graphic, KapaImageWidget *image));
     217int           PNGfunction         PROTO((Graphic *graphic, KapaImageWidget *image));
     218int           JPEGfunction        PROTO((Graphic *graphic, KapaImageWidget *image));
    214219
    215220/* misc functions */
     
    219224int           SaveOverlay  (int sock);
    220225int           CSaveOverlay (int sock);
    221 int           JPEGit24     (int sock);
     226int           JPEGit24     (char *filename);
     227int           JPEGcommand  (int sock);
    222228
    223229int           UpdatePointer (Graphic *graphic, XMotionEvent *event);
     
    241247int           GetActiveSocket (void);
    242248void          InvertButton (Graphic *graphic, Button *button);
    243 void          bDrawOverlay (KapaImageWidget *image, int N);
     249void          bDrawOverlay (bDrawBuffer *buffer, KapaImageWidget *image, int N);
    244250
    245251/* color cube tools */
     
    261267int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image);
    262268int SetColorCubeHistogram (void);
     269int GetGraphBoundary (Section *section, double *x0, double *y0, double *x1, double *y1, int *dXm, int *dXp, int *dYm, int *dYp);
     270int ResizeByImage (int sock);
     271
  • branches/czw_branch/20101203/Ohana/src/kapa2/include/structures.h

    r29539 r30118  
    148148  int IsMajor;
    149149  int IsLabel;
     150  int nsignif;
    150151} TickMarkData;
    151152
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/ButtonFunctions.c

    r29539 r30118  
    77
    88  status = PSit ("kapa.ps", "default", TRUE, KAPA_PS_NEWPLOT);
     9  return (status);
     10}
     11
     12int PNGfunction (Graphic *graphic, KapaImageWidget *image) {
     13
     14  int status;
     15
     16  status = PNGit ("kapa.png");
     17  return (status);
     18}
     19
     20int JPEGfunction (Graphic *graphic, KapaImageWidget *image) {
     21
     22  int status;
     23
     24  status = JPEGit24 ("kapa.jpg");
    925  return (status);
    1026}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/CheckPipe.c

    r27790 r30118  
    8989 
    9090  if (!strcmp (word, "PNGF")) {
    91     status = PNGit (sock);
    92     KiiSendCommand (sock, 4, "DONE");
    93     FINISHED (status);
    94   }
    95  
     91    status = PNGcommand (sock);
     92    KiiSendCommand (sock, 4, "DONE");
     93    FINISHED (status);
     94  }
     95 
     96  if (!strcmp (word, "JPEG")) {
     97    status = JPEGcommand (sock);
     98    KiiSendCommand (sock, 4, "DONE");
     99    FINISHED (status);
     100  }
     101
    96102  if (!strcmp (word, "PPMF")) {
    97103    status = PPMit (sock);
     
    131137  }
    132138
     139  if (!strcmp (word, "ISIZ")) {
     140    status = ResizeByImage (sock);
     141    KiiSendCommand (sock, 4, "DONE");
     142    FINISHED (TRUE);
     143  }
     144 
    133145  if (!strcmp (word, "MOVE")) {
    134146    status = Relocate (sock);
     
    211223  if (!strcmp (word, "DSEC")) {
    212224    status = DefineSection (sock);
     225    KiiSendCommand (sock, 4, "DONE");
     226    FINISHED (TRUE);
     227  }
     228 
     229  if (!strcmp (word, "ISEC")) {
     230    status = DefineSectionByImage (sock);
    213231    KiiSendCommand (sock, 4, "DONE");
    214232    FINISHED (TRUE);
     
    300318  if (!strcmp (word, "CSVE")) {
    301319    status = CSaveOverlay (sock);
    302     KiiSendCommand (sock, 4, "DONE");
    303     FINISHED (status);
    304   }
    305 
    306   if (!strcmp (word, "JPEG")) {
    307     status = JPEGit24 (sock);
    308320    KiiSendCommand (sock, 4, "DONE");
    309321    FINISHED (status);
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/DefineSection.c

    r27790 r30118  
    4040  return (TRUE);
    4141}
     42
     43// define the section, but do not create a graph or image
     44int DefineSectionByImage (int sock) {
     45 
     46  int N, bg;
     47  char name[128];
     48  double x, y, dx, dy;
     49  int dXm, dXp, dYm, dYp;
     50  double x0, y0, x1, y1, expand;
     51  Section *section;
     52  Graphic *graphic;
     53  KapaImageWidget *image;
     54
     55  KiiScanMessage (sock, "%s %lf %lf %d", name, &x, &y, &bg);
     56
     57  N = GetSectionByName (name);
     58  section = GetSectionByNumber (N);
     59  image = section->image;
     60  if (!image) {
     61    fprintf (stderr, "no image to define section\n");
     62    return (TRUE);
     63  }
     64  SetActiveSectionByNumber (N);
     65
     66  graphic = GetGraphic ();
     67
     68  GetGraphBoundary (section, &x0, &y0, &x1, &y1, &dXm, &dXp, &dYm, &dYp);
     69
     70  expand = 1.0;
     71  if (image[0].picture.expand > 0) {
     72    expand = image[0].picture.expand;
     73  }
     74  if (image[0].picture.expand < 0) {
     75    expand = 1.0 / fabs((double)image[0].picture.expand);
     76  }
     77
     78  // pixel dimensions of the imaging region + boundary
     79  dx = image[0].image[0].matrix.Naxis[0]*expand + x1;
     80  dy = image[0].image[0].matrix.Naxis[1]*expand + y1;
     81
     82  section[0].x = x;
     83  section[0].y = y;
     84  section[0].bg = bg;
     85  section[0].dx = dx / graphic[0].dx;
     86  section[0].dy = dy / graphic[0].dy;
     87
     88  // if (section[0].x != x)   MoveSection = TRUE;
     89  // if (section[0].y != y)   MoveSection = TRUE;
     90  // if (section[0].dx != dx) MoveSection = TRUE;
     91  // if (section[0].dy != dy) MoveSection = TRUE;
     92
     93  SetSectionSizes (section);
     94  Refresh ();
     95
     96  return (TRUE);
     97}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/DrawFrame.c

    r29539 r30118  
    55int DrawFrame (KapaGraphWidget *graph) {
    66 
    7   int i, j, Nticks, P;
    8   double fx, fy, dfx, dfy, lweight;
     7  int i, j, Nticks, P, doffset;
     8  double fx, fy, dfx, dfy, dx = 0, dy = 0, lweight;
    99  Graphic *graphic;
    1010  TickMarkData *ticks;
     
    1515  /* each axis is drawn independently, but ticks and labels are placed according to perpendicular distance. */
    1616  for (i = 0; i < 4; i++) {
    17     fx  = graph[0].axis[i].fx;
    18     fy  = graph[0].axis[i].fy;
    19     dfx = graph[0].axis[i].dfx;
    20     dfy = graph[0].axis[i].dfy;
    21     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    22 
    2317    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2418    color = MAX (0, MIN (15, graph[0].axis[i].color));
     19
     20    /* temporarily assume rectilinear axes */
     21    doffset = ((int)(lweight) % 2) ? 0.5*(lweight - 1) : 0.5*lweight;
     22    if (i == 0) { dx = doffset; dy = 0.0; }
     23    if (i == 2) { dx = doffset; dy = 0.0; }
     24    if (i == 1) { dx = 0.0; dy = doffset; }
     25    if (i == 3) { dx = 0.0; dy = doffset; }
     26
     27    fx  = graph[0].axis[i].fx - dx;
     28    fy  = graph[0].axis[i].fy - dy;
     29    dfx = graph[0].axis[i].dfx + 2*dx;
     30    dfy = graph[0].axis[i].dfy + 2*dy;
     31
     32    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     33    P *= (1 + 0.25*lweight);
    2534
    2635    XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
     
    4352}
    4453
    45 int PrintTick (char *string, double value, double min, double max) {
     54int PrintTick (char *string, double value, double min, double max, int nsignif) {
    4655
    4756  int Nexp = 0;
     
    5463  }
    5564
    56   double lvalue = log10(fabs(value));
    57 
    58   if (isfinite(lvalue)) {
    59     Nexp = fabs(lvalue);
    60   } else {
    61     Nexp = 0;
    62   }
    63  
     65//   double lvalue = log10(fabs(value));
     66//   if (isfinite(lvalue)) {
     67//     Nexp = fabs(lvalue);
     68//   } else {
     69//     Nexp = 0;
     70//   }
     71 
     72  Nexp = abs(nsignif);
     73
    6474  if (Nexp > 3) {
    6575    Nchar = sprintf (string, "%.1e", value);
    6676  } else {
    67     Nchar = sprintf (string, "%.1f", value);
     77    if (nsignif < 0) {
     78      char format[16];
     79      snprintf (format, 16, "%%.%df", -1 * nsignif);
     80      Nchar = sprintf (string, format, value);
     81    } else {
     82      Nchar = sprintf (string, "%.1f", value);
     83    }
    6884  }
    6985  return Nchar;
     
    129145    yt = fy + (value-min)*dfy/(max - min) + dy;
    130146
    131     PrintTick (string, value, min, max);
     147    PrintTick (string, value, min, max, tick->nsignif);
    132148    DrawRotText (xt, yt, string, pos, 0.0);
    133149  }
     
    136152# define MIN_RANGE 1e-10
    137153
    138 void AxisTickScale (Axis *axis, double *major, double *minor) {
     154void AxisTickScale (Axis *axis, double *major, double *minor, int *nsignif) {
    139155
    140156  double range, lrange, factor, mantis, fmantis, power;
     
    152168  }
    153169 
     170  // how many significant digits are needed?
     171
    154172  power = MAX(pow(10.0, factor), MIN_RANGE);
    155173  fmantis = pow(10.0, mantis);
     
    160178    *major = 0.5 * power;
    161179    *minor = 0.1 * power;
     180    *nsignif = factor - 1;
    162181    if (axis[0].areticks == 1) {
    163182      *major = 0.25 * power;
    164183      *minor = 0.05 * power;
     184      *nsignif = factor - 2;
    165185    }     
    166186  }
     
    168188    *major = 1.0 * power;
    169189    *minor = 0.2 * power;
     190    *nsignif = factor;
    170191    if (axis[0].areticks == 1) {
    171192      *major = 0.5 * power;
    172193      *minor = 0.1 * power;
     194      *nsignif = factor - 1;
    173195    }     
    174196  }
     
    176198    *major = 1.0 * power;
    177199    *minor = 0.5 * power;
     200    *nsignif = factor;
    178201    if (axis[0].areticks == 1) {
    179202      *major = 1.0 * power;
    180203      *minor = 0.2 * power;
     204      *nsignif = factor;
    181205    }     
    182206  }
     
    184208    *major = 2.0 * power;
    185209    *minor = 0.5 * power;
     210    *nsignif = factor;
    186211    if (axis[0].areticks == 1) {
    187212      *major = 1.0 * power;
    188213      *minor = 0.5 * power;
     214      *nsignif = factor;
    189215    }     
    190216  }
     
    192218    *major = 2.5 * power;
    193219    *minor = 0.5 * power;
     220      *nsignif = factor - 1;
    194221    if (axis[0].areticks == 1) {
    195222      *major = 2.0 * power;
    196223      *minor = 0.5 * power;
     224      *nsignif = factor;
    197225    }     
    198226  }
     
    203231  TickMarkData *ticks;
    204232  double range, major, minor, first, value, dPixels, overshoot;
    205   int i, NTICKS, nPixels, done, ifirst;
     233  int i, NTICKS, nPixels, done, ifirst, nsignif;
    206234
    207235  *nticks = 0;
     
    223251  dPixels = nPixels / range; // axis pixel-scale
    224252
    225   AxisTickScale (axis, &major, &minor);
     253  AxisTickScale (axis, &major, &minor, &nsignif);
    226254
    227255  // be a little generous
     
    256284    ticks[i].IsLabel = (ticks[i].IsMajor && axis->islabel);
    257285    ticks[i].value = value;
     286    ticks[i].nsignif = nsignif;
    258287    if (range > 0)
    259288      value += minor;
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/Image.c

    r29539 r30118  
    8888
    8989  InitButtonSize (&image[0].PS_button, PS_width, PS_height, PS_bits);
    90   InitButtonFunc (&image[0].PS_button, PSfunction);
     90  // InitButtonFunc (&image[0].PS_button, PSfunction);
     91  image->PS_button.function_1 = PSfunction;
     92  image->PS_button.function_2 = PNGfunction;
     93  image->PS_button.function_3 = JPEGfunction;
    9194
    9295  InitButtonSize (&image[0].grey_button, grey_width, grey_height, grey_bits);
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/JPEGit24.c

    r27601 r30118  
    88# define WHITE_B 255
    99
     10int JPEGcommand (int sock) {
     11
     12  int status;
     13  char filename[1024];
     14
     15  KiiScanMessage (sock, "%s", filename);
     16  status = JPEGit24 (filename);
     17  return (status);
     18}
     19
    1020// XXX this currently writes out the jpeg for just the active image
    11 int JPEGit24 (int sock) {
     21int JPEGit24 (char *filename) {
    1222
    1323  struct jpeg_compress_struct cinfo;
     
    3141  unsigned short *in_pix, *in_pix_ref;
    3242  unsigned char *pixel1, *pixel2, *pixel3;
    33   char filename[1024];
    3443  FILE *f;
    35 
    36   /* expect a line telling the number of bytes and a filename */
    37   KiiScanMessage (sock, "%s", filename);
    3844
    3945  graphic = GetGraphic();
     
    196202    palette = KapaPNGPalette (&Npalette);
    197203
    198     buffer = bDrawBufferCreate (dx, dy);
    199     bDrawSetBuffer (buffer);
     204    buffer = bDrawBufferCreate (dx, dy, 1, palette, Npalette);
    200205    for (i = 0; i < NOVERLAYS; i++) {
    201       if (image[i].overlay[i].active) bDrawOverlay (image, i);
     206      if (image[0].overlay[i].active) bDrawOverlay (buffer, image, i);
    202207    }
    203208
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/PNGit.c

    r29408 r30118  
    77*/
    88
    9 bDrawBuffer *bDrawBufferCreate8bitRGB (int Nx, int Ny);
    10 int bDrawImage (bDrawBuffer *buffer, Graphic *graphic);
     9int PNGcommand (int sock) {
    1110
    12 int PNGit (int sock) {
     11  int status;
     12  char filename[1024];
     13
     14  KiiScanMessage (sock, "%s", filename);
     15  status = PNGit (filename);
     16  return (status);
     17}
     18
     19int PNGit (char *filename) {
    1320
    1421  FILE *f;
    1522  png_structp png_ptr;
    1623  png_infop info_ptr;
    17   int status, Npalette;
    18   char filename[1024];
     24  int i, status, Npalette, Nsection;
    1925  bDrawBuffer *buffer = NULL;
    2026  Graphic *graphic = NULL;
    2127  png_color *palette = NULL;
     28  Section *section;
    2229
    2330  graphic = GetGraphic();
    24 
    25   /* expect a line telling the number of bytes and a filename */
    26   KiiScanMessage (sock, "%s", filename);
    2731
    2832  f = fopen (filename, "w");
     
    6266  png_init_io (png_ptr, f);
    6367
     68  palette = KapaPNGPalette (&Npalette);
     69
     70  // do we have an image in any of the sections?
     71  Nsection = GetNumberOfSections ();
     72  int haveImage = FALSE;
     73  for (i = 0; !haveImage && (i < Nsection); i++) {
     74    section = GetSectionByNumber (i);
     75    haveImage = (section->image != NULL);
     76  }
     77
    6478  /* see docs for write-row-callback to provide progress info */
    65 # define PALETTE 1
    66   if (PALETTE) {
    67     png_set_IHDR (png_ptr, info_ptr, graphic->dx, graphic->dy, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    68     palette = KapaPNGPalette (&Npalette);
    69     png_set_PLTE (png_ptr, info_ptr, palette, Npalette);
    70   } else {
     79  if (haveImage) {
    7180    // png_set_IHDR (png_ptr, info_ptr, graphic->dx, graphic->dy, 16, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    7281    png_set_IHDR (png_ptr, info_ptr, graphic->dx, graphic->dy, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    7382    png_set_sRGB (png_ptr, info_ptr, PNG_sRGB_INTENT_ABSOLUTE);
     83  } else {
     84    png_set_IHDR (png_ptr, info_ptr, graphic->dx, graphic->dy, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
     85    png_set_PLTE (png_ptr, info_ptr, palette, Npalette);
    7486  }
    7587
     
    8193  png_write_info (png_ptr, info_ptr);
    8294
    83   if (PALETTE) {
    84     buffer = bDrawIt ();
     95  if (haveImage) {
     96    buffer = bDrawIt (palette, Npalette, 3);
     97    // bDrawImage (buffer, graphic);
    8598  } else {
    86     buffer = bDrawBufferCreate8bitRGB(graphic->dx, graphic->dy);
    87     bDrawImage (buffer, graphic);
     99    buffer = bDrawIt (palette, Npalette, 1);
    88100  }
    89101
     
    93105 
    94106  bDrawBufferFree (buffer);
    95   free (palette);
    96107  fclose (f);
    97108  return (TRUE);
    98109
    99110}
    100 
    101 /* For color images, I need to define the relationship between the drawing colors and the RGB values? */
    102 
    103 
    104 bDrawBuffer *bDrawBufferCreate8bitRGB (int Nx, int Ny) {
    105 
    106   int i, j;
    107   bDrawBuffer *buffer;
    108 
    109   ALLOCATE (buffer, bDrawBuffer, 1);
    110   buffer[0].Nx = Nx;
    111   buffer[0].Ny = Ny;
    112 
    113   ALLOCATE (buffer[0].pixels, bDrawColor *, Ny);
    114   for (i = 0; i < Ny; i++) {
    115     ALLOCATE (buffer[0].pixels[i], bDrawColor, 3*Nx);
    116     for (j = 0; j < 3*Nx; j+=3) {
    117       buffer[0].pixels[i][j+0] = 0xff;
    118       buffer[0].pixels[i][j+1] = 0xff;
    119       buffer[0].pixels[i][j+2] = 0xff;
    120     }
    121   }
    122   return (buffer);
    123 }
    124 
    125 # define WHITE_R 255
    126 # define WHITE_G 255
    127 # define WHITE_B 255
    128 # define MY_SWAP_INT(A,B) { int tmp; tmp = A; A = B; B = tmp; }
    129 
    130 int bDrawImage (bDrawBuffer *buffer, Graphic *graphic) {
    131  
    132   Section *section;
    133   KapaImageWidget *image;
    134 
    135   int ii, i, j;
    136   int i_start, i_end, j_start, j_end;
    137   int I_start, J_start;
    138   int dropback;  /* this is a bit of a kludge... */
    139   int dx, dy, DX, DY, inDX, inDY;
    140   int expand_in, expand_out;
    141   double expand, Ix, Iy;
    142   unsigned char *out_pix;
    143   unsigned short *in_pix, *in_pix_ref;
    144   unsigned char *pixel1, *pixel2, *pixel3;
    145 
    146   bDrawColor *line_buffer;
    147 
    148   section = GetActiveSection();
    149   image   = section->image;
    150   if (image == NULL) return (TRUE);
    151 
    152   ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
    153   ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
    154   ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
    155 
    156   /** cmap[i].pixel must be defined even if X is not used **/
    157   for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
    158     pixel1[i] = graphic[0].cmap[i].red >> 8;
    159     pixel2[i] = graphic[0].cmap[i].green >> 8;
    160     pixel3[i] = graphic[0].cmap[i].blue >> 8;
    161   }
    162 
    163   assert ((image[0].picture.expand >= 1) || (image[0].picture.expand <= -2));
    164   expand = expand_in = expand_out = 1.0;
    165   if (image[0].picture.expand > 0) {
    166     expand = 1 / (1.0*image[0].picture.expand);
    167     expand_out = image[0].picture.expand;
    168     expand_in  = 1;
    169   }
    170   if (image[0].picture.expand < 0) {
    171     expand = fabs((double)image[0].picture.expand);
    172     expand_out = 1;
    173     expand_in  = -image[0].picture.expand;
    174   }
    175 
    176   dx = image[0].picture.dx;
    177   dy = image[0].picture.dy;
    178   DX = image[0].image[0].matrix.Naxis[0];
    179   DY = image[0].image[0].matrix.Naxis[1];
    180 
    181   // i_start, j_start are the closest lit screen pixel to 0,0
    182   // I_start, J_start are the image pixel corresponding to i_start, j_start
    183   Picture_Lower (&i_start, &j_start, &I_start, &J_start, &image[0].image[0].matrix, &image[0].picture);
    184 
    185   // i_end, j_end are the closest lit screen pixel to dx, dy
    186   // I_end, J_end are the image pixel corresponding to i_end, j_end
    187   Picture_Upper (&i_end, &j_end, i_start, j_start, &image[0].image[0].matrix, &image[0].picture);
    188 
    189   assert (i_start <= i_end);
    190   assert (j_start <= j_end);
    191 
    192   Ix = image[0].picture.flipx ? I_start - 1 : I_start;
    193   Iy = image[0].picture.flipy ? J_start - 1 : J_start;
    194 
    195   inDX = image[0].picture.flipx ? -1 : +1;
    196   inDY = image[0].picture.flipy ? -1 : +1;
    197 
    198   dropback = expand_out - (i_end - i_start) % expand_out;
    199   if ((i_end - i_start) % expand_out == 0) dropback = 0;
    200 
    201   ALLOCATE (line_buffer, bDrawColor, 3*dx);
    202 
    203   in_pix_ref  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
    204 
    205   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
    206 
    207   /**** fill in bottom area ****/
    208   out_pix = line_buffer;
    209   for (i = 0; i < dx; i++, out_pix+=3) {
    210     out_pix[0] = WHITE_R;
    211     out_pix[1] = WHITE_G;
    212     out_pix[2] = WHITE_B;
    213   }
    214   for (j = 0; j < j_start; j++) {
    215     memcpy (buffer[0].pixels[j], line_buffer, 3*dx);
    216   }
    217  
    218   /*** fill in the image data region ***/
    219   for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += inDY*expand_in*DX) {
    220    
    221     /* create one output image line */
    222     in_pix = in_pix_ref;
    223     out_pix = line_buffer;
    224 
    225     /**** fill in area to the left of the picture ****/
    226     for (i = 0; i < i_start; i++, out_pix+=3) {
    227       out_pix[0] = WHITE_R;
    228       out_pix[1] = WHITE_G;
    229       out_pix[2] = WHITE_B;
    230     }
    231    
    232     /*** fill in the picture region ***/
    233     for (i = i_start; i < i_end; i+=expand_out, in_pix += inDX*expand_in) {
    234       for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
    235         out_pix[0] = pixel1[*in_pix];
    236         out_pix[1] = pixel2[*in_pix];
    237         out_pix[2] = pixel3[*in_pix];
    238       }
    239     }
    240    
    241     /**** fill in area to the right of the picture ****/
    242     for (i = i_end; i < dx; i++, out_pix+=3) {
    243       out_pix[0] = WHITE_R;
    244       out_pix[1] = WHITE_G;
    245       out_pix[2] = WHITE_B;
    246     }
    247 
    248     /* write out the image line expand_out times */
    249     for (i = 0; i < expand_out; i++) {
    250       memcpy (buffer[0].pixels[j + i], line_buffer, 3*dx);
    251     }
    252   }
    253 
    254   /**** fill in top area ****/
    255   out_pix = line_buffer;
    256   for (i = 0; i < dx; i++, out_pix+=3) {
    257     out_pix[0] = WHITE_R;
    258     out_pix[1] = WHITE_G;
    259     out_pix[2] = WHITE_B;
    260   }
    261   for (j = j_end; j < dy; j++) {
    262     memcpy (buffer[0].pixels[j], line_buffer, 3*dx);
    263   }
    264 
    265   free (pixel1);
    266   free (pixel2);
    267   free (pixel3);
    268   free (line_buffer);
    269 
    270   return (TRUE);
    271 }
    272 
    273 # if (0)
    274 
    275   /* I need to write the overlay objects on the jpeg image.
    276      if i can write / overwrite data in jpeg buffer, then do it here,
    277      otherwise i need to create a temporary image buffer, then write the
    278      scanlines to that buffer */
    279 
    280   {
    281     int Npalette;
    282     png_color *palette;
    283     bDrawColor white, color;
    284     bDrawBuffer *buffer;
    285 
    286     palette = KapaPNGPalette (&Npalette);
    287 
    288     buffer = bDrawBufferCreate (dx, dy);
    289     bDrawSetBuffer (buffer);
    290     for (i = 0; i < NOVERLAYS; i++) {
    291       if (image[i].overlay[i].active) bDrawOverlay (image, i);
    292     }
    293 
    294     white = KapaColorByName ("white");
    295     for (j = 0; j < dy; j++) {
    296       for (i = 0; i < dx; i++) {
    297         color = buffer[0].pixels[j][i];
    298         if (color == white) continue;
    299         image_buffer[j*3*dx + 3*i + 0] = palette[color].red;
    300         image_buffer[j*3*dx + 3*i + 1] = palette[color].green;
    301         image_buffer[j*3*dx + 3*i + 2] = palette[color].blue;
    302       }
    303     }
    304     bDrawBufferFree (buffer);
    305   }
    306 
    307 # endif
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/PPMit.c

    r27435 r30118  
    3030  fprintf (f, "255\n");
    3131
    32   buffer = bDrawIt ();
     32  buffer = bDrawIt (palette, Npalette, 1);
    3333
    3434  ALLOCATE (line, char, 3*dx);
     
    4747  bDrawBufferFree (buffer);
    4848  return (TRUE);
    49 
    5049}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/PSFrame.c

    r29539 r30118  
    44int PSFrame (KapaGraphWidget *graph, FILE *f) {
    55 
    6   int i, j, Nticks, P;
    7   double fx, fy, dfx, dfy, lweight;
     6  int i, j, Nticks, P, doffset;
     7  double fx, fy, dfx, dfy, dx = 0, dy = 0, lweight;
    88  Graphic *graphic;
    99  TickMarkData *ticks;
     
    1515  fprintf (f, "1 setlinewidth\n");
    1616  for (i = 0; i < 4; i++) {
    17     fx  = graph[0].axis[i].fx;
    18     fy  = graphic->dy - graph[0].axis[i].fy;
    19     dfx = graph[0].axis[i].dfx;
    20     dfy = -graph[0].axis[i].dfy;
    21     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    22 
    2317    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2418    color = MAX (0, MIN (15, graph[0].axis[i].color));
     19
     20    /* temporarily assume rectilinear axes */
     21    doffset = ((int)(lweight) % 2) ? 0.5*(lweight - 1) : 0.5*lweight;
     22    if (i == 0) { dx = doffset; dy = 0.0; }
     23    if (i == 2) { dx = doffset; dy = 0.0; }
     24    if (i == 1) { dx = 0.0; dy = doffset; }
     25    if (i == 3) { dx = 0.0; dy = doffset; }
     26
     27    fx  = graph[0].axis[i].fx - dx;
     28    fy  = graphic->dy - graph[0].axis[i].fy - dy;
     29    dfx = graph[0].axis[i].dfx + 2*dx;
     30    dfy = -graph[0].axis[i].dfy + 2*dy;
     31
     32    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     33    P *= (1 + 0.25*lweight);
    2534
    2635    fprintf (f, "%.1f setlinewidth\n", lweight);
     
    95104    yt = fy + (value-min)*dfy/(max - min) + dy;
    96105
    97     PrintTick (string, value, min, max);
     106    PrintTick (string, value, min, max, tick->nsignif);
    98107    PSRotText (f, xt, yt, string, pos, 0.0);
    99108  }
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/PSimage.c

    r14913 r30118  
    1313  graphic = GetGraphic();
    1414
    15   fprintf (f, " newpath 0 0 moveto %d 0 lineto %d %d lineto 0 %d lineto closepath clip\n\n",
    16            image[0].picture.dx, image[0].picture.dx, image[0].picture.dy, image[0].picture.dy);
     15  fprintf (f, " newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath\n\n",
     16           (int) image[0].picture.x,                       graphic->dy - (int) image[0].picture.y,
     17           (int) image[0].picture.x + image[0].picture.dx, graphic->dy - (int) image[0].picture.y,
     18           (int) image[0].picture.x + image[0].picture.dx, graphic->dy - (int) image[0].picture.y - image[0].picture.dy,
     19           (int) image[0].picture.x,                       graphic->dy - (int) image[0].picture.y - image[0].picture.dy);
    1720  fprintf (f, "gsave %% encloses image\n");
     21  fprintf (f, "%d %d translate\n", (int) image[0].picture.x, graphic->dy - (int) image[0].picture.y - image[0].picture.dy);
    1822  fprintf (f, "%d %d 8\n", image[0].picture.dx, image[0].picture.dy);
    1923  fprintf (f, "[1 0 0 1 0 0]\n");
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/PSit.c

    r13479 r30118  
    8787  for (i = 0; i < Nsection; i++) {
    8888    section = GetSectionByNumber (i);
     89    if (section->image) {
     90      PSimage (section->image, f);
     91    }
    8992    if (section->graph) {
    9093      PSFrame (section->graph, f);
     
    9295      PSLabels (section->graph, f);
    9396      PSTextlines (section->graph, f);
    94     }
    95     if (section->image) {
    96       PSimage (section->image, f);
    9797    }
    9898  }
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/Resize.c

    r26891 r30118  
    3939  return (TRUE);
    4040}
     41
     42// resise the window so the image in the currently active window fills its section
     43int ResizeByImage (int sock) {
     44 
     45  int i, Nsection;
     46  unsigned int NX, NY;
     47  double dx, dy;
     48  int dXm, dXp, dYm, dYp;
     49  double x0, y0, x1, y1, expand;
     50  Section *section;
     51  Graphic *graphic;
     52  KapaImageWidget *image;
     53
     54  graphic = GetGraphic();
     55
     56  section = GetActiveSection();
     57
     58  image = section->image;
     59  if (!image) {
     60    fprintf (stderr, "no image to define size\n");
     61    return (TRUE);
     62  }
     63
     64  GetGraphBoundary (section, &x0, &y0, &x1, &y1, &dXm, &dXp, &dYm, &dYp);
     65
     66  expand = 1.0;
     67  if (image[0].picture.expand > 0) {
     68    expand = image[0].picture.expand;
     69  }
     70  if (image[0].picture.expand < 0) {
     71    expand = 1.0 / fabs((double)image[0].picture.expand);
     72  }
     73
     74  // pixel dimensions of the imaging region + boundary
     75  dx = image[0].image[0].matrix.Naxis[0]*expand + x1;
     76  dy = image[0].image[0].matrix.Naxis[1]*expand + y1;
     77
     78  NX = dx / section[0].dx;
     79  NY = dy / section[0].dy;
     80
     81  NX = MAX(NX, MIN_WIDTH);
     82  NY = MAX(NY, MIN_HEIGHT);
     83
     84  // if the new size is the same as the old size, do nothing.
     85  if ((graphic->dx == NX) && (graphic->dy == NY)) return (TRUE);
     86
     87  // set the new window size
     88  graphic->dx = NX;
     89  graphic->dy = NY;
     90
     91  if (USE_XWINDOW) XResizeWindow (graphic->display, graphic->window, NX, NY);
     92
     93  // reset the sizes for all sections
     94  Nsection = GetNumberOfSections ();
     95  for (i = 0; i < Nsection; i++) {
     96      section = GetSectionByNumber (i);
     97      SetSectionSizes (section);
     98  }
     99
     100  if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
     101  Refresh ();
     102
     103  return (TRUE);
     104}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/SetGraphSize.c

    r29539 r30118  
    55
    66void SetGraphSize (Section *section) {
     7
     8  int dXm, dXp, dYm, dYp;
     9  double x0, y0, x1, y1;
     10  KapaGraphWidget *graph;
     11  Graphic *graphic;
     12
     13  GetGraphBoundary(section, &x0, &y0, &x1, &y1, &dXm, &dXp, &dYm, &dYp);
     14
     15  if (section == NULL) return;
     16  graph = section->graph;
     17  if (graph == NULL) return;
     18
     19  graphic = GetGraphic ();
     20
     21  double X0 = graphic[0].dx * section[0].x  + x0;
     22  double Y0 = graphic[0].dy * section[0].y  + y0;
     23  double dX = graphic[0].dx * section[0].dx - x1;
     24  double dY = graphic[0].dy * section[0].dy - y1;
     25
     26  /* define locations of coordinate axes */
     27  graph[0].axis[0].fx  = X0;
     28  graph[0].axis[0].fy  = graphic->dy - Y0;
     29  graph[0].axis[0].dfx = dX;
     30  graph[0].axis[0].dfy = 0;
     31
     32  graph[0].axis[1].fx  = X0;
     33  graph[0].axis[1].fy  = graphic->dy - Y0;
     34  graph[0].axis[1].dfx = 0;
     35  graph[0].axis[1].dfy = -dY;
     36
     37  graph[0].axis[2].fx  = X0;
     38  graph[0].axis[2].fy  = graphic->dy - Y0 - dY;
     39  graph[0].axis[2].dfx = dX;
     40  graph[0].axis[2].dfy = 0;
     41
     42  graph[0].axis[3].fx  = X0 + dX;
     43  graph[0].axis[3].fy  = graphic->dy - Y0;
     44  graph[0].axis[3].dfx = 0;
     45  graph[0].axis[3].dfy = -dY;
     46
     47  /* define locations of axis labels */
     48  graph[0].label[LABELLL].x = graph[0].axis[0].fx;
     49  graph[0].label[LABELLL].y = graph[0].axis[0].fy + dXm;
     50  graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
     51  graph[0].label[LABELX0].y = graph[0].axis[0].fy + dXm;
     52  graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     53  graph[0].label[LABELLR].y = graph[0].axis[0].fy + dXm;
     54
     55  graph[0].label[LABELUL].x = graph[0].axis[2].fx;
     56  graph[0].label[LABELUL].y = graph[0].axis[2].fy - dXp;
     57  graph[0].label[LABELX1].x = graph[0].axis[2].fx + 0.5*graph[0].axis[2].dfx;
     58  graph[0].label[LABELX1].y = graph[0].axis[2].fy - dXp;
     59  graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx;
     60  graph[0].label[LABELUR].y = graph[0].axis[2].fy - dXp;
     61
     62  graph[0].label[LABELY0].y = graph[0].axis[1].fy + 0.5*graph[0].axis[1].dfy;
     63  graph[0].label[LABELY0].x = graph[0].axis[1].fx - dYm;
     64
     65  graph[0].label[LABELY1].y = graph[0].axis[3].fy + 0.5*graph[0].axis[3].dfy;
     66  graph[0].label[LABELY1].x = graph[0].axis[3].fx + dYp;
     67
     68  return;
     69}
     70
     71int GetGraphBoundary (Section *section, double *x0, double *y0, double *x1, double *y1, int *dXm, int *dXp, int *dYm, int *dYp) {
    772
    873  int i, Nticks;
    974  int fontsize, Nc = 0;
    1075  int textpad, textdY, WdY;
    11   int dXm, dXp, dYm, dYp;
    1276  double padXm, padXp, padYm, padYp;
    1377  double minPADx, maxPADx, minPADy;
    1478  double minPAD, maxPAD;
    15   double X0, Y0, dX, dY;
    1679  char string[64], *fontname;
    1780  KapaGraphWidget *graph;
     
    1982  TickMarkData *ticks;
    2083
    21   if (section == NULL) return;
     84  *x0 = 0.0;
     85  *y0 = 0.0;
     86  *x1 = 0.0;
     87  *y1 = 0.0;
     88
     89  *dXm = 0;
     90  *dXp = 0;
     91  *dYm = 0;
     92  *dYp = 0;
     93
     94  if (section == NULL) return FALSE;
    2295  graph = section->graph;
    23   if (graph == NULL) return;
     96  if (graph == NULL) return FALSE;
    2497
    2598  graphic = GetGraphic ();
     
    40113  // these depend on (a) existence of tick labels and (b) auto-offset or not
    41114  if (isnan(graph[0].axis[0].labelPad)) {
    42     dXm = (graph[0].axis[0].islabel) ? maxPAD  : minPAD;
    43   } else {
    44     dXm = graph[0].axis[0].labelPad * fontsize;
     115    *dXm = (graph[0].axis[0].islabel) ? maxPAD  : minPAD;
     116  } else {
     117    *dXm = graph[0].axis[0].labelPad * fontsize;
    45118  }
    46119  if (isnan(graph[0].axis[0].pad)) {
     
    53126  // these depend on (a) existence of tick labels and (b) auto-offset or not
    54127  if (isnan(graph[0].axis[2].labelPad)) {
    55     dXp = (graph[0].axis[2].islabel) ? maxPAD : minPAD;
    56   } else {
    57     dXp = graph[0].axis[2].labelPad * fontsize;
     128    *dXp = (graph[0].axis[2].islabel) ? maxPAD : minPAD;
     129  } else {
     130    *dXp = graph[0].axis[2].labelPad * fontsize;
    58131  }
    59132  if (isnan(graph[0].axis[2].pad)) {
     
    73146      if (!ticks[i].IsMajor) continue;
    74147
    75       int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[1].min, graph[0].axis[1].max);
     148      int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[1].min, graph[0].axis[1].max, ticks[i].nsignif);
    76149
    77150      Nc = MAX (Nc, Nchar);
     
    80153  }
    81154  if (isnan(graph[0].axis[1].labelPad)) {
    82     dYm = (graph[0].axis[1].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
    83   } else {
    84     dYm = graph[0].axis[1].labelPad * fontsize;
     155    *dYm = (graph[0].axis[1].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     156  } else {
     157    *dYm = graph[0].axis[1].labelPad * fontsize;
    85158  }
    86159  if (isnan(graph[0].axis[1].pad)) {
     
    98171    for (i = 0; i < Nticks; i++) {
    99172      if (!ticks[i].IsMajor) continue;
    100       int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[3].min, graph[0].axis[3].max);
     173      int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[3].min, graph[0].axis[3].max, ticks[i].nsignif);
    101174      Nc = MAX (Nc, Nchar);
    102175    }
     
    104177  }
    105178  if (isnan(graph[0].axis[3].labelPad)) {
    106     dYp = (graph[0].axis[3].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
    107   } else {
    108     dYp = graph[0].axis[3].labelPad * fontsize;
     179    *dYp = (graph[0].axis[3].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     180  } else {
     181    *dYp = graph[0].axis[3].labelPad * fontsize;
    109182  }
    110183  if (isnan(graph[0].axis[3].pad)) {
     
    115188
    116189  /* basic size of the graph in Xwindow coordinates, but measured from lower-left corner */
    117   X0 = graphic[0].dx * section[0].x + padYm;
    118   Y0 = graphic[0].dy * section[0].y + padXm;
    119   dX = graphic[0].dx * section[0].dx - padYm - padYp;
    120   dY = graphic[0].dy * section[0].dy - padXm - padXp;
     190  *x0 = padYm;
     191  *y0 = padXm;
     192  *x1 = padYm + padYp;
     193  *y1 = padXm + padXp;
    121194
    122195  // if we are tied to an image, make mods as needed
     
    128201    switch (section->image->location) {
    129202      case 0:
    130         // no changes?
    131203        break;
    132204      case 1:
    133         Y0 = graphic[0].dy * section[0].y  + padXm        + 2*PAD1 + WdY + 2;
    134         dY = graphic[0].dy * section[0].dy - padXm - padXp - 4*PAD1 - 1 - WdY - COLORPAD;
     205        *y0 = padXm + 2*PAD1 + WdY + 2;
     206        *y1 = padXm + padXp + 4*PAD1 + 1 + WdY + COLORPAD;
    135207        break;
    136208      case 3:
    137         dY = graphic[0].dy * section[0].dy - padXm - padXp - 4*PAD1 - 1 - WdY - COLORPAD;
     209        *y1 = padXm + padXp + 4*PAD1 + 1 + WdY + COLORPAD;
    138210        break;
    139211      case 2:
    140         X0 = graphic[0].dx * section[0].x  + padYm        + 2*PAD1 + ZOOM_X;
    141         dX = graphic[0].dx * section[0].dx - padYm - padYp - 3*PAD1 - ZOOM_X;
    142         dY = graphic[0].dy * section[0].dy - padXm - padXp - 2*PAD1 - COLORPAD;
     212        *x0 = padYm + 2*PAD1 + ZOOM_X;
     213        *x1 = padYm + padYp + 3*PAD1 + ZOOM_X;
     214        *y1 = padXm + padXp + 2*PAD1 + COLORPAD;
    143215        break;
    144216      case 4:
    145         dX = graphic[0].dx * section[0].dx - padYm - padYp - 3*PAD1 - ZOOM_X;
    146         dY = graphic[0].dy * section[0].dy - padXm - padXp - 2*PAD1 - COLORPAD;
     217        *x1 = padYm + padYp + 3*PAD1 + ZOOM_X;
     218        *y1 = padXm + padXp + 2*PAD1 + COLORPAD;
    147219        break;
    148220    }
    149221  }
    150222
    151   /* define locations of coordinate axes */
    152   graph[0].axis[0].fx  = X0;
    153   graph[0].axis[0].fy  = graphic->dy - Y0;
    154   graph[0].axis[0].dfx = dX;
    155   graph[0].axis[0].dfy = 0;
    156 
    157   graph[0].axis[1].fx  = X0;
    158   graph[0].axis[1].fy  = graphic->dy - Y0;
    159   graph[0].axis[1].dfx = 0;
    160   graph[0].axis[1].dfy = -dY;
    161 
    162   graph[0].axis[2].fx  = X0;
    163   graph[0].axis[2].fy  = graphic->dy - Y0 - dY;
    164   graph[0].axis[2].dfx = dX;
    165   graph[0].axis[2].dfy = 0;
    166 
    167   graph[0].axis[3].fx  = X0 + dX;
    168   graph[0].axis[3].fy  = graphic->dy - Y0;
    169   graph[0].axis[3].dfx = 0;
    170   graph[0].axis[3].dfy = -dY;
    171 
    172   /* define locations of axis labels */
    173   graph[0].label[LABELLL].x = graph[0].axis[0].fx;
    174   graph[0].label[LABELLL].y = graph[0].axis[0].fy + dXm;
    175   graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
    176   graph[0].label[LABELX0].y = graph[0].axis[0].fy + dXm;
    177   graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx;
    178   graph[0].label[LABELLR].y = graph[0].axis[0].fy + dXm;
    179 
    180   graph[0].label[LABELUL].x = graph[0].axis[2].fx;
    181   graph[0].label[LABELUL].y = graph[0].axis[2].fy - dXp;
    182   graph[0].label[LABELX1].x = graph[0].axis[2].fx + 0.5*graph[0].axis[2].dfx;
    183   graph[0].label[LABELX1].y = graph[0].axis[2].fy - dXp;
    184   graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx;
    185   graph[0].label[LABELUR].y = graph[0].axis[2].fy - dXp;
    186 
    187   graph[0].label[LABELY0].y = graph[0].axis[1].fy + 0.5*graph[0].axis[1].dfy;
    188   graph[0].label[LABELY0].x = graph[0].axis[1].fx - dYm;
    189 
    190   graph[0].label[LABELY1].y = graph[0].axis[3].fy + 0.5*graph[0].axis[3].dfy;
    191   graph[0].label[LABELY1].x = graph[0].axis[3].fx + dYp;
    192 
    193   // fprintf (stderr, "section %s, %f,%f : %f,%f\n", section->name, X0, Y0, dX, dY);
    194 
    195   /* these are wrong and have to be adjusted to sit in the corners */
    196 
     223  return (TRUE);
    197224}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawFrame.c

    r29539 r30118  
    22// bDrawLine is a function, not a macro like DrawLine
    33
    4 int bDrawFrame (KapaGraphWidget *graph) {
     4int bDrawFrame (bDrawBuffer *buffer, KapaGraphWidget *graph) {
    55 
    6   int i, j, Nticks, P;
    7   double fx, fy, dfx, dfy, lweight;
     6  int i, j, Nticks, P, doffset;
     7  double fx, fy, dfx, dfy, lweight, dx = 0, dy = 0;
    88  // Graphic graphic; is not needed
    99  TickMarkData *ticks;
     
    1414  /* each axis is drawn independently */
    1515  for (i = 0; i < 4; i++) {
    16     fx  = graph[0].axis[i].fx;
    17     fy  = graph[0].axis[i].fy;
    18     dfx = graph[0].axis[i].dfx;
    19     dfy = graph[0].axis[i].dfy;
    20     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    21 
    2216    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2317    color = MAX (0, MIN (15, graph[0].axis[i].color));
    2418
    25     bDrawSetStyle (color, lweight, 0);
    26     // function about sets solor and weight
     19    /* temporarily assume rectilinear axes */
     20    doffset = ((int)(lweight) % 2) ? 0.5*(lweight - 1) : 0.5*lweight;
     21    if (i == 0) { dx = doffset; dy = 0.0; }
     22    if (i == 2) { dx = doffset; dy = 0.0; }
     23    if (i == 1) { dx = 0.0; dy = doffset; }
     24    if (i == 3) { dx = 0.0; dy = doffset; }
     25
     26    fx  = graph[0].axis[i].fx - dx;
     27    fy  = graph[0].axis[i].fy - dy;
     28    dfx = graph[0].axis[i].dfx + 2*dx;
     29    dfy = graph[0].axis[i].dfy + 2*dy;
     30    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     31    P *= (1 + 0.25*lweight);
     32
     33    bDrawSetStyle (buffer, color, lweight, 0);
     34    // function about sets color and weight
    2735    // bDrawRotTextInit does not exist
    2836
    2937    if (graph[0].axis[i].isaxis) {
    30       bDrawLine (fx, fy, fx+dfx, fy+dfy);
     38      bDrawLine (buffer, fx, fy, fx+dfx, fy+dfy);
    3139    }
    3240   
     
    3442      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
    3543      for (j = 0; j < Nticks; j++) {
    36         bDrawTick (&graph[0].axis[i], P, &ticks[j], i);
     44        bDrawTick (buffer, &graph[0].axis[i], P, &ticks[j], i);
     45
     46        // XXX DrawTick sets the style to (color, 0, 0) for the font
     47        // should the font weight stay the same?
     48        // XXX probably not needed now:
     49        // bDrawSetStyle (buffer, color, lweight, 0);
    3750      }
    3851      FREE (ticks);
     
    4255}
    4356
    44 void bDrawTick (Axis *axis, int P, TickMarkData *tick, int naxis) {
     57void bDrawTick (bDrawBuffer *buffer, Axis *axis, int P, TickMarkData *tick, int naxis) {
    4558 
    4659  double x, y, dx, dy;
     
    7588  dy = dir*size*dfx*n;
    7689 
    77   bDrawLine (x, y, x+dx, y+dy);
     90  bDrawLine (buffer, x, y, x+dx, y+dy);
    7891
    7992  if (tick->IsLabel) {
     
    94107    yt = fy + (value-min)*dfy/(max - min) + dy;
    95108
    96     PrintTick (string, value, min, max);
    97     bDrawRotText (xt, yt, string, pos, 0.0);
     109    PrintTick (string, value, min, max, tick->nsignif);
     110    bDrawRotText (buffer, xt, yt, string, pos, 0.0);
    98111  }
    99112}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawIt.c

    r13479 r30118  
    11# include "Ximage.h"
    22
    3 bDrawBuffer *bDrawIt () {
     3bDrawBuffer *bDrawIt (png_color *palette, int Npalette, int Nbyte) {
    44
    55  int i, Nsection;
     
    1313  black = KapaColorByName ("black");
    1414
    15   buffer = bDrawBufferCreate (graphic->dx, graphic->dy);
    16   bDrawSetBuffer (buffer);
    17   bDrawSetStyle (black, 0, 0);
     15  buffer = bDrawBufferCreate (graphic->dx, graphic->dy, Nbyte, palette, Npalette);
     16  bDrawSetStyle (buffer, black, 0, 0);
    1817 
    1918  // reset the sizes for all sections
     
    2120  for (i = 0; i < Nsection; i++) {
    2221      section = GetSectionByNumber (i);
    23       bDrawGraph (section->graph);
    24       // bDrawImage (section->image);
     22      bDrawImage (buffer, section->image, graphic);
     23      bDrawGraph (buffer, section->graph);
    2524  }
    2625
     
    2827}
    2928
    30 void bDrawGraph (KapaGraphWidget *graph) {
     29void bDrawGraph (bDrawBuffer *buffer, KapaGraphWidget *graph) {
    3130  if (graph == NULL) return;
    32   bDrawFrame (graph);
    33   bDrawObjects (graph);
    34   bDrawLabels (graph);
    35   bDrawTextlines (graph);
     31  bDrawFrame (buffer, graph);
     32  bDrawObjects (buffer, graph);
     33  bDrawLabels (buffer, graph);
     34  bDrawTextlines (buffer, graph);
    3635}
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawLabels.c

    r13320 r30118  
    11# include "Ximage.h"
    22 
    3 void bDrawLabels (KapaGraphWidget *graph) {
     3void bDrawLabels (bDrawBuffer *buffer, KapaGraphWidget *graph) {
    44 
    55  int i, pos, x, y, size;
     
    2525      y = graph[0].label[i].y;
    2626      SetRotFont (graph[0].label[i].font, graph[0].label[i].size);
    27       bDrawRotText (x, y, graph[0].label[i].text, pos, angle);
     27      bDrawRotText (buffer, x, y, graph[0].label[i].text, pos, angle);
    2828    }
    2929  }
     
    3131}
    3232
    33 void bDrawTextlines (KapaGraphWidget *graph) {
     33void bDrawTextlines (bDrawBuffer *buffer, KapaGraphWidget *graph) {
    3434
    3535  int i, x, y, size;
     
    4444      y = graph[0].textline[i].y;
    4545      SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
    46       bDrawRotText (x, y, graph[0].textline[i].text, 5, angle);
     46      bDrawRotText (buffer, x, y, graph[0].textline[i].text, 5, angle);
    4747    }
    4848  }
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawObjects.c

    r27530 r30118  
    11# include "Ximage.h"
    22
    3 # define DrawLine(X1,Y1,X2,Y2) (bDrawLine ((X1), (Y1), (X2), (Y2)))
    4 # define DrawCircle(X1,Y1,R) (bDrawCircle ((X1), (Y1), (R)))
    5 # define DrawRectangle(X,Y,dX,dY) (bDrawRectOpen ((X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
    6 # define FillRectangle(X,Y,dX,dY) (bDrawRectFill ((X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
    7 # define FillTriangle(X1,Y1,X2,Y2,X3,Y3) (bDrawTriFill ((X1), (Y1), (X2), (Y2), (X3), (Y3)))
    8 # define OpenTriangle(X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen ((X1), (Y1), (X2), (Y2), (X3), (Y3)))
     3# define DrawLine(BUF,X1,Y1,X2,Y2) (bDrawLine (BUF, (X1), (Y1), (X2), (Y2)))
     4# define DrawCircle(BUF,X1,Y1,R) (bDrawCircle (BUF, (X1), (Y1), (R)))
     5# define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
     6# define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
     7# define FillTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriFill (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
     8# define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
    99
    1010# define CONNECT 0
     
    1414static Graphic *graphic;
    1515
    16 int bDrawObjects (KapaGraphWidget *graph) {
     16int bDrawObjects (bDrawBuffer *buffer, KapaGraphWidget *graph) {
    1717 
    1818  int i;
     
    3030    type = graph[0].objects[i].ltype;   
    3131    color = graph[0].objects[i].color;
    32     bDrawSetStyle (color, weight, type);
     32    bDrawSetStyle (buffer, color, weight, type);
    3333
    3434    switch (graph[0].objects[i].style) {
    3535      case CONNECT:
    36         bDrawConnect (graph, &graph[0].objects[i]);
     36        bDrawConnect (buffer, graph, &graph[0].objects[i]);
    3737        break;
    3838      case HISTOGRAM:
    39         bDrawHistogram (graph, &graph[0].objects[i]);
     39        bDrawHistogram (buffer, graph, &graph[0].objects[i]);
    4040        break;
    4141      case POINTS:
    42         bDrawPoints (graph, &graph[0].objects[i]);
     42        bDrawPoints (buffer, graph, &graph[0].objects[i]);
    4343        break;
    4444    }
    4545
    4646    if (graph[0].objects[i].etype & 0x01) {
    47       bDrawYErrors (graph, &graph[0].objects[i]);
     47      bDrawYErrors (buffer, graph, &graph[0].objects[i]);
    4848    }
    4949    if (graph[0].objects[i].etype & 0x02) {
    50       bDrawXErrors (graph, &graph[0].objects[i]);
    51     }
    52   }
    53   bDrawSetStyle (black, 0, 0);
     50      bDrawXErrors (buffer, graph, &graph[0].objects[i]);
     51    }
     52  }
     53  bDrawSetStyle (buffer, black, 0, 0);
    5454  return (TRUE);
    5555}
    5656
    57 void bDrawConnect (KapaGraphWidget *graph, Gobjects *object) {
     57void bDrawConnect (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
    5858 
    5959  int i;
     
    9191    sx1 = x[i]*mxi + y[i]*mxj + bx;
    9292    sy1 = x[i]*myi + y[i]*myj + by;
    93     bDrawClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     93    bDrawClipLine (buffer, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    9494    sx0 = sx1; sy0 = sy1;
    9595  }
    9696}
    9797
    98 void bDrawClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
     98void bDrawClipLine (bDrawBuffer *buffer, double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
    9999
    100100  /* skip line segement if both points are beyond box */
     
    145145    y1 = Y1;
    146146  }
    147   DrawLine (x0, y0, x1, y1);
     147  DrawLine (buffer, x0, y0, x1, y1);
    148148}
    149149
    150150/*******/
    151 void bDrawHistogram (KapaGraphWidget *graph, Gobjects *object) {
     151void bDrawHistogram (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
    152152
    153153  int i;
     
    192192    sy1 = MAX (MIN (sy1, Y0), Y1);
    193193    sxa = 0.5*(sx0 + sx1);
    194     DrawLine (sx0, sy0, sxa, sy0);
    195     DrawLine (sxa, sy0, sxa, sy1);
    196     DrawLine (sxa, sy1, sx1, sy1);
     194    DrawLine (buffer, sx0, sy0, sxa, sy0);
     195    DrawLine (buffer, sxa, sy0, sxa, sy1);
     196    DrawLine (buffer, sxa, sy1, sx1, sy1);
    197197    sx0 = sx1; sy0 = sy1;
    198198  }
     
    200200
    201201/*******/
    202 void bDrawPoints (KapaGraphWidget *graph, Gobjects *object) {
     202void bDrawPoints (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
    203203 
    204204  int i;
     
    233233            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    234234        {
    235           FillRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
     235          FillRectangle (buffer, sx, sy, 2*d*z[i], 2*d*z[i]);
    236236        }
    237237      }
     
    245245            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    246246        {
    247           DrawRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
     247          DrawRectangle (buffer, sx, sy, 2*d*z[i], 2*d*z[i]);
    248248        }
    249249      }
     
    257257            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    258258        {
    259           DrawLine (sx - d*z[i], sy, sx + d*z[i], sy);
    260           DrawLine (sx, sy - d*z[i], sx, sy + d*z[i]);
     259          DrawLine (buffer, sx - d*z[i], sy, sx + d*z[i], sy);
     260          DrawLine (buffer, sx, sy - d*z[i], sx, sy + d*z[i]);
    261261        }
    262262      }
     
    270270            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    271271        {
    272           DrawLine (sx + d*z[i], sy - d*z[i], sx - d*z[i], sy + d*z[i]);
    273           DrawLine (sx - d*z[i], sy - d*z[i], sx + d*z[i], sy + d*z[i]);
     272          DrawLine (buffer, sx + d*z[i], sy - d*z[i], sx - d*z[i], sy + d*z[i]);
     273          DrawLine (buffer, sx - d*z[i], sy - d*z[i], sx + d*z[i], sy + d*z[i]);
    274274        }
    275275      }
     
    283283            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    284284        {
    285           FillTriangle (sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i], sx, sy + 1.15*d*z[i]);
     285          FillTriangle (buffer, sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i], sx, sy + 1.15*d*z[i]);
    286286        }
    287287      }
     
    295295            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    296296        {
    297           OpenTriangle (sx - d*z[i], sy + 0.58*d*z[i], sx, sy - 1.15*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
     297          OpenTriangle (buffer, sx - d*z[i], sy + 0.58*d*z[i], sx, sy - 1.15*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
    298298        }
    299299      }
     
    307307            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    308308        {
    309           DrawLine (sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
    310           DrawLine (sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
    311           DrawLine (sx, sy, sx,          sy - 1.15*d*z[i]);
     309          DrawLine (buffer, sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
     310          DrawLine (buffer, sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
     311          DrawLine (buffer, sx, sy, sx,          sy - 1.15*d*z[i]);
    312312        }
    313313      }
     
    321321            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    322322        {
    323           DrawCircle (sx, sy, d*z[i]);
     323          DrawCircle (buffer, sx, sy, d*z[i]);
    324324        }
    325325      }
     
    333333            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    334334        {
    335           DrawLine (sx + 0.00*d*z[i], sy - 1.00*d*z[i], sx + 0.95*d*z[i], sy - 0.31*d*z[i]);
    336           DrawLine (sx + 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.58*d*z[i], sy + 0.81*d*z[i]);
    337           DrawLine (sx + 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.58*d*z[i], sy + 0.81*d*z[i]);
    338           DrawLine (sx - 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.95*d*z[i], sy - 0.31*d*z[i]);
    339           DrawLine (sx - 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.00*d*z[i], sy - 1.00*d*z[i]);
     335          DrawLine (buffer, sx + 0.00*d*z[i], sy - 1.00*d*z[i], sx + 0.95*d*z[i], sy - 0.31*d*z[i]);
     336          DrawLine (buffer, sx + 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.58*d*z[i], sy + 0.81*d*z[i]);
     337          DrawLine (buffer, sx + 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.58*d*z[i], sy + 0.81*d*z[i]);
     338          DrawLine (buffer, sx - 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.95*d*z[i], sy - 0.31*d*z[i]);
     339          DrawLine (buffer, sx - 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.00*d*z[i], sy - 1.00*d*z[i]);
    340340        }
    341341      }
     
    349349            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    350350        {
    351           DrawLine (sx -      d*z[i], sy,               sx - 0.50*d*z[i], sy + 0.87*d*z[i]);
    352           DrawLine (sx - 0.50*d*z[i], sy + 0.87*d*z[i], sx + 0.50*d*z[i], sy + 0.87*d*z[i]);
    353           DrawLine (sx + 0.50*d*z[i], sy + 0.87*d*z[i], sx +      d*z[i], sy);
    354 
    355           DrawLine (sx +      d*z[i], sy,               sx + 0.50*d*z[i], sy - 0.87*d*z[i]);
    356           DrawLine (sx + 0.50*d*z[i], sy - 0.87*d*z[i], sx - 0.50*d*z[i], sy - 0.87*d*z[i]);
    357           DrawLine (sx - 0.50*d*z[i], sy - 0.87*d*z[i], sx -      d*z[i], sy);
     351          DrawLine (buffer, sx -      d*z[i], sy,               sx - 0.50*d*z[i], sy + 0.87*d*z[i]);
     352          DrawLine (buffer, sx - 0.50*d*z[i], sy + 0.87*d*z[i], sx + 0.50*d*z[i], sy + 0.87*d*z[i]);
     353          DrawLine (buffer, sx + 0.50*d*z[i], sy + 0.87*d*z[i], sx +      d*z[i], sy);
     354
     355          DrawLine (buffer, sx +      d*z[i], sy,               sx + 0.50*d*z[i], sy - 0.87*d*z[i]);
     356          DrawLine (buffer, sx + 0.50*d*z[i], sy - 0.87*d*z[i], sx - 0.50*d*z[i], sy - 0.87*d*z[i]);
     357          DrawLine (buffer, sx - 0.50*d*z[i], sy - 0.87*d*z[i], sx -      d*z[i], sy);
    358358        }
    359359      }
     
    366366        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    367367        sy2 = x[i+1]*myi + y[i+1]*myj + by;
    368         DrawLine (sx1, sy1, sx2, sy2);
     368        DrawLine (buffer, sx1, sy1, sx2, sy2);
    369369      }
    370370    }
     
    380380            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    381381        {
    382           FillRectangle (sx, sy, 2*d, 2*d);
     382          FillRectangle (buffer, sx, sy, 2*d, 2*d);
    383383        }
    384384      }
     
    392392            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    393393        {
    394           DrawRectangle (sx, sy, 2*d, 2*d);
     394          DrawRectangle (buffer, sx, sy, 2*d, 2*d);
    395395        }
    396396      }
     
    404404            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    405405        {
    406           DrawLine (sx - d, sy, sx + d, sy);
    407           DrawLine (sx, sy - d, sx, sy + d);
     406          DrawLine (buffer, sx - d, sy, sx + d, sy);
     407          DrawLine (buffer, sx, sy - d, sx, sy + d);
    408408        }
    409409      }
     
    417417            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    418418        {
    419           DrawLine (sx + d, sy - d, sx - d, sy + d);
    420           DrawLine (sx - d, sy - d, sx + d, sy + d);
     419          DrawLine (buffer, sx + d, sy - d, sx - d, sy + d);
     420          DrawLine (buffer, sx - d, sy - d, sx + d, sy + d);
    421421        }
    422422      }
     
    430430            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    431431        {
    432           FillTriangle (sx - d, sy - 0.58*d, sx + d, sy - 0.58*d, sx, sy + 1.15*d);
     432          FillTriangle (buffer, sx - d, sy - 0.58*d, sx + d, sy - 0.58*d, sx, sy + 1.15*d);
    433433        }
    434434      }
     
    442442            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    443443        {
    444           OpenTriangle (sx - d, sy + 0.58*d, sx + d, sy + 0.58*d, sx, sy - 1.15*d);
     444          OpenTriangle (buffer, sx - d, sy + 0.58*d, sx + d, sy + 0.58*d, sx, sy - 1.15*d);
    445445        }
    446446      }
     
    454454            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    455455        {
    456           DrawLine (sx, sy, sx - d, sy - 0.58*d);
    457           DrawLine (sx, sy, sx + d, sy - 0.58*d);
    458           DrawLine (sx, sy, sx,     sy + 1.15*d);
     456          DrawLine (buffer, sx, sy, sx - d, sy - 0.58*d);
     457          DrawLine (buffer, sx, sy, sx + d, sy - 0.58*d);
     458          DrawLine (buffer, sx, sy, sx,     sy + 1.15*d);
    459459        }
    460460      }
     
    468468            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    469469        {
    470           DrawCircle (sx, sy, d);
     470          DrawCircle (buffer, sx, sy, d);
    471471        }
    472472      }
     
    480480            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    481481        {
    482           DrawLine (sx + 0.00*d, sy - 1.00*d, sx + 0.95*d, sy - 0.31*d);
    483           DrawLine (sx + 0.95*d, sy - 0.31*d, sx + 0.58*d, sy + 0.81*d);
    484           DrawLine (sx + 0.58*d, sy + 0.81*d, sx - 0.58*d, sy + 0.81*d);
    485           DrawLine (sx - 0.58*d, sy + 0.81*d, sx - 0.95*d, sy - 0.31*d);
    486           DrawLine (sx - 0.95*d, sy - 0.31*d, sx + 0.00*d, sy - 1.00*d);
     482          DrawLine (buffer, sx + 0.00*d, sy - 1.00*d, sx + 0.95*d, sy - 0.31*d);
     483          DrawLine (buffer, sx + 0.95*d, sy - 0.31*d, sx + 0.58*d, sy + 0.81*d);
     484          DrawLine (buffer, sx + 0.58*d, sy + 0.81*d, sx - 0.58*d, sy + 0.81*d);
     485          DrawLine (buffer, sx - 0.58*d, sy + 0.81*d, sx - 0.95*d, sy - 0.31*d);
     486          DrawLine (buffer, sx - 0.95*d, sy - 0.31*d, sx + 0.00*d, sy - 1.00*d);
    487487        }
    488488      }
     
    496496            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    497497        {
    498           DrawLine (sx - 1.00*d, sy + 0.00*d, sx - 0.50*d, sy + 0.87*d);
    499           DrawLine (sx - 0.50*d, sy + 0.87*d, sx + 0.50*d, sy + 0.87*d);
    500           DrawLine (sx + 0.50*d, sy + 0.87*d, sx + 1.00*d, sy + 0.00*d);
    501           DrawLine (sx + 1.00*d, sy + 0.00*d, sx + 0.50*d, sy - 0.87*d);
    502           DrawLine (sx + 0.50*d, sy - 0.87*d, sx - 0.50*d, sy - 0.87*d);
    503           DrawLine (sx - 0.50*d, sy - 0.87*d, sx - 1.00*d, sy + 0.00*d);
     498          DrawLine (buffer, sx - 1.00*d, sy + 0.00*d, sx - 0.50*d, sy + 0.87*d);
     499          DrawLine (buffer, sx - 0.50*d, sy + 0.87*d, sx + 0.50*d, sy + 0.87*d);
     500          DrawLine (buffer, sx + 0.50*d, sy + 0.87*d, sx + 1.00*d, sy + 0.00*d);
     501          DrawLine (buffer, sx + 1.00*d, sy + 0.00*d, sx + 0.50*d, sy - 0.87*d);
     502          DrawLine (buffer, sx + 0.50*d, sy - 0.87*d, sx - 0.50*d, sy - 0.87*d);
     503          DrawLine (buffer, sx - 0.50*d, sy - 0.87*d, sx - 1.00*d, sy + 0.00*d);
    504504        }
    505505      }
     
    512512        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    513513        sy2 = x[i+1]*myi + y[i+1]*myj + by;
    514         DrawLine (sx1, sy1, sx2, sy2);
     514        DrawLine (buffer, sx1, sy1, sx2, sy2);
    515515      }
    516516    }
     
    519519   
    520520/*******/
    521 void bDrawXErrors (KapaGraphWidget *graph, Gobjects *object) {
     521void bDrawXErrors (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
    522522 
    523523  int i, bar;
     
    553553         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    554554    {
    555       DrawLine (sx0, sy0, sx1, sy1);
     555      DrawLine (buffer, sx0, sy0, sx1, sy1);
    556556      if (bar) {
    557557        sx10 = sy1 - sz;
    558558        sx11 = sy1 + sz;
    559         DrawLine (sx1, sx10, sx1, sx11);
     559        DrawLine (buffer, sx1, sx10, sx1, sx11);
    560560      }
    561561    }
     
    570570         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    571571    {
    572       DrawLine (sx0, sy0, sx1, sy1);
     572      DrawLine (buffer, sx0, sy0, sx1, sy1);
    573573      if (bar) {
    574574        sx10 = sy1 - sz;
    575575        sx11 = sy1 + sz;
    576         DrawLine (sx1, sx10, sx1, sx11);
     576        DrawLine (buffer, sx1, sx10, sx1, sx11);
    577577      }
    578578    }
     
    581581   
    582582/*******/
    583 void bDrawYErrors (KapaGraphWidget *graph, Gobjects *object) {
     583void bDrawYErrors (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
    584584 
    585585  int i, bar;
     
    615615         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    616616    {
    617       DrawLine (sx0, sy0, sx1, sy1);
     617      DrawLine (buffer, sx0, sy0, sx1, sy1);
    618618      if (bar) {
    619619        sx10 = sx1 - sz;
    620620        sx11 = sx1 + sz;
    621         DrawLine (sx10, sy1, sx11, sy1);
     621        DrawLine (buffer, sx10, sy1, sx11, sy1);
    622622      }
    623623    }
     
    632632         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    633633    {
    634       DrawLine (sx0, sy0, sx1, sy1);
     634      DrawLine (buffer, sx0, sy0, sx1, sy1);
    635635      if (bar) {
    636636        sx10 = sx1 - sz;
    637637        sx11 = sx1 + sz;
    638         DrawLine (sx10, sy1, sx11, sy1);
     638        DrawLine (buffer, sx10, sy1, sx11, sy1);
    639639      }
    640640    }
  • branches/czw_branch/20101203/Ohana/src/kapa2/src/bDrawOverlay.c

    r25757 r30118  
    44static char name[4][16] = {"red", "green", "blue", "yellow"};
    55
    6 void bDrawOverlay (KapaImageWidget *image, int N) {
     6void bDrawOverlay (bDrawBuffer *buffer, KapaImageWidget *image, int N) {
    77
    88  int i;
     
    1414  /* translate color to bDrawColors : image[0].overlay[N].color */
    1515  color = KapaColorByName (name[N]);
    16   bDrawSetStyle (color, 0, 0);
     16  bDrawSetStyle (buffer, color, 0, 0);
    1717 
    1818  expand = 1.0;
     
    5757    switch (image[0].overlay[N].objects[i].type) {
    5858      case KII_OVERLAY_LINE:
    59         bDrawLine (X, Y, (X+dX), (Y+dY));
     59        bDrawLine (buffer, X, Y, (X+dX), (Y+dY));
    6060        break;
    6161      case KII_OVERLAY_TEXT:
    62         bDrawRotText (X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
     62        bDrawRotText (buffer, X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
    6363        break;
    6464      case KII_OVERLAY_BOX:
    6565        dx = MAX (abs(dX),2) / 2;
    6666        dy = MAX (abs(dY),2) / 2;
    67         bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
    68         // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
     67        bDrawRectOpen (buffer, (X-dx), (Y-dy), (X+dx), (Y+dy));
     68        // bDrawRectOpen (buffer, (X-dx), (Y-dy), (X), (Y));
    6969        break;
    7070      case KII_OVERLAY_CIRCLE:
     
    7272        dy = MAX (abs(dY),2);
    7373        if (image[0].overlay[N].objects[i].angle == 0.0) {
    74           bDrawArc (X, Y, dx, dy, 0, 360);
     74          bDrawArc (buffer, X, Y, dx, dy, 0, 360);
    7575        } else {
    7676          // moderately-stupid rotated ellipse drawing:
     
    8888            x1 = X + pX*dx*cos(t)*cs - pX*dy*sin(t)*sn;
    8989            y1 = Y + pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
    90             bDrawLine (x0, y0, x1, y1);
     90            bDrawLine (buffer, x0, y0, x1, y1);
    9191            x0 = x1;
    9292            y0 = y1;
     
    101101 
    102102  /* translate color to bDrawColors : image[0].overlay[N].color */
    103   bDrawSetStyle (color, 0, 0);
     103  bDrawSetStyle (buffer, color, 0, 0);
    104104}
    105105
  • branches/czw_branch/20101203/Ohana/src/libdvo/include/dvo.h

    r29001 r30118  
    5858// these are used as NAN for types of int values
    5959typedef enum {
    60     NAN_S_CHAR  = 0x7f,
    61     NAN_U_CHAR  = 0xff,   // was NO_ERR
    62     NAN_S_SHORT = 0x7fff, // was NO_MAG
    63     NAN_U_SHORT = 0xffff,
    64     NAN_S_INT   = 0x7fffffff,
    65     NAN_U_INT   = 0xffffffff,
     60  NAN_S_CHAR  = 0x7f,
     61  NAN_U_CHAR  = 0xff,   // was NO_ERR
     62  NAN_S_SHORT = 0x7fff, // was NO_MAG
     63  NAN_U_SHORT = 0xffff,
     64  NAN_S_INT   = 0x7fffffff,
     65  NAN_U_INT   = (signed int) 0xffffffff,
    6666} DVO_INT_NAN;
    6767
     
    135135/* Average.code values -- these values are 32 bit (as of PS1_V1) */
    136136typedef enum {
    137   ID_STAR_FEW     = 0x00000001, // used within relphot: skip star 
    138   ID_STAR_POOR    = 0x00000002, // used within relphot: skip star 
    139   ID_PROPER       = 0x00000400, // star with large proper motion 
    140   ID_TRANSIENT    = 0x00001000, // is this mutually exclusive with USNO? 
    141   ID_VARIABLE     = 0x00002000, // not currently set? 
    142   ID_ASTEROID     = 0x00002000, // identified with an asteroid 
    143   ID_BAD_OBJECT   = 0x00004000, // if all measurements are bad, set this bit 
     137  ID_STAR_FEW     = 0x00000001, // used within relphot: skip star
     138  ID_STAR_POOR    = 0x00000002, // used within relphot: skip star
     139  ID_PROPER       = 0x00000400, // star with large proper motion
     140  ID_TRANSIENT    = 0x00001000, // is this mutually exclusive with USNO?
     141  ID_VARIABLE     = 0x00002000, // not currently set?
     142  ID_ASTEROID     = 0x00002000, // identified with an asteroid
     143  ID_BAD_OBJECT   = 0x00004000, // if all measurements are bad, set this bit
    144144  ID_MOVING       = 0x00008000, // is a moving object
    145   ID_ROCK         = 0x0000a000, // 0x8000 + 0x2000 
    146   ID_GHOST        = 0x0000c001, // 0x8000 + 0x4000 + 0x0001 
    147   ID_TRAIL        = 0x0000c002, // 0x8000 + 0x4000 + 0x0002 
    148   ID_BLEED        = 0x0000c003, // 0x8000 + 0x4000 + 0x0003 
    149   ID_COSMIC       = 0x0000c004, // 0x8000 + 0x4000 + 0x0004 
     145  ID_ROCK         = 0x0000a000, // 0x8000 + 0x2000
     146  ID_GHOST        = 0x0000c001, // 0x8000 + 0x4000 + 0x0001
     147  ID_TRAIL        = 0x0000c002, // 0x8000 + 0x4000 + 0x0002
     148  ID_BLEED        = 0x0000c003, // 0x8000 + 0x4000 + 0x0003
     149  ID_COSMIC       = 0x0000c004, // 0x8000 + 0x4000 + 0x0004
    150150  ID_STAR_FIT_AVE = 0x00010000, // average position fitted
    151151  ID_STAR_FIT_PM  = 0x00020000, // proper motion fitted
     
    156156  ID_OBJ_EXT      = 0x01000000, // extended in our data (eg, PS)
    157157  ID_OBJ_EXT_ALT  = 0x02000000, // extended in external data (eg, 2MASS)
    158   ID_OBJ_GOOD     = 0x04000000, // good-quality measurement in our data (eg, PS)
    159   ID_OBJ_GOOD_ALT = 0x08000000, // good-quality measurement in external data (eg, 2MASS)
     158  ID_OBJ_GOOD     = 0x04000000, // good-quality measurement in our data (eg,PS)
     159  ID_OBJ_GOOD_ALT = 0x08000000, // good-quality measurement in  external data (eg, 2MASS)
    160160} DVOAverageFlags;
    161161
     
    233233     *** that is just silly, and bad: convert to using Nsec_mem, Nsec_disk, Nsec_off.
    234234     *** unless we always require the secfilt and average entries to be loaded sychronously.
    235    */
     235     */
    236236
    237237  /* pointers to split data files */
     
    293293int isRegisteredMosaic (void);
    294294off_t GetRegisteredMosaic (void);
     295off_t *GetChipMatch (void);
    295296int GetMosaicCoords (Coords *coords);
    296297int FindMosaicForImage (Image *images, off_t Nimages, off_t entry);
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_catalog.c

    r27580 r30118  
    302302int dvo_catalog_save (Catalog *catalog, char VERBOSE) {
    303303
     304  int status = FALSE;
     305
    304306  // set the 'sorted' header keyword
    305307  gfits_modify_alt (&catalog[0].header, "SORTED",  "%t", 1, catalog[0].sorted);
     
    308310  switch (catalog[0].catmode) {
    309311    case DVO_MODE_RAW:
    310       dvo_catalog_save_raw (catalog, VERBOSE);
     312      status = dvo_catalog_save_raw (catalog, VERBOSE);
    311313      break;
    312314    case DVO_MODE_MEF:
    313       dvo_catalog_save_mef (catalog, VERBOSE);
     315      status = dvo_catalog_save_mef (catalog, VERBOSE);
    314316      break;
    315317    case DVO_MODE_SPLIT:
    316       dvo_catalog_save_split (catalog, VERBOSE);
     318      status = dvo_catalog_save_split (catalog, VERBOSE);
    317319      break;
    318320    default:
     
    320322      exit (2);
    321323  }
    322   return (TRUE);
     324  return (status);
    323325}
    324326
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r29001 r30118  
    6666  /* read Average table data (or skip) */
    6767  if (catalog[0].catflags & LOAD_AVES) {
    68     if (!gfits_fread_ftable_data (f, &ftable)) {
     68    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    6969      if (VERBOSE) fprintf (stderr, "can't read table average data");
    7070      return (FALSE);
     
    9494  /* read Measure table data */
    9595  if (catalog[0].catflags & LOAD_MEAS) {
    96     if (!gfits_fread_ftable_data (f, &ftable)) {
     96    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    9797      if (VERBOSE) fprintf (stderr, "can't read table measure data");
    9898      return (FALSE);
     
    119119  /* read Missing table data */
    120120  if (catalog[0].catflags & LOAD_MISS) {
    121     if (!gfits_fread_ftable_data (f, &ftable)) {
     121    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    122122      if (VERBOSE) fprintf (stderr, "can't read table missing data");
    123123      return (FALSE);
     
    149149  /* read secfilt table data */
    150150  if (catalog[0].catflags & LOAD_SECF) {
    151     if (!gfits_fread_ftable_data (f, &ftable)) {
     151    if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
    152152      if (VERBOSE) fprintf (stderr, "can't read table secfilt data");
    153153      return (FALSE);
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_catalog_split.c

    r29001 r30118  
    218218    }
    219219    /* read Average table data : format is irrelevant here */
    220     if (!gfits_fread_ftable_data (catalog[0].f, &ftable)) {
     220    if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) {
    221221      if (VERBOSE) fprintf (stderr, "can't read table average data");
    222222      return (FALSE);
     
    249249    // XXX this allows an empty Measure catalog with non-empty Average catalog : is that OK?
    250250    /* read Measure table data */
    251     if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable)) {
     251    if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable, FALSE)) {
    252252      if (VERBOSE) fprintf (stderr, "can't read table measure data\n");
    253253      return (FALSE);
     
    279279  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MISS)) {
    280280    /* read Missing table data */
    281     if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable)) {
     281    if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable, FALSE)) {
    282282      if (VERBOSE) fprintf (stderr, "can't read table missing data\n");
    283283      return (FALSE);
     
    313313  if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_SECF)) {
    314314    /* read secfilt table data */
    315     if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable)) {
     315    if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable, FALSE)) {
    316316      if (VERBOSE) fprintf (stderr, "can't read table secfilt data\n");
    317317      return (FALSE);
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r29182 r30118  
    557557      }
    558558    }
    559     if (entry == -1) {
    560       // entry is missing fail (no printfs in this file)
    561       free(map);
    562       return(FALSE);
    563     }
     559    // if (entry == -1) {
     560    //   // entry is missing fail (no printfs in this file)
     561    //   free(map);
     562    //   return(FALSE);
     563    // }
     564
     565    // if entry is still -1, we will skip this one (not map into the output db)
    564566    map[i] = entry;
    565567  }
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/fits_db.c

    r28246 r30118  
    8383    return (FALSE);
    8484  }
    85   if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable)) {
     85  if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable, FALSE)) {
    8686    fprintf (stderr, "can't read table data");
    8787    gfits_db_free (db);
  • branches/czw_branch/20101203/Ohana/src/libdvo/src/mosaic_astrom.c

    r27435 r30118  
    1717}
    1818
     19/* what is the currently registered mosaic image? */
     20off_t *GetChipMatch () {
     21  return (ChipMatch);
     22}
     23
    1924/* given an image array and a current entry of type WRP, find matching DIS & Register it */
    2025int FindMosaicForImage (Image *images, off_t Nimages, off_t entry) {
     
    4045  if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
    4146    /* not a wrp image, do nothing */
    42     return (TRUE); /* error or not */
     47    return (entry + 1); /* error or not */
    4348  }
    4449
     
    5257    RegisterMosaic (&images[i].coords);
    5358    iDIS = i;
    54     return (TRUE);
     59    return (i + 1);
    5560  }
    5661
     
    6267    RegisterMosaic (&images[i].coords);
    6368    iDIS = i;
    64     return (TRUE);
     69    return (i + 1);
    6570  }
    6671  return (FALSE);
     
    7479  if (strcmp(&images[entry].coords.ctype[4], "-WRP")) {
    7580    /* not a wrp image, do nothing */
    76     return (TRUE); /* error or not? */
     81    return (entry + 1); /* error or not? */
    7782  }
    7883
     
    8590  RegisterMosaic (&images[N].coords);
    8691  iDIS = N;
    87   return (TRUE);
     92  return (N + 1);
    8893}
    8994
     
    165170  SortDISindex (DIStzero, DISentry, Ndis);
    166171
     172  // ChipMatch has a few possible values:
     173  // -3 : image is a mosaic (DIS)
     174  // -2 : image is an unassigned WRP image
     175  // -1 : image is not a WRP or DIS images
     176  // >= 0 : value is the mosaic seq number for this WRP image
     177
    167178  /* find all matched WRP images */
    168179  ALLOCATE (ChipMatch, off_t, Nimages);
    169180  for (i = 0; i < Nimages; i++) {
    170181    ChipMatch[i] = -1;
     182    if (!strcmp(&images[i].coords.ctype[4], "-DIS")) {
     183      ChipMatch[i] = -3;
     184      continue;
     185    }
    171186    if (strcmp(&images[i].coords.ctype[4], "-WRP")) continue;
    172187
  • branches/czw_branch/20101203/Ohana/src/libfits/include/gfitsio.h

    r29537 r30118  
    6464  char                   *buffer;
    6565  off_t                   datasize;
     66  off_t                   validsize;
    6667} FTable;
    6768
     
    172173int     gfits_define_table_column      PROTO((Header *header, char *format, char *label, char *comment, char *unit));
    173174int     gfits_fread_ftable             PROTO((FILE *f, FTable *ftable, char *extname));
    174 int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable));
     175int     gfits_fread_ftable_data        PROTO((FILE *f, FTable *ftable, int padIfShort));
    175176int     gfits_fread_ftable_range       PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows));
    176177int     gfits_fread_vtable             PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row));
  • branches/czw_branch/20101203/Ohana/src/libfits/table/F_read_T.c

    r28241 r30118  
    3636    gfits_scan (header, "EXTNAME", "%s", 1, tname);
    3737    if (!strcmp (tname, extname)) {
    38       if (gfits_fread_ftable_data (f, table)) return (TRUE);
     38      if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE);
    3939      gfits_free_header (header);
    4040      return (FALSE);
     
    5050
    5151/*********************** fits read ftable data ***********************************/
    52 int gfits_fread_ftable_data (FILE *f, FTable *table) {
     52int gfits_fread_ftable_data (FILE *f, FTable *table, int padIfShort) {
    5353
    5454  off_t Nbytes, Nread;
     
    6565    if (Nread < gfits_data_min_size (table[0].header)) {
    6666      fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  gfits_data_min_size (table[0].header));
    67       gfits_free_table  (table);
    68       return (FALSE);
     67      if (padIfShort) {
     68        memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     69        fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
     70        table[0].validsize = Nread;
     71        table[0].datasize = Nbytes;
     72        return (TRUE);
     73      } else {
     74        gfits_free_table  (table);
     75        return (FALSE);
     76      }
    6977    }
    7078    fprintf (stderr, "warning: file missing pad\n");
    7179  }
     80  table[0].validsize = Nread;
    7281  table[0].datasize = Nbytes;
    7382  return (TRUE);
  • branches/czw_branch/20101203/Ohana/src/libkapa/include/kapa.h

    r29537 r30118  
    115115
    116116typedef struct {
    117   int Nx, Ny;
     117  int Nx, Ny, Nbyte;
    118118  bDrawColor **pixels;
     119  png_color *palette;
     120  int Npalette;
     121  // current drawing values:
     122  int bWeight;
     123  int bType;
     124  bDrawColor bColor;
     125  bDrawColor bColor_R;
     126  bDrawColor bColor_G;
     127  bDrawColor bColor_B;
    119128} bDrawBuffer;
    120129
     
    165174/* KapaWindow.c */
    166175int KiiResize (int fd, int Nx, int Ny);
     176int KiiResizeByImage (int fd);
    167177int KiiRelocate (int fd, int x, int y);
    168178int KiiCenter (int fd, double x, double y, int zoom);
     
    182192int KapaGetLimits (int fd, float *dx, float *dy);
    183193int KapaSetSection (int fd, KapaSection *section);
     194int KapaSetSectionByImage (int fd, KapaSection *section);
    184195int KapaSelectSection (int fd, char *name);
    185196int KapaGetSection (int fd, char *name);
     
    221232
    222233/* bDrawFuncs.c */
    223 bDrawBuffer *bDrawBufferCreate (int Nx, int Ny);
     234bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette);
    224235void bDrawBufferFree (bDrawBuffer *buffer);
    225236void bDrawSetBuffer (bDrawBuffer *buffer);
    226 void bDrawSetStyle (bDrawColor color, int lw, int lt);
    227 void bDrawPoint (int x, int y);
    228 void bDrawPointf (float x, float y);
    229 
    230 void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
    231 void bDrawCircle (double Xc, double Yc, double radius);
    232 void bDrawCircleFill (double xc, double yc, double radius);
    233 
    234 void bDrawLine (double x1, double y1, double x2, double y2);
    235 void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords);
    236 void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords);
    237 void bDrawLineHorizontal (int X1, int X2, int Y);
    238 void bDrawLineVertical (int X, int Y1, int Y2);
    239 
    240 void bDrawRectOpen (double x1, double y1, double x2, double y2);
    241 void bDrawRectFill (double x1, double y1, double x2, double y2);
    242 void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3);
    243 void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3);
     237void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt);
     238void bDrawPoint (bDrawBuffer *buffer, int x, int y);
     239void bDrawPointf (bDrawBuffer *buffer, float x, float y);
     240
     241void bDrawArc (bDrawBuffer *buffer, double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
     242void bDrawCircle (bDrawBuffer *buffer, double Xc, double Yc, double radius);
     243void bDrawCircleFill (bDrawBuffer *buffer, double xc, double yc, double radius);
     244
     245void bDrawLine (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
     246void bDrawLineWeight (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords);
     247void bDrawLineBresen (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords);
     248void bDrawLineHorizontal (bDrawBuffer *buffer, int X1, int X2, int Y);
     249void bDrawLineVertical (bDrawBuffer *buffer, int X, int Y1, int Y2);
     250
     251void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
     252void bDrawRectFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
     253void bDrawTriOpen  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
     254void bDrawTriFill  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
    244255
    245256/* bDrawRotFont.c */
    246 int bDrawRotText (int x, int y, char *string, int pos, double angle);
    247 int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
     257int bDrawRotText (bDrawBuffer *buffer, int x, int y, char *string, int pos, double angle);
     258int bDrawRotBitmap (bDrawBuffer *buffer, int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
    248259
    249260/* Kapa Socket functions */
  • branches/czw_branch/20101203/Ohana/src/libkapa/src/KapaWindow.c

    r27790 r30118  
    2323  KiiSendCommand (fd, 4, "RSIZ");
    2424  KiiSendMessage (fd, "%d %d", Nx, Ny);
     25  KiiWaitAnswer (fd, "DONE");
     26  return (TRUE);
     27}
     28
     29int KiiResizeByImage (int fd) {
     30
     31  KiiSendCommand (fd, 4, "ISIZ");
    2532  KiiWaitAnswer (fd, "DONE");
    2633  return (TRUE);
     
    370377}
    371378
     379int KapaSetSectionByImage (int fd, KapaSection *section) {
     380
     381  KiiSendCommand (fd, 4, "ISEC");
     382  KiiSendMessage (fd, "%s %6.3f %6.3f %3d",
     383                  section[0].name,
     384                  section[0].x,
     385                  section[0].y,
     386                  section[0].bg);
     387  KiiWaitAnswer (fd, "DONE");
     388  return (TRUE);
     389}
     390
    372391int KapaSectionBG (int fd, char *name, int bg) {
    373392
  • branches/czw_branch/20101203/Ohana/src/libkapa/src/bDrawFuncs.c

    r29537 r30118  
    11# include <kapa_internal.h>
    2 
    3 // XXX we can get rid of these static vars by making them elements of the bDrawBuffer
    4 //
    5 
    6 
    7 static int bWeight;
    8 static int bType;
    9 static bDrawColor bColor;
    10 static bDrawBuffer *bBuffer;
    11 void bDrawCircleSingle (double xc, double yc, double radius);
    12 
    13 bDrawBuffer *bDrawBufferCreate (int Nx, int Ny) {
     2# define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort (); } }
     3
     4// move these to the bDrawBuffer type
     5// static int bWeight;
     6// static int bType;
     7// static bDrawColor bColor;
     8// static bDrawColor bColor_R;
     9// static bDrawColor bColor_G;
     10// static bDrawColor bColor_B;
     11// static bDrawBuffer *bBuffer;
     12
     13void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius);
     14
     15// create a drawing buffer with either 1 or 3 byte colors
     16bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette) {
    1417
    1518  int i, j;
    16   bDrawColor white;
     19  bDrawColor white, white_R, white_G, white_B;
    1720  bDrawBuffer *buffer;
    1821
     22  myAssert((Nbyte == 1) || (Nbyte == 3), "invalid depth");
     23  myAssert(palette, "missing palette");
     24
    1925  white = KapaColorByName ("white");
     26  white_R = palette[white].red;
     27  white_G = palette[white].green;
     28  white_B = palette[white].blue;
    2029
    2130  ALLOCATE (buffer, bDrawBuffer, 1);
    2231  buffer[0].Nx = Nx;
    2332  buffer[0].Ny = Ny;
     33  buffer[0].Nbyte = Nbyte;
     34  buffer[0].palette = palette;
     35  buffer[0].Npalette = Npalette;
    2436
    2537  ALLOCATE (buffer[0].pixels, bDrawColor *, Ny);
    2638  for (i = 0; i < Ny; i++) {
    27     ALLOCATE (buffer[0].pixels[i], bDrawColor, Nx);
     39    ALLOCATE (buffer[0].pixels[i], bDrawColor, Nbyte*Nx);
    2840    for (j = 0; j < Nx; j++) {
    29       buffer[0].pixels[i][j] = white;
    30     }
    31   }
     41      if (Nbyte == 1) {
     42        buffer[0].pixels[i][j] = white;
     43      } else {
     44        buffer[0].pixels[i][3*j+0] = white_R;
     45        buffer[0].pixels[i][3*j+1] = white_G;
     46        buffer[0].pixels[i][3*j+2] = white_B;
     47      }
     48    }
     49  }
     50
     51  buffer[0].bWeight = 0;
     52  buffer[0].bType = 0;
     53  buffer[0].bColor = white;
     54  buffer[0].bColor_R = white_R;
     55  buffer[0].bColor_G = white_G;
     56  buffer[0].bColor_B = white_B;
    3257  return (buffer);
    3358}
     
    4166  }
    4267  free (buffer[0].pixels);
     68  free (buffer[0].palette);
    4369  free (buffer);
    4470  return;
    4571}
    4672
    47 void bDrawSetBuffer (bDrawBuffer *buffer) {
    48   bBuffer = buffer;
    49   return;
    50 }
    51 
    52 void bDrawSetStyle (bDrawColor color, int lw, int lt) {
    53   bColor = color;
    54   bWeight = lw;
    55   bType = lt;
     73// void bDrawSetBuffer (bDrawBuffer *buffer) {
     74//   myAssert(buffer[0].Nbyte == 1, "invalid depth");
     75//   bBuffer = buffer;
     76//   return;
     77// }
     78
     79void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
     80  buffer->bColor = color;
     81  buffer->bColor_R = buffer->palette[color].red;
     82  buffer->bColor_G = buffer->palette[color].green;
     83  buffer->bColor_B = buffer->palette[color].blue;
     84  buffer->bWeight = lw;
     85  buffer->bType = lt;
    5686  return;
    5787}
    5888
    5989// draw a point in the current color
    60 void bDrawPoint (int x, int y) {
    61 
     90void bDrawPoint (bDrawBuffer *buffer, int x, int y) {
     91
     92  // myAssert(buffer[0].Nbyte == 1, "invalid depth");
    6293  if (x < 0) return;
    6394  if (y < 0) return;
    64   if (x >= bBuffer[0].Nx) return;
    65   if (y >= bBuffer[0].Ny) return;
    66   bBuffer[0].pixels[y][x] = bColor;
     95  if (x >= buffer[0].Nx) return;
     96  if (y >= buffer[0].Ny) return;
     97  if (buffer[0].Nbyte == 1) {
     98    buffer[0].pixels[y][x] = buffer->bColor;
     99  } else {
     100    buffer[0].pixels[y][3*x+0] = buffer->bColor_R;
     101    buffer[0].pixels[y][3*x+1] = buffer->bColor_G;
     102    buffer[0].pixels[y][3*x+2] = buffer->bColor_B;
     103  }
    67104  return;
    68105}
    69106
    70107// draw a point in the current color
    71 void bDrawPointf (float x, float y) {
    72 
    73   bDrawPoint (ROUND(x), ROUND(y));
    74   return;
    75 }
    76 
    77 void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3) {
    78 
    79   bDrawLine (x1, y1, x2, y2);
    80   bDrawLine (x2, y2, x3, y3);
    81   bDrawLine (x3, y3, x1, y1);
    82 
    83   return;
    84 }
    85 
    86 void bDrawRectOpen (double x1, double y1, double x2, double y2) {
     108void bDrawPointf (bDrawBuffer *buffer, float x, float y) {
     109
     110  bDrawPoint (buffer, ROUND(x), ROUND(y));
     111  return;
     112}
     113
     114void bDrawTriOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3) {
     115
     116  bDrawLine (buffer, x1, y1, x2, y2);
     117  bDrawLine (buffer, x2, y2, x3, y3);
     118  bDrawLine (buffer, x3, y3, x1, y1);
     119
     120  return;
     121}
     122
     123void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
    87124
    88125  int X1, Y1, X2, Y2;
     
    91128  if (y1 > y2) SWAP (y1, y2);
    92129
    93   X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
    94   X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
    95 
    96   Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
    97   Y2 = MIN (MAX (ROUND (y2), 1), bBuffer[0].Ny);
    98 
    99   bDrawLineHorizontal (X1, X2, Y1);
    100   bDrawLineHorizontal (X1, X2, Y2);
    101   bDrawLineVertical (X1, Y1, Y2);
    102   bDrawLineVertical (X2, Y1, Y2);
    103   return;
    104 }
    105 
    106 void bDrawRectFill (double x1, double y1, double x2, double y2) {
     130  X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1);
     131  X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1);
     132
     133  Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1);
     134  Y2 = MIN (MAX (ROUND (y2), 1), buffer[0].Ny - 1);
     135
     136  bDrawLineHorizontal (buffer, X1, X2, Y1);
     137  bDrawLineHorizontal (buffer, X1, X2, Y2);
     138  bDrawLineVertical   (buffer, X1, Y1, Y2);
     139  bDrawLineVertical   (buffer, X2, Y1, Y2);
     140  return;
     141}
     142
     143void bDrawRectFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
    107144
    108145  int i;
     
    112149  if (y1 > y2) SWAP (y1, y2);
    113150
    114   X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
    115   X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
    116 
    117   Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
    118   Y2 = MIN (MAX (ROUND (y2), 0), bBuffer[0].Ny);
     151  X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1);
     152  X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1);
     153
     154  Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1);
     155  Y2 = MIN (MAX (ROUND (y2), 0), buffer[0].Ny - 1);
    119156
    120157  for (i = Y1; i < Y2; i++) {
    121     bDrawLineHorizontal (X1, X2, i);
     158    bDrawLineHorizontal (buffer, X1, X2, i);
    122159  }
    123160  return;
     
    125162
    126163// identify the quadrant and draw the correct line
    127 void bDrawLine (double x1, double y1, double x2, double y2) {
     164void bDrawLine (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
    128165
    129166  int FlipDirect, FlipCoords;
     
    144181  FlipDirect = FlipCoords ? (y1 > y2) : (x1 > x2);
    145182
    146   if (!FlipDirect && !FlipCoords) bDrawLineWeight (X1, Y1, X2, Y2, FALSE);
    147   if ( FlipDirect && !FlipCoords) bDrawLineWeight (X2, Y2, X1, Y1, FALSE);
    148   if (!FlipDirect &&  FlipCoords) bDrawLineWeight (Y1, X1, Y2, X2, TRUE);
    149   if ( FlipDirect &&  FlipCoords) bDrawLineWeight (Y2, X2, Y1, X1, TRUE);
     183  if (!FlipDirect && !FlipCoords) bDrawLineWeight (buffer, X1, Y1, X2, Y2, FALSE);
     184  if ( FlipDirect && !FlipCoords) bDrawLineWeight (buffer, X2, Y2, X1, Y1, FALSE);
     185  if (!FlipDirect &&  FlipCoords) bDrawLineWeight (buffer, Y1, X1, Y2, X2, TRUE);
     186  if ( FlipDirect &&  FlipCoords) bDrawLineWeight (buffer, Y2, X2, Y1, X1, TRUE);
    150187
    151188  return;
     
    153190
    154191// draw a series of lines to give the line weight
    155 void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords) {
     192void bDrawLineWeight (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords) {
    156193
    157194  int dN, dNs, dNe;
    158195
    159   dNs = -0.5*(bWeight - 1);
     196  dNs = -0.5*(buffer->bWeight - 1);
    160197  /* 0, 0, 0, -1, -1, -2, -2 */
    161198
    162   dNe = +0.5*bWeight + 1;
     199  dNe = +0.5*buffer->bWeight + 1;
    163200  /* 1, 1, 2, 2, 2, 3, 3 */
    164201
    165202  for (dN = dNs; dN < dNe; dN++) {
    166     bDrawLineBresen (X1, Y1 + dN, X2, Y2 + dN, swapcoords);
     203    bDrawLineBresen (buffer, X1, Y1 + dN, X2, Y2 + dN, swapcoords);
    167204  }
    168205  return;
     
    171208// use the Bresenham line drawing technique
    172209// integer-only Bresenham line-draw version which is fast
    173 void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords) {
     210void bDrawLineBresen (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords) {
    174211
    175212  int X, Y, dX, dY;
     
    185222  e = 0;
    186223  for (X = X1, N = 0; X <= X2; X++, N++) {
    187     if (bType == 1) { DashOn = (N % 10) < 5; }
    188     if (bType == 2) { DashOn = (N % 6) < 3; }
     224    if (buffer->bType == 1) { DashOn = (N % 10) < 5; }
     225    if (buffer->bType == 2) { DashOn = (N % 6) < 3; }
    189226    if (swapcoords) {
    190       if (DashOn) bDrawPoint (Y,X);
     227      if (DashOn) bDrawPoint (buffer, Y,X);
    191228    } else {
    192       if (DashOn) bDrawPoint (X,Y);
     229      if (DashOn) bDrawPoint (buffer, X,Y);
    193230    }
    194231    e += dY;
     
    206243}
    207244
    208 void bDrawLineHorizontal (int X1, int X2, int Y) {
     245void bDrawLineHorizontal (bDrawBuffer *buffer, int X1, int X2, int Y) {
    209246 
    210247  int i;
    211248
    212249  for (i = X1; i < X2; i++) {
    213     bBuffer[0].pixels[Y][i] = bColor;
    214   }
    215   return;
    216 }
    217 
    218 void bDrawLineVertical (int X, int Y1, int Y2) {
     250    if (buffer[0].Nbyte == 1) {
     251      buffer[0].pixels[Y][i] = buffer->bColor;
     252    } else {
     253      buffer[0].pixels[Y][3*i+0] = buffer->bColor_R;
     254      buffer[0].pixels[Y][3*i+1] = buffer->bColor_G;
     255      buffer[0].pixels[Y][3*i+2] = buffer->bColor_B;
     256    }
     257  }
     258  return;
     259}
     260
     261void bDrawLineVertical (bDrawBuffer *buffer, int X, int Y1, int Y2) {
    219262 
    220263  int i;
    221264
    222265  for (i = Y1; i < Y2; i++) {
    223     bBuffer[0].pixels[i][X] = bColor;
    224   }
    225   return;
    226 }
    227 
    228 void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3) {
    229 
    230   bDrawTriOpen (x1, y1, x2, y2, x3, y3);
    231   return;
    232 }
    233 
    234 void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
     266    if (buffer[0].Nbyte == 1) {
     267      buffer[0].pixels[i][X] = buffer->bColor;
     268    } else {
     269      buffer[0].pixels[i][3*X+0] = buffer->bColor_R;
     270      buffer[0].pixels[i][3*X+1] = buffer->bColor_G;
     271      buffer[0].pixels[i][3*X+2] = buffer->bColor_B;
     272    }
     273  }
     274  return;
     275}
     276
     277void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3) {
     278
     279  bDrawTriOpen (buffer, x1, y1, x2, y2, x3, y3);
     280  return;
     281}
     282
     283void bDrawArc (bDrawBuffer *buffer, double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
    235284
    236285  float t, dt;
     
    258307
    259308    /* we could use the value of MAX(dy/dt,dx/dt) to set dt */
    260     bDrawPoint (x,y);
     309    bDrawPoint (buffer, x,y);
    261310
    262311    dt = MAX (fabs(Xr * sin(t)), fabs(Yr * cos(t)));
     
    267316
    268317// draw a series of circles to give line weight
    269 void bDrawCircle (double xc, double yc, double radius) {
     318void bDrawCircle (bDrawBuffer *buffer, double xc, double yc, double radius) {
    270319
    271320  int dN, dNs, dNe;
    272321
    273   dNs = -0.5*(bWeight - 1);
     322  dNs = -0.5*(buffer->bWeight - 1);
    274323  /* 0, 0, 0, -1, -1, -2, -2 */
    275324
    276   dNe = +0.5*bWeight + 1;
     325  dNe = +0.5*buffer->bWeight + 1;
    277326  /* 1, 1, 2, 2, 2, 3, 3 */
    278327
    279328  for (dN = dNs; dN < dNe; dN++) {
    280     bDrawCircleSingle (xc, yc, radius + dN);
     329    bDrawCircleSingle (buffer, xc, yc, radius + dN);
    281330  }
    282331  return;
     
    284333
    285334// draw a pure circle 
    286 void bDrawCircleSingle (double xc, double yc, double radius) {
     335void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius) {
    287336
    288337  int Xc, Yc, Radius;
     
    300349
    301350  while (x <= y) {
    302     bDrawPoint (Xc+x, Yc+y);
    303     bDrawPoint (Xc+x, Yc-y);
    304     bDrawPoint (Xc-x, Yc+y);
    305     bDrawPoint (Xc-x, Yc-y);
    306     bDrawPoint (Xc+y, Yc+x);
    307     bDrawPoint (Xc+y, Yc-x);
    308     bDrawPoint (Xc-y, Yc+x);
    309     bDrawPoint (Xc-y, Yc-x);
     351    bDrawPoint (buffer, Xc+x, Yc+y);
     352    bDrawPoint (buffer, Xc+x, Yc-y);
     353    bDrawPoint (buffer, Xc-x, Yc+y);
     354    bDrawPoint (buffer, Xc-x, Yc-y);
     355    bDrawPoint (buffer, Xc+y, Yc+x);
     356    bDrawPoint (buffer, Xc+y, Yc-x);
     357    bDrawPoint (buffer, Xc-y, Yc+x);
     358    bDrawPoint (buffer, Xc-y, Yc-x);
    310359
    311360    if (d < 0) {
     
    322371
    323372// draw a pure circle 
    324 void bDrawCircleFill (double xc, double yc, double radius) {
     373void bDrawCircleFill (bDrawBuffer *buffer, double xc, double yc, double radius) {
    325374
    326375  int Xc, Yc, Radius;
     
    338387
    339388  while (x <= y) {
    340     bDrawLineHorizontal (Xc-x, Xc+x, Yc+y);
    341     bDrawLineHorizontal (Xc-x, Xc+x, Yc-y);
    342     bDrawLineHorizontal (Xc-y, Xc+y, Yc+x);
    343     bDrawLineHorizontal (Xc-y, Xc+y, Yc-x);
     389    bDrawLineHorizontal (buffer, Xc-x, Xc+x, Yc+y);
     390    bDrawLineHorizontal (buffer, Xc-x, Xc+x, Yc-y);
     391    bDrawLineHorizontal (buffer, Xc-y, Xc+y, Yc+x);
     392    bDrawLineHorizontal (buffer, Xc-y, Xc+y, Yc-x);
    344393
    345394    if (d < 0) {
  • branches/czw_branch/20101203/Ohana/src/libkapa/src/bDrawRotFont.c

    r12332 r30118  
    66# define NEARINT(x) ((x < 0) ? ((int)(x - 0.5)) : ((int)(x + 0.5)))
    77 
    8 static bDrawColor black;
    9 static bDrawColor white;
    10 
    11 int bDrawRotText (int x, int y, char *string, int pos, double angle) {
     8// XXX need to pass the rot text color here
     9// static bDrawColor black;
     10// static bDrawColor white;
     11
     12int bDrawRotText (bDrawBuffer *buffer, int x, int y, char *string, int pos, double angle) {
    1213
    1314  unsigned char *bitmap;
     
    1920  RotFont *currentfont;
    2021
    21   white = KapaColorByName ("white");
    22   black = KapaColorByName ("black");
     22  // white = KapaColorByName ("white");
     23  // black = KapaColorByName ("black");
    2324
    2425  currentname = GetRotFont (&currentsize);
     
    111112    X = x + (int)(Xoff*cs - Yoff*sn) + (int)(currentscale*currentfont[N].ascent*sn);
    112113    Y = y + (int)(Xoff*sn + Yoff*cs) - (int)(currentscale*currentfont[N].ascent*cs);
    113     bDrawRotBitmap (X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
     114    bDrawRotBitmap (buffer, X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
    114115    Xoff += 1 + (int)(currentscale*dx + 0.5);
    115116  }
     
    118119}
    119120
    120 int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
     121int bDrawRotBitmap (bDrawBuffer *buffer, int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
    121122
    122123  int ii, jj, byte_line, byte, bit, flag;
    123   bDrawColor color;
    124124  double i, j, cs, sn, rscale, tmp;
    125125  int X, Y, X0, X1, X2, Y0, Y1, Y2, x0, y0;
    126126
    127127  /* this mode option is nort actually used... */
    128   if (mode) {
    129     color = black;
    130   } else {
    131     color = white;
    132   }
     128  // if (mode) {
     129  //   color = black;
     130  // } else {
     131  //   color = white;
     132  // }
    133133   
    134134  byte_line = (int) ((dx + 7) / 8);
     
    148148  Y = YPROC (dx,0);
    149149# ifdef DRAWBOXES
    150   bDrawLine (x+X, y+Y, x+X1, y+Y1);
     150  bDrawLine (buffer, x+X, y+Y, x+X1, y+Y1);
    151151  Xt = X;
    152152  Yt = Y;
     
    160160  Y = YPROC (dx,dy);
    161161# ifdef DRAWBOXES
    162   bDrawLine (x+X, y+Y, x+Xt, y+Yt);
     162  bDrawLine (buffer, x+X, y+Y, x+Xt, y+Yt);
    163163  Xt = X;
    164164  Yt = Y;
     
    172172  Y = YPROC (0,dy);
    173173# ifdef DRAWBOXES
    174   bDrawLine (x+X, y+Y, x+Xt, y+Yt);
     174  bDrawLine (buffer, x+X, y+Y, x+Xt, y+Yt);
    175175  Xt = X;
    176176  Yt = Y;
     
    181181  X2 = MAX (X, X2);
    182182
    183   bDrawSetStyle (color, 0, 0);
     183  // bDrawSetStyle (color, 0, 0);
    184184  if (scale > 1) {
    185185    for (i = X1; i <= X2; i+=1) {
     
    191191        bit = ii % 8;
    192192        flag = 0x01 & (bitmap[byte] >> bit);
    193         if (flag) bDrawPointf (x + i, y + j);
     193        if (flag) bDrawPointf (buffer, x + i, y + j);
    194194      }
    195195    }
     
    203203        bit = ii % 8;
    204204        flag = 0x01 & (bitmap[byte] >> bit);
    205         if (flag) bDrawPointf (x + i, y + j);
     205        if (flag) bDrawPointf (buffer, x + i, y + j);
    206206      }
    207207    }
    208208  }
    209   bDrawSetStyle (black, 0, 0);
     209  // bDrawSetStyle (black, 0, 0);
    210210  return (TRUE);
    211211}
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.astro/region.c

    r27435 r30118  
    5555  if ((argc != 4) && (argc != 5)) {
    5656    gprint (GP_ERR, "USAGE: region Ra Dec Radius [projection] [orientation]\n");
     57    gprint (GP_ERR, "  [-image] [-ew] [+ew] [-ns] [+ns] [-no-clear]\n");
    5758    gprint (GP_ERR, " current: %f %f (%f x %f) (%s)\n",
    5859             graphmode.coords.crval1, graphmode.coords.crval2,
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/Makefile

    r29540 r30118  
    3636$(SRC)/cut.$(ARCH).o            \
    3737$(SRC)/delete.$(ARCH).o \
     38$(SRC)/densify.$(ARCH).o        \
    3839$(SRC)/device.$(ARCH).o \
    3940$(SRC)/dimendown.$(ARCH).o      \
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/init.c

    r29540 r30118  
    2525int dbselect         PROTO((int, char **));
    2626int delete           PROTO((int, char **));
     27int densify          PROTO((int, char **));
    2728int device           PROTO((int, char **));
    2829int dimendown        PROTO((int, char **));
     
    161162  {1, "dbselect",     dbselect,         "extract vectors from mysql database table"},
    162163  {1, "delete",       delete,           "delete vectors or images"},
     164  {1, "densify",      densify,          "create an image histogram from a set of vectors"},
    163165  {1, "device",       device,           "set / get current graphics device"},
    164166  {1, "dimendown",    dimendown,        "convert image to vector"},
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/rd.c

    r28241 r30118  
    184184    ftable.header[0].buffer = NULL;
    185185    gfits_copy_header (&buf[0].header, ftable.header);
    186     status = gfits_fread_ftable_data (f, &ftable);  // this just reads the bytes (not even a SWAP)
     186    status = gfits_fread_ftable_data (f, &ftable, FALSE);  // this just reads the bytes (not even a SWAP)
    187187    status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable);
    188188    // uncompressing the image leaves the format as an extension
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/read_vectors.c

    r29540 r30118  
    160160
    161161  off_t Nbytes;
    162   int i, j, k, N, Nextend, Ny, Binary, vecType;
     162  int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort;
    163163  char type[16], ID[80], *CCDKeyword;
    164164  FTable table;
     
    174174    CCDKeyword = strcreate (argv[N]);
    175175    remove_argument (N, &argc, argv);
     176  }
     177
     178  padIfShort = FALSE;
     179  if ((N = get_argument (argc, argv, "-pad-if-short"))) {
     180    remove_argument (N, &argc, argv);
     181    padIfShort = TRUE;
    176182  }
    177183
     
    205211    }
    206212    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension");
    207     if (!gfits_fread_ftable_data (f, &table)) ESCAPE ("error reading table for extension");
     213    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
    208214
    209215  } else {
     
    236242        continue;
    237243      }
    238       if (!gfits_fread_ftable_data (f, &table)) ESCAPE ("error reading table for extension");
     244      if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
    239245      break;
    240246    }
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/resize.c

    r13479 r30118  
    1717  if (!GetImage (NULL, &kapa, name)) return (FALSE);
    1818  FREE (name);
     19
     20  if ((N = get_argument (argc, argv, "-by-image"))) {
     21    remove_argument (N, &argc, argv);
     22    KiiResizeByImage (kapa);
     23    return (TRUE);
     24  }
    1925
    2026  if (argc != 3) {
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/section.c

    r27790 r30118  
    11# include "data.h"
    22
    3 enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG};
     3enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE};
    44
    55int section (int argc, char **argv) {
     
    4949    remove_argument (N, &argc, argv);
    5050    action = BG;
     51  }
     52
     53  if ((N = get_argument (argc, argv, "-image"))) {
     54    remove_argument (N, &argc, argv);
     55    action = IMAGE;
    5156  }
    5257
     
    130135  }
    131136 
     137  if (argc == 4) {
     138    /* set section */
     139    section.name = argv[1];
     140    section.x = atof (argv[2]);
     141    section.y = atof (argv[3]);
     142    section.bg = background;
     143    KapaSetSectionByImage (kapa, &section);
     144    return (TRUE);
     145  }
     146
    132147  if (argc == 6) {
    133148    /* set section */
     
    142157  }
    143158  gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
     159  gprint (GP_ERR, "USAGE: section name [-image x y] : width based on current image\n");
    144160  gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom]\n");
    145161  return (FALSE);
  • branches/czw_branch/20101203/Ohana/src/opihi/cmd.data/vgauss.c

    r29001 r30118  
    4545  CastVector (yvec, OPIHI_FLT);
    4646  CastVector (svec, OPIHI_FLT);
     47  // XXX Cast is failing.
     48   
    4749
    4850  Npts = xvec[0].Nelements;
  • branches/czw_branch/20101203/Ohana/src/opihi/dvo/images.c

    r28958 r30118  
    1111int images (int argc, char **argv) {
    1212
    13   off_t i, Nimage;
     13  off_t i, Nimage, Nmosaic;
    1414  int j, status, InPic, leftside, *plist, TimeSelect, ByName;
    1515  int WITH_MOSAIC, SOLO_MOSAIC, HIDDEN;
    1616  time_t tzero, tend;
    17   int N, NPTS, n, npts, Npts, kapa;
     17  int N, NPTS, n, npts, Npts, kapa, *foundMosaic;
    1818  Vector Xvec, Yvec;
    1919  double r[8], d[8], x[8], y[8], Rmin, Rmax, Rmid, trange, Radius;
     
    3535
    3636  SOLO_MOSAIC = FALSE;
     37  foundMosaic = NULL;
    3738  if ((N = get_argument (argc, argv, "-mosaic"))) {
    3839    remove_argument (N, &argc, argv);
     
    132133  BuildChipMatch (image, Nimage);
    133134
     135  if (SOLO_MOSAIC && photcode) {
     136    ALLOCATE(foundMosaic, int, Nimage);
     137    memset(foundMosaic, 0, Nimage*sizeof(int));
     138  }
     139
    134140  Rmin = graphmode.coords.crval1 - 180.0;
    135141  Rmax = graphmode.coords.crval1 + 180.0;
     
    137143 
    138144  int DistortImage = wordhash ("-DIS");
     145  int ChipImage    = wordhash ("-WRP");
    139146  int TriangleUp   = wordhash ("TRP-");
    140147  int TriangleDn   = wordhash ("TRM-");
     
    150157    if (ByName && strncmp (image[i].name, name, strlen(name))) continue;
    151158    if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
    152     if (!FindMosaicForImage (image, Nimage, i)) continue;
     159    if (!(Nmosaic = FindMosaicForImage (image, Nimage, i))) continue;
     160    Nmosaic --; // XXX kind of a hack: FindMosaicForImage returns 0 or the mosaic seq number + 1
    153161    if (photcode) {
    154162      if ( photcodeEquiv && (photcode[0].code != GetPhotcodeEquivCodebyCode(image[i].photcode))) continue;
     
    161169
    162170    typehash = wordhash (&image[i].coords.ctype[4]);
     171
     172    if (photcode && SOLO_MOSAIC) {
     173      // mosaic (DIS) images are not currently given a photcode : plot these via the WRP entries
     174      /* DIS images represent a field, not a chip */
     175      if (typehash != ChipImage) continue;
     176      if (foundMosaic[Nmosaic]) continue;
     177      x[0] = -0.5*image[Nmosaic].NX; y[0] = -0.5*image[Nmosaic].NY;
     178      x[1] = +0.5*image[Nmosaic].NX; y[1] = -0.5*image[Nmosaic].NY;
     179      x[2] = +0.5*image[Nmosaic].NX; y[2] = +0.5*image[Nmosaic].NY;
     180      x[3] = -0.5*image[Nmosaic].NX; y[3] = +0.5*image[Nmosaic].NY;
     181      for (j = 0; j < Npts; j++) {
     182        status = XY_to_RD (&r[j], &d[j], x[j], y[j], &image[Nmosaic].coords);
     183        if (!status) break;
     184        r[j] = ohana_normalize_angle (r[j]);
     185        while (r[j] < Rmin) { r[j] += 360.0; }
     186        while (r[j] > Rmax) { r[j] -= 360.0; }
     187        if (j == 0) {
     188          leftside = (r[j] < Rmid);
     189        }
     190        if (j > 0) {
     191          if ( leftside && (r[j] > Rmid + 90)) { r[j] -= 360.0; }
     192          if (!leftside && (r[j] < Rmid - 90)) { r[j] += 360.0; }
     193        }
     194      }
     195      foundMosaic[Nmosaic] = TRUE;
     196      goto plot_points;
     197    }
    163198
    164199    /* DIS images represent a field, not a chip */
     
    270305    if (Npts == 0) continue;
    271306
     307  plot_points:
     308
    272309    status = FALSE;
    273310    for (j = 0; j < Npts; j++) {
     
    320357  free (Yvec.elements.Flt);
    321358  FreeImages (image);
     359  FREE (foundMosaic);
    322360  return (TRUE);
    323361
  • branches/czw_branch/20101203/Ohana/src/opihi/dvo/imlist.c

    r29540 r30118  
    104104      XY_to_RD (&r, &d, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    105105    }
    106     gprint (GP_LOG, "%3lld %s %8.4f %8.4f %f %5d %2d %4.2f %5.3f %5.3f\n",
    107             (long long) i, image[i].name, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal);
     106    gprint (GP_LOG, "%3lld %s %8lld %8.4f %8.4f %f %5d %2d %4.2f %5.3f %5.3f\n",
     107            (long long) i, image[i].name, (long long) image[i].imageID, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal);
    108108  }
    109109
  • branches/czw_branch/20101203/Ohana/src/opihi/lib.data/starfuncs.c

    r20936 r30118  
    55  double *ring;
    66  double x, y, x2, y2, xy, I, sky, FWHMx, FWHMy, value, mag, Sxy;
    7   int i, j, n, Npix2, Nring, Nmax;
     7  int i, j, n, Radius, Nring, Nmax;
    88  double Npts, gain, dsky2, dmag, peak, offset;
    99  char *string;
     
    1919  Nborder = MIN (1000, Nborder);
    2020 
    21   Npix2 = (int)(0.5*Npix);
    22   Npix = 2 * Npix2 + 1;
     21  Radius = (int)(0.5*Npix);
     22  Npix = 2 * Radius + 1;
    2323  Nring = 4*Nborder*(Nborder + Npix);
    2424  ALLOCATE (ring, double, Nring);
     
    2727  n = 0; 
    2828  for (j = 0; j < Nborder; j++) {
    29     for (i = X - Npix2 - Nborder; i < X + Npix2 + Nborder + 1; i++, n+=2) {
    30       ring[n]   = gfits_get_matrix_value (matrix, i, (int)(Y - Npix2 - j));
    31       ring[n+1] = gfits_get_matrix_value (matrix, i, (int)(Y + Npix2 + j));
    32     }
    33     for (i = Y - Npix2; i < Y + Npix2 + 1; i++, n+=2) {
    34       ring[n]   = gfits_get_matrix_value (matrix, (int)(X - Npix2 - j), i);
    35       ring[n+1] = gfits_get_matrix_value (matrix, (int)(X + Npix2 + j), i);
     29    for (i = X - Radius - Nborder; i < X + Radius + Nborder + 1; i++, n+=2) {
     30      ring[n]   = gfits_get_matrix_value (matrix, i, (int)(Y - Radius - j));
     31      ring[n+1] = gfits_get_matrix_value (matrix, i, (int)(Y + Radius + j));
     32    }
     33    for (i = Y - Radius; i < Y + Radius + 1; i++, n+=2) {
     34      ring[n]   = gfits_get_matrix_value (matrix, (int)(X - Radius - j), i);
     35      ring[n+1] = gfits_get_matrix_value (matrix, (int)(X + Radius + j), i);
    3636    }
    3737  }
     
    5050  Npts = Nmax = 0;
    5151  x = y = x2 = y2 = xy = I = 0;
    52   for (i = X - Npix2; i < X + Npix2 + 1; i++) {
    53     for (j = Y - Npix2; j < Y + Npix2 + 1; j++) {
     52  for (i = X - Radius; i < X + Radius + 1; i++) {
     53    for (j = Y - Radius; j < Y + Radius + 1; j++) {
     54      if (hypot((i-X), (j-Y)) > Radius) continue;
    5455      value = gfits_get_matrix_value (matrix, i, j);
    5556      offset = value - sky;
     
    9293  set_variable ("Zpk", peak);
    9394  set_int_variable ("Nsat", Nmax);
     95  set_int_variable ("Npts", Npts);
    9496 
    9597  gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
  • branches/czw_branch/20101203/Ohana/src/photdbc/include/photdbc.h

    r28331 r30118  
    114114int SetSignals (void);
    115115int copy_images (char *outdir);
     116void usage();
  • branches/czw_branch/20101203/Ohana/src/photdbc/src/args.c

    r8630 r30118  
    6161  }
    6262
    63   if (argc != 2) {
    64     fprintf (stderr, "USAGE: photdbc (output)\n");
    65     exit (2);
    66   }
     63  if (argc != 2) usage();
    6764
    6865  if ((REGION.Rmin == 0) && (REGION.Rmax == 360) && (REGION.Dmin == -90) && (REGION.Dmax == +90)) {
     
    8077}
    8178
    82 /**
     79void usage() {
    8380
    84  this program takes an existing DVO database and makes a copy, applying a number of optional
    85  filters in the process. 
    86 
    87  photdbc (output)
    88 
    89  allowed filters / restrictions include:
    90 
    91  -region ra dec ra dec : limit operation to the specified region
    92  -join                 : join measurements between stars using JOIN_RADIUS
    93  -ccdregion X Y X Y    : only keep detections within the specified detector region
    94                          (can this be limited to specific photcodes? cameras? detectors?)
    95  -photcode_limits code Mmin Mmax : allow multiples of these
    96 
    97  SIGMA_MAX
    98  NMEAS_MIN
    99  INST_MAG_MAX
    100  INST_MAG_MIN
    101 
    102 **/
     81  fprintf (stderr, "USAGE: photdbc (output)\n\n");
     82  fprintf (stderr, " this program takes an existing DVO database and makes a copy, applying a number of optional\n");
     83  fprintf (stderr, " filters in the process.  \n");
     84  fprintf (stderr, "\n");
     85  fprintf (stderr, " photdbc (output)\n");
     86  fprintf (stderr, "\n");
     87  fprintf (stderr, " allowed filters / restrictions include:\n");
     88  fprintf (stderr, "\n");
     89  fprintf (stderr, " -region Rmin Rmax Dmin Dmax : limit operation to the specified region \n");
     90  fprintf (stderr, " -join                 : join measurements between stars using JOIN_RADIUS\n");
     91  fprintf (stderr, " -ccdregion X Y X Y    : only keep detections within the specified detector region\n");
     92  fprintf (stderr, "                         (can this be limited to specific photcodes? cameras? detectors?)\n");
     93  fprintf (stderr, " -photcode_limits code Mmin Mmax : allow multiples of these\n");
     94  fprintf (stderr, "\n");
     95  fprintf (stderr, " SIGMA_MAX\n");
     96  fprintf (stderr, " NMEAS_MIN\n");
     97  fprintf (stderr, " INST_MAG_MAX\n");
     98  fprintf (stderr, " INST_MAG_MIN\n");
     99  exit (2);
     100}
  • branches/czw_branch/20101203/Ohana/src/photdbc/src/initialize.c

    r4808 r30118  
    44
    55  /* are these set correctly? */
     6  if (get_argument (argc, argv, "-h")) usage();
     7  if (get_argument (argc, argv, "--h")) usage();
     8  if (get_argument (argc, argv, "-help")) usage();
     9  if (get_argument (argc, argv, "--help")) usage();
     10
    611  ConfigInit (&argc, argv);
    712  args (argc, argv);
  • branches/czw_branch/20101203/Ohana/src/photdbc/src/join_stars.c

    r28306 r30118  
    3232
    3333  /* reference for coords is this region */
     34  Ncurr = 0;
    3435  Naves = 0;
    3536  Rmid = Dmid = 0;
  • branches/czw_branch/20101203/Ohana/src/relastro/src/GetAstromError.c

    r27581 r30118  
    22
    33float GetAstromError (Measure *measure, int mode) {
    4 
     4  //BIG HACKXXXXXXXX
     5  return 0.1;
    56  PhotCode *code;
    67  float dPobs, dPsys, dPtotal, dM, AS, MS;
    7 
    88  switch (mode) {
    99    case ERROR_MODE_RA:
     
    1919      abort();
    2020  }
    21 
    2221  /* the astrometric errors are not being carried yet (but should be!) */
    2322  /* we use the photometric mag error as a weighting term */
     
    2827  dPsys = code[0].astromErrSys;
    2928  dM    = measure[0].dM;
    30  
    3129  dPtotal = sqrt(SQ(dPsys) + AS*SQ(dPobs) + MS*SQ(dM));
    3230
     
    3533
    3634  dPtotal = MAX (dPtotal, MIN_ERROR);
    37 
    3835  return (dPtotal);
    3936}
  • branches/czw_branch/20101203/Ohana/src/relastro/src/UpdateObjects.c

    r28241 r30118  
    5454  memset (&fitPM,  0, sizeof(fitPM));
    5555  memset (&fitPAR, 0, sizeof(fitPAR));
    56  
    5756  initObjectData (catalog, Ncatalog);
    5857
     
    7271  // use J2000 as a reference time
    7372  T2000 = ohana_date_to_sec ("2000/01/01");
    74 
    7573  // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
    7674  Nsecfilt = GetPhotcodeNsecfilt ();
     
    9795      N = 0;
    9896      m = catalog[i].average[j].measureOffset;
    99 
    10097      Tmin = Tmax = (catalog[i].measure[m].t - T2000) / (86400*365.25);
    10198      mode = FIT_MODE;
     
    137134
    138135        // dX, dY : error in arcsec --
    139         dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
    140         dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
     136        // dX[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_RA);
     137        // dY[N] = GetAstromError (&catalog[i].measure[m], ERROR_MODE_DEC);
     138
     139        dX[N] = 0.1;
     140        dY[N] = 0.1;
    141141        dT[N] = catalog[i].measure[m].dt;
    142142
     
    145145        // non-circular errors (different values for X and Y), then dR and dD will be
    146146        // incorrect: they would need to be rotated to take out the position angle
    147         dR[k] = dX[k] / 3600.0;
    148         dD[k] = dY[k] / 3600.0;
     147        dR[N] = dX[N] / 3600.0;
     148        dD[N] = dY[N] / 3600.0;
    149149
    150150        N++;
     
    194194
    195195        FitPM (&fitPM, X, dX, Y, dY, T, N);
     196
    196197        if (XVERB) fprintf (stderr, "fitted:  %f - %f : %f %f : %f %f : %f vs %f\n", Tmin, Tmax, fitPM.Ro, fitPM.Do, fitPM.uR, fitPM.uD, fitPM.chisq, fitAve.chisq);
    197198
     
    244245
    245246      switch (result) {
    246         case FIT_AVERAGE:
    247           catalog[i].average[j].flags |= ID_STAR_USE_AVE;
    248           fit = fitAve;
    249           break;
    250         case FIT_PM_ONLY:
    251           catalog[i].average[j].flags |= ID_STAR_USE_PM;
    252           fit = fitPM;
    253           break;
    254         case FIT_PM_AND_PAR:
    255           catalog[i].average[j].flags |= ID_STAR_USE_PAR;
    256           fit = fitPAR;
    257           break;
    258       }
    259 
    260       if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f)\n",
     247      case FIT_AVERAGE:
     248        catalog[i].average[j].flags |= ID_STAR_USE_AVE;
     249        fit = fitAve;
     250        break;
     251      case FIT_PM_ONLY:
     252        catalog[i].average[j].flags |= ID_STAR_USE_PM;
     253        fit = fitPM;
     254        break;
     255      case FIT_PM_AND_PAR:
     256        catalog[i].average[j].flags |= ID_STAR_USE_PAR;
     257        fit = fitPAR;
     258        break;
     259      }
     260      if (XVERB) fprintf (stderr, "A%f %f -> %f %f (%f,%f) pm=(%f %f)\n",
    261261                          catalog[i].average[j].R,
    262262                          catalog[i].average[j].D,
    263263                          fit.Ro, fit.Do,
    264264                          3600*(catalog[i].average[j].R - fit.Ro),
    265                           3600*(catalog[i].average[j].D - fit.Do));
     265                          3600*(catalog[i].average[j].D - fit.Do),
     266                          fit.uR,
     267                          fit.uD);
    266268
    267269      //make sure that the fit succeeded
    268       status  = finite(fit.Ro);
     270      status = TRUE;
     271      status &= finite(fit.Ro);
    269272      status &= finite(fit.Do);
    270273      status &= finite(fit.dRo);
     
    310313      catalog[i].average[j].Trange = (Trange * 86400 * 365.26);
    311314      catalog[i].average[j].Npos = fit.Nfit;
     315      if (XVERB) fprintf (stderr, "%f %f -> %f %f (%f,%f) pm=(%f %f)\n",
     316                          catalog[i].average[j].R,
     317                          catalog[i].average[j].D,
     318                          fit.Ro, fit.Do,
     319                          3600*(catalog[i].average[j].R - fit.Ro),
     320                          3600*(catalog[i].average[j].D - fit.Do),
     321                          catalog[i].average[j].uR,
     322                          catalog[i].average[j].uD);
     323
    312324    }
    313325
  • branches/czw_branch/20101203/Ohana/src/relastro/src/high_speed_objects.c

    r28811 r30118  
    1313  // XXX seems silly to require region here just to find the catalog bounds / center
    1414
    15   off_t i, j, m, J, ni, nj, *N1, Nslow, Ninvalid, NgroupA, NgroupB, NgroupAbad, NgroupBbad;
    16   int *slowMoving, *groupA, *groupB, status, foundA, foundB, Nmatch, valid;
     15  off_t i, j, m, J, ni, nj, *N1, Nslow, Ninvalid, NgroupA, NgroupB, NgroupAbad, NgroupBbad,l,i1,Noff,Nmeasure,Naverage, NAVERAGE, NMEASURE;
     16  int *slowMoving, *groupA, *groupB, status, foundA, foundB, Nmatch, valid,Nmatchmeas,Nepoch,nv[2],Nmatchmeasobj;
    1717  double *X1, *Y1;
    18   double dX, dY, dR, RADIUS2, yJ;
     18  double dX, dY, dR, RADIUS2;
    1919  Coords tcoords;
     20  Catalog catalog1;
    2021
    2122  int zcode, zNsec, ycode, yNsec, jcode, jNsec, hcode, hNsec, kcode, kNsec, USNO_R, USNO_N, Nsecfilt;
     23  char filename[1024];
     24  char outdir[]="/data/ipp022.0/ndeacon/hispeedzy";
     25  Noff = strlen(CATDIR);
     26  sprintf (filename, "%s/%s", outdir, &catalog[0].filename[Noff]);
     27  dvo_catalog_init(&catalog1, TRUE); /*initialise new catalogue*/
     28  catalog1.filename = strcreate(filename);
     29
     30  SIGMA_LIM = 0.0;
    2231
    2332  Nsecfilt = GetPhotcodeNsecfilt();
     33  Naverage=catalog[0].Naverage;
     34  Nmeasure=catalog[0].Nmeasure;
     35  // ALLOCATE (catalog1.average, Average,Naverage);
     36  // ALLOCATE (catalog1.measure, Measure,Nmeasure);
     37  // ALLOCATE(catalog1.secfilt, SecFilt,catalog[0].Naverage*Nsecfilt);
     38  catalog1.filename = filename; // based on the input name, need to keep everything below the catdir portion
     39  catalog1.Nsecfilt  = Nsecfilt;
     40  // always load all of the data (if any exists)
     41  catalog1.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     42 
     43  catalog1.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     44  catalog1.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     45
     46  if (!dvo_catalog_open (&catalog1, region, VERBOSE,"w")) {
     47    fprintf (stderr, "ERROR: failure to open catalog file %s\n",
     48             filename);
     49    exit (2);
     50  }
     51
     52  NAVERAGE = 1000;
     53  NMEASURE = 10000;
     54  REALLOCATE (catalog1.average, Average, NAVERAGE);
     55  REALLOCATE (catalog1.measure, Measure, NMEASURE);
     56  REALLOCATE(catalog1.secfilt, SecFilt, NAVERAGE*Nsecfilt);
    2457
    2558  ycode = GetPhotcodeCodebyName("y");
     
    67100  NgroupBbad = 0;
    68101
    69   fprintf (stdout, "#      RA_A  DEC_A              RA_B  DEC_B      :     pmx     pmy      dR  :    z      dz       y      dy       J      dJ       H      dH       K      dK\n");
     102  fprintf (stdout, "#      RA_A  DEC_A              RA_B  DEC_B      :     pmx     pmy      dR  dt:    z      dz       y      dy       J      dJ       H      dH       K      dK\n");
    70103  //................270.2346670  20.2471540  270.2170434  20.2717396 :  -59.11   88.78   106.66 :   0.000  0.000   19.582  0.112   16.041  0.110   15.388  0.098   14.858  0.001
    71104
     
    88121    foundA = FALSE;
    89122    for (j = 0; !foundA && (j < catalog[0].average[i].Nmeasure); j++, m++) {
     123      if((catalog[0].average[i].R>204.1923)&&(catalog[0].average[i].R<204.1924)&&(catalog[0].average[i].D>11.376)&&(catalog[0].average[i].D<11.377))
     124        {
     125          printf("Hello");
     126        }
     127
    90128      if (MeasMatchesPhotcode(&catalog[0].measure[m], photcodesGroupA, NphotcodesGroupA)) {
    91129        foundA = TRUE;
     
    97135    foundB = FALSE;
    98136    for (j = 0; !foundB && (j < catalog[0].average[i].Nmeasure); j++, m++) {
     137                                                   
     138      if((catalog[0].average[i].R>204.192)&&(catalog[0].average[i].R<204.1925)&&(catalog[0].average[i].D>11.376)&&(catalog[0].average[i].D<11.377))
     139        {
     140          printf("Hello");
     141        }
     142
    99143      if (MeasMatchesPhotcode(&catalog[0].measure[m], photcodesGroupB, NphotcodesGroupB)) {
    100144        foundB = TRUE;
     
    114158    if (foundA && !foundB) {
    115159      // average-based tests:
     160                                                   
     161      if((catalog[0].average[i].R>204.1923)&&(catalog[0].average[i].R<204.1924)&&(catalog[0].average[i].D>11.376)&&(catalog[0].average[i].D<11.377))
     162        {
     163          printf("Hello");
     164        }
     165
    116166      valid = TRUE;
    117       valid &= ((catalog[0].average[i].flags & 0x40000) == 0);
    118       valid &= ((catalog[0].average[i].flags & 0x80000)  > 0);
    119       valid &= (catalog[0].secfilt[i*Nsecfilt + yNsec].M < 1.0);
    120       valid &= (catalog[0].secfilt[i*Nsecfilt + zNsec].M < 1.0);
     167      valid &= ((catalog[0].average[i].flags & 0x02000000) == 0);
     168      valid &= ((catalog[0].average[i].flags & 0x08000000)  > 0);
     169      valid &= ((catalog[0].secfilt[i*Nsecfilt + yNsec].M < 1.0)||(isnan(catalog[0].secfilt[i*Nsecfilt + yNsec].M)));
     170      valid &= (((catalog[0].secfilt[i*Nsecfilt + zNsec].M < 1.0))||(isnan(catalog[0].secfilt[i*Nsecfilt + zNsec].M)));
    121171      // XXX color restrictions are applied in the pair-wise matching below
    122172     
    123173      // measure-based tests:
    124       m = catalog[0].average[i].measureOffset;
     174      /*      m = catalog[0].average[i].measureOffset;
    125175      for (j = 0; valid && (j < catalog[0].average[i].Nmeasure); j++, m++) {
    126176        if (catalog[0].measure[m].photcode == USNO_R) {
     
    130180          valid &= ((catalog[0].measure[m].M > 18.0) || isnan(catalog[0].measure[m].M));
    131181        }
    132       }
     182        }*/
    133183
    134184      // ((objflags & 524288) == 524288) &&
     
    154204
    155205      // average-based tests:
     206      if((catalog[0].average[i].R>204.192)&&(catalog[0].average[i].R<204.193)&&(catalog[0].average[i].D>11.372)&&(catalog[0].average[i].D<11.373))
     207        {
     208          printf("Hello");
     209        }
    156210      valid = TRUE;
    157       valid &= ((catalog[0].average[i].flags & 0x10000) == 0);
    158       valid &= ((catalog[0].average[i].flags & 0x20000)  > 0);
    159       valid &= (catalog[0].secfilt[i*Nsecfilt + jNsec].M < 1.0);
     211      valid &= ((catalog[0].average[i].flags & 0x01000000) == 0);
     212
     213      valid &= ((catalog[0].average[i].flags & 0x04000000)  > 0);
     214
     215      valid &= ((catalog[0].secfilt[i*Nsecfilt + jNsec].M < 1.0)||(isnan(catalog[0].secfilt[i*Nsecfilt + jNsec].M)));
    160216      valid &= (catalog[0].secfilt[i*Nsecfilt + yNsec].Nused > 1);
    161217      valid &= (catalog[0].secfilt[i*Nsecfilt + yNsec].dM < 0.2);
    162218
    163       if ((catalog[0].secfilt[i*Nsecfilt + zNsec].M < 1.0) || (catalog[0].secfilt[i*Nsecfilt + zNsec].Nused == 1)) {
     219      /*if ((catalog[0].secfilt[i*Nsecfilt + zNsec].M < 1.0) || (catalog[0].secfilt[i*Nsecfilt + zNsec].Nused == 1)) {
    164220        valid &= TRUE;
    165221      } else {
    166222        valid &= ((catalog[0].secfilt[i*Nsecfilt + zNsec].M - catalog[0].secfilt[i*Nsecfilt + yNsec].M) > 0.2);
    167       }
     223        }*/
    168224
    169225      // measure-based tests:
    170       m = catalog[0].average[i].measureOffset;
     226      /*m = catalog[0].average[i].measureOffset;
    171227      for (j = 0; valid && (j < catalog[0].average[i].Nmeasure); j++, m++) {
    172228        if (catalog[0].measure[m].photcode == USNO_R) {
     
    176232          valid &= ((catalog[0].measure[m].M > 18.5) || isnan(catalog[0].measure[m].M));
    177233        }
    178       }
     234        }*/
    179235
    180236      // (abs(glat)>15.0) &&
     
    236292
    237293  Nmatch = 0;
     294  Nmatchmeas = 0;
    238295  RADIUS2 = SQ(RADIUS);
    239296
     
    243300    ni = N1[i];
    244301    nj = N1[j];
    245 
    246302    // if (ni == 131030) {
    247303    //   fprintf (stderr, "got 2mass\n");
     
    268324
    269325    // within match range; look for valid matches
    270     for (J = j; (dX > -1.02*RADIUS) && (J < catalog[0].Naverage); J++) {
     326    for (J = j; (dX > -1.02*RADIUS) && (J < catalog[0].Naverage); J++) {     
    271327      if (J == i) continue;  // avoid auto-matches
    272328
     
    281337
    282338      // y_groupA - J_groupB
    283       yJ = catalog[0].secfilt[nj*Nsecfilt + yNsec].M - catalog[0].secfilt[ni*Nsecfilt + jNsec].M;
     339
     340      /*      yJ = catalog[0].secfilt[nj*Nsecfilt + yNsec].M - catalog[0].secfilt[ni*Nsecfilt + jNsec].M;
    284341      if (yJ < 1.25) continue;
    285       if (yJ > 5.0) continue;
     342      if (yJ > 5.0) continue;*/
    286343
    287344      /*** a match is found (just print it for the moment) ***/
     345      /*Define a vector of matched indices and set averages in new catalogue*/
     346      Nepoch=2;
     347      FIT_MODE = FIT_PM_ONLY;
     348/*nv=(int *)malloc(Nepoch*sizeof(int));*/
     349      nv[0]=ni; /*THESE SHOULD BE CHANGED FOR MULTIPLE EPOCHS AS SHOULD nv*/
     350      nv[1]=nj;
     351
     352      catalog1.average[Nmatch]=catalog[0].average[nv[0]];
     353      /*Loop over index values and set measurements in new catalogue*/
     354      Nmatchmeasobj=0;
     355      catalog1.average[Nmatch].measureOffset=Nmatchmeas;
     356      for(l=0;l<Nepoch;l++) {
     357          m = catalog[0].average[nv[l]].measureOffset;
     358          for(i1=0;i1<catalog[0].average[nv[l]].Nmeasure;i1++) {
     359              catalog1.measure[Nmatchmeas]=catalog[0].measure[m+i1];
     360              /*Set offset RA and Dec wrt correct average value*/
     361              catalog1.measure[Nmatchmeas].dR=catalog[0].measure[m+i1].dR+3600.0*(catalog[0].average[nv[0]].R-catalog[0].average[nv[l]].R);
     362              catalog1.measure[Nmatchmeas].dD=catalog[0].measure[m+i1].dD+3600.0*(catalog[0].average[nv[0]].D-catalog[0].average[nv[l]].D);
     363              catalog1.measure[Nmatchmeas].averef = Nmatch;
     364              Nmatchmeasobj++;
     365              Nmatchmeas++;
     366
     367              if (Nmatchmeas == NMEASURE - 1) {
     368                NMEASURE += 10000;
     369                REALLOCATE (catalog1.measure, Measure, NMEASURE);
     370              }
     371          }
     372      }
     373      catalog1.average[Nmatch].Nmeasure=Nmatchmeasobj;
    288374      Nmatch ++;
    289375
     376      if (Nmatch == NAVERAGE - 1) {
     377        NAVERAGE += 1000;
     378        REALLOCATE (catalog1.average, Average, NAVERAGE);
     379        REALLOCATE(catalog1.secfilt, SecFilt, NAVERAGE*Nsecfilt);
     380      }
    290381      // for the moment, just write the matches to stdout:
    291       float pmx = -dX; // proper-motion displacement in ra  direction (B - A) [arcsec]
    292       float pmy = -dY; // proper-motion displacement in dec direction (B - A) [arcsec]
    293       fprintf (stdout, "%11.7f %11.7f  %11.7f %11.7f : %7.2f %7.2f  %7.2f : %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f\n",
     382      //float pmx = -dX; // proper-motion displacement in ra  direction (B - A) [arcsec]
     383      //float pmy = -dY; // proper-motion displacement in dec direction (B - A) [arcsec]
     384      /*           fprintf (stdout, "%11.7f %11.7f  %11.7f %11.7f : %7.2f %7.2f  %7.2f: %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f  %7.3f %6.3f\n",
    294385               catalog[0].average[ni].R, catalog[0].average[ni].D,
    295386               catalog[0].average[nj].R, catalog[0].average[nj].D,
    296                pmx, pmy, sqrt(dR),
     387               dX, dY, sqrt(dR),
    297388               catalog[0].secfilt[nj*Nsecfilt + zNsec].M,
    298389               catalog[0].secfilt[nj*Nsecfilt + zNsec].dM,
     
    304395               catalog[0].secfilt[ni*Nsecfilt + hNsec].dM,
    305396               catalog[0].secfilt[ni*Nsecfilt + kNsec].M,
    306                catalog[0].secfilt[ni*Nsecfilt + kNsec].dM);
     397               catalog[0].secfilt[ni*Nsecfilt + kNsec].dM);*/
    307398    }
    308399    i++;
    309400  }
     401  catalog1.Naverage=Nmatch;
     402  catalog1.Nmeasure=Nmatchmeas;
     403  catalog1.Nsecfilt=Nsecfilt;
     404  catalog1.Nsecf_mem=Nmatch*Nsecfilt;
     405
     406  UpdateObjects(&catalog1, 1);
     407
    310408  fprintf (stderr, "found %d matches\n", Nmatch);
    311  
     409  dvo_catalog_save (&catalog1, VERBOSE);
     410  dvo_catalog_unlock (&catalog1);
     411  dvo_catalog_free (&catalog1);
    312412  free (slowMoving);
    313413  free (groupA);
  • branches/czw_branch/20101203/Ohana/src/tools/Makefile

    r20983 r30118  
    1717PROGRAMS = gconfig fhead ftable fields list_astro glockfile \
    1818radec mktemp precess csystem fits_insert \
    19 medianfilter mefhead ckfits
     19medianfilter mefhead ckfits roc
    2020
    2121all tools: $(PROGRAMS)
  • branches/czw_branch/20101203/PS-IPP-Config/lib/PS/IPP/Config.pm

    r29891 r30118  
    11071107    }
    11081108
    1109     if (file_scheme($output) ne 'neb') {
     1109    my $scheme = file_scheme($output);
     1110    if (!$scheme or ($scheme ne 'neb')) {
    11101111        # non-nebulous file we're done
    1111         if ($delete_existing) {
     1112        if ($delete_existing and $self->file_exists($output)) {
    11121113            if (!$self->file_delete($output)) {
    11131114                carp "failed to delete $output";
     
    11811182    my $copies = shift;
    11821183
    1183     if (file_scheme($file) ne 'neb') {
     1184    my $scheme = file_scheme($file);
     1185    if (!$scheme or ($scheme ne 'neb')) {
    11841186        carp "cannot replicate non-neulous file: $file";
    11851187        return 0;
  • branches/czw_branch/20101203/dbconfig

    • Property svn:mergeinfo deleted
  • branches/czw_branch/20101203/dbconfig/changes.txt

    r29965 r30118  
    19891989UPDATE dbversion set schema_version = '1.1.66',  updated= CURRENT_TIMESTAMP();
    19901990
     1991-- output format for publishing / unique name for clients
     1992ALTER TABLE publishClient ADD name VARCHAR(64) UNIQUE; -- (Bill's request)
     1993ALTER TABLE publishClient ADD output_format SMALLINT NOT NULL default 1;
     1994
    19911995-- Version 1.1.67
    19921996
  • branches/czw_branch/20101203/dbconfig/notes.txt

    r13740 r30118  
    88   * build ippbd ('make src' in dbconfig)
    99   * check in dbconfig, ippdb, and ippTools
     10   * update dbversion.schema.version (added by bills)
    1011
    11122007.06.04 : EAM
  • branches/czw_branch/20101203/dbconfig/publish.md

    r27028 r30118  
    99    workdir      STR         255
    1010    comment      STR         255
     11    name         STR         64
     12    output_format S16        0
    1113END             
    1214                 
  • branches/czw_branch/20101203/ippMonitor/raw/czartool_labels.php

    r29792 r30118  
    6464include 'version.php';
    6565echo "</p>";
    66 echo "<p  align=\"center\"> Current status of the IPP as of $lastUpdateTime (faults are shown in parentheses). <br>Documentation can be found <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\">here</a> and cluster load monitored <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&c=IPP%2520Production\">here</a><br>Current nightly science status: $nsStatus<br>Use <a href=\"$link\"> $plotTypeLink</a> plots <br/><a href=\"http://ipp004.ifa.hawaii.edu/clusterMonitor/top.html\">Who uses the cluster?</a></p>";
     66echo "<p  align=\"center\"> Current status of the IPP as of $lastUpdateTime (faults are shown in parentheses). <br>Documentation can be found <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\">here</a> and cluster load monitored <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&c=IPP%2520Production\">here</a><br>Current nightly science status: $nsStatus<br>Use <a href=\"$link\"> $plotTypeLink</a> plots <br/><a href=\"http://ipp004.ifa.hawaii.edu/clusterMonitor/top.html\">Who uses the cluster?</a><br><a href=\"http://ipp004.ifa.hawaii.edu/ippMetrics\">IPP Metrics</a><br/><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PS1_IPP_CzarLogs\">Czar log pages</a></p>";
    6767
    6868
     
    399399        ."&plottype=".$plotType;
    400400
     401    $searchState = "new";
     402    if ($server == "update") $searchState = "update";
     403
    401404    // write rows
    402405    foreach ($labels as &$thisLabel) {
     
    437440        write_table_cell($class, '%s', $anyFaults ? $link : "", $str);
    438441
    439         $link = "failedChipProcessedImfile.php?pass=" . $pass . "&proj=" . $proj . "&chipRun.label=" . $thisLabel . "&chipRun.state=new";
     442        $link = "failedChipProcessedImfile.php?pass=" . $pass . "&proj=" . $proj . "&chipRun.label=" . $thisLabel . "&chipRun.state=".$searchState;
    440443        getStateAndFaults($db, $thisLabel, $selectedState, "chip", $str, $anyFaults);
    441444        write_table_cell($class, '%s', $anyFaults ? $link : "", $str);
    442445
    443         $link = "failedCamProcessedExp.php?pass=" . $pass . "&proj=" . $proj . "&camRun.label=" . $thisLabel . "&camRun.state=new";
     446        $link = "failedCamProcessedExp.php?pass=" . $pass . "&proj=" . $proj . "&camRun.label=" . $thisLabel . "&camRun.state=".$searchState;
    444447        getStateAndFaults($db, $thisLabel, $selectedState, "cam", $str, $anyFaults);
    445448        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
    446449
    447         $link =  "failedFakeProcessedImfile.php?pass=" . $pass . "&proj=" . $proj . "&fakeRun.label=" . $thisLabel . "&fakeRun.state=new";
     450        $link =  "failedFakeProcessedImfile.php?pass=" . $pass . "&proj=" . $proj . "&fakeRun.label=" . $thisLabel . "&fakeRun.state=".$searchState;
    448451        getStateAndFaults($db, $thisLabel, $selectedState, "fake", $str, $anyFaults);
    449452        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
    450453
    451         $link = "failedWarpSkyfiles.php?pass=" . $pass . "&proj=" . $proj . "&warpRun.label=" . $thisLabel . "&warpRun.state=new";
     454        $link = "failedWarpSkyfiles.php?pass=" . $pass . "&proj=" . $proj . "&warpRun.label=" . $thisLabel . "&warpRun.state=".$searchState;
    452455        getStateAndFaults($db, $thisLabel, $selectedState, "warp", $str, $anyFaults);
    453456        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
    454457
    455         $link = "failedStackSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&stackRun.label=" . $thisLabel . "&stackRun.state=new";
     458        $link = "failedStackSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&stackRun.label=" . $thisLabel . "&stackRun.state=".$searchState;
    456459        getStateAndFaults($db, $thisLabel, $selectedState, "stack", $str, $anyFaults);
    457460        write_table_cell($class, '%s',  $anyFaults ? $link : "", $str);
    458461
    459         $link = "failedDiffSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&diffRun.label=" . $thisLabel . "&diffRun.state=new";
     462        $link = "failedDiffSkyfile.php?pass=" . $pass . "&proj=" . $proj . "&diffRun.label=" . $thisLabel . "&diffRun.state=".$searchState;
    460463        getStateAndFaults($db, $thisLabel, $selectedState, "diff", $str, $anyFaults);
    461464        write_table_cell($class, '%s',  $anyFaults ? $link : "",  $str);
     
    605608        ."&allservercmd=stop";
    606609
    607     write_table_cell($class, '%s', $link, "Stop all");
     610    $link = ""; # TODO removed links temporarily
     611        write_table_cell($class, '%s', $link, "Stop all");
    608612    $link = "czartool_labels.php?pass=".$pass
    609613        ."&proj=".$proj
     
    613617        ."&allservercmd=run";
    614618
    615     write_table_cell($class, '%s', $link, "Run all");
     619    $link = ""; # TODO removed links temporarily
     620        write_table_cell($class, '%s', $link, "Run all");
    616621    echo "</tr>\n";
    617622
     
    628633            ."&plottype=".$plotType;
    629634
    630         write_table_cell($class, '%s', $link, $server);
     635        $link = ""; # TODO removed links temporarily
     636            write_table_cell($class, '%s', $link, $server);
    631637        write_table_cell($class, '%s', "", $alive ? "yes" : "NO");
    632638
     
    644650
    645651                $link = $link . "stop";
    646                 write_table_cell($class, '%s', $link, "stop");
     652                $link = ""; # TODO removed links temporarily
     653                    write_table_cell($class, '%s', $link, "stop");
    647654                write_table_cell($class, '%s', "", "");
    648655            }
     
    651658                $link = $link . "run";
    652659                write_table_cell($class, '%s', "", "");
    653                 write_table_cell($class, '%s', $link, "run");
     660                $link = ""; # TODO removed links temporarily
     661                    write_table_cell($class, '%s', $link, "run");
    654662            }
    655663        }
     
    759767###########################################################################
    760768function showReplicationsStatus($replHost, $replUser, $replPassword, $replDatabaseName) {
    761   #print "<br>$replHost, $replUser, $replPassword, $replDatabaseName<br/>";
    762   $dbRepl = DB::connect("mysql://$replUser:$replPassword@$replHost");
    763   if (PEAR::isError($dbRepl)) {
    764     die("MySQL DB connection error: Check the configuration for $replDatabaseName");
    765   }
    766   $res = $dbRepl->query('SHOW SLAVE STATUS');
    767   while ($res->fetchInto($row)) {
    768     # Have a look for Last_Errno in http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html
    769     $errorStatusInMySql = $row[18];
    770     $replStatus = ($errorStatusInMySql==0?"OK":"<font color=\"red\">PROBLEM</font>");
    771     echo "<tr><td>$replDatabaseName</td><td>$replStatus</td></tr>";
    772     if ($errorStatusInMySql!=0) {
    773       echo "<tr><td colspan=\"2\">Connect to $replDatabaseName replication host, execute 'SHOW SLAVE STATUS', and fix the problem.<br/>";
    774       echo "Information <a href=\"http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html\">here</a></td></tr>";
    775     }
    776   }
    777   $dbRepl->disconnect();
     769    #print "<br>$replHost, $replUser, $replPassword, $replDatabaseName<br/>";
     770    $dbRepl = DB::connect("mysql://$replUser:$replPassword@$replHost");
     771    if (PEAR::isError($dbRepl)) {
     772        die("MySQL DB connection error: Check the configuration for $replDatabaseName");
     773    }
     774    $res = $dbRepl->query('SHOW SLAVE STATUS');
     775    while ($res->fetchInto($row)) {
     776        # Have a look for Last_Errno in http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html
     777        $errorStatusInMySql = $row[18];
     778        $replStatus = ($errorStatusInMySql==0?"OK":"<font color=\"red\">PROBLEM</font>");
     779        echo "<tr><td>$replDatabaseName</td><td>$replStatus</td></tr>";
     780        if ($errorStatusInMySql!=0) {
     781            echo "<tr><td colspan=\"2\">Connect to $replDatabaseName replication host, execute 'SHOW SLAVE STATUS', and fix the problem.<br/>";
     782            echo "Information <a href=\"http://dev.mysql.com/doc/refman/5.0/en/show-slave-status.html\">here</a></td></tr>";
     783        }
     784    }
     785    $dbRepl->disconnect();
    778786}
    779787
  • branches/czw_branch/20101203/ippMonitor/raw/site.php.in

    r29654 r30118  
    2727$REPL_DBNAME_GPC1 = "gpc1";
    2828
    29 $REPL_HOST_NEBULOUS = "ipp0222.IfA.Hawaii.Edu";
     29$REPL_HOST_NEBULOUS = "ippdb02.IfA.Hawaii.Edu";
    3030$REPL_USER_NEBULOUS = "ippMonitor";
    3131$REPL_PASSWORD_NEBULOUS = "ippMonitor";
  • branches/czw_branch/20101203/ippScripts

    • Property svn:mergeinfo deleted
  • branches/czw_branch/20101203/ippScripts/scripts/automate_stacks.pl

    r29700 r30118  
    13551355    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
    13561356
    1357     if ($target eq 'OSS') {
     1357    if (($target eq 'OSS')||($target eq 'SweetSpot')) {
    13581358        my $db = init_gpc_db();
    13591359
     
    13721372           
    13731373            if (($#{ $warps } + 1) % 2 != 0) {
    1374                 print STDERR "Number of input warps to make OSS diffs is not even! $#{ $warps }\n";
    1375                 last;
     1374                print STDERR "Number of input warps to make OSS diffs is not even! $this_object $#{ $warps }\n";
     1375#               last;
     1376                next;
    13761377            }
    13771378           
  • branches/czw_branch/20101203/ippScripts/scripts/camera_exp.pl

    r29893 r30118  
    378378        $ipprc->file_exists($file);
    379379
    380     if ($replicate and (file_scheme($file) eq 'neb')) {
     380    my $scheme = file_scheme($file);
     381    if ($replicate and $scheme and (file_scheme($file) eq 'neb')) {
    381382        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $cam_id, $PS_EXIT_SYS_ERROR);
    382383    }
  • branches/czw_branch/20101203/ippScripts/scripts/chip_imfile.pl

    r29896 r30118  
    159159        if (storage_object_exists($configuration, \$gone)) {
    160160            if ($gone) {
    161                 rename_gone_file($configuration);
    162161                $configuration = prepare_output('PPIMAGE.CONFIG', $outroot, $class_id, 1);
    163162                # if we dump the config we need to insure that the config dump represents
     
    177176    $ipprc->delete_destreak_backup_file($outputWeight)
    178177        or &my_die("failed to delete existing destreak backup weight file", $exp_id, $chip_id, $class_id, $PS_EXIT_UNKNOWN_ERROR);
     178
     179    # don't do binned images when updating unless we are starting from scratch.
     180    $do_binned_images = 0 unless $dump_config;
    179181}
    180182if ($do_binned_images) {
     
    491493        check_output($configuration, 1) if $dump_config;
    492494        check_output($backmdl, 1) if $outputBackmdlExpect;
    493         check_output($pattern, 1) if $outputPatternExpect;
     495        # allow the pattern file to be missing if run state is update older data doesn't have one
     496        # I should parse the config dump file to calculate the 'Expect' variables
     497        check_output($pattern, 1, $run_state eq 'update') if $outputPatternExpect;
    494498        if ($do_photom) {
    495499            check_output($outputSources, 1);
     
    556560            if ($gone) {
    557561                carp "WARNING: photometry sources storage object exists but all instances are permanently gone";
    558                 rename_gone_file($outputSources);
    559562                $make_sources = 1;
    560563            }
     
    579582            if ($gone) {
    580583                carp "WARNING: PSF storage object exists but all instances are permanently gone";
    581                 rename_gone_file($outputPsf);
    582584                $make_psf = 1;
    583585            }
     
    613615sub storage_object_exists
    614616{
     617    return 0 if !$neb;
     618
    615619    my $file = shift;
    616620    my $ref_all_gone = shift;
     621
    617622
    618623    my $exists = $neb->storage_object_exists($file);
     
    678683    return 1;
    679684}
    680 sub rename_gone_file
    681 {
    682     # check whether the only instance of file is on a lost volume
    683     # XXX: we don't have a proper interface for this.
    684     # For now try to use Bill's hack: the script 'whichnode'
    685 
    686     my $file = shift;
    687     $neb->move($file, "$file.gone") or
    688                     &my_die("failed to rename: $file", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
    689 }
    690685
    691686# Prepare to write to an output file
     
    711706    my $file = shift;
    712707    my $replicate = shift;
     708    my $allow_missing = shift;
    713709
    714710    if (!defined $file) {
     
    716712    }
    717713
    718     &my_die("Couldn't find expected output file: $file",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
    719 
    720     if ($replicate and (file_scheme($file) eq 'neb')) {
     714    my $exists = $ipprc->file_exists($file);
     715
     716    if (!$exists) {
     717        if ($allow_missing) {
     718            carp("Couldn't find expected output_file: $file but continuing anyways\n");
     719            return 1;
     720        }
     721        &my_die("Couldn't find expected output file: $file",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     722    }
     723
     724    if ($replicate and $neb) {
    721725        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    722726    }
  • branches/czw_branch/20101203/ippScripts/scripts/dist_bundle.pl

    r29063 r30118  
    6262my $streaksrelease   = can_run('streaksrelease') or (warn "Can't find streaksrelease" and $missing_tools = 1);
    6363my $bgtool   = can_run('bgtool') or (warn "Can't find bgtool" and $missing_tools = 1);
     64my $file_cmd   = can_run('file') or (warn "can't find program file" and $missing_tools = 1);
     65my $zcat   = can_run('zcat') or (warn "can't find program zcat" and $missing_tools = 1);
    6466if ($missing_tools) {
    6567    warn("Can't find required tools.");
     
    526528                    $PS_EXIT_CONFIG_ERROR) if (!$resolved);
    527529
     530    &my_die("config dump file resolved but not accessible: $config_file_rule", $component,
     531                    $PS_EXIT_CONFIG_ERROR) if !$ipprc->file_exists($resolved);
     532
     533    my $mdc_compressed;
     534    {
     535        my $command = "$file_cmd $resolved";
     536        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     537            run(command => $command, verbose => $verbose);
     538        unless ($success) {
     539            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     540            &my_die("Unable to perform $command: $error_code", $component, $error_code);
     541        }
     542        my $output = join "", @$stdout_buf;
     543        # XXX: may need to to make this more robust
     544        $mdc_compressed = ($output =~ /gzip/);
     545    }
     546    my $inName;
     547    if ($mdc_compressed) {
     548        my $tmpfile;
     549        ($tmpfile, $inName) = tempfile( "/tmp/bundle.XXXX", UNLINK => !$save_temps );
     550        close($tmpfile) or &my_die("failed to close $inName", $component, $PS_EXIT_UNKNOWN_ERROR);
     551
     552        my $command = "$zcat $resolved > $inName";
     553        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     554            run(command => $command, verbose => $verbose);
     555        unless ($success) {
     556            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     557            &my_die("Unable to perform $command: $error_code", $component, $error_code);
     558        }
     559
     560
     561    } else {
     562        $inName = $resolved;
     563    }
     564    my $in = open_with_retries($inName);
     565
    528566    # we don't use the mdc parser because the perl parser is way is too slow for complicated config
    529567    # files like this
    530     my $in = open_with_retries($resolved);
    531 
    532568    my $line;
    533569    while ($line = <$in>) {
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak.pl

    r29571 r30118  
    309309        }
    310310
    311         $sources = $ipprc->filename("PSPHOT.OUTPUT",  $path_base, $class_id);
     311        # only destreak cmf file if this is a new run
     312        if ($run_state eq 'new') {
     313            $sources = $ipprc->filename("PSPHOT.OUTPUT",  $path_base, $class_id);
     314        }
    312315
    313316    } elsif ($stage eq "chip_bg") {
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_defineruns.pl

    r27718 r30118  
    7878    foreach my $label (@labels) {
    7979        my $command = "$magicdstool -definebyquery -stage $stage -workdir $workdir -label $label";
    80         $command .= " -dry_run" if $no_update;
     80        $command .= " -pretend" if $no_update;
    8181        $command .= " -limit $stage_limit" if $stage_limit;
    8282        $command .= " -set_label $label";
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_revert.pl

    r29573 r30118  
    191191    $image  = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id);
    192192    $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
    193     $sources = $ipprc->filename("PSPHOT.OUTPUT", $path_base, $class_id);
    194193
    195194    # we use the mask output from the camera stage for input and replace
     
    204203    }
    205204
     205    # only revert sources if this is a new run, not one being updated
     206    if ($run_state eq 'new') {
     207        $sources = $ipprc->filename("PSPHOT.OUTPUT", $path_base, $class_id);
     208        $bsources = $ipprc->filename("PSPHOT.OUTPUT", $backup_path_base, $class_id);
     209    }
     210
    206211    $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $class_id);
    207212    # This is somewhat kludgey but it works whether the mask is camera mask or chip mask
     
    209214    $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $class_id);
    210215    $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $class_id);
    211     $bsources = $ipprc->filename("PSPHOT.OUTPUT", $backup_path_base, $class_id);
    212216} elsif ($stage eq "camera") {
    213217    $astrom =  $ipprc->filename("PSASTRO.OUTPUT", $path_base);
  • branches/czw_branch/20101203/ippScripts/scripts/publish_file.pl

    r29622 r30118  
    4444my ( $pub_id, $camera, $stage, $stage_id, $fileset, $format, $product, $workdir );
    4545my ( $dbname, $verbose, $no_update, $no_op, $save_temps, $redirect );
     46my ( $output_format );
    4647
    4748GetOptions(
     
    5960    'save-temps'        => \$save_temps, # Save temporary files?
    6061    'redirect-output'   => \$redirect,   # Redirect output to log file?
     62    'output_format=i'   => \$output_format, # Output format for ppMops
    6163    ) or pod2usage( 2 );
    6264
     
    191193                     warp_id => $comp->{warp1},
    192194                     diff_id => $comp->{diff_id},
     195                     output_format => $comp->{output_format},
    193196                     direction => 1,
    194197        };
     
    323326
    324327    my $command = "$ppMops $input $output";
    325     $command .= " -version 1"; # XXX : NOTE: for now, MOPS just wants PS1_DV1 (remove this eventually...)
    326328    $command .= " -exp_name " . $data->{exp_name} if defined $data->{exp_name};
    327329    $command .= " -exp_id " . $data->{exp_id} if defined $data->{exp_id};
     
    335337    $command .= " -zp_error " . $data->{zp_err} if defined $data->{zp_err};
    336338    $command .= " -astrom_rms " . $data->{astrom} if defined $data->{astrom};
     339    $command .= " -version " . $data->{output_format} if defined $data->{output_format};
    337340
    338341    unless ($no_op) {
  • branches/czw_branch/20101203/ippScripts/scripts/receive_file.pl

    r29574 r30118  
    3232my $receivetool = can_run('receivetool') or (warn "Can't find receivetool" and $missing_tools = 1);
    3333my $dsproductls = can_run('dsfilesetls') or (warn "Can't find dsfilesetls" and $missing_tools = 1);
     34my $gunzip = can_run('gunzip') or (warn "Can't find gunzip" and $missing_tools = 1);
    3435if ($missing_tools) {
    3536    warn("Can't find required tools.");
     
    404405    my $workdir = shift;
    405406
     407    my $filecmd_output = `file $src`;
     408    &my_die("failed to determinte file type of $src", $file_id, $PS_EXIT_UNKNOWN_ERROR) if !$filecmd_output;
     409    chomp $filecmd_output;
     410
     411    my $tmpName;
     412    if ($filecmd_output =~ /gzip/) {
     413        my $tmpfile;
     414        ($tmpfile, $tmpName) = tempfile( "/tmp/receive.XXXX", UNLINK => !$save_temps );
     415        close($tmpfile) or &my_die("failed to close $tmpName", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     416
     417        my $command = "$gunzip -c $src > $tmpName";
     418        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     419            run(command => $command, verbose => $verbose);
     420        unless ($success) {
     421            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     422            &my_die("Unable to perform $command: $error_code", $component, $error_code);
     423        }
     424        $src = $tmpName;
     425    }
     426
    406427    open my $IN,  "<$src" or &my_die("failed to open $src for input", $file_id, $PS_EXIT_UNKNOWN_ERROR);
    407428    open my $OUT, ">$dest" or &my_die("failed to open $dest for output", $file_id, $PS_EXIT_UNKNOWN_ERROR);
  • branches/czw_branch/20101203/ippScripts/scripts/register_imfile.pl

    r29982 r30118  
    287287    if ($burntool_data->{burnable} == 0) {
    288288        $regtool_update .= " -burntool_state 0 -set_state pending_burntool ";
     289        unless ($no_update) {
     290            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     291                IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
     292            unless ($success) {
     293                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     294                warn ("Unable to perform regtool -addprocessedimfile: $error_code");
     295                exit($error_code);
     296            }
     297        } else {
     298            print "skipping command: $command\n";
     299        }
    289300    }
    290301    else {
     
    296307        $apply_command .= " --verbose " if $verbose;
    297308        print "$apply_command\n";
    298         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    299             IPC::Cmd::run(command => $apply_command, verbose => $verbose);
    300         unless ($success) {
    301             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    302             warn ("Unable to perform ipp_apply_burntool_single.pl: $error_code");
    303             exit($error_code);
     309        unless ($no_update) {
     310            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     311                IPC::Cmd::run(command => $apply_command, verbose => $verbose);
     312            unless ($success) {
     313                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     314                warn ("Unable to perform ipp_apply_burntool_single.pl: $error_code");
     315                exit($error_code);
     316            }
    304317        }
    305318    }   
    306319
    307     unless ($no_update) {
    308         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    309             IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
    310         unless ($success) {
    311             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    312             warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    313             exit($error_code);
    314         }
    315     } else {
    316         print "skipping command: $command\n";
    317     }
    318320
    319321}
  • branches/czw_branch/20101203/ippTasks

    • Property svn:mergeinfo deleted
  • branches/czw_branch/20101203/ippTasks/detrend.resid.pro

    r28598 r30118  
    136136
    137137  task.exec
     138    periods -exec $RUNEXEC
     139
    138140    book npages detPendingResidImfile -var N
    139141    if ($N == 0) break
     
    187189      echo command $run
    188190    end
     191    periods -exec 0.05
    189192    command $run
    190193  end
  • branches/czw_branch/20101203/ippTasks/publish.pro

    r29724 r30118  
    130130    book getword publishRun $pageName stage_id -var STAGE_ID
    131131    book getword publishRun $pageName dbname -var DBNAME
     132    book getword publishRun $pageName output_format -var OUTPUT_FORMAT
    132133
    133134    stdout $LOGDIR/publish.run.log
     
    137138    strsub $WORKDIR_TEMPLATE @HOST@ $default_host -var WORKDIR
    138139
    139     $run = publish_file.pl --pub_id $PUB_ID --camera $CAMERA --workdir $WORKDIR --product $PRODUCT --stage $STAGE --stage_id $STAGE_ID --redirect-output
     140    $run = publish_file.pl --pub_id $PUB_ID --camera $CAMERA --workdir $WORKDIR --product $PRODUCT --stage $STAGE --stage_id $STAGE_ID --output_format $OUTPUT_FORMAT --redirect-output
    140141    add_standard_args run
    141142
  • branches/czw_branch/20101203/ippTasks/register.pro

    r29982 r30118  
    466466    $today = `date -u +%Y-%m-%d`
    467467# debugging purposes
    468     $today = "2010-12-06"
     468#    $today = "2010-12-06"
    469469    $run = $run -date $today -valid_burntool $valid_burntool_value
    470470    if ($DB:n == 0)
     
    478478    end
    479479
    480     echo $run
     480#    echo $run
    481481    add_poll_args run
    482482    command $run
  • branches/czw_branch/20101203/ippToPsps/perl/checkOdmStatus.pl

    r29652 r30118  
    3939        );
    4040
     41if (@ARGV) {
     42    print "* UNKNKOWN: option                          @ARGV\n";
     43}
    4144if (!defined $product) {
    4245    print "* OPTIONAL: a datastore product name            -p <name>\n";
     
    159162        $numBatchesToCheck++;
    160163
    161         # if not merged then update by polling ODM for status
     164        # if not merged or failed load, then update by polling ODM for status
    162165        if (!$merged && !$loadFailed) {
    163 
    164166            if (checkODM($batch->getName(), \$loadedToOdm, \$loadFailed, \$mergeWorthy, \$merged)) {
    165167               
  • branches/czw_branch/20101203/ippToPsps/perl/ippToPsps/DetectionBatch.pm

    r29236 r30118  
    7878    # get neb path of smf file
    7979    my $nebPath = $self->{_gpc1Db}->getCameraStageSmfForThisDvoDb($self->{_dvoDb}, $self->{_expId});
    80     if (!$nebPath) { return 0; }
     80    if (!$nebPath) { return undef; }
    8181
    8282    # get real filename from neb 'key'
  • branches/czw_branch/20101203/ippToPsps/perl/ippToPsps/IppToPspsDb.pm

    r29345 r30118  
    1111###########################################################################
    1212#
    13 # Returns a list of batches that have been processed and loaded to datastore
     13# Returns a list of batches created within the provided dates
    1414#
    1515###########################################################################
     
    3939    $query->execute;
    4040    ${$batches} = $query->fetchall_arrayref();
    41     my $count = scalar @{${$batches}};
    42 
    43    return $count;
     41    return scalar @{${$batches}};
    4442}
    4543
     
    7270    $query->execute;
    7371    ${$batches} = $query->fetchall_arrayref();
    74     my $count = scalar @{${$batches}};
    75 
    76    return $count;
     72    return scalar @{${$batches}};
     73}
     74
     75###########################################################################
     76#
     77# Returns a count of all distinct exposures between provided limits
     78#
     79###########################################################################
     80sub countExposures {
     81    my ($self, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
     82
     83    my $query = $self->{_db}->prepare(<<SQL);
     84    SELECT COUNT(distinct exp_id)
     85        FROM batches
     86        WHERE exp_id >= $fromExp
     87        AND exp_id <= $toExp
     88        AND dvo_db = '$dvoDb'
     89        AND batch_type = '$batchType'
     90        AND datastore_product = '$datastoreProduct'
     91SQL
     92
     93    $query->execute;
     94    return scalar $query->fetchrow_array();
     95}
     96
     97###########################################################################
     98#
     99# Returns a count of exposures (between provided limits) that have been merged
     100#
     101###########################################################################
     102sub countMergedExposures {
     103    my ($self, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
     104
     105    my $query = $self->{_db}->prepare(<<SQL);
     106    SELECT COUNT(distinct exp_id)
     107        FROM batches
     108        WHERE exp_id >= $fromExp
     109        AND exp_id <= $toExp
     110        AND dvo_db = '$dvoDb'
     111        AND batch_type = '$batchType'
     112        AND datastore_product = '$datastoreProduct'
     113        AND merged
     114SQL
     115
     116    $query->execute;
     117    return scalar $query->fetchrow_array();
     118}
     119
     120###########################################################################
     121#
     122# Returns a list of exposures (between provided limits) that have not been merged
     123#
     124###########################################################################
     125sub getUnmergedExposures {
     126    my ($self, $exposures, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
     127
     128    my $query = $self->{_db}->prepare(<<SQL);
     129    SELECT batch_id, exp_id
     130        FROM batches
     131        WHERE exp_id >= $fromExp
     132        AND exp_id <= $toExp
     133        AND dvo_db = '$dvoDb'
     134        AND batch_type = '$batchType'
     135        AND datastore_product = '$datastoreProduct'
     136        AND !merged
     137        GROUP BY exp_id
     138SQL
     139
     140    $query->execute;
     141    ${$exposures} = $query->fetchall_arrayref();
     142    return scalar @{${$exposures}};
    77143}
    78144
     
    166232#######################################################################################
    167233#
     234# Checks whether this exposure failed to load to the ODM
     235#
     236########################################################################################
     237sub didLoadFail {
     238    my ($self, $expId) = @_;
     239
     240    my $query = $self->{_db}->prepare(<<SQL);
     241    SELECT COUNT(*)
     242        FROM batches
     243        WHERE exp_id = $expId
     244        AND load_failed
     245SQL
     246
     247    $query->execute;
     248
     249    return scalar $query->fetchrow_array();
     250}
     251
     252#######################################################################################
     253#
     254# Checks whether this exposure has a min object ID under old PSPS hard limit of 72010000000000001
     255#
     256########################################################################################
     257sub isMinObjIdUnderLimit {
     258    my ($self, $expId) = @_;
     259
     260    my $query = $self->{_db}->prepare(<<SQL);
     261    SELECT COUNT(*)
     262        FROM batches
     263        WHERE exp_id = $expId
     264        AND min_obj_id < 72010000000000001
     265SQL
     266
     267    $query->execute;
     268
     269    return scalar $query->fetchrow_array();
     270}
     271#######################################################################################
     272#
     273# Checks whether this exposure has been processed
     274#
     275########################################################################################
     276sub isExposureProcessed {
     277    my ($self, $expId) = @_;
     278
     279    my $query = $self->{_db}->prepare(<<SQL);
     280    SELECT COUNT(*)
     281        FROM batches
     282        WHERE exp_id = $expId
     283        AND processed
     284SQL
     285
     286    $query->execute;
     287
     288    return scalar $query->fetchrow_array();
     289}
     290
     291#######################################################################################
     292#
     293# Checks whether this exposure has been merged
     294#
     295########################################################################################
     296sub isExposureMerged {
     297    my ($self, $expId) = @_;
     298
     299    my $query = $self->{_db}->prepare(<<SQL);
     300    SELECT COUNT(*)
     301        FROM batches
     302        WHERE exp_id = $expId
     303        AND merged
     304SQL
     305
     306    $query->execute;
     307
     308    return scalar $query->fetchrow_array();
     309}
     310
     311#######################################################################################
     312#
     313# Checks whether this exposure has been loaded to ODM
     314#
     315########################################################################################
     316sub isExposureLoadedToOdm {
     317    my ($self, $expId) = @_;
     318
     319    my $query = $self->{_db}->prepare(<<SQL);
     320    SELECT COUNT(*)
     321        FROM batches
     322        WHERE exp_id = $expId
     323        AND loaded_to_ODM
     324SQL
     325
     326    $query->execute;
     327
     328    return scalar $query->fetchrow_array();
     329}
     330
     331#######################################################################################
     332#
    168333# Checks whether we have successfully processed this exposure and loaded it to the datastore
    169334#
     
    184349    my $processed = $query->fetchrow_array();
    185350
     351    # TODO can use return scalar $query->fetchrow_array();
    186352    return $processed;
    187353}
  • branches/czw_branch/20101203/ippToPsps/perl/ippToPsps_run.pl

    r29089 r30118  
    1515use ippToPsps::IppToPspsDb;
    1616use ippToPsps::Datastore;
     17#use ippToPsps::BatchManager;
    1718
    1819# globals
     
    112113my $datastore = undef;
    113114if ($datastoreProduct) {$datastore = new ippToPsps::Datastore($datastoreProduct, $verbose, $save_temps);}
     115#my $batchManager = new ippToPsps::BatchManager($ippToPspsDb, $output, $verbose, $save_temps);
    114116
    115117# check we can run programs and get camera config
  • branches/czw_branch/20101203/ippTools

    • Property svn:mergeinfo deleted
  • branches/czw_branch/20101203/ippTools/configure.ac

    r29499 r30118  
    11AC_PREREQ(2.61)
    22
    3 AC_INIT([ipptools], [1.1.65], [ipp-support@ifa.hawaii.edu])
     3AC_INIT([ipptools], [1.1.66], [ipp-support@ifa.hawaii.edu])
    44AC_CONFIG_SRCDIR([autogen.sh])
    55
     
    1818PKG_CHECK_MODULES([PSLIB], [pslib >= 1.1.0])
    1919PKG_CHECK_MODULES([PSMODULES], [psmodules >= 1.1.0])
    20 PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.65])
     20PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.66])
    2121PKG_CHECK_MODULES([PPSTAMP], [ppstamp >= 0.1.1])
    2222
  • branches/czw_branch/20101203/ippTools/share/camtool_find_pendingimfile.sql

  • branches/czw_branch/20101203/ippTools/share/pubtool_definerun.sql

    r28428 r30118  
    33    client_id,
    44    stage_id,
    5     src_label
     5    src_label,
     6    output_format
    67FROM (
    78    -- Get diffs to publish
     
    910        client_id,
    1011        diff_id AS stage_id,
    11         diffRun.label AS src_label
     12        diffRun.label AS src_label,
     13        output_format
    1214    FROM publishClient
    1315    JOIN diffRun
     
    2830        client_id,
    2931        cam_id AS stage_id,
    30         camRun.label AS src_label
     32        camRun.label AS src_label,
     33        output_format
    3134    FROM publishClient
    3235    JOIN camRun
     
    4346        client_id,
    4447        diff_phot_id AS stage_id,
    45         diffPhotRun.label AS src_label
     48        diffPhotRun.label AS src_label,
     49        output_format
    4650    FROM publishClient
    4751    JOIN diffPhotRun
  • branches/czw_branch/20101203/ippTools/share/pubtool_pending.sql

    r28491 r30118  
    99        publishClient.stage,
    1010        publishClient.workdir,
     11        publishClient.output_format,
    1112        diffRun.diff_id AS stage_id,
    1213        rawExp.camera,
     
    3536        publishClient.stage,
    3637        publishClient.workdir,
     38        publishClient.output_format,
    3739        camRun.cam_id AS stage_id,
    3840        rawExp.camera,
     
    5658        publishClient.stage,
    5759        publishClient.workdir,
     60        publishClient.output_format,
    5861        diffPhotRun.diff_phot_id AS stage_id,
    5962        rawExp.camera,
  • branches/czw_branch/20101203/ippTools/share/pxadmin_create_tables.sql

    r29982 r30118  
    16451645    workdir VARCHAR(255) NOT NULL, -- working directory
    16461646    comment VARCHAR(255),            -- for human memory
    1647     PRIMARY KEY(client_id)
     1647    name varchar(64) default NULL, -- unique client_id verbose identifier
     1648    output_format SMALLINT NOT NULL default 1, -- format output versioning
     1649    PRIMARY KEY(client_id),
     1650    UNIQUE KEY name (name)
    16481651) ENGINE=innodb DEFAULT CHARSET=latin1;
    16491652
  • branches/czw_branch/20101203/ippTools/share/regtool_pendingexp.sql

    r29982 r30118  
    11SELECT DISTINCT
    2     exp_id,
    3     tmp_exp_name,
    4     tmp_camera,
    5     tmp_telescope,
    6     state,
    7     workdir,
    8     workdir_state,
    9     reduction,
    10     dvodb,
    11     tess_id,
    12     end_stage,
    13     label,
    14     camera,
    15     filter,
    16     obs_mode,
    17     obs_group,
    18     epoch,
    19     dateobs
    20 FROM
    21     (SELECT
    22        newExp.*,
    23        newImfile.tmp_class_id,
    24        rawImfile.tmp_class_id as raw_tmp_class_id,
    25        rawImfile.camera,
    26        rawImfile.filter,
    27        rawImfile.dateobs,
    28        rawImfile.obs_mode,
    29        rawImfile.obs_group
    30     FROM newExp
    31     JOIN newImfile
    32        USING(exp_id)
    33     LEFT JOIN rawExp
    34        USING(exp_id)
    35     LEFT JOIN rawImfile
    36         ON newImfile.exp_id = rawImfile.exp_id
    37         AND newImfile.tmp_class_id = rawImfile.tmp_class_id
    38     WHERE
    39         newExp.state = 'run'
    40         AND rawExp.exp_id IS NULL
    41         AND rawImfile.data_state = 'full'
    42 -- where hook %s
    43     GROUP BY
    44         newExp.exp_id
    45     HAVING
    46         COUNT(newImfile.tmp_class_id) = COUNT(rawImfile.tmp_class_id)
    47         AND SUM(rawImfile.fault) = 0
     2     exp_id,
     3     tmp_exp_name,
     4     tmp_camera,
     5     tmp_telescope,
     6     state,
     7     workdir,
     8     workdir_state,
     9     reduction,
     10     dvodb,
     11     tess_id,
     12     end_stage,
     13     label,
     14     camera,
     15     filter,
     16     obs_mode,
     17     obs_group,
     18     epoch,
     19     dateobs
     20FROM
     21        (
     22        select DISTINCT * from
     23         (
     24          select newExp.*,count(newImfile.tmp_class_id) AS new_count
     25          from newExp
     26          LEFT JOIN newImfile USING (exp_id)
     27          LEFT JOIN rawExp USING (exp_id)
     28          where
     29           newExp.state = 'run' AND rawExp.exp_id IS NULL
     30          GROUP BY newExp.exp_id
     31         ) AS NEWEXPOSURES
     32         JOIN
     33         (
     34          select DISTINCT newExp.exp_id,
     35          rawImfile.camera,
     36          rawImfile.filter,
     37          rawImfile.dateobs,
     38          rawImfile.obs_mode,
     39          rawImfile.obs_group,
     40          count(rawImfile.tmp_class_id) AS raw_count
     41          from newExp
     42          LEFT JOIN rawExp USING (exp_id)
     43          LEFT JOIN rawImfile USING (exp_id)
     44          where
     45           newExp.state = 'run' AND rawExp.exp_id IS NULL
     46           AND rawImfile.data_state = 'full'
     47           -- where hook %s
     48          GROUP BY newExp.exp_id
     49          HAVING SUM(rawImfile.fault) = 0
     50         ) AS RAWEXPOSURES
     51         USING (exp_id)
     52        WHERE raw_count = new_count
     53    ) AS Foo
    4854-- limit hook %s
    49     ) as Foo
  • branches/czw_branch/20101203/ippTools/src

  • branches/czw_branch/20101203/ippTools/src/dettool.c

    r28689 r30118  
    572572    PXOPT_COPY_F64(config->args, where, "-select_moon_phase_min", "moon_phase", ">=");
    573573    PXOPT_COPY_F64(config->args, where, "-select_moon_phase_max", "moon_phase", "<=");
     574
     575    PXOPT_COPY_STR(config->args, where, "-select_state", "state", "=");
    574576    PXOPT_COPY_STR(config->args, where, "-comment", "comment", "LIKE");
    575577
  • branches/czw_branch/20101203/ippTools/src/dettoolConfig.c

    r28578 r30118  
    138138    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_phase_min",  0,          "define min moon phase", NAN);
    139139    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_moon_phase_max",  0,          "define max moon phase", NAN);
     140    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-select_state",           0,          "select by state (default is 'full')", "full");
    140141    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-comment",                0,          "search by comment field (LIKE comparison)", NULL);
    141142
  • branches/czw_branch/20101203/ippTools/src/difftool.c

    r29696 r30118  
    483483    psFree(where);
    484484
    485      psStringAppend(&query, "\nORDER by priority DESC, diff_id");
     485     psStringAppend(&query, "\nORDER by priority DESC, diff_id, skycell_id");
    486486
    487487    // treat limit == 0 as "no limit"
     
    19781978    PXOPT_COPY_STR(config->args, stack2Where, "-skycell_id", "stackRun.skycell_id", "==");
    19791979    PXOPT_COPY_STR(config->args, stack1Where, "-input_label", "stackRun.label","==");
     1980    PXOPT_COPY_STR(config->args, stack1Where, "-input_data_group", "stackRun.data_group","==");
    19801981    PXOPT_COPY_STR(config->args, stack2Where, "-template_label", "stackRun.label","==");
    19811982    PXOPT_COPY_F32(config->args, stack1Where, "-good_frac", "stackSumSkyfile.good_frac", ">=");
     
    20422043    }
    20432044
    2044     psString queryCopy = psStringCopy(query);
    2045     psFree(query);
    2046     query = queryCopy;
    2047    
    20482045    psStringSubstitute(&query, stack1Query, "@STACK1_QUERY@");
    20492046    psStringSubstitute(&query, stack2Query, "@STACK2_QUERY@");
     
    21202117        psStringAppend(&this_stack1Query,"AND %s", thisWhere);
    21212118        psFree(thisWhere);
    2122 
    2123         psString queryCopy = psStringCopy(query);
    2124         psFree(query);
    2125         query = queryCopy;
    2126    
    21272119
    21282120        psStringSubstitute(&query, this_stack1Query, "@STACK1_QUERY@");
  • branches/czw_branch/20101203/ippTools/src/difftoolConfig.c

    r29553 r30118  
    336336    psMetadataAddStr(definestackstackArgs, PS_LIST_TAIL, "-input_label", 0, "search by stack label for input", NULL);
    337337    psMetadataAddStr(definestackstackArgs, PS_LIST_TAIL, "-template_label", 0, "search by stack label for template", NULL);
     338    psMetadataAddStr(definestackstackArgs, PS_LIST_TAIL, "-input_data_group", 0, "search by stack data_group for input", NULL);
    338339    psMetadataAddF32(definestackstackArgs, PS_LIST_TAIL, "-good_frac", 0, "minimum good fraction of skycell", NAN);
    339340    psMetadataAddStr(definestackstackArgs, PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
  • branches/czw_branch/20101203/ippTools/src/magicdstool.c

    r29611 r30118  
    11551155
    11561156    psMetadata *where = psMetadataAlloc();
    1157     // new state
    1158     PXOPT_LOOKUP_STR(new_state, config->args, "-set_state", false, false);
     1157    // new state (required
     1158    PXOPT_LOOKUP_STR(new_state, config->args, "-set_state", true, false);
    11591159    // old state (required)
    11601160    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
  • branches/czw_branch/20101203/ippTools/src/magicdstoolConfig.c

    r29611 r30118  
    163163    // -clearstatefaults
    164164    psMetadata *clearstatefaultsArgs = psMetadataAlloc();
    165     psMetadataAddStr(clearstatefaultsArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state", NULL);
     165    psMetadataAddStr(clearstatefaultsArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state (required)", NULL);
    166166    psMetadataAddStr(clearstatefaultsArgs, PS_LIST_TAIL, "-state", 0, "search by state (required)", NULL);
    167167    psMetadataAddS64(clearstatefaultsArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magictool de-streak ID", 0);
  • branches/czw_branch/20101203/ippTools/src/pstamptool.c

    r29569 r30118  
    950950    PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
    951951    PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
     952
     953    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     954    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     955
    952956    PXOPT_COPY_S32(config->args, where, "-fault",  "pstampDependent.fault", "==");
     957
    953958    pxAddLabelSearchArgs(config, where, "-label", "pstampRequest.label", "LIKE");
    954     // if (fault_count) {
    955         PXOPT_COPY_S32(config->args, where, "-fault_count", "pstampDependent.fault_count", ">=");
    956     // }
     959    PXOPT_COPY_S32(config->args, where, "-fault_count", "pstampDependent.fault_count", ">=");
    957960
    958961    // XXX: How about selecting by pstampRequest.label? No. That is too dangerous by itself.
  • branches/czw_branch/20101203/ippTools/src/pstamptoolConfig.c

    r29328 r30118  
    178178    psMetadataAddS64(stopdependentjobArgs, PS_LIST_TAIL,  "-job_id", 0,       "job_id of jobs to update", 0);
    179179    psMetadataAddS64(stopdependentjobArgs, PS_LIST_TAIL,  "-dep_id", 0,       "dep_id of jobs to update", 0);
     180    psMetadataAddS64(stopdependentjobArgs, PS_LIST_TAIL,  "-stage_id", 0,     "stage_id of jobs to update", 0);
     181    psMetadataAddStr(stopdependentjobArgs, PS_LIST_TAIL,  "-component", 0,    "component of jobs to update", NULL);
    180182    psMetadataAddS16(stopdependentjobArgs, PS_LIST_TAIL,  "-fault", 0,        "current value for dependent fault", 0);
    181183    psMetadataAddS32(stopdependentjobArgs, PS_LIST_TAIL,  "-fault_count", 0,   "select by fault_count (>=)", 0);
  • branches/czw_branch/20101203/ippTools/src/pubtool.c

    r29321 r30118  
    9696    PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
    9797    PXOPT_LOOKUP_BOOL(unmagicked, config->args, "-unmagicked",  false);
    98 
    99     if (!publishClientInsert(config->dbh, 0, 0, product, stage, !unmagicked, workdir, comment)) {
     98    PXOPT_LOOKUP_STR(name, config->args, "-name",  false, false);
     99    PXOPT_LOOKUP_S16(output_format, config->args, "-output_format",  false, false);
     100
     101    if (!publishClientInsert(config->dbh, 0, 0, product, stage, !unmagicked, workdir, comment, name, output_format)) {
    100102        psError(PS_ERR_UNKNOWN, false, "Database error");
    101103        return false;
     
    313315    PXOPT_COPY_STR(config->args, where, "-stage", "publishClient.stage", "==");
    314316    PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
     317    PXOPT_COPY_STR(config->args, where, "-name", "publishClient.name", "LIKE");
    315318    pxAddLabelSearchArgs(config, where, "-label", "publishRun.label", "==");
    316319
  • branches/czw_branch/20101203/ippTools/src/pubtoolConfig.c

    r28371 r30118  
    8383    psMetadataAddBool(pendingArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
    8484    psMetadataAddU64(pendingArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
     85    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-name", 0, "search on client name", NULL);
    8586
    8687    // -add
  • branches/czw_branch/20101203/ippTools/src/regtool.c

    r30014 r30118  
    300300  psStringSubstitute(&query,date,"@DATE@");
    301301
    302   fprintf(stderr,"%s",query);
     302  //  fprintf(stderr,"%s",query);
    303303
    304304  if (!p_psDBRunQuery(config->dbh, query)) {
     
    349349      psMetadataAddStr(row,PS_LIST_TAIL,"previous_class_id",PS_META_REPLACE,"",previous_class_id);
    350350    }
    351    
     351    // class_id = NULL sorts to the top of the list, so skip those (incomplete downloads)
     352    if (!this_class_id) {
     353      continue;
     354    }
    352355    // Determine if we've crossed a class_id boundary, as this resets the bits.
    353356    if (previous_class_id) {
     
    370373    if ((psMetadataLookupS32(NULL,row,"is_downloaded") != 1)||
    371374        (psMetadataLookupS32(NULL,row,"is_registered") != 1)) {
     375      //      printf("I claim this isn't downloaded or registered? %s %s\n",this_uri,this_class_id);
    372376      ok_to_burn = false;
    373377    }
    374378    if (already_burned == false) {
     379      //      printf("already_burned looks false %s %s\n",this_uri,this_class_id);
    375380      ok_to_burn = false;
    376381    }
     
    398403    }     
    399404
    400     //    printf("STATUS: %s %s %s %s (%d %d)\n",this_uri,previous_uri,this_class_id,previous_class_id,ok_to_burn,already_burned);
     405    //    printf("STATUS: %s %s %s %s (%d %d) %d %d %d\n",this_uri,previous_uri,this_class_id,previous_class_id,ok_to_burn,already_burned,psMetadataLookupS32(NULL,row,"burntool_state"),psMetadataLookupS32(NULL,row,"is_registered"),psMetadataLookupS32(NULL,row,"is_downloaded"));
    401406
    402407    // If the state of this imfile is not "pending_burntool" then we can't burn it.
  • branches/czw_branch/20101203/ippconfig

  • branches/czw_branch/20101203/ippconfig/gpc1/camera.config

    r29434 r30118  
    164164# This value is equal to CONV.POOR | STARCORE | SPIKE | SUSPECT  = 0x5280
    165165# unfortunately the perl parser won't accept a hex value
    166 MASK.NO.CENSOR      U32      21120
     166MASK.NO.CENSOR               U32      21120
     167
     168METADATA.COMPRESSION         STR      7f # compression mode (nM): n = 1-9, M = f (filtered), h (Huffman), R (run-length)
  • branches/czw_branch/20101203/ippconfig/gpc1/ppImage.config

    r29833 r30118  
    1313NORM.CLASS              STR     CHIP             # How to find the per-class normalizations
    1414
     15NONLIN                  BOOL    FALSE            # apply non-linearity correction
    1516OLDDARK                 BOOL    FALSE
    1617
     
    279280  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    280281  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     282  NONLIN           BOOL    FALSE            # apply non-linearity correction
    281283  BIAS             BOOL    FALSE           # Bias subtraction
    282284  DARK             BOOL    TRUE            # Dark subtraction
     
    308310  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    309311  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     312  NONLIN           BOOL    FALSE            # apply non-linearity correction
    310313  BIAS               BOOL    FALSE           # Bias subtraction
    311314  DARK               BOOL    TRUE            # Dark subtraction
     
    337340  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    338341  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     342  NONLIN           BOOL    TRUE            # apply non-linearity correction
    339343  BIAS               BOOL    FALSE           # Bias subtraction
    340344  DARK               BOOL    TRUE            # Dark subtraction
     
    367371  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    368372  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     373  NONLIN           BOOL    TRUE            # apply non-linearity correction
    369374  BIAS             BOOL    FALSE           # Bias subtraction
    370375  DARK             BOOL    TRUE            # Dark subtraction
     
    392397  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    393398  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     399  NONLIN           BOOL    TRUE            # apply non-linearity correction
    394400  BIAS               BOOL    FALSE           # Bias subtraction
    395401  DARK               BOOL    FALSE           # Dark subtraction
     
    415421  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    416422  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     423  NONLIN           BOOL    TRUE            # apply non-linearity correction
    417424  BIAS             BOOL    FALSE           # Bias subtraction
    418425  DARK             BOOL    TRUE            # Dark subtraction
     
    438445  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    439446  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     447  NONLIN           BOOL    TRUE            # apply non-linearity correction
    440448  BIAS             BOOL    FALSE
    441449  DARK             BOOL    TRUE            # Dark subtraction
     
    468476  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    469477  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     478  NONLIN           BOOL    TRUE            # apply non-linearity correction
    470479  BIAS             BOOL    FALSE           # Bias subtraction
    471480  DARK             BOOL    TRUE            # Dark subtraction
     
    521530  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    522531  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     532  NONLIN             BOOL    TRUE            # apply non-linearity correction
    523533  BIAS               BOOL    FALSE           # Bias subtraction
    524534  DARK               BOOL    TRUE            # Dark subtraction
     
    544554  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    545555  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     556  NONLIN           BOOL    TRUE            # apply non-linearity correction
    546557  BIAS               BOOL    FALSE           # Bias subtraction
    547558  DARK               BOOL    TRUE            # Dark subtraction
     
    574585  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    575586  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     587  NONLIN           BOOL    TRUE            # apply non-linearity correction
    576588  BIAS             BOOL    FALSE           # Bias subtraction
    577589  DARK             BOOL    TRUE            # Dark subtraction
     
    597609  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    598610  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     611  NONLIN           BOOL    TRUE            # apply non-linearity correction
    599612  BIAS             BOOL    FALSE           # Bias subtraction
    600613  DARK             BOOL    TRUE            # Dark subtraction
     
    631644  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    632645  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     646  NONLIN           BOOL    TRUE            # apply non-linearity correction
    633647  BIAS             BOOL    FALSE           # Bias subtraction
    634648  DARK             BOOL    TRUE            # Dark subtraction
     
    656670  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    657671  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     672  NONLIN           BOOL    TRUE            # apply non-linearity correction
    658673  BIAS             BOOL    FALSE           # Bias subtraction
    659674  DARK             BOOL    TRUE            # Dark subtraction
     
    680695  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    681696  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     697  NONLIN           BOOL    TRUE            # apply non-linearity correction
    682698  BIAS             BOOL    FALSE           # Bias subtraction
    683699  DARK             BOOL    TRUE            # Dark subtraction
     
    704720  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    705721  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     722  NONLIN           BOOL    TRUE            # apply non-linearity correction
    706723  BIAS             BOOL    FALSE           # Bias subtraction
    707724  DARK             BOOL    TRUE            # Dark subtraction
     
    728745  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    729746  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     747  NONLIN           BOOL    TRUE            # apply non-linearity correction
    730748  BIAS             BOOL    FALSE           # Bias subtraction
    731749  DARK             BOOL    TRUE            # Dark subtraction
     
    776794  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    777795  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     796  NONLIN           BOOL    TRUE            # apply non-linearity correction
    778797  BIAS             BOOL    FALSE           # Bias subtraction
    779798  DARK             BOOL    TRUE            # Dark subtraction
     
    820839  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    821840  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     841  NONLIN           BOOL    FALSE            # apply non-linearity correction
    822842  BIAS             BOOL    FALSE           # Bias subtraction
    823843  DARK             BOOL    FALSE           # Dark subtraction
     
    840860PPIMAGE_J1_RESID_B      METADATA
    841861  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     862  NONLIN           BOOL    FALSE           # apply non-linearity correction
    842863  BIAS             BOOL    FALSE           # Bias subtraction
    843864  DARK             BOOL    FALSE           # Dark subtraction
     
    877898PPIMAGE_J2_RESID_B        METADATA
    878899  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     900  NONLIN           BOOL    FALSE            # apply non-linearity correction
    879901  BIAS             BOOL    FALSE           # Bias subtraction
    880902  DARK             BOOL    FALSE           # Dark subtraction
     
    914936PPIMAGE_J1_RESID_F      METADATA
    915937  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     938  NONLIN           BOOL    FALSE            # apply non-linearity correction
    916939  BIAS             BOOL    FALSE           # Bias subtraction
    917940  DARK             BOOL    FALSE           # Dark subtraction
     
    950973PPIMAGE_J2_RESID_F        METADATA
    951974  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     975  NONLIN           BOOL    FALSE            # apply non-linearity correction
    952976  BIAS             BOOL    FALSE           # Bias subtraction
    953977  DARK             BOOL    FALSE           # Dark subtraction
     
    9911015  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image?
    9921016  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    993   OVERSCAN         BOOL    FALSE           # Overscan subtraction
    994   OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1017  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1018  NONLIN           BOOL    TRUE            # apply non-linearity correction
    9951019  BIAS             BOOL    FALSE           # Bias subtraction
    9961020  DARK             BOOL    TRUE            # Dark subtraction
     
    10281052  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    10291053  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1054  NONLIN           BOOL    TRUE            # apply non-linearity correction
    10301055  BIAS             BOOL    FALSE           # Bias subtraction
    10311056  DARK             BOOL    TRUE            # Dark subtraction
     
    10801105  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    10811106  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1107  NONLIN           BOOL    TRUE            # apply non-linearity correction
    10821108  BIAS             BOOL    FALSE           # Bias subtraction
    10831109  DARK             BOOL    TRUE            # Dark subtraction
     
    11091135  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    11101136  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1137  NONLIN           BOOL    TRUE            # apply non-linearity correction
    11111138  BIAS               BOOL    FALSE           # Bias subtraction
    11121139  DARK               BOOL    TRUE            # Dark subtraction
     
    11381165  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    11391166  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1167  NONLIN           BOOL    TRUE            # apply non-linearity correction
    11401168  BIAS             BOOL    FALSE           # Bias subtraction
    11411169  DARK             BOOL    TRUE            # Dark subtraction
     
    11671195  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    11681196  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1197  NONLIN             BOOL    TRUE            # apply non-linearity correction
    11691198  BIAS               BOOL    FALSE            # Bias subtraction
    11701199  DARK               BOOL    TRUE            # Dark subtraction
  • branches/czw_branch/20101203/ippconfig/gpc1/psastro.config

    r29591 r30118  
    291291        REFSTAR_MASK    BOOL    FALSE
    292292END
     293
     294SAS_REFERENCE METADATA
     295    PSASTRO.CATDIR              STR      SAS.REF.V1
     296END
  • branches/czw_branch/20101203/ippconfig/recipes/filerules-mef.mdc

    r29889 r30118  
    276276PPSUB.REF.CONV.VARIANCE OUTPUT {OUTPUT}.refConv.wt.fits          VARIANCE  COMP_WT    FPA        TRUE      NONE
    277277                                                                                     
     278PPSUB.FORCED1.SOURCES   OUTPUT {OUTPUT}.frc1.cmf                 CMF       NONE       FPA        TRUE      NONE
     279PPSUB.FORCED2.SOURCES   OUTPUT {OUTPUT}.frc2.cmf                 CMF       NONE       FPA        TRUE      NONE
     280PPSUB.POS1.SOURCES      OUTPUT {OUTPUT}.pos1.cmf                 CMF       NONE       FPA        TRUE      NONE
     281PPSUB.POS2.SOURCES      OUTPUT {OUTPUT}.pos2.cmf                 CMF       NONE       FPA        TRUE      NONE
    278282                                                                                     
    279283PPSTACK.OUTPUT          OUTPUT {OUTPUT}.fits                     IMAGE     COMP_IMG   FPA        TRUE      NONE
  • branches/czw_branch/20101203/ippconfig/recipes/filerules-simple.mdc

    r29889 r30118  
    246246PPSUB.REF.CONV.VARIANCE      OUTPUT {OUTPUT}.refConv.wt.fits      VARIANCE        NONE       FPA        TRUE      NONE
    247247                                             
     248PPSUB.FORCED1.SOURCES        OUTPUT {OUTPUT}.frc1.cmf             CMF             NONE       FPA        TRUE      NONE
     249PPSUB.FORCED2.SOURCES        OUTPUT {OUTPUT}.frc2.cmf             CMF             NONE       FPA        TRUE      NONE
     250PPSUB.POS1.SOURCES           OUTPUT {OUTPUT}.pos1.cmf             CMF             NONE       FPA        TRUE      NONE
     251PPSUB.POS2.SOURCES           OUTPUT {OUTPUT}.pos2.cmf             CMF             NONE       FPA        TRUE      NONE
     252
    248253PPSTACK.OUTPUT.COMP          OUTPUT {OUTPUT}.fits                 IMAGE           COMP_IMG   FPA        TRUE      NONE
    249254PPSTACK.OUTPUT.RAW           OUTPUT {OUTPUT}.fits                 IMAGE           NONE       FPA        TRUE      NONE
  • branches/czw_branch/20101203/ippconfig/recipes/filerules-split.mdc

    r29889 r30118  
    272272PPSUB.REF.CONV.VARIANCE      OUTPUT {OUTPUT}.refConv.wt.fits          VARIANCE        COMP_WT    FPA        TRUE      NONE
    273273                                                                                                     
     274PPSUB.FORCED1.SOURCES        OUTPUT {OUTPUT}.frc1.cmf                 CMF             NONE       FPA        TRUE      NONE
     275PPSUB.FORCED2.SOURCES        OUTPUT {OUTPUT}.frc2.cmf                 CMF             NONE       FPA        TRUE      NONE
     276PPSUB.POS1.SOURCES           OUTPUT {OUTPUT}.pos1.cmf                 CMF             NONE       FPA        TRUE      NONE
     277PPSUB.POS2.SOURCES           OUTPUT {OUTPUT}.pos2.cmf                 CMF             NONE       FPA        TRUE      NONE
     278
    274279PPSTACK.OUTPUT.COMP          OUTPUT {OUTPUT}.fits                     IMAGE           COMP_IMG   FPA        TRUE      NONE
    275280PPSTACK.OUTPUT.NOCOMP        OUTPUT {OUTPUT}.fits                     IMAGE           NONE       FPA        TRUE      NONE
     
    278283PPSTACK.OUTPUT.VARIANCE.COMP OUTPUT {OUTPUT}.wt.fits                  VARIANCE        COMP_WT    FPA        TRUE      NONE
    279284PPSTACK.OUTPUT.VARIANCE.NOCOMP OUTPUT {OUTPUT}.wt.fits                VARIANCE        NONE       FPA        TRUE      NONE
     285
    280286PPSTACK.OUTPUT.EXP           OUTPUT {OUTPUT}.exp.fits                 IMAGE           EXP        FPA        TRUE      NONE
    281287PPSTACK.OUTPUT.EXPNUM        OUTPUT {OUTPUT}.num.fits                 MASK            EXPNUM     FPA        TRUE      NONE
  • branches/czw_branch/20101203/ippconfig/recipes/nightly_science.config

    r30048 r30118  
    8282  NAME      STR  MD02
    8383  DISTRIBUTION STR MD02
    84   TESS      STR MD02
     84  TESS      STR MD02.V2
    8585  OBSMODE   STR MD
    8686  OBJECT    STR MD02%
     
    104104  NAME      STR MD04
    105105  DISTRIBUTION STR MD04
    106   TESS      STR MD04
     106  TESS      STR MD04.V2
    107107  OBSMODE   STR MD
    108108  OBJECT    STR MD04%
  • branches/czw_branch/20101203/ippconfig/recipes/ppImage.config

    r28043 r30118  
    44
    55# List of tasks to perform
     6OVERSCAN           BOOL    TRUE            # Overscan subtraction
    67NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    7 OVERSCAN           BOOL    TRUE            # Overscan subtraction
    88NOISEMAP           BOOL    FALSE           # Apply read noise map
    99BIAS               BOOL    TRUE            # Bias subtraction
     
    162162  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    163163  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     164  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    164165  BIAS               BOOL    TRUE            # Bias subtraction
    165166  DARK               BOOL    TRUE            # Dark subtraction
     
    186187  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    187188  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     189  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    188190  BIAS               BOOL    TRUE            # Bias subtraction
    189191  DARK               BOOL    TRUE            # Dark subtraction
     
    209211  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    210212  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     213  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    211214  BIAS               BOOL    TRUE            # Bias subtraction
    212215  DARK               BOOL    TRUE            # Dark subtraction
     
    236239  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    237240  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     241  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    238242  BIAS             BOOL    FALSE           # Bias subtraction
    239243  DARK             BOOL    FALSE           # Dark subtraction
     
    260264  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    261265  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     266  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    262267  BIAS             BOOL    FALSE           # Bias subtraction
    263268  DARK             BOOL    FALSE           # Dark subtraction
     
    283288  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    284289  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     290  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    285291  BIAS             BOOL    FALSE           # Bias subtraction
    286292  DARK             BOOL    FALSE           # Dark subtraction
     
    306312  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    307313  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     314  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    308315  BIAS               BOOL    FALSE           # Bias subtraction
    309316  DARK               BOOL    FALSE           # Dark subtraction
     
    329336  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    330337  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     338  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    331339  BIAS             BOOL    TRUE            # Bias subtraction
    332340  DARK             BOOL    FALSE           # Dark subtraction
     
    345353# Dark subtraction only
    346354PPIMAGE_D          METADATA
    347   BASE.FITS        BOOL    TRUE            # Save base detrended image?
    348   BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
    349   BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
    350   CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image?
    351   CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image?
    352   CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    353   OVERSCAN         BOOL    FALSE           # Overscan subtraction
    354   BIAS             BOOL    FALSE           # Bias subtraction
    355   DARK             BOOL    TRUE            # Dark subtraction
    356   SHUTTER          BOOL    FALSE           # Shutter correction
    357   FLAT             BOOL    FALSE           # Flat-field normalisation
    358   MASK             BOOL    FALSE           # Mask bad pixels
    359   MASK.BUILD       BOOL    FALSE           # Build internal mask?
    360   FRINGE           BOOL    FALSE           # Fringe subtraction
    361   PHOTOM           BOOL    FALSE           # Source identification and photometry
    362   ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
    363   ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
    364   BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
    365   BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
     355  BASE.FITS          BOOL    TRUE            # Save base detrended image?
     356  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
     357  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
     358  CHIP.FITS          BOOL    FALSE           # Save chip-mosaic-ed image?
     359  CHIP.MASK.FITS     BOOL    FALSE           # Save chip-mosaic-ed image?
     360  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
     361  OVERSCAN           BOOL    FALSE           # Overscan subtraction
     362  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
     363  BIAS               BOOL    FALSE           # Bias subtraction
     364  DARK               BOOL    TRUE            # Dark subtraction
     365  SHUTTER            BOOL    FALSE           # Shutter correction
     366  FLAT               BOOL    FALSE           # Flat-field normalisation
     367  MASK               BOOL    FALSE           # Mask bad pixels
     368  MASK.BUILD         BOOL    FALSE         # Build internal mask?
     369  FRINGE             BOOL    FALSE           # Fringe subtraction
     370  PHOTOM             BOOL    FALSE           # Source identification and photometry
     371  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
     372  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
     373  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
     374  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
    366375END
    367376
     
    375384  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    376385  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     386  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    377387  BIAS             BOOL    FALSE           # Bias subtraction
    378388  DARK             BOOL    FALSE           # Dark subtraction
     
    398408  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    399409  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     410  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    400411  BIAS             BOOL    FALSE           # Bias subtraction
    401412  DARK             BOOL    FALSE           # Dark subtraction
     
    421432  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    422433  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     434  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    423435  BIAS             BOOL    FALSE           # Bias subtraction
    424436  DARK             BOOL    FALSE           # Dark subtraction
     
    444456  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    445457  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     458  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    446459  BIAS             BOOL    FALSE           # Bias subtraction
    447460  DARK             BOOL    FALSE           # Dark subtraction
     
    467480  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    468481  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     482  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    469483  BIAS             BOOL    FALSE           # Bias subtraction
    470484  DARK             BOOL    FALSE           # Dark subtraction
     
    490504  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    491505  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     506  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    492507  BIAS             BOOL    FALSE           # Bias subtraction
    493508  DARK             BOOL    FALSE           # Dark subtraction
     
    513528  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    514529  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     530  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    515531  BIAS             BOOL    TRUE            # Bias subtraction
    516532  DARK             BOOL    FALSE           # Dark subtraction
     
    536552  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    537553  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     554  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    538555  BIAS             BOOL    TRUE            # Bias subtraction
    539556  DARK             BOOL    TRUE            # Dark subtraction
     
    559576  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    560577  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     578  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    561579  BIAS             BOOL    TRUE            # Bias subtraction
    562580  DARK             BOOL    TRUE            # Dark subtraction
     
    589607  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    590608  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     609  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    591610  BIAS               BOOL    TRUE            # Bias subtraction
    592611  DARK               BOOL    TRUE            # Dark subtraction
     
    619638  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    620639  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     640  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    621641  BIAS               BOOL    TRUE            # Bias subtraction
    622642  DARK               BOOL    TRUE            # Dark subtraction
     
    642662  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    643663  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     664  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    644665  BIAS               BOOL    TRUE            # Bias subtraction
    645666  DARK               BOOL    TRUE            # Dark subtraction
     
    672693  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    673694  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     695  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    674696  BIAS             BOOL    TRUE            # Bias subtraction
    675697  DARK             BOOL    TRUE            # Dark subtraction
     
    695717  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    696718  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     719  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    697720  BIAS             BOOL    TRUE            # Bias subtraction
    698721  DARK             BOOL    TRUE            # Dark subtraction
     
    729752  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    730753  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     754  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    731755  BIAS             BOOL    TRUE            # Bias subtraction
    732756  DARK             BOOL    TRUE            # Dark subtraction
     
    752776  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    753777  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     778  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    754779  BIAS             BOOL    TRUE            # Bias subtraction
    755780  DARK             BOOL    TRUE            # Dark subtraction
     
    775800  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    776801  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     802  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    777803  BIAS             BOOL    TRUE            # Bias subtraction
    778804  DARK             BOOL    TRUE            # Dark subtraction
     
    798824  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    799825  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     826  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    800827  BIAS             BOOL    TRUE            # Bias subtraction
    801828  DARK             BOOL    TRUE            # Dark subtraction
     
    827854  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    828855  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     856  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    829857  BIAS             BOOL    TRUE            # Bias subtraction
    830858  DARK             BOOL    TRUE            # Dark subtraction
     
    856884  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    857885  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     886  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    858887  BIAS             BOOL    TRUE            # Bias subtraction
    859888  DARK             BOOL    TRUE            # Dark subtraction
     
    879908  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image?
    880909  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     910  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    881911  BIAS             BOOL    FALSE           # Bias subtraction
    882912  DARK             BOOL    FALSE           # Dark subtraction
     
    896926PPIMAGE_JPEG       METADATA
    897927  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     928  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    898929  BIAS             BOOL    FALSE           # Bias subtraction
    899930  DARK             BOOL    FALSE           # Dark subtraction
     
    916947  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
    917948  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
     949  MASK.SATURATED   BOOL    FALSE           # DO NOT Mask the saturated pixels
     950  MASK.LOW         BOOL    FALSE           # DO NOT Mask the saturated pixels
    918951END
    919952
     
    921954PPIMAGE_J1         METADATA
    922955  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     956  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    923957  BIAS             BOOL    FALSE           # Bias subtraction
    924958  DARK             BOOL    FALSE           # Dark subtraction
     
    945979  BIN2.XBIN        S32     1               # Image is already binned
    946980  BIN2.YBIN        S32     1               # Image is already binned
     981  MASK.SATURATED   BOOL    FALSE           # DO NOT Mask the saturated pixels
     982  MASK.LOW         BOOL    FALSE           # DO NOT Mask the saturated pixels
    947983END
    948984
     
    950986PPIMAGE_J2         METADATA
    951987  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     988  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    952989  BIAS             BOOL    FALSE           # Bias subtraction
    953990  DARK             BOOL    FALSE           # Dark subtraction
     
    9741011  BIN2.XBIN        S32     1               # Image is already binned
    9751012  BIN2.YBIN        S32     1               # Image is already binned
     1013  MASK.SATURATED   BOOL    FALSE           # DO NOT Mask the saturated pixels
     1014  MASK.LOW         BOOL    FALSE           # DO NOT Mask the saturated pixels
    9761015END
    9771016
     
    9791018PPIMAGE_OA         METADATA
    9801019  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1020  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    9811021  BIAS             BOOL    FALSE           # Bias subtraction
    9821022  DARK             BOOL    FALSE           # Dark subtraction
     
    9981038PPIMAGE_OP         METADATA
    9991039  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1040  NONLIN           BOOL    FALSE           # Non-linearity correction; not implemented
    10001041  BIAS             BOOL    FALSE           # Bias subtraction
    10011042  DARK             BOOL    FALSE           # Dark subtraction
     
    10231064  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    10241065  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1066  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    10251067  BIAS             BOOL    FALSE           # Bias subtraction
    10261068  DARK             BOOL    FALSE           # Dark subtraction
     
    10431085PPIMAGE_J1_RESID_B      METADATA
    10441086  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1087  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    10451088  BIAS             BOOL    FALSE           # Bias subtraction
    10461089  DARK             BOOL    FALSE           # Dark subtraction
     
    10791122PPIMAGE_J2_RESID_B        METADATA
    10801123  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1124  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    10811125  BIAS             BOOL    FALSE           # Bias subtraction
    10821126  DARK             BOOL    FALSE           # Dark subtraction
     
    11151159PPIMAGE_J1_RESID_F      METADATA
    11161160  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1161  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    11171162  BIAS             BOOL    FALSE           # Bias subtraction
    11181163  DARK             BOOL    FALSE           # Dark subtraction
     
    11511196PPIMAGE_J2_RESID_F        METADATA
    11521197  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1198  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    11531199  BIAS             BOOL    FALSE           # Bias subtraction
    11541200  DARK             BOOL    FALSE           # Dark subtraction
     
    11871233PPIMAGE_J1_RESID_R      METADATA
    11881234  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1235  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    11891236  BIAS             BOOL    FALSE           # Bias subtraction
    11901237  DARK             BOOL    FALSE           # Dark subtraction
     
    12231270PPIMAGE_J2_RESID_R        METADATA
    12241271  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1272  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    12251273  BIAS             BOOL    FALSE           # Bias subtraction
    12261274  DARK             BOOL    FALSE           # Dark subtraction
     
    12601308PPIMAGE_J1_IMAGE_B      METADATA
    12611309  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1310  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    12621311  BIAS             BOOL    FALSE           # Bias subtraction
    12631312  DARK             BOOL    FALSE           # Dark subtraction
     
    12961345PPIMAGE_J2_IMAGE_B        METADATA
    12971346  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1347  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    12981348  BIAS            BOOL    FALSE           # Bias subtraction
    12991349  DARK            BOOL    FALSE           # Dark subtraction
     
    13321382PPIMAGE_J1_IMAGE_F      METADATA
    13331383  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1384  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    13341385  BIAS            BOOL    FALSE           # Bias subtraction
    13351386  DARK            BOOL    FALSE           # Dark subtraction
     
    13681419PPIMAGE_J2_IMAGE_F        METADATA
    13691420  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1421  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    13701422  BIAS            BOOL    FALSE           # Bias subtraction
    13711423  DARK            BOOL    FALSE           # Dark subtraction
     
    14041456PPIMAGE_J1_IMAGE_R      METADATA
    14051457  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1458  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    14061459  BIAS            BOOL    FALSE           # Bias subtraction
    14071460  DARK            BOOL    FALSE           # Dark subtraction
     
    14401493PPIMAGE_J2_IMAGE_R        METADATA
    14411494  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1495  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    14421496  BIAS            BOOL    FALSE           # Bias subtraction
    14431497  DARK            BOOL    FALSE           # Dark subtraction
     
    14761530PPIMAGE_J1_IMAGE_M        METADATA
    14771531  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1532  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    14781533  BIAS            BOOL    FALSE           # Bias subtraction
    14791534  DARK            BOOL    FALSE           # Dark subtraction
     
    15121567PPIMAGE_J2_IMAGE_M        METADATA
    15131568  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1569  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    15141570  BIAS            BOOL    FALSE           # Bias subtraction
    15151571  DARK            BOOL    FALSE           # Dark subtraction
     
    15481604PPIMAGE_J1_RESID_M        METADATA
    15491605  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1606  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    15501607  BIAS            BOOL    FALSE           # Bias subtraction
    15511608  DARK            BOOL    FALSE           # Dark subtraction
     
    15841641PPIMAGE_J2_RESID_M        METADATA
    15851642  OVERSCAN        BOOL    FALSE           # Overscan subtraction
     1643  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    15861644  BIAS            BOOL    FALSE           # Bias subtraction
    15871645  DARK            BOOL    FALSE           # Dark subtraction
     
    16211679PPIMAGE_MOSAIC     METADATA
    16221680  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1681  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    16231682  BIAS             BOOL    FALSE           # Bias subtraction
    16241683  DARK             BOOL    FALSE           # Dark subtraction
     
    16521711PPIMAGE_CHIPMOSAIC     METADATA
    16531712  OVERSCAN         BOOL    FALSE           # Overscan subtraction
     1713  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    16541714  BIAS             BOOL    FALSE           # Bias subtraction
    16551715  DARK             BOOL    FALSE           # Dark subtraction
     
    16881748  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image?
    16891749  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image?
    1690   OVERSCAN         BOOL    FALSE           # Overscan subtraction
    16911750  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1751  NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
    16921752  BIAS             BOOL    TRUE            # Bias subtraction
    16931753  DARK             BOOL    TRUE            # Dark subtraction
     
    17321792  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    17331793  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1794  NONLIN             BOOL    FALSE           # Overscan subtraction
    17341795  BIAS               BOOL    TRUE            # Bias subtraction
    17351796  DARK               BOOL    TRUE            # Dark subtraction
     
    17621823  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    17631824  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1825  NONLIN             BOOL    FALSE           # Overscan subtraction
    17641826  BIAS               BOOL    TRUE            # Bias subtraction
    17651827  DARK               BOOL    TRUE            # Dark subtraction
     
    17851847  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    17861848  OVERSCAN         BOOL    TRUE            # Overscan subtraction
     1849  NONLIN             BOOL    FALSE           # Overscan subtraction
    17871850  BIAS             BOOL    FALSE           # Bias subtraction
    17881851  DARK             BOOL    TRUE            # Dark subtraction
     
    18131876  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    18141877  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1878  NONLIN             BOOL    FALSE           # Overscan subtraction
    18151879  BIAS               BOOL    TRUE            # Bias subtraction
    18161880  DARK               BOOL    TRUE            # Dark subtraction
     
    18401904  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    18411905  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1906  NONLIN             BOOL    FALSE           # Overscan subtraction
    18421907  BIAS               BOOL    TRUE            # Bias subtraction
    18431908  DARK               BOOL    TRUE            # Dark subtraction
     
    18651930  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image?
    18661931  OVERSCAN           BOOL    TRUE            # Overscan subtraction
     1932  NONLIN             BOOL    FALSE           # Overscan subtraction
    18671933  BIAS               BOOL    TRUE            # Bias subtraction
    18681934  DARK               BOOL    TRUE            # Dark subtraction
  • branches/czw_branch/20101203/ippconfig/recipes/ppSub.config

    r29617 r30118  
    7272PHOTOMETRY      BOOL    FALSE           # Perform photometry?
    7373
     74FORCED.PHOTOMETRY.BOTH BOOL FALSE       # forced photometry on input sources?
     75FORCED.PHOTOMETRY.INPUT1 BOOL FALSE       # forced photometry on input sources?
     76FORCED.PHOTOMETRY.INPUT2 BOOL FALSE       # forced photometry on input sources?
    7477
    7578# Recipe overrides for STACK
     
    112115        PHOTOMETRY      BOOL    TRUE    # Perform photometry?
    113116        CONVOLVE.TARGET STR     SINGLE2 # convolution direction
     117END
     118
     119# Difference of warp - stack
     120WARPSTACK_FORCED     METADATA
     121        DUAL            BOOL    FALSE   # Dual convolution?
     122        INVERSE         BOOL    FALSE   # Generate inverse subtraction?
     123        PHOTOMETRY      BOOL    TRUE    # Perform photometry?
     124        CONVOLVE.TARGET STR     SINGLE2 # convolution direction
     125 FORCED.PHOTOMETRY.BOTH BOOL    TRUE    # forced photometry on input sources
    114126END
    115127
  • branches/czw_branch/20101203/ippconfig/recipes/psastro.config

    r28641 r30118  
    238238MOPS.TEST       METADATA
    239239END
     240
     241SAS_REFERENCE METADATA
     242END
     243
  • branches/czw_branch/20101203/ippconfig/recipes/psphot.config

    r29609 r30118  
    4949PEAKS_NMAX                          S32   5000            # on first pass, only keep NMAX peaks (0 == all)
    5050PEAKS_MIN_GAUSS                     F32   0.5             # On quick convolution, mask pixels for which the
     51PEAKS_POS2_NSIGMA_LIMIT             F32   25.0            # peak signficance threshold for POS2 sources. (ppSub)
    5152                                                          # input pixels contribute less than this fraction of the flux
    5253# parameters which adjust the footprint analysis
  • branches/czw_branch/20101203/ippconfig/recipes/reductionClasses.mdc

    r29766 r30118  
    173173WARPSTACK       METADATA
    174174        DIFF_PPSUB      STR     WARPSTACK
     175        DIFF_PSPHOT     STR     DIFF
     176        JPEG_BIN1       STR     PPIMAGE_J1
     177        JPEG_BIN2       STR     PPIMAGE_J2
     178END
     179
     180# reduction class specifically for warpstack diffs:
     181WARPSTACK_FORCED        METADATA
     182        DIFF_PPSUB      STR     WARPSTACK_FORCED
    175183        DIFF_PSPHOT     STR     DIFF
    176184        JPEG_BIN1       STR     PPIMAGE_J1
     
    535543END
    536544
     545SAS_REFERENCE METADATA
     546   CHIP_PPIMAGE    STR CHIP
     547   CHIP_PSPHOT STR CHIP
     548   WARP_PSWARP STR WARP
     549   STACK_PPSTACK   STR STACK
     550   STACK_PPSUB STR STACK
     551   STACK_PSPHOT    STR STACK
     552   DIFF_PPSUB  STR DIFF
     553   DIFF_PSPHOT STR DIFF
     554   JPEG_BIN1   STR PPIMAGE_J1
     555   JPEG_BIN2   STR PPIMAGE_J2
     556   FAKEPHOT    STR FAKEPHOT
     557   ADDSTAR     STR ADDSTAR
     558   PSASTRO     STR SAS_REFERENCE
     559   STACKPHOT       STR     STACKPHOT
     560END
     561
  • branches/czw_branch/20101203/ippconfig/simtest/camera.config

    r29902 r30118  
    8080
    8181# don't censor any masked pixels when making postage stamps
     82# MASK.NO.CENSOR               U32 0xFFFFFFFF -- need to fix the MDC parser(s) to handle hex values
    8283MASK.NO.CENSOR               U32 4294967295
  • branches/czw_branch/20101203/pedestal/src/pedestal.c

    r15639 r30118  
    2929    psFitsMoveExtName(inFile, extname);
    3030    psArray *cube = psFitsReadImageCube(inFile, psRegionSet(0, 0, 0, 0)); // Image cube
     31    assert(cube);
    3132    assert(cube->n == 2);               // We checked NAXIS3 earlier
    3233
  • branches/czw_branch/20101203/ppConfigDump/src/ppConfigDump.c

    r24187 r30118  
    2626void dump(const char *filename,     // Filename to which to dump
    2727          const char *description,  // Description of what's being dumped
    28           psMetadata *md            // Metadata to dump
    29           )
     28          psMetadata *md,           // Metadata to dump
     29          const char *compressMode
     30    )
    3031{
    3132    if (!filename || strlen(filename) == 0) {
     
    3839            die(PS_EXIT_SYS_ERROR);
    3940        }
    40         fprintf(stdout, "%s", string);
     41
     42        if (compressMode) {
     43            if (strlen(compressMode) > 2) {
     44                psErrorStackPrint(stderr, "invalid compression options %s!\n", compressMode);
     45                die(PS_EXIT_CONFIG_ERROR);
     46            }
     47            char modeString[4];
     48            snprintf (modeString, 4, "w%s", compressMode);
     49
     50            gzFile file = gzdopen (STDOUT_FILENO, modeString);
     51            if (file == Z_NULL) {
     52                psErrorStackPrint(stderr, "Failed to open file\n");
     53                die(PS_EXIT_SYS_ERROR);
     54            }
     55            int nbytes = gzwrite (file, string, strlen(string));
     56            if (nbytes != strlen(string)) {
     57                psErrorStackPrint(stderr, "Failed to write contents of configuration file %s", filename);
     58                psFree(string);
     59                gzclose(file);
     60                die(PS_EXIT_SYS_ERROR);
     61            }
     62            psFree(string);
     63            if (gzclose(file) != Z_OK) {
     64                psErrorStackPrint(stderr, "Failed to close file, %s\n", filename);
     65                die(PS_EXIT_SYS_ERROR);
     66            }
     67        } else {
     68            fprintf(stdout, "%s", string);
     69        }
    4170        psFree(string);
    42     } else if (!psMetadataConfigWrite(md, filename)) {
    43         psErrorStackPrint(stderr, "Can't write %s to %s\n", description, filename);
    44         die(PS_EXIT_SYS_ERROR);
     71    } else {
     72        if (!psMetadataConfigWrite(md, filename, compressMode)) {
     73            psErrorStackPrint(stderr, "Can't write %s to %s\n", description, filename);
     74            die(PS_EXIT_SYS_ERROR);
     75        }
    4576    }
    4677}
     
    6293    arguments = psMetadataAlloc();
    6394    psMetadataAddStr(arguments, PS_LIST_TAIL, "-file", 0, "FITS file to use for camera determination", NULL);
     95    psMetadataAddStr(arguments, PS_LIST_TAIL, "-compress", 0, "output compression mode", NULL);
     96    psMetadataAddBool(arguments, PS_LIST_TAIL, "-z", 0, "default compression", false);
    6497    psMetadataAddStr(arguments, PS_LIST_TAIL, "-dump-user", 0, "Filename for user configuration", NULL);
    6598    psMetadataAddStr(arguments, PS_LIST_TAIL, "-dump-site", 0, "Filename for site configuration", NULL);
     
    84117        psArgumentHelp(arguments);
    85118        die(PS_EXIT_CONFIG_ERROR);
     119    }
     120
     121    const char *defaultCompressMode = "7f";
     122    const char *compressMode = psMetadataLookupStr(NULL, arguments, "-compress"); // compression
     123    bool defaultCompression = psMetadataLookupBool(NULL, arguments, "-z"); // compression?
     124    if (!compressMode && defaultCompression) {
     125        compressMode = defaultCompressMode;
    86126    }
    87127
     
    122162
    123163    const char *userName = psMetadataLookupStr(NULL, arguments, "-dump-user"); // User filename
    124     dump(userName, "user configuration", config->user);
     164    dump(userName, "user configuration", config->user, compressMode);
    125165
    126166    const char *siteName = psMetadataLookupStr(NULL, arguments, "-dump-site"); // Site filename
    127     dump(siteName, "site configuration", config->site);
     167    dump(siteName, "site configuration", config->site, compressMode);
    128168
    129169    const char *systemName = psMetadataLookupStr(NULL, arguments, "-dump-system"); // System filename
    130     dump(systemName, "system configuration", config->system);
     170    dump(systemName, "system configuration", config->system, compressMode);
    131171
    132172    const char *camName = psMetadataLookupStr(NULL, arguments, "-dump-camera"); // Camera filename
    133     dump(camName, "camera configuration", config->camera);
     173    dump(camName, "camera configuration", config->camera, compressMode);
    134174
    135175    const char *formatName = psMetadataLookupStr(NULL, arguments, "-dump-format"); // Format filename
    136     dump(formatName, "camera format", config->format);
     176    dump(formatName, "camera format", config->format, compressMode);
    137177
    138178    const char *recipesName = psMetadataLookupStr(NULL, arguments, "-dump-recipes"); // Recipes filename
    139     dump(recipesName, "recipes", config->recipes);
     179    dump(recipesName, "recipes", config->recipes, compressMode);
    140180
    141181    recipeArgs = psMetadataLookupMetadata(NULL, arguments, "-dump-recipe");
     
    148188        }
    149189        const char *recipeFile = psMetadataLookupStr(NULL, recipeArgs, "filename"); // Filename for recipe
    150         dump(recipeFile, "recipe", recipe);
     190        dump(recipeFile, "recipe", recipe, compressMode);
    151191    }
    152192
  • branches/czw_branch/20101203/ppImage/src/ppImageDetrendReadout.c

    r29833 r30118  
    6262    // Non-linearity correction
    6363    if (options->doNonLin) {
    64       //      linearity = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.LINEARITY");
    6564      if (!ppImageDetrendNonLinear(input,detview,config)) {
    6665        psError(PS_ERR_UNKNOWN, false, "Unable to correct NonLinearity");
     
    6867        return(false);
    6968      }
    70       /*       ppImageDetrendNonLinear(detrend->input, input, options); */
    7169    }
    7270
  • branches/czw_branch/20101203/ppImage/src/ppImageOptions.c

    r29833 r30118  
    216216
    217217    // for these images, even if not required otherwise
    218     options->doMaskBuild = psMetadataLookupBool(NULL, recipe, "MASK.BUILD");
    219     options->doMaskSat   = psMetadataLookupBool(NULL, recipe, "MASK.SATURATED");
    220     options->doMaskLow   = psMetadataLookupBool(NULL, recipe, "MASK.LOW");
    221     options->doMaskBurntool = psMetadataLookupBool(NULL, recipe, "MASK.BURNTOOL");
     218    options->doMaskBuild     = psMetadataLookupBool(NULL, recipe, "MASK.BUILD");
     219    options->doMaskSat       = psMetadataLookupBool(NULL, recipe, "MASK.SATURATED");
     220    options->doMaskLow       = psMetadataLookupBool(NULL, recipe, "MASK.LOW");
     221    options->doMaskBurntool  = psMetadataLookupBool(NULL, recipe, "MASK.BURNTOOL");
    222222    options->doVarianceBuild = psMetadataLookupBool(NULL, recipe, "VARIANCE.BUILD");
    223223
     
    301301    options->checkCTE       = psMetadataLookupBool(NULL, recipe, "CHECK.CTE");
    302302
    303     // even if not requested explicitly, if any of these are set, build an internal mask and variance:
    304     if (options->doNoiseMap || options->doBias || options->doOverscan || options->doDark || options->doShutter || options->doFlat ||
    305         options->doPhotom) {
     303    /* doMaskBuild : there are some cases where we require a mask, so we force doMaskBuild to be set even if the user specified 'FALSE'
     304     *
     305     * doPhotom : a mask is required because it is used to mark the locations of stars
     306     *
     307     * doNoiseMap : no reason this needs to trigger a mask?
     308     * doBias : no reason this needs to trigger a mask?
     309     * doOverscan : no reason this needs to trigger a mask?
     310     * doDark : no reason this needs to trigger a mask?
     311     * doShutter : no reason this needs to trigger a mask?
     312     * doFlat : no reason this needs to trigger a mask?
     313     */
     314
     315    // if the variance image is requested, build it (if not supplied)
     316    if (options->BaseVarianceFITS || options->ChipVarianceFITS) {
     317        options->doVarianceBuild = true;
     318    }
     319    // photometry and noisemap both require a variance image
     320    if (options->doNoiseMap || options->doPhotom) {
     321        options->doVarianceBuild = true;
     322    }
     323
     324    // we need a mask if we are going to apply these things:
     325    if (options->doMaskSat || options->doMaskLow || options->doMaskBurntool || options->doMaskStats) {
    306326        options->doMaskBuild = true;
    307         options->doVarianceBuild = true;
    308     } else if (options->doMask || options->doBG) {
     327    }
     328    // photometry, mask, and background all require a mask image
     329    if (options->doMask || options->doBG || options->doPhotom) {
    309330        options->doMaskBuild = true;
    310331    }
  • branches/czw_branch/20101203/ppImage/src/ppImagePhotom.c

    r28375 r30118  
    1111    pmCell *cell;
    1212    pmReadout *readout;
    13     printf("%x %s\n",psErrorCodeLast(),psErrorCodeString(psErrorCodeLast()));
     13
    1414    psphotInit();
    15     printf("%x %s\n",psErrorCodeLast(),psErrorCodeString(psErrorCodeLast()));
     15
    1616    // find or define a pmFPAfile PSPHOT.INPUT
    1717    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
     
    2020        return false;
    2121    }
    22     printf("%x %s\n",psErrorCodeLast(),psErrorCodeString(psErrorCodeLast()));
     22
    2323    // we make a new copy of the output chip to keep psphot from modifying the output image
    2424    pmChip *oldChip = pmFPAviewThisChip (view, input->src);
    2525    pmChip *newChip = pmFPAviewThisChip (view, input->fpa);
    2626    pmChipCopy (newChip, oldChip);
    27     printf("%x %s\n",psErrorCodeLast(),psErrorCodeString(psErrorCodeLast()));
     27
    2828    // iterate over the cells and readout for this chip
    2929    while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     
    3434        while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
    3535            if (! readout->data_exists) { continue; }
    36             printf("%x %s\n",psErrorCodeLast(),psErrorCodeString(psErrorCodeLast()));
     36
    3737            // run the actual photometry analysis
    38             if (!psphotReadout (config, view)) {
     38            if (!psphotReadout (config, view, "PSPHOT.INPUT")) {
    3939                // This is likely a data quality issue
    4040                // XXX Split into multiple cases using error codes?
     
    6060    ppImageMemoryDump("photom");
    6161
    62     // the PSPHOT.INPUT file is a temporary file used to carry PPIMAGE.CHIP to psphotReadout
    63     // XXX not sure that this is needed...
    64 //    pmFPAfileActivate (config->files, false, "PSPHOT.INPUT");
    65 
    6662    return true;
    6763}
    68 
    69 // XXX do we need to deactivate all files and activate the psphot ones explicitly?
  • branches/czw_branch/20101203/ppImage/src/ppImageStatsOutput.c

    r27064 r30118  
    2828        return false;
    2929    }
    30     if (!psMetadataConfigWrite(stats, resolved)) {
     30
     31    // check for Metadata compression options:
     32    char *compressMode = NULL;
     33    bool status = false;
     34    if (config->camera) {
     35        // XXX use a different config variable for this output?
     36        compressMode = psMetadataLookupStr(&status, config->camera, "METADATA.COMPRESSION");
     37    }
     38
     39    if (!psMetadataConfigWrite(stats, resolved, compressMode)) {
    3140        psError(psErrorCodeLast(), false, "Unable to serialize stats metadata.\n");
    3241        psFree(resolved);
  • branches/czw_branch/20101203/ppStack/src/ppStackPhotometry.c

    r27343 r30118  
    5454    psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
    5555    psImageMaskType markValue = pmConfigMaskGet("MARK.VALUE", config); // Bits to use for marking
    56     psMetadataAddImageMask(psphot, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE,
    57                             "Bits to mask", maskValue);
    58     psMetadataAddImageMask(psphot, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE,
    59                            "Bits to use for mark", markValue);
     56    psMetadataAddImageMask(psphot, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "Bits to mask", maskValue);
     57    psMetadataAddImageMask(psphot, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "Bits to use for mark", markValue);
    6058
    6159    psArray *inSources = options->sources;
     
    6765
    6866    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX);
    69     if (!psphotReadoutKnownSources(config, photView, inSources)) {
     67    if (!psphotReadoutKnownSources(config, photView, "PSPHOT.INPUT", inSources)) {
    7068        // This is likely a data quality issue
    7169        // XXX Split into multiple cases using error codes?
  • branches/czw_branch/20101203/ppSub/src/Makefile.am

    r29003 r30118  
    3838        ppSubLoop.c                     \
    3939        ppSubDefineOutput.c             \
     40        ppSubInputDetections.c          \
    4041        ppSubExtras.c                   \
    4142        ppSubFlagNeighbors.c            \
     
    4647        ppSubReadoutJpeg.c              \
    4748        ppSubReadoutPhotometry.c        \
     49        ppSubReadoutForcedPhot.c        \
    4850        ppSubReadoutStats.c             \
    4951        ppSubReadoutSubtract.c          \
  • branches/czw_branch/20101203/ppSub/src/ppSub.h

    r29003 r30118  
    4545    bool photometry;                    // Perform photometry?
    4646    bool inverse;                       // Output inverse subtraction as well?
     47    bool forcedPhot1;                   // perform forced photometry?
     48    bool forcedPhot2;                   // perform forced photometry?
    4749    bool saveInConv;                    // Save convolved input?
    4850    bool saveRefConv;                   // Save convolved reference?
     
    105107                            ppSubData *data ///< Processing data
    106108    );
     109
     110bool ppSubInputDetections (bool *foundDetections, const char *sourcesName, const char *imageName, ppSubData *data);
     111bool ppSubReadoutForcedPhot(const char *outputName, const char *targetName, const char *sourceName, ppSubData *data);
     112bool psphotCopyResults (bool *foundDetections, pmFPAfile *target, pmFPAfile *source, pmFPAview *view);
    107113
    108114/// Higher-order background subtraction
  • branches/czw_branch/20101203/ppSub/src/ppSubArguments.c

    r27596 r30118  
    8686    psMetadataAddS32(arguments, PS_LIST_TAIL, "-convolve", 0, "Image to convolve [1 or 2]", 0);
    8787    psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", NULL);
     88    psMetadataAddBool(arguments, PS_LIST_TAIL, "-forced-phot", 0, "Perform forced photometry?", NULL);
     89    psMetadataAddBool(arguments, PS_LIST_TAIL, "-forced-input1", 0, "Perform forced photometry?", NULL);
     90    psMetadataAddBool(arguments, PS_LIST_TAIL, "-forced-input2", 0, "Perform forced photometry?", NULL);
    8891    psMetadataAddF32(arguments, PS_LIST_TAIL, "-zp", 0, "Zero point for photometry", NAN);
    8992    psMetadataAddBool(arguments, PS_LIST_TAIL, "-inverse", 0, "Generate inverse subtractions?", false);
  • branches/czw_branch/20101203/ppSub/src/ppSubBackground.c

    r29003 r30118  
    3737    pmFPAview *view = ppSubViewReadout(); // View to readout
    3838    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image
    39     pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); // Background model
    4039
    41     // Generate the background model, if required
     40    // Generate the background model
     41    if (!psphotModelBackground(config, view, "PPSUB.OUTPUT")) {
     42      psError(psErrorCodeLast(), false, "Unable to model background");
     43      psFree(view);
     44      return false;
     45    }
     46
     47    // select the model readout (should now exist)
     48    pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
    4249    if (!modelRO) {
    43         // Create the background model
    44         if (!psphotModelBackgroundReadoutFileIndex(config, view, "PPSUB.OUTPUT", 0)) {
    45             psError(psErrorCodeLast(), false, "Unable to model background");
    46             psFree(view);
    47             return false;
    48         }
    49         // select the model readout (should now exist)
    50         modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
    51         if (!modelRO) {
    52             psError(psErrorCodeLast(), false, "Unable to find background model");
    53             psFree(view);
    54             return false;
    55         }
     50      psError(psErrorCodeLast(), false, "Unable to find background model");
     51      psFree(view);
     52      return false;
    5653    }
    5754    psFree(view);
    5855
    59     psImageBinning *binning = psMetadataLookupPtr(&mdok, modelRO->analysis,
    60                                                   "PSPHOT.BACKGROUND.BINNING"); // Binning for model
     56    psImageBinning *binning = psMetadataLookupPtr(&mdok, modelRO->analysis, "PSPHOT.BACKGROUND.BINNING"); // Binning for model
    6157    psImage *modelImage = modelRO->image; // Background model
    6258    psImage *image = outRO->image; // Image of interest
     
    8379    }
    8480
    85     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
    86     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
    87 
    8881    return true;
    8982}
  • branches/czw_branch/20101203/ppSub/src/ppSubCamera.c

    r27661 r30118  
    221221                          "Generate inverse subtractions?", true);
    222222    }
    223 
    224     data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE");
    225     data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
     223    if (psMetadataLookupBool(NULL, config->arguments, "-forced-phot")) {
     224        psMetadataAddBool(recipe, PS_LIST_TAIL, "FORCED.PHOTOMETRY.BOTH", PS_META_REPLACE, "Perform forced photometry?", true);
     225    }
     226    if (psMetadataLookupBool(NULL, config->arguments, "-forced-input1")) {
     227        psMetadataAddBool(recipe, PS_LIST_TAIL, "FORCED.PHOTOMETRY.INPUT1", PS_META_REPLACE, "Perform forced photometry?", true);
     228    }
     229    if (psMetadataLookupBool(NULL, config->arguments, "-forced-input2")) {
     230        psMetadataAddBool(recipe, PS_LIST_TAIL, "FORCED.PHOTOMETRY.INPUT2", PS_META_REPLACE, "Perform forced photometry?", true);
     231    }
     232
     233    data->inverse     = psMetadataLookupBool(NULL, recipe, "INVERSE");
     234    data->photometry  = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
     235    data->forcedPhot1 = psMetadataLookupBool(NULL, recipe, "FORCED.PHOTOMETRY.BOTH") || psMetadataLookupBool(NULL, recipe, "FORCED.PHOTOMETRY.INPUT1");
     236    data->forcedPhot2 = psMetadataLookupBool(NULL, recipe, "FORCED.PHOTOMETRY.BOTH") || psMetadataLookupBool(NULL, recipe, "FORCED.PHOTOMETRY.INPUT2");
    226237
    227238    // Convolved input image
     
    363374            return false;
    364375        }
    365         // specify the number of psphot input images
    366         psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
    367376        pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
    368377
     
    405414            invSources->save = true;
    406415        }
     416
     417        // files need to do the forced photometry on the positions of sources in the positive images
     418        if (data->forcedPhot1) {
     419            // this pmFPAfile is used to carry sources detected in the positive image #1
     420            pmFPAfile *posSources1 = defineOutputFile(config, input, true, "PPSUB.POS1.SOURCES", PM_FPA_FILE_CMF);
     421            if (!posSources1) {
     422                psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
     423                return false;
     424            }
     425            posSources1->save = true;
     426
     427            // this pmFPAfile is used to carry sources detected in the diff image @ the positions from positive image #1
     428            pmFPAfile *frcSources1 = defineOutputFile(config, input, true, "PPSUB.FORCED1.SOURCES", PM_FPA_FILE_CMF);
     429            if (!frcSources1) {
     430                psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
     431                return false;
     432            }
     433            frcSources1->save = true;
     434        }
     435
     436        if (data->forcedPhot2) {
     437            // this pmFPAfile is used to carry sources detected in the positive image #2
     438            pmFPAfile *posSources2 = defineOutputFile(config, ref, true, "PPSUB.POS2.SOURCES", PM_FPA_FILE_CMF);
     439            if (!posSources2) {
     440                psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
     441                return false;
     442            }
     443            posSources2->save = true;
     444
     445            // this pmFPAfile is used to carry sources detected in the diff image @ the positions from positive image #2
     446            pmFPAfile *frcSources2 = defineOutputFile(config, ref, true, "PPSUB.FORCED2.SOURCES", PM_FPA_FILE_CMF);
     447            if (!frcSources2) {
     448                psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
     449                return false;
     450            }
     451            frcSources2->save = true;
     452        }
    407453    }
    408454
  • branches/czw_branch/20101203/ppSub/src/ppSubFlagNeighbors.c

    r29003 r30118  
    235235        src = sources->data[Imin];
    236236
    237         fprintf (stderr, "j: %d, Imin: %d, obj x,y: %f, %f  src x,y: %f, %f, SN: %f, ID: %d\n", j, Imin, obj->x, obj->y, src->peak->xf, src->peak->yf, src->peak->SN, src->id);
     237        // fprintf (stderr, "j: %d, Imin: %d, obj x,y: %f, %f  src x,y: %f, %f, SN: %f, ID: %d\n", j, Imin, obj->x, obj->y, src->peak->xf, src->peak->yf, src->peak->SN, src->id);
    238238
    239239        // add source to object
  • branches/czw_branch/20101203/ppSub/src/ppSubLoop.c

    r29003 r30118  
    3636    psAssert(config, "Require configuration.");
    3737
     38    bool success = true;
     39
    3840    pmConfigCamerasCull(config, NULL);
    3941    pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
     
    5759    }
    5860
     61    if (data->forcedPhot1) {
     62        bool foundDetections = false;
     63        if (!ppSubInputDetections(&foundDetections, "PPSUB.POS1.SOURCES", "PPSUB.INPUT", data)) {
     64            psError(psErrorCodeLast(), false, "Unable to measure positive detections (1)");
     65            success = false;
     66            goto ESCAPE;
     67        }
     68        // if nothing was found, don't bother doing the forced photometry below
     69        if (!foundDetections) {
     70            psWarning ("no sources found in positive image 1, skipping forced photometry");
     71            data->forcedPhot1 = false;
     72        }
     73    }
     74    if (data->forcedPhot2) {
     75        // Change the recipe to use a higher nsigma limit and quit after pass1
     76        psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
     77
     78        psF32 nsigma_peak_save = psMetadataLookupF32 (NULL, recipe, "PEAKS_NSIGMA_LIMIT");
     79        char *breakPt_save =  psMetadataLookupStr (NULL, recipe, "BREAK_POINT");
     80
     81        bool mdok;
     82        psF32 pos2_nsigma_peak = psMetadataLookupF32 (&mdok, recipe, "PEAKS_POS2_NSIGMA_LIMIT");
     83        if (!mdok) {
     84            psWarning("PEAKS_POS2_NSIGMA_LIMIT not found in recipe. Will use 25.\n");
     85            pos2_nsigma_peak = 25.;
     86        }
     87        psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", pos2_nsigma_peak);
     88        psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", "PASS1");
     89
     90        bool foundDetections = false;
     91        if (!ppSubInputDetections(&foundDetections, "PPSUB.POS2.SOURCES", "PPSUB.REF", data)) {
     92            psError(psErrorCodeLast(), false, "Unable to measure positive detections (2)");
     93            psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
     94            psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
     95            success = false;
     96            goto ESCAPE;
     97        }
     98        psMetadataAddF32(recipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
     99        psMetadataAddStr(recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
     100        // if nothing was found, don't bother doing the forced photometry below
     101        if (!foundDetections) {
     102            psWarning ("no sources found in positive image 2, skipping forced photometry");
     103            data->forcedPhot2 = false;
     104        }
     105    }
     106
     107    // XXX if it exists, use the POS1, POS2 successs for the FWHMs
    59108    if (!ppSubMatchPSFs(data)) {
    60109        psError(psErrorCodeLast(), false, "Unable to match PSFs.");
    61         return false;
     110        success = false;
     111        goto ESCAPE;
    62112    }
    63113    if (data->quality) {
    64114        // Can't do anything at all
    65         return true;
     115        success = false;
     116        goto ESCAPE;
    66117    }
    67118    // generate the residual stamp grid for visualization
    68119    if (!ppSubResidualSampleJpeg(config)) {
    69120        psError(psErrorCodeLast(), false, "Unable to update.");
    70         return false;
    71     }
     121        success = false;
     122        goto ESCAPE;
     123    }
     124
     125    // XXX add in a positive image detection step here (if needed)
     126   
    72127
    73128    psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
     
    77132    if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
    78133        psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    79         return false;
     134        success = false;
     135        goto ESCAPE;
    80136    }
    81137
    82138    if (!ppSubLowThreshold(data)) {
    83139        psError(psErrorCodeLast(), false, "Unable to threshold images.");
    84         return false;
     140        success = false;
     141        goto ESCAPE;
    85142    }
    86143
     
    88145    if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) {
    89146        psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files.");
    90         return false;
     147        success = false;
     148        goto ESCAPE;
    91149    }
    92150
    93151    if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
    94152        psError(psErrorCodeLast(), false, "Unable to define output.");
    95         return false;
     153        success = false;
     154        goto ESCAPE;
    96155    }
    97156
    98157    if (!data->quality && !ppSubMakePSF(data)) {
    99158        psError(psErrorCodeLast(), false, "Unable to generate PSF.");
    100         return false;
     159        success = false;
     160        goto ESCAPE;
    101161    }
    102162
     
    113173    if (!ppSubReadoutSubtract(config)) {
    114174        psError(psErrorCodeLast(), false, "Unable to subtract images.");
    115         return false;
     175        success = false;
     176        goto ESCAPE;
    116177    }
    117178    // dumpout(config, "diff.1.fits");
     
    120181    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) {
    121182        psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    122         return false;
     183        success = false;
     184        goto ESCAPE;
    123185    }
    124186    // dumpout(config, "diff.2a.fits");
     
    127189    if (!ppSubBackground(config)) {
    128190        psError(psErrorCodeLast(), false, "Unable to subtract background.");
    129         return false;
     191        success = false;
     192        goto ESCAPE;
    130193    }
    131194    // dumpout(config, "diff.2b.fits");
     
    134197    if (!ppSubVarianceRescale(config, data)) {
    135198        psError(psErrorCodeLast(), false, "Unable to rescale variance.");
    136         return false;
     199        success = false;
     200        goto ESCAPE;
    137201    }
    138202    // dumpout(config, "diff.2c.fits");
     
    140204    if (data->quality) {
    141205        // Done all we can do up to this point
    142         return true;
     206        success = false;
     207        goto ESCAPE;
    143208    }
    144209
    145210    if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) {
    146211        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
    147         return false;
     212        success = false;
     213        goto ESCAPE;
    148214    }
    149215
    150216    if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", data)) {
    151217        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    152         return false;
     218        success = false;
     219        goto ESCAPE;
    153220    }
    154221    // dumpout(config, "diff.3.fits");
     222
     223    // forced photometry for positive image 1
     224    if (data->forcedPhot1 && !data->quality) {
     225        if (!ppSubReadoutForcedPhot("PPSUB.FORCED1.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS1.SOURCES", data)) {
     226            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     227            success = false;
     228            goto ESCAPE;
     229        }
     230    }
     231
     232    // forced photometry for positive image 2
     233    if (data->forcedPhot2 && !data->quality) {
     234        if (!ppSubReadoutForcedPhot("PPSUB.FORCED2.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS2.SOURCES", data)) {
     235            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     236            success = false;
     237            goto ESCAPE;
     238        }
     239    }
    155240
    156241    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
    157242        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
    158         return false;
     243        success = false;
     244        goto ESCAPE;
    159245    }
    160246
     
    162248    if (!ppSubReadoutStats(data)) {
    163249        psError(psErrorCodeLast(), false, "Unable to collect statistics");
    164         return false;
     250        success = false;
     251        goto ESCAPE;
    165252    }
    166253    // Do Mask Stats
     
    169256      if (!ppSubMaskStats(config, view,data->stats)) {
    170257        psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
    171         return(false);
     258        success = false;
     259        goto ESCAPE;
    172260      }
    173261    }
     
    177265    if (!ppSubReadoutJpeg(config)) {
    178266        psError(psErrorCodeLast(), false, "Unable to update.");
    179         return false;
     267        success = false;
     268        goto ESCAPE;
    180269    }
    181270
     
    184273        if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) {
    185274            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
    186             return false;
     275            success = false;
     276            goto ESCAPE;
    187277        }
    188278
    189279        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
    190280            psError(psErrorCodeLast(), false, "Unable to define inverse.");
    191             return false;
     281            success = false;
     282            goto ESCAPE;
    192283        }
    193284
    194285        if (!ppSubReadoutInverse(config)) {
    195286            psError(psErrorCodeLast(), false, "Unable to invert images.");
    196             return false;
     287            success = false;
     288            goto ESCAPE;
    197289        }
    198290
     
    200292        if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
    201293            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    202             return false;
     294            success = false;
     295            goto ESCAPE;
    203296        }
    204297
    205298        if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) {
    206299            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
    207             return false;
     300            success = false;
     301            goto ESCAPE;
    208302        }
    209303
    210304        if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", data)) {
    211305            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    212             return false;
     306            success = false;
     307            goto ESCAPE;
    213308        }
    214309
     
    216311        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) {
    217312            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    218             return false;
     313            success = false;
     314            goto ESCAPE;
    219315        }
    220316    } else {
     
    223319        if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
    224320            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    225             return false;
    226         }
    227     }
    228 
    229     return true;
     321            success = false;
     322            goto ESCAPE;
     323        }
     324    }
     325
     326ESCAPE:
     327    pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND");
     328    pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
     329    pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
     330
     331    return success;
    230332}
  • branches/czw_branch/20101203/ppSub/src/ppSubMakePSF.c

    r28049 r30118  
    3535
    3636    psTimerStart("PPSUB_PHOT");
    37 
    38     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    39     psAssert(recipe, "We checked this earlier, so it should be here.");
    40 
    41     if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
    42         return true;
    43     }
    4437
    4538    bool reverse = psMetadataLookupBool(NULL, config->arguments, "REVERSE"); // Reverse sense of subtraction?
     
    9386    // use flags to toss totally bogus entries?
    9487    psArray *goodSources = ppSubSelectPSFSources (sources);
    95     if (!psphotReadoutFindPSF(config, view, goodSources)) {
     88    if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", goodSources)) {
    9689        // This is likely a data quality issue
    9790        // XXX Split into multiple cases using error codes?
  • branches/czw_branch/20101203/ppSub/src/ppSubMatchPSFs.c

    r29593 r30118  
    7272    // Extract the loaded sources from the associated readout, and generate PSF
    7373    // Here, we assume the image is background-subtracted
    74     if (!psphotReadoutFindPSF(config, view, sources)) {
     74    if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {
    7575        psErrorStackPrint(stderr, "Unable to determine PSF");
    7676        psWarning("Unable to determine PSF.");
  • branches/czw_branch/20101203/ppSub/src/ppSubReadoutPhotometry.c

    r29003 r30118  
    3131
    3232    if (!data->photometry) {
    33         return true;
    34     }
    35 
    36     // Look up recipe values
    37     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    38     psAssert(recipe, "We checked this earlier, so it should be here.");
    39 
    40     if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
    41         pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
    42         pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
    4333        return true;
    4434    }
     
    8171    }
    8272
    83     if (!psphotReadoutMinimal(config, view)) {
     73    if (!psphotReadoutMinimal(config, view, "PSPHOT.INPUT")) {
    8474        // This is likely a data quality issue
    8575        // XXX Split into multiple cases using error codes?
     
    9080
    9181    // If no sources were found, there's no error,  but we want to trigger 'bad quality'
     82    psWarning("no sources found: why is this being set to bad quality??");
    9283    pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // Sources
    9384    if (!detections) {
     
    136127        }
    137128    }
    138 
    139     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
    140     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
    141129
    142130    return true;
  • branches/czw_branch/20101203/psLib/src/fits/psFitsImage.c

    r28509 r30118  
    900900
    901901    if (nAxis == 2) {
     902        psImage *image = psFitsReadImage(fits, region, 0);
     903        if (!image) {
     904            psFitsError(status, true, "Could not read image into cube");
     905            return NULL;
     906        }
    902907        psArray *images = psArrayAlloc(1); // Single image plane
    903         images->data[0] = psFitsReadImage(fits, region, 0);
     908        images->data[0] = image;
    904909        return images;
    905910    }
  • branches/czw_branch/20101203/psLib/src/imageops

  • branches/czw_branch/20101203/psLib/src/imageops/psImageMapFit.c

    r25753 r30118  
    4848
    4949// map defines the output image dimensions and scaling.
    50 bool psImageMapFit(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     50bool psImageMapFit(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    5151                   const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    5252{
    5353    // XXX Add Asserts
     54
     55    *pGoodFit = false;
    5456
    5557    // dimensions of the output map image
     
    8183        map->map->data.F32[0][0]   = psStatsGetValue(map->stats, mean);
    8284        map->error->data.F32[0][0] = psStatsGetValue(map->stats, stdev);
     85        if (isfinite(map->map->data.F32[0][0]) && isfinite( map->error->data.F32[0][0])) {
     86            *pGoodFit = true;
     87        }
    8388        return true;
    8489    }
     
    8691    if (Nx == 1) {
    8792        bool status;
    88         status = psImageMapFit1DinY (map, mask, maskValue, x, y, f, df);
     93        status = psImageMapFit1DinY (pGoodFit, map, mask, maskValue, x, y, f, df);
    8994        return status;
    9095    }
    9196    if (Ny == 1) {
    9297        bool status;
    93         status = psImageMapFit1DinX (map, mask, maskValue, x, y, f, df);
     98        status = psImageMapFit1DinX (pGoodFit, map, mask, maskValue, x, y, f, df);
    9499        return status;
    95100    }
     
    310315
    311316    if (!psMatrixGJSolve(A, B)) {
    312         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
    313317        psFree (A);
    314318        psFree (B);
    315         return false;
     319        return true;
    316320    }
    317321
     
    337341    psFree (Empty);
    338342
     343    *pGoodFit = true;
    339344    return true;
    340345}
    341346
    342347// measure residuals on each pass and clip outliers based on stats
    343 bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
     348bool psImageMapClipFit(bool *pGoodFit, psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
    344349                       const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    345350{
     
    351356    psAssert(f, "impossible");
    352357
     358    *pGoodFit = false;
     359
    353360    // the user supplies one of various stats option pairs,
    354361    // determine the desired mean and stdev STATS options:
     
    393400        psTrace("psLib.imageops", 6, "Loop iteration %d.  Calling psImageMapFit()\n", N);
    394401        psS32 Nkeep = 0;
    395         if (!psImageMapFit(map, mask, maskValue, x, y, f, df)) {
     402        if (!psImageMapFit(pGoodFit, map, mask, maskValue, x, y, f, df)) {
    396403            psError(PS_ERR_UNKNOWN, false, "Could not fit image map.\n");
    397404            psFree(resid);
     
    399406            return false;
    400407        }
     408        if (!*pGoodFit) {
     409            psWarning ("bad fit to image map, try something else");
     410            return true;
     411        }
    401412
    402413        psVector *fit = psImageMapEvalVector(map, mask, maskValue, x, y);
     
    454465    psFree(resid);
    455466    if (!inMask) psFree (mask);
     467    *pGoodFit = true; // XXX probably don't need to set this (set by psImageMapFit)
    456468    return true;
    457469}
    458470
    459471// map defines the output image dimensions and scaling.
    460 bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     472bool psImageMapFit1DinY(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    461473                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    462474{
    463475    // XXX Add Asserts
    464476    assert (map->binning->nXruff == 1);
     477
     478    *pGoodFit = false;
    465479
    466480    // dimensions of the output map image
     
    578592
    579593    if (!psMatrixGJSolve(A, B)) {
    580         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.\n");
    581594        psFree (A);
    582595        psFree (B);
    583596        psFree (Empty);
    584         return false;
     597        return true;
    585598    }
    586599
     
    602615    psFree (Empty);
    603616
     617    *pGoodFit = true;
    604618    return true;
    605619}
    606620
    607621// map defines the output image dimensions and scaling.
    608 bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
     622bool psImageMapFit1DinX(bool *pGoodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
    609623                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
    610624{
    611625    // XXX Add Asserts
    612626    assert (map->binning->nYruff == 1);
     627
     628    *pGoodFit = false;
    613629
    614630    // dimensions of the output map image
     
    726742
    727743    if (!psMatrixGJSolve(A, B)) {
    728         psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations..\n");
    729744        psFree (A);
    730745        psFree (B);
    731746        psFree (Empty);
    732         return false;
     747        return true;
    733748    }
    734749
     
    750765    psFree (Empty);
    751766
     767    *pGoodFit = true;
    752768    return true;
    753769}
  • branches/czw_branch/20101203/psLib/src/imageops/psImageMapFit.h

    r25753 r30118  
    88
    99// fit the image map to a set of points
    10 bool psImageMapFit(psImageMap *map,
     10bool psImageMapFit(bool *pGoodFit,
     11                   psImageMap *map,
    1112                   const psVector *mask,
    1213                   psVectorMaskType maskValue, //
     
    1819
    1920// fit the image map to a set of points
    20 bool psImageMapClipFit(psImageMap *map,
     21bool psImageMapClipFit(bool *pGoodFit,
     22                       psImageMap *map,
    2123                       psStats *stats,
    2224                       psVector *mask,  // WARNING: Mask is modified!
     
    2830    );
    2931
    30 bool psImageMapFit1DinY(psImageMap *map,
     32bool psImageMapFit1DinY(bool *pGoodFit,
     33                        psImageMap *map,
    3134                        const psVector *mask,
    3235                        psVectorMaskType maskValue,
     
    3740    );
    3841
    39 bool psImageMapFit1DinX(psImageMap *map,
     42bool psImageMapFit1DinX(bool *pGoodFit,
     43                        psImageMap *map,
    4044                        const psVector *mask,
    4145                        psVectorMaskType maskValue,
  • branches/czw_branch/20101203/psLib/src/jpeg/psImageJpeg.c

    r29542 r30118  
    167167  int dy = image->numRows;
    168168 
    169   bDrawBuffer *bdbuf = bDrawBufferCreate(dx, dy);
     169  int Npalette;
     170  png_color *palette = KapaPNGPalette (&Npalette);
     171
     172  bDrawBuffer *bdbuf = bDrawBufferCreate(dx, dy, 1, palette, Npalette);
    170173
    171174  return bdbuf;
     
    180183  int dy = bdbuf->Ny;
    181184
    182   int Npalette;
    183   png_color *palette = KapaPNGPalette (&Npalette);
     185  png_color *palette = bdbuf->palette;
    184186  bDrawColor white = KapaColorByName ("white");
    185187  for (int j = 0; j < dy; j++) {
     
    336338
    337339    // set the scalebar labels
     340    int Npalette;
     341    png_color *palette = KapaPNGPalette (&Npalette);
     342
    338343    char string[64];
    339     bDrawBuffer *labels = bDrawBufferCreate(dx, PS_JPEG_LABELPAD);
     344    bDrawBuffer *labels = bDrawBufferCreate(dx, PS_JPEG_LABELPAD, 1, palette, Npalette);
    340345    SetRotFont ("helvetica", 8);
    341     bDrawSetBuffer(labels);
    342346    sprint_double (string, options->min);
    343     bDrawRotText(2, 2, string, 2, 0.0);
     347    bDrawRotText(labels, 2, 2, string, 2, 0.0);
    344348    sprint_double (string, options->max);
    345     bDrawRotText(dx - 2, 2, string, 0, 0.0);
     349    bDrawRotText(labels, dx - 2, 2, string, 0, 0.0);
    346350    sprint_double (string, 0.5*(options->min + options->max));
    347     bDrawRotText(0.5*dx, 2, string, 1, 0.0);
     351    bDrawRotText(labels, 0.5*dx, 2, string, 1, 0.0);
    348352    psImageJpegOverlayDraw(jpegImage, labels, 0, offset);
     353    bDrawBufferFree(labels);
    349354  }
    350355   
  • branches/czw_branch/20101203/psLib/src/math/psStats.c

    r28998 r30118  
    827827        // values; nearly bi-modal distribution).  if so, keep only points within 5? 10?
    828828        // bins of that excess bin:
    829         int nMaxBin = 0;
     829        int nMaxBin = histogram->nums->data.F32[0];
    830830        int iMaxBin = 0;
    831831        for (long i = 1; i < histogram->nums->n; i++) {
     
    843843                if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue;
    844844                bool invalid = false;
    845                 invalid |= (myVector->data.F32[i] <= minKeep);
    846                 invalid |= (myVector->data.F32[i] >= maxKeep);
     845                invalid |= (myVector->data.F32[i] < minKeep);
     846                invalid |= (myVector->data.F32[i] > maxKeep);
    847847                invalid |= (!isfinite(myVector->data.F32[i]));
    848848                if (!invalid) continue;
     
    852852
    853853            if (nInvalid) {
    854               psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid);
     854              psTrace(TRACE, 6, "data is concentrated in a single bin (%d = %f - %f), masking %d extreme outliers and retrying\n",
     855                      iMaxBin, histogram->bounds->data.F32[iMaxBin], histogram->bounds->data.F32[iMaxBin+1], nInvalid);
    855856              psFree(histogram);
    856857              psFree(cumulative);
     
    11081109    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    11091110    if (isnan(stats->robustMedian)) {
    1110         stats->fittedStdev = NAN;
    1111         stats->fittedStdev = NAN;
     1111        stats->fittedMean = NAN;
     1112        stats->fittedStdev = NAN;
     1113        stats->results |= PS_STAT_FITTED_MEAN;
     1114        stats->results |= PS_STAT_FITTED_STDEV;
     1115        return true;
     1116    }
     1117
     1118    if (stats->robustStdev <= FLT_EPSILON) {
     1119        stats->fittedMean = stats->robustMedian;
     1120        stats->fittedStdev = stats->robustStdev;
     1121        stats->results |= PS_STAT_FITTED_MEAN;
     1122        stats->results |= PS_STAT_FITTED_STDEV;
    11121123        return true;
    11131124    }
     
    12891300    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    12901301    if (isnan(stats->robustMedian)) {
    1291         stats->fittedStdev = NAN;
    1292         stats->fittedStdev = NAN;
    1293         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1302        stats->fittedMean = NAN;
     1303        stats->fittedStdev = NAN;
     1304        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1305        stats->results |= PS_STAT_FITTED_STDEV_V2;
     1306        return true;
     1307    }
     1308
     1309    if (stats->robustStdev <= FLT_EPSILON) {
     1310        stats->fittedMean = stats->robustMedian;
     1311        stats->fittedStdev = stats->robustStdev;
     1312        stats->results |= PS_STAT_FITTED_MEAN_V2;
     1313        stats->results |= PS_STAT_FITTED_STDEV_V2;
    12941314        return true;
    12951315    }
     
    14861506    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    14871507    if (isnan(stats->robustMedian)) {
    1488         stats->fittedStdev = NAN;
    1489         stats->fittedStdev = NAN;
    1490         psTrace(TRACE, 4, "---- %s() end ----\n", __func__);
     1508        stats->fittedMean = NAN;
     1509        stats->fittedStdev = NAN;
     1510        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1511        stats->results |= PS_STAT_FITTED_STDEV_V3;
     1512        return true;
     1513    }
     1514
     1515    if (stats->robustStdev <= FLT_EPSILON) {
     1516        stats->fittedMean = stats->robustMedian;
     1517        stats->fittedStdev = stats->robustStdev;
     1518        stats->results |= PS_STAT_FITTED_MEAN_V3;
     1519        stats->results |= PS_STAT_FITTED_STDEV_V3;
    14911520        return true;
    14921521    }
     
    17821811
    17831812    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    1784     if (isnan(stats->robustMedian)) goto escape;
     1813    if (isnan(stats->robustMedian)) {
     1814        stats->fittedMean = NAN;
     1815        stats->fittedStdev = NAN;
     1816        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1817        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1818        return true;
     1819    }
     1820
     1821    if (stats->robustStdev <= FLT_EPSILON) {
     1822        stats->fittedMean = stats->robustMedian;
     1823        stats->fittedStdev = stats->robustStdev;
     1824        stats->results |= PS_STAT_FITTED_MEAN_V4;
     1825        stats->results |= PS_STAT_FITTED_STDEV_V4;
     1826        return true;
     1827    }
    17851828
    17861829    float guessStdev = stats->robustStdev;  // pass the guess sigma
  • branches/czw_branch/20101203/psLib/src/sys/psSlurp.c

    r12072 r30118  
    2727#include "psMemory.h"
    2828
    29 #define SLURP_SIZE 4096
     29# define SLURP_SIZE 4096
     30
     31# if (PS_SLURP_GZIP)
     32
     33psString psSlurpFD(int fd) {
     34
     35 gzFile file = gzdopen (fd, "r");
     36 if (file == Z_NULL) {
     37     psError(PS_ERR_IO, true, "Failed to open file\n");
     38     return NULL;
     39 }
     40 
     41 psString str = psSlurpGZIP(file);
     42
     43 return str;
     44}
     45
     46# else
    3047
    3148psString psSlurpFD(int fd)
     
    3855        // increase the allocated string size
    3956        size += SLURP_SIZE;
    40         str = psRealloc(str, size);
     57        str = psStringRealloc(str, size);
    4158
    4259        // read a block from the stream
     
    5976    return str;
    6077}
     78# endif
    6179
     80# if (PS_SLURP_GZIP)
     81psString psSlurpGZIP(gzFile fd)
     82{
     83    psString str = NULL;                // String to which to write
     84    size_t size  = 1;                   // bytes allocated -  make sure there is room for '\0'
     85    size_t used = 0;                    // bytes actually used
     86    ssize_t bytes;                      // Number of bytes read
     87    do {
     88        // increase the allocated string size
     89        size += SLURP_SIZE;
     90        str = psStringRealloc(str, size);
     91
     92        // read a block from the stream
     93        bytes = gzread(fd, str + used, SLURP_SIZE);
     94        if (bytes < 0) {
     95            // it's an error
     96            psError(PS_ERR_IO, true, "slurp failed on read");
     97            psFree(str);
     98            return NULL;
     99        }
     100
     101        // Increase the size of the known string
     102        used += bytes;
     103
     104    } while (bytes != 0);
     105
     106    // append '\0' to the end of the string
     107    str[used] = '\0';
     108
     109    return str;
     110}
     111# endif
    62112
    63113psString psSlurpFile(FILE *stream)
     
    70120{
    71121    PS_ASSERT_PTR_NON_NULL(filename, NULL);
     122   
     123# if (PS_SLURP_GZIP)
     124    gzFile fd = gzopen(filename, "r");
     125    if (fd == Z_NULL) {
     126        psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     127        return NULL;
     128    }
     129    psString text = psSlurpGZIP(fd);
     130
     131    if (gzclose(fd) != Z_OK) {
     132        psError(PS_ERR_IO, true, "Failed to close specified file, %s\n", filename);
     133        psFree(text);
     134        return NULL;
     135    }
     136
     137# else
    72138
    73139    int fd = open(filename, O_RDONLY);
     
    76142        return NULL;
    77143    }
    78 
    79144    psString text = psSlurpFD(fd);
    80145
     
    84149        return NULL;
    85150    }
     151# endif
    86152
    87153    return text;
  • branches/czw_branch/20101203/psLib/src/sys/psSlurp.h

    r15410 r30118  
    1212
    1313#include <psString.h>
     14
     15# define PS_SLURP_GZIP 1
     16
     17# if (PS_SLURP_GZIP)
     18# include <zlib.h>
     19# endif
    1420
    1521/// @addtogroup FileIO Input/Output
     
    3137                    );
    3238
     39# if (PS_SLURP_GZIP)
     40psString psSlurpGZIP(gzFile fd);
     41# endif
     42
    3343/// @}
    3444#endif
  • branches/czw_branch/20101203/psLib/src/sys/psString.c

    r19070 r30118  
    4848    psString string = p_psAlloc(file, lineno, func, nChar + 1);
    4949    psMemSetDeallocator(string, (psFreeFunc)stringFree);
     50
     51    return string;
     52}
     53
     54
     55psString p_psStringRealloc(const char *file,
     56                           unsigned int lineno,
     57                           const char *func,
     58                           psString string,
     59                           size_t nChar)
     60{
     61    if (!string) {
     62        string = p_psAlloc(file, lineno, func, nChar + 1);
     63        psMemSetDeallocator(string, (psFreeFunc)stringFree);
     64    } else {
     65        string = p_psRealloc(file, lineno, func, string, nChar + 1);
     66    }
    5067
    5168    return string;
  • branches/czw_branch/20101203/psLib/src/sys/psString.h

    r15523 r30118  
    4040#define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
    4141
    42 
    4342/** Allocates a new psString.
    4443 *
     
    6059#endif // ifdef DOXYGEN
    6160
     61/** Reallocate an existing psString (or alloc if not existent)
     62 *
     63 *  @return psString:       string of length n.
     64 */
     65#ifdef DOXYGEN
     66psString psStringRealloc(
     67    psString string,
     68    size_t nChar                        ///< Size of psString to allocate.
     69);
     70#else // ifdef DOXYGEN
     71psString p_psStringRealloc(
     72    const char *file,                   ///< File of caller
     73    unsigned int lineno,                ///< Line number of caller
     74    const char *func,                   ///< Function name of caller
     75    psString string,                    ///< supplied string or NULL
     76    size_t nChar                        ///< Size of psString to allocate.
     77) PS_ATTR_MALLOC;
     78#define psStringRealloc(string, nChar)                          \
     79    p_psStringRealloc(__FILE__, __LINE__, __func__, string, nChar)
     80#endif // ifdef DOXYGEN
    6281
    6382/** Checks the type of a particular pointer.
  • branches/czw_branch/20101203/psLib/src/types/psMetadata.c

    r29833 r30118  
    13711371            break;
    13721372        case PS_DATA_S64:
    1373             fprintf(fd, "%jd\n", item->data.S64);
     1373            fprintf(fd, "%" PRId64 "\n", item->data.S64);
    13741374            break;
    13751375        case PS_DATA_U8:
     
    13831383            break;
    13841384        case PS_DATA_U64:
    1385             fprintf(fd, "%ju\n", item->data.U64);
     1385            fprintf(fd, "%" PRIu64 "\n", item->data.U64);
    13861386            break;
    13871387        case PS_DATA_F32:
     
    14581458              fprintf(fd, "U64  ");
    14591459              for (int i = 0; i < vector->n; i++) {
    1460                   fprintf(fd, "%ju ", vector->data.U64[i]);
     1460                  fprintf(fd, "%" PRIu64, vector->data.U64[i]);
    14611461              }
    14621462              fprintf(fd, "\n");
     
    14861486              fprintf(fd, "S64  ");
    14871487              for (int i = 0; i < vector->n; i++) {
    1488                   fprintf(fd, "%jd ", vector->data.S64[i]);
     1488                  fprintf(fd, "%" PRId64, vector->data.S64[i]);
    14891489              }
    14901490              fprintf(fd, "\n");
  • branches/czw_branch/20101203/psLib/src/types/psMetadataConfig.c

    r27056 r30118  
    16301630}
    16311631
    1632 
    1633 bool psMetadataConfigWrite(psMetadata *md,
    1634                            const char *filename)
    1635 {
    1636     PS_ASSERT_METADATA_NON_NULL(md, NULL);
    1637     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    1638     FILE *file;
    1639     if ( !(file = fopen(filename, "w")) ) {
    1640         psError(PS_ERR_IO, true,
    1641                 "Failed to open specified file, %s\n", filename);
    1642         return false;
    1643     }
    1644     psString fileString = NULL;
    1645     fileString = psMetadataConfigFormat(md);
    1646     if (fileString == NULL) {
    1647         psError(PS_ERR_BAD_PARAMETER_NULL, false,
    1648                 "psMetadataConfigFormat returned NULL.\n");
    1649         return false;
    1650     }
    1651     if (fprintf(file, "%s", fileString) != strlen(fileString)) {
    1652         psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
    1653         psFree(fileString);
    1654         fclose(file);
    1655         return false;
     1632bool psMetadataConfigWrite(psMetadata *md, const char *filename, const char *compress)
     1633{
     1634  PS_ASSERT_METADATA_NON_NULL(md, NULL);
     1635  PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     1636
     1637  psString fileString = NULL;
     1638  fileString = psMetadataConfigFormat(md);
     1639  if (fileString == NULL) {
     1640    psError(PS_ERR_BAD_PARAMETER_NULL, false, "psMetadataConfigFormat returned NULL.\n");
     1641    return false;
     1642  }
     1643
     1644  if (compress) {
     1645    if (strlen(compress) > 2) {
     1646      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "invalid compression options %s", compress);
     1647      psFree(fileString);
     1648      return false;
     1649    }
     1650    char modeString[4];
     1651    snprintf (modeString, 4, "w%s", compress);
     1652
     1653    gzFile file = gzopen(filename, modeString);
     1654    if (file == Z_NULL) {
     1655      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1656      psFree(fileString);
     1657      return false;
     1658    }
     1659
     1660    int nbytes = gzwrite (file, fileString, strlen(fileString));
     1661    if (nbytes != strlen(fileString)) {
     1662      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1663      psFree(fileString);
     1664      gzclose(file);
     1665      return false;
     1666    }
     1667    psFree(fileString);
     1668    if (gzclose(file) != Z_OK) {
     1669      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1670      return false;
     1671    }
     1672  } else {
     1673    FILE *file = fopen(filename, "w");
     1674    if (file == NULL) {
     1675      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1676      psFree(fileString);
     1677      return false;
     1678    }
     1679
     1680    int nbytes = fwrite(fileString, 1, strlen(fileString), file);
     1681    if (nbytes != strlen(fileString)) {
     1682      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1683      psFree(fileString);
     1684      fclose(file);
     1685      return false;
    16561686    }
    16571687    psFree(fileString);
    16581688    if (fclose(file) == EOF) {
    1659         psError(PS_ERR_IO, true,
    1660                 "Failed to close file, %s\n", filename);
    1661         return false;
    1662     }
    1663     return true;
     1689      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1690      return false;
     1691    }
     1692  }
     1693  return true;
    16641694}
    16651695
  • branches/czw_branch/20101203/psLib/src/types/psMetadataConfig.h

    r11248 r30118  
    3333 *  a string, the formatting command must also be for a string. If the
    3434 *  metadata type is any other data type, printing is not allowed.
     35 *  Currently, this function does not compress the output file
    3536 *
    3637 * @return psMetadataItem* :    Pointer metadata item.
     
    8586bool psMetadataConfigWrite(
    8687    psMetadata *md,                    ///< The metadata to convert
    87     const char *filename               ///< Name of file to write
     88    const char *filename,              ///< Name of file to write
     89    const char *compress               ///< Output compression options
    8890);
    8991
    9092/** Converts a psMetadata structure (including any nested psMetadata) into a
    9193 *  configuration file formatted string that is written a file stream.
     94 *  Currently, this function does not compress the output file
    9295 *
    9396 *  @return bool:       True if successful, otherwise false.
  • branches/czw_branch/20101203/psLib/test/imageops

    • Property svn:ignore
      •  

        old new  
        2727convolutionBench
        2828tap_psImageInterpolate2
         29tap_psImageInterpolate3
        2930tap_psImageGeomManip
        3031tap_psImageMaskOps
  • branches/czw_branch/20101203/psLib/test/imageops/Makefile.am

    r14926 r30118  
    2222        tap_psImagePixelExtract \
    2323        tap_psImageInterpolate2 \
     24        tap_psImageInterpolate3 \
    2425        tap_psImageMap \
    2526        tap_psImageMapFit \
  • branches/czw_branch/20101203/psLib/test/math

  • branches/czw_branch/20101203/psLib/test/math/tap_psStats_Sample_01.c

    r12513 r30118  
    487487                         };
    488488
     489static float yraw_04[] = {
     490    -1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -1.000000, -1.000000, -1.000000,
     491    0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     492    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.963289,
     493    -1.000000, 0.000000, -1.000000, -1.000000, -0.915174, -1.000000, -1.000000, -1.000000,
     494    -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     495    -1.000000, -1.000000, -1.000000, -0.853025, 0.000000, -1.000000, -1.000000, -1.000000,
     496    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.989926, -1.000000, -1.000000,
     497    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.834902, -1.000000, -1.000000,
     498    -0.942985, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     499    -1.000000, -1.000000, -0.990081, -1.000000, -0.990456, -0.814654, -1.000000, -1.000000,
     500    -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     501    -0.968021, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000, -0.993967, -0.957540,
     502    -0.894533, -0.958363, -1.000000, -1.000000, -1.000000, -0.988915, -1.000000, -1.000000,
     503    -1.000000, -1.000000, -1.000000, -1.000000, -0.985367, -1.000000, -0.972040, -1.000000,
     504    -1.000000, -1.000000, 0.000000, -1.000000, -0.882278, -1.000000, -1.000000, -1.000000,
     505    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     506    -1.000000, -0.962575, -0.976843, -0.998926, -1.000000, -0.914090, 0.000000, -0.957808,
     507    -1.000000, -1.000000, -1.000000, 0.000000, -0.902593, -1.000000, -1.000000, -1.000000,
     508    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.975404,
     509    -1.000000, 0.000000, -0.984627, -1.000000, -0.969547, -0.851295, -1.000000, -0.988146,
     510    -1.000000, 0.000000, -1.000000, -0.993753, -0.861851, -1.000000, -0.980836, -0.979644,
     511    -1.000000, -1.000000, -1.000000, -0.995401, -1.000000, -1.000000, -1.000000, -1.000000,
     512    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000,
     513    0.000000, -1.000000, -0.990123, -0.944934, -1.000000, 0.000000, -1.000000, -0.952198,
     514    -1.000000, -1.000000, -0.960814, -1.000000, -1.000000, -1.000000, -0.956806, -1.000000,
     515    0.000000, -0.991778, -1.000000, -1.000000, -1.000000, -1.000000, 0.000000, -1.000000,
     516    -0.977640, -1.000000, -1.000000, 0.000000, -1.000000, -0.977630, -1.000000, -0.974242,
     517    -1.000000, -1.000000, -0.940085, -0.930729, -1.000000, -1.000000, 0.000000, -1.000000,
     518    -1.000000, -0.933695, -1.000000, -0.932306, -1.000000, -1.000000, -1.000000, -0.836774,
     519    -0.931762, -0.926990, -0.861895, -1.000000, -0.922505, -1.000000, -0.956420, -0.998768,
     520    -0.974626, -0.964573, -1.000000, -0.933995, -1.000000, -0.995117, -1.000000, -1.000000,
     521    0.000000, 0.000000, -1.000000, -0.955537, -0.996360, -0.988015, -1.000000, -1.000000,
     522    -0.963953, -0.920429, -0.955252, -0.950946, -1.000000, -1.000000, -1.000000, -0.979526,
     523    -1.000000, -1.000000, -0.997193, -1.000000, -1.000000, 0.000000, -1.000000, -1.000000,
     524    -1.000000, -0.893445, -1.000000, -1.000000, -0.997704, -1.000000, -1.000000, -0.952295,
     525    -1.000000, 0.000000, -0.928042, -1.000000, -1.000000, -0.994029, -0.919350, -1.000000,
     526    -1.000000, -1.000000, -1.000000, -0.958966, -0.806458, -0.903843, -1.000000, -1.000000,
     527    -1.000000, -1.000000, -1.000000, -1.000000, 0.000000, -0.989002, 0.000000, -0.999874,
     528    -1.000000, 0.000000, -1.000000, 0.000000, -0.923556, -0.906242, -0.923497, -0.997873,
     529    -1.000000, -1.000000, 0.000000, -0.960376, -0.998760, -1.000000, 0.000000, -1.000000,
     530    -0.852141, -1.000000, -0.957442, -0.942000, -1.000000, -1.000000, -1.000000, -1.000000,
     531    -1.000000, -1.000000, -0.996748, -0.997676, -0.976159, -0.951572, -1.000000, -0.993083,
     532    -0.715375, -0.997984, -1.000000, -0.962484, -0.996733, -1.000000, -1.000000, -0.953423,
     533    -1.000000, -0.882232, -1.000000, -1.000000, -0.944493, -1.000000, -0.979617, -1.000000,
     534    -0.990002, -1.000000, -0.844745, -0.945080, -1.000000, -1.000000, -0.904816, -1.000000,
     535    -0.986999, -1.000000, -0.854941, -1.000000, -0.946096, -0.977678, -1.000000, -0.955933,
     536    -0.979545, -1.000000, -1.000000, -0.863616, -0.973953, -0.996599, -0.990304, -0.978263,
     537    -1.000000, -0.967798, -0.912566, 0.000000, -1.000000, -1.000000, -0.990321, -0.995921,
     538    -1.000000, -1.000000, -1.000000, -0.927030, -0.886393, -0.987297, -1.000000, -1.000000,
     539    -0.987206, -0.978084, -1.000000, -0.923876, -0.957539, -0.991587, -0.819295, -1.000000,
     540    -0.985077, -1.000000, 0.000000, -1.000000, -1.000000, -0.822353, -1.000000, -1.000000,
     541    -0.987783, -1.000000, -0.909520, -1.000000, -0.932334, -0.991847, -1.000000, -0.885318,
     542    -0.945695, -0.977144, -0.989444, -0.887085, -0.891662, -0.894193, -1.000000, 0.000000,
     543    -1.000000, -0.917484, -1.000000, -0.892801, -1.000000, -0.963580, -0.869279, -0.965420,
     544    -0.906966, -0.929646, -0.981315, -1.000000, -1.000000, -0.749674, -1.000000, -0.886804,
     545    -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -1.000000, -0.970826, -0.909766,
     546    -1.000000, -0.910406, -0.983636, -1.000000, -0.961209, -0.935273, -1.000000, -0.989806,
     547    0.000000, -0.981563, -0.989701, -0.915626, -0.997493, -0.981429, -1.000000, -0.964583,
     548    -1.000000, -0.930216, -0.737797, -1.000000, -0.944314, -0.999998, -0.999611, -0.945788,
     549    -0.773886, -0.848979, -0.980186, -1.000000, -1.000000, 0.000000, -0.951392, -0.993398,
     550    -0.931889, -0.991680, -0.959021, -0.904240, -1.000000, -0.983561, -0.821324, 0.000000,
     551    0.000000, -1.000000, -0.925782, -0.841267, -1.000000, -0.907313, -1.000000, -0.990704,
     552    -1.000000, -1.000000, -0.936372, -0.885059
     553};
     554
    489555int main (void)
    490556{
    491557    plan_tests(21);
    492558
    493 //    diag("psStats Tests with sample SDSS data from RHL and Megacam from EAM");
    494 //    diag("this file does not yet define a specific test");
    495 //    diag("the fitted mean is currently wrong for these two data sets");
    496 
    497     {
     559    // float **yraw = {yraw_01, yraw_02, yraw_03, yraw_04, NULL};
     560
     561    if (1) {
     562        diag("sample 1 : problem with integer-binned data driven to tiny sigma values");
     563
    498564        psMemId id = psMemGetId();
    499565
    500 //        diag("sample 1 : problem with integer-binned data driven to tiny sigma values");
    501566        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    502567                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     
    505570                                       PS_STAT_SAMPLE_STDEV | PS_STAT_USE_BINSIZE);
    506571        stats->binsize = 1.0;
    507 
    508572
    509573        // copy data in static array
     
    533597
    534598
    535     {
     599    if (1) {
    536600        psMemId id = psMemGetId();
    537601
    538 //        diag("sample 2");
     602        diag("sample 2");
    539603        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    540604                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     
    568632    }
    569633
    570     {
     634    if (1) {
    571635        psMemId id = psMemGetId();
    572636
    573 //        diag("sample 3");
     637        diag("sample 3");
    574638        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
    575639                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
    576640                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
    577641                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
    578                                        PS_STAT_SAMPLE_STDEV | PS_STAT_USE_BINSIZE);
    579         stats->binsize = 1.0;
    580 
     642                                       PS_STAT_SAMPLE_STDEV);
    581643
    582644        // copy data in static array
     
    605667    }
    606668
     669    {
     670        psMemId id = psMemGetId();
     671
     672        // psTraceSetLevel("psLib.math.vectorRobustStats", 6);
     673
     674        diag("sample 4");
     675        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
     676                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
     677                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
     678                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
     679                                       PS_STAT_SAMPLE_STDEV);
     680
     681        // copy data in static array
     682        int nPts = sizeof(yraw_04) / sizeof (float);
     683        psVector *y = psVectorAlloc (nPts, PS_TYPE_F32);
     684        for (int i = 0; i < y->n; i++) {
     685            y->data.F32[i] = yraw_04[i];
     686        }
     687
     688        psVectorStats (stats, y, NULL, NULL, 1);
     689        ok (1, "sample  mean   %f, stdev %f", stats->sampleMean,   stats->sampleStdev);
     690        ok (1, "sample  median %f, stdev %f", stats->sampleMedian, stats->sampleStdev);
     691        ok (1, "clipped mean   %f, stdev %f", stats->clippedMean,  stats->clippedStdev);
     692        ok (1, "robust  median %f, stdev %f", stats->robustMedian, stats->robustStdev);
     693        ok (1, "fitted  mean   %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
     694        psFree (stats);
     695
     696        stats = psStatsAlloc (PS_STAT_FITTED_MEAN_V2 | PS_STAT_FITTED_STDEV_V2 | PS_STAT_USE_BINSIZE);
     697        stats->binsize = 1.0;
     698        psVectorStats (stats, y, NULL, NULL, 1);
     699        ok (1, "fitted  mean v2 %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
     700        psFree (stats);
     701
     702        psFree (y);
     703        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     704    }
     705
    607706    return exit_status();
    608707}
     708
  • branches/czw_branch/20101203/psLib/test/types/tap_psMetadataConfigWrite.c

    r17515 r30118  
    2525    {
    2626        psMemId id = psMemGetId();
    27         ok( !psMetadataConfigWrite(NULL, "mdcfg.wrt"),
     27        ok( !psMetadataConfigWrite(NULL, "mdcfg.wrt", NULL),
    2828            "return false for NULL metadata input.");
    2929        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     
    3535        psMemId id = psMemGetId();
    3636        psMetadata *md = psMetadataAlloc();
    37         ok( !psMetadataConfigWrite(md, NULL),
     37        ok( !psMetadataConfigWrite(md, NULL, NULL),
    3838            "return false for NULL filename input.");
    3939        psFree(md);
     
    4646        psMemId id = psMemGetId();
    4747        psMetadata *md = psMetadataAlloc();
    48         ok( !psMetadataConfigWrite(md, "."),
     48        ok( !psMetadataConfigWrite(md, ".", NULL),
    4949            "return false for invalid filename input.");
    5050        psFree(md);
     
    5757        psMemId id = psMemGetId();
    5858        psMetadata *md = psMetadataAlloc();
    59         ok(psMetadataConfigWrite(md, "mdcfg.wrt"), "return false for empty metadata input.");
     59        ok(psMetadataConfigWrite(md, "mdcfg.wrt", NULL), "return false for empty metadata input.");
    6060        psFree(md);
    6161        ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     
    6868        psMetadata *md = psMetadataAlloc();
    6969        psMetadataAddBool(md, PS_LIST_TAIL, "item1-1", 0, "I am a boolean", true);
    70         ok( psMetadataConfigWrite(md, "mdcfg.wrt"),
     70        ok( psMetadataConfigWrite(md, "mdcfg.wrt", NULL),
    7171            "return true for valid inputs.");
    7272        char configTest[61];
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAFlags.c

    r15477 r30118  
    4949}
    5050
     51bool pmReadoutSetFileStatus(pmReadout *readout, bool status)
     52{
     53    PS_ASSERT_PTR_NON_NULL(readout, false);
     54
     55    readout->file_exists = status;
     56    return true;
     57}
     58
     59bool pmFPAviewSetFileStatus (pmFPA *fpa, const pmFPAview *view, bool status) {
     60
     61    PS_ASSERT_PTR_NON_NULL(fpa, false);
     62    PS_ASSERT_PTR_NON_NULL(view, false);
     63
     64    if (view->chip == -1) {
     65        bool set = pmFPASetFileStatus (fpa, status);
     66        return set;
     67    }
     68
     69    if (view->chip >= fpa->chips->n) {
     70        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
     71        return false;
     72    }
     73    pmChip *chip = fpa->chips->data[view->chip];
     74
     75    if (view->cell == -1) {
     76        bool set = pmChipSetFileStatus (chip, status);
     77        return set;
     78    }
     79
     80    if (view->cell >= chip->cells->n) {
     81        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
     82        return false;
     83    }
     84    pmCell *cell = chip->cells->data[view->cell];
     85
     86    if (view->readout == -1) {
     87        bool set = pmCellSetFileStatus (cell, status);
     88        return set;
     89    }
     90
     91    if (view->readout >= cell->readouts->n) {
     92        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
     93        return false;
     94    }
     95    pmReadout *readout = cell->readouts->data[view->readout];
     96
     97    bool set = pmReadoutSetFileStatus (readout, status);
     98    return set;
     99}
     100
    51101bool pmFPACheckFileStatus(const pmFPA *fpa)
    52102{
     
    125175    for (int i = 0; i < cell->readouts->n; i++) {
    126176        pmReadout *readout = cell->readouts->data[i];
    127         readout->data_exists = status;
    128     }
    129     return true;
     177        pmReadoutSetDataStatus(readout, status);
     178    }
     179    return true;
     180}
     181
     182bool pmReadoutSetDataStatus (pmReadout *readout, bool status)
     183{
     184    PS_ASSERT_PTR_NON_NULL(readout, false);
     185
     186    readout->data_exists = status;
     187    return true;
     188}
     189
     190bool pmFPAviewSetDataStatus (pmFPA *fpa, const pmFPAview *view, bool status) {
     191
     192    PS_ASSERT_PTR_NON_NULL(fpa, false);
     193    PS_ASSERT_PTR_NON_NULL(view, false);
     194
     195    if (view->chip == -1) {
     196        bool set = pmFPASetDataStatus (fpa, status);
     197        return set;
     198    }
     199
     200    if (view->chip >= fpa->chips->n) {
     201        psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);
     202        return false;
     203    }
     204    pmChip *chip = fpa->chips->data[view->chip];
     205
     206    if (view->cell == -1) {
     207        bool set = pmChipSetDataStatus (chip, status);
     208        return set;
     209    }
     210
     211    if (view->cell >= chip->cells->n) {
     212        psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);
     213        return false;
     214    }
     215    pmCell *cell = chip->cells->data[view->cell];
     216
     217    if (view->readout == -1) {
     218        bool set = pmCellSetDataStatus (cell, status);
     219        return set;
     220    }
     221
     222    if (view->readout >= cell->readouts->n) {
     223        psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);
     224        return false;
     225    }
     226    pmReadout *readout = cell->readouts->data[view->readout];
     227
     228    bool set = pmReadoutSetDataStatus (readout, status);
     229    return set;
    130230}
    131231
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAFlags.h

    r13190 r30118  
    3434                        );
    3535
     36bool pmReadoutSetFileStatus(pmReadout *readout, bool status);
     37
     38bool pmFPAviewSetFileStatus (pmFPA *fpa, const pmFPAview *view, bool status);
     39
    3640// Functions to check the file_exists flags
    3741
     
    6569                        );
    6670
     71bool pmReadoutSetDataStatus (pmReadout *readout, bool status);
     72
     73bool pmFPAviewSetDataStatus (pmFPA *fpa, const pmFPAview *view, bool status);
    6774
    6875// Functions the check the data_exists flags
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAfile.c

    r29833 r30118  
    3636        return;
    3737    }
    38     psTrace ("pmFPAfileFree", 5, "freeing %s %ld\n", file->name,(psU64) file->fits);
     38    psTrace ("pmFPAfileFree", 5, "freeing %s %p\n", file->name, file->fits);
    3939    psAssert(!fpaFileFreeStrict || file->fits == NULL, "File %s wasn't closed.", file->name);
    4040
  • branches/czw_branch/20101203/psModules/src/camera/pmFPAfileIO.c

    r29833 r30118  
    135135    PS_ASSERT_PTR_NON_NULL(view, false);
    136136
    137     // an internal file should not be sent here (should not be left on config->files)
    138     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    139 
    140137    // skip the following states
    141138    if (file->state & PM_FPA_STATE_INACTIVE) {
     
    143140        return true;
    144141    }
     142
     143    // an active internal file should not be sent here (should not be left on config->files)
     144    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     145
    145146    if (file->mode != PM_FPA_MODE_READ) {
    146147        psTrace("psModules.camera", 6, "skip read for %s, mode is not READ", file->name);
     
    258259        return true;
    259260    }
     261
     262    // an active internal file should not be returned to here
     263    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     264
    260265    if (file->mode != PM_FPA_MODE_WRITE) {
    261266        psTrace("psModules.camera", 6, "skip create for non-write file %s", file->name);
    262267        return true;
    263268    }
    264 
    265     // an internal file should not be returned to here
    266     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    267269
    268270    // get the current level
     
    335337    }
    336338
     339    // an ACTIVE internal file should not be sent here
     340    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
     341
    337342    if (file->mode != PM_FPA_MODE_WRITE) {
    338343        psTrace("psModules.camera", 6, "skip write for %s, mode is not WRITE", file->name);
    339344        return true;
    340     }
    341 
    342     // an internal file should not be returned to here
    343     if (file->mode == PM_FPA_MODE_INTERNAL) {
    344         psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_INTERNAL");
    345         return false;
    346345    }
    347346
     
    523522    PS_ASSERT_PTR_NON_NULL(view, false);
    524523
    525     // an internal file should not be sent here (should not be left on config->files)
    526     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    527 
    528524    // skip the following states
    529525    if (file->state & PM_FPA_STATE_INACTIVE) {
     
    531527        return true;
    532528    }
     529
    533530    if (file->state == PM_FPA_STATE_CLOSED) {
    534531        psTrace("psModules.camera", 6, "skip close for %s, files is closed", file->name);
    535532        return true;
    536533    }
     534
     535    // an active internal file should not be sent here (should not be left on config->files)
     536    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    537537
    538538    // is current level == open level?
     
    596596    PS_ASSERT_PTR_NON_NULL(view, false);
    597597
    598     // an internal file should not be sent here (should not be left on config->files)
    599     PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    600 
    601598    if (file->state & PM_FPA_STATE_INACTIVE) {
    602599        psTrace("psModules.camera", 6, "skip free for %s, files is inactive", file->name);
    603600        return true;
    604601    }
     602
     603    // an active internal file should not be sent here (should not be left on config->files)
     604    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
    605605
    606606    // get the current level
     
    746746    }
    747747
    748     // these are programming errors
     748    // an ACTIVE internal file should not be sent here
    749749    PS_ASSERT(file->mode != PM_FPA_MODE_NONE, false);
    750750    PS_ASSERT(file->mode != PM_FPA_MODE_INTERNAL, false);
  • branches/czw_branch/20101203/psModules/src/concepts/pmConceptsAverage.c

    r29603 r30118  
    136136    return average;
    137137}
     138float medianWithDropouts (psList *sources, char *name) {
     139
     140    bool status;
     141
     142    psListIterator *sourcesIter = psListIteratorAlloc(sources, PS_LIST_HEAD, false); // Iterator for sources
     143    pmCell *cell = NULL;                // Source cell from iteration
     144
     145    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
     146    psVector *values = psVectorAlloc(sources->n, PS_TYPE_F32);
     147    int nvalues = 0;
     148    while ((cell = psListGetAndIncrement(sourcesIter))) {
     149        if (!cell) {
     150            continue;
     151        }
     152
     153        float value = psMetadataLookupF32(&status, cell->concepts, name);
     154        if (!status) continue;
     155        if (!isfinite(value)) continue;
     156
     157        values->data.F32[nvalues++] = value;
     158    }
     159    psFree (sourcesIter);
     160    if (!nvalues) {
     161        psWarning("no valid values found for %s\n", name);
     162        psFree(values);
     163        psFree(stats);
     164        return INFINITY;
     165    }
     166    if (!(values = psVectorRealloc(values, nvalues))) {
     167        psWarning("failed to reallocate values vector for %s\n", name);
     168        psFree(stats);
     169        return INFINITY;
     170    }
     171    if (!psVectorStats(stats, values, NULL, NULL, 0)) {
     172        psWarning("psVectorStats failed for %s\n", name);
     173        psFree(values);
     174        psFree(stats);
     175        return INFINITY;
     176    }
     177
     178    psF32 median = psStatsGetValue(stats, PS_STAT_SAMPLE_MEDIAN);
     179
     180    psFree(values);
     181    psFree(stats);
     182
     183    return median;
     184}
    138185
    139186// Set a variety of concepts in a cell by averaging over several
     
    145192    PS_ASSERT_INT_POSITIVE(sources->n, false);
    146193
    147     float saturation = INFINITY;        // Saturation level
    148194    float bad        = -INFINITY;       // Bad level
    149195    double time      = 0.0;             // Time of observation
     
    158204    float exposure  = averageWithDropouts (sources, "CELL.EXPOSURE");
    159205    float darktime  = averageWithDropouts (sources, "CELL.DARKTIME");
     206    float saturation = medianWithDropouts(sources, "CELL.SATURATION");
    160207
    161208    // other concepts are a bit more "special"
     
    221268        }
    222269
    223         float cellSaturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
    224         if (cellSaturation > 10000) {
    225             // do not allow invalid values to polute this calculation
    226             // XXX really need to do this on the basis of the fraction of the cell that contributes..
    227             // if a cell is completely masked, it should not be included.
    228             if (cellSaturation < saturation) {
    229                 saturation = cellSaturation;
    230             }
    231         }
    232270        float cellBad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD");
    233271        if (cellBad > bad) {
  • branches/czw_branch/20101203/psModules/src/config/pmConfigDump.c

    r27147 r30118  
    150150    }
    151151
    152     if (!psMetadataConfigWrite(config->user, resolved)) {
     152    // check for Metadata compression options:
     153    char *compressMode = NULL;
     154    bool status = false;
     155    if (config->camera) {
     156        compressMode = psMetadataLookupStr(&status, config->camera, "METADATA.COMPRESSION");
     157    }
     158
     159    if (!psMetadataConfigWrite(config->user, resolved, compressMode)) {
    153160        psError(psErrorCodeLast(), false, "Unable to dump configuration to %s", filename);
    154161        psFree(resolved);
  • branches/czw_branch/20101203/psModules/src/detrend/pmNonLinear.c

    r29833 r30118  
    332332        return(0.0);
    333333    }
    334 /*     if (flux > correction_fluxes->data.F32[bin]) { */
    335 /*      return(0.0); */
    336 /*     } */
    337334 
    338335    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     
    347344    }
    348345
    349 /*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
    350 /*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
    351 /*     return(1.0); */
    352 /*   } */
    353  
    354 /*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
    355346    if (!isfinite(result)) {
    356347        result = 0.0;
    357348    }
    358 /*     if (result <= 0) { */
    359 /*      result = 1.0; */
    360 /*     } */
    361349    return(result);
    362350}
     
    372360        return(0.0);
    373361    }
    374 /*     if (flux > correction_fluxes->data.F32[bin]) { */
    375 /*      return(0.0); */
    376 /*     } */
    377362
    378363    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     
    389374    }
    390375
    391 /*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
    392 /*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
    393 /*     return(1.0); */
    394 /*   } */
    395  
    396 /*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
    397376    if (!isfinite(result)) {
    398377        result = 0.0;
    399378    }
    400 /*     if (result <= 0) { */
    401 /*      result = 1.0; */
    402 /*     } */
    403379    return(result);
    404380}
    405 
    406  
    407  
  • branches/czw_branch/20101203/psModules/src/objects

  • branches/czw_branch/20101203/psModules/src/objects/pmPSF_IO.c

    r29004 r30118  
    6262#include "pmSourceIO.h"
    6363
     64bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header);
     65
    6466bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
    6567{
     
    851853
    852854    // read the psf clump data for each region
     855    status = false;
    853856    if (roAnalysis) {
    854         int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN");
    855         if (!status) {
    856             // read old-style psf clump data
    857 
    858             char regionName[64];
    859             snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
    860             psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
    861 
    862             psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    863             if (!regionMD) {
    864                 regionMD = psMetadataAlloc();
    865                 psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    866                 psFree (regionMD);
    867             }
    868 
    869             // psf clump data
    870             pmPSFClump psfClump;
    871 
    872             psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  assert(status);
    873             psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  assert(status);
    874             psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  assert(status);
    875             psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  assert(status);
    876 
    877             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    878             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    879             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    880             psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    881         } else {
    882             psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
    883 
    884             for (int i = 0; i < nRegions; i++) {
    885                 char key[10];
    886                 char regionName[64];
    887                 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
    888 
    889                 psMetadata *regionMD = psMetadataLookupPtr (&status, roAnalysis, regionName);
    890                 if (!regionMD) {
    891                     regionMD = psMetadataAlloc();
    892                     psMetadataAddMetadata (roAnalysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
    893                     psFree (regionMD);
    894                 }
    895 
    896                 // psf clump data
    897                 pmPSFClump psfClump;
    898 
    899                 snprintf (key, 9, "CLX_%03d", i);
    900                 psfClump.X  = psMetadataLookupF32 (&status, header, key);  assert(status);
    901                 snprintf (key, 9, "CLY_%03d", i);
    902                 psfClump.Y  = psMetadataLookupF32 (&status, header, key);  assert(status);
    903                 snprintf (key, 9, "CLDX_%03d", i);
    904                 psfClump.dX = psMetadataLookupF32 (&status, header, key);  assert(status);
    905                 snprintf (key, 9, "CLDY_%03d", i);
    906                 psfClump.dY = psMetadataLookupF32 (&status, header, key);  assert(status);
    907 
    908                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
    909                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
    910                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
    911                 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
    912             }
    913         }
     857        status = pmPSFmodelReadPSFClump (roAnalysis, header);
     858        if (!status) {
     859            psMetadataAddS32 (roAnalysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 0);
     860        }
     861    }
     862    if (!roAnalysis || !status) {
     863        psWarning ("no PSF.CLUMP data available for PSF model");
    914864    }
    915865
     
    11231073}
    11241074
    1125 // XXX pmPSF to/from Metadata functions were defined for 1.22 and earlier, but were dropped
     1075bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header) {
     1076
     1077    bool status = false;;
     1078
     1079    int nRegions = psMetadataLookupS32 (&status, header, "PSF_CLN");
     1080    if (!status) {
     1081        // read old-style psf clump data
     1082
     1083        char regionName[64];
     1084        snprintf (regionName, 64, "PSF.CLUMP.REGION.000");
     1085        psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     1086
     1087        if (!regionMD) {
     1088            regionMD = psMetadataAlloc();
     1089            psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     1090            psFree (regionMD);
     1091        }
     1092
     1093        // psf clump data
     1094        pmPSFClump psfClump;
     1095        psfClump.X  = psMetadataLookupF32 (&status, header, "PSF_CLX" );  if (!status) return false;
     1096        psfClump.Y  = psMetadataLookupF32 (&status, header, "PSF_CLY" );  if (!status) return false;
     1097        psfClump.dX = psMetadataLookupF32 (&status, header, "PSF_CLDX");  if (!status) return false;
     1098        psfClump.dY = psMetadataLookupF32 (&status, header, "PSF_CLDY");  if (!status) return false;
     1099
     1100        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     1101        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     1102        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     1103        psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     1104        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", 1);
     1105    } else {
     1106        for (int i = 0; i < nRegions; i++) {
     1107            char key[10];
     1108            char regionName[64];
     1109            snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);
     1110
     1111            psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName);
     1112            if (!regionMD) {
     1113                regionMD = psMetadataAlloc();
     1114                psMetadataAddMetadata (analysis, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);
     1115                psFree (regionMD);
     1116            }
     1117
     1118            // psf clump data
     1119            pmPSFClump psfClump;
     1120
     1121            snprintf (key, 9, "CLX_%03d", i);
     1122            psfClump.X  = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1123            snprintf (key, 9, "CLY_%03d", i);
     1124            psfClump.Y  = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1125            snprintf (key, 9, "CLDX_%03d", i);
     1126            psfClump.dX = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1127            snprintf (key, 9, "CLDY_%03d", i);
     1128            psfClump.dY = psMetadataLookupF32 (&status, header, key);  if (!status) return false;
     1129
     1130            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X",  PS_META_REPLACE, "psf clump center", psfClump.X);
     1131            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y",  PS_META_REPLACE, "psf clump center", psfClump.Y);
     1132            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);
     1133            psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);
     1134        }
     1135        psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS",  PS_META_REPLACE, "psf clump regions", nRegions);
     1136    }
     1137    return true;
     1138}
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtry.h

    r25754 r30118  
    100100bool pmPSFtryFitEXT (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
    101101
    102 bool pmPSFtryMakePSF (pmPSFtry *psfTry);
     102bool pmPSFtryMakePSF (bool *pGoodFit, pmPSFtry *psfTry);
    103103
    104104bool pmPSFtryFitPSF (pmPSFtry *psfTry, pmPSFOptions *options, psImageMaskType maskVal, psImageMaskType markVal);
     
    123123);
    124124
    125 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
     125bool pmPSFFitShapeParams (bool *pGoodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask);
    126126
    127127float psVectorSystematicError (psVector *residuals, psVector *errors, float clipFraction);
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtryMakePSF.c

    r29004 r30118  
    5050Note: some of the array entries may be NULL (failed fits); ignore them.
    5151 *****************************************************************************/
    52 bool pmPSFtryMakePSF (pmPSFtry *psfTry)
     52bool pmPSFtryMakePSF (bool *pGoodFit, pmPSFtry *psfTry)
    5353{
    5454    PS_ASSERT_PTR_NON_NULL(psfTry, false);
     
    7474
    7575    // fit the shape parameters (SXX, SYY, SXY) as a function of position
    76     if (!pmPSFFitShapeParams (psf, psfTry->sources, x, y, srcMask)) {
     76    if (!pmPSFFitShapeParams (pGoodFit, psf, psfTry->sources, x, y, srcMask)) {
    7777        psFree(x);
    7878        psFree(y);
    7979        return false;
     80    }
     81    if (!*pGoodFit) {
     82        psWarning ("poor fit to PSF shape parameters for trend order %d, %d, skipping\n", psf->trendNx, psf->trendNy);
     83        psFree(x);
     84        psFree(y);
     85        return true;
    8086    }
    8187
     
    115121        // the mask is carried from previous steps and updated with this operation
    116122        // the weight is either the flux error or NULL, depending on 'psf->poissonErrorParams'
    117         if (!pmTrend2DFit (trend, srcMask, 0xff, x, y, z, NULL)) {
     123        if (!pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, z, NULL)) {
    118124            psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
    119125            psFree(x);
     
    122128            return false;
    123129        }
     130        if (!*pGoodFit) {
     131            // if we do not get a good fit (but do not actually hit an error),
     132            // tell the calling program to try something else
     133            psWarning ("poor fit to PSF parameter %d for trend order %d, %d, skipping\n", i, psf->trendNx, psf->trendNy);
     134            psFree(x);
     135            psFree(y);
     136            psFree(z);
     137            return true;
     138        }
    124139        if (trend->mode == PM_TREND_MAP) {
    125140            // p_psImagePrint (2, trend->map->map, "param N Before"); // XXX TEST:
     
    139154
    140155            pmModel *modelPSF = pmModelFromPSF (source->modelEXT, psf);
     156            if (!modelPSF) {
     157                fprintf(f, "modelPSF is NULL\n");
     158                break;
     159            }
     160            if (!source->modelEXT) {
     161                fprintf(f, "source->modelEXT is NULL\n");
     162                break;
     163            }
    141164
    142165            fprintf (f, "%f %f : ", source->modelEXT->params->data.F32[PM_PAR_XPOS], source->modelEXT->params->data.F32[PM_PAR_YPOS]);
     
    163186
    164187// fit the shape parameters using the supplied order (pmPSF->trendNx,trendNy)
    165 bool pmPSFFitShapeParams (pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
     188bool pmPSFFitShapeParams (bool *pGoodFit, pmPSF *psf, psArray *sources, psVector *x, psVector *y, psVector *srcMask) {
    166189
    167190    // we are doing a robust fit.  after each pass, we drop points which are more deviant than
     
    219242        trend = psf->params->data[PM_PAR_E0];
    220243        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    221         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e0, NULL);
     244        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e0, NULL);
     245        if (!*pGoodFit) {
     246            psFree (e0);
     247            psFree (e1);
     248            psFree (e2);
     249            return true;
     250        }
    222251        mean = psStatsGetValue (trend->stats, meanOption);
    223252        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    228257        trend = psf->params->data[PM_PAR_E1];
    229258        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    230         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e1, NULL);
     259        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e1, NULL);
     260        if (!*pGoodFit) {
     261            psFree (e0);
     262            psFree (e1);
     263            psFree (e2);
     264            return true;
     265        }
    231266        mean = psStatsGetValue (trend->stats, meanOption);
    232267        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    237272        trend = psf->params->data[PM_PAR_E2];
    238273        trend->stats->clipIter = 1; // in allocation, this value is set to the value of nIter, but we should use 1 here
    239         status &= pmTrend2DFit (trend, srcMask, 0xff, x, y, e2, NULL);
     274        status &= pmTrend2DFit (pGoodFit, trend, srcMask, 0xff, x, y, e2, NULL);
     275        if (!*pGoodFit) {
     276            psFree (e0);
     277            psFree (e1);
     278            psFree (e2);
     279            return true;
     280        }
    240281        mean = psStatsGetValue (trend->stats, meanOption);
    241282        stdev = psStatsGetValue (trend->stats, stdevOption);
     
    246287        if (!status) {
    247288            psError (PS_ERR_UNKNOWN, true, "failed to fit PSF shape params");
     289            psFree (e0);
     290            psFree (e1);
     291            psFree (e2);
    248292            return false;
    249293        }
  • branches/czw_branch/20101203/psModules/src/objects/pmPSFtryModel.c

    r29004 r30118  
    136136
    137137        // stage 2: construct a psf (pmPSF) from this collection of model fits, including the 2D variation
    138         if (!pmPSFtryMakePSF (psfTry)) {
     138        bool goodFit = false;
     139        if (!pmPSFtryMakePSF (&goodFit, psfTry)) {
    139140            psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
    140141            psFree(psfTry);
    141142            return NULL;
    142143        }
     144        if (!goodFit) {
     145            psWarning ("poor psf fit for order %d, skipping\n", i);
     146            continue;
     147        }
    143148
    144149        // stage 3: refit with fixed shape parameters, measure pmPSFtry->metric
     
    169174    }
    170175    psFree (srcMask);
     176
     177    if (!minPSF) {
     178        psError(PS_ERR_UNKNOWN, false, "failed to construct a valid psf model from the sources");
     179        psFree(psfTry);
     180        return NULL;
     181    }
    171182
    172183    // keep the ones matching the min systematic error:
  • branches/czw_branch/20101203/psModules/src/objects/pmSource.c

    r29546 r30118  
    189189    // pixels.  Modifying these pixels (ie, subtracting the model) will affect the pixels seen
    190190    // by all copies.
    191     source->pixels   = psImageCopyView(NULL, in->pixels);
    192     source->variance   = psImageCopyView(NULL, in->variance);
     191    source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
     192    source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
    193193    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
    194194
  • branches/czw_branch/20101203/psModules/src/objects/pmSourcePhotometry.c

    r29546 r30118  
    107107    // XXX handle negative flux, low-significance
    108108    if (model->dparams->data.F32[PM_PAR_I0] > 0) {
    109         SN = model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0];
     109        SN = fabs(model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);
    110110        source->errMag = 1.0 / SN;
    111111    } else {
     
    331331    }
    332332    if (apFluxOut) *apFluxOut = apFlux;
    333     if (apFluxErr) *apFluxErr = sqrt(apFluxVar);
     333    if (apFluxErr) *apFluxErr = sqrt(fabs(apFluxVar));
    334334
    335335    if (apFlux <= 0) {
  • branches/czw_branch/20101203/psModules/src/objects/pmTrend2D.c

    r25754 r30118  
    179179}
    180180
    181 bool pmTrend2DFit(pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
     181bool pmTrend2DFit(bool *pGoodFit, pmTrend2D *trend, psVector *mask, psVectorMaskType maskVal, const psVector *x,
    182182                  const psVector *y, const psVector *f, const psVector *df)
    183183{
     
    188188    PS_ASSERT_VECTOR_NON_NULL(f, false);
    189189
    190     bool status;
     190    bool status = false;
     191    *pGoodFit = false;
     192    // for the psImageMap fit, it is possible to have valid data but no valid solution for
     193    // example, an isolated cell may not be reached from other cells, making the solution
     194    // degenerate.  psImageMapFit should probably handle this case, but until it does, we allow
     195    // it to fail on the result, but not yield an error (pGoodFit = false).
     196    // psVectorClipFitPolynomial2D can not fail in this way (really?), so pGoodFit is always
     197    // true
     198
    191199    switch (trend->mode) {
    192200      case PM_TREND_POLY_ORD:
     
    196204        // of points in the image, and potentially based on the fractional range of the
    197205        // data?
     206        *pGoodFit = true;
    198207        break;
    199208
     
    201210        // XXX supply fraction from trend elements
    202211        // XXX need to add the API which adjusts the scale
    203         status = psImageMapClipFit(trend->map, trend->stats, mask, maskVal, x, y, f, df);
     212        status = psImageMapClipFit(pGoodFit, trend->map, trend->stats, mask, maskVal, x, y, f, df);
    204213        break;
    205214
  • branches/czw_branch/20101203/psModules/src/objects/pmTrend2D.h

    r29004 r30118  
    7676    );
    7777
    78 bool pmTrend2DFit(pmTrend2D *trend,
     78bool pmTrend2DFit(bool *goodFit,
     79                  pmTrend2D *trend,
    7980                  psVector *mask,       // Warning: mask is modified!
    8081                  psVectorMaskType maskVal,
  • branches/czw_branch/20101203/psphot

  • branches/czw_branch/20101203/psphot/src/Makefile.am

    r29004 r30118  
    103103        psphotCleanup.c
    104104
    105 
    106 
    107 # # psphot analysis of the detectability of specified positions
    108 # psphotDetect_SOURCES =            \
    109 #         psphotDetect.c            \
    110 #       psphotDetectArguments.c   \
    111 #       psphotDetectParseCamera.c \
    112 #       psphotDetectImageLoop.c   \
    113 #       psphotDetectReadout.c     \
    114 #       psphotMosaicChip.c        \
    115 #       psphotCleanup.c
    116 
    117105# psphotTest_SOURCES = \
    118106#         psphotTest.c
     
    137125        psphotReadoutFindPSF.c         \
    138126        psphotReadoutKnownSources.c    \
     127        psphotReadoutForcedKnownSources.c    \
    139128        psphotReadoutMinimal.c         \
    140129        psphotModelBackground.c        \
  • branches/czw_branch/20101203/psphot/src/psphot.h

    r29608 r30118  
    2424bool            psphotModelTest (pmConfig *config, const pmFPAview *view, psMetadata *recipe);
    2525bool            psphotInit (void);
    26 bool            psphotReadout (pmConfig *config, const pmFPAview *view);
    27 bool            psphotReadoutFindPSF(pmConfig *config, const pmFPAview *view, psArray *inSources);
    28 bool            psphotReadoutKnownSources(pmConfig *config, const pmFPAview *view, psArray *inSources);
    29 bool            psphotReadoutMinimal(pmConfig *config, const pmFPAview *view);
     26bool            psphotReadout (pmConfig *config, const pmFPAview *view, const char *filerule);
     27bool            psphotReadoutFindPSF(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources);
     28bool            psphotReadoutKnownSources(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources);
     29bool            psphotReadoutForcedKnownSources(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources);
     30bool            psphotReadoutMinimal(pmConfig *config, const pmFPAview *view, const char *filerule);
    3031
    3132bool            psphotReadoutCleanup (pmConfig *config, const pmFPAview *view, const char *filerule);
     
    219220bool            psphotFitSummary (void);
    220221
    221 bool            psphotLoadPSF (pmConfig *config, const pmFPAview *view);
     222bool            psphotLoadPSF (pmConfig *config, const pmFPAview *view, const char *filerule);
    222223bool            psphotLoadPSFReadout (pmConfig *config, const pmFPAview *view, const char *outFilename, const char *inFilename, int index);
    223224
     
    304305pmConfig *psphotForcedArguments(int argc, char **argv);
    305306bool psphotForcedImageLoop (pmConfig *config);
    306 bool psphotForcedReadout(pmConfig *config, const pmFPAview *view);
     307bool psphotForcedReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
    307308
    308309pmConfig *psphotMakePSFArguments(int argc, char **argv);
    309310bool psphotMakePSFImageLoop (pmConfig *config);
    310 bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view);
     311bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view, const char *filerule);
     312
     313int psphotFileruleCount(const pmConfig *config, const char *filerule);
     314
     315bool psphotAddKnownSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources);
     316
    311317
    312318/**** psphotStack prototypes ****/
     
    432438pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize);
    433439
     440bool psphotCleanInputs (pmConfig *config, const pmFPAview *view, const char *filerule);
     441
    434442#endif
  • branches/czw_branch/20101203/psphot/src/psphotAddNoise.c

    r29004 r30118  
    1818    psAssert (recipe, "missing recipe?");
    1919
    20     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    21     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     20    int num = psphotFileruleCount(config, filerule);
    2221
    2322    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotApResid.c

    r29548 r30118  
    1313    psAssert (recipe, "missing recipe?");
    1414
    15     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    16     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     15    int num = psphotFileruleCount(config, filerule);
    1716
    1817    // skip the chisq image (optionally?)
     
    7271    if (!measureAptrend) {
    7372        // save nan values since these were not calculated
    74         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APMIFIT",  PS_DATA_F32 | PS_META_REPLACE, "aperture residual",   NAN);
    75         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN);
    76         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0);
    77         psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN);
     73        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APMIFIT", PS_META_REPLACE, "aperture residual",   NAN);
     74        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_META_REPLACE, "ap residual scatter", NAN);
     75        psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_META_REPLACE, "number of apresid stars", 0);
     76        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",  PS_META_REPLACE, "aperture loss (mag)", NAN);
    7877        return true;
    7978    }
     
    325324
    326325    // save results for later output
    327     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APMIFIT",  PS_DATA_F32 | PS_META_REPLACE, "aperture residual",   psf->ApResid);
    328     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", psf->dApResid);
    329     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", psf->nApResid);
    330     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", psf->growth ? psf->growth->apLoss : NAN);
     326    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APMIFIT", PS_META_REPLACE, "aperture residual",   psf->ApResid);
     327    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_META_REPLACE, "ap residual scatter", psf->dApResid);
     328    psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_META_REPLACE, "number of apresid stars", psf->nApResid);
     329    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",  PS_META_REPLACE, "aperture loss (mag)", psf->growth ? psf->growth->apLoss : NAN);
    331330
    332331    psLogMsg ("psphot.apresid", PS_LOG_DETAIL, "aperture residual: %f +/- %f\n", psf->ApResid, psf->dApResid);
     
    345344escape:
    346345    // save nan values since these were not calculated
    347     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APMIFIT",  PS_DATA_F32 | PS_META_REPLACE, "aperture residual",   NAN);
    348     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN);
    349     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0);
    350     psMetadataAdd (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN);
     346    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APMIFIT", PS_META_REPLACE, "aperture residual",   NAN);
     347    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_META_REPLACE, "ap residual scatter", NAN);
     348    psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_META_REPLACE, "number of apresid stars", 0);
     349    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",  PS_META_REPLACE, "aperture loss (mag)", NAN);
    351350
    352351    psFree (xPos);
     
    379378
    380379    // XXX test for errors here
    381     if (!pmTrend2DFit (apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) {
     380    bool goodFit = false;
     381    if (!pmTrend2DFit (&goodFit, apTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft)) {
     382        // XXX this is probably a real error, and I should exit
     383        psWarning("Failed to fit trend for %d x %d map", Nx, Ny);
     384        psFree (apTrend);
     385        return NULL;
     386    }
     387    if (!goodFit) {
    382388        psWarning("Failed to fit trend for %d x %d map", Nx, Ny);
    383389        psFree (apTrend);
  • branches/czw_branch/20101203/psphot/src/psphotBasicDeblend.c

    r28013 r30118  
    44bool psphotBasicDeblend (pmConfig *config, const pmFPAview *view, const char *filerule)
    55{
    6     bool status = true;
    7 
    8     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    9     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     6    int num = psphotFileruleCount(config, filerule);
    107
    118    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotBlendFit.c

    r29017 r30118  
    1010    psAssert (recipe, "missing recipe?");
    1111
    12     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    13     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     12    int num = psphotFileruleCount(config, filerule);
    1413
    1514    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotChoosePSF.c

    r29004 r30118  
    1010    psAssert (recipe, "missing recipe?");
    1111
    12     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    13     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     12    int num = psphotFileruleCount(config, filerule);
    1413
    1514    // skip the chisq image (optionally?)
     
    250249        if (!try) {
    251250            // No big deal --- we'll try another model
    252             psErrorClear();
     251            if (i < modelNames->n - 1) {
     252                psErrorClear();
     253            }
    253254            continue;
    254255        }
  • branches/czw_branch/20101203/psphot/src/psphotDeblendSatstars.c

    r29606 r30118  
    44bool psphotDeblendSatstars (pmConfig *config, const pmFPAview *view, const char *filerule)
    55{
    6     bool status = true;
    7 
    8     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    9     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     6    int num = psphotFileruleCount(config, filerule);
    107
    118    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotEfficiency.c

    r29902 r30118  
    164164    psAssert (recipe, "missing recipe?");
    165165
    166     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    167     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     166    int num = psphotFileruleCount(config, filerule);
    168167
    169168    // skip the chisq image (optionally?)
  • branches/czw_branch/20101203/psphot/src/psphotExtendedSourceAnalysis.c

    r29027 r30118  
    2222    }
    2323
    24     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    25     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     24    int num = psphotFileruleCount(config, filerule);
    2625
    2726    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotExtendedSourceAnalysisByObject.c

    r29548 r30118  
    4141
    4242    // number of images used to define sources
    43     int nImages = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    44     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     43    int nImages = psphotFileruleCount(config, filerule);
    4544
    4645    // generate look-up arrays for readouts
  • branches/czw_branch/20101203/psphot/src/psphotExtendedSourceFits.c

    r29548 r30118  
    1616    }
    1717
    18     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    19     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     18    int num = psphotFileruleCount(config, filerule);
    2019
    2120    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotFindDetections.c

    r29548 r30118  
    1212    psAssert (recipe, "missing recipe?");
    1313
    14     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    15     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     14    int num = psphotFileruleCount(config, filerule);
    1615
    1716    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotFitSourcesLinear.c

    r29548 r30118  
    2121    assert (recipe);
    2222
    23     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    24     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     23    int num = psphotFileruleCount(config, filerule);
    2524
    2625    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotForcedImageLoop.c

    r25981 r30118  
    8484
    8585                // run the actual photometry analysis on this chip/cell/readout
    86                 if (!psphotForcedReadout (config, view)) {
     86                if (!psphotForcedReadout (config, view, "PSPHOT.INPUT")) {
    8787                    psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
    8888                    psFree (view);
  • branches/czw_branch/20101203/psphot/src/psphotForcedReadout.c

    r28013 r30118  
    11# include "psphotInternal.h"
    22
    3 bool psphotForcedReadout(pmConfig *config, const pmFPAview *view) {
     3bool psphotForcedReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
    44
    55    // measure the total elapsed time in psphotReadout.  XXX the current threading plan
     
    2020
    2121    // set the photcode for this image
    22     if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
     22    if (!psphotAddPhotcode (config, view, filerule)) {
    2323        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2424        return false;
     
    3030
    3131    // Generate the mask and weight images, including the user-defined analysis region of interest
    32     psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     32    psphotSetMaskAndVariance (config, view, filerule);
    3333    if (!strcasecmp (breakPt, "NOTHING")) {
    34         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     34        return psphotReadoutCleanup (config, view, filerule);
    3535    }
    3636
    3737    // generate a background model (median, smoothed image)
    38     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
    39         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     38    if (!psphotModelBackground (config, view, filerule)) {
     39        return psphotReadoutCleanup (config, view, filerule);
    4040    }
    41     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
    42         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     41    if (!psphotSubtractBackground (config, view, filerule)) {
     42        return psphotReadoutCleanup (config, view, filerule);
    4343    }
    4444    if (!strcasecmp (breakPt, "BACKMDL")) {
    45         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     45        return psphotReadoutCleanup (config, view, filerule);
    4646    }
    4747
    48     if (!psphotLoadPSF (config, view)) {
     48    if (!psphotLoadPSF (config, view, filerule)) {
    4949        // this only happens if we had a programming error in psphotLoadPSF
    5050        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
    51         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     51        return psphotReadoutCleanup (config, view, filerule);
    5252    }
    5353
    5454    // include externally-supplied sources
    55     psphotLoadExtSources (config, view, "PSPHOT.INPUT");
     55    psphotLoadExtSources (config, view, filerule);
    5656
    5757    // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    58     psphotGuessModels (config, view, "PSPHOT.INPUT");
     58    psphotGuessModels (config, view, filerule);
    5959
    6060    // merge the newly selected sources into the existing list
    6161    // NOTE: merge OLD and NEW
    62     psphotMergeSources (config, view, "PSPHOT.INPUT");
     62    psphotMergeSources (config, view, filerule);
    6363
    6464    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    65     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
     65    psphotFitSourcesLinear (config, view, filerule, false);
    6666
    6767    // identify CRs and extended sources
     
    7171
    7272    // calculate source magnitudes
    73     psphotMagnitudes(config, view, "PSPHOT.INPUT");
     73    psphotMagnitudes(config, view, filerule);
    7474
    7575    // XXX do I want to do this?
     
    8080
    8181    // replace background in residual image
    82     psphotSkyReplace (config, view, "PSPHOT.INPUT");
     82    psphotSkyReplace (config, view, filerule);
    8383
    8484    // drop the references to the image pixels held by each source
    85     psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
     85    psphotSourceFreePixels (config, view, filerule);
    8686
    8787    // create the exported-metadata and free local data
    88     return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     88    return psphotReadoutCleanup (config, view, filerule);
    8989}
  • branches/czw_branch/20101203/psphot/src/psphotGuessModels.c

    r29605 r30118  
    1212    bool status = true;
    1313
    14     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    15     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     14    int num = psphotFileruleCount(config, filerule);
    1615
    1716    // skip the chisq image (optionally?)
     
    207206            float Xc = 0.5*readout->image->numCols;
    208207            float Yc = 0.5*readout->image->numRows;
    209             pmModel *modelPSF = pmModelFromPSFforXY(psf, Xc, Yc, Io);
     208            modelPSF = pmModelFromPSFforXY(psf, Xc, Yc, Io);
    210209            if (modelPSF == NULL) {
    211210                psError(PSPHOT_ERR_PSF, false, "Failed to determine PSF model at center of image");
  • branches/czw_branch/20101203/psphot/src/psphotImageLoop.c

    r29548 r30118  
    109109
    110110                // run the actual photometry analysis on this chip/cell/readout
    111                 if (!psphotReadout (config, view)) {
     111                if (!psphotReadout (config, view, "PSPHOT.INPUT")) {
    112112                    psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
    113113                    psFree (view);
  • branches/czw_branch/20101203/psphot/src/psphotImageQuality.c

    r28013 r30118  
    1313    psAssert (recipe, "missing recipe?");
    1414
    15     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    16     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     15    int num = psphotFileruleCount(config, filerule);
    1716
    1817    // skip the chisq image (optionally?)
     
    9998        // r^2 sin(2t) = r^2 2 cos t sin t = 2 x y
    10099
    101         // r^2 cos(3t) = r^2 cos^3 t - r^2 3 cos t sin^2 t = (x^3 - 3 x y^2) / r
    102         // r^2 sin(3t) = r^2 3 cos^2 t sin t - sin^3 t = (3 x^2 y - y^3) / r
    103 
    104         // r^2 cos(4t) = r^2 cos^4 t - r^2 6 cos^2 t sin^2 t + r^2 sin^4 t = (x^4 - 6 x^2 y^2 + y^4) / r^2
    105         // r^2 sin(4t) = r^2 4 cos^3 t sin t - 4 sin^3 t cos t = (4 x^3 y - 4 y^3 x) / r^2
     100        // r^3 cos(3t) = r^3 cos^3 t - r^2 3 cos t sin^2 t = (x^3 - 3 x y^2)
     101        // r^3 sin(3t) = r^3 3 cos^2 t sin t - sin^3 t = (3 x^2 y - y^3)
     102
     103        // r^4 cos(4t) = r^4 cos^4 t - r^2 6 cos^2 t sin^2 t + r^2 sin^4 t = (x^4 - 6 x^2 y^2 + y^4)
     104        // r^4 sin(4t) = r^4 4 cos^3 t sin t - 4 sin^3 t cos t = (4 x^3 y - 4 y^3 x)
    106105
    107106        num++;
  • branches/czw_branch/20101203/psphot/src/psphotLoadPSF.c

    r26894 r30118  
    66
    77// XXX for now (2010.01.27), the supporting programs do not define multiple PSPHOT.PSF.LOAD
    8 // files to go with multiple PSPHOT.INPUT files.  as a result, the implementation below is
     8// files to go with multiple input files.  as a result, the implementation below is
    99// currently going to work for the case of a single input file, but will fail if we try with a
    1010// stack of images.
     
    5959}
    6060
    61 bool psphotLoadPSF (pmConfig *config, const pmFPAview *view) {
     61// PSPHOT.PSF.LOAD vs input file -- see note at top
     62bool psphotLoadPSF (pmConfig *config, const pmFPAview *view, const char *filerule) {
    6263
    63     bool status = false;
    64 
    65     // XXX PSPHOT.PSF.LOAD vs PSPHOT.INPUT -- see note at top
    66     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    67     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     64    int num = psphotFileruleCount(config, filerule);
    6865
    6966    // loop over the available readouts
     
    7168
    7269        // Generate the mask and weight images, including the user-defined analysis region of interest
    73         if (!psphotLoadPSFReadout (config, view, "PSPHOT.INPUT", "PSPHOT.PSF.LOAD", i)) {
     70        if (!psphotLoadPSFReadout (config, view, filerule, "PSPHOT.PSF.LOAD", i)) {
    7471            psError (PSPHOT_ERR_CONFIG, false, "failed to load PSF model for PSPHOT.PSF.LOAD entry %d", i);
    7572            return false;
  • branches/czw_branch/20101203/psphot/src/psphotMagnitudes.c

    r29004 r30118  
    99    psAssert (recipe, "missing recipe?");
    1010
    11     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    12     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     11    int num = psphotFileruleCount(config, filerule);
    1312
    1413    // skip the chisq image (optionally?)
  • branches/czw_branch/20101203/psphot/src/psphotMakeFluxScale.c

    r25755 r30118  
    5555    fPts->n = Npts;
    5656
    57     if (!pmTrend2DFit (trend, NULL, 0xff, xPts, yPts, fPts, NULL)) {
     57    // XXX we should allow the spatial sampling to decrease if the fit fails
     58    bool goodFit = false;
     59    if (!pmTrend2DFit (&goodFit, trend, NULL, 0xff, xPts, yPts, fPts, NULL)) {
    5860        psError(PS_ERR_UNKNOWN, false, "Unable to fit trend");
     61        success = false;
     62        goto DONE;
     63    }
     64    if (!goodFit) {
     65        psError(PS_ERR_UNKNOWN, false, "poor fit to flux-scale trend");
    5966        success = false;
    6067        goto DONE;
  • branches/czw_branch/20101203/psphot/src/psphotMakePSFImageLoop.c

    r25982 r30118  
    8484
    8585                // run the actual photometry analysis on this chip/cell/readout
    86                 if (!psphotMakePSFReadout (config, view)) {
     86                if (!psphotMakePSFReadout (config, view, "PSPHOT.INPUT")) {
    8787                    psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
    8888                    psFree (view);
  • branches/czw_branch/20101203/psphot/src/psphotMakePSFReadout.c

    r28013 r30118  
    11# include "psphotInternal.h"
    22
    3 bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view) {
     3bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
    44
    55    // measure the total elapsed time in psphotReadout.  XXX the current threading plan
     
    1919
    2020    // set the photcode for this image
    21     if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
     21    if (!psphotAddPhotcode (config, view, filerule)) {
    2222        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2323        return false;
     
    2929
    3030    // Generate the mask and weight images, including the user-defined analysis region of interest
    31     psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     31    psphotSetMaskAndVariance (config, view, filerule);
    3232    if (!strcasecmp (breakPt, "NOTHING")) {
    33         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     33        return psphotReadoutCleanup (config, view, filerule);
    3434    }
    3535
    3636    // generate a background model (median, smoothed image)
    37     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
    38         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     37    if (!psphotModelBackground (config, view, filerule)) {
     38        return psphotReadoutCleanup (config, view, filerule);
    3939    }
    40     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
    41         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     40    if (!psphotSubtractBackground (config, view, filerule)) {
     41        return psphotReadoutCleanup (config, view, filerule);
    4242    }
    4343    if (!strcasecmp (breakPt, "BACKMDL")) {
    44         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     44        return psphotReadoutCleanup (config, view, filerule);
    4545    }
    4646
    47     psphotLoadExtSources (config, view, "PSPHOT.INPUT");
     47    psphotLoadExtSources (config, view, filerule);
    4848
    4949    // If sources have been supplied, then these should be used to measure the PSF include
     
    5353    // a text file have no valid SN values, but psphotChoosePSF needs to select the top
    5454    // PSF_MAX_NSTARS to generate the PSF.
    55     if (!psphotCheckExtSources (config, view, "PSPHOT.INPUT")) {
     55    if (!psphotCheckExtSources (config, view, filerule)) {
    5656        psLogMsg ("psphot", 3, "failure to select possible PSF sources (external or internal)");
    57         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     57        return psphotReadoutCleanup (config, view, filerule);
    5858    }
    5959
    6060    // Use bright stellar objects to measure PSF. If we do not have enough stars to generate
    6161    // the PSF, build one from the SEEING guess and model class
    62     if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) {
     62    if (!psphotChoosePSF (config, view, filerule)) {
    6363        psLogMsg ("psphot", 3, "failure to construct a psf model");
    64         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     64        return psphotReadoutCleanup (config, view, filerule);
    6565    }
    6666
    6767    // measure aperture photometry corrections
    6868# if 0
    69     if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
     69    if (!psphotApResid (config, view, filerule)) {
    7070        psLogMsg ("psphot", 3, "failed on psphotApResid");
    71         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     71        return psphotReadoutCleanup (config, view, filerule);
    7272    }
    7373# endif
    7474
    75     return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     75    return psphotReadoutCleanup (config, view, filerule);
    7676}
  • branches/czw_branch/20101203/psphot/src/psphotMaskReadout.c

    r28013 r30118  
    99    psAssert (recipe, "missing recipe?");
    1010
    11     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    12     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     11    int num = psphotFileruleCount(config, filerule);
    1312
    1413    // loop over the available readouts
     
    1716        // Generate the mask and weight images, including the user-defined analysis region of interest
    1817        if (!psphotSetMaskAndVarianceReadout (config, view, filerule, i, recipe)) {
    19             psError (PSPHOT_ERR_CONFIG, false, "failed to generate mask for PSPHOT.INPUT entry %d", i);
     18            psError (PSPHOT_ERR_CONFIG, false, "failed to generate mask for %s entry %d", filerule, i);
    2019            return false;
    2120        }
  • branches/czw_branch/20101203/psphot/src/psphotMergeSources.c

    r28013 r30118  
    88bool psphotMergeSources (pmConfig *config, const pmFPAview *view, const char *filerule)
    99{
    10     bool status = true;
    11 
    12     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    13     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     10    int num = psphotFileruleCount(config, filerule);
    1411
    1512    // loop over the available readouts
     
    7067// XXX This function needs to be updated to loop over set of input files.  At the moment, we
    7168// only expect a single entry for PSPHOT.INPUT.CMF and PSPHOT.SOURCES.TEXT, so we can only
    72 // associate input sources with a single entry for PSPHOT.INPUT
     69// associate input sources with a single entry for the filerule
    7370bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, const char *filerule) {
    7471
     
    166163}
    167164
     165// copy the known sources (as external) to the detection list of the given filerule
     166bool psphotAddKnownSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources) {
     167
     168    bool status = false;
     169
     170    // select the appropriate recipe information
     171    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE);
     172    psAssert (recipe, "missing recipe?");
     173
     174    // determine properties (sky, moments) of initial sources
     175    float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
     176    psAssert (status, "missing SKY_OUTER_RADIUS in recipe?");
     177
     178    // XXX this seems like an arbitrary number...
     179    OUTER = PS_MAX(OUTER, 20.0); // XXX Guarantee that we can encompass the max moments radius
     180
     181    // find the currently selected readout
     182    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, 0); // File of interest
     183    psAssert (file, "missing file?");
     184
     185    pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);
     186    psAssert (readout, "missing readout?");
     187
     188    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
     189    if (!detections) {
     190        detections = pmDetectionsAlloc();
     191        detections->newSources = psArrayAllocEmpty (100);
     192        // save detections on the readout->analysis
     193        if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detections)) {
     194            psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout");
     195            return false;
     196        }
     197    } else {
     198        psMemIncrRefCounter(detections); // so we can free the detections below
     199    }
     200
     201    // copy the sources from inSources to the new detection structure
     202    for (int i = 0; i < inSources->n; i++) {
     203      pmSource *inSource = inSources->data[i];
     204
     205      pmSource *newSource = pmSourceCopy(inSource);
     206      newSource->mode |= PM_SOURCE_MODE_EXTERNAL;
     207     
     208      // drop the loaded source modelPSF
     209      psFree (newSource->modelPSF);
     210      // source->modelPSF = NULL;  check this!
     211
     212      // drop the references to the original image pixels:
     213      pmSourceFreePixels (newSource);
     214
     215      // allocate image, weight, mask for the new image for each peak (square of radius OUTER)
     216      pmSourceDefinePixels (newSource, readout, newSource->peak->x, newSource->peak->y, OUTER);
     217
     218      newSource->imageID = 0;
     219      // XXX reset the source ID? raised questions about the meaning of this ID...
     220      // P_PM_SOURCE_SET_ID(source, i);
     221
     222      psArrayAdd (detections->newSources, 100, newSource);
     223    }
     224    psLogMsg ("psphot", 3, "%ld known sources supplied", detections->newSources->n);
     225
     226    psFree (detections);
     227    return true;
     228}
     229
    168230// extract the input sources corresponding to this readout
    169231// XXX this function needs to be updated to work with the new context of psphot inputs
     
    405467    bool status = true;
    406468
    407     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    408     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     469    int num = psphotFileruleCount(config, ruleSrc);
    409470
    410471    // skip the chisq image because it is a duplicate of the detection version
  • branches/czw_branch/20101203/psphot/src/psphotModelBackground.c

    r28013 r30118  
    383383}
    384384
    385 // XXX supply filename or keep PSPHOT.INPUT fixed?
    386385bool psphotModelBackground (pmConfig *config, const pmFPAview *view, const char *filerule)
    387386{
    388     bool status = false;
    389 
    390     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    391     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     387    int num = psphotFileruleCount(config, filerule);
    392388
    393389    // loop over the available readouts
    394390    for (int i = 0; i < num; i++) {
    395391        if (!psphotModelBackgroundReadoutFileIndex(config, view, filerule, i)) {
    396             psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
     392            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for %s entry %d", filerule, i);
    397393            return false;
    398394        }
  • branches/czw_branch/20101203/psphot/src/psphotOutput.c

    r29902 r30118  
    11# include "psphotInternal.h"
     2
     3// convert filerule to filerule.NUM and look up in the config->arguments metadata
     4int psphotFileruleCount(const pmConfig *config, const char *filerule) {
     5
     6    bool status = false;
     7
     8    psString name = NULL;
     9    psStringAppend(&name, "%s.NUM", filerule);
     10    int num = psMetadataLookupS32 (&status, config->arguments, name);
     11    if (!status) {
     12      // we only explicitly define (filerule.NUM) if we have more than 1
     13      num = 1;
     14    }
     15    psFree (name);
     16    return num;
     17}
    218
    319pmReadout *psphotSelectBackground (pmConfig *config,
     
    6379    fclose (f);
    6480    return true;
    65 }
    66 
    67 // XXX replace this with a call to a pmConfig function (pmConfigDump...)
    68 bool psphotDumpConfig (pmConfig *config) {
    69 
    70   psMetadataConfigWrite (config->user, "user.md");
    71   psMetadataConfigWrite (config->camera, "camera.md");
    72   psMetadataConfigWrite (config->recipes, "recipes.md");
    73   psMetadataConfigWrite (config->arguments, "arguments.md");
    74   psMetadataConfigWrite (config->files, "files.md");
    75   return true;
    7681}
    7782
     
    126131}
    127132
     133bool psphotCleanInputsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index);
     134bool psphotCleanInputs (pmConfig *config, const pmFPAview *view, const char *filerule) {
     135
     136    int num = psphotFileruleCount(config, filerule);
     137
     138    // loop over the available readouts
     139    for (int i = 0; i < num; i++) {
     140        if (!psphotCleanInputsReadout (config, view, filerule, i)) {
     141          psError (PSPHOT_ERR_CONFIG, false, "failed to clean inputs for %s entry %d", filerule, i);
     142            return false;
     143        }
     144    }
     145    return true;
     146}
     147
     148bool psphotCleanInputsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index) {
     149
     150    pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest
     151    PS_ASSERT (file, false);
     152
     153    pmReadout  *readout = pmFPAviewThisReadout (view, file->fpa);
     154
     155    // XXX anything else to remove?
     156    if (psMetadataLookup(readout->analysis, "PSPHOT.DETECTIONS")) {
     157        psMetadataRemoveKey(readout->analysis, "PSPHOT.DETECTIONS");
     158    }
     159
     160    return true;
     161}
     162
    128163bool psphotAddPhotcode (pmConfig *config, const pmFPAview *view, const char *filerule) {
    129164
    130     bool status = false;
    131 
    132     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    133     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     165    int num = psphotFileruleCount(config, filerule);
    134166
    135167    // loop over the available readouts
    136168    for (int i = 0; i < num; i++) {
    137169        if (!psphotAddPhotcodeReadout (config, view, filerule, i)) {
    138             psError (PSPHOT_ERR_CONFIG, false, "failed to add photcode to PSPHOT.INPUT entry %d", i);
     170          psError (PSPHOT_ERR_CONFIG, false, "failed to add photcode to %s entry %d", filerule, i);
    139171            return false;
    140172        }
     
    357389    // XXX need alternative output function
    358390    // psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf);
    359     // psMetadataConfigWrite (psfData, "psfmodel.dat");
     391    // psMetadataConfigWrite (psfData, "psfmodel.dat", NULL);
    360392    psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "wrote out psf-subtracted image, psf data, exiting\n");
    361393
  • branches/czw_branch/20101203/psphot/src/psphotParseCamera.c

    r26894 r30118  
    3939        return NULL;
    4040    }
    41     // specify the number of psphot input images
    42     psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
    4341
    4442    // define the additional input/output files associated with psphot
  • branches/czw_branch/20101203/psphot/src/psphotRadialApertures.c

    r28013 r30118  
    1818    }
    1919
    20     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    21     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     20    int num = psphotFileruleCount(config, filerule);
    2221
    2322    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotRadialAperturesByObject.c

    r28013 r30118  
    2121
    2222    // number of images used to define sources
    23     int nImages = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    24     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     23    int nImages = psphotFileruleCount(config, filerule);
    2524
    2625    // radMax stores the upper bounds of the annuli
  • branches/czw_branch/20101203/psphot/src/psphotRadiusChecks.c

    r29004 r30118  
    135135    EXT_FIT_MAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS");
    136136
    137     float skyMean  = psMetadataLookupF32 (&status, readout->analysis, "SKY_MEAN");
    138137    float skyStdev = psMetadataLookupF32 (&status, readout->analysis, "SKY_STDEV");
    139 
    140     fprintf (stderr, "sky: %f +/- %f\n", skyMean, skyStdev);
    141138
    142139    EXT_FIT_SKY_SIG = skyStdev;
  • branches/czw_branch/20101203/psphot/src/psphotReadout.c

    r29004 r30118  
    99}
    1010
    11 bool psphotReadout(pmConfig *config, const pmFPAview *view) {
     11bool psphotReadout(pmConfig *config, const pmFPAview *view, const char *filerule) {
    1212
    1313    // measure the total elapsed time in psphotReadout.  dtime is the elapsed time used jointly
     
    2727    psAssert (breakPt, "configuration error: set BREAK_POINT");
    2828
     29    // remove cruft from the input analysis structure
     30    if (!psphotCleanInputs (config, view, filerule)) {
     31        psError (PSPHOT_ERR_PROG, false, "trouble setting up the inputs");
     32        return false;
     33    }
     34
    2935    // set the photcode for this image
    30     if (!psphotAddPhotcode (config, view, "PSPHOT.INPUT")) {
     36    if (!psphotAddPhotcode (config, view, filerule)) {
    3137        psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    3238        return false;
     
    3440
    3541    // Generate the mask and weight images, including the user-defined analysis region of interest
    36     if (!psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT")) {
    37         return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
     42    if (!psphotSetMaskAndVariance (config, view, filerule)) {
     43        return psphotReadoutCleanup(config, view, filerule);
    3844    }
    3945    if (!strcasecmp (breakPt, "NOTHING")) {
    40         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     46        return psphotReadoutCleanup (config, view, filerule);
    4147    }
    4248
    4349    // generate a background model (median, smoothed image)
    44     if (!psphotModelBackground (config, view, "PSPHOT.INPUT")) {
    45         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
    46     }
    47 
    48     if (!psphotSubtractBackground (config, view, "PSPHOT.INPUT")) {
    49         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     50    if (!psphotModelBackground (config, view, filerule)) {
     51        return psphotReadoutCleanup (config, view, filerule);
     52    }
     53
     54    if (!psphotSubtractBackground (config, view, filerule)) {
     55        return psphotReadoutCleanup (config, view, filerule);
    5056    }
    5157    if (!strcasecmp (breakPt, "BACKMDL")) {
    52         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     58        return psphotReadoutCleanup (config, view, filerule);
    5359    }
    5460
    5561    // load the psf model, if suppled.  FWHM_MAJ,FWHM_MIN,etc are determined and saved on
    56     // readout->analysis. XXX Note: this function currently only works with a single
    57     // PSPHOT.INPUT
    58     if (!psphotLoadPSF (config, view)) { // ??? need to supply 2 ?
     62    // readout->analysis. NOTE: this function currently only loads from PSPHOT.PSF.LOAD
     63    if (!psphotLoadPSF (config, view, filerule)) { // ??? need to supply 2 ?
    5964        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
    60         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     65        return psphotReadoutCleanup (config, view, filerule);
    6166    }
    6267
    6368    // find the detections (by peak and/or footprint) in the image.
    64     if (!psphotFindDetections (config, view, "PSPHOT.INPUT", true)) { // pass 1
     69    if (!psphotFindDetections (config, view, filerule, true)) { // pass 1
    6570        // this only happens if we had an error in psphotFindDetections
    6671        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
    67         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     72        return psphotReadoutCleanup (config, view, filerule);
    6873    }
    6974
    7075    // construct sources and measure basic stats (saved on detections->newSources)
    71     if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) { // pass 1
     76    if (!psphotSourceStats (config, view, filerule, true)) { // pass 1
    7277        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
    73         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     78        return psphotReadoutCleanup (config, view, filerule);
    7479    }
    7580    if (!strcasecmp (breakPt, "PEAKS")) {
    76         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     81        return psphotReadoutCleanup (config, view, filerule);
    7782    }
    7883
    7984    // find blended neighbors of very saturated stars (detections->newSources)
    80     if (!psphotDeblendSatstars (config, view, "PSPHOT.INPUT")) {
     85    if (!psphotDeblendSatstars (config, view, filerule)) {
    8186        psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis");
    82         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     87        return psphotReadoutCleanup (config, view, filerule);
    8388    }
    8489
    8590    // mark blended peaks PS_SOURCE_BLEND (detections->newSources)
    86     if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {
     91    if (!psphotBasicDeblend (config, view, filerule)) {
    8792        psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis");
    88         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     93        return psphotReadoutCleanup (config, view, filerule);
    8994    }
    9095
    9196    // classify sources based on moments, brightness.  if a PSF model has been loaded, the PSF
    9297    // clump defined for it is used not measured (detections->newSources)
    93     if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 1
     98    if (!psphotRoughClass (config, view, filerule)) { // pass 1
    9499        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications");
    95         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     100        return psphotReadoutCleanup (config, view, filerule);
    96101    }
    97102
    98103    // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources)
    99     if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) { // pass 1
     104    if (!psphotImageQuality (config, view, filerule)) { // pass 1
    100105        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
    101         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     106        return psphotReadoutCleanup (config, view, filerule);
    102107    }
    103108    if (!strcasecmp (breakPt, "MOMENTS")) {
    104         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     109        return psphotReadoutCleanup (config, view, filerule);
    105110    }
    106111
    107112    // use bright stellar objects to measure PSF if we were supplied a PSF for any input file,
    108113    // this step is skipped
    109     if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) { // pass 1
     114    if (!psphotChoosePSF (config, view, filerule)) { // pass 1
    110115        psLogMsg ("psphot", 3, "failure to construct a psf model");
    111         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     116        return psphotReadoutCleanup (config, view, filerule);
    112117    }
    113118    if (!strcasecmp (breakPt, "PSFMODEL")) {
    114         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     119        return psphotReadoutCleanup (config, view, filerule);
    115120    }
    116121
    117122    // include externally-supplied sources
    118123    // XXX fix this in the new multi-input context
    119     // psphotLoadExtSources (config, view, "PSPHOT.INPUT"); // pass 1
     124    // psphotLoadExtSources (config, view, filerule); // pass 1
    120125
    121126    // construct an initial model for each object, set the radius to fitRadius, set circular
    122127    // fit mask (detections->newSources)
    123     psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 1
     128    psphotGuessModels (config, view, filerule); // pass 1
    124129
    125130    // merge the newly selected sources into the existing list
    126131    // NOTE: merge OLD and NEW
    127     psphotMergeSources (config, view, "PSPHOT.INPUT");
     132    psphotMergeSources (config, view, filerule);
    128133
    129134    // linear PSF fit to source peaks, subtract the models from the image (in PSF mask)
    130     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false); // pass 1 (detections->allSources)
     135    psphotFitSourcesLinear (config, view, filerule, false); // pass 1 (detections->allSources)
    131136
    132137    // identify CRs and extended sources (only unmeasured sources are measured)
    133     psphotSourceSize (config, view, "PSPHOT.INPUT", true); // pass 1 (detections->allSources)
     138    psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources)
    134139    if (!strcasecmp (breakPt, "ENSEMBLE")) {
    135140        goto finish;
     
    138143    // non-linear PSF and EXT fit to brighter sources
    139144    // replace model flux, adjust mask as needed, fit, subtract the models (full stamp)
    140     psphotBlendFit (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
     145    psphotBlendFit (config, view, filerule); // pass 1 (detections->allSources)
    141146
    142147    // replace all sources
    143     psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
     148    psphotReplaceAllSources (config, view, filerule); // pass 1 (detections->allSources)
    144149
    145150    // linear fit to include all sources (subtract again)
    146151    // NOTE : apply to ALL sources (extended + psf)
    147     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 2 (detections->allSources)
     152    psphotFitSourcesLinear (config, view, filerule, true); // pass 2 (detections->allSources)
    148153
    149154    // if we only do one pass, skip to extended source analysis
     
    153158
    154159    // add noise for subtracted objects
    155     psphotAddNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
     160    psphotAddNoise (config, view, filerule); // pass 1 (detections->allSources)
    156161
    157162    // find fainter sources
    158163    // NOTE: finds new peaks and new footprints, OLD and FULL set are saved on detections
    159     psphotFindDetections (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->peaks, detections->footprints)
     164    psphotFindDetections (config, view, filerule, false); // pass 2 (detections->peaks, detections->footprints)
    160165
    161166    // remove noise for subtracted objects (ie, return to normal noise level)
    162167    // NOTE: this needs to operate only on the OLD sources
    163     psphotSubNoise (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
     168    psphotSubNoise (config, view, filerule); // pass 1 (detections->allSources)
    164169
    165170    // define new sources based on only the new peaks
    166171    // NOTE: new sources are saved on detections->newSources
    167     psphotSourceStats (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->newSources)
     172    psphotSourceStats (config, view, filerule, false); // pass 2 (detections->newSources)
    168173
    169174    // set source type
    170175    // NOTE: apply only to detections->newSources
    171     if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) { // pass 2 (detections->newSources)
     176    if (!psphotRoughClass (config, view, filerule)) { // pass 2 (detections->newSources)
    172177        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    173         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     178        return psphotReadoutCleanup (config, view, filerule);
    174179    }
    175180
    176181    // create full input models, set the radius to fitRadius, set circular fit mask
    177182    // NOTE: apply only to detections->newSources
    178     psphotGuessModels (config, view, "PSPHOT.INPUT"); // pass 2 (detections->newSources)
     183    psphotGuessModels (config, view, filerule); // pass 2 (detections->newSources)
    179184
    180185    // replace all sources so fit below applies to all at once
    181186    // NOTE: apply only to OLD sources (which have been subtracted)
    182     psphotReplaceAllSources (config, view, "PSPHOT.INPUT"); // pass 2
     187    psphotReplaceAllSources (config, view, filerule); // pass 2
    183188
    184189    // merge the newly selected sources into the existing list
    185190    // NOTE: merge OLD and NEW
    186191    // XXX check on free of sources...
    187     psphotMergeSources (config, view, "PSPHOT.INPUT"); // (detections->newSources + detections->allSources -> detections->allSources)
     192    psphotMergeSources (config, view, filerule); // (detections->newSources + detections->allSources -> detections->allSources)
    188193
    189194    // NOTE: apply to ALL sources
    190     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", true); // pass 3 (detections->allSources)
     195    psphotFitSourcesLinear (config, view, filerule, true); // pass 3 (detections->allSources)
    191196
    192197pass1finish:
     
    194199    // measure source size for the remaining sources
    195200    // NOTE: applies only to NEW (unmeasured) sources
    196     psphotSourceSize (config, view, "PSPHOT.INPUT", false); // pass 2 (detections->allSources)
    197 
    198     psphotExtendedSourceAnalysis (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
    199     psphotExtendedSourceFits (config, view, "PSPHOT.INPUT"); // pass 1 (detections->allSources)
     201    psphotSourceSize (config, view, filerule, false); // pass 2 (detections->allSources)
     202
     203    psphotExtendedSourceAnalysis (config, view, filerule); // pass 1 (detections->allSources)
     204    psphotExtendedSourceFits (config, view, filerule); // pass 1 (detections->allSources)
    200205
    201206finish:
     
    205210
    206211    // measure aperture photometry corrections
    207     if (!psphotApResid (config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
     212    if (!psphotApResid (config, view, filerule)) { // pass 1 (detections->allSources)
    208213        psLogMsg ("psphot", 3, "failed on psphotApResid");
    209         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     214        return psphotReadoutCleanup (config, view, filerule);
    210215    }
    211216
    212217    // calculate source magnitudes
    213     if (!psphotMagnitudes(config, view, "PSPHOT.INPUT")) { // pass 1 (detections->allSources)
     218    if (!psphotMagnitudes(config, view, filerule)) { // pass 1 (detections->allSources)
    214219      psErrorStackPrint(stderr, "Unable to do magnitudes.");
    215220        psErrorClear();
    216221    }
    217     if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) { // pass 1
     222    if (!psphotEfficiency(config, view, filerule)) { // pass 1
    218223        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    219224        psErrorClear();
     
    224229
    225230    // replace background in residual image
    226     if (!psphotSkyReplace (config, view, "PSPHOT.INPUT")) { // pass 1
     231    if (!psphotSkyReplace (config, view, filerule)) { // pass 1
    227232      psErrorStackPrint(stderr, "Unable to replace sky");
    228233      psErrorClear();
    229234
    230235/*       psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */
    231 /*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
     236/*       return(psphotReadoutCleanup(config, view, filerule)); */
    232237    }
    233238    // drop the references to the image pixels held by each source
    234     if (!psphotSourceFreePixels (config, view, "PSPHOT.INPUT")) { // pass 1
     239    if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1
    235240      psErrorStackPrint(stderr, "Unable to free source pixels");
    236241      psErrorClear();
    237242
    238243/*       psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */
    239 /*       return(psphotReadoutCleanup(config, view, "PSPHOT.INPUT")); */
     244/*       return(psphotReadoutCleanup(config, view, filerule)); */
    240245    }
    241246    // create the exported-metadata and free local data
    242     return psphotReadoutCleanup(config, view, "PSPHOT.INPUT");
     247    return psphotReadoutCleanup(config, view, filerule);
    243248}
  • branches/czw_branch/20101203/psphot/src/psphotReadoutCleanup.c

    r28013 r30118  
    1919    psAssert (recipe, "missing recipe?");
    2020
    21     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    22     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     21    int num = psphotFileruleCount(config, filerule);
    2322
    2423    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotReadoutFindPSF.c

    r28013 r30118  
    33// in this psphotReadout-variant, we are only trying to determine the PSF given an existing set
    44// of input source positions to use as initial PSF stars.
    5 bool psphotReadoutFindPSF(pmConfig *config, const pmFPAview *view, psArray *inSources) {
     5bool psphotReadoutFindPSF(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources) {
    66
    77    psTimerStart ("psphotReadout");
    88
    9     // set the photcode for the PSPHOT.INPUT
    10     if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
     9    // set the photcode for the input
     10    if (!psphotAddPhotcode(config, view, filerule)) {
    1111        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    1212        return false;
     
    1414
    1515    // Generate the mask and variance images, including the user-defined analysis region of interest
    16     psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     16    psphotSetMaskAndVariance (config, view, filerule);
    1717
    1818    // Note that in this implementation, we do NOT model the background and we do not
    1919    // attempt to detect the sources in the image
    2020
    21     // include externally-supplied sources (supplied as PSPHOT.INPUT.CMF)
    22     // XXX we assume a single set of input sources is supplied
    23     if (!psphotDetectionsFromSources (config, view, "PSPHOT.INPUT", inSources)) {
     21    // include the externally-supplied sources (inSources)
     22    // (we assume a single set of input sources is supplied)
     23    if (!psphotDetectionsFromSources (config, view, filerule, inSources)) {
    2424        psError(PSPHOT_ERR_ARGUMENTS, true, "Can't find PSF stars");
    25         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     25        return psphotReadoutCleanup (config, view, filerule);
    2626    }
    2727
    2828    // construct detections->newSources and measure basic stats (moments, local sky)
    29     if (!psphotSourceStats(config, view, "PSPHOT.INPUT", true)) {
     29    if (!psphotSourceStats(config, view, filerule, true)) {
    3030        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
    3131        return false;
     
    3333
    3434    // peak flux is wrong : use the peak measured in the moments analysis:
    35     if (!psphotRepairLoadedSources(config, view, "PSPHOT.INPUT")) {
     35    if (!psphotRepairLoadedSources(config, view, filerule)) {
    3636        psError(PSPHOT_ERR_UNKNOWN, false, "failure to repair sources");
    3737        return false;
     
    3939
    4040    // classify sources based on moments, brightness (psf is not known)
    41     if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
     41    if (!psphotRoughClass (config, view, filerule)) {
    4242        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough source class");
    43         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     43        return psphotReadoutCleanup (config, view, filerule);
    4444    }
    4545
    46     if (!psphotImageQuality (config, view, "PSPHOT.INPUT")) {
     46    if (!psphotImageQuality (config, view, filerule)) {
    4747        psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality");
    48         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     48        return psphotReadoutCleanup (config, view, filerule);
    4949    }
    5050
    51     if (!psphotChoosePSF(config, view, "PSPHOT.INPUT")) {
     51    if (!psphotChoosePSF(config, view, filerule)) {
    5252        psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model");
    53         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     53        return psphotReadoutCleanup (config, view, filerule);
    5454    }
    5555
     
    5959    // fits from that analysis, or run the linear PSF fit for all objects currently in hand
    6060    // construct an initial model for each object, set the radius to fitRadius, set circular fit mask
    61     psphotGuessModels (config, view, "PSPHOT.INPUT");
     61    psphotGuessModels (config, view, filerule);
    6262# endif
    6363
    6464    // merge the newly selected sources into the existing list
    6565    // NOTE: merge OLD and NEW
    66     psphotMergeSources (config, view, "PSPHOT.INPUT");
     66    psphotMergeSources (config, view, filerule);
    6767
    6868# if 0
    6969    // measure aperture photometry corrections
    70     if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
     70    if (!psphotApResid (config, view, filerule)) {
    7171        psLogMsg ("psphot", 3, "failed on psphotApResid");
    72         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     72        return psphotReadoutCleanup (config, view, filerule);
    7373    }
    7474# endif
    7575
    7676    // drop the references to the image pixels held by each source
    77     psphotSourceFreePixels(config, view, "PSPHOT.INPUT");
     77    psphotSourceFreePixels(config, view, filerule);
    7878
    7979    // create the exported-metadata and free local data
    80     return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     80    return psphotReadoutCleanup (config, view, filerule);
    8181}
  • branches/czw_branch/20101203/psphot/src/psphotReadoutKnownSources.c

    r28013 r30118  
    33// in this psphotReadout-variant, we are only measuring the photometry for known sources, using
    44// a PSF generated for this observation from those sources
    5 bool psphotReadoutKnownSources(pmConfig *config, const pmFPAview *view, psArray *inSources) {
     5bool psphotReadoutKnownSources(pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources) {
    66
    77    psTimerStart ("psphotReadout");
    88
    99    // set the photcode for this image
    10     if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
     10    if (!psphotAddPhotcode(config, view, filerule)) {
    1111        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    1212        return false;
     
    1414
    1515    // Generate the mask and weight images, including the user-defined analysis region of interest
    16     psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     16    psphotSetMaskAndVariance (config, view, filerule);
    1717
    1818    // Note that in this implementation, we do NOT model the background and we do not
     
    2020
    2121    // include externally-supplied sources (supplied as PSPHOT.INPUT.CMF)
    22     if (!psphotDetectionsFromSources (config, view, "PSPHOT.INPUT", inSources)) {
     22    if (!psphotDetectionsFromSources (config, view, filerule, inSources)) {
    2323        psError(PSPHOT_ERR_ARGUMENTS, true, "Can't find PSF stars");
    24         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     24        return psphotReadoutCleanup (config, view, filerule);
    2525    }
    2626
    2727    // construct sources and measure basic stats
    28     if (!psphotSourceStats (config, view, "PSPHOT.INPUT", true)) {
     28    if (!psphotSourceStats (config, view, filerule, true)) {
    2929        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
    3030        return false;
     
    3232
    3333    // peak flux is wrong : use the peak measured in the moments analysis:
    34     if (!psphotRepairLoadedSources(config, view, "PSPHOT.INPUT")) {
     34    if (!psphotRepairLoadedSources(config, view, filerule)) {
    3535        psError(PSPHOT_ERR_UNKNOWN, false, "failure to repair sources");
    3636        return false;
     
    3838
    3939    // classify sources based on moments, brightness (psf is not known)
    40     if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
     40    if (!psphotRoughClass (config, view, filerule)) {
    4141        psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough source class");
    42         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     42        return psphotReadoutCleanup (config, view, filerule);
    4343    }
    4444
    45     if (!psphotChoosePSF (config, view, "PSPHOT.INPUT")) {
     45    if (!psphotChoosePSF (config, view, filerule)) {
    4646        psError(PSPHOT_ERR_PSF, false, "Failed to construct a psf model");
    47         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     47        return psphotReadoutCleanup (config, view, filerule);
    4848    }
    4949
    5050    // construct an initial model for each object
    51     psphotGuessModels (config, view, "PSPHOT.INPUT");
     51    psphotGuessModels (config, view, filerule);
    5252
    5353    // merge the newly selected sources into the existing list
    5454    // NOTE: merge OLD and NEW
    55     psphotMergeSources (config, view, "PSPHOT.INPUT");
     55    psphotMergeSources (config, view, filerule);
    5656
    5757    // linear PSF fit to source peaks
    58     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
     58    psphotFitSourcesLinear (config, view, filerule, false);
    5959
    6060    // measure aperture photometry corrections
    61     if (!psphotApResid (config, view, "PSPHOT.INPUT")) {
     61    if (!psphotApResid (config, view, filerule)) {
    6262        psLogMsg ("psphot", 3, "failed on psphotApResid");
    63         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     63        return psphotReadoutCleanup (config, view, filerule);
    6464    }
    6565
    6666    // calculate source magnitudes
    67     psphotMagnitudes(config, view, "PSPHOT.INPUT");
     67    psphotMagnitudes(config, view, filerule);
    6868
    6969    // drop the references to the image pixels held by each source
    70     psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
     70    psphotSourceFreePixels (config, view, filerule);
    7171
    7272    // create the exported-metadata and free local data
    73     return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     73    return psphotReadoutCleanup (config, view, filerule);
    7474}
  • branches/czw_branch/20101203/psphot/src/psphotReadoutMinimal.c

    r28013 r30118  
    77// NOTE: ppSub needs to perform extended source analysis for comets and trails.
    88
    9 bool psphotReadoutMinimal(pmConfig *config, const pmFPAview *view) {
     9bool psphotReadoutMinimal(pmConfig *config, const pmFPAview *view, const char *filerule) {
    1010
    1111    // measure the total elapsed time in psphotReadout.  XXX the current threading plan
     
    1818
    1919    // set the photcode for this image
    20     if (!psphotAddPhotcode(config, view, "PSPHOT.INPUT")) {
     20    if (!psphotAddPhotcode(config, view, filerule)) {
    2121        psError(PSPHOT_ERR_CONFIG, false, "trouble defining the photcode");
    2222        return false;
     
    2424
    2525    // Generate the mask and weight images, including the user-defined analysis region of interest
    26     psphotSetMaskAndVariance (config, view, "PSPHOT.INPUT");
     26    psphotSetMaskAndVariance (config, view, filerule);
    2727
    2828    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved on readout->analysis
    29     if (!psphotLoadPSF (config, view)) {
     29    if (!psphotLoadPSF (config, view, filerule)) {
    3030      psError (PSPHOT_ERR_CONFIG, false, "missing psf model");
    31       return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     31      return psphotReadoutCleanup (config, view, filerule);
    3232    }
    3333
    3434    // find the detections (by peak and/or footprint) in the image. (final pass)
    35     if (!psphotFindDetections(config, view, "PSPHOT.INPUT", false)) {
     35    if (!psphotFindDetections(config, view, filerule, false)) {
    3636        psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis");
    37         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     37        return psphotReadoutCleanup (config, view, filerule);
    3838    }
    3939
    4040    // construct sources and measure basic stats (saved on detections->newSources)
    41     if (!psphotSourceStats (config, view, "PSPHOT.INPUT", false)) { // pass 1
     41    if (!psphotSourceStats (config, view, filerule, false)) { // pass 1
    4242        psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources");
    43         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     43        return psphotReadoutCleanup (config, view, filerule);
    4444    }
    4545
    4646    // find blended neighbors of very saturated stars
    47     psphotDeblendSatstars (config, view, "PSPHOT.INPUT");
     47    psphotDeblendSatstars (config, view, filerule);
    4848
    4949    // mark blended peaks PS_SOURCE_BLEND
    50     if (!psphotBasicDeblend (config, view, "PSPHOT.INPUT")) {
     50    if (!psphotBasicDeblend (config, view, filerule)) {
    5151        psLogMsg ("psphot", 3, "failed on deblend analysis");
    52         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     52        return psphotReadoutCleanup (config, view, filerule);
    5353    }
    5454
    5555    // classify sources based on moments, brightness (use supplied psf shape parameters)
    56     if (!psphotRoughClass (config, view, "PSPHOT.INPUT")) {
     56    if (!psphotRoughClass (config, view, filerule)) {
    5757        psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    58         return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     58        return psphotReadoutCleanup (config, view, filerule);
    5959    }
    6060
    6161    // construct an initial model for each object
    62     psphotGuessModels (config, view, "PSPHOT.INPUT");
     62    psphotGuessModels (config, view, filerule);
    6363
    6464    // merge the newly selected sources into the existing list
    65     psphotMergeSources (config, view, "PSPHOT.INPUT");
     65    psphotMergeSources (config, view, filerule);
    6666
    6767    // linear PSF fit to source peaks
    68     psphotFitSourcesLinear (config, view, "PSPHOT.INPUT", false);
     68    psphotFitSourcesLinear (config, view, filerule, false);
    6969
    7070// XXX eventually, add the extended source fits here
    7171# if (0)
    7272    // measure source size for the remaining sources
    73     psphotSourceSize (config, view, "PSPHOT.INPUT");
     73    psphotSourceSize (config, view, filerule);
    7474
    75     psphotExtendedSourceAnalysis (config, view, "PSPHOT.INPUT");
     75    psphotExtendedSourceAnalysis (config, view, filerule);
    7676
    77     psphotExtendedSourceFits (config, view, "PSPHOT.INPUT");
     77    psphotExtendedSourceFits (config, view, filerule);
    7878# endif
    7979
    8080    // calculate source magnitudes
    81     psphotMagnitudes(config, view, "PSPHOT.INPUT");
     81    psphotMagnitudes(config, view, filerule);
    8282
    8383    // XXX ensure this is measured if the analysis succeeds (even if quality is low)
    84     if (!psphotEfficiency(config, view, "PSPHOT.INPUT")) {
     84    if (!psphotEfficiency(config, view, filerule)) {
    8585        psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources");
    8686        psErrorClear();
     
    8888
    8989    // drop the references to the image pixels held by each source
    90     psphotSourceFreePixels (config, view, "PSPHOT.INPUT");
     90    psphotSourceFreePixels (config, view, filerule);
    9191
    9292    // create the exported-metadata and free local data
    93     return psphotReadoutCleanup (config, view, "PSPHOT.INPUT");
     93    return psphotReadoutCleanup (config, view, filerule);
    9494}
  • branches/czw_branch/20101203/psphot/src/psphotReplaceUnfit.c

    r28013 r30118  
    3131    psAssert (recipe, "missing recipe?");
    3232
    33     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    34     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     33    int num = psphotFileruleCount(config, filerule);
    3534
    3635    // loop over the available readouts
    3736    for (int i = 0; i < num; i++) {
    3837        if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe)) {
    39             psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for PSPHOT.INPUT entry %d", i);
     38            psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
    4039            return false;
    4140        }
  • branches/czw_branch/20101203/psphot/src/psphotRoughClass.c

    r28425 r30118  
    1616    psAssert (recipe, "missing recipe?");
    1717
    18     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    19     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     18    int num = psphotFileruleCount(config, filerule);
    2019
    2120    // skip the chisq image (optionally?)
  • branches/czw_branch/20101203/psphot/src/psphotSkyReplace.c

    r28013 r30118  
    55    bool status = true;
    66
    7     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    8     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     7    int num = psphotFileruleCount(config, filerule);
    98
    109    // skip the chisq image (optionally?)
  • branches/czw_branch/20101203/psphot/src/psphotSourceFreePixels.c

    r28013 r30118  
    33bool psphotSourceFreePixels (pmConfig *config, const pmFPAview *view, const char *filerule)
    44{
    5     bool status = true;
    6 
    7     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    8     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     5    int num = psphotFileruleCount(config, filerule);
    96
    107    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotSourceMatch.c

    r29548 r30118  
    66psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule)
    77{
    8     bool status = true;
    9 
    108    psArray *objects = psArrayAllocEmpty(100);
    119
    12     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    13     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     10    int num = psphotFileruleCount(config, filerule);
    1411
    1512    // loop over the available readouts
    1613    for (int i = 0; i < num; i++) {
    1714        if (!psphotMatchSourcesReadout (objects, config, view, filerule, i)) {
    18             psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
     15            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for %s entry %d", filerule, i);
    1916            psFree (objects);
    2017            return NULL;
     
    162159    psAssert (status, "missing SKY_OUTER_RADIUS in recipe?");
    163160
    164     int nImages = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    165     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     161    int nImages = psphotFileruleCount(config, filerule);
    166162
    167163    // generate look-up arrays for detections and readouts
  • branches/czw_branch/20101203/psphot/src/psphotSourceSize.c

    r29610 r30118  
    4949    psAssert (recipe, "missing recipe?");
    5050
    51     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    52     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     51    int num = psphotFileruleCount(config, filerule);
    5352
    5453    // skip the chisq image (optionally?)
     
    6059        if (i == chisqNum) continue; // skip chisq image
    6160        if (!psphotSourceSizeReadout (config, view, filerule, i, recipe, getPSFsize)) {
    62             psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for PSPHOT.INPUT entry %d", i);
     61            psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for %s entry %d", filerule, i);
    6362            return false;
    6463        }
  • branches/czw_branch/20101203/psphot/src/psphotSourceStats.c

    r29604 r30118  
    1414    psAssert (recipe, "missing recipe?");
    1515
    16     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    17     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     16    int num = psphotFileruleCount(config, filerule);
    1817
    1918    // skip the chisq image (optionally?)
  • branches/czw_branch/20101203/psphot/src/psphotStackChisqImage.c

    r28013 r30118  
    88bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *ruleDet, const char *ruleCnv)
    99{
    10     bool status = false;
    11 
    1210    psTimerStart ("psphot.chisq.image");
    1311
     
    1715    pmReadout *chiReadout = NULL;
    1816
    19     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    20     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     17    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    2118
    2219    // loop over the available readouts
     
    2825        }
    2926    }
    30 
    31     num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    32     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
    3327
    3428    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.CHISQ.NUM", PS_META_REPLACE, "", num);
     
    125119    psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM");
    126120
    127     int inputNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    128     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     121    int inputNum = psphotFileruleCount(config, "PSPHOT.INPUT");
    129122
    130123    pmFPAfileRemoveSingle (config->files, filerule, chisqNum);
  • branches/czw_branch/20101203/psphot/src/psphotStackImageLoop.c

    r28013 r30118  
    105105bool GetAstrometryFPA (pmConfig *config, pmFPAview *view) {
    106106
    107     bool status = false;
    108 
    109107    bool foundAstrometry = false;
    110108    bool bilevelAstrometry = false;
    111109
    112     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    113     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     110    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    114111
    115112    // loop over the available readouts
     
    158155bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
    159156
    160     bool status = false;
    161 
    162     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    163     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     157    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    164158
    165159    // loop over the available readouts
     
    220214bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {
    221215
    222     bool status = false;
    223 
    224216    if (!bilevelAstrometry) return true;
    225217
    226     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    227     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     218    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    228219
    229220    // loop over the available readouts
  • branches/czw_branch/20101203/psphot/src/psphotStackMatchPSFs.c

    r29548 r30118  
    88    psAssert(recipe, "We've thrown an error on this before.");
    99
    10     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    11     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     10    int num = psphotFileruleCount(config, "PSPHOT.INPUT");
    1211
    1312    // 'options' carries info needed to perform the stack matching
  • branches/czw_branch/20101203/psphot/src/psphotStackReadout.c

    r29548 r30118  
    5252    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are determined and saved on
    5353    // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT
    54     if (!psphotLoadPSF (config, view)) {
     54    if (!psphotLoadPSF (config, view, STACK_RAW)) {
    5555        psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model");
    5656        return psphotReadoutCleanup (config, view, STACK_OUT);
  • branches/czw_branch/20101203/psphot/src/psphotSubtractBackground.c

    r28013 r30118  
    132132    psAssert (recipe, "missing recipe?");
    133133
    134     int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
    135     psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     134    int num = psphotFileruleCount(config, filerule);
    136135
    137136    // loop over the available readouts
    138137    for (int i = 0; i < num; i++) {
    139138        if (!psphotSubtractBackgroundReadout (config, view, filerule, i, recipe)) {
    140             psError (PSPHOT_ERR_CONFIG, false, "failed to subtract background for PSPHOT.INPUT entry %d", i);
     139            psError (PSPHOT_ERR_CONFIG, false, "failed to subtract background for %s entry %d", filerule, i);
    141140            return false;
    142141        }
  • branches/czw_branch/20101203/psphot/src/psphotTest.c

    r28405 r30118  
    137137    psMetadataItem *mdi;
    138138
    139     psMetadataConfigWrite (header, argv[2]);
     139    psMetadataConfigWrite (header, argv[2], NULL);
    140140
    141141    // attempt to write image with NAXIS = 0
  • branches/czw_branch/20101203/pstamp/scripts/pstamp_job_run.pl

    r29885 r30118  
    277277        # silently skip them if they don't exist. Perhaps this should be
    278278        # detected in pstampparse so that the user can be notified with
    279         # a message in parse_error.txt ("warp do not have a background model")
    280         my $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     279        # a message in parse_error.txt ("warp does not have a background model")
    281280        my $psf_file = $params->{psf} if ($options & $PSTAMP_SELECT_PSF);
    282281        my $backmdl_file = $params->{backmdl} if ($options & $PSTAMP_SELECT_BACKMDL);
    283282        my $pattern_file = $params->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL);
     283        my $cmf_file;
     284        if ($stage ne 'chip') {
     285            # we don't ship chip stage cmf files because they may not be censored
     286            $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     287        }
    284288
    285289        my $outdir = dirname($output_base);
  • branches/czw_branch/20101203/pstamp/scripts/pstampparse.pl

    r29578 r30118  
    126126}
    127127
     128# Adjust the label for requests coming in over the web interaface
     129
     130my $label_changed = 0;
     131if ($label and $label eq "WEB.UP") {
     132    my $lcname = lc($req_name);
     133    if ($lcname =~ /pitt/) {
     134        $label = "PITT";
     135        $label_changed = 1;
     136    } elsif ($lcname =~ /cfa/) {
     137        $label = "CFA";
     138        $label_changed = 1;
     139    } elsif ($lcname =~ /durham/) {
     140        $label = "DURHAM";
     141        $label_changed = 1;
     142    } elsif ($lcname =~ /qub/) {
     143        $label = "QUB";
     144        $label_changed = 1;
     145    }
     146    print "Setting label for $req_name to $label\n" if $label_changed;
     147}
     148
     149
    128150if ($req_id and !$no_update) {
    129151    # update the database with the request name. This will be used as the
     
    131153    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
    132154    $command .= " -set_outProduct $product";
     155    $command .= " -set_label $label" if $label_changed;
    133156    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    134157        run(command => $command, verbose => $verbose);
  • branches/czw_branch/20101203/pstamp/src/ppstampMakeStamp.c

    r29885 r30118  
    320320        }
    321321        if (readout->mask) {
    322             outReadout->mask = extractStamp(readout->mask, extractRegion,  0);
     322            psImageMaskType maskInitValue = pmConfigMaskGet("BLANK", config);
     323            outReadout->mask = extractStamp(readout->mask, extractRegion,  maskInitValue);
    323324            if (!outReadout->mask) {
    324325                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
  • branches/czw_branch/20101203/pswarp/src/pswarpLoop.c

    r28043 r30118  
    384384
    385385        // measure the PSF using these sources
    386         if (!psphotReadoutFindPSF(config, view, sources)) {
     386        if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {
    387387            // This is likely a data quality issue
    388388            // XXX Split into multiple cases using error codes?
  • branches/czw_branch/20101203/tools/czarplot.pl

    r29862 r30118  
    126126
    127127
    128 my $plotter = new czartool::Plotter(
    129         $gpc1Db,
    130         $czarDb,
    131         "%Y%m%d-%H%M%S",
    132         $savingToFile ? "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8" : "X11",
    133         $path,
    134         $save_temps);
     128my $plotter = undef;
     129if ($savingToFile) {
     130
     131    $plotter = czartool::Plotter->new_file(
     132            $gpc1Db,
     133            $czarDb,
     134            $path,
     135            $save_temps);
     136}
     137else {
     138
     139    $plotter = czartool::Plotter->new_display(
     140            $gpc1Db,
     141            $czarDb,
     142            $save_temps);
     143}
    135144
    136145# sort out times
     
    168177elsif ($nebulous) {$plotter->plotDiskUsageHistogram();}
    169178if ($magicMask) {
    170    
     179
    171180    if ($exposureId) {$plotter->plotMagicMaskFractionForThisExposure($exposureId);}
    172181    else {$plotter->plotMagicMaskFraction($begin, $end);}
  • branches/czw_branch/20101203/tools/czarpoll.pl

    r29861 r30118  
    1414use czartool::Burntool;
    1515use czartool::DayMetrics;
    16 
     16use czartool::MetricsIndex;
    1717
    1818my $period = 60;
     
    2929my $nebulous = new czartool::Nebulous($czarDb);
    3030my $pantasks = new czartool::Pantasks();
    31 my $plotter = new czartool::Plotter($gpc1Db, $czarDb, "%Y%m%d-%H%M%S", "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8", "/tmp", $save_temps); # TODO hardcoded font path
     31my $plotter = czartool::Plotter->new_file($gpc1Db, $czarDb, "/tmp", $save_temps);
    3232my $burntool = new czartool::Burntool();
    3333
     
    108108    my $newState = undef;
    109109    my $nsStatus = undef;
    110     my $lastDay = strftime('%Y-%m-%d', localtime);
    111110    my $today = undef;
    112     my $doneMetricsToday = 1;
    113 
     111    my $yesterday = undef;
     112    my $newDayTime = "18:00";
     113    my $lastDayDailyTasks = "2010-01-01";
     114
     115    # main polling loop
    114116    while (1) {
    115117
    116         # check whether day has changed. if so, cleanup tables from previous day and optimize
     118        # sort out times
    117119        $today = strftime('%Y-%m-%d', localtime);
    118         if ($czarDb->isBefore($lastDay, $today)) {
    119        
     120        $yesterday = $czarDb->subtractInterval($today, "1 DAY");
     121        $end = $czarDb->getNowTimestamp();
     122
     123        # if before 18:00 today, then start plots from 18:00 yesterday
     124        if ($czarDb->isBefore($end, "$today $newDayTime")) {$begin = "$yesterday $newDayTime";}
     125        # if after 18:00 today, then perform some daily tasks and start plots from 18:00 today
     126        else {
     127           
     128            $begin = "$today $newDayTime";
     129
     130            # check whether yesterday was cleaned. if not, cleanup tables and optimize
     131            if ($lastDayDailyTasks ne $yesterday) {
     132   
     133                print "* performing daily tasks (clean-up, metrics)";
     134
     135                # create metrics for last 24 hours
     136                print "* Creating metrics for last 24 hours\n";
     137                # TODO hardcoded path needs to be in config
     138                my $dayMetrics = new czartool::DayMetrics($gpc1Db,
     139                        $czarDb,
     140                        "/data/ipp004.0/ipp/ippMetrics/",
     141                        1, 0, $today);
     142                $dayMetrics->writeHTML();
     143
     144                # now update metrics index page
     145                my $metricsIndex = new czartool::MetricsIndex($gpc1Db,
     146                        $czarDb,
     147                        "/data/ipp004.0/ipp/ippMetrics/",
     148                        1, 0);
     149                $metricsIndex->writeHTML();
     150
     151                # now cleanup tables from yesterday and optimize
    120152                print "* New day - performing cleanup\n";
    121                 $czarDb->cleanupDateRange($lastDay, $lastDay, "30 MINUTE");
     153                $czarDb->cleanupDateRange($yesterday, $yesterday, "30 MINUTE");
    122154                $czarDb->optimize();
    123                 $lastDay = $today;
    124                 $doneMetricsToday = 0;
    125         }
    126 
    127         # sort out times
    128         $begin = strftime('%Y-%m-%d 06:35', localtime);
    129         $end = $czarDb->getNowTimestamp();
    130 
    131         # if time now is after 06:35am, then create metrics for past 24 hours
    132         if (!$doneMetricsToday && $czarDb->isBefore($begin, $end)) {
    133        
    134                 print "* Creating metrics for last 24 hours\n";
    135                 my $yesterday = $czarDb->subtractInterval($today, "1 DAY");
    136                 # TODO hardcoded path needs to be in config
    137                 my $dayMetrics = new czartool::DayMetrics($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0, $yesterday);
    138                 $dayMetrics->writeHTML();
    139                 $doneMetricsToday = 1;
    140         }
    141 
    142         # if time now is before 06:35am, include data from previous day
    143         if ($czarDb->isBefore($end, $begin)) {
    144 
    145             $begin = $czarDb->subtractInterval($begin, "1 DAY");
     155                $lastDayDailyTasks = $yesterday;
     156            }
    146157        }
    147158
     
    237248
    238249        $plotter->createLogAndLinearTimeSeries($allServerLabels,  $stage, $begin, $end); # TODO must be a neater way...
    239         $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
     250            $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
    240251    }
    241252}
     
    261272    my $server = undef;
    262273    my $state = undef;
    263    
     274
    264275    foreach $stage (@stages) {
    265276
  • branches/czw_branch/20101203/tools/czartool/DayMetrics.pm

    r29863 r30118  
    3737    $self->{day} = $_[6];
    3838
     39    my $yesterday =  $self->{czarDb}->subtractInterval($self->{day}, "1 DAY");
     40
    3941    # sort out times
    40     $self->{begin} =  "$self->{day} 06:00";
     42    $self->{begin} =  "$yesterday 18:00";
    4143    $self->{end} = $self->{czarDb}->addInterval($self->{begin}, "1 DAY");
    4244    $self->{burntoolEnd} = $self->{czarDb}->addInterval($self->{begin}, "12 HOUR");
  • branches/czw_branch/20101203/tools/czartool/Metrics.pm

    r29867 r30118  
    3535
    3636    # instantiate a plotter object
    37     $self->{plotter} = new czartool::Plotter(
     37    $self->{plotter} = czartool::Plotter->new_file(
    3838            $self->{gpc1Db},
    3939            $self->{czarDb},
    40             "%Y%m%d-%H%M%S",
    41             "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8",
    4240            ".",
    4341            $self->{save_temps});
  • branches/czw_branch/20101203/tools/czartool/Plotter.pm

    r29864 r30118  
    1010my @allStages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
    1111
    12 
    13 ###########################################################################
    14 #
    15 # Constructor
     12###########################################################################
     13#
     14# Main constructor with all arguments
    1615#
    1716###########################################################################
     
    3029    return $self;
    3130}
     31
     32###########################################################################
     33#
     34# Constructor sending all plots to file
     35#
     36###########################################################################
     37sub new_file {
     38    my $class = shift;
     39    my $self = {
     40        _gpc1Db => shift,
     41        _czarDb => shift,
     42        _outputPath => shift,
     43        _save_temps => shift,
     44                                                    };
     45
     46    $self->{_dateFormat} = "%Y%m%d-%H%M%S";
     47    $self->{_outputFormat} = "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8"; # TODO path needs to be in config
     48
     49        bless $self, $class;
     50    return $self;
     51}
     52
     53###########################################################################
     54#
     55# Constructor sending all plots to an X window
     56#
     57###########################################################################
     58sub new_display {
     59    my $class = shift;
     60    my $self = {
     61        _gpc1Db => shift,
     62        _czarDb => shift,
     63        _save_temps => shift,
     64    };
     65
     66    $self->{_dateFormat} = "%Y%m%d-%H%M%S";
     67    $self->{_outputFormat} = "X11";
     68    $self->{_outputPath} = undef;
     69
     70    bless $self, $class;
     71    return $self;
     72}
     73
     74
    3275
    3376###########################################################################
  • branches/czw_branch/20101203/tools/makedistdest

    r29237 r30118  
    1313
    1414my $prod_name;
     15my $dbhost;
    1516
    1617GetOptions(
    1718           'prod_name=s'     => \$prod_name,
     19           'dbhost=s'        => \$dbhost,
    1820) or pod2usage( 2 );
    1921
    2022pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    21 pod2usage( -msg => "Required options: --prod_name",
     23pod2usage( -msg => "Required options: --prod_name --dbhost",
    2224           -exitval => 3)
    23     unless defined $prod_name; 
     25    unless defined $prod_name
     26    and defined $dbhost; 
    2427
    2528my $cmd = "dsprodtool --add $prod_name --type ipp-dist --description $prod_name";
     
    3134die "dsprodtool failed: $rc" if $rc;
    3235
    33 $cmd = "disttool -dbname gpc1 -definedestination -ds_dbname ippRequestServer -ds_dbhost ippdb02 -name $prod_name";
     36$cmd = "disttool -dbname gpc1 -definedestination -ds_dbname ippRequestServer -ds_dbhost $dbhost -name $prod_name";
    3437
    3538$rc = system $cmd;
Note: See TracChangeset for help on using the changeset viewer.