IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5451


Ignore:
Timestamp:
Oct 27, 2005, 7:10:17 PM (21 years ago)
Author:
eugene
Message:

working on SkyRegion conversion

Location:
trunk/Ohana/src
Files:
1 added
47 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/src/SkyRegionUtils.c

    r5448 r5451  
    44 
    55  int i, status, Nsubset, NSUBSET;
    6   char filename[256];
    76  SkyList *subset;
    87  struct stat filestats;
     
    1514  /* match the basename against the GSCRegion file names */
    1615  for (i = 0; i < input[0].Nregions; i++) {
    17     status = stat (input[0].regions[i][0].filename, &filestats);
     16    status = stat ((char *) input[0].regions[i][0].filename, &filestats);
    1817    if ((status == -1) && (errno == ENOENT)) continue;
    1918    /* give an error for other conditions? */
     
    2625  return (subset);
    2726}
    28 
    29 int SkyTableSetDepth (SkyTable *sky, int depth) {
    30 
    31   int i;
    32 
    33   for (i = 0; i < sky[0].Nregions; i++) {
    34     sky[0].regions[i].table = (sky[0].regions[i].depth == depth);
    35   }
    36   return (TRUE);
    37 }
    38 
  • trunk/Ohana/src/addstar/src/get2mass.c

    r5448 r5451  
    8484    if (De < patch[0].Dmin) continue;
    8585    sprintf (datafile, "%s/%s", path, filename);
    86     regions[Nregions].filename = strcreate (datafile);
     86    regions[Nregions].filename = (e_void) strcreate (datafile);
    8787    regions[Nregions].Rmin = Rs;
    8888    regions[Nregions].Rmax = Re;
  • trunk/Ohana/src/addstar/src/get2mass_as.c

    r5448 r5451  
    5151  if (!FilterSkip) Shutdown ("invalid photcode %s", GetPhotcodeNamebyCode(photcode));
    5252
    53   filename = region[0].filename;
     53  filename = (char *) region[0].filename;
    5454  gf = gzopen (filename, "rb");
    5555  if (gf == NULL) Shutdown ("can't read 2mass data file: %s", filename);
  • trunk/Ohana/src/addstar/src/get2mass_dr2.c

    r5448 r5451  
    2727  fprintf (stderr, "overlap: %f - %f, %f - %f\n", RA0, RA1, DEC0, DEC1);
    2828
    29   filename = region[0].filename;
     29  filename = (char *) region[0].filename;
    3030  gf = gzopen (filename, "rb");
    3131  if (gf == NULL) Shutdown ("can't read 2mass data file: %s", filename);
  • trunk/Ohana/src/addstar/src/getgsc.c

    r5448 r5451  
    1818  /* load regions from GSC table, restrict to patch */
    1919  sky = SkyTableFromGSC (GSCFILE, 2, VERBOSE);
    20   SkyTableSetPath (sky, GSCDIR, "cpt");
     20  SkyTableSetFilenames (sky, GSCDIR, "cpt");
    2121  skylist = SkyListByPatch (sky, -1, patch);
    2222 
     
    2525 
    2626  for (i = 0; i < skylist[0].Nregions; i++) {
    27     gsc = rd_gsc (skylist[0].regions[i][0].filename, &Ngsc);
     27    gsc = rd_gsc ((char *)skylist[0].regions[i][0].filename, &Ngsc);
    2828
    2929    REALLOCATE (stars, Stars, MAX (1, Nstars + Ngsc));
  • trunk/Ohana/src/addstar/src/load_pt_catalog.c

    r5448 r5451  
    33int load_pt_catalog (Catalog *catalog, SkyRegion *region, char *path) {
    44 
    5   char filename[256];
    6 
    7   catalog[0].filename = region[0].filename;
     5  catalog[0].filename = (char *) region[0].filename;
    86
    97  check_permissions (catalog[0].filename);
  • trunk/Ohana/src/delstar/include/delstar.h

    r4864 r5451  
    2424int    ORPHAN;
    2525int    MISSED;
     26char   SKY_TABLE[256];
     27int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
    2628
    2729time_t    START;
  • trunk/Ohana/src/delstar/src/ConfigInit.c

    r4832 r5451  
    3333  ScanConfig (config, "JD-KEYWORD",             "%s", 0, JDKeyword);
    3434
     35  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     36    SKY_DEPTH = 2;
     37  }
     38  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
     39    SKY_TABLE[0] = 0;
     40  }
     41
    3542  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
    3643  if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
  • trunk/Ohana/src/delstar/src/RegionOps.c

    r4810 r5451  
    33# define NBANDS 24
    44
    5 double DecBands[] = {
     5static double DecBands[] = {
    66  -90.0, -82.5, -75.0, -67.5, -60.0,
    77  -52.5, -45.0, -37.5, -30.0, -22.5,
     
    1111};
    1212
    13 char *DecNames[] = {
     13static char *DecNames[] = {
    1414  "s8230", "s7500", "s6730", "s6000", "s5230",
    1515  "s4500", "s3730", "s3000", "s2230", "s1500",
  • trunk/Ohana/src/delstar/src/delete_imagefile.c

    r5448 r5451  
    2323
    2424  for (i = 0; i < skylist[0].Nregions; i++) {
    25     if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].region[i][0].filename);
    26     catalog.filename = skylist[0].region[i][0].filename;  /* don't free region before catalog! */
     25    if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].regions[i][0].filename);
     26    catalog.filename = (char *) skylist[0].regions[i][0].filename;  /* don't free region before catalog! */
    2727    switch (lock_catalog (&catalog, LCK_XCLD)) {
    2828      case 0:
  • trunk/Ohana/src/delstar/src/delete_imagename.c

    r5448 r5451  
    3333
    3434    for (i = 0; i < skylist[0].Nregions; i++) {
    35       if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].region[i][0].filename);
    36       catalog.filename = skylist[0].region[i][0].filename;  /* don't free region before catalog! */
     35      if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].regions[i][0].filename);
     36      catalog.filename = (char *) skylist[0].regions[i][0].filename;  /* don't free region before catalog! */
    3737      switch (lock_catalog (&catalog, LCK_XCLD)) {
    3838        case 0:
  • trunk/Ohana/src/delstar/src/delete_times.c

    r5448 r5451  
    2121  NREGIONS = 10;
    2222  ALLOCATE (skylist, SkyList, 1);
    23   ALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS);
     23  ALLOCATE (skylist[0].regions, SkyRegion *, NREGIONS);
    2424
    2525  image = fits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
     
    4141      found = FALSE;
    4242      for (k = 0; (k < skylist[0].Nregions) && !found; k++) {
    43         found = !strcmp (skylist[0].region[k][0].name, skyset[0].region[i][0].name);
     43        found = !strcmp (skylist[0].regions[k][0].name, skyset[0].regions[i][0].name);
    4444      }
    4545      if (found) continue;
    4646      skylist[0].regions[Nregions] = skyset[0].regions[i];
    4747      Nregions ++;
    48       CHECK_REALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS, Nregions, 10);
     48      CHECK_REALLOCATE (skylist[0].regions, SkyRegion *, NREGIONS, Nregions, 10);
    4949    }
    5050    SkyListFree (skyset);
     
    5353  /* delete from all identified regions */
    5454  for (i = 0; i < skylist[0].Nregions; i++) {
    55     if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].region[i][0].filename);
    56     catalog.filename = skylist[0].region[i][0].filename;  /* don't free region before catalog! */
     55    if (VERBOSE) fprintf (stderr, "deleting from %s\n", skylist[0].regions[i][0].filename);
     56    catalog.filename = (char *) skylist[0].regions[i][0].filename;  /* don't free region before catalog! */
    5757    switch (lock_catalog (&catalog, LCK_XCLD)) {
    5858      case 0:
  • trunk/Ohana/src/libautocode/def/common.h

    r5242 r5451  
    3535
    3636# define e_time unsigned int
     37# define e_void long long
    3738# define rawshort short
    3839
  • trunk/Ohana/src/libdvo/include/dvo.h

    r5448 r5451  
    335335
    336336/* skyregion APIs */
    337 int SkyTableSave (SkyTable *table, char *filename);
    338 SkyTable *SkyTableLoad (char *filename, int VERBOSE);
    339 SkyTable *SkyTableFromGSC (char *filename, int depth, int VERBOSE);
    340 SkyTable *SkyTableLoadOptimal (char *catdir, char *SKY_TABLE, char *GSCFILE, int VERBOSE);
    341 SkyRegion *SkyRegionByPoint (SkyTable *table, int depth, double ra, double dec);
    342 SkyList *SkyListByPoint (SkyTable *table, double ra, double dec);
    343 SkyList *SkyListByRadius (SkyTable *table, int depth, double RA, double DEC, double radius);
    344 SkyList *SkyListByPatch (SkyTable *table, int depth, SkyRegion *patch);
    345 SkyList *SkyListByImage (SkyTable *table, int depth, Image *image, Coords *mosaic);
    346 SkyList *SkyListByBounds (SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax);
    347 SkyList *SkyListChildrenByBounds (SkyTable *table, int No, int depth, double Rmin, double Rmax, double Dmin, double Dmax);
    348 int SkyListFree (SkyList *list);
    349 int SkyTableFree (SkyTable *table);
     337int        SkyTableSave            PROTO((SkyTable *table, char *filename));
     338SkyTable  *SkyTableLoad            PROTO((char *filename, int VERBOSE));
     339SkyTable  *SkyTableFromGSC         PROTO((char *filename, int depth, int VERBOSE));
     340SkyTable  *SkyTableLoadOptimal     PROTO((char *catdir, char *SKYFILE, char *GSCFILE, int depth, int VERBOSE));
     341int        SkyTableSetDepth        PROTO((SkyTable *sky, int depth));
     342SkyRegion *SkyRegionByPoint        PROTO((SkyTable *table, int depth, double ra, double dec));
     343SkyList   *SkyListByPoint          PROTO((SkyTable *table, double ra, double dec));
     344SkyList   *SkyListByRadius         PROTO((SkyTable *table, int depth, double RA, double DEC, double radius));
     345SkyList   *SkyListByPatch          PROTO((SkyTable *table, int depth, SkyRegion *patch));
     346SkyList   *SkyListByImage          PROTO((SkyTable *table, int depth, Image *image));
     347SkyList   *SkyListByBounds         PROTO((SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
     348SkyList   *SkyListChildrenByBounds PROTO((SkyTable *table, int No, int depth, double Rmin, double Rmax, double Dmin, double Dmax));
     349int        SkyListFree             PROTO((SkyList *list, int ELEMENTS));
     350int        SkyTableFree            PROTO((SkyTable *table));
     351int        SkyListSetFilenames     PROTO((SkyList *list, char *path, char *ext));
     352int        SkyTableSetFilenames    PROTO((SkyTable *sky, char *path, char *ext));
    350353
    351354# endif
  • trunk/Ohana/src/libdvo/src/skyregion_gsc.c

    r5448 r5451  
    33# define NDIV 4
    44
    5 int DecLines[] = {593, 584, 551, 530, 522, 465, 406, 362, 280, 198, 123, 24, 0,
    6                   597, 578, 574, 577, 534, 499, 442, 376, 294, 212, 144, 48, 0};
    7 
    8 double DecBands[] = {0.0, +7.5, +15.0, +22.5, +30.0, +37.5, +45.0, +52.5, +60.0, +67.5, +75.0, +82.5, +90.0,
    9                      0.0, -7.5, -15.0, -22.5, -30.0, -37.5, -45.0, -52.5, -60.0, -67.5, -75.0, -82.5, -90.0};
    10 
    11 char *DecNames[] = {
    12   "n0000", "n0730", "n1500", "n2230", "n3000", "n3730", "n4500", "n5230", "n6000", "n6730", "n7500", "n8230", "none",
    13   "s0000", "s0730", "s1500", "s2230", "s3000", "s3730", "s4500", "s5230", "s6000", "s6730", "s7500", "s8230", "none",
    14 };
     5static int DecLines[] = {593, 584, 551, 530, 522, 465, 406, 362, 280, 198, 123, 24, 0,
     6                         597, 578, 574, 577, 534, 499, 442, 376, 294, 212, 144, 48, 0};
     7
     8static double DecBands[] = {0.0, +7.5, +15.0, +22.5, +30.0, +37.5, +45.0, +52.5, +60.0, +67.5, +75.0, +82.5, +90.0,
     9                            0.0, -7.5, -15.0, -22.5, -30.0, -37.5, -45.0, -52.5, -60.0, -67.5, -75.0, -82.5, -90.0};
     10
     11static char *DecNames[] = {"n0000", "n0730", "n1500", "n2230", "n3000", "n3730", "n4500", "n5230", "n6000", "n6730", "n7500", "n8230", "none",
     12                           "s0000", "s0730", "s1500", "s2230", "s3000", "s3730", "s4500", "s5230", "s6000", "s6730", "s7500", "s8230", "none"};
    1513
    1614SkyTable *SkyTableFromGSC (char *filename, int depth, int VERBOSE) {
     
    6159  regions[Nr].child     =  TRUE;
    6260  regions[Nr].table     =  (depth == 0);
    63   regions[Nr].filename  =  NULL;
     61  regions[Nr].filename  =  (e_void) NULL;
    6462  strcpy (regions[Nr].name, "fullsky");
    6563 
     
    8179    regions[Nr].child     =  TRUE;
    8280    regions[Nr].table     =  (depth == 1);
    83     regions[Nr].filename  =  NULL;
     81    regions[Nr].filename  =  (e_void) NULL;
    8482    strcpy (regions[Nr].name, DecNames[i]);
    8583  }
     
    9593    regions[Nr].child     =  TRUE;
    9694    regions[Nr].table     =  (depth == 1);
    97     regions[Nr].filename  =  NULL;
     95    regions[Nr].filename  =  (e_void) NULL;
    9896    strcpy (regions[Nr].name, DecNames[i+13]);
    9997  }
     
    143141      regions[Nr].child    =  TRUE;
    144142      regions[Nr].table    =  (depth == 2);
    145       regions[Nr].filename =  NULL;
     143      regions[Nr].filename =  (e_void) NULL;
    146144      regions[Nr].childS   =  0;
    147145      regions[Nr].childE   =  0;
     
    181179        regions[Nr].child    =  FALSE;
    182180        regions[Nr].table    =  (depth == 3);
    183         regions[Nr].filename =  NULL;
     181        regions[Nr].filename =  (e_void) NULL;
    184182        regions[Nr].childS   =  0;
    185183        regions[Nr].childE   =  0;
  • trunk/Ohana/src/libdvo/src/skyregion_io.c

    r5448 r5451  
    99  SkyTable *skytable;
    1010  FILE *f;
     11  int i;
    1112 
    1213  f = fopen (filename, "r");
     
    4041  skytable[0].regions = fits_table_get_SkyRegion (&ftable, &skytable[0].Nregions, NULL);
    4142  for (i = 0; i < skytable[0].Nregions; i++) {
    42     skytable[0].regions[i].filename = NULL;
     43    skytable[0].regions[i].filename = (e_void) NULL;
    4344  }
    4445 
     
    8283}
    8384
    84 SkyTable *SkyTableLoadOptimal (char *catdir, char *SKY_TABLE, char *GSCFILE, int SKY_DEPTH, int VERBOSE) {
     85SkyTable *SkyTableLoadOptimal (char *catdir, char *skyfile, char *gscfile, int depth, int verbose) {
    8586
    8687  char filename[256];
     
    8990  int status;
    9091
    91   /* first option: CATDIR/SkyTable.fits */
    92   sprintf (filename, "%s/SkyTable.fits", CATDIR);
    93   check_permissions (filename);
     92  /* first option: catdir/SkyTable.fits */
     93  sprintf (filename, "%s/SkyTable.fits", catdir);
     94  check_file_access (filename, FALSE, verbose);
    9495
    9596  /* check for file existence */
    9697  status = stat (filename, &filestat);
    9798  if (status == 0) { /* file exists, are permissions OK? */
    98     sky = SkyTableLoad (filename, VERBOSE);
     99    sky = SkyTableLoad (filename, verbose);
    99100    if (sky == NULL) {
    100101      fprintf (stderr, "error loading sky table\n");
     
    105106
    106107  /* first option: SKY_TABLE */
    107   if ((SKY_TABLE != NULL) && (SKY_TABLE[0] != 0)) {
    108     status = stat (SKY_TABLE, &filestat);
     108  if ((skyfile != NULL) && (skyfile[0] != 0)) {
     109    status = stat (skyfile, &filestat);
    109110    if (status == 0) { /* file exists, are permissions OK? */
    110       sky = SkyTableLoad (SKY_TABLE, VERBOSE);
     111      sky = SkyTableLoad (skyfile, verbose);
    111112      if (sky == NULL) {
    112113        fprintf (stderr, "error loading sky table\n");
    113114        exit (1);
    114115      }
    115       SkyTableSetDepth (sky, SKY_DEPTH);
     116      SkyTableSetDepth (sky, depth);
    116117
    117118      /* write CATDIR copy */
    118       sprintf (filename, "%s/SkyTable.fits", CATDIR);
    119       check_permissions (filename);
     119      sprintf (filename, "%s/SkyTable.fits", catdir);
     120      check_file_access (filename, FALSE, verbose);
    120121      SkyTableSave (sky, filename);
    121122      fits_convert_SkyRegion (sky[0].regions, sizeof (SkyTable), sky[0].Nregions);
     
    124125  }
    125126
    126   sky = SkyTableFromGSC (GSCFILE, SKY_DEPTH, VERBOSE);
     127  sky = SkyTableFromGSC (gscfile, depth, verbose);
    127128  if (sky == NULL) {
    128129    fprintf (stderr, "error loading sky table\n");
     
    131132
    132133  /* write CATDIR copy */
    133   sprintf (filename, "%s/SkyTable.fits", CATDIR);
    134   check_permissions (filename);
     134  sprintf (filename, "%s/SkyTable.fits", catdir);
     135  check_file_access (filename, FALSE, verbose);
    135136  SkyTableSave (sky, filename);
    136137  fits_convert_SkyRegion (sky[0].regions, sizeof (SkyRegion), sky[0].Nregions);
     
    147148  for (i = 0; i < list[0].Nregions; i++) {
    148149    sprintf (line, "%s/%s.%s", path, list[0].regions[i][0].name, ext);
    149     list[0].regions[i][0].filename = strcreate (line);
     150    list[0].regions[i][0].filename = (e_void) strcreate (line);
    150151  }
    151152
     
    153154}
    154155
     156int SkyTableSetFilenames (SkyTable *sky, char *path, char *ext) {
     157
     158  int i;
     159  char line[256];
     160
     161  // this generates the names, be sure to free when not needed
     162  for (i = 0; i < sky[0].Nregions; i++) {
     163    sprintf (line, "%s/%s.%s", path, sky[0].regions[i].name, ext);
     164    sky[0].regions[i].filename = (e_void) strcreate (line);
     165  }
     166
     167  return (TRUE);
     168}
     169
  • trunk/Ohana/src/libdvo/src/skyregion_ops.c

    r5448 r5451  
    121121SkyList *SkyListByImage (SkyTable *table, int depth, Image *image) {
    122122
    123   int i, j;
     123  int j;
    124124  SkyList *list;
    125125  double r, d, X[4], Y[4];
     
    172172    }
    173173    list[0].Nregions += extra[0].Nregions;
    174     SkyListFree (extra);
     174    SkyListFree (extra, FALSE);
    175175  } else {
    176176    list = SkyListChildrenByBounds (table, -1, depth, Rmin, Rmax, Dmin, Dmax);
     
    226226      }
    227227      Nnew += children[0].Nregions;
    228       SkyListFree (children);
     228      SkyListFree (children, FALSE);
    229229    } else {
    230230      list[0].regions[Nnew] = &region[i];
     
    254254}
    255255
    256 int SkyListFree (SkyList *list) {
     256int SkyTableSetDepth (SkyTable *sky, int depth) {
     257
     258  int i;
     259
     260  for (i = 0; i < sky[0].Nregions; i++) {
     261    sky[0].regions[i].table = (sky[0].regions[i].depth == depth);
     262  }
     263  return (TRUE);
     264}
     265
     266int SkyListFree (SkyList *list, int ELEMENTS) {
     267
     268  int i;
    257269
    258270  if (list == NULL) return (TRUE);
    259271  if (list[0].regions != NULL) {
     272    if (ELEMENTS) {
     273      for (i = 0; i < list[0].Nregions; i++) {
     274        if (list[0].regions[i][0].filename != (e_void) NULL) {
     275          free ((size_t *) list[0].regions[i][0].filename);
     276        }
     277        free (list[0].regions[i]);
     278      }
     279    }
    260280    free (list[0].regions);
    261281  }
     
    267287int SkyTableFree (SkyTable *table) {
    268288
     289  int i;
     290
    269291  if (table == NULL) return (TRUE);
    270292  if (table[0].regions != NULL) {
    271293    for (i = 0; i < table[0].Nregions; i++) {
    272       if (table[0].regions[i].filename != NULL) {
    273         free (table[0].regions[i].filename);
     294      if (table[0].regions[i].filename != (e_void) NULL) {
     295        free ((size_t *) table[0].regions[i].filename);
    274296      }
    275297    }
  • trunk/Ohana/src/libohana/include/ohana.h

    r5273 r5451  
    118118int     mkdirhier              PROTO((char *path));
    119119void    make_backup            PROTO((char *filename));
     120int     check_file_access      PROTO((char *basefile, int backup, int verbose));
    120121
    121122/* in glockfile.c */
  • trunk/Ohana/src/libohana/src/findexec.c

    r4810 r5451  
    2525}
    2626
    27 /* pathname
    28 
     27/* check that file can be written to:
     28   - dir exists
     29   - dir permissions OK
     30   - file permissions OK,
     31   - file backup permission OK (optional)
     32*/
     33int check_file_access (char *basefile, int BACKUP, int VERBOSE) {
     34 
     35  char *path, *filename;
     36  struct stat filestat;
     37  uid_t uid;
     38  gid_t gid;
     39  int status, cmode;
     40
     41  uid = getuid();
     42  gid = getgid();
     43
     44  /* check permission to write to directory */
     45  path = pathname (basefile);
     46  status = stat (path, &filestat);
     47  if (status == -1) {
     48    if (VERBOSE) fprintf (stderr, "directory %s does not exist, creating...\n", path);
     49    cmode = S_IRWXU | S_IRWXG | S_IRWXO;
     50    status = mkdir (path, cmode);
     51    if (status == -1) {
     52      if (VERBOSE) fprintf (stderr, "can't create %s\n", path);
     53      return (FALSE);
     54    }
     55  }
     56  status = stat (path, &filestat);
     57  if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRWXU)) ||
     58      ((gid == filestat.st_gid) && (filestat.st_mode & S_IRWXG)) ||
     59      (filestat.st_mode & S_IRWXO)) {
     60  } else {
     61    if (VERBOSE) fprintf (stderr, "can't write to %s\n", path);
     62    return (FALSE);
     63  }
     64  free (path);
     65 
     66  /* check permission to write to file */
     67  status = stat (basefile, &filestat);
     68  if (status == 0) { /* file exists, are permissions OK? */
     69    if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) ||
     70        ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) ||
     71        ((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) {
     72    } else {
     73      if (VERBOSE) fprintf (stderr, "can't write to %s\n", basefile);
     74      return (FALSE);
     75    }
     76  }
     77 
     78  /* check permission to write to backup file */
     79  if (BACKUP) {
     80    ALLOCATE (filename, char, strlen(basefile) + 2);
     81    sprintf (filename, "%s~", basefile);
     82    status = stat (filename, &filestat);
     83    if (status == 0) { /* file exists, are permissions OK? */
     84      if (((uid == filestat.st_uid) && (filestat.st_mode & S_IRUSR) && (filestat.st_mode & S_IWUSR)) ||
     85          ((gid == filestat.st_gid) && (filestat.st_mode & S_IRGRP) && (filestat.st_mode & S_IWGRP)) ||
     86          ((filestat.st_mode & S_IROTH) && (filestat.st_mode & S_IWOTH))) {
     87      } else {
     88        if (VERBOSE) fprintf (stderr, "can't write to %s\n", filename);
     89        return (FALSE);
     90      }
     91    }
     92    free (filename);
     93  }
     94  return (TRUE);
     95}
     96
     97/* pathname:
    2998   given path/filename, returns path
    3099   given just filename, returns .
  • trunk/Ohana/src/opihi/dvo/ImageSelection.c

    r4585 r5451  
    99
    1010/* load images based on parameters and region, etc */
    11 int SetImageSelection (int mode) {
     11int SetImageSelection (int mode, int RegionSelect) {
    1212
    1313  int Ngraph;
    1414  Graphdata graphsky;
    15   int RegionSelect, TimeSelect;
     15  int TimeSelect;
    1616  time_t tzero, tend;
    1717
     
    1919  subset = NULL;
    2020 
    21   RegionSelect = GetRegionSelection();
    2221  if (RegionSelect) {
    2322    Ngraph = 0;
  • trunk/Ohana/src/opihi/dvo/Makefile

    r5442 r5451  
    2929$(SDIR)/LoadImages.$(ARCH).o            \
    3030$(SDIR)/cmpRead.$(ARCH).o               \
    31 $(SDIR)/aregion.$(ARCH).o               \
    3231$(SDIR)/compare.$(ARCH).o               \
    33 $(SDIR)/find_regions.$(ARCH).o          \
    34 $(SDIR)/get_regions.$(ARCH).o           \
    3532$(SDIR)/match_image.$(ARCH).o           \
    3633$(SDIR)/photometry.$(ARCH).o            \
     
    3936$(SDIR)/dvo.$(ARCH).o
    4037
     38# $(SDIR)/aregion.$(ARCH).o               \
     39# $(SDIR)/find_regions.$(ARCH).o                \
     40# $(SDIR)/get_regions.$(ARCH).o           \
     41
    4142cmds = \
    4243$(SDIR)/avextract.$(ARCH).o             \
     
    4445$(SDIR)/calextract.$(ARCH).o            \
    4546$(SDIR)/calmextract.$(ARCH).o           \
    46 $(SDIR)/catalog.$(ARCH).o               \
    4747$(SDIR)/ccd.$(ARCH).o                   \
    4848$(SDIR)/cmatch.$(ARCH).o                \
     
    7575$(SDIR)/lightcurve.$(ARCH).o            \
    7676$(SDIR)/mextract.$(ARCH).o              \
    77 $(SDIR)/pcat.$(ARCH).o                  \
    7877$(SDIR)/photcodes.$(ARCH).o             \
    7978$(SDIR)/pmeasure.$(ARCH).o              \
     
    101100help: cmd.basic.help cmd.data.help cmd.astro.help dvo.help
    102101
     102$(funcs) $(cmds) $(libs) : $(INC)/dvo1.h
     103
    103104.PHONY: dvo
    104105
     
    106107
    107108# deprecated functions: verify & delete
     109#$(SDIR)/catalog.$(ARCH).o              \
    108110#$(SDIR)/abszero.$(ARCH).o \
    109111#$(SDIR)/cals.$(ARCH).o \
     
    119121#$(SDIR)/dmagextract.$(ARCH).o \
    120122#$(SDIR)/ddmagextract.$(ARCH).o \
     123#$(SDIR)/pcat.$(ARCH).o                 \
    121124
    122125# future functions, not fully implemented
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r5320 r5451  
    44 
    55  int i, j, m, N, NPTS, param;
    6   int Nsec, Nregions, mode;
    7   char filename[256], catdir[256], *RegionName, *RegionList, *p;
     6  int Nsec, mode;
     7  char *RegionName, *RegionList, *p;
    88
    99  Catalog catalog;
    10   RegionFile *regions;
     10  SkyList *skylist;
    1111  PhotCode *code;
    1212  Vector *vec;
    1313
    1414  /* defaults */
    15   regions = NULL;
    1615  catalog.average = NULL;
    1716  catalog.secfilt = NULL;
     
    2524  if (!InitPhotcodes ()) goto escape;
    2625  Nsec = GetPhotcodeNsecfilt ();
    27 
    28   /* find CATDIR in config system */
    29   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3026
    3127  /* interpret command-line options */
     
    5046
    5147  /* load region corresponding to selection above */
    52   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     48  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    5349
    5450  /* create storage vector */
     
    5753  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5854
    59   for (i = 0; i < Nregions; i++) {
     55  for (i = 0; i < skylist[0].Nregions; i++) {
    6056    /* lock, load, unlock catalog */
    61     sprintf (filename, "%s/%s", catdir, regions[i].name);
    62     catalog.filename = filename;
     57    catalog.filename = (char *) skylist[0].regions[i][0].filename;
    6358    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6459    case 2:
     
    9085  REALLOCATE (vec[0].elements, float, MAX(1,N));
    9186
    92   if (regions != NULL) free (regions);
     87  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    9388  return (TRUE);
    9489
     
    9893
    9994escape:
    100   if (regions != NULL) free (regions);
     95  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    10196  if (catalog.average != NULL) free (catalog.average);
    10297  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/calextract.c

    r5320 r5451  
    55int calextract (int argc, char **argv) {
    66 
    7   int i, j, m, N, Nr, Nregions, mode[2];
     7  int i, j, m, N, Nr, mode[2];
    88  int Nsec, NSTAR;
    9   char filename[256], catdir[256], *RegionName, *RegionList;
     9  char *RegionName, *RegionList;
    1010  double M1, M2, dM2, color;
    1111
     12  PhotCode *code[2];
    1213  Catalog catalog;
    13   RegionFile *regions;
    14   PhotCode *code[2];
     14  SkyList *skylist;
    1515  Vector **vec;
    1616
    1717  /* these need to be freed in the end */
    18   regions = NULL;
    1918  catalog.average = NULL;
    2019  catalog.secfilt = NULL;
     
    2726  if (!InitPhotcodes ()) return (FALSE);
    2827  Nsec = GetPhotcodeNsecfilt ();
    29 
    30   /* find CATDIR in config system */
    31   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3228
    3329  /* command line arguments */
     
    5955
    6056  /* load region corresponding to selection above */
    61   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     57  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    6258
    63   for (Nr = 0; Nr < Nregions; Nr++) {
     59  for (Nr = 0; Nr < skylist[0].Nregions; Nr++) {
    6460    if (Nr && !(Nr % 500)) { fprintf (stderr, "."); }
    6561
    6662    /* lock, load, unlock catalog */
    67     sprintf (filename, "%s/%s", catdir, regions[Nr].name);
    68     catalog.filename = filename;
     63    catalog.filename = (char *) skylist[0].regions[Nr][0].filename;
    6964    switch (lock_catalog (&catalog, LCK_SOFT)) {
    7065    case 2:
     
    127122    catalog.measure = (Measure *) NULL;
    128123  }
    129   if (regions != NULL) free (regions); 
     124
     125  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    130126  for (i = 0; i < NVEC; i++) {
    131127    vec[i][0].Nelements = N;
     
    141137  if (RegionName != NULL) free (RegionName);
    142138  if (RegionList != NULL) free (RegionList);
    143   if (regions != NULL) free (regions); 
     139  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    144140  for (i = 0; i < NVEC; i++) {
    145141    DeleteVector (vec[i]);
  • trunk/Ohana/src/opihi/dvo/calmextract.c

    r5320 r5451  
    77 
    88  int i, j, k, m, N, N1, Nr, mode[2];
    9   int NSTAR, Nstar, Nsec, Nregions;
    10   char filename[256], catdir[256], *RegionName, *RegionList;
     9  int NSTAR, Nstar, Nsec;
     10  char *RegionName, *RegionList;
    1111  double *M1, M2, dM2, color;
    1212
    1313  Catalog catalog;
    14   RegionFile *regions;
    1514  PhotCode *code[2];
     15  SkyList *skylist;
    1616  Vector **vec;
    1717
    1818  /* these need to be freed in the end */
    19   regions = NULL;
    2019  catalog.average = NULL;
    2120  catalog.secfilt = NULL;
     
    2827  if (!InitPhotcodes ()) goto escape;
    2928  Nsec = GetPhotcodeNsecfilt ();
    30 
    31   /* find CATDIR in config system */
    32   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3329
    3430  /* command line arguments */
     
    7167
    7268  /* load region corresponding to selection above */
    73   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    74   if (!SetImageSelection (MEAS_XMOSAIC)) goto escape;
     69  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
     70  if (!SetImageSelection (MEAS_XMOSAIC, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
    7571
    76   for (Nr = 0; Nr < Nregions; Nr++) {
     72  for (Nr = 0; Nr < skylist[0].Nregions; Nr++) {
    7773    if (Nr && !(Nr % 500)) { fprintf (stderr, "."); }
    7874
    7975    /* lock, load, unlock catalog */
    80     sprintf (filename, "%s/%s", catdir, regions[Nr].name);
    81     catalog.filename = filename;
     76    catalog.filename = (char *) skylist[0].regions[Nr][0].filename;
    8277    switch (lock_catalog (&catalog, LCK_SOFT)) {
    8378    case 2:
     
    153148    catalog.measure = (Measure *) NULL;
    154149  }
    155   if (regions != NULL) free (regions); 
     150
     151  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    156152  for (i = 0; i < NVEC; i++) {
    157153    vec[i][0].Nelements = N;
     
    167163 
    168164  FreeImageSelection ();
    169   if (regions != NULL) free (regions); 
     165  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    170166  for (i = 0; i < NVEC; i++) {
    171167    DeleteVector (vec[i]);
  • trunk/Ohana/src/opihi/dvo/ccd.c

    r5320 r5451  
    33int ccd (int argc, char **argv) {
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, *M2;
    77  int i, m, k, Npts, NPTS, N;
    88  int N1, N2, i1, i2, mode[4];
    9   int Nsec, Nregions, KeepNulls;
     9  int Nsec, KeepNulls;
    1010
    1111  Catalog catalog;
    12   RegionFile *regions;
    1312  PhotCode *code[4];
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2524  if (!InitPhotcodes ()) goto escape;
    2625  Nsec = GetPhotcodeNsecfilt ();
    27 
    28   /* find CATDIR in config system */
    29   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3026
    3127  /* interpret command-line options */
     
    5147
    5248  /* load region corresponding to selection above */
    53   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     49  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    5450
    5551  /* init vectors to save data */
     
    6056
    6157  /* loop over regions, extract data for each region */
    62   for (k = 0; k < Nregions; k++) {
     58  for (k = 0; k < skylist[0].Nregions; k++) {
    6359    /* lock, load, unlock catalog */
    64     sprintf (filename, "%s/%s", catdir, regions[k].name);
    65     catalog.filename = filename;
     60    catalog.filename = (char *) skylist[0].regions[k][0].filename;
    6661    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6762      case 2:
     
    121116    catalog.measure = (Measure *) NULL;
    122117  }
    123   if (regions != NULL) free (regions);
     118  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    124119  xvec[0].Nelements = yvec[0].Nelements = Npts;
    125120  return (TRUE);
     
    130125
    131126escape:
    132   if (regions != NULL) free (regions);
     127  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    133128  if (catalog.average != NULL) free (catalog.average);
    134129  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/cmatch.c

    r5320 r5451  
    66  char filename[128];
    77  double radius;
    8   char catdir[256], gscdir[256];
    98  Vector *rvec, *dvec, *mvec, *drvec, *ddvec, *dmvec;
    109
    11   VarConfig ("GSCDIR", "%s", gscdir);
    12   VarConfig ("CATDIR", "%s", catdir);
    13      
    1410  if (argc != 9) {
    1511    fprintf (stderr, "USAGE: cmatch file radius (RA) (DEC) (Mag) (dRA) (dDEC) (dMag)\n");
     
    3228
    3329  /* load data from the photometry database file */
    34   sprintf (filename, "%s/%s", catdir, argv[1]);
    3530  catalog1.filename = filename;
    3631  switch (lock_catalog (&catalog1, LCK_SOFT)) {
  • trunk/Ohana/src/opihi/dvo/cmd.c

    r5320 r5451  
    33int cmd (int argc, char **argv) { /* really need to think about upper limits & how to represent them */
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, *M3;
    77  int i, j, m, i1, i3, N1, N3, N;
    88  int Npts, NPTS, mode[3];
    9   int Nsec, Nregions, KeepNulls;
     9  int Nsec, KeepNulls;
    1010
     11  PhotCode *code[3];
    1112  Catalog catalog;
    12   RegionFile *regions;
    13   PhotCode *code[3];
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2524  if (!InitPhotcodes ()) goto escape;
    2625  Nsec = GetPhotcodeNsecfilt ();
    27 
    28   /* find CATDIR in config system */
    29   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3026
    3127  /* interpret command-line options */
     
    4945
    5046  /* load region corresponding to selection above */
    51   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     47  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    5248
    5349  /* init vectors to save data */
     
    5854
    5955  /* loop over regions, extract data for each region */
    60   for (j = 0; j < Nregions; j++) {
     56  for (j = 0; j < skylist[0].Nregions; j++) {
    6157    /* lock, load, unlock catalog */
    62     sprintf (filename, "%s/%s", catdir, regions[j].name);
    63     catalog.filename = filename;
     58    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    6459    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6560    case 2:
     
    119114    catalog.measure = (Measure *) NULL;
    120115  }
    121   if (regions != NULL) free (regions);
     116  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    122117  xvec[0].Nelements = yvec[0].Nelements = Npts;
    123118  return (TRUE);
     
    128123
    129124escape:
    130   if (regions != NULL) free (regions);
     125  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    131126  if (catalog.average != NULL) free (catalog.average);
    132127  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/ddmags.c

    r5320 r5451  
    33int ddmags (int argc, char **argv) {
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, *M2;
    77  int i, m, k, N, Npts, NPTS;
    88  int N1, N2, i1, i2, mode[4];
    9   int Nsec, Nregions, KeepNulls;
     9  int Nsec, KeepNulls;
    1010
    1111  Catalog catalog;
    12   RegionFile *regions;
    1312  PhotCode *code[4];
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2524  if (!InitPhotcodes ()) goto escape;
    2625  Nsec = GetPhotcodeNsecfilt ();
    27 
    28   /* find CATDIR in config system */
    29   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3026
    3127  /* interpret command-line options */
     
    5147
    5248  /* load region corresponding to selection above */
    53   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     49  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    5450
    5551  /* init vectors to save data */
     
    6056
    6157  /* loop over regions, extract data for each region */
    62   for (k = 0; k < Nregions; k++) {
     58  for (k = 0; k < skylist[0].Nregions; k++) {
    6359    /* lock, load, unlock catalog */
    64     sprintf (filename, "%s/%s", catdir, regions[k].name);
    65     catalog.filename = filename;
     60    catalog.filename = (char *) skylist[0].regions[k][0].filename;
    6661    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6762      case 2:
     
    121116    catalog.measure = (Measure *) NULL;
    122117  }
    123   if (regions != NULL) free (regions);
     118  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    124119  xvec[0].Nelements = yvec[0].Nelements = Npts;
    125120  return (TRUE);
     
    129124
    130125escape:
    131   if (regions != NULL) free (regions);
     126  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    132127  if (catalog.average != NULL) free (catalog.average);
    133128  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/dmagaves.c

    r5320 r5451  
    33int dmagaves (int argc, char **argv) {
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, M2;
    77  int i, j, k, m, N1;
    88  int Npts, NPTS, param, mode[3];
    9   int Nsec, Nregions;
     9  int Nsec;
    1010
     11  PhotCode *code[3];
    1112  Catalog catalog;
    12   RegionFile *regions;
    13   PhotCode *code[3];
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2625  if (!InitPhotcodes ()) goto escape;
    2726  Nsec = GetPhotcodeNsecfilt ();
    28 
    29   /* find CATDIR in config system */
    30   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3127
    3228  /* interpret command-line options */
     
    4440
    4541  /* load region corresponding to selection above */
    46   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     42  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    4743
    4844  /* init vectors to save data */
     
    5248  if ((yvec = SelectVector ("yv", ANYVECTOR, TRUE)) == NULL) goto escape;
    5349
    54   for (j = 0; j < Nregions; j++) {
     50  for (j = 0; j < skylist[0].Nregions; j++) {
    5551    /* lock, load, unlock catalog */
    56     sprintf (filename, "%s/%s", catdir, regions[j].name);
    57     catalog.filename = filename;
     52    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    5853    switch (lock_catalog (&catalog, LCK_SOFT)) {
    5954    case 2:
     
    10196    catalog.measure = (Measure *) NULL;
    10297  }
    103   if (regions != NULL) free (regions);
     98  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    10499  xvec[0].Nelements = yvec[0].Nelements = Npts;
    105100  return (TRUE);
     
    110105
    111106escape:
    112   if (regions != NULL) free (regions);
     107  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    113108  if (catalog.average != NULL) free (catalog.average);
    114109  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/dmagmeas.c

    r5320 r5451  
    33int dmagmeas (int argc, char **argv) {
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, *M3;
    77  int i, j, m, i1, i3, N1, N3, N;
    88  int Npts, NPTS, param, mode[3];
    9   int Nsec, Nregions, KeepNulls;
     9  int Nsec, KeepNulls;
    1010
    1111  Catalog catalog;
    12   RegionFile *regions;
    1312  PhotCode *code[3];
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2625  if (!InitPhotcodes ()) goto escape;
    2726  Nsec = GetPhotcodeNsecfilt ();
    28 
    29   /* find CATDIR in config system */
    30   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3127
    3228  /* interpret command-line options */
     
    5046
    5147  /* load region corresponding to selection above */
    52   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    53   if (!SetImageSelection (param)) goto escape;
     48  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
     49  if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
    5450
    5551  /* init vectors to save data */
     
    6056
    6157  /* loop over regions, extract data for each region */
    62   for (j = 0; j < Nregions; j++) {
     58  for (j = 0; j < skylist[0].Nregions; j++) {
    6359    /* lock, load, unlock catalog */
    64     sprintf (filename, "%s/%s", catdir, regions[j].name);
    65     catalog.filename = filename;
     60    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    6661    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6762      case 2:
     
    122117  }
    123118  FreeImageSelection ();
    124   if (regions != NULL) free (regions);
     119  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    125120  xvec[0].Nelements = yvec[0].Nelements = Npts;
    126121  return (TRUE);
     
    132127escape:
    133128  FreeImageSelection ();
    134   if (regions != NULL) free (regions);
     129  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    135130  if (catalog.average != NULL) free (catalog.average);
    136131  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/dmags.c

    r5320 r5451  
    33int dmags (int argc, char **argv) {
    44 
    5   char filename[256], catdir[256], *RegionName, *RegionList;
     5  char *RegionName, *RegionList;
    66  double *M1, *M3;
    77  int i, j, m, i1, i3, N1, N3, N;
    88  int Npts, NPTS, mode[3];
    9   int Nsec, Nregions, KeepNulls;
     9  int Nsec, KeepNulls;
    1010
    1111  PhotCode *code[3];
    1212  Catalog catalog;
    13   RegionFile *regions;
     13  SkyList *skylist;
    1414  Vector *xvec, *yvec;
    1515
    1616  /* defaults */
    17   regions = NULL;
    1817  catalog.average = NULL;
    1918  catalog.secfilt = NULL;
     
    2524  if (!InitPhotcodes ()) goto escape;
    2625  Nsec = GetPhotcodeNsecfilt ();
    27 
    28   /* find CATDIR in config system */
    29   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3026
    3127  /* interpret command-line options */
     
    4945
    5046  /* load region corresponding to selection above */
    51   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     47  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    5248
    5349  /* init vectors to save data */
     
    5854
    5955  /* loop over regions, extract data for each region */
    60   for (j = 0; j < Nregions; j++) {
     56  for (j = 0; j < skylist[0].Nregions; j++) {
    6157    /* lock, load, unlock catalog */
    62     sprintf (filename, "%s/%s", catdir, regions[j].name);
    63     catalog.filename = filename;
     58    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    6459    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6560      case 2:
     
    119114    catalog.measure = (Measure *) NULL;
    120115  }
    121   if (regions != NULL) free (regions);
     116
     117  /* need to free SkyList / or free all regions as well */
     118  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    122119  xvec[0].Nelements = yvec[0].Nelements = Npts;
    123120  return (TRUE);
     
    132129
    133130escape:
    134   if (regions != NULL) free (regions);
     131  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    135132  if (catalog.average != NULL) free (catalog.average);
    136133  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/dmt.c

    r5448 r5451  
    66  int i, m, k, N, Ngraph, SaveVectors;
    77  int Ns, Nsec, NPTS;
    8   char catdir[256], filename[256];
    98  double Radius;
    109  float dt1, dt2, dmt1, dmt2;
     
    1918
    2019  if (!InitPhotcodes ()) return (FALSE);
    21 
    22   VarConfig ("CATDIR", "%s", catdir);
    2320
    2421  vec1 = vec2 = vec3 = vec4 = vec5 = NULL;
     
    5451  Ns = GetPhotcodeNsec (code[0].code);
    5552
    56   /* load sky from correct table */
    57   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    58   SkyTableSetFilenames (sky, CATDIR, "cpt");
     53  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    5954
    60   Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
     55  sky = GetSkyTable ();
    6156  skylist = SkyListByRadius (sky, -1, graphsky.coords.crval1, graphsky.coords.crval2, Radius);
    6257 
     
    7469
    7570    /* lock, load, unlock catalog */
    76     catalog.filename = skylist[0].regions[k][0].filename;
     71    catalog.filename = (char *) skylist[0].regions[k][0].filename;
    7772    switch (lock_catalog (&catalog, LCK_SOFT)) {
    7873    case 2:
  • trunk/Ohana/src/opihi/dvo/dvo.c

    r4714 r5451  
    1717  InitAstro ();
    1818  InitDVO ();
     19
     20  if (SetCATDIR (NULL, TRUE)) {
     21    fprintf (stderr, "CATDIR is not defined\n");
     22  }
    1923
    2024  rl_readline_name = opihi_name;
  • trunk/Ohana/src/opihi/dvo/fitcolors.c

    r5320 r5451  
    1313  int i, k, m, NP1, NP2, NP, Np, Npts, NPTS;
    1414  int N1, N2, i1, i2, mode[4];
    15   int Nsec, Nregions, status;
    16   char catdir[256], filename[256], *RegionName, *RegionList;
     15  int Nsec, status;
     16  char *RegionName, *RegionList;
    1717  char *cmd, *outcmd, *camera;
    1818  double *M1, *M2;
     
    2020
    2121  Catalog *catalog;
    22   RegionFile *regions;
    2322  PhotCode **codelist, *tcode, *code[4];
     23  SkyList *skylist;
    2424  Vector *xvec, *yvec;
    2525  Buffer *buf;
    2626
    2727  /* defaults */
    28   regions  = NULL;
    2928  catalog  = NULL;
    3029  codelist = NULL;
     
    3433  if (!InitPhotcodes ()) goto escape;
    3534  Nsec = GetPhotcodeNsecfilt ();
    36 
    37   /* find CATDIR in config system */
    38   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3935
    4036  /* interpret command-line options */
     
    9793
    9894  /* load region corresponding to selection above */
    99   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
     95  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    10096
    10197  /* loop over regions, extract data for each region */
    102   ALLOCATE (catalog, Catalog, Nregions);
    103   for (k = 0; k < Nregions; k++) {
     98  ALLOCATE (catalog, Catalog, skylist[0].Nregions);
     99  for (k = 0; k < skylist[0].Nregions; k++) {
    104100    /* lock, load, unlock catalog */
    105     sprintf (filename, "%s/%s", catdir, regions[k].name);
    106     catalog[k].filename = filename;
     101    catalog[k].filename = (char *) skylist[0].regions[k][0].filename;
    107102    switch (lock_catalog (&catalog[k], LCK_SOFT)) {
    108103      case 2:
     
    120115    unlock_catalog (&catalog[k]);
    121116  }
    122   fprintf (stderr, "using %d regions\n", Nregions);
     117  fprintf (stderr, "using %d regions\n", skylist[0].Nregions);
    123118
    124119  /* vectors to save data */
     
    137132      /* extract all magnitude pairs from catalog tables */
    138133      Npts = 0;
    139       for (k = 0; k < Nregions; k++) {
     134      for (k = 0; k < skylist[0].Nregions; k++) {
    140135        if (catalog[k].Naverage == 0) continue;
    141136
     
    186181    }
    187182  }
     183  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
     184  if (RegionName != NULL) free (RegionName);
     185  if (RegionList != NULL) free (RegionList);
    188186  return (TRUE);
    189187
     
    196194
    197195escape:
    198   if (regions != NULL) free (regions);
     196  free_catalog (catalog, skylist[0].Nregions);
     197  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
     198  if (RegionName != NULL) free (RegionName);
     199  if (RegionList != NULL) free (RegionList);
    199200  if (codelist != NULL) free (codelist);
    200201  DeleteVector (xvec);
    201202  DeleteVector (yvec);
    202   free_catalog (catalog, Nregions);
    203203  return (FALSE);
    204204}
  • trunk/Ohana/src/opihi/dvo/gcat.c

    r5448 r5451  
    88  SkyTable *sky;
    99  SkyList *skylist;
    10   char catdir[256];
    11 
    12   VarConfig ("CATDIR", "%s", catdir);
    1310
    1411  if ((argc != 3) && (argc != 4)) {
     
    1815
    1916  /* load sky from correct table */
    20   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    21   SkyTableSetFilenames (sky, CATDIR, "cpt");
    22 
    2317  Ra = atof (argv[1]);
    2418  Dec = atof (argv[2]);
     
    2822    Radius = 0.0001;
    2923
     24  sky = GetSkyTable ();
    3025  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);
    3126
    3227  for (i = 0; i < skylist[0].Nregions; i++) {
    33     if (stat (skylist[0].regions[i][0].filename, &filestat) != -1) {
    34       fprintf (stderr, "%3d %s *\n", i, regions[i].name);
     28    if (stat ((char *) skylist[0].regions[i][0].filename, &filestat) != -1) {
     29      fprintf (stderr, "%3d %s *\n", i, skylist[0].regions[i][0].name);
    3530    } else {
    36       fprintf (stderr, "%3d %s\n", i, regions[i].name);
     31      fprintf (stderr, "%3d %s\n", i, skylist[0].regions[i][0].name);
    3732    }
    38     set_str_variable ("CATNAME", regions[i].name);
     33    set_str_variable ("CATNAME", (char *) skylist[0].regions[i][0].filename);
    3934  }
    4035
    4136  return (TRUE);
    42   SkyListFree (regions);
     37  SkyListFree (skylist, FALSE);
    4338}
  • trunk/Ohana/src/opihi/dvo/gstar.c

    r5448 r5451  
    55int gstar (int argc, char **argv) {
    66 
    7   char filename[128], catdir[256], *date;
     7  char *date;
    88  double Ra, Dec, Radius, Radius2, r, dec0, dec1;
    99  double Mcat, Mrel;
     
    1818  PhotCode *code;
    1919
    20   if (VarConfig ("CATDIR", "%s", catdir) == NULL) return (FALSE);
    21 
    2220  if (!InitPhotcodes ()) return (FALSE);
    2321  Nsec = GetPhotcodeNsecfilt ();
     
    5452 
    5553  /* load sky from correct table */
    56   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    57   SkyTableSetFilenames (sky, CATDIR, "cpt");
     54  sky = GetSkyTable ();
    5855  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);
    5956
     
    6360
    6461  /* lock, load, unlock catalog */
    65   catalog.filename = skylist[0].regions[0][0].filename;
     62  catalog.filename = (char *) skylist[0].regions[0][0].filename;
    6663  switch (lock_catalog (&catalog, LCK_SOFT)) {
    6764  case 2:
  • trunk/Ohana/src/opihi/dvo/imdata.c

    r5448 r5451  
    44 
    55  int i, j, k, I;
    6   int Nimage, N, NPTS, skip, mode, TimeSelect;
    7   int n, Nregion, Ntregion, TimeFormat;
     6  int Nimage, N, NPTS, found, mode, TimeSelect;
     7  int n, Nregions, NREGIONS, TimeFormat;
    88  int *subset, Nsubset;
    9   char filename[256];
    109  double trange;
    1110  unsigned long tzero, start, stop, TimeReference;
     
    8180
    8281  /* load sky from correct table */
    83   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    84   SkyTableSetFilenames (sky, CATDIR, "cpt");
     82  sky = GetSkyTable ();
    8583
    8684  Nregions = 0;
    8785  NREGIONS = 10;
    8886  ALLOCATE (skylist, SkyList, 1);
    89   ALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS);
     87  ALLOCATE (skylist[0].regions, SkyRegion *, NREGIONS);
    9088
    9189  /* for each image of interest, find the appropriate region files */
     
    9492
    9593    if (!FindMosaicForImage (image, Nimage, I)) continue;
    96     skyset = SkyListByImage (table, -1, &image[I]);
     94    skyset = SkyListByImage (sky, -1, &image[I]);
    9795
    9896    for (j = 0; j < skyset[0].Nregions; j++) {
    9997      found = FALSE;
    100       for (k = 0; (k < skylist[0].Nregion) && !found; k++) {
    101         found = !strcmp (skylist[0].regions[k].name, skyset[0].regions[j].name);
     98      for (k = 0; (k < skylist[0].Nregions) && !found; k++) {
     99        found = !strcmp (skylist[0].regions[k][0].name, skyset[0].regions[j][0].name);
    102100      }
    103101      if (found) continue;
    104102      skylist[0].regions[Nregions] = skyset[0].regions[j];
    105103      Nregions ++;
    106       CHECK_REALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS, Nregions, 10);
    107     }
    108     SkyListFree (skyset);
     104      CHECK_REALLOCATE (skylist[0].regions, SkyRegion *, NREGIONS, Nregions, 10);
     105    }
     106    SkyListFree (skyset, FALSE);
    109107  }     
    110108  free (subset);
     
    122120
    123121    /* get file name and open */
    124     catalog.filename = skylist[0].regions[j][0].filename;
     122    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    125123    switch (lock_catalog (&catalog, LCK_SOFT)) {
    126124    case 2:
  • trunk/Ohana/src/opihi/dvo/init.c

    r5448 r5451  
    112112    AddCommand (&cmds[i]);
    113113  }
    114 
    115114}
  • trunk/Ohana/src/opihi/dvo/lcat.c

    r5448 r5451  
    44 
    55  double Radius;
    6   int i, N, Nregions, ShowAll;
    7   char filename[128], exists;
     6  int i, N, ShowAll;
     7  char exists;
    88  struct stat filestat;
    9   char catdir[256];
    109  Graphdata graphmode;
    1110  int Ngraph;
     
    1514  Ngraph = 0;
    1615  if (!GetGraphData (&graphmode, NULL, &Ngraph)) return (FALSE);
    17 
    18   VarConfig ("CATDIR", "%s", catdir);
    19 
    20   /* load sky from correct table */
    21   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    22   SkyTableSetFilenames (sky, CATDIR, "cpt");
    2316
    2417  ShowAll = FALSE;
     
    3326
    3427  Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
     28
     29  /* load sky from correct table */
     30  sky = GetSkyTable ();
    3531  skylist = SkyListByRadius (sky, -1, graphmode.coords.crval1, graphmode.coords.crval2, Radius);
    3632
    3733  for (i = 0; i < skylist[0].Nregions; i++) {
    3834    exists = 'Y';
    39     if (stat (skylist[0].regions[i][0].filename, &filestat) == -1) exists = 'N';
     35    if (stat ((char *) skylist[0].regions[i][0].filename, &filestat) == -1) exists = 'N';
    4036    if (ShowAll) {
    4137      fprintf (stderr, "%3d %s  %c\n", i, skylist[0].regions[i][0].name, exists);
     
    4743  }
    4844
     45  SkyListFree (skylist, FALSE);
    4946  return (TRUE);
    50   SkyListFree (regions);
    5147}
    5248
  • trunk/Ohana/src/opihi/dvo/lcurve.c

    r5448 r5451  
    33int lcurve (int argc, char **argv) {
    44 
    5   char filename[128], string[128], catdir[256], *p;
     5  char string[128], *p;
    66  double Ra, Dec, Radius, Radius2, r;
    77  float *RA, *DEC;
     
    1818  SkyList *skylist;
    1919
    20   VarConfig ("CATDIR", "%s", catdir);
    21 
    2220  if (!InitPhotcodes ()) return (FALSE);
    2321
     
    7068  }
    7169 
    72   /* load sky from correct table */
    73   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    74   SkyTableSetFilenames (sky, CATDIR, "cpt");
    75 
    7670  Ra = atof (argv[1]);
    7771  Dec = atof (argv[2]);
    7872  Radius = atof (argv[3]);
    7973
     74  /* load sky from correct table */
     75  sky = GetSkyTable ();
    8076  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);
    8177
     
    8581
    8682  /* set filename, read in header */
    87   catalog.filename = skylist[0].regions[0][0].filename;
     83  catalog.filename = (char *) skylist[0].regions[0][0].filename;
    8884  switch (lock_catalog (&catalog, LCK_SOFT)) {
    8985  case 2:
     
    202198  if (catalog.measure != 0) free (catalog.measure);
    203199 
    204   SkyListFree (skylist);
     200  SkyListFree (skylist, FALSE);
    205201  return (TRUE);
    206202}
  • trunk/Ohana/src/opihi/dvo/lightcurve.c

    r5448 r5451  
    33int lightcurve (int argc, char **argv) {
    44 
    5   char filename[128], catdir[256];
    65  double Ra, Dec, Radius, Radius2, r;
    76  float *RA, *DEC;
     
    98  int i, j, k, m, N, NPTS, Nsec, RELPHOT, *N1, TimeFormat;
    109  time_t TimeReference;
     10
     11  PhotCode *code;
     12  Catalog catalog;
     13  SkyTable *sky;
     14  SkyList *skylist;
    1115  Vector *tvec, *mvec, *dmvec;
    12   Catalog catalog;
    13   PhotCode *code;
    14 
    15   VarConfig ("CATDIR", "%s", catdir);
    1616
    1717  if (!InitPhotcodes ()) return (FALSE);
     
    4949  Radius = atof (argv[3]);
    5050
    51   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    52   SkyTableSetFilenames (sky, CATDIR, "cpt");
     51  sky = GetSkyTable ();
    5352  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);
    5453
     
    5857
    5958  /* set filename, read in header */
    60   catalog.filename = skylist[0].regions[0][0].filename;
     59  catalog.filename = (char *) skylist[0].regions[0][0].filename;
    6160  switch (lock_catalog (&catalog, LCK_SOFT)) {
    6261  case 2:
     
    148147  if (catalog.secfilt != 0) free (catalog.secfilt);
    149148 
    150   SkyListFree (skylist);
     149  SkyListFree (skylist, FALSE);
    151150  return (TRUE);
    152151}
  • trunk/Ohana/src/opihi/dvo/mextract.c

    r5320 r5451  
    44 
    55  int i, j, k, m, N, N1, NPTS;
    6   int param, mode, Nregions, Nsec;
    7   char filename[128], catdir[256], *RegionName, *RegionList, *p;
     6  int param, mode, Nsec;
     7  char *RegionName, *RegionList, *p;
    88  double *M1;
    99
    1010  PhotCode *code;
    1111  Catalog catalog;
    12   RegionFile *regions;
     12  SkyList *skylist;
    1313  Vector *vec;
    1414
    1515  /* defaults */
    16   regions = NULL;
    1716  catalog.average = (Average *) NULL;
    1817  catalog.secfilt = (SecFilt *) NULL;
     
    2625  if (!InitPhotcodes ()) goto escape;
    2726  Nsec = GetPhotcodeNsecfilt ();
    28 
    29   /* find CATDIR in config system */
    30   if (VarConfig ("CATDIR", "%s", catdir) == NULL) goto escape;
    3127
    3228  /* interpret command-line options */
     
    5147
    5248  /* load region corresponding to selection above */
    53   if ((regions = SelectRegions (RegionName, RegionList, &Nregions)) == NULL) goto escape;
    54   if (!SetImageSelection (param)) goto escape;
     49  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
     50  if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
    5551
    5652  /* create storage vector */
     
    5955  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    6056
    61   for (i = 0; i < Nregions; i++) {
    62     /* lock, load, unlock catalog */
    63     sprintf (filename, "%s/%s", catdir, regions[i].name);
    64     catalog.filename = filename;
     57  for (i = 0; i < skylist[0].Nregions; i++) {
     58    catalog.filename = (char *) skylist[0].regions[i][0].filename;
    6559    switch (lock_catalog (&catalog, LCK_SOFT)) {
    6660    case 2:
     
    9791  REALLOCATE (vec[0].elements, float, MAX(1,N));
    9892
    99   if (regions != NULL) free (regions);
    10093  FreeImageSelection ();
     94  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
     95  if (RegionName != NULL) free (RegionName);
     96  if (RegionList != NULL) free (RegionList);
    10197  return (TRUE);
    10298
     
    108104escape:
    109105  FreeImageSelection ();
    110   if (regions != NULL) free (regions);
     106  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
    111107  if (catalog.average != NULL) free (catalog.average);
    112108  if (catalog.secfilt != NULL) free (catalog.secfilt);
  • trunk/Ohana/src/opihi/dvo/pmeasure.c

    r5448 r5451  
    66  int i, j, k, m, N;
    77  int Ngraph;
    8   char filename[128], catdir[256];
    98  double Mz, Mr, mag;
    109  double Radius, Rmin, Rmax;
     
    2221  if (!InitPhotcodes ()) return (FALSE);
    2322  if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
    24   if (VarConfig ("CATDIR", "%s", catdir) == NULL) return (FALSE);
    2523
    2624  f = (FILE *) NULL;
     
    7674
    7775  /* load sky from correct table */
    78   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    79   SkyTableSetFilenames (sky, CATDIR, "cpt");
     76  sky = GetSkyTable ();
    8077  skylist = SkyListByRadius (sky, -1, graphmode.coords.crval1, graphmode.coords.crval2, Radius);
    8178 
     
    8481   
    8582    /* lock, load, unlock catalog */
    86     catalog.filename = skylist[0].regions[j][0].filename;
     83    catalog.filename = (char *) skylist[0].regions[j][0].filename;
    8784    switch (lock_catalog (&catalog, LCK_SOFT)) {
    8885    case 2:
  • trunk/Ohana/src/opihi/dvo/region_list.c

    r5448 r5451  
    55   information carried back up */
    66
    7 static int RegionSelect;
     7static char *CATDIR  = NULL;
     8static SkyTable *sky = NULL;
    89
    9 int GetRegionSelection () {
    10   return (RegionSelect);
     10int SetCATDIR (char *path, int verbose) {
     11
     12  char *newpath;
     13  char catdir[256];
     14  char gscfile[256];
     15  char skyfile[256];
     16  int  skydepth;
     17
     18  /* find CATDIR in config system */
     19  if (path == NULL) {
     20    if (VarConfig ("CATDIR", "%s", catdir) == NULL) return (FALSE);
     21    newpath = catdir;
     22  } else {
     23    newpath = path;
     24  }
     25
     26  if (CATDIR != NULL) free (CATDIR);
     27  CATDIR = strcreate (newpath);
     28
     29  if (VarConfig ("GSCFILE",  "%s", gscfile) == NULL) gscfile[0] = 0;
     30  if (VarConfig ("SKYFILE",  "%s", skyfile) == NULL) skyfile[0] = 0;
     31  if (VarConfig ("SKYDEPTH", "%d", &skydepth) == NULL) skydepth = 2;
     32
     33  /* load the SkyTable at this point */
     34  /* set the image path as well */
     35
     36  if (sky != NULL) SkyTableFree (sky);
     37  sky = SkyTableLoadOptimal (catdir, skyfile, gscfile, skydepth, verbose);
     38  SkyTableSetFilenames (sky, catdir, "cpt");
     39
     40  return (TRUE);
     41}
     42
     43SkyTable *GetSkyTable () {
     44  return (sky);
    1145}
    1246
     
    1448 
    1549  int N;
    16 
    17   RegionSelect = FALSE;
    1850
    1951  /* check for Region selection */
     
    3365    return (TRUE);
    3466  }
    35   if ((*RegionName == NULL) && (*RegionList == NULL)) {
    36     RegionSelect = TRUE;
    37     return (TRUE);
    38   }
     67  if ((*RegionName == NULL) && (*RegionList == NULL)) return (TRUE);
    3968
    4069  fprintf (stderr, "-cpt and -cptlist are incompatible\n");
     
    4675}
    4776
     77/* given possible options (by name, by list, by graph region), select SkyRegions */
    4878SkyList *SelectRegions (char *RegionName, char *RegionList) {
    4979
     
    5383  SkyTable *sky;
    5484  SkyList *skylist;
     85  char filename[256];
    5586
    5687  /* determine region-file names */
    5788  if (RegionName != NULL) {
    5889    ALLOCATE (skylist, SkyList, 1);
    59     ALLOCATE (skylist[0].regions[0], SkyRegion *, 1);
    60     ALLOCATE (skylist[0].regions[0][0], SkyRegion, 1);
     90    ALLOCATE (skylist[0].regions, SkyRegion *, 1);
     91    ALLOCATE (skylist[0].regions[0], SkyRegion, 1);
    6192    strcpy (skylist[0].regions[0][0].name, RegionName);
    6293    sprintf (filename, "%s/%s.cpt", CATDIR, RegionName);
    63     skylist[0].regions[0][0].filename = strcreate (filename);
     94    skylist[0].regions[0][0].filename = (e_void) strcreate (filename);
    6495    free (RegionName);
    6596    RegionName = NULL;
     
    80111
    81112  Radius = MAX (fabs(graphsky.xmax), fabs(graphsky.ymax));
    82 
    83   /* load sky from correct table */
    84   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    85   SkyTableSetFilenames (sky, CATDIR, "cpt");
    86   skylist = SkyListByRadius (sky, -1, graphmode.coords.crval1, graphmode.coords.crval2, Radius);
     113  skylist = SkyListByRadius (sky, -1, graphsky.coords.crval1, graphsky.coords.crval2, Radius);
    87114
    88115  return (skylist);
    89116}
    90117
    91 /* XXX EAM this should perhaps return a skytable? */
    92118/* returns a list of region files names from file */
    93 SkyList *SkyListFromFile (char *filename) {
     119SkyList *SkyListLoadFile (char *filename) {
    94120 
    95121  FILE *f;
    96   int NREGIONS, nregion;
     122  int NREGIONS, Nregions;
    97123  SkyList *skylist;
    98124
     
    115141    strcpy (skylist[0].regions[Nregions][0].name, filename);
    116142    sprintf (filename, "%s/%s.cpt", CATDIR, skylist[0].regions[Nregions][0].name);
    117     skylist[0].regions[Nregions][0].filename = strcreate (filename);
     143    skylist[0].regions[Nregions][0].filename = (e_void) strcreate (filename);
    118144    Nregions ++;
    119145    CHECK_REALLOCATE (skylist[0].regions, SkyRegion *, NREGIONS, Nregions, 50);
    120     }
    121146  }
    122 
    123   *Nregions = nregion;
    124   return (regions);
     147  skylist[0].Nregions = Nregions;
     148  return (skylist);
    125149}
    126150
  • trunk/Ohana/src/opihi/dvo/skycat.c

    r5442 r5451  
    11# include "dvo1.h"
     2
     3int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside);
    24
    35int skycat (int argc, char **argv) {
     
    57  double Radius;
    68  int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside, Depth, TableDepth;
    7   char filename[128];
    89  struct stat filestat;
    910  Vector Xvec, Yvec;
    1011  Graphdata graphmode;
    1112  double X[4], Y[4], Rmin, Rmax, Rmid;
    12   char catdir[256], gscfile[256];
    1313  int Ngraph, VERBOSE;
    1414  SkyTable *sky;
    1515  SkyList *skylist;
    1616  SkyRegion **regions;
    17 
    18   VarConfig ("CATDIR", "%s", catdir);
    19   VarConfig ("GSCFILE", "%s", gscfile);
    2017
    2118  VERBOSE = FALSE;
     
    4542
    4643  Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
    47   sky = SkyTableFromGSC (gscfile, TableDepth, VERBOSE);
    48   if (sky == NULL) return (FALSE);
     44
     45  sky = GetSkyTable ();
    4946  skylist = SkyListByRadius (sky, Depth, graphmode.coords.crval1, graphmode.coords.crval2, Radius);
    5047 
     
    6663
    6764  for (i = 0; i < Nregions; i++) {
    68     sprintf (filename, "%s/%s", catdir, regions[i][0].name);
    69     if (ShowAll || (stat (filename, &filestat) != -1)) {
     65    if (ShowAll || (stat ((char *) regions[i][0].filename, &filestat) != -1)) {
    7066      if (VERBOSE) fprintf (stderr, "%3d %s %6.2f - %6.2f, %6.2f - %6.2f\n", i, regions[i][0].name,
    7167                            regions[i][0].Rmin, regions[i][0].Rmax, regions[i][0].Dmin, regions[i][0].Dmax);
     
    114110
    115111}
     112
     113
     114int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside) {
     115
     116  while (r < Rmin) { r += 360.0; }
     117  while (r > Rmax) { r -= 360.0; }
     118
     119  if (*leftside == -1) {
     120    *leftside = (r < Rmid);
     121  } else {
     122    if (  *leftside && (r > Rmid + 90)) { r -= 360.0; }
     123    if (! *leftside && (r < Rmid - 90)) { r += 360.0; }
     124  }
     125
     126  RD_to_XY (x, y, r, d, coords);
     127
     128  return (TRUE);
     129}
  • trunk/Ohana/src/opihi/dvo/subpix.c

    r5448 r5451  
    1313  double Ra, Dec, Radius, Radius2, r, Rmin;
    1414  double *RA, *DEC;
    15   char catdir[256], filename[256];
    1615 
     16  SkyTable *sky;
     17  SkyList *skylist;
    1718  Measure *measure;
    1819  Image *image;
     
    2021
    2122  if (!InitPhotcodes ()) return (FALSE);
    22 
    23   VarConfig ("CATDIR", "%s", catdir);
    2423
    2524  GetTimeFormat (&TimeReference, &TimeFormat);
     
    3433  Radius = atof (argv[3]);
    3534
    36   /* load sky from correct table */
    37   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
    38   SkyTableSetFilenames (sky, CATDIR, "cpt");
    39 
    4035  /* load star nearest position */
     36  sky = GetSkyTable ();
    4137  skylist = SkyListByRadius (sky, -1, Ra, Dec, Radius);
    4238  if (skylist[0].Nregions > 1) {
     
    4541
    4642  /* lock, load, unlock catalog */
    47   catalog.filename = skylist[0].regions[0][0].filename;
     43  catalog.filename = (char *) skylist[0].regions[0][0].filename;
    4844  switch (lock_catalog (&catalog, LCK_SOFT)) {
    4945  case 2:
     
    9490    if (catalog.average != 0) free (catalog.average);
    9591    if (catalog.measure != 0) free (catalog.measure);
    96     SkyListFree (skylist);
     92    SkyListFree (skylist, FALSE);
    9793    return (TRUE);
    9894  }
     
    160156  free (image);
    161157  free (index);
    162   SkyListFree (regions);
     158  SkyListFree (skylist, FALSE);
    163159
    164160  return (TRUE);
  • trunk/Ohana/src/opihi/include/dvo1.h

    r5442 r5451  
    5757int           GetMeasureTypeCode    PROTO((Measure *measure));
    5858int           GetPhotcodeInfo       PROTO((char *string, PhotCode **Code, int *Mode));
    59 int           GetRegionSelection    PROTO(());
    6059int           GetSelectionParam     PROTO(());
    6160int           GetTimeSelection      PROTO((time_t *tz, time_t *te));
     
    6867int           Quality               PROTO((Measure *measure, int IsDophot));
    6968int           SelectMags            PROTO((int Nphot, int Tphot, int Ns, Average *average, Measure *measure, SecFilt *secfilt, int UL));
    70 RegionFile   *SelectRegions         PROTO((char *RegionName, char *RegionList, int *nregions));
    71 int           SetImageSelection     PROTO((int mode));
     69
     70SkyList      *SelectRegions         PROTO((char *RegionName, char *RegionList));
     71SkyList      *SkyListLoadFile       PROTO((char *filename));
     72int           SetCATDIR             PROTO((char *path, int verbose));
     73SkyTable     *GetSkyTable           PROTO(());
     74SkyList      *SkyListFromFile       PROTO((char *filename));
     75int           SetRegionSelection    PROTO((int *argc, char **argv, char **RegionName, char **RegionList));
     76
     77int           SetImageSelection     PROTO((int mode, int RegionSelect));
    7278int           SetPhotSelections     PROTO((int *argc, char **argv, int Nparams));
    73 int           SetRegionSelection    PROTO((int *argc, char **argv, char **RegionName, char **RegionList));
    7479int           SetSelectionParam     PROTO((int param));
    7580int           TestAverage           PROTO((PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure));
    7681int           TestPhotSelections    PROTO((PhotCode **code, int *mode, int param));
    77 void          aregion               PROTO((GSCRegion *region, FILE *f, double ra, double dec, char *path));
    7882void          compare               PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec,  Vector *dvec,  Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius));
    7983void          cprecess              PROTO((Average *average, int Naverage, double in_epoch, double out_epoch));
    80 RegionFile   *find_regions          PROTO((double Ra, double Dec, double radius, int *Nregions));
    81 GSCRegion    *get_regions           PROTO((Image *image, int *Nregions));
    8284void          image_subset          PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, Graphdata *graph, int RegionSelect, unsigned long int tzero, double trange, int TimeSelect));
    8385int           match_image           PROTO((Image *image, int Nimage, unsigned int T, short int S));
    8486int           match_image_subset    PROTO((Image *image, int *subset, int Nsubset, unsigned int T, short int S));
    8587void          print_value           PROTO((FILE *f, double value, short int ival));
    86 RegionFile   *region_list           PROTO((char *filename, int *Nregions));
    8788void          sort_image_subset     PROTO((Image *image, int *subset, int N));
    8889void          sort_images           PROTO((Image *image, int N));
    8990void          sortave               PROTO((Average *ave, int N));
    90 CMPstars *cmpReadFits (FILE *f, int *nstars);
    91 CMPstars *cmpReadText (FILE *f, int *nstars);
    92 int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside);
     91CMPstars     *cmpReadFits           PROTO((FILE *f, int *nstars));
     92CMPstars     *cmpReadText           PROTO((FILE *f, int *nstars));
     93int           RD_to_XYpic           PROTO((double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside));
     94
     95RegionFile   *find_regions          PROTO((double Ra, double Dec, double radius, int *Nregions));
     96GSCRegion    *get_regions           PROTO((Image *image, int *Nregions));
     97RegionFile   *region_list           PROTO((char *filename, int *Nregions));
     98void          aregion               PROTO((GSCRegion *region, FILE *f, double ra, double dec, char *path));
    9399
    94100# endif
Note: See TracChangeset for help on using the changeset viewer.