Changeset 4680 for trunk/Ohana/src/delstar/src/image-db.c
- Timestamp:
- Jul 30, 2005, 9:14:00 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/delstar/src/image-db.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/delstar/src/image-db.c
r4607 r4680 7 7 static int dbstate = LCK_UNLOCK; 8 8 9 static Header header; 10 static Image *image = NULL; 11 static int Nimage; 12 9 13 FILE *GetDB (int *state) { 10 14 *state = dbstate; 11 15 return (f); 16 } 17 18 Image *GetImages (int *nimage) { 19 *nimage = Nimage; 20 return (image); 21 } 22 23 int SetImages (Image *new, int Nnew) { 24 Nimage = Nnew; 25 image = new; 26 fits_modify (&header, "NIMAGES", "%d", 1, Nimage); 27 return (TRUE); 12 28 } 13 29 … … 23 39 va_start (argp, format); 24 40 vfprintf (stderr, formatplus, argp); 25 free (formatplus);26 41 va_end (argp); 27 42 … … 37 52 f = fsetlockfile (ImageCat, 3600.0, LOCK, &dbstate); 38 53 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"); 41 58 } 42 59 fseek (f, 0, SEEK_SET); 43 60 } 44 61 45 void unlock_image_db (Image *image) { 62 int 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 85 int 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 112 void unlock_image_db () { 46 113 47 114 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 }55 115 56 116 fclearlockfile (ImageCat, f, LOCK, &dbstate);
Note:
See TracChangeset
for help on using the changeset viewer.
