IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33869


Ignore:
Timestamp:
May 16, 2012, 4:16:14 PM (14 years ago)
Author:
eugene
Message:

move max path length to dvo.h and rename DVO_MAX_PATH; HostTable.index should not be unsigned (we use -1 as an unassigned value, and 215 is sufficient); add functions to save a backup of the database table, and remove the backup if desired; add \n to some error messages

Location:
branches/eam_branches/ipp-20120405/Ohana/src/libdvo
Files:
4 edited

Legend:

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

    r33649 r33869  
    6969  NAN_U_INT   = (signed int) 0xffffffff,
    7070} DVO_INT_NAN;
     71
     72// max path length
     73# define DVO_MAX_PATH 1024
    7174
    7275/* RegImage.flag values */
     
    268271  int Nhosts;
    269272  HostInfo *hosts;
    270   unsigned short *index;
     273  short *index;
    271274} HostTable;
    272275
     
    516519void dvo_catalog_test (Catalog *catalog, int halt);
    517520
     521int dvo_catalog_backup (Catalog *catalog, int primary);
     522int dvo_catalog_unlink_backup (Catalog *catalog, int primary);
     523
    518524/* catmode-specific APIs */
    519525int dvo_catalog_load_raw (Catalog *catalog, int VERBOSE);
  • branches/eam_branches/ipp-20120405/Ohana/src/libdvo/src/HostTable.c

    r33649 r33869  
    121121  table->hosts = hosts;
    122122
    123   ALLOCATE (table->index, unsigned short, maxID + 1);
     123  ALLOCATE (table->index, short, maxID + 1);
    124124  for (i = 0; i <= maxID; i++) table->index[i] = -1;
    125125
    126126  for (i = 0; i < table->Nhosts; i++) {
    127     if (table->index[table->hosts[i].hostID] == -1) {
     127    if (table->index[table->hosts[i].hostID] != -1) {
    128128      fprintf (stderr, "error: duplicate hostID %d\n", table->hosts[i].hostID);
    129129      exit (1);
  • branches/eam_branches/ipp-20120405/Ohana/src/libdvo/src/dvo_catalog.c

    r33649 r33869  
    499499}
    500500
     501// make a backup of this catalog (including the measure, secfilt, and missing tables as needed)
     502int dvo_catalog_backup (Catalog *catalog, int primary) {
     503
     504  // skip empty cpt files
     505  if (primary && !catalog->Naves_disk) {
     506    return TRUE;
     507  }
     508
     509  char tmpfilename[DVO_MAX_PATH];
     510  int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s~", catalog->filename);
     511  if (status >= DVO_MAX_PATH) {
     512    fprintf (stderr, "path name too long: %s\n", catalog->filename);
     513    return FALSE;
     514  }
     515     
     516  // unlock the catalog here (closes file as well) (also closes subcat files Measure, Secfilt, Missing)
     517  if (primary) {
     518    status = dvo_catalog_unlock (catalog);
     519    if (!status) {
     520      fprintf (stderr, "failed to unlock catalog %s\n", catalog->filename);
     521      return FALSE;
     522    }
     523  }
     524
     525  status = rename (catalog->filename, tmpfilename);
     526  if (status) {
     527    fprintf (stderr, "failed to rename catalog %s\n", catalog->filename);
     528    return FALSE;
     529  }
     530     
     531  // keep the same lockmode
     532  int lockmode = catalog->lockmode;
     533
     534  // lock the new catalog file here (re-opens file as well) (does NOT open/lock the subcat files)
     535  status = dvo_catalog_lock (catalog, lockmode);
     536  if (!status) {
     537    fprintf (stderr, "failed to lock new catalog file %s\n", catalog->filename);
     538    return FALSE;
     539  }
     540
     541  if (catalog[0].catmode == DVO_MODE_SPLIT) {
     542    if (catalog[0].measure_catalog != NULL) {
     543      if (!dvo_catalog_backup (catalog[0].measure_catalog, FALSE)) {
     544        return FALSE;
     545      }
     546    }
     547    if (catalog[0].missing_catalog != NULL) {
     548      if (!dvo_catalog_backup (catalog[0].missing_catalog, FALSE)) {
     549        return FALSE;
     550      }
     551    }
     552    if (catalog[0].secfilt_catalog != NULL) {
     553      if (!dvo_catalog_backup (catalog[0].secfilt_catalog, FALSE)) {
     554        return FALSE;
     555      }
     556    }
     557  }
     558  return TRUE;
     559}
     560
     561// make a backup of this catalog (including the measure, secfilt, and missing tables as needed)
     562int dvo_catalog_unlink_backup (Catalog *catalog, int primary) {
     563
     564  if (primary && !catalog->Naves_disk) {
     565    // skip empty files (empty when read, but output may not be empty)
     566    return TRUE;
     567  }
     568
     569  char tmpfilename[DVO_MAX_PATH];
     570  int status = snprintf (tmpfilename, DVO_MAX_PATH, "%s~", catalog->filename);
     571  if (status >= DVO_MAX_PATH) {
     572    fprintf (stderr, "path name too long: %s\n", catalog->filename);
     573    return FALSE;
     574  }
     575     
     576  status = unlink (tmpfilename);
     577  if (status) {
     578    fprintf (stderr, "failed to unlink catalog %s\n", catalog->filename);
     579    return FALSE;
     580  }
     581     
     582  if (catalog[0].catmode == DVO_MODE_SPLIT) {
     583    if (catalog[0].measure_catalog != NULL) {
     584      if (!dvo_catalog_unlink_backup (catalog[0].measure_catalog, FALSE)) {
     585        return FALSE;
     586      }
     587    }
     588    if (catalog[0].missing_catalog != NULL) {
     589      if (!dvo_catalog_unlink_backup (catalog[0].missing_catalog, FALSE)) {
     590        return FALSE;
     591      }
     592    }
     593    if (catalog[0].secfilt_catalog != NULL) {
     594      if (!dvo_catalog_unlink_backup (catalog[0].secfilt_catalog, FALSE)) {
     595        return FALSE;
     596      }
     597    }
     598  }
     599  return TRUE;
     600}
     601
  • branches/eam_branches/ipp-20120405/Ohana/src/libdvo/src/dvo_catalog_split.c

    r33649 r33869  
    8080  // write PHU header
    8181  if (!gfits_fwrite_header  (catalog->f, &catalog->header)) {
    82     fprintf (stderr, "can't write primary header");
     82    fprintf (stderr, "can't write primary header\n");
    8383    return (FALSE);
    8484  }
     
    8787  gfits_create_matrix (&catalog->header, &matrix);
    8888  if (!gfits_fwrite_matrix  (catalog->f, &matrix)) {
    89     fprintf (stderr, "can't write primary matrix");
     89    fprintf (stderr, "can't write primary matrix\n");
    9090    gfits_free_matrix (&matrix);
    9191    return (FALSE);
     
    9595  // write the table data
    9696  if (!gfits_fwrite_ftable_range (catalog->f, ftable, start, Nrows, Ndisk, Ntotal)) {
    97     fprintf (stderr, "can't write table data");
     97    fprintf (stderr, "can't write table data\n");
    9898    return (FALSE);
    9999  }
Note: See TracChangeset for help on using the changeset viewer.