예제 #1
0
파일: fileUtil.c 프로젝트: glshort/MapReady
// Strip of known extension and return file name with band extension added
void append_band_ext(char *inFile, char *outFile, char *bandExt)
{
  char *ext, *base_name;

  ext = findExt(inFile);

  if (ext &&
      (strcmp_case(ext, ".IMG") == 0 ||
       strcmp_case(ext, ".TIF") == 0 ||
       strcmp_case(ext, ".TIFF") == 0 ||
       strcmp_case(ext, ".JPG") == 0 ||
       strcmp_case(ext, ".JPEG") == 0 ||
       strcmp_case(ext, ".PNG") == 0 ||
       strcmp_case(ext, ".PGM") == 0 ||
       strcmp_case(ext, ".BIN") == 0 ||
       strcmp_case(ext, ".NC") == 0 ||
       strcmp_case(ext, ".H5") == 0))
    base_name = stripExt(inFile);
  else {
    base_name = (char *) MALLOC(sizeof(char)*255);
    strcpy(base_name, inFile);
  }
  if (bandExt)
    sprintf(outFile, "%s_%s", base_name, bandExt);
  else
    sprintf(outFile, "%s", base_name);
  if (ext)
    strcat(outFile, ext);
  free(base_name);
}
예제 #2
0
int handle_terrasar_file(const char *filename, char *meta_name, char *data_name,
			 char **err)
{
  // allocate error buffer, just in case we need it
  *err = (char *) MALLOC(sizeof(char)*1024);
  
  // check for metadata
  if (!fileExists(filename))
    meta_name = appendExt(filename, ".xml");
  else
    strcpy(meta_name, filename);
  if (!fileExists(meta_name)) {
    sprintf(*err, "Error opening TerraSAR-X file, metadata file (%s) does "
	    "not exist!\n", meta_name);
    return FALSE;
  }
  xmlDoc *doc = xmlReadFile(meta_name, NULL, 0);
  if (!doc) {
    sprintf(*err, "Could not parse file %s\n", meta_name);
    return FALSE;
  }
  
  // path from the xml (metadata) file
  char *path = get_dirname(filename);
  if (strlen(path)>0) {
    strcpy(data_name, path);
    if (data_name[strlen(data_name)-1] != '/')
      strcat(data_name, "/");
  }
  else
    strcpy(data_name, "");
  free(path);
  
  // strcat() on the path & file from the XML entry
  strcat(data_name, xml_get_string_value(doc, 
    "level1Product.productComponents.imageData[0].file.location.path"));
  strcat(data_name, "/");
  strcat(data_name, xml_get_string_value(doc, 
    "level1Product.productComponents.imageData[0].file.location.filename"));
  if (!fileExists(data_name)) {
    sprintf(*err, "Data file (%s) does not exist!\n", data_name);
    return FALSE;
  }

  // check data type
  terrasar_meta *terrasar = read_terrasar_meta(meta_name);
  if (!strcmp_case(terrasar->imageDataType, "COMPLEX") == 0 &&
      !strcmp_case(terrasar->imageDataFormat, "COSAR") == 0) {
    sprintf(*err, "Data type (%s) and data format (%s) currently not "
	    "supported!\n", 
	    terrasar->imageDataType, terrasar->imageDataFormat);
    return FALSE;
  }

  FREE(*err);
  err = NULL;
  return TRUE;
}
예제 #3
0
int meta_uses_incid_polynomial(meta_parameters *meta)
{
  return strcmp_case(meta->general->sensor, "ALOS") == 0 &&
      strcmp_case(meta->general->sensor_name, "SAR") == 0 &&
      meta_is_valid_double(meta->sar->incid_a[0]) &&
      meta->sar->incid_a[0] != 0 &&
      meta->sar->incid_a[1] != 0 &&
      meta->sar->incid_a[2] != 0 &&
      meta->sar->incid_a[3] != 0 &&
      meta->sar->incid_a[4] != 0 &&
      meta->sar->incid_a[5] != 0;
}
예제 #4
0
int handle_asf_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_asf_ext = has_ext &&
        (strcmp_case(ext,".img")==0 || strcmp_case(ext,".meta")==0);

    // either they gave us an ASF Internal extension, or we try adding it
    // to a user-provided basename, and that file does exist
    if (has_asf_ext || try_ext(filename, ".img"))
    {
        char *m = appendExt(filename, ".meta");
        char *d = appendExt(filename, ".img");

        strcpy(meta_name, m);
        strcpy(data_name, d);

        int ret;
        if (!fileExists(meta_name) || !fileExists(data_name)) {
            int l = sizeof(char)*strlen(filename)*2+255;
            *err = MALLOC(l);
            snprintf(*err, l,
                "Error opening ASF Internal Format file.\n"
                "  Metadata file: %s - %s\n"
                "      Data file: %s - %s\n",
                m, fileExists(m) ? "Found" : "NOT FOUND",
                d, fileExists(d) ? "Found" : "NOT FOUND");

            ret = FALSE;
        }
        else
            ret = TRUE;

        free(m);
        free(d);

        return ret;
    }
    else {
        // in theory this shouldn't happen, if try_ext is working
        assert(!try_ext(filename, ".img"));
        int l = sizeof(char)*strlen(filename)*2+255;
        *err = MALLOC(l);
        snprintf(*err, l,
            "Failed to open %s as an ASF Internal Format File.\n", filename);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
예제 #5
0
int try_asf(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
        return strcmp_case(ext, ".img") == 0 ||
               strcmp_case(ext, ".meta") == 0;
    } else if (try_extensions) {
        return try_ext(filename, ".img");
    } else {
        return FALSE;
    }
}
예제 #6
0
/**********************************************************
 * meta_incid:  Returns the incidence angle
 * This is the angle measured by the target between straight
 * up and the satellite. Returns radians.*/
