IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 5, 2012, 3:28:10 PM (14 years ago)
Author:
eugene
Message:

add a database ID to the image header when creating; function for creating database ID

Location:
branches/eam_branches/ipp-20120805/Ohana/src/libdvo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20120805/Ohana/src/libdvo/include/dvo.h

    r34291 r34388  
    623623int dvo_image_save_raw (FITS_DB *db, int VERBOSE);
    624624int dvo_image_addrows (FITS_DB *db, Image *new, off_t Nnew);
     625int dvo_image_createID (Header *header);
    625626void dvo_image_create (FITS_DB *db, double ZeroPoint);
    626627
  • branches/eam_branches/ipp-20120805/Ohana/src/libdvo/src/dvo_image.c

    r34260 r34388  
    200200  gfits_modify (&db[0].header, "NIMAGES", "%d", 1, 0);
    201201  gfits_modify (&db[0].header, "ZERO_PT", "%lf", 1, ZeroPoint);
     202 
     203  dvo_image_createID (&db[0].header);
    202204
    203205  if (db[0].format == DVO_FORMAT_INTERNAL)        gfits_modify (&db[0].header, "FORMAT", "%s", 1, "INTERNAL");
     
    217219  return;
    218220}
     221
     222// given a dvo image db, add an ID to the header
     223int dvo_image_createID (Header *header) {
     224 
     225  char dbID[33];
     226
     227  if (!header->buffer) return FALSE;
     228
     229  int status = gfits_scan (header, "DVO_DBID", "%s", 1, dbID);     
     230  if (status) {
     231    // do not add a DVO_DBID to a table which already has one
     232    return TRUE;
     233  }
     234
     235  // I have a header, I want to add ONE line.  double check there is enough space
     236  char *p = gfits_header_field (header, "END", 1);
     237  if (p == NULL) {
     238    fprintf (stderr, "header is missing END\n");
     239    return FALSE;
     240  }
     241  if (p - header->buffer + 80 == header->datasize) {
     242    fprintf (stderr, "no free space in block, can't insert keyword\n");
     243    return FALSE;
     244  }
     245
     246  int start_size = header->datasize;
     247
     248  long A = time(NULL);
     249  srand48(A);
     250 
     251  int i;
     252  for (i = 0; i < 32; i++) {
     253    sprintf (&dbID[i], "%1x", (int)(16.0*drand48()));
     254  }
     255
     256  gfits_modify (header, "DVO_DBID", "%s", 1, dbID);     
     257  if (start_size != header->datasize) {
     258    fprintf (stderr, "error: header buffer grew? (%d to %d bytes)\n", (int) start_size, (int) header->datasize);
     259    return FALSE;
     260  }
     261  return TRUE;
     262}
     263
Note: See TracChangeset for help on using the changeset viewer.