示例#1
0
float *read_flt_hdr_files(
    // returns allocated array of data values;
    // NOTE: caller is responsible to free this pointer!
    FILE *in_flt_file,  // .flt file - should be opened in BINARY mode
    FILE *in_hdr_file,  // .hdr file - should be opened in BINARY mode
    int *nrows,         // number of rows in data array
    int *ncols,         // number of cols in data array
    double *xmin,       // min X coordinate (longitude or easting)
    double *xmax,       // max X coordinate (longitude or easting)
    double *ymin,       // min Y coordinate (latitude  or northing)
    double *ymax,       // max Y coordinate (latitude  or northing)
    int *has_nulls,
    int *all_ints,
    char * (*software)  // if software != 0, returns with *software either
                        // null or pointing to a software name/version string;
                        // caller is responsible to free *software pointer!
)
{
    float nodata;
    int big_endian;
    int skipbytes;
    int rowpad;

    // Read and validate .hdr file:

    read_hdr_file(
        in_hdr_file, nrows, ncols, xmin, xmax, ymin, ymax,
        &nodata, &big_endian, &skipbytes, &rowpad, software );

    // Read data from .flt file:

    return read_flt_file(
        in_flt_file, *nrows, *ncols, nodata, big_endian, skipbytes, rowpad,
        has_nulls, all_ints );
}
示例#2
0
int main(int argc, char *argv[]) {
  int           idx=1;
  uuid_t        fid;
  char        * pFid=NULL;
  char        * pRoot=NULL;
  int           ret;
  int           slice;
  int           devices;
  rozofs_stor_bins_file_hdr_vall_t hdr;
  char          path[256];
  int           spare;
  int           block_per_chunk;
  int           chunk;
  int           chunk_stop;

  /*
  ** read common config file
  */
  common_config_read(NULL); 
  
  
  // Get utility name
  utility_name = basename(argv[0]); 
  
  if (argc < 3) usage(); 

  idx = 1;
  while (idx < argc) {

    /* -h */
    if (strcmp(argv[idx], "-h") == 0) usage();
    
    /* -d */
    if (strcmp(argv[idx], "-d") == 0) {
      idx++;
      dump_data = 1;
      continue;
    }
    
    /* -f */
    if (strcmp(argv[idx], "-f") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      pFid = argv[idx];
      ret = rozofs_uuid_parse( pFid, fid);
      if (ret != 0) {
        printf("%s is not a FID !!!\n", pFid);
        usage();
      }  
      idx++;
      continue;    
    }

    /* -p */
    if (strcmp(argv[idx], "-p") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      pRoot = argv[idx];
      struct statfs st;
      if (statfs(pRoot, &st) != 0) {
        printf("%s is not a directory !!!\n", pRoot);
        usage();
      }
      idx++;
      continue;    
    }
    
    /* -a */
    if (strcmp(argv[idx], "-a") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      ret = sscanf(argv[idx], "%u", &prjid);
      if (ret != 1) {
        printf("Bad projection identifier %s !!!\n",argv[idx]);
	usage();
      }
      idx++;
      continue;
    }
            
    /* -b */
    if (strcmp(argv[idx], "-b") == 0) {
      display_blocks = 1;
      idx++;
      if (idx == argc) {
        continue;
      } 
      
      ret = sscanf(argv[idx], "%llu:%llu", (long long unsigned int *)&first, (long long unsigned int *)&last);
      if (ret == 2) {
        if (first>last) {
	  printf("first block index %llu must be lower than last block index %llu !!!\n", (long long unsigned int)first, (long long unsigned int)last);
	  usage();
	}
        idx++;
	continue;
      }
      
      ret = sscanf(argv[idx], ":%llu", (long long unsigned int *)&last);
      if (ret == 1) {
        first = 0;
        idx++;
	continue;
      }
            
      ret = sscanf(argv[idx], "%llu", (long long unsigned int *)&first);
      if (ret == 1) {
        if (argv[idx][strlen(argv[idx])-1]==':') {
          last = -1;
	}
	else {
	  last = first;
	}  
        idx++;
	continue;
      }
   
      continue;
    }
    
    printf("No such option or parameter %s\n",argv[idx]);
    usage();
  }
  
  if ((pFid == NULL)||(pRoot == NULL)) {
    printf("Missing mandatory parameters !!!\n");
    usage();
  }

  rozofs_layout_initialize();
  
  /*
  ** Compute the FID slice
  */
  slice = rozofs_storage_fid_slice(fid);
  
  /*
  ** Get the number of devices
  */
  devices = rozofs_storage_get_device_number(pRoot);
  
  /*
  ** Find out a header file
  */
  if (read_hdr_file(pRoot,devices, slice, &hdr, fid, &spare)!= 0) {
    printf("No header file found for %s under %s !!!\n",pFid,pRoot);
    return -1;
  }
  
  block_per_chunk = ROZOFS_STORAGE_NB_BLOCK_PER_CHUNK(hdr.v0.bsize);
   
  
  if (first == 0) {
    chunk = 0;
  }
  else {
    chunk = first / block_per_chunk;
  }  
  
  if (last == -1) {
    chunk_stop = ROZOFS_STORAGE_MAX_CHUNK_PER_FILE+1;
  }
  else {
    chunk_stop = (last / block_per_chunk)+1;
  }  
     
  while(chunk<chunk_stop) {
    int dev;
    
    dev = rozofs_st_header_get_chunk(&hdr, chunk);
      
    if (dev == ROZOFS_EOF_CHUNK) {
      printf ("\n============ CHUNK %d EOF   ================\n", chunk);      
      break;
    }
    if (dev == ROZOFS_EMPTY_CHUNK) {
      printf ("\n============ CHUNK %d EMPTY ================\n", chunk);
      chunk++;
      continue;
    }
    
    storage_build_chunk_full_path(path, pRoot, dev, spare, slice, fid, chunk);
    printf ("\n============ CHUNK %d ==  %s ================\n", chunk, path);
    
    if (display_blocks) {
      read_chunk_file(fid,path,&hdr,spare, chunk*block_per_chunk);
    }  
    chunk++;
  }
  return 0;
}