double meta_incid(meta_parameters *meta,double y,double x)
{
  // No effort has been made to make this routine work with
  // pseudoprojected images.
  if (strcmp_case(meta->general->sensor, "UAVSAR") == 0)
    // placeholder for incidence angle information, most likely coming from
    // a band in the image file
    return 0.0;
  else
    assert (meta->projection == NULL || 
	    meta->projection->type != LAT_LONG_PSEUDO_PROJECTION);

  double sr = meta_get_slant(meta,y,x);

  if (meta_uses_incid_polynomial(meta)) {
    // Use the incidence angle polynomial if it is available and non-zero.
    double R = sr/1000.;
    double R2=R*R;
    return
      meta->sar->incid_a[0] +
      meta->sar->incid_a[1] * R +
      meta->sar->incid_a[2] * R2 +
      meta->sar->incid_a[3] * R2 * R +
      meta->sar->incid_a[4] * R2 * R2 +
      meta->sar->incid_a[5] * R2 * R2 * R;

  } else {
    double er = meta_get_earth_radius(meta,y,x);
    double ht = meta_get_sat_height(meta,y,x);
    return PI-acos((SQR(sr) + SQR(er) - SQR(ht)) / (2.0*sr*er));
  }
}
예제 #7
0
int isUAVSAR(char *dataFile, char **error)
{
  int found = FALSE;
  char *inFile = STRDUP(dataFile);
  // Let's first check for an .ann extension
  char *ext = findExt(inFile);

  // If it has the correct extension, investigate it further
  if (ext && strcmp_case(ext, ".ann") == 0) {

    // We have the most generic annotation file ever, with no indication what
    // kind of data we are supposed to have. It just list everything that was
    // originally produced.
    // The only identifier for even UAVSAR, I could find, was the URL.
    char line[512];
    FILE *fp = fopen(inFile, "r");;
    if (fp) {
      while (fgets(line, 512, fp)) {
        if (strstr(line, "uavsar.jpl.nasa.gov"))
   	  found = TRUE;
      }
      fclose(fp);
    }
  }
  FREE(inFile);

  return found;
}
예제 #8
0
int try_uavsar(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
        if (strcmp_case(ext, ".grd") == 0 ||
            strcmp_case(ext, ".hgt") == 0 ||
            strcmp_case(ext, ".mlc") == 0)
        {
           char *ann_file = find_uavsar_annotation_file(filename);
           int ret = ann_file != NULL;
           FREE(ann_file);
           return ret;
        }
    }   
    return FALSE;
}
예제 #9
0
static char *get_arclist_from_settings(char *sensor)
{
    if (strcmp_case(sensor, "ERS-1") == 0 ||
            strcmp_case(sensor, "ERS-2") == 0)
    {
        char *settings_file = find_in_share("mapready_settings.cfg");
        if (!settings_file) {
            asfPrintWarning("Could not find mapready_settings.cfg");
            return NULL;
        }
        char match_str[256];
        char *arclist = NULL;
        sprintf(match_str, "precise orbits %s", sensor);
        FILE *fSettings = FOPEN(settings_file, "r");
        if (fSettings) {
            char line[1024];
            while (fgets(line, 1024, fSettings) != NULL) {
                if (strncmp(line, match_str, strlen(match_str)) == 0) {
                    arclist = read_str(line, match_str);
                    if (strcmp_case(arclist, "<location of arclist file>") == 0)
                        strcpy(arclist, "");
                    break;
                }
            }
            FCLOSE(fSettings);
            if (!arclist || strlen(arclist) == 0) {
                // not an error, user probably does not have precision state vectors
                asfPrintStatus("No precise orbits found in mapready_settings.cfg for %s\n",
                               sensor);
            }
            FREE(settings_file);
            return arclist;
        }
        else {
            asfPrintError("Could not open mapready_settings.cfg");
            return NULL;
        }
    }
    else {
        asfPrintError("Internal error, bad sensor: %s\n", sensor);
        return NULL;
    }
    // not reached
    return NULL;
}
예제 #10
0
int open_uavsar_data(const char *filename, int multilook,
                     meta_parameters *meta, ClientInterface *client)
{
    ReadUavsarClientInfo *info = MALLOC(sizeof(ReadUavsarClientInfo));
    info->ml = multilook;

    char *ext = findExt(filename);
    if (strcmp_case(ext, ".grd") == 0 ||
        strcmp_case(ext, ".mlc") == 0)
    {
        // UAVSAR .grd/.mlc files are real for HHHH, HVHV, and VVVV
        info->is_complex = strstr(filename, "HHHV_") != NULL ||
                           strstr(filename, "HHVV_") != NULL ||
                           strstr(filename, "HVVV_") != NULL;
    }
    else if (strcmp_case(ext, ".hgt") == 0) {
        // UAVSAR .hgt files are real
        info->is_complex = FALSE;
    }

    asfPrintStatus("Reading UAVSAR data as %s\n",
                   info->is_complex ? "complex" : "real");

    if (info->is_complex)
        meta->general->data_type = COMPLEX_REAL32;

    info->fp = fopen(filename, "rb");
    if (!info->fp) {
        asfPrintWarning("Failed to open UAVSAR data file %s: %s\n",
            filename, strerror(errno));
        return FALSE;
    }

    client->read_client_info = info;
    client->read_fn = read_uavsar_client;
    client->thumb_fn = get_uavsar_thumbnail_data;
    client->free_fn = free_uavsar_client_info;

    if (meta->general->data_type == ASF_BYTE)
        client->data_type = GREYSCALE_BYTE;
    else
        client->data_type = GREYSCALE_FLOAT;

    return TRUE;
}
예제 #11
0
meta_parameters *read_uavsar_meta(const char *meta_name, const char *data_name)
{
  char *ext = findExt(data_name);
  assert(ext);

  uavsar_polsar *polsar_params = NULL;
  if (strcmp_case(ext, ".mlc") == 0)
    polsar_params = read_uavsar_polsar_params(meta_name, POLSAR_MLC);
  else if (strcmp_case(ext, ".grd") == 0)
    polsar_params = read_uavsar_polsar_params(meta_name, POLSAR_GRD);
  else if (strcmp_case(ext, ".hgt") == 0)
    polsar_params = read_uavsar_polsar_params(meta_name, POLSAR_HGT);
  else
    asfPrintError("Unexpected UAVSAR extension: %s\n", ext);

  assert(polsar_params);
  return uavsar_polsar2meta(polsar_params);
}
예제 #12
0
void init_library_function(t_library *lib, char *name)
{
  lib->get_cal_dn = NULL;
  if (strcmp_case(name, "get_cal_dn") == 0) {
    lib->get_cal_dn = (t_get_cal_dn *) MALLOC(sizeof(t_get_cal_dn));
    lib->get_cal_dn->meta_file = (char *) MALLOC(sizeof(char)*255);
    lib->get_cal_dn->bandExt = (char *) MALLOC(sizeof(char)*25);
  }
}
예제 #13
0
// if a file is a .img file, test it for overlap, otherwise do nothing
static void process_file(const char *file, int level,
                         char *overlapping_dems[], int *next_dem_number,
                         meta_parameters *meta, int *n_dems_total)
{
    char *base = get_filename(file);
    char *ext = findExt(base);
    if (ext && strcmp_case(ext, ".img") == 0)
    {
        char *does;
        ++(*n_dems_total);

        char *meta_filename = appendExt(file, ".meta");
        meta_parameters *meta_dem = meta_read(meta_filename);

        if (meta_dem->general->image_data_type != DEM) {
            does = "Not a DEM";
        } else if (test_overlap(meta, meta_dem)) {
            // overlaps!
            overlapping_dems[*next_dem_number] = STRDUP(file);
            ++(*next_dem_number);
            does = "Overlaps";
        } else {
            does = "No";
        }

        free(meta_filename);
        meta_free(meta_dem);

        asfPrintStatus("  %s%s - %s\n", spaces(level), base, does);
    }
    else if (ext && (strcmp_case(ext, ".meta") == 0 ||
                     strcmp_case(ext, ".ddr") == 0)) {
        // silently ignore the .meta, etc files -- they will be picked up
        // when processing the corresponding .img file
        ;
    }
    else {
        // loudly ignore other stuff in the directory
        asfPrintStatus("  %s%s (ignored)\n", spaces(level), base);
    }
    FREE(base);
}
예제 #14
0
int try_png(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
      return strcmp_case(ext, ".png") == 0;
    } else if (try_extensions) {
      return try_ext(filename, ".png");
    }
    return FALSE;
}
예제 #15
0
static void add_overlay_file(char *overlay_file)
{
  char *ext = findExt(overlay_file);

  if (ext) {
    if (strcmp_case(ext, ".SHP") == 0) {
      add_shapefile(curr->meta, overlay_file);
      fill_big(curr);
      return;
    }
    else if (strcmp_case(ext, ".CSV") == 0) {
      add_generic_csv(curr->meta, overlay_file, FALSE);
      fill_big(curr);
      return;
    }
  }

  // if we got here, must have failed to find a handler
  message_box("Do not know how to handle the overlay file: %s", overlay_file);
}
예제 #16
0
파일: asf_test.c 프로젝트: glshort/MapReady
static void manual_geotiff(char *configFile)
{
  char inFile[1024];
  char specsFile[1024];
  int ii, suite_passed = TRUE;
  test_config *cfg = read_test_config(configFile);

  if (strcmp_case(cfg->general->status, "new") != 0)
    asfPrintError("Can't run manual tests. Current status: '%s'\nTo run these "
		  "tests manually, reset the general status to 'new'\n", 
		  cfg->general->status);
  asfPrintStatus("   Suite: %s\n", cfg->general->suite);
  for (ii=0; ii<cfg->general->test_count; ii++) {
    strcpy(inFile, cfg->test[ii]->file);
    strcpy(specsFile, cfg->test[ii]->specs);
    asfPrintStatus("\n   Test[%d]: %s ...\n", ii+1, cfg->test[ii]->test);
    if (strcmp_case(cfg->test[ii]->status, "skip") != 0) {
      if (geotiff_test_ext(inFile, specsFile, REPORT_LEVEL_STATUS)) {
	asfPrintStatus("   Test passed\n");
	strcpy(cfg->test[ii]->status, "passed");
      }
      else {
	asfPrintStatus("   Test failed\n");
	strcpy(cfg->test[ii]->status, "failed");
	suite_passed = FALSE;
      }
    }
    else
      asfPrintStatus("   Test skipped\n");
  }
  if (suite_passed) {
    asfPrintStatus("\n   Suite passed\n\n");
    strcpy(cfg->general->status, "passed");
  }
  else {
    asfPrintStatus("\n   Suite failed\n\n");
    strcpy(cfg->general->status, "failed");
  }
  write_test_config(configFile, cfg);
  free_test_config(cfg);  
}
예제 #17
0
static int is_PolSARpro(const char *infile)
{
  int found_bin = FALSE;
  int found_bin_hdr = FALSE;
  char *bin = NULL, *bin_hdr = NULL, *dupe = NULL, *ext = NULL;

  ext = findExt(infile);
  if (!ext) {
    // If no file extension exists, then maybe it has been stripped
    // off.  Guess .bin and check for existence...
    char *inFile = (char *)MALLOC(sizeof(char) * strlen(infile) + 5);
    sprintf(inFile, "%s.bin", infile);
    int ret = is_PolSARpro(inFile);
    FREE(inFile);
    return ret;
  }
  if (strcmp_case(ext, ".bin")==0) {
    bin = (char *)infile;
    bin_hdr = (char *)MALLOC(sizeof(char) * (strlen(infile) + 5));
    sprintf(bin_hdr, "%s.hdr", infile);
    found_bin = fileExists(bin);
    found_bin_hdr = fileExists(bin_hdr);
    FREE(bin_hdr);
  }
  else if (strcmp_case(ext, ".hdr")==0) {
    dupe = STRDUP(infile);
    bin_hdr = (char *)infile;
    ext = findExt(dupe);
    *ext = '\0';
    ext = findExt(dupe);
    if (ext && (strcmp_case(ext, ".bin")==0)) {
      bin = dupe;
    }
    found_bin = fileExists(bin);
    found_bin_hdr = fileExists(bin_hdr);
    FREE(dupe);
  }
  int ret = found_bin + found_bin_hdr;

  return ret;
}
예제 #18
0
파일: read_brs.c 프로젝트: glshort/MapReady
int handle_brs_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_brs_ext = has_ext && strcmp_case(ext,".brs")==0;
    char *file;

    if (!has_ext) {
        has_brs_ext = try_ext(filename, ".brs");
        if (!has_brs_ext) {
            has_brs_ext = try_ext(filename, ".BRS");
            if (has_brs_ext)
                file = appendExt(filename, ".BRS");
        }
        else {
            file = appendExt(filename, ".brs");
        }
    }
    else
        file = STRDUP(filename);

    if (has_brs_ext)
    {
        strcpy(meta_name, file);
        strcpy(data_name, file);

        int ret;
        if (!fileExists(data_name)) {
            // I don't think this will actually ever run
            int l = sizeof(char)*strlen(filename)+255;
            *err = MALLOC(l);
            snprintf(*err, l, "Error opening BRS file: %s\n", data_name);
            ret = FALSE;
        }
        else
            ret = TRUE;

        free(file);
        return ret;
    }
    else {
        int l = sizeof(char)*strlen(filename)+255;
        *err = MALLOC(l);
        snprintf(*err, l, "Failed to open %s as a BRS File.\n", filename);
        free(file);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
예제 #19
0
static int get_band_num(char *bands, int band_count, const char *channel)
{
  char *t_channel, *ptr;
  int ii;

  char *t_bands = STRDUP(bands);
  t_channel = STRTOK_R(t_bands, ",", &ptr);
  if (t_channel != NULL && strcmp_case(t_channel, channel) == 0) {
    FREE(t_bands);
    return 0;
  }
  for (ii=1; ii<band_count; ii++) {
    t_channel = STRTOK_R(NULL, ",", &ptr);
    if (t_channel != NULL && strcmp_case(t_channel, channel) == 0) {
      FREE(t_bands);
      return ii;
    }
  }
  FREE(t_bands);
  return -1;
}
예제 #20
0
파일: asf_test.c 프로젝트: glshort/MapReady
void cu_difftext(char *testFile, char *referenceFile, char *exceptFile)
{
  char line[1024], tLine[1024], rLine[1024];
  int ii, nExcept = 0;

  // Read exceptions
  FILE *fp = FOPEN(exceptFile, "r");
  while(fgets(line, 1024, fp)) {
    chomp(line);
    nExcept++;
  }
  FCLOSE(fp);
  char **exception = (char **) MALLOC(sizeof(char *)*nExcept);
  fp = FOPEN(exceptFile, "r");
  for (ii=0; ii<nExcept; ii++) {
    exception[ii] = (char *) MALLOC(sizeof(char)*1024);
    fgets(exception[ii], 1024, fp);
  }
  FCLOSE(fp);

  // Go through both text files simultaneously
  FILE *fpTest = FOPEN(testFile, "r");
  FILE *fpRef = FOPEN(referenceFile, "r");
  while (fgets(tLine, 1024, fpTest)) {
    fgets(rLine, 1024, fpRef);
    for (ii=0; ii<nExcept; ii++) {
      if (strcmp_case(rLine, exception[ii]) != 0) {
	if (strcmp_case(tLine, rLine) != 0) {
	  asfForcePrintStatus("\ntest: %sreference: %s", tLine, rLine);
	  CU_ASSERT_TRUE(strcmp_case(tLine, rLine) == 0);
	}
      }
    }
  }

  // Clean up
  for (ii=0; ii<nExcept; ii++)
    FREE(exception[ii]);
  FREE(exception);
}
예제 #21
0
int isGeocoded(const char *dataFile)
{
  char enviName[1024];
  envi_header *envi;
  int ret = FALSE;
  sprintf(enviName, "%s.hdr", dataFile);
  envi = read_envi(enviName);
  if (strcmp_case(envi->projection, "not map projected") != 0)
    ret = TRUE;
  FREE(envi);
  
  return ret;
}
예제 #22
0
int handle_png_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_png_ext = has_ext && strcmp_case(ext,".png")==0;

    if (!has_ext) {
        has_png_ext = try_ext(filename, ".png");
    }

    if (has_png_ext)
    {
        char *d=NULL;
        if (has_ext)
            d = STRDUP(filename);
        else if (has_png_ext)
            d = appendExt(filename, ".png");
        assert(d);

        strcpy(meta_name, d);
        strcpy(data_name, d);
        free(d);

        int ret;
        if (!fileExists(data_name)) {
            // I don't think this will actually ever run
            int l = sizeof(char)*strlen(filename)+255;
            *err = MALLOC(l);
            snprintf(*err, l, "Error opening PNG file: %s\n", data_name);
            ret = FALSE;
        }
        else
            ret = TRUE;

        return ret;
    }
    else {
        // in theory this shouldn't happen, if try_ext is working
        assert(!try_ext(filename, ".png"));
        int l = sizeof(char)*strlen(filename)+255;
        *err = MALLOC(l);
        snprintf(*err, l, "Failed to open %s as a PNG File.\n", filename);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
예제 #23
0
파일: read_brs.c 프로젝트: glshort/MapReady
int try_brs(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
        return strcmp_case(ext, ".brs") == 0;
    } else if (try_extensions) {
        int ret = try_ext(filename, ".brs");
        if (!ret)
            ret = try_ext(filename, ".BRS");
        return ret;
    }
    return FALSE;
}
예제 #24
0
static void ncai_identify_module_is_VM(ncaiModule module)
{
    const char* vm_modules[] = {"java", "vmcore", "harmonyvm", "em", "interpreter",
        "gc_gen", "gc_gen_uncomp", "gc_cc", "vmi", "encoder", "jitrino", "hythr"};

    for (size_t i = 0; i < sizeof(vm_modules)/sizeof(vm_modules[0]); i++)
    {
        if(strcmp_case(module->info->name, vm_modules[i]) == 0)
        {
            module->info->kind = NCAI_MODULE_VM_INTERNAL;
            return;
        }
    }
}
예제 #25
0
static int is_asf_complex_data(const char *meta_file)
{
    char *ext = findExt(meta_file);
    if (ext && strcmp_case(ext, ".meta")==0) {
        meta_parameters *meta = meta_read(meta_file);
        if (meta->general->data_type == COMPLEX_BYTE ||
            meta->general->data_type == COMPLEX_INTEGER16 ||
            meta->general->data_type == COMPLEX_INTEGER32 ||
            meta->general->data_type == COMPLEX_REAL32 ||
            meta->general->data_type == COMPLEX_REAL64)
        {
            meta_free(meta);
            return 1;
        }
        meta_free(meta);
    }

    return 0;
}
예제 #26
0
void h5_att_str(hid_t file_id, char *group, char *name, char *value)
{
  int ii, kk;
  void *buf = NULL;
  hid_t attr_id;
  H5O_info_t object_info;
  char *attr_name = (char *) MALLOC(sizeof(char)*50);

  H5Oget_info_by_name(file_id, group, &object_info, H5P_DEFAULT);
  for (ii=0; ii<object_info.num_attrs; ii++) {
    attr_id = H5Aopen_by_idx(file_id, group, H5_INDEX_NAME, H5_ITER_NATIVE, ii,
      H5P_DEFAULT, H5P_DEFAULT);
    H5Aget_name(attr_id, 50, attr_name);
    if (strcmp_case(name, attr_name) == 0) {
      hid_t attr_type = H5Aget_type(attr_id);
      H5T_class_t data_type = H5Tget_native_type(attr_type, H5T_DIR_DEFAULT);
      size_t data_size = H5Tget_size(data_type);
      hid_t attr_space = H5Aget_space(attr_id);
      hsize_t dims[H5S_MAX_RANK];
      int rank = H5Sget_simple_extent_dims(attr_space, dims, NULL);
      hsize_t elements = 1;
      for (kk=0; kk<rank; kk++)
        elements *= dims[kk];
      buf = (void *) MALLOC((unsigned)(elements*data_size));
      H5Aread(attr_id, attr_type, buf);
      H5Tclose(attr_type);
      H5Tclose(data_type);
      H5Sclose(attr_space);
    }
    else {
      H5Aclose(attr_id);
      continue;
    }
    H5Aclose(attr_id);
  }
  if (buf) {
    strcpy(value, buf);
    FREE(buf);
  }
  else
    strcpy(value, "???");
  FREE(attr_name);
}
예제 #27
0
/*Extract date from the metadata-style given string:
instr="DD-MMM-YYYY, hh:mm:ss"
index  000000000011111111112
index  012345678901234567890
*/
void parse_DMYdate(const char *inStr,ymd_date *date,hms_time *time)
{
  char mon[][5]=
    {"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
  char buf[100];
  int i,sec;
#define subStr(start,len,dest) strncpy(buf,&inStr[start],len);buf[len]=0;sscanf(buf,"%d",dest);
  subStr(7,4,&date->year);
  for (i=0; i<13; i++) {
    strncpy(buf, &inStr[3], 3);
    buf[3] = 0;
    if (strcmp_case(uc(buf), mon[i]) == 0)
      date->month = i;
  }
  subStr(0,2,&date->day);
  subStr(13,2,&time->hour);
  subStr(16,2,&time->min);
  subStr(19,2,&sec);
  time->sec=sec;
#undef subStr
}
예제 #28
0
// MMM-DD-YYYY hh:mm:ss
// 01234567890123456789
void ursa2date(const char *inStr, ymd_date *date, hms_time *time)
{
  char mon[][5]= 
    {"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
  char buf[100];
  int i,sec;
  if (strcmp(inStr, "???") == 0)
    sprintf(inStr, "01-Jan-1900, 00:00:00");
#define subStr(start,len,dest) strncpy(buf,&inStr[start],len);buf[len]=0;sscanf(buf,"%d",dest);
  for (i=0; i<13; i++) {
    strncpy(buf, &inStr[0], 3);
    buf[3] = 0;
    if (strcmp_case(uc(buf), mon[i]) == 0)
      date->month = i;
  }
  subStr(4,2,&date->day);
  subStr(7,4,&date->year);
  subStr(12,2,&time->hour);
  subStr(15,2,&time->min);
  subStr(18,2,&sec);
  time->sec = sec;
#undef subStr
}
예제 #29
0
int isparfile(char *file)
{
  char *inFile = STRDUP(file);
  int isParfile=0;
  char *line=NULL, *s;
  FILE *fp = NULL;

  if (findExt(inFile) && (strcmp_case(findExt(inFile), ".PAR") != 0)) {
    strcat(inFile, ".par");
    if (!fileExists(inFile))
      return FALSE;
  }

  fp = fopen(inFile, "r");
  if (fp) {
    int line_count = 0;
    line = (char*)MALLOC(sizeof(char)*LINE_MAX);
    while (fgets(line, LINE_MAX, fp)) {
      line[strlen(line)-1] = '\0';
      s=line;
      while(isspace((int)(*s))) ++s;
      if (s && strlen(s) && 
	  strncmp_case(s, "processor_name: SKY", 19) == 0) {
	isParfile = 1;
	break;
      }
      // avoid scanning the entire contents of a huge file
      if (++line_count>10000)
	break;
    }
  }
  FREE(line);
  FREE(inFile);
  FCLOSE(fp);
  
  return isParfile;
}
예제 #30
0
int isshape(char *inFile)
{
    char *ext = findExt(inFile);
    if (ext && strcmp_case(ext,".shp")!=0) {
        return FALSE;
    }

    char *dbaseFile, *basename;
    int isShape = 0;
    int nEntities, pointType;
    DBFHandle dbase;
    SHPHandle shape;

    dbaseFile = (char *)MALLOC(sizeof(char)*(strlen(inFile)+5));
    basename = get_basename(inFile);
    sprintf(dbaseFile, "%s.dbf", basename);
    dbase = DBFOpen(dbaseFile, "r+b");
    shape = SHPOpen(inFile, "r+b");
    if (dbase != NULL && shape != NULL) {
        SHPGetInfo(shape, &nEntities, &pointType, NULL, NULL);
        if (nEntities >= 1 &&
            (pointType == SHPT_POLYGON   ||
             pointType == SHPT_POINT     ||
             pointType == SHPT_ARC       ||
             pointType == SHPT_MULTIPOINT )
        )
        {
            isShape = 1;
        }
    }
    if (shape) SHPClose(shape);
    if (dbase) DBFClose(dbase);
    FREE(basename);
    FREE(dbaseFile);

    return isShape;
}