IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12488


Ignore:
Timestamp:
Mar 18, 2007, 12:09:07 PM (19 years ago)
Author:
eugene
Message:

allow input components to fail without dropping the entire file / set of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/src/gstars.c

    r12461 r12488  
    55Stars *gstars (char *filename, int *Nstars, Image **images, int *Nimages, int photcode) {
    66
    7   int i, j, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
     7  int i, j, N, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
    88  int Nskip, Nhead, Ndata, done, status, mode, NinStars;
    99  char **file, *name;
     
    5252    Nimage = Nfile;
    5353    ALLOCATE (image, Image, Nimage);
    54     for (i = 0; i < Nfile; i++) {
     54    for (i = N = 0; i < Nfile; i++) {
     55      // XXX we should not drop all input images if one fails
    5556      if (i > 0) {
    5657        f = fopen (file[i], "r");
    5758        if (f == NULL) {
    58           fprintf (stderr, "ERROR: can't read header for %s\n", file[i]);
    59           exit (1);
     59          fprintf (stderr, "can't read header for %s, skipping\n", file[i]);
     60          continue;
    6061        }
    6162        gfits_fread_header (f, header);
    6263      }
    6364
    64       ReadImageHeader (header, &image[i], photcode);
     65      if (!ReadImageHeader (header, &image[N], photcode)) {
     66        fprintf (stderr, "skipping %s\n", file[i]);
     67        continue;
     68      }
    6569     
    6670      /* find image rootname */
    6771      name = filebasename (file[i]);
    68       snprintf (image[i].name, 32, name);
     72      snprintf (image[N].name, 32, name);
    6973      free (name);
    7074   
     
    7276        case SIMPLE_CMP:
    7377        case MOSAIC_CMP:
    74           inStars = ReadStarsTEXT (f, &image[i].nstar);
    75           inStars = FilterStars (inStars, &image[i]);
    76           stars = MergeStars (stars, Nstars, inStars, image[i].nstar);
     78          inStars = ReadStarsTEXT (f, &image[N].nstar);
     79          inStars = FilterStars (inStars, &image[N]);
     80          stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
    7781          break;
    7882
    7983        case SIMPLE_CMF:
    8084        case MOSAIC_CMF:
    81           inStars = ReadStarsFITS (f, header, NULL, &image[i].nstar);
    82           inStars = FilterStars (inStars, &image[i]);
    83           stars = MergeStars (stars, Nstars, inStars, image[i].nstar);
     85          inStars = ReadStarsFITS (f, header, NULL, &image[N].nstar);
     86          inStars = FilterStars (inStars, &image[N]);
     87          stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
    8488          break;
    8589
     
    9195      fclose (f);
    9296      gfits_free_header (header);
     97      N++;
    9398    }
    94     *Nimages = Nimage;
     99    *Nimages = N;
    95100    *images = image;
    96101   
     102    if (N == 0) {
     103      fprintf (stderr, "ERROR: no valid image data in %s, giving up\n", filename);
     104      exit (1);
     105    }
     106
    97107    return stars;
    98108  }
     
    206216
    207217  // now run through the images, interpret the headers and read the stars
    208   for (i = 0; i < Nimage; i++) {
     218  for (i = N = 0; i < Nimage; i++) {
    209219      Nhead = extnum_head[i];
    210220
    211221      if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", exthead[i], extdata[i]);
    212       ReadImageHeader (headers[Nhead], &image[i], 0);
     222      if (!ReadImageHeader (headers[Nhead], &image[N], 0)) {
     223          fprintf (stderr, "skipping %s\n", exthead[i]);
     224          continue;
     225      }
    213226
    214227      // XXX use something to set the chip name? EXTNAME?
    215228      if (!strcmp(exthead[i], "PHU") && (Nimage == 1)) {
    216         snprintf (image[i].name, 32, "%s", name);
     229        snprintf (image[N].name, 32, "%s", name);
    217230      } else {
    218         snprintf (image[i].name, 32, "%s.%s", name, exthead[i]);
    219       }
    220 
    221       // this is an error we should not encounter
    222       if (!strcmp(extdata[i], "PHU")) Shutdown ("error in data segment: PHU cannot be table");
     231        snprintf (image[N].name, 32, "%s.%s", name, exthead[i]);
     232      }
     233
     234      // skip the table if there is not data segment (eg, mosaic WRP image)
     235      if (!strcmp(extdata[i], "NONE")) {
     236          N++;
     237          continue;
     238      }
    223239
    224240      // advance the pointer to the start of the corresponding table block
     
    230246      fseek (f, Nskip, SEEK_SET);
    231247         
    232       inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &image[i].nstar);
    233       inStars = FilterStars (inStars, &image[i]);
    234       stars = MergeStars (stars, Nstars, inStars, image[i].nstar);
     248      inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &image[N].nstar);
     249      inStars = FilterStars (inStars, &image[N]);
     250      stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
     251      N++;
    235252  }
    236253  free (name);
    237   *Nimages = Nimage;
     254  *Nimages = N;
    238255  *images = image;
     256
     257  if (N == 0) {
     258    fprintf (stderr, "ERROR: no valid image data in %s, giving up\n", filename);
     259    exit (1);
     260  }
    239261
    240262  return stars;
Note: See TracChangeset for help on using the changeset viewer.