コード例 #1
0
ファイル: gen_data.c プロジェクト: andlaus/ResInsight
bool gen_data_fload_with_report_step( gen_data_type * gen_data , const char * filename , int report_step) {
  bool   has_file = util_file_exists(filename);
  void * buffer   = NULL;
  int    size     = 0;
  ecl_type_enum load_type;
  
  if ( has_file ) {
    ecl_type_enum internal_type            = gen_data_config_get_internal_type(gen_data->config);
    gen_data_file_format_type input_format = gen_data_config_get_input_format( gen_data->config );
    buffer = gen_common_fload_alloc( filename , input_format , internal_type , &load_type , &size);
    
    /* 
       Look for file @filename_active - if that file is found it is
       interpreted as a an active|inactive mask created by the forward
       model.

       The file is assumed to be an ASCII file with integers, 0
       indicates inactive elements and 1 active elements. The file
       should of course be as long as @filename.
       
       If the file is not found the gen_data->active_mask is set to
       all-true (i.e. the default true value is invoked).
    */
    if (gen_data_config_is_dynamic( gen_data->config )) {
      bool_vector_reset( gen_data->active_mask );  
      bool_vector_iset( gen_data->active_mask , size - 1, true );
      {
        char * active_file = util_alloc_sprintf("%s_active" , filename );
        if (util_file_exists( active_file )) {
          FILE * stream = util_fopen( active_file , "r");
          int active_int;
          for (int index=0; index < size; index++) {
            if (fscanf( stream ,  "%d" , &active_int) == 1) {
              if (active_int == 1)
                bool_vector_iset( gen_data->active_mask , index , true);
              else if (active_int == 0)
                bool_vector_iset( gen_data->active_mask , index , false);
              else
                util_abort("%s: error when loading active mask from:%s only 0 and 1 allowed \n",__func__ , active_file);
            } else
              util_abort("%s: error when loading active mask from:%s - file not long enough.\n",__func__ , active_file );
          }
          fclose( stream );
        }
        free( active_file );
      }
    }
  } 
  gen_data_set_data__(gen_data , size , report_step , load_type , buffer );
  util_safe_free(buffer);
  return has_file;
}
コード例 #2
0
ファイル: gen_data.c プロジェクト: Ensembles/ert
bool gen_data_fload_with_report_step( gen_data_type * gen_data , const char * filename , const forward_load_context_type * load_context) {
  bool   file_exists  = util_file_exists(filename);
  void * buffer   = NULL;
  ecl_data_type load_type;

  if ( file_exists ) {
    ecl_data_type internal_type            = gen_data_config_get_internal_data_type(gen_data->config);
    gen_data_file_format_type input_format = gen_data_config_get_input_format( gen_data->config );
    int    size     = 0;
    buffer = gen_common_fload_alloc( filename , input_format , internal_type , &load_type , &size);
    if (size > 0) {
      gen_data_fload_active__(gen_data, filename, size);
    } else {
      bool_vector_reset( gen_data->active_mask );
    }
    gen_data_set_data__(gen_data , size , load_context , load_type , buffer );
    util_safe_free(buffer);
  }
  return file_exists;
}