IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 124


Ignore:
Timestamp:
Oct 14, 2003, 12:35:40 PM (23 years ago)
Author:
eugene
Message:

added 'update' mode which makes the database consistent with the data
on disk (existence in all altpath locations).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/detrend/altpath.c

    r76 r124  
    77  int Nimage, Nlist, Ncurrent, Nadd, Nremove;
    88  int *list, *current, *curfound, *add, *remove;
    9   char *dBPath, input[256], output[256], line[1024];
     9  char *dBPath, infile[256], outfile[256], line[1024];
    1010  DetReg *image;
    11  
     11  struct stat statbuf;
     12
    1213  image = get_images (&Nimage);
    1314  ALLOCATE (current, int, Nimage);
    1415
    15   /* identify current altpath images */
    16   Ncurrent = 0;
    17   for (i = 0; i < Nimage; i++) {
    18     if (image[i].altpath) {
    19       current[Ncurrent] = i;
    20       Ncurrent++;
    21     }
    22   }
    23 
    24   /* extract 'remove' and 'add' entries from current & match */
    25   ALLOCATE (remove, int, Nimage);
    26   ALLOCATE (add, int, Nimage);
    27  
    28   ALLOCATE (curfound, int, Ncurrent);
    29   bzero (curfound, Ncurrent*sizeof(int));
    30 
    31   Nadd = Nremove = 0;
    32   for (i = 0; i < Nmatch; i++) {
    33     found = FALSE;
    34     for (j = 0; !found && (j < Ncurrent); j++) {
    35       if (match[i].image == current[j]) {
    36         found = TRUE;
    37         curfound[j] = TRUE;
    38       }
    39     }
    40     if (!found) {
    41       add[Nadd] = match[i].image;
    42       Nadd ++;
    43     }
    44   }
    45   for (i = 0; i < Ncurrent; i++) {
    46     if (!curfound[i]) {
    47       remove[Nremove] = current[i];
    48       Nremove ++;
    49     }
    50   }
    51   free (current);
    52   free (curfound);
    53  
    5416  ALLOCATE (list, int, Nimage);
    5517  Nlist = 0;
     
    5820
    5921  /* set altpath for 'add' images */
    60   for (j = 0; j < Nadd; j++) {
    61     i = add[j];
    62     image[i].altpath = TRUE;
    63     list[Nlist] = i;
    64     Nlist ++;
    65     for (n = 0; n < NDetrendAltDB; n++) {
    66       sprintf (input, "%s/%s", dBPath, image[i].filename);
    67       sprintf (output, "%s/%s", DetrendAltDB[n], image[i].filename);
    68       status = ckpathname (output);
    69       if (!status) {
    70         remove[Nremove] = i;
    71         Nremove ++;
    72         break;
    73       }
    74       sprintf (line, "cp %s %s", input, output);
    75       fprintf (stderr, "%s\n", line);
    76       status = system (line);
    77       if (status) {
    78         remove[Nremove] = i;
    79         Nremove ++;
    80         break;
     22  if (output.Altpath == ADD) {
     23    /* find images to add */
     24    for (i = 0; i < Nmatch; i++) {
     25      if (image[match[i].image].altpath == FALSE) {
     26        list[Nlist] = match[i].image;
     27        Nlist ++;
    8128      }
    8229    }
     30    /* copy the masters to the altpath locations */
     31    for (j = 0; j < Nlist; j++) {
     32      i = list[j];
     33      for (n = 0; n < NDetrendAltDB; n++) {
     34        sprintf (infile, "%s/%s", dBPath, image[i].filename);
     35        sprintf (outfile, "%s/%s", DetrendAltDB[n], image[i].filename);
     36        status = ckpathname (outfile);
     37        if (!status) {
     38          fprintf (stderr, "warning: can't make outfile directory for %s\n", outfile);
     39          continue;
     40        }
     41        sprintf (line, "cp %s %s", infile, outfile);
     42        fprintf (stderr, "%s\n", line);
     43        status = system (line);
     44        if (status) {
     45          fprintf (stderr, "warning: can't make outfile directory for %s\n", outfile);
     46          continue;
     47        }
     48      }
     49      image[i].altpath = TRUE;
     50    }
     51    update_db (list, Nlist);
     52    close_db ();
     53    fprintf (stderr, "SUCCESS\n");
     54    exit (0);
    8355  }
    8456
    85   /* unset altpath for 'remove' images */
    86   for (j = 0; j < Nremove; j++) {
    87     i = remove[j];
    88     image[i].altpath = FALSE;
    89     list[Nlist] = i;
    90     Nlist ++;
    91     for (n = 0; n < NDetrendAltDB; n++) {
    92       sprintf (output, "%s/%s", DetrendAltDB[n], image[i].filename);
    93       sprintf (line, "rm %s", output);
    94       fprintf (stderr, "%s\n", line);
    95       status = system (line);
    96       if (status) {
    97         fprintf (stderr, "warning: can't delete %s\n", output);
     57  /* unset altpath for 'delete' images */
     58  if (output.Altpath == DELETE) {
     59    /* find images to delete */
     60    for (i = 0; i < Nmatch; i++) {
     61      if (image[match[i].image].altpath == TRUE) {
     62        list[Nlist] = match[i].image;
     63        Nlist ++;
    9864      }
    9965    }
     66    /* remove the copies from the altpath locations */
     67    for (j = 0; j < Nlist; j++) {
     68      i = list[j];
     69      image[i].altpath = FALSE;
     70      for (n = 0; n < NDetrendAltDB; n++) {
     71        sprintf (outfile, "%s/%s", DetrendAltDB[n], image[i].filename);
     72        sprintf (line, "rm %s", outfile);
     73        fprintf (stderr, "%s\n", line);
     74        status = system (line);
     75        if (status) {
     76          fprintf (stderr, "warning: can't delete %s\n", outfile);
     77        }
     78      }
     79    }
     80    update_db (list, Nlist);
     81    close_db ();
     82    fprintf (stderr, "SUCCESS\n");
     83    exit (0);
    10084  }
    10185
    102   update_db (list, Nlist);
    103   close_db ();
    104   fprintf (stderr, "SUCCESS\n");
    105   exit (0);
     86  /* check for existence in altpath, set flag as appropriate */
     87  if (output.Altpath == UPDATE) {
     88    for (j = 0; j < Nmatch; j++) {
     89      i = match[j].image;
     90      list[Nlist] = i;
     91      Nlist ++;
     92      found = TRUE;
     93      for (n = 0; found && (n < NDetrendAltDB); n++) {
     94        sprintf (outfile, "%s/%s", DetrendAltDB[n], image[i].filename);
     95        status = stat (outfile, &statbuf);
     96        fprintf (stderr, "checking for %s, status is %d\n", outfile, status);
     97        if (status == -1) found = FALSE;
     98      }
     99      image[i].altpath = found;
     100    }
     101    update_db (list, Nlist);
     102    close_db ();
     103    fprintf (stderr, "SUCCESS\n");
     104    exit (0);
     105  }
    106106
     107  fprintf (stderr, "unknown altpath mode: %d\n", output.Altpath);
    107108}
    108109
     
    131132  return (TRUE);
    132133}
     134
Note: See TracChangeset for help on using the changeset viewer.