IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2005, 9:14:00 AM (21 years ago)
Author:
eugene
Message:

adjust to use match DVO catalog access methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/delstar/src/image-db.c

    r4607 r4680  
    77static int dbstate = LCK_UNLOCK;
    88
     9static Header header;
     10static Image *image = NULL;
     11static int   Nimage;
     12
    913FILE *GetDB (int *state) {
    1014  *state = dbstate;
    1115  return (f);
     16}
     17
     18Image *GetImages (int *nimage) {
     19  *nimage = Nimage;
     20  return (image);
     21}
     22
     23int SetImages (Image *new, int Nnew) {
     24  Nimage = Nnew;
     25  image  =  new;
     26  fits_modify (&header, "NIMAGES", "%d", 1, Nimage);
     27  return (TRUE);
    1228}
    1329
     
    2339  va_start (argp, format);
    2440  vfprintf (stderr, formatplus, argp);
    25   free (formatplus);
    2641  va_end (argp);
    2742
     
    3752  f = fsetlockfile (ImageCat, 3600.0, LOCK, &dbstate);
    3853  if (f == NULL) {
    39     fprintf (stderr, "ERROR: can't lock image catalog\n");
    40     exit (1);
     54    Shutdown ("ERROR: can't lock image catalog");
     55  }
     56  if (dbstate == LCK_EMPTY) {
     57    Shutdown ("ERROR: database is empty");
    4158  }
    4259  fseek (f, 0, SEEK_SET);
    4360}
    4461
    45 void unlock_image_db (Image *image) {
     62int load_image_db () {
     63
     64  int nimage;
     65
     66  /* read header */
     67  fseek (f, 0, SEEK_SET);
     68  if (!fits_fread_header (f, &header)) {
     69    Shutdown ("can't read image catalog %s", ImageCat);
     70  }
     71  fseek (f, header.size, SEEK_SET);
     72
     73  Nimage = 0;
     74  fits_scan (&header, "NIMAGES", "%d", 1, &Nimage);
     75  ALLOCATE (image, Image, Nimage);
     76
     77  nimage = Fread (image, sizeof(Image), Nimage, f, "image");
     78  if (nimage != Nimage) {
     79    Shutdown ("error reading images from db file");
     80  }
     81 
     82  return (TRUE);
     83}
     84
     85int save_image_db () {
     86
     87  int status;
     88  char line[1024];
     89  mode_t mode;
     90
     91  /* use cp to make backup copy */
     92  sprintf (line, "cp %s %s~", ImageCat, ImageCat);
     93  status = system (line);
     94  if (status) {
     95    Shutdown ("ERROR: unable to create %s~, exiting", ImageCat);
     96  }
     97  mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
     98  sprintf (line, "%s~", ImageCat);
     99  chmod (line, mode);
     100
     101  /* update header */
     102  fits_modify (&header, "NIMAGES", "%d", 1, Nimage);
     103
     104  /* write out data to already opened file */
     105  fseek (f, 0, SEEK_SET);
     106  Fwrite (header.buffer, 1, header.size, f, "char");
     107  Fwrite (image, sizeof(Image), Nimage, f, "image");
     108
     109  return (TRUE);
     110}
     111
     112void unlock_image_db () {
    46113
    47114  mode_t mode;
    48 
    49   /* protect wimage from interrupt signals */
    50   if (MODE == M_IMAGE) {
    51     SetProtect (TRUE);
    52     wimage (image);
    53     SetProtect (FALSE);
    54   }
    55115
    56116  fclearlockfile (ImageCat, f, LOCK, &dbstate);
Note: See TracChangeset for help on using the changeset viewer.