Example #1
0
// Convert datapool to kml file
int datapool2kml(char *in_file, char *out_file, int listFlag, int stack)
{
  datapool_type_t datapool;
  dbf_header_t *dbf;
  char *header;
  int nCols, nColumns;
  char line[1024];

  // Read configuration file
  read_header_config("DATAPOOL", &dbf, &nCols);

  FILE *ifp = FOPEN(in_file, "r");
  assert(ifp);
  check_datapool_location(ifp, &header, &nColumns);

  FILE *ofp = FOPEN(out_file, "w");
  if (!ofp) {
    printf("Failed to open output file %s: %s\n", out_file, strerror(errno));
    return 0;
  }

  kml_header(ofp);

  int ii = 0;
  while (fgets(line, 1022, ifp) != NULL) {
    strip_end_whitesp(line);

    // now get the individual column values
    datapool_init(&datapool);
    if (read_datapool_line(header, nColumns, line, &datapool)) {
      if (stack) {
	if (ii == 0)
	  open_stack(ofp, &datapool);
	add_to_stack_kml(ofp, &datapool, nCols);
      }
      else
	add_to_kml(ofp, &datapool, dbf, nCols);
      ii++;
    }
  }

  if (stack)
    close_stack(ofp, &datapool);
  kml_footer(ofp);

  fclose(ifp);
  fclose(ofp);

  return 1;
}
Example #2
0
int datapool2shape(char *inFile, char *outFile, int listFlag, int stack)
{
  DBFHandle dbase;
  SHPHandle shape;
  datapool_type_t datapool;
  dbf_header_t *dbf;
  char *header, line[1024];
  int nCols, nColumns, ii=0;
  double *lat, *lon;

  // Read configuration file
  read_header_config("DATAPOOL", &dbf, &nCols);

  // Read datapool file
  FILE *ifp = FOPEN(inFile, "r");
  assert(ifp);
  check_datapool_location(ifp, &header, &nColumns);

  // Initalize the database file
  shape_datapool_init(outFile, header);
  open_shape(outFile, &dbase, &shape);

  while (fgets(line, 1022, ifp) != NULL) {
    strip_end_whitesp(line);

    // now get the individual column values
    datapool_init(&datapool);
    if (read_datapool_line(header, nColumns, line, &datapool)) {
      if (ii == 0)
	get_polygon_location(&datapool, &lat, &lon);
      else if (!stack)
	get_polygon_location(&datapool, &lat, &lon);
      add_to_shape(dbase, shape, &datapool, dbf, nCols, ii, lat, lon);
      ii++;
    }
  }

  // Clean up
  close_shape(dbase, shape);
  write_esri_proj_file(outFile);

  FCLOSE(ifp);

  return 1;
}
Example #3
0
void shape_datapool_init(char *inFile, char *header)
{
  char *dbaseFile;
  DBFHandle dbase;
  SHPHandle shape;
  dbf_header_t *dbf;
  int ii, nCols, length=32, length2=255;

  // Read configuration file
  read_header_config("DATAPOOL", &dbf, &nCols);

  // Open database for initialization
  dbaseFile = appendExt(inFile, ".dbf");
  dbase = DBFCreate(dbaseFile);
  if (!dbase)
    asfPrintError("Could not create database file '%s'\n", dbaseFile);

  // Add fields to database
  for (ii=0; ii<nCols; ii++) {
    if (strcmp(dbf[ii].header, "Granule_Name") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "GRAN_NAME", FTString, length, 0) == -1)
        asfPrintError("Could not add GRAN_NAME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Platform") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "PLATFORM", FTString, length, 0) == -1)
        asfPrintError("Could not add PLATFORM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Sensor") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "SENSOR", FTString, length, 0) == -1)
        asfPrintError("Could not add SENSOR field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Beam_Mode") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "BEAM_MODE", FTString, length2, 0) == -1)
        asfPrintError("Could not add BEAM_MODE field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Beam_Mode_Description") == 0 && 
	     dbf[ii].visible) {
      if (DBFAddField(dbase, "BEAM_MODE_D", FTString, length, 0) == -1)
        asfPrintError("Could not add BEAM_MODE_D field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Orbit") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "ORBIT", FTInteger, 7, 0) == -1)
        asfPrintError("Could not add ORBIT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Path_Number") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "PATH_NUM", FTInteger, 10, 0) == -1)
        asfPrintError("Could not add PATH_NUM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Frame_Number") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FRAME_NUM", FTInteger, 10, 0) == -1)
        asfPrintError("Could not add FRAME_NUM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Acquisition_Date") == 0 && 
	     dbf[ii].visible) {
      if (DBFAddField(dbase, "ACQ_DATE", FTString, length, 0) == -1)
        asfPrintError("Could not add ACQ_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Processing_Date") == 0 && 
	     dbf[ii].visible) {
      if (DBFAddField(dbase, "PROC_DATE", FTString, length, 0) == -1)
        asfPrintError("Could not add PROC_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Processing_Level") == 0 && 
	     dbf[ii].visible) {
      if (DBFAddField(dbase, "PROC_LEVEL", FTString, 10, 0) == -1)
        asfPrintError("Could not add PROC_LEVEL field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Start_Time") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "START_TIME", FTString, length, 0) == -1)
        asfPrintError("Could not add START_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "End_Time") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "END_TIME", FTString, length, 0) == -1)
        asfPrintError("Could not add END_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Center_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "CENTER_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add CENTER_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Center_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "CENTER_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add CENTER_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_Start_Lat") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "NSTART_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add NSTART_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_Start_Lon") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "NSTART_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add NSTART_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_Start_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FSTART_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add FSTART_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_Start_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FSTART_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add FSTART_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_End_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "N_END_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add N_END_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_End_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "N_END_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add N_END_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_End_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "F_END_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add F_END_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_End_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "F_END_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add F_END_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Faraday_Rotation") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "FARADAYROT", FTDouble, 16, 1) == -1)
        asfPrintError("Could not add FARADAYROT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Orbit_Direction") == 0 && 
	     dbf[ii].visible) {
      if (DBFAddField(dbase, "ORBIT_DIR", FTString, length, 0) == -1)
        asfPrintError("Could not add ORBIT_DIR field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Url") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "URL", FTString, length2, 0) == -1)
        asfPrintError("Could not add URL field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Size") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "SIZE_MB", FTDouble, 16, 2) == -1)
        asfPrintError("Could not add SIZE_MB field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Off_Nadir_Angle") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "OFF_NADIR", FTDouble, 16, 2) == -1)
        asfPrintError("Could not add OFF_NADIR field to database file\n");
    }
  }

  // Close the database for initialization
  DBFClose(dbase);

  // Open shapefile for initialization
  shape = SHPCreate(inFile, SHPT_POLYGON);
  if (!shape)
    asfPrintError("Could not create shapefile '%s'\n", inFile);

  // Close shapefile for initialization
  SHPClose(shape);

  FREE(dbaseFile);

  return;
}
Example #4
0
// Check location information
static int check_datapool_location(FILE *ifp, char **header_line, int *n)
{
  dbf_header_t *dbf;
  int ii, nCols;
  char *header = (char *) MALLOC(sizeof(char)*1024);
  fgets(header, 1024, ifp);
  strip_end_whitesp(header);
  int nColumns = get_number_columns(header);

  // Read configuration file
  read_header_config("DATAPOOL", &dbf, &nCols);

  // ensure we have the columns we need
  int granule_col = find_str(header, "Granule Name");
  int near_start_lat_col = find_str(header, "Near Start Lat");
  int near_start_lon_col = find_str(header, "Near Start Lon");
  int far_start_lat_col = find_str(header, "Far Start Lat");
  int far_start_lon_col = find_str(header, "Far Start Lon");
  int near_end_lat_col = find_str(header, "Near End Lat");
  int near_end_lon_col = find_str(header, "Near End Lon");
  int far_end_lat_col = find_str(header, "Far End Lat");
  int far_end_lon_col = find_str(header, "Far End Lon");

  // Check whether all visible columns are actually available in the file
  for (ii=0; ii<nCols; ii++) {
    if (find_str(header, dbf[ii].header) < 0)
      dbf[ii].visible = FALSE;
  }

  int all_ok=TRUE;
  if (granule_col < 0) {
    printf("Missing: Granule Name\n");
    all_ok=FALSE;
  }
  if (near_start_lat_col < 0) {
    printf("Missing: Near Start Lat\n");
    all_ok=FALSE;
  }
  if (near_start_lon_col < 0) {
    printf("Missing: Near Start Lon\n");
    all_ok=FALSE;
  }
  if (far_start_lat_col < 0) {
    printf("Missing: Far Start Lat\n");
    all_ok=FALSE;
  }
  if (far_start_lon_col < 0) {
    printf("Missing: Far Start Lon\n");
    all_ok=FALSE;
  }
  if (near_end_lat_col < 0) {
    printf("Missing: Near End Lat\n");
    all_ok=FALSE;
  }
  if (near_end_lon_col < 0) {
    printf("Missing: Near End Lon\n");
    all_ok=FALSE;
  }
  if (far_end_lat_col < 0) {
    printf("Missing: Far End Lat\n");
    all_ok=FALSE;
  }
  if (far_end_lon_col < 0) {
    printf("Missing: Far End Lon\n");
    all_ok=FALSE;
  }
  if (!all_ok) {
    printf("Required data columns missing, cannot process this file.\n");
    return 0;
  }
  *header_line = header;
  *n = nColumns;

  return 1;
}
Example #5
0
int main(int argc, char **argv)
{
  char inFormat[25], outFormat[25], configFile[255];
  int currArg = 1, NUM_ARGS = 1, configFlag = FALSE;
  c2v_config *cfg=NULL;

  if (argc < 3) {
    usage(argv[0]);
    exit(1);
  }
    
  // Check for configuration file option first
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-help", "--help", NULL)) {
      usage(argv[0]);
      char format[25], data_dictionary[512];
      CHECK_ARG(1);
      strcpy(format, GET_ARG(1));
      sprintf(data_dictionary, "%s%c%s_data_dictionary.csv", 
        get_asf_share_dir(), DIR_SEPARATOR, format);
      if (fileExists(data_dictionary)) {
        asfPrintStatus("\nFormat defined in %s_data_dictionary.csv\n\n", 
        format);
        catFile(data_dictionary);
        asfPrintStatus("\n\n");
      }
      else
        asfPrintWarning("Could not find a data dictionary for format (%s)!\n\n", 
          format);
      exit(1);
    }
    else if (strmatches(key, "-config", "--config", "-c", NULL)) {
      CHECK_ARG(1);
      strcpy(configFile, GET_ARG(1));
      cfg = read_c2v_config(configFile);
      configFlag = TRUE;
    }
  }
  if (!configFlag) {
    sprintf(configFile, "%s%cconvert2vector.config", 
      get_asf_share_dir(), DIR_SEPARATOR);
    asfPrintStatus("\nReading parameters from default configuration file:\n"
		   "%s\n", configFile);
    cfg = read_c2v_config(configFile);
  }

  // Pick up the rest of the arguments
  currArg = 1;
  NUM_ARGS = 2;
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-config", "--config", "-c", NULL)) { ; }
    else if (strmatches(key, "-log", "--log", NULL)) {
      CHECK_ARG(1);
      strcpy(logFile,GET_ARG(1));
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key, "-quiet", "--quiet", "-q", NULL))
      quietflag = TRUE;
    else if (strmatches(key, "-list", "--list", NULL))
      cfg->list = TRUE;
    else if (strmatches(key, "-nosplit", "--nosplit", "-ns", NULL))
      cfg->nosplit = TRUE;
    else if (strmatches(key, "-input-format", "--input-format", "-i", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->input_format, GET_ARG(1));
    }
    else if (strmatches(key, "-output-format", "--output-format", "-o", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->output_format, GET_ARG(1));
    }
    else {
      --currArg;
      break;
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  }

  if (!configFlag) {
    sprintf(cfg->input_file, "%s", argv[currArg++]);
    sprintf(cfg->output_file, "%s", argv[currArg]);
  }

  asfSplashScreen (argc, argv);

  sprintf(inFormat, "%s", uc(cfg->input_format));
  sprintf(outFormat, "%s", uc(cfg->output_format));
  
  // Check whether you can find information about the format in the header
  // list file in the share directory
  dbf_header_t *dbf;
  int nCols;
  char shape_type[25];
  if (strcmp_case(inFormat, "CSV") == 0 ||
    read_header_config(inFormat, &dbf, &nCols, shape_type))
    asfPrintStatus("   Converting a %s format file to %s\n", 
      inFormat, outFormat);
  else
    asfPrintError("   Unsupported input format (%s)\n", inFormat);
  
  // Set output directory as the temporary directory -- where all temp files
  // created during import should be put
  char *tmpdir = get_dirname(cfg->output_file);
  if (tmpdir && strlen(tmpdir) > 0)
    set_asf_tmp_dir(tmpdir);

  convert2vector(cfg);

  asfPrintStatus("Done.\n\n");

  return(0);
}
Example #6
0
void shape_ursa_init(char *inFile, char *header)
{
  char *dbaseFile;
  DBFHandle dbase;
  SHPHandle shape;
  dbf_header_t *dbf;
  int ii, nCols, length=50;

  // Read configuration file
  read_header_config("URSA", &dbf, &nCols);

  // Open database for initialization
  dbaseFile = appendExt(inFile, ".dbf");
  dbase = DBFCreate(dbaseFile);
  if (!dbase)
    asfPrintError("Could not create database file '%s'\n", dbaseFile);

  // Add fields to database
  for (ii=0; ii<nCols; ii++) {
    if (strcmp(dbf[ii].header, "Granule_Name") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "GRAN_NAME", FTString, length, 0) == -1)
        asfPrintError("Could not add GRAN_NAME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Granule_Type") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "GRAN_TYPE", FTString, length, 0) == -1)
        asfPrintError("Could not add GRAN_TYPE field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Platform") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "PLATFORM", FTString, length, 0) == -1)
        asfPrintError("Could not add PLATFORM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Sensor") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "SENSOR", FTString, length, 0) == -1)
        asfPrintError("Could not add SENSOR field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Orbit") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "ORBIT", FTInteger, 7, 0) == -1)
        asfPrintError("Could not add ORBIT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Beam_Mode") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "BEAM_MODE", FTString, length, 0) == -1)
        asfPrintError("Could not add BEAM_MODE field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Off_Nadir_Angle") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "OFF_NADIR", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add OFF_NADIR field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Start_Time") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "START_TIME", FTString, length, 0) == -1)
        asfPrintError("Could not add START_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "End_Time") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "END_TIME", FTString, length, 0) == -1)
        asfPrintError("Could not add END_TIME field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_Start_Lat") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "NSTART_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add NSTART_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_Start_Lon") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "NSTART_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add NSTART_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_Start_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FSTART_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add FSTART_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_Start_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FSTART_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add FSTART_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_End_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "N_END_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add N_END_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Near_End_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "N_END_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add N_END_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_End_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "F_END_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add F_END_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Far_End_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "F_END_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add F_END_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Center_Lat") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "CENTER_LAT", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add CENTER_LAT field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Center_Lon") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "CENTER_LON", FTDouble, 16, 4) == -1)
        asfPrintError("Could not add CENTER_LON field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Path_Number") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "PATH_NUM", FTInteger, 10, 0) == -1)
        asfPrintError("Could not add PATH_NUM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Frame_Number") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "FRAME_NUM", FTInteger, 10, 0) == -1)
        asfPrintError("Could not add FRAME_NUM field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Cloud_Cover") == 0 && dbf[ii].visible) {
      if (DBFAddField(dbase, "CLOUDCOVER", FTInteger, 5, 0) == -1)
        asfPrintError("Could not add CLOUDCOVER field to database file\n");
    }
    else if (strcmp(dbf[ii].header, "Faraday_Rotation") == 0 &&
         dbf[ii].visible) {
      if (DBFAddField(dbase, "FARADAYROT", FTDouble, 16, 1) == -1)
        asfPrintError("Could not add FARADAYROT field to database file\n");
    }
  }

  // Close the database for initialization
  DBFClose(dbase);

  // Open shapefile for initialization
  shape = SHPCreate(inFile, SHPT_POLYGON);
  if (!shape)
    asfPrintError("Could not create shapefile '%s'\n", inFile);

  // Close shapefile for initialization
  SHPClose(shape);

  FREE(dbaseFile);

  return;
}
Example #7
0
int main(int argc, char **argv)
{
  dbf_header_t *header;
  extern int currArg; // Pre-initialized to 1
  int n=0;
  char motion[512], deformation[512], connectivity[512], definition[512];
  char cell[512], shape_type[25], line[1024], **col;

  // Parse command line
  if ((argc-currArg)<1) {
    printf("Insufficient arguments.\n"); 
    usage();
  }
  strcpy(motion, argv[currArg]);
  strcpy(deformation, argv[currArg+1]);
  strcpy(connectivity, argv[currArg+2]);
  strcpy(definition, argv[currArg+3]);
  strcpy(cell, argv[currArg+4]);

  asfSplashScreen(argc, argv);

  // Reading cell connectivity file
  asfPrintStatus("Reading cell connectivity file ...\n");
  FILE *fp = FOPEN(connectivity, "r");
  int ii, kk, nCells = 0;
  fgets(line, 1024, fp);
  while (fgets(line, 1024, fp))
    nCells++;
  FCLOSE(fp);
  rgps_cell_t *cells = (rgps_cell_t *) MALLOC(sizeof(rgps_cell_t)*nCells);
  fp = FOPEN(connectivity, "r");
  fgets(line, 1024, fp);
  for (ii=0; ii<nCells; ii++) {
    fgets(line, 1024, fp);
    chomp(line);
    split_into_array(line, ',', &n, &col);
    cells[ii].cell_id = atoi(col[0]);
    cells[ii].grid_id = atoi(col[1]);
    cells[ii].order = atoi(col[2]);
    free_char_array(&col, n);
  }
  FCLOSE(fp);

  // Reading cell definition file
  asfPrintStatus("Reading cell definition file ...\n");
  fp = FOPEN(definition, "r");
  fgets(line, 1024, fp);
  while (fgets(line, 1024, fp)) {
    chomp(line);
    split_into_array(line, ',', &n, &col);
    for (ii=0; ii<nCells; ii++)
      if (cells[ii].cell_id == atoi(col[0])) {
        cells[ii].birth_year = atoi(col[3]);
        cells[ii].birth_time = atof(col[4]);
        cells[ii].death_year = atoi(col[5]);
        cells[ii].death_time = atof(col[6]);
      }
    free_char_array(&col, n);
  }
  FCLOSE(fp);
  
  // Reading ice motion file
  asfPrintStatus("Reading ice motion file ...\n");
  read_header_config("RGPS_LP_GRID", &header, &n, shape_type);
  fp = FOPEN(motion, "r");
  int nGrids = 0;
  fgets(line, 1024, fp);
  chomp(line);
  while (fgets(line, 1024, fp))
    nGrids++;
  FCLOSE(fp);
  rgps_grid_t *grid = (rgps_grid_t *) MALLOC(sizeof(rgps_grid_t)*nGrids);
  fp = FOPEN(motion, "r");
  fgets(line, 1024, fp);
  for (ii=0; ii<nGrids; ii++) {
    fgets(line, 1024, fp);
    chomp(line);
    split_into_array(line, ',', &n, &col);
    for (kk=0; kk<n; kk++) {
      if (strcmp_case(header[kk].shape, "IMAGE_ID") == 0)
        strcpy(grid[ii].image_id, col[kk]);
      else if (strcmp_case(header[kk].shape, "GPID") == 0)
        grid[ii].gpid = atoi(col[kk]);
      else if (strcmp_case(header[kk].shape, "OBS_YEAR") == 0)
        grid[ii].obs_year = atoi(col[kk]);
      else if (strcmp_case(header[kk].shape, "OBS_TIME") == 0)
        grid[ii].obs_time = atof(col[kk]);
      else if (strcmp_case(header[kk].shape, "BIRTH_YEAR") == 0)
        grid[ii].birth_year = atoi(col[kk]);
      else if (strcmp_case(header[kk].shape, "BIRTH_TIME") == 0)
        grid[ii].birth_time = atof(col[kk]);
      else if (strcmp_case(header[kk].shape, "DEATH_YEAR") == 0)
        grid[ii].death_year = atoi(col[kk]);
      else if (strcmp_case(header[kk].shape, "DEATH_TIME") == 0)
        grid[ii].death_time = atof(col[kk]);
      else if (strcmp_case(header[kk].shape, "X_MAP") == 0)
        grid[ii].x = atof(col[kk]);
      else if (strcmp_case(header[kk].shape, "Y_MAP") == 0)
        grid[ii].y = atof(col[kk]);
    }
    free_char_array(&col, n);
  }
  FCLOSE(fp);

  // Reading ice deformation file
  asfPrintStatus("Converting ice deformation file ...\n");
  read_header_config("RGPS_DP_GRID", &header, &n, shape_type);
  fp = FOPEN(deformation, "r");
  FILE *fpOut = FOPEN(cell, "w");
  fprintf(fpOut, "CELL_TIME,CELL_ID,STREAM,BIRTH_YEAR,BIRTH_TIME,DEATH_YEAR,"
    "DEATH_TIME,N_OBS,OBS_YEAR,OBS_TIME,X_MAP,Y_MAP,LAT,LON,X_DISP,Y_DISP,"
    "C_AREA,D_AREA,DTP,DUDX,DUDY,DVDX,DVDY,IMAGE_ID,DISP_MAG\n");
  fgets(line, 1024, fp); // header line
  while (fgets(line, 1024, fp)) {
    chomp(line);
    rgps_grid2cell(line, grid, nGrids, cells, nCells, header, fpOut);
  }
  FCLOSE(fp);
  FCLOSE(fpOut);
  FREE(grid);
  FREE(cells);
  
  return(0);
}