Пример #1
0
static void recalibration(char *str, report_level_t level)
{
  asfReport(level, "Hardcoded calibration parameters published by JAXA are "
	    "automatically applied:\n%s\n"
	    "If you don't want to apply these changes, please "
	    "(temporarily) remove\nthe workreport file.\n", str);
}
Пример #2
0
void create_cal_params(const char *inSAR, meta_parameters *meta, 
		       report_level_t level)
{
  int ii, kk;
  struct dataset_sum_rec dssr; // Data set summary record
  double *noise;
  char sarName[512], *facilityStr, *processorStr, *error;
  ceos_description *ceos; 
  meta->calibration = meta_calibration_init();

  strcpy (sarName, inSAR);

  if (isCEOS(sarName, &error)) {
    // Check for the various processors
    get_dssr(sarName, &dssr);
    facilityStr = trim_spaces(dssr.fac_id);
    processorStr = trim_spaces(dssr.sys_id);
    
    ceos = get_ceos_description_ext(inSAR, REPORT_LEVEL_NONE, FALSE);

    if (strncmp(facilityStr , "ASF"  , 3) == 0 &&
	strncmp(processorStr, "FOCUS", 5) != 0 &&
	((meta->projection && meta->projection->type == SCANSAR_PROJECTION) ||
	 (meta->projection &&
	  (strcmp_case(meta->general->mode, "SWA") == 0 || 
	   strcmp_case(meta->general->mode, "SWB") == 0))
	 )
	) {
      // ASF internal processor (PP or SSP), ScanSar data
      asf_scansar_cal_params *asf = MALLOC(sizeof(asf_scansar_cal_params));
      meta->calibration->type = asf_scansar_cal;
      meta->calibration->asf_scansar = asf;
      
      // Get values for calibration coefficients and LUT
      struct VRADDR rdr; // Radiometric data record
      get_raddr(sarName, &rdr);
      
      // hardcodings for not-yet-calibrated fields
      if (rdr.a[0] == -99.0 || rdr.a[1]==0.0 ) {
	asf->a0 = 1.1E4;
	asf->a1 = 2.2E-5;
	asf->a2 = 0.0;
      }
      else {
	asf->a0 = rdr.a[0];
	asf->a1 = rdr.a[1];
	asf->a2 = rdr.a[2];
      }
      
      // Set the Noise Correction Vector to correct version
      if (strncmp(dssr.cal_params_file,"SSPSWB010.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb010\n");
	noise = sspswb010_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB011.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb011\n");
	noise = sspswb011_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB013.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb013\n");
	noise = sspswb013_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB014.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb014\n");
	noise = sspswb014_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB015.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb015\n");
	noise = sspswb015_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB016.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb016\n");
	noise = sspswb015_noise_vec;
	// 16 and 15 were identical antenna patterns, only metadata fields were
	// changed, so the noise vector for 16 is the same and that for 15. JBN
      }
      else
	noise = rdr.noise;
      
      for (kk=0; kk<256; ++kk)
	asf->noise[kk] = noise[kk];
      
    }
    else if (strncmp(facilityStr, "ASF", 3)== 0 &&
	     strncmp(processorStr, "FOCUS", 5) != 0) {
      // ASF internal processor (PP or SSP) (non-Scansar)
      asf_cal_params *asf = (asf_cal_params *) MALLOC(sizeof(asf_cal_params));
      meta->calibration->type = asf_cal;
      meta->calibration->asf = asf;
      
      // Get values for calibration coefficients and LUT
      struct VRADDR rdr; // Radiometric data record
      get_raddr(sarName, &rdr);
      
      // hardcodings for not-yet-calibrated fields
      if (rdr.a[0] == -99.0 || rdr.a[1]==0.0 ) {
	asf->a0 = 1.1E4;
	asf->a1 = 2.2E-5;
	asf->a2 = 0.0;
      }
      else {
	asf->a0 = rdr.a[0];
	asf->a1 = rdr.a[1];
	asf->a2 = rdr.a[2];
      }
      
      if (ceos->product == SLC && ceos->sensor == ERS &&
	  meta->general->radiometry > r_AMP &&
	  meta->general->radiometry < r_POWER) {
	asfPrintStatus("Applying calibration adjustment of x1.3 for SLC data."
		       "\n");
	asf->a1 *= 1.3;
      }
      
      // grab the noise vector
      for (kk=0; kk<256; ++kk)
	asf->noise[kk] = rdr.noise[kk];
      asf->sample_count = meta->general->sample_count;
    }
    else if ((strncmp(facilityStr, "ASF", 3) == 0 &&
	      strncmp(dssr.sys_id, "FOCUS", 5) == 0) ||
	     (strncmp(facilityStr, "CDPF", 4) == 0 ||
	      strncmp(facilityStr, "RSI", 3) == 0 ||
	      ((strncmp(facilityStr, "CSTARS", 6) == 0 ||
		strncmp(facilityStr, "TRNS", 4) == 0) &&
	       strncmp(dssr.mission_id, "RSAT", 4) == 0))) {
      // Radarsat style calibration
      rsat_cal_params *rsat =
	(rsat_cal_params *) MALLOC(sizeof(rsat_cal_params));
      meta->calibration->type = rsat_cal;
      meta->calibration->rsat = rsat;
      rsat->slc = FALSE;
      rsat->focus = FALSE;
      if (strncmp(dssr.product_type, "SLANT RANGE COMPLEX", 19) == 0 ||
	  strncmp(dssr.product_type,
		  "SPECIAL PRODUCT(SINGL-LOOK COMP)", 32) == 0) {
	rsat->slc = TRUE;
      }
      if (strncmp(dssr.sys_id, "FOCUS", 5) == 0)
	rsat->focus = TRUE;
      
      // Read lookup up table from radiometric data record
      struct RSI_VRADDR radr;
      get_rsi_raddr(sarName, &radr);
      rsat->n = radr.n_samp;
      //rsat->lut = (double *) MALLOC(sizeof(double) * rsat->n);
      for (ii=0; ii<rsat->n; ii++) {
	if (strncmp(dssr.sys_id, "FOCUS", 5) == 0)
	  rsat->lut[ii] = radr.lookup_tab[0];
	else
	  rsat->lut[ii] = radr.lookup_tab[ii];
      }
      rsat->samp_inc = radr.samp_inc;
      rsat->a3 = radr.offset;
      
    }
    else if (strncmp(facilityStr, "ES", 2)      == 0 ||
	     strncmp(facilityStr, "D-PAF", 5)   == 0 ||
	     strncmp(facilityStr, "I-PAF", 2)   == 0 ||
	     strncmp(facilityStr, "Beijing", 7) == 0 ||
	     (strncmp(facilityStr, "CSTARS", 6) == 0 &&
	      (strncmp(dssr.mission_id, "E", 1) == 0 ||
	       strncmp(dssr.mission_id, "J", 1) == 0))
	     ) {
      // ESA style calibration
      esa_cal_params *esa = (esa_cal_params *) MALLOC(sizeof(esa_cal_params));
      meta->calibration->type = esa_cal;
      meta->calibration->esa = esa;
      
      // Read calibration coefficient and reference incidence angle
      struct ESA_FACDR facdr;
      get_esa_facdr(sarName, &facdr);
      esa->k = facdr.abs_cal_const;
      esa->ref_incid = dssr.incident_ang;
    }
    else if (strncmp(facilityStr, "EOC", 3) == 0) {
      // ALOS processor
      struct alos_rad_data_rec ardr; // ALOS Radiometric Data record
      alos_cal_params *alos =
	(alos_cal_params *) MALLOC(sizeof(alos_cal_params));
      meta->calibration->type = alos_cal;
      meta->calibration->alos = alos;
      
      // Determine beam mode
      int beam = dssr.ant_beam_num;
      int beam_count = dssr.nchn;
      if (beam >= 0 && beam <= 35 && beam_count == 2)
	beam += 36; // actually dual-pol data (HH+HV or VV+VH)
      else if (beam == 3 && beam_count == 4)
	beam = 127; // actually PLR 21.5
      else if (beam_count == 1 && dssr.product_id[3] == 'S') {
	// some fine backwards engineering here to figure out the correct beam
	// number - off nadir angle and processing bandwidth required
	// don't care for the HH versus VV at the moment
	if (dssr.off_nadir_angle < 25.0) {
	  if (dssr.bnd_rng < 20000.0)
	    beam = 72; // WB1 HH3scan
	  else
	    beam = 73; // WB2 HH3scan
	}
	else if (dssr.off_nadir_angle > 25.0 && dssr.off_nadir_angle < 26.0) {
	  if (dssr.off_nadir_angle < 25.0) {
	    if (dssr.bnd_rng < 20000.0)
	      beam = 76; // WB1 HH4scan
	    else
	      beam = 77; // WB2 HH4scan
	  }
	}
	else {
	  if (dssr.bnd_rng < 20000.0)
	    beam = 80; // WB1 HH5scan
	  else
	    beam = 81; // WB2 HH5scan
	}
      }
      
      // Reading calibration coefficient
      get_ardr(sarName, &ardr);
      if (strncmp(dssr.lev_code, "1.1", 3) == 0) { // SLC
	// HH polarization
	if ((beam >=   0 && beam <=  17) || // FBS HH polarization
	    (beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >=  72 && beam <=  73) || // WB  HH3scan
	    (beam >=  76 && beam <=  77) || // WB  HH4scan
	    (beam >=  80 && beam <=  81) || // WB  HH5scan
	    (beam >=  84 && beam <= 101) || // DSN HH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hh = ardr.calibration_factor - 32;
	else
	  alos->cf_hh = MAGIC_UNSET_DOUBLE;
	// HV polarization
	if ((beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hv = ardr.calibration_factor - 32;
	else
	  alos->cf_hv = MAGIC_UNSET_DOUBLE;
	// VH polarization
	if ((beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vh = ardr.calibration_factor - 32;
	else
	  alos->cf_vh = MAGIC_UNSET_DOUBLE;
	// VV polarization
	if ((beam >=  18 && beam <=  35) || // FBS VV polarization
	    (beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >=  74 && beam <=  75) || // WB  VV3scan
	    (beam >=  78 && beam <=  79) || // WB  VV4scan
	    (beam >=  82 && beam <=  83) || // WB  VV5scan
	    (beam >= 102 && beam <= 119) || // DSN VV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vv = ardr.calibration_factor - 32;
	else
	  alos->cf_vv = MAGIC_UNSET_DOUBLE;
      }
      else if (strncmp(dssr.lev_code, "1.5", 3) == 0) { // regular detected
	// HH polarization
	if ((beam >=   0 && beam <=  17) || // FBS HH polarization
	    (beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >=  72 && beam <=  73) || // WB  HH3scan
	    (beam >=  76 && beam <=  77) || // WB  HH4scan
	    (beam >=  80 && beam <=  81) || // WB  HH5scan
	    (beam >=  84 && beam <= 101) || // DSN HH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hh = ardr.calibration_factor;
	else
	  alos->cf_hh = MAGIC_UNSET_DOUBLE;
	// HV polarization
	if ((beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hv = ardr.calibration_factor;
	else
	  alos->cf_hv = MAGIC_UNSET_DOUBLE;
	// VH polarization
	if ((beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vh = ardr.calibration_factor;
	else
	  alos->cf_vh = MAGIC_UNSET_DOUBLE;
	// VV polarization
	if ((beam >=  18 && beam <=  35) || // FBS VV polarization
	    (beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >=  74 && beam <=  75) || // WB  VV3scan
	    (beam >=  78 && beam <=  79) || // WB  VV4scan
	    (beam >=  82 && beam <=  83) || // WB  VV5scan
	    (beam >= 102 && beam <= 119) || // DSN VV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vv = ardr.calibration_factor;
	else
	  alos->cf_vv = MAGIC_UNSET_DOUBLE;
      }
      
      // Check on processor version
      // Prior to processor version 9.02 some calibration parameters have been
      // determined again.
      double version;
      if (!get_alos_processor_version(inSAR, &version))
	asfReport(level, "Could not find workreport file!\n"
		  "Calibration parameters applied to the data might be "
		  "inaccurate!\n");
      else if (version < 9.02) {
	char str[512];
	
	switch (beam)
	  {
	  case 0: 
	    alos->cf_hh = -83.16; // FBS  9.9 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 3:
	    alos->cf_hh = -83.55; // FBS 21.5 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 7:
	    alos->cf_hh = -83.40; // FBS 34.3 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 10:
	    alos->cf_hh = -83.65; // FBS 41.5 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 35:
	    alos->cf_hh = -83.30; // FBS 50.8 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 43:
	    alos->cf_hh = -83.20; // FBD 34.3 HH
	    alos->cf_hv = -80.20; // FBD 34.3 HV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\n", alos->cf_hh, alos->cf_hv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	    }
	    break;
	  case 46:
	    alos->cf_hh = -83.19; // FBD 41.5 HH
	    alos->cf_hv = -80.19; // FBD 41.5 HV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\n", alos->cf_hh, alos->cf_hv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	    }
	    break;
	  case 127:
	    alos->cf_hh = -83.40; // PLR 21.5 HH
	    alos->cf_hv = -83.40; // PLR 21.5 HV
	    alos->cf_vh = -83.40; // PLR 21.5 VH
	    alos->cf_vv = -83.40; // PLR 21.5 VV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\nVH: %.2lf\nVV: %.2lf", 
		    alos->cf_hh, alos->cf_hv, alos->cf_vh, alos->cf_vv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	      alos->cf_vh -= 32;
	      alos->cf_vv -= 32;
	    }
	    break;
	  }
      }
    }
  }
  else if (isTerrasar(sarName, &error)) {
    // TSX style calibration
    tsx_cal_params *tsx = (tsx_cal_params *) MALLOC(sizeof(tsx_cal_params));
    meta->calibration->type = tsx_cal;
    meta->calibration->tsx = tsx;

    terrasar_meta *terrasar = read_terrasar_meta(sarName);
    tsx->k = terrasar->cal_factor; // calibration factor in beta naught
    FREE(terrasar);
  }
  else
    // should never get here
    asfPrintWarning("Unknown calibration parameter scheme!\n");

}
Пример #3
0
int get_tiff_data_config(TIFF *tif,
                         short *sample_format, short *bits_per_sample, short *planar_config,
                         data_type_t *data_type, short *num_bands,
                         int *is_scanline_format, int *is_palette_color_tiff, report_level_t report_level)
{
  int     ret = 0, read_count;
  uint16  planarConfiguration = 0;
  uint16  bitsPerSample = 0;
  uint16  sampleFormat = 0;
  uint16  samplesPerPixel = 0;

  *data_type = -1;
  *num_bands = 0;

  /*********************************************************/
  /*  Read all tags and accept them as-is into the fields  */
  /*********************************************************/
  // Required tag for all images
  ret = 0;

  tiff_type_t t;
  get_tiff_type(tif, &t);
  *is_scanline_format = (t.format == SCANLINE_TIFF) ? 1 : 0;
  if (t.format != SCANLINE_TIFF &&
      t.format != STRIP_TIFF    &&
      t.format != TILED_TIFF)
  {
    ret = -1;
  }

  read_count = TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitsPerSample);
  if (read_count) *bits_per_sample = bitsPerSample;

  read_count += TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sampleFormat);
  if (read_count < 2          &&
      (bitsPerSample == 8   ||
       bitsPerSample == 16  ||
       bitsPerSample == 32))
  {
      asfReport(report_level,
              "Found missing or invalid sample format.  Should be unsigned integer,\n"
              "integer, or IEEE floating point.\n");
      switch (bitsPerSample) {
          case 8:
              asfReport(report_level,
                    "Data is 8-bit data ...guessing unsigned integer sample\n"
                        "format and attempting to continue.\n");
              sampleFormat = SAMPLEFORMAT_UINT;
              read_count++;
              break;
          case 16:
              asfReport(report_level,
                    "Data is 16-bit data ...guessing signed integer sample\n"
                        "format and attempting to continue.\n");
              sampleFormat = SAMPLEFORMAT_INT;
              read_count++;
              break;
          case 32:
              asfReport(report_level,
                    "Data is 32-bit data ...guessing IEEE floating point sample\n"
                        "format and attempting to continue.\n");
              sampleFormat = SAMPLEFORMAT_IEEEFP;
              read_count++;
              break;
          default:
              ret = -1;
              break;
      }
  }
  if (read_count == 2) {
    *sample_format = sampleFormat;
    switch (sampleFormat) {
      case SAMPLEFORMAT_UINT:
      {
        switch (bitsPerSample) {
          case 8:
            *data_type = BYTE;
            break;
          case 16:
            *data_type = INTEGER32;
            break;
          case 32:
            *data_type = REAL32;
            break;
          default:
            *data_type = 0;
            break;
        }
      }
      break;
      case SAMPLEFORMAT_INT:
      {
        switch (bitsPerSample) {
          case 8:
          case 16:
            *data_type = INTEGER16;
            break;
          case 32:
            *data_type = INTEGER32;
            break;
          default:
            *data_type = 0;
            break;
        }
      }
      break;
      case SAMPLEFORMAT_IEEEFP:
      {
        *data_type = REAL32;
      }
      break;
      default:
      {
        switch (bitsPerSample) {
          case 8:
              // Most likely unsigned 8-bit byte
            *data_type = BYTE;
            break;
          case 16:
              // Most likely 16-bit integer
            *data_type = INTEGER16;
            break;
          case 32:
              // Most likely 32-bot float
            *data_type = REAL32;
            break;
          default:
            *data_type = 0;
            break;
        }
      }
      break;
    }
  }

  read_count = TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel);
  if (read_count != 1) {
      samplesPerPixel = 0;
  }

  unsigned short *maps[3];
  read_count = TIFFGetField(tif, TIFFTAG_COLORMAP, maps+0, maps+1, maps+2);
  *is_palette_color_tiff = 0;
  if (read_count) {
    if (samplesPerPixel == 1) {
      *is_palette_color_tiff = 1;
    }
    // NOTE: Do not free the colormaps ...this results in a glib double-free error
    // when closing the tiff file.
  }

  read_count = TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planarConfiguration);
  if (read_count) *planar_config = planarConfiguration;

  /*********************************************************/
  /*  Determine health                                     */
  /*********************************************************/

  if (bitsPerSample != 8  &&
      bitsPerSample != 16 &&
      bitsPerSample != 32)
  {
    // Only support byte, integer16, integer32, and 32-bit floats
    ret = -1;
  }
  else {
      *num_bands = samplesPerPixel;
  }

  if (sampleFormat != SAMPLEFORMAT_UINT &&
      sampleFormat != SAMPLEFORMAT_INT  &&
      sampleFormat != SAMPLEFORMAT_IEEEFP)
  {
    ret = -1;
  }

  if (samplesPerPixel < 1 || samplesPerPixel > MAX_BANDS) {
    // Only support 1 through MAX_BANDS bands in the image
    ret = -1;
  }

  if (samplesPerPixel > 1 &&
      planarConfiguration != PLANARCONFIG_CONTIG &&
      planarConfiguration != PLANARCONFIG_SEPARATE)
  {
    ret = -1;
  }

  // Required tag only for color (multi-band) images
  if (ret == 0 && samplesPerPixel > 1) {
    if (planarConfiguration != PLANARCONFIG_CONTIG &&
        planarConfiguration != PLANARCONFIG_SEPARATE)
    {
      ret = guess_planar_configuration(tif, planar_config);
      if (ret == 0) {
          asfReport(report_level,
                "Found multi-band TIFF but the planar configuration TIFF tag\n"
                    "is not populated ...GUESSING the planar configuration to be %s\n"
                    "based on calculated scanline lengths for interlaced and band-sequential\n"
                    "TIFFs v. the actual scanline length derived from the TIFF file itself.\n",
                    (*planar_config == PLANARCONFIG_CONTIG) ?
                    "Contiguous Planes (interlaced)" :
                    (*planar_config == PLANARCONFIG_SEPARATE) ?
                    "Separate Planes (band-sequential)" :
                    "Unknown Planar Config (?)");
      }
    }
  }

  return ret;
}
Пример #4
0
void baseline_catalog(char *sensor, char *beam_mode, char *input_dir, 
		      char *output_dir)
{
  struct dirent *dp;
  DIR *dir;
  FILE *fpTxt, *fpKml, *fpShape, *fpDB;
  int track, nOrbits, nFrames, nPairs, nTracks, orbit=0;
  report_level_t report = REPORT_LEVEL_STATUS;
  struct base_pair *base_pairs=NULL;
  struct srf_orbit *srf_orbit=NULL;
  char cmd[255], tmp_dir[1024], track_list[1024];

  // Some more error checking on beam modes
  if (strcmp_case(sensor, "R1") == 0) {
    if (strcmp_case(beam_mode, "FN1") != 0 &&
	strcmp_case(beam_mode, "FN2") != 0 &&
	strcmp_case(beam_mode, "FN3") != 0 &&
	strcmp_case(beam_mode, "FN4") != 0 &&
	strcmp_case(beam_mode, "FN5") != 0 &&
	strcmp_case(beam_mode, "ST1") != 0 &&
	strcmp_case(beam_mode, "ST2") != 0 &&
	strcmp_case(beam_mode, "ST3") != 0 &&
	strcmp_case(beam_mode, "ST4") != 0 &&
	strcmp_case(beam_mode, "ST5") != 0 &&
	strcmp_case(beam_mode, "ST6") != 0 &&
	strcmp_case(beam_mode, "ST7") != 0)
      asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n",
		    beam_mode, sensor);
  }
  else if ((strcmp_case(sensor, "E1") == 0 || 
	    strcmp_case(sensor, "E2") == 0) &&
	   strcmp_case(beam_mode, "STD") != 0)
    asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n",
		  beam_mode, sensor);
  else if (strcmp_case(sensor, "J1") == 0 && 
	   strcmp_case(beam_mode, "STD") != 0)
    asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n",
		  beam_mode, sensor);
  else if (strcmp_case(sensor, "PALSAR") == 0 &&
	   strcmp_case(beam_mode, "PLR") != 0)
    asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n",
		  beam_mode, sensor);

  // Report what is going on
  asfReport(report, "Calculating baseline catalog for satellite '%s' in "
	    "beam mode '%s'\n\n", sensor, beam_mode);

  // Create temporary directory for list files
  sprintf(tmp_dir, "%s/%s", output_dir, time_stamp_dir());
  create_clean_dir(tmp_dir);

  // Setup the baseline calculation
  setup_files(sensor, beam_mode, input_dir, tmp_dir, &nTracks, &nFrames);
     
  // Step through the archive track by track - save plenty of memory
  for (track=0; track<nTracks; track++) {
    asfPrintStatus("\nTrack: %d (out of %d)\n", track+1, nTracks);
    nOrbits = 0;
    nPairs = 0;
    
    // Get a list of recent SRFs
    if (strcmp(sensor, "PSR") == 0)
      asfPrintStatus("Reading metadata file ...\n");
    else
      asfPrintStatus("Reading SRFs ...\n");
    sprintf(track_list, "%s/%s_track%d.lst", tmp_dir, sensor, track);
    if (fileExists(track_list)) {
      if (strcmp(sensor, "PSR") == 0)
	read_palsar(track_list, &srf_orbit, &nOrbits);
      else
	read_srf(input_dir, track_list, &srf_orbit, &nOrbits);
    }
    else
      continue;
    
    // Determine baselines
    if (nOrbits) {
      asfPrintStatus("Determining baselines ...\n");
      determine_baseline(sensor, sensor, beam_mode, track, orbit, 
			 srf_orbit, nOrbits, &base_pairs, &nPairs);
    }
    
    // Generate products
    if (nPairs) {
      asfPrintStatus("Generate products ...\n");
      generate_products(output_dir, base_pairs, nPairs);
    }
    
    // Clean up before last track
    if (srf_orbit)
      FREE(srf_orbit);
    if (base_pairs)
      FREE(base_pairs);
    srf_orbit = NULL;
    base_pairs = NULL;
    //exit(0);
  }

  // Pack text, KML and shape files for entire mode
  chdir(output_dir);
  fpTxt = FOPEN("txt.lst", "w");
  fpKml = FOPEN("kml.lst", "w");
  fpShape = FOPEN("shape.lst", "w");
  fpDB = FOPEN("db.lst", "w");
  dir = opendir(output_dir);
  while ((dp = readdir(dir)) != NULL) {
    if (strstr(dp->d_name, ".txt"))
      fprintf(fpTxt, "%s\n", dp->d_name);
    if (strstr(dp->d_name, ".kml"))
      fprintf(fpKml, "%s\n", dp->d_name);
    if (strstr(dp->d_name, ".tgz"))
      fprintf(fpShape, "%s\n", dp->d_name);
    if (strstr(dp->d_name, ".db") && !strstr(dp->d_name, ".dbf"))
      fprintf(fpDB, "%s\n", dp->d_name);
  }
  closedir(dir);
  FCLOSE(fpTxt);
  FCLOSE(fpKml);
  FCLOSE(fpShape);
  FCLOSE(fpDB);
  printf("\nZipping text files ...\n");
  sprintf(cmd, "tar czf %s_%s_txt.tgz -T txt.lst", sensor, beam_mode);
  asfSystem(cmd);
  printf("\nZipping KML files ...\n");
  sprintf(cmd, "tar czf %s_%s_kml.tgz -T kml.lst", sensor, beam_mode);
  asfSystem(cmd);
  printf("\nZipping shape files ...\n");
  sprintf(cmd, "tar czf %s_%s_shape.tgz -T shape.lst", sensor, beam_mode);
  asfSystem(cmd);
  printf("\nZipping database files ...\n");
  sprintf(cmd, "tar czf %s_%s_db.tgz -T db.lst", sensor, beam_mode);
  asfSystem(cmd);
  sprintf(cmd, "rm txt.lst kml.lst shape.lst db.lst");
  asfSystem(cmd);

  printf("\n\n");
}
Пример #5
0
int meta_test_ext(char *in_file, char *spec_file, report_level_t level)
{
  char *filename = NULL, line[1024], param[100], type[25], valid[500], *p;
  char *strValue;
  int nMin, nMax, nValue, err, passed = TRUE;
  double lfMin, lfMax, lfValue;
  
  // First try to find the spec file locally
  FILE *fp = fopen(spec_file, "r");
  if (!fp) {
    filename = appendExt(spec_file, ".specs");
    fp = fopen(filename, "r");
  }

  // Second try the spec file from share directory
  if (!fp) {
    FREE(filename);
    filename = (char *) MALLOC(sizeof(char)*1024);
    sprintf(filename, "%s/meta_test/%s", get_asf_share_dir(), spec_file);
    fp = fopen(filename, "r");
  }
  if (!fp) {
    sprintf(filename, "%s/meta_test/%s.specs", 
	    get_asf_share_dir(), spec_file);
    fp = fopen(filename, "r");
  }
  if (!fp)
    asfPrintError("Could not find spec file (%s)\n", spec_file);
  if (filename)
    FREE(filename);

  // FIXME: Need to implement some pre-checks.
  // For example, map projections will need special treatment. For a given
  // map projection, a set of parameters need are required to define that.
  // We need to be able to ignore some parameters in this context as well.
  // Only for the UAVSAR case, we are good to go.
  
  while(fgets(line, 1024, fp)) {
    // skip comments
    if (strstr(line, "#"))
      continue;
    else
      line[strlen(line)-1] = '\0';

    // parameter out of the metadata structure
    p = strchr(line, ',');
    *p = '\0';
    sprintf(param, "%s", line);
    strcat(param, ":");

    // data type
    sprintf(line, "%s", p+1);
    p = strchr(line, ',');
    if (p)
      *p = '\0';
    sprintf(type, "%s", line);

    // valid
    // If no value is given, we just want to check the parameter is given in
    // the metadata file. If we find quotation marks then assume we have a list
    // of values to check. Otherwise, we assume to find a minimum and a maximum
    // value to check.
    if (p) {
      sprintf(line, "%s", p+1);
      if (line[0] == '\'' && line[strlen(line)-1] == '\'') {
	sprintf(valid, "%s", line+1);
	valid[strlen(valid)-1] = '\0';
	strValue = getString(in_file, param, &err);
	if (err || (strlen(valid) > 0  && strstr(valid, strValue) == NULL)) {
	  asfReport(level, "   %s failed\n", param);
	  passed = FALSE;
	}
      }
      else {
	if (strncmp_case(type, "INT", 3) == 0) {
	  sscanf(line, "%d,%d", &nMin, &nMax);
	  nValue = getInt(in_file, param, &err);
	  if (err || nValue < nMin || nValue > nMax) {
	    asfReport(level, "   %s failed\n", param);
	    passed = FALSE;
	  }
	}
	else if (strncmp_case(type, "DOUBLE", 6) == 0) {
	  sscanf(line, "%lf,%lf", &lfMin, &lfMax);
	  lfValue = getDouble(in_file, param, &err);
	  if (err || lfValue < lfMin || lfValue > lfMax) {
	    asfReport(level, "   %s failed\n", param);
	    passed = FALSE;
	  }
	}
      }
    }
  }
  return passed;
}