IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4


Ignore:
Timestamp:
Nov 21, 2002, 10:06:13 PM (23 years ago)
Author:
eugene
Message:

clean error handling

Location:
trunk/Ohana/src/imregister
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/imreg/db.c

    r3 r4  
    1111RegImage *image;
    1212int Nimage;
    13 int lockstate, dbstate;
     13int lockstate;
     14int dbstate = LCK_UNLOCK;
    1415
    1516RegImage *get_images (int *N) {
     
    4445  /* lock database (soft) */
    4546  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
    46   if (dbstate == LCK_EMPTY) return (0);
    47 
    4847  if (f == (FILE *) NULL) {
    4948    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
    5049    exit (1);
    5150  }
     51  if (dbstate == LCK_EMPTY) return (0);
    5252
    5353  /* load in table data */
    5454  table.header = &theader;
    55   fits_fread_header (f, &header);
    56   fits_fread_matrix (f, &matrix, &header);
    57   fits_fread_ftable  (f, &table, "IMAGE_DATABASE");
     55  if (!fits_fread_header (f, &header))                     escape (UNLOCK, "ERROR: can't read primary header");
     56  if (!fits_fread_matrix (f, &matrix, &header))            escape (UNLOCK, "ERROR: can't read primary header");
     57  if (!fits_fread_ftable  (f, &table, "IMAGE_DATABASE"))   escape (UNLOCK, "ERROR: can't read primary header");
    5858
    5959  /* convert to internal format */
     
    6363  Nimage = Ny;
    6464
    65   ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage");
     65  if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage"))
     66    escape (UNLOCK, "ERROR: can't read primary header");
     67
    6668  return (1);
    6769}
     
    7072int save_db () {
    7173
    72   ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage");
     74  if (!ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage"))
     75    escape (UNLOCK, "ERROR: can't convert from native format");
    7376
    7477  /* write all images to file */
    7578  make_backup (dBFile);
    7679  Fseek (f, 0, SEEK_SET);
    77   fits_fwrite_header (f, &header);
    78   fits_fwrite_matrix (f, &matrix);
    79   fits_fwrite_Theader (f, &theader);
    80   fits_fwrite_table   (f, &table);
     80  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
     81  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
     82  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
     83  if (!fits_fwrite_table   (f, &table))   escape (LOCK, "ERROR: can't update db");
    8184  fclearlockfile (dBFile, f, lockstate, &dbstate);
    8285  return (TRUE);
     
    114117  make_backup (dBFile);
    115118  Fseek (f, 0, SEEK_SET);
    116   fits_fwrite_header (f, &header);
    117   fits_fwrite_matrix (f, &matrix);
    118   fits_fwrite_Theader (f, &theader);
    119   fits_fwrite_vtable   (f, &vtable);
     119  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
     120  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
     121  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
     122  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't update db");
    120123  fclearlockfile (dBFile, f, lockstate, &dbstate);
    121124  return (TRUE);
     
    126129  VTable vtable;
    127130
    128   fits_table_to_vtable (&table, &vtable);
     131  /* add error checks! */
     132  fits_table_to_vtable (&table, &vtable, 0, 0);
    129133
    130134  ConvertStruct ((char *) new, sizeof (RegImage), Nnew, "regimage");
     
    133137  /* write subset to file */
    134138  Fseek (f, 0, SEEK_SET);
    135   fits_fwrite_header (f, &header);
    136   fits_fwrite_matrix (f, &matrix);
    137   fits_fwrite_Theader (f, &theader);
    138   fits_fwrite_vtable   (f, &vtable);
     139  if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't append to db");
     140  if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't append to db");
     141  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't append to db");
     142  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't append to db");
     143
    139144  fclearlockfile (dBFile, f, lockstate, &dbstate);
    140145  return (TRUE);
     
    156161
    157162int close_db () {
    158   fclearlockfile (dBFile, f, LCK_HARD, &dbstate);
     163  if (dbstate == LCK_UNLOCK) return (TRUE);
     164  fclearlockfile (dBFile, f, lockstate, &dbstate);
    159165  return (TRUE);
    160166
    161167
     168int escape (int mode, char *message) {
     169 
     170  if (mode == UNLOCK) close_db ();
     171  fprintf (stderr, "%s\n", message);
     172  exit (1);
     173}
  • trunk/Ohana/src/imregister/src/imregtable.c

    r3 r4  
    11# include "imregister.h"
    22# include "imreg.h"
    3 static char *version = "imregtable $Revision: 3.0 $";
     3static char *version = "imregtable $Revision: 3.1 $";
    44
    55int main (int argc, char **argv) {
     
    2222  }
    2323  infile = argv[1];
     24  output.modify = TRUE;
    2425
    2526  /* load in table data */
    2627  table.header = &theader;
    27   fits_read_header (infile, &header);
    28   fits_read_matrix (infile, &matrix, &header);
    29   fits_read_ftable  (infile, &table, "IMAGE_DATABASE");
     28  if (!fits_read_header (infile, &header))                   escape (UNLOCK, "can't open file header");
     29  if (!fits_read_matrix (infile, &matrix, &header))          escape (UNLOCK, "can't open file matrix");
     30  if (!fits_read_ftable  (infile, &table, "IMAGE_DATABASE")) escape (UNLOCK, "can't open file table");
    3031
    3132  /* convert to internal format */
     
    4647  exit (0);
    4748}
    48 
Note: See TracChangeset for help on using the changeset viewer.