void airsar2meta(char* airsarname, meta_parameters *meta)
{
    char dtype[50];

    strcpy(meta->general->sensor, "AirSAR");

    /* number of lines in image	*/
    meta->general->line_count = 
      atoi(get_airsar(airsarname, "FIRST", "NUMBER OF LINES IN IMAGE"));
    printf(".");

    /* number of samples in image */
    meta->general->sample_count = 
      atoi(get_airsar(airsarname, "FIRST", "NUMBER OF SAMPLES PER RECORD"));
    printf(".");

    /* number of bands in image	*/
    meta->general->band_count = 1; 
    printf(".");

    meta->general->y_pixel_size = 
      atof(get_airsar(airsarname, "FIRST", "AZIMUTH PIXEL SPACING (METERS)"));
    printf(".");
    meta->general->x_pixel_size = 
      atof(get_airsar(airsarname, "FIRST", "RANGE PIXEL SPACING (METERS)"));
    printf(".");

    /* data type of pixels (unsigned char, short int, float)*/
    strcpy(dtype, get_airsar(airsarname, "FIRST", "DATA TYPE"));
    if(!strcmp(dtype, "BYTE")) meta->general->data_type = ASF_BYTE;
    else if(!strcmp(dtype, "INTEGER*2")) meta->general->data_type = INTEGER16;
    else if(!strcmp(dtype, "INTEGER*4")) meta->general->data_type = INTEGER32;
    else if(!strcmp(dtype, "REAL*4")) meta->general->data_type = REAL32;
    else if(!strcmp(dtype, "REAL*8")) meta->general->data_type = REAL64;
    printf(".");

    /* line relative to master image. */
    meta->general->start_line = 0; 
    printf(".");

    /* sample relative to master image */
    meta->general->start_sample = 0; 
    printf(".");

    /* line increment for sampling */
    meta->sar->line_increment = 1; 
    printf(".");

    /* sample increment for sampling */
    meta->sar->sample_increment = 1; 
    printf(".\n");

    return;
}
void airsar2ddr(char* airsarname, struct DDR *ddrOut)
{
    char dtype[50];
    int dt, i;

printf("Starting AirSAR Header -> DDR conversion!\n");
/* The necessary parts of a DDR file: setting up. *
 *------------------------------------------------*
 ********************void airsar2ddr(char* airsarname, struct DDR *ddrOut)
******************************/
    c_intddr(ddrOut);

    /* number of lines in image	*/
    ddrOut->nl = atoi(get_airsar(airsarname, "FIRST", "NUMBER OF LINES IN IMAGE"));
    printf(".");

    /* number of samples in image */
    ddrOut->ns = atoi(get_airsar(airsarname, "FIRST", "NUMBER OF SAMPLES PER RECORD"));
    printf(".");

    /* number of bands in image	*/
    ddrOut->nbands = 1; 
    printf(".");

    ddrOut->pdist_y = atof(get_airsar(airsarname, "FIRST", "AZIMUTH PIXEL SPACING (METERS)"));
    printf(".");
    ddrOut->pdist_x = atof(get_airsar(airsarname, "FIRST", "RANGE PIXEL SPACING (METERS)"));
    printf(".");

    strcpy(dtype, get_airsar(airsarname, "FIRST", "DATA TYPE"));

    if(!strcmp(dtype, "BYTE")) dt=EBYTE;
    else if(!strcmp(dtype, "INTEGER*2")) dt=EWORD;
    else if(!strcmp(dtype, "INTEGER*4")) dt=ELONG;
    else if(!strcmp(dtype, "REAL*4")) dt=EREAL;
    else if(!strcmp(dtype, "REAL*8")) dt=EDOUBLE;
    else asfPrintError("Unknown data type '%s'\n",dtype);

    /* data type of pixels (unsigned char, short int, float)*/
    ddrOut->dtype = dt;
    printf(".");

    /* computer system data is on */
    strcpy(ddrOut->system, "ieee-std"); 
    printf(".");

    /* line relative to master image. */
    ddrOut->master_line = 1; 
    printf(".");

    /* sample relative to master image */
    ddrOut->master_sample = 1; 
    printf(".");

    for(i=0; i<8; i++) {
      ddrOut->valid[i] = INVAL; /* valid flags: 0, 1, 2		*/
    printf(".");
    }

    ddrOut->valid[4] = VALID;           /* Projection Units    */
    ddrOut->valid[5] = VALID;           /* Projection Distance */
    ddrOut->valid[7] = VALID;           /* Increment           */

    /* Projection units (GCTP units+other) */
    strcpy(ddrOut->proj_units, "METERS"); 
    printf(".");

    /*  Not currently implemented
    ddrOut->upleft[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 2")); 
    ddrOut->upleft[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 2")); 
    ddrOut->loleft[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 4")); 
    ddrOut->loleft[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 4")); 
    ddrOut->upright[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 1"));
    ddrOut->upright[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 1")); 
    ddrOut->loright[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 3")); 
    ddrOut->loright[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 3")); 

    ddrOut->pdist_y = atof(get_airsar(airsarname, "DEM", "Y-DIRECTION POST SPACING"));
    ddrOut->pdist_x = atof(get_airsar(airsarname,"DEM", "X-DIRECTION POST SPACING")); 
    */

    /* line increment for sampling */
    ddrOut->line_inc = 1.0; 
    printf(".");

    /* sample increment for sampling */
    ddrOut->sample_inc = 1.0; 
    printf(".\n");

    printf("Finished DDR conversion!\n");

    return;
}
Exemple #3
0
int isAIRSAR(char *dataFile)
{
  airsar_header *header = NULL;
  FILE *fp;
  int L_airsar = 0;
  int C_airsar = 0;
  int P_airsar = 0;
  char buf[4400], *value, *band_data, *s;
  double version;
  if (is_dir(dataFile))
    return FALSE;
  char *inFile = STRDUP(dataFile);

  // Allocate memory and file handling
  value = (char *) MALLOC(sizeof(char)*25);
  header = (airsar_header *) CALLOC(1, sizeof(airsar_header));
  band_data = (char *) MALLOC(sizeof(char)*(strlen(inFile)+32));
  strcpy(band_data, inFile);

  // Try L-band
  s = strrchr(band_data, '_');
  if (s) {
    *s = '\0';
    strcat(s, "_l.dat");
  }
  //if (fileExists(band_data)) {
    strcpy(buf, "");
    fp = fopen(band_data, "r");
    if (fp != NULL && fgets(buf, 4400, fp) == NULL)
      asfPrintError("Could not read general header\n");
    FCLOSE(fp);
    version = atof(get_airsar(buf, "JPL AIRCRAFT SAR PROCESSOR VERSION"));
    L_airsar = (version > 0.0) ? 1 : 0;
    /*}
  else
  L_airsar = FALSE;*/

  // Try C-band
  s = strrchr(band_data, '_');
  if (s) {
    *s = '\0';
    strcat(s, "_c.dat");
  }
  //if (fileExists(band_data)) {
    strcpy(buf, "");
    fp = fopen(band_data, "r");
    if (fp != NULL && fgets(buf, 4400, fp) == NULL)
      asfPrintError("Could not read general header\n");
    FCLOSE(fp);
    version = atof(get_airsar(buf, "JPL AIRCRAFT SAR PROCESSOR VERSION"));
    C_airsar = (version > 0.0) ? 1 : 0;
    /*}
  else
  C_airsar = FALSE;*/

    // Try P-band
  s = strrchr(band_data, '_');
  if (s) {
    *s = '\0';
    strcat(s, "_p.dat");
  }
  //if (fileExists(band_data)) {
    strcpy(buf, "");
    fp = fopen(band_data, "r");
    if (fp != NULL && fgets(buf, 4400, fp) == NULL)
      asfPrintError("Could not read general header\n");
    FCLOSE(fp);
    version = atof(get_airsar(buf, "JPL AIRCRAFT SAR PROCESSOR VERSION"));
    P_airsar = (version > 0.0) ? 1 : 0;
    /*}
  else
  P_airsar = FALSE;*/

  FREE(value);
  FREE(header);
  FREE(band_data);
  FREE(inFile);

  return (L_airsar || C_airsar || P_airsar);
}
Exemple #4
0
int main(int argc, char *argv[])
{
  char basename[256];
  char *airsarname;
  char *outname;
  char *ext;
  char *off_char;

  int *ibuff;			/* Input and output buffers		*/
  float *obuff;
  unsigned char *obuff_char;

  FILE *fpOut;			
  FILE *fpIn;

  int nl, ns;			/* Number of lines, number of samples	*/
  int y, x;			/* Counters				*/
  int hb, lb;			/* Header Bytes, Line Bytes		*/
  int demi2=0;			/* Is this a DEM?			*/

  float incr=1;
  float offset=0;

  meta_parameters *meta;

  if(argc != 3){
    printf("Usage:	%s inSARfile outLASfile\n",argv[0]);
    printf("\tinput: inSARfile, an AirSAR image\n");
    printf("\toutput: outLASfile, a LAS image (.img and .ddr)\n");

    printf("\nAirsarin reads an AirSAR image, and\n");
    printf("converts it to the format used by our \n");
    printf("other tools.\n");
    printf("This is often the first step in analysing a SAR image.\n");
    printf("\nVersion %.2f, ASF STEP Tools\n",VERSION);
    exit(1);
  }

  airsarname=argv[1];
  outname=argv[2];

/* Strip the extension off for the basename */
  strcpy(basename, airsarname);
  ext = strchr(basename, '.');

  if(!strcmp(".demi2",ext)) demi2=1;
  *ext = '\0';
  if(demi2==1) printf("It's a DEM!\n");
  else printf("Hrmmm....\n");

/* Create the output ddr */
  meta = raw_init();
  airsar2meta(airsarname, meta);
  if (demi2)
    meta->general->image_data_type = DEM;
  else
    meta->general->image_data_type = AMPLITUDE_IMAGE;
  meta_write(meta, outname);
  fpOut = fopenImage(outname, "wb");
  ns = meta->general->sample_count;
  nl = meta->general->line_count;

/* Allocate buffer space */
  ibuff = (int *) malloc(ns * sizeof(int));
  obuff = (float *)malloc(ns * sizeof(float));
  obuff_char =(unsigned char*)malloc(ns * sizeof(unsigned char));

/* Determine the headerBytes and the length of each line */
  hb = atoi(get_airsar(airsarname,"FIRST","BYTE OFFSET OF FIRST DATA RECORD"));
  lb = atoi(get_airsar(airsarname,"FIRST","RECORD LENGTH IN BYTES"));

  if(demi2){
    off_char = (char *)malloc(sizeof(char));
    strcpy(off_char, get_airsar(airsarname,"DEM","ELEVATION OFFSET"));
    offset = atof(off_char); 
    incr = atof( get_airsar(airsarname,"DEM","ELEVATION INCREMENT"));
    printf("offset should be = \t%s\n", off_char);
    printf("offset = \t\t%f\n", offset);
    printf("increment = \t\t%f\n", incr);
  }

  printf("\nBeginning IMG conversion...\n");

  fpIn = FOPEN(airsarname, "r");

/* Read input file, convert, and write to output file */
  for (y = 0; y< nl; y++)
  {
    readAirSARLine(fpIn, ibuff, hb, lb, y, meta);
    
    if( meta->general->data_type == BYTE) {
      for (x = 0; x< ns; x++)
	obuff_char[x]=(unsigned char)ibuff[x];
      FWRITE(obuff_char, ns, 1, fpOut);
    }
    else {
      for (x = 0; x < ns; x++){
	obuff[x]=(float)ibuff[x];
	
	if(obuff[x]!=49152)obuff[x]=obuff[x]*incr+offset;
	else obuff[x]=0;
      }
      put_float_line(fpOut, meta, y, obuff);
    }
    if ((y % 500) == 0)
      printf("Now Processing Line No = %d \n", y);
  }

  FCLOSE(fpOut);
  FCLOSE(fpIn);

  return 0;
}