IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3538


Ignore:
Timestamp:
Mar 29, 2005, 9:21:03 AM (21 years ago)
Author:
eugene
Message:

fits_db cleanups

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

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/photreg/args.photreg.c

    r3536 r3538  
    137137
    138138void usage () { 
    139   fprintf (stderr, "USAGE: photreg (-zp zp) (-dzp dzp) (-tstart date) (-dt dt) (-photcode code)\n");
     139  fprintf (stderr, "USAGE: photreg (-zp zp) (-dzp dzp) (-trange start range|end) (-photcode code)\n");
    140140  fprintf (stderr, "       [-label label] [-offset] [-Nmeas N] [-Ntime N] [-db trans]\n");
    141141  exit (1);
  • trunk/Ohana/src/imregister/src/photreg.c

    r3536 r3538  
    11# include "imregister.h"
    22# include "photreg.h"
    3 static char *version = "photreg $Revision: 1.4 $";
     3static char *version = "photreg $Revision: 1.5 $";
    44
    55int main (int argc, char **argv) {
     
    1717  fits_db_init (&db);
    1818
    19   if (!strcmp (output.db, "phot")) {
    20     filename = PhotDB;
    21   } else {
    22     filename = TransDB;
    23   }
     19  filename = PhotDB;
     20  if (!strcmp (output.db, "trans")) filename = TransDB;
    2421
    25   if (!fits_db_lock (&db, filename)) {
    26     fits_db_close (&db);
    27     exit (1);
    28   }
     22  if (!fits_db_lock (&db, filename)) exit (1);
     23
    2924  if (db.dbstate == LCK_EMPTY) {
    3025    fits_init_header (&db.header);   
  • trunk/Ohana/src/imregister/src/photsearch.c

    r3536 r3538  
    11# include "imregister.h"
    22# include "photreg.h"
    3 static char *version = "photsearch $Revision: 1.4 $";
     3static char *version = "photsearch $Revision: 1.5 $";
    44
    55int main (int argc, char **argv) {
     
    2525  }
    2626
    27   if (!fits_db_lock (&db, filename)) {
    28     fits_db_close (&db);
    29     exit (1);
    30   }
     27  if (!fits_db_lock (&db, filename)) exit (1);
    3128 
    3229  if (!fits_db_load (&db)) {
  • trunk/Ohana/src/libohana/src/fits_db.c

    r3508 r3538  
    1616  /* database name must be set first */
    1717  if (filename == NULL) {
    18     fprintf (stderr, "ERROR: db file is not set\n");
     18    fprintf (stderr, "db file is not set\n");
    1919    return (FALSE);
    2020  }
     
    2222  /* database handle must be set first */
    2323  if (db == NULL) {
    24     fprintf (stderr, "ERROR: db handle is not set\n");
     24    fprintf (stderr, "db handle is not set\n");
    2525    return (FALSE);
    2626  }
     
    2929  db[0].f = fsetlockfile (filename, db[0].timeout, db[0].lockstate, &db[0].dbstate);
    3030  if (db[0].f == NULL) {
    31     fprintf (stderr, "ERROR: cannot set lock on db\n");
     31    fprintf (stderr, "cannot set lock on db file %s\n", filename);
    3232    return (FALSE);
    3333  }
     
    4242  /* database name must be set first */
    4343  if (db == NULL) {
    44     fprintf (stderr, "ERROR: db handle is not set\n");
     44    fprintf (stderr, "db handle is not set\n");
    4545    return (FALSE);
    4646  }
     
    4848  /* init & load in FITS table data - return FALSE on error */
    4949  if (!fits_fread_header (db[0].f, &db[0].header)) {
    50     fprintf (stderr, "ERROR: can't read primary header\n");
     50    fprintf (stderr, "can't read primary header\n");
    5151    return (FALSE);
    5252  }
    5353  if (!fits_fread_matrix (db[0].f, &db[0].matrix, &db[0].header)) {
    54     fprintf (stderr, "ERROR: can't read primary matrix");
     54    fprintf (stderr, "can't read primary matrix");
    5555    return (FALSE);
    5656  }
    5757  if (!fits_fread_header (db[0].f, &db[0].theader)) {
    58     fprintf (stderr, "ERROR: can't read table header");
     58    fprintf (stderr, "can't read table header");
    5959    return (FALSE);
    6060  }
    6161  if (!fits_fread_ftable_data (db[0].f, &db[0].ftable)) {
    62     fprintf (stderr, "ERROR: can't read table data");
     62    fprintf (stderr, "can't read table data");
    6363    return (FALSE);
    6464  }
     
    7474
    7575  if (!fits_fwrite_header  (db[0].f, &db[0].header)) {
    76     fprintf (stderr, "ERROR: can't write primary header");
     76    fprintf (stderr, "can't write primary header");
    7777    return (FALSE);
    7878  }
    7979  if (!fits_fwrite_matrix  (db[0].f, &db[0].matrix)) {
    80     fprintf (stderr, "ERROR: can't write primary matrix");
     80    fprintf (stderr, "can't write primary matrix");
    8181    return (FALSE);
    8282  }
    8383  if (!fits_fwrite_Theader (db[0].f, &db[0].theader)) {
    84     fprintf (stderr, "ERROR: can't write table header");
     84    fprintf (stderr, "can't write table header");
    8585    return (FALSE);
    8686  }
    8787  if (!fits_fwrite_table   (db[0].f, &db[0].ftable)) {
    88     fprintf (stderr, "ERROR: can't write table data");
     88    fprintf (stderr, "can't write table data");
    8989    return (FALSE);
    9090  }
     
    103103  /* do we revert to the old version if this fails? */
    104104  if (!fits_fwrite_header   (db[0].f, &db[0].header))  {
    105     fprintf (stderr, "ERROR: can't update primary header");
     105    fprintf (stderr, "can't update primary header");
    106106    return (FALSE);
    107107  }
    108108  if (!fits_fwrite_matrix   (db[0].f, &db[0].matrix))  {
    109     fprintf (stderr, "ERROR: can't update primary matrix");
     109    fprintf (stderr, "can't update primary matrix");
    110110    return (FALSE);
    111111  }
    112112  if (!fits_fwrite_Theader  (db[0].f, &db[0].theader)) {
    113     fprintf (stderr, "ERROR: can't update table header");
     113    fprintf (stderr, "can't update table header");
    114114    return (FALSE);
    115115  }
    116116  if (!fits_fwrite_vtable   (db[0].f, vtable))  {
    117     fprintf (stderr, "ERROR: can't update table data");
     117    fprintf (stderr, "can't update table data");
    118118    return (FALSE);
    119119  }
  • trunk/Ohana/src/libohana/src/glockfile.c

    r3364 r3538  
    11# include <ohana.h>
    22
    3 /* lockfile concepts:
    4    
    5    set a lockfile on [path]/filename. 
    6    we allow three types of locks:
    7    LCK_HARD - exclusive lock with persistent lock file
    8    LCK_XCLD - exclusive lock, no persistent lock file
    9    LCK_SOFT - shared lock
    10 
    11    both lock types set a filesystem-level lock on the given file,
    12     using exclusive for hard and shared for soft locks
    13 
    14    a hard lock also uses a lockfile to make the lock permanent:
    15     the lockfile must be actively removed and will not vanish
    16     even if the locking program dies
    17 
    18    a soft lock will vanish if the locking program dies.
    19 
    20    if a hard lock is set, both hard & soft locks will block
    21    if a soft lock is set, a hard lock will block, but not a soft lock
    22 
    23    the hard lockfile uses the file [path]/.filename.lck
    24 
    25    setlockfile2 returns a file descriptor to an open READ/WRITE access file,
    26      or -1 on failure, and sets state.
    27 */
    28 
     3/* set a lock on the given file */
    294FILE *fsetlockfile (char *filename, double timeout, int type, int *state) {
    305 
     
    5934  return (status);
    6035}
     36
     37/* should eventually rewrite these two to use a stream as the basic
     38   element and only grab the fileno when needed by fcntl
     39   (fileno cannot fail) */
    6140
    6241int setlockfile2 (char *filename, double timeout, int type, int *state) {
     
    9473  default:
    9574    fprintf (stderr, "invalid lock type %d\n", type);
     75    goto failure;
    9676  }
    9777
     
    121101      goto failure;
    122102    }
    123     usleep (1000);
     103    usleep (10000); /* 10 ms is min */
    124104
    125105    /* try to lock file */
Note: See TracChangeset for help on using the changeset viewer.