示例#1
0
文件: ecl_util.c 项目: danielfmva/ert
void ecl_util_alloc_summary_data_files(const char * path , const char * base , bool fmt_file , stringlist_type * filelist) {
  char  * unif_data_file = ecl_util_alloc_exfilename(path , base , ECL_UNIFIED_SUMMARY_FILE , fmt_file , -1);
  int files = ecl_util_select_filelist( path , base , ECL_SUMMARY_FILE , fmt_file , filelist);

  if ((files > 0) && (unif_data_file != NULL)) {
    /* 
       We have both a unified file AND a list of files: BASE.S0000,
       BASE.S0001, BASE.S0002, ..., must check which is newest and
       load accordingly.
    */
    bool unified_newest = true;
    int file_nr = 0;
    while (unified_newest && (file_nr < files)) {
      if (util_file_difftime( stringlist_iget(filelist , file_nr) , unif_data_file ) > 0) 
        unified_newest = false;
      file_nr++;
    }
    
    if (unified_newest) {
      stringlist_clear( filelist ); /* Clear out all the BASE.Snnnn selections. */
      stringlist_append_copy( filelist , unif_data_file );
    } 
  } else if (unif_data_file != NULL) {
    /* Found a unified summary file :  Clear out all the BASE.Snnnn selections. */
    stringlist_clear( filelist );      /* Clear out all the BASE.Snnnn selections. */
    stringlist_append_copy( filelist , unif_data_file );
  } 
  util_safe_free( unif_data_file );
}
示例#2
0
int main(int argc , char ** argv) {
  const char * case_path = argv[1];
  char * grid_file = util_alloc_filename(NULL , case_path, "EGRID");
  stringlist_type * file_list = stringlist_alloc_new( );
  ecl_grid_type * grid = ecl_grid_alloc( grid_file );
  ecl_util_select_filelist( NULL , case_path , ECL_RESTART_FILE , false , file_list);
  
  printf("Searching in:%s \n",case_path);
  test_assert_int_equal( 4 , stringlist_get_size( file_list ));
  stringlist_sort( file_list , (string_cmp_ftype *) util_strcmp_int );
  
  
  {
    int i;
    for (i=0; i < stringlist_get_size( file_list); i++) {
      char * ext;
      char * target_ext = util_alloc_sprintf("X%04d" , i);
      util_alloc_file_components( stringlist_iget( file_list , i ) , NULL , NULL , &ext);
      
      test_assert_string_equal( ext , target_ext);
      free( ext );
      free( target_ext );
    }
  }
  {
    well_info_type * well_info = well_info_alloc( grid );
    int i;
    for (i=0; i < stringlist_get_size( file_list ); i++) {
      printf("Loading file:%s \n",stringlist_iget( file_list , i ));
      well_info_load_rstfile( well_info , stringlist_iget(file_list , i));
    }
    well_info_free( well_info );
  }
  
  {
    well_info_type * well_info = well_info_alloc( grid );
    int i;
    stringlist_reverse( file_list );
    for (i=0; i < stringlist_get_size( file_list ); i++) 
      well_info_load_rstfile( well_info , stringlist_iget(file_list , i));
    well_info_free( well_info );
  }


  exit(0);
}
//--------------------------------------------------------------------------------------------------
/// Get set of Eclipse files based on an input file and its path
//--------------------------------------------------------------------------------------------------
bool RifEclipseOutputFileTools::findSiblingFilesWithSameBaseName(const QString& fullPathFileName, QStringList* baseNameFiles)
{
    CVF_ASSERT(baseNameFiles);
    baseNameFiles->clear();

    QString filePath = QFileInfo(fullPathFileName).absoluteFilePath();
    filePath = QFileInfo(filePath).path();
    QString fileNameBase = QFileInfo(fullPathFileName).completeBaseName();

    stringlist_type* eclipseFiles = stringlist_alloc_new();
    ecl_util_select_filelist(RiaStringEncodingTools::toNativeEncoded(filePath).data(), RiaStringEncodingTools::toNativeEncoded(fileNameBase).data(), ECL_OTHER_FILE, false, eclipseFiles);

    int i;
    for (i = 0; i < stringlist_get_size(eclipseFiles); i++)
    {
        baseNameFiles->append(RiaStringEncodingTools::fromNativeEncoded(stringlist_safe_iget(eclipseFiles, i)));
    }

    stringlist_free(eclipseFiles);

    return baseNameFiles->count() > 0;
}
示例#4
0
// Inspired by the ecl_pack application in the ERT library
void concatenateRestart(const std::string& basename) {
    std::string inputPath, inputBase;
    splitBasename(basename, inputPath, inputBase);
    stringlist_type* inputFiles = stringlist_alloc_new();
    const int numFiles = ecl_util_select_filelist(inputPath.c_str(), inputBase.c_str(), ECL_RESTART_FILE, false, inputFiles);

    const char* target_file_name = ecl_util_alloc_filename(inputPath.c_str(), inputBase.c_str(), ECL_UNIFIED_RESTART_FILE, false, -1);
    fortio_type* target = fortio_open_writer(target_file_name, false, ECL_ENDIAN_FLIP);
    int dummy;
    ecl_kw_type* seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy);

    int reportStep = 0;
    for (int i = 0; i < numFiles; ++i) {
        ecl_util_get_file_type(stringlist_iget(inputFiles, i), nullptr, &reportStep);
        ecl_file_type* src_file = ecl_file_open(stringlist_iget(inputFiles, i), 0);
        ecl_kw_iset_int(seqnum_kw, 0, reportStep);
        ecl_kw_fwrite(seqnum_kw, target);
        ecl_file_fwrite_fortio(src_file, target, 0);
        ecl_file_close(src_file);
    }
    fortio_fclose(target);
    stringlist_free(inputFiles);
}
示例#5
0
文件: ecl_util.c 项目: danielfmva/ert
bool ecl_util_alloc_summary_files(const char * path , const char * _base , const char * ext , char ** _header_file , stringlist_type * filelist) {
  bool    fmt_input      = false;
  bool    fmt_set        = false;
  bool    fmt_file       = true; 
  bool    unif_input     = false;
  bool    unif_set       = false;

  
  char  * header_file    = NULL;
  char  * base;

  *_header_file = NULL;

  /* 1: We start by inspecting the input extension and see if we can
     learn anything about formatted/unformatted and
     unified/non-unified from this. The input extension can be NULL,
     in which case we learn nothing.
  */

  if (_base == NULL)
    base = ecl_util_alloc_base_guess(path);
  else
    base = (char *) _base;
  
  if (ext != NULL) {
    ecl_file_enum input_type;

    {
      char * test_name = util_alloc_filename( NULL , base, ext );
      input_type = ecl_util_get_file_type( test_name , &fmt_input , NULL);
      free( test_name );
    }

    if ((input_type != ECL_OTHER_FILE) && (input_type != ECL_DATA_FILE)) {
      /* 
         The file has been recognized as a file type from which we can
         at least infer formatted/unformatted inforamtion.
      */
      fmt_set = true;
      switch (input_type) {
      case(ECL_SUMMARY_FILE):
      case(ECL_RESTART_FILE):
        unif_input = false;
        unif_set   = true;
        break;
      case(ECL_UNIFIED_SUMMARY_FILE):
      case(ECL_UNIFIED_RESTART_FILE):
        unif_input = true;
        unif_set   = true;
        break;
      default:  /* Nothing wrong with this */
        break;
      }
    } 
  }
  
  
  /*
    2: We continue by looking for header files. 
  */
  
  {
    char * fsmspec_file = ecl_util_alloc_exfilename(path , base , ECL_SUMMARY_HEADER_FILE , true  , -1);
    char *  smspec_file = ecl_util_alloc_exfilename(path , base , ECL_SUMMARY_HEADER_FILE , false , -1);
    
    if ((fsmspec_file == NULL) && (smspec_file == NULL))   /* Neither file exists */
      return false;

    
    if (fmt_set)  /* The question of formatted|unformatted has already been settled based on the input filename. */
      fmt_file = fmt_input;
    else {
      if ((fsmspec_file != NULL) && (smspec_file != NULL)) {   /* Both fsmspec and smspec exist - we take the newest. */
        if (util_file_difftime(fsmspec_file , smspec_file) < 0) 
          fmt_file = true;
        else 
          fmt_file = false;
      } else {                                                /* Only one of fsmspec / smspec exists */
        if (fsmspec_file != NULL)
          fmt_file = true;
        else
          fmt_file = false;
      }
    }
    
    if (fmt_file) {
      header_file = fsmspec_file;
      util_safe_free( smspec_file );
    } else {
      header_file = smspec_file;
      util_safe_free( fsmspec_file );
    }

    if (header_file == NULL)
      return false;                                           /* If you insist on e.g. unformatted and only fsmspec exists - no results for you. */
  }
  
  

  /* 
     3: OK - we have found a SMSPEC / FMSPEC file - continue to look for
     XXX.Snnnn / XXX.UNSMRY files.
  */

  if (unif_set) { /* Based on the input file we have inferred whether to look for unified or
                     non-unified input files. */

    if ( unif_input ) {
      char  * unif_data_file = ecl_util_alloc_exfilename(path , base , ECL_UNIFIED_SUMMARY_FILE , fmt_file , -1);
      if (unif_data_file != NULL) {
        stringlist_append_copy( filelist , unif_data_file );
        free( unif_data_file );
      }
    } else 
      ecl_util_select_filelist( path , base , ECL_SUMMARY_FILE , fmt_file , filelist);
  } else          
    ecl_util_alloc_summary_data_files( path , base , fmt_file , filelist );
    
  if (_base == NULL)
    free(base);

  *_header_file    = header_file;
    
  return (stringlist_get_size(filelist) > 0) ? true : false;
}