IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29938 for trunk


Ignore:
Timestamp:
Dec 5, 2010, 10:04:42 PM (15 years ago)
Author:
eugene
Message:

handle errors in dvo I/O functions; better support for DIS images; merge in high-speed mods from Niall; systematic errors in astrometry (somewhat hackish); add fits I/O option to succeed reading a short file (padding as needed); various kapa improvements (frames consistent in X, PS, PNG; fix tick label signif digits; add function for image overlays; better thick box lines; PNG of the image); bDrawBuffer mods to drop static buffer and refer to passed through buffer; ResizeByImage; DefineSectionByImage; buutos to do png & jpeg; add program roc for raid over cluster; support for mosaic photcodes in dvo image plot; densify; section name [-image x y] : width based on current image; resize -by-image; threaded addstar -resort; threaded dvomerge; dvorepair; dvoverify; dvomerge continue; dvomerge from list (of regions)

Location:
trunk/Ohana/src
Files:
74 edited
26 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/Makefile

    r27582 r29938  
    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 \
  • trunk/Ohana/src/addstar/include/addstar.h

    r29541 r29938  
    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));
  • trunk/Ohana/src/addstar/src/ReadStarsFITS.c

    r29541 r29938  
    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);
  • trunk/Ohana/src/addstar/src/ReadStarsSDSS.c

    r28939 r29938  
    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);
  • trunk/Ohana/src/addstar/src/addstar.c

    r28241 r29938  
    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;
  • trunk/Ohana/src/addstar/src/args.c

    r27392 r29938  
    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  }
  • trunk/Ohana/src/addstar/src/resort_catalog.c

    r27435 r29938  
    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
  • trunk/Ohana/src/addstar/test/dvomerge.dvo

    r29001 r29938  
    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/
  • trunk/Ohana/src/dvomerge/Makefile

    r29001 r29938  
    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 #########################
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r29001 r29938  
    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));
  • trunk/Ohana/src/dvomerge/src/LoadCatalog.c

    r28329 r29938  
    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)
  • trunk/Ohana/src/dvomerge/src/args.c

    r29001 r29938  
    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}
  • trunk/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r29001 r29938  
    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
  • trunk/Ohana/src/dvomerge/src/dvoconvert.c

    r29001 r29938  
    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
  • trunk/Ohana/src/dvomerge/src/dvomerge.c

    r28327 r29938  
    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*/
  • trunk/Ohana/src/dvomerge/src/dvomergeCreate.c

    r28855 r29938  
    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
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r29001 r29938  
    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 }
  • trunk/Ohana/src/dvomerge/src/dvoverify.c

    r29001 r29938  
    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 
  • trunk/Ohana/src/dvomerge/src/help.c

    r29001 r29938  
    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
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r29181 r29938  
    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 **/
  • trunk/Ohana/src/imregister/imphot/rfits.c

    r7080 r29938  
    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);
  • trunk/Ohana/src/kapa2/Makefile

    r25757 r29938  
    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         \
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r29539 r29938  
    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
  • trunk/Ohana/src/kapa2/include/structures.h

    r29539 r29938  
    148148  int IsMajor;
    149149  int IsLabel;
     150  int nsignif;
    150151} TickMarkData;
    151152
  • trunk/Ohana/src/kapa2/src/ButtonFunctions.c

    r29539 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/CheckPipe.c

    r27790 r29938  
    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);
  • trunk/Ohana/src/kapa2/src/DefineSection.c

    r27790 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/DrawFrame.c

    r29539 r29938  
    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, dy, 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;
  • trunk/Ohana/src/kapa2/src/Image.c

    r29539 r29938  
    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);
  • trunk/Ohana/src/kapa2/src/JPEGit24.c

    r27601 r29938  
    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
  • trunk/Ohana/src/kapa2/src/PNGit.c

    r29408 r29938  
    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
  • trunk/Ohana/src/kapa2/src/PPMit.c

    r27435 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/PSFrame.c

    r29539 r29938  
    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, dy, 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  }
  • trunk/Ohana/src/kapa2/src/PSimage.c

    r14913 r29938  
    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");
  • trunk/Ohana/src/kapa2/src/PSit.c

    r13479 r29938  
    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  }
  • trunk/Ohana/src/kapa2/src/Resize.c

    r26891 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r29539 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/bDrawFrame.c

    r29539 r29938  
    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, dy;
    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}
  • trunk/Ohana/src/kapa2/src/bDrawIt.c

    r13479 r29938  
    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}
  • trunk/Ohana/src/kapa2/src/bDrawLabels.c

    r13320 r29938  
    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  }
  • trunk/Ohana/src/kapa2/src/bDrawObjects.c

    r27530 r29938  
    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    }
  • trunk/Ohana/src/kapa2/src/bDrawOverlay.c

    r25757 r29938  
    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
  • trunk/Ohana/src/libdvo/include/dvo.h

    r29001 r29938  
    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);
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r27580 r29938  
    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
  • trunk/Ohana/src/libdvo/src/dvo_catalog_mef.c

    r29001 r29938  
    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);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r29001 r29938  
    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);
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r29182 r29938  
    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  }
  • trunk/Ohana/src/libdvo/src/fits_db.c

    r28246 r29938  
    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);
  • trunk/Ohana/src/libdvo/src/mosaic_astrom.c

    r27435 r29938  
    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
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r29537 r29938  
    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));
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r28241 r29938  
    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);
  • trunk/Ohana/src/libkapa/include/kapa.h

    r29537 r29938  
    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 */
  • trunk/Ohana/src/libkapa/src/KapaWindow.c

    r27790 r29938  
    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
  • trunk/Ohana/src/libkapa/src/bDrawFuncs.c

    r29537 r29938  
    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) {
  • trunk/Ohana/src/libkapa/src/bDrawRotFont.c

    r12332 r29938  
    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}
  • trunk/Ohana/src/opihi/cmd.astro/region.c

    r27435 r29938  
    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,
  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r29540 r29938  
    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      \
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r29540 r29938  
    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"},
  • trunk/Ohana/src/opihi/cmd.data/rd.c

    r28241 r29938  
    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
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r29540 r29938  
    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    }
  • trunk/Ohana/src/opihi/cmd.data/resize.c

    r13479 r29938  
    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) {
  • trunk/Ohana/src/opihi/cmd.data/section.c

    r27790 r29938  
    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);
  • trunk/Ohana/src/opihi/cmd.data/vgauss.c

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

    r28958 r29938  
    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
  • trunk/Ohana/src/opihi/dvo/imlist.c

    r29540 r29938  
    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
  • trunk/Ohana/src/opihi/lib.data/starfuncs.c

    r20936 r29938  
    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);
  • trunk/Ohana/src/photdbc/include/photdbc.h

    r28331 r29938  
    114114int SetSignals (void);
    115115int copy_images (char *outdir);
     116void usage();
  • trunk/Ohana/src/photdbc/src/args.c

    r8630 r29938  
    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}
  • trunk/Ohana/src/photdbc/src/initialize.c

    r4808 r29938  
    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);
  • trunk/Ohana/src/photdbc/src/join_stars.c

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

    r27581 r29938  
    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}
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r28241 r29938  
    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
  • trunk/Ohana/src/relastro/src/high_speed_objects.c

    r28811 r29938  
    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);
  • trunk/Ohana/src/tools/Makefile

    r20983 r29938  
    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)
Note: See TracChangeset for help on using the changeset viewer.