예제 #1
0
파일: stringlist.c 프로젝트: akva2/ert
int stringlist_select_matching_files(stringlist_type * names , const char * path , const char * file_pattern) {
#ifdef ERT_HAVE_GLOB
  char * pattern  = util_alloc_filename( path , file_pattern , NULL );
  int match_count = stringlist_select_matching( names , pattern );
  free( pattern );
  return match_count;
#else
  {
    WIN32_FIND_DATA file_data;
    HANDLE          file_handle;
    char * pattern  = util_alloc_filename( path , file_pattern , NULL );

    stringlist_clear( names );
    file_handle = FindFirstFile( pattern , &file_data );
    if (file_handle != INVALID_HANDLE_VALUE) {
      do {
        char * full_path = util_alloc_filename( path , file_data.cFileName , NULL);
        stringlist_append_owned_ref( names , full_path );
      } while (FindNextFile( file_handle , &file_data) != 0);
    }
    FindClose( file_handle );
    free( pattern );

    return stringlist_get_size( names );
  }
#endif
}
예제 #2
0
파일: ens_tar.c 프로젝트: JacobStoren/ert
bool tar_and_remove_dir( const char * root_path , const char * current_dir , int current_depth , void * arg) {
  if (strncmp(current_dir , "mem" , 3) == 0) {
    msg_type * msg = msg_safe_cast( arg );
    {
      char * tar_file    = util_alloc_filename(NULL , current_dir , "tar.gz");
      char * target_file = util_alloc_filename(root_path , current_dir , "tar.gz");
      char * text        = util_alloc_sprintf("%s: Creating %s" , root_path , tar_file );
      msg_update( msg , text );
      util_fork_exec("tar" , 3 , (const char *[3]) {"-czf" , tar_file , current_dir} , true , target_file , root_path , NULL , NULL , NULL);
      free( text );
      free( tar_file );
      free( target_file );
    }
예제 #3
0
파일: migrate_bfs.c 프로젝트: Ensembles/ert
static void copy_index( const char * src_case , const char * target_case) {
  char * mount_src    = util_alloc_filename(src_case , "INDEX" , "mnt");
  char * mount_target = util_alloc_filename(target_case , "INDEX" , "mnt");
  char * data_src     = util_alloc_filename(src_case , "INDEX" , "data_0");
  char * data_target  = util_alloc_filename(target_case , "INDEX" , "data_0");

  util_copy_file( mount_src , mount_target );
  util_copy_file( data_src , data_target );

  free( mount_src );
  free( mount_target );
  free( data_src );
  free( data_target );
}
예제 #4
0
void create_submit_script_script_according_to_input() {
  char ** args = util_calloc(2, sizeof * args);
  args[0] = "/tmp/jaja/";
  args[1] = "number2arg";
  char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh");
  torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args);
  printf("Create submit script OK\n");

  FILE* file_stream = util_fopen(script_filename, "r");
  bool at_eof = false;

  char * line = util_fscanf_alloc_line(file_stream, &at_eof);
  test_assert_string_equal("#!/bin/sh", line);
  free(line);

  line = util_fscanf_alloc_line(file_stream, &at_eof);
  test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line);
  free(line);

  line = util_fscanf_alloc_line(file_stream, &at_eof);
  free(line);
  test_assert_true(at_eof);

  fclose(file_stream);
}
예제 #5
0
void * status_job__( void * arg ) {
  const int usleep_time = 10000;
  arg_pack_type * arg_pack = arg_pack_safe_cast( arg );
  job_type * job = job_safe_cast( arg_pack_iget_ptr( arg_pack , 0 ) );
  job_queue_type * queue = arg_pack_iget_ptr( arg_pack , 1 );
  char * run_file = util_alloc_filename( job->run_path , "RUNNING" , NULL);

  while (true) {
    if (job->queue_index >= 0) {
      job_status_type status;
      if (util_is_file(run_file)) {
        status = job_queue_iget_job_status(queue, job->queue_index);
        if (util_is_file(run_file))
          test_assert_true( (status == JOB_QUEUE_RUNNING) || (status == JOB_QUEUE_SUBMITTED) );
      }
      status = job_queue_iget_job_status(queue, job->queue_index);
      if (status == JOB_QUEUE_SUCCESS)
        break;
    }
    usleep( usleep_time );
  }

  free( run_file );
  return NULL;
}
예제 #6
0
int main(int argc , char ** argv) {
    enkf_main_install_SIGNALS();

    const char * config_file             = argv[1];
    ert_test_context_type * test_context = ert_test_context_alloc("VerifyJobsFileTest" , config_file);
    enkf_main_type * enkf_main           = ert_test_context_get_main(test_context);

    {
        const int ens_size         = enkf_main_get_ensemble_size( enkf_main );
        bool_vector_type * iactive = bool_vector_alloc(0, false);
        bool_vector_iset( iactive , ens_size - 1 , true );

        enkf_main_create_run_path(enkf_main , iactive , 0);
        bool_vector_free(iactive);
    }

    const char * filename = util_alloc_filename(ert_test_context_get_cwd(test_context),
                            "simulations/run0/jobs.py", NULL);
    const char * jobs_file_content = util_fread_alloc_file_content(filename, NULL);

    test_assert_true  (strstr(jobs_file_content, "umask = 0022") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0023") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0032") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0122") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 1022") != NULL);

    ert_test_context_free(test_context);
    exit(0);
}
예제 #7
0
void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * input_case ) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    int root_version = enkf_fs_get_version104( ens_path );
    if (root_version == -1 || root_version == 105) {
        if (input_case == NULL) {
            char * current_mount_point = util_alloc_filename( ens_path , CURRENT_CASE , NULL);

            if (enkf_main_current_case_file_exists(enkf_main)) {
                char * current_case = enkf_main_read_alloc_current_case_name(enkf_main);
                enkf_main_select_fs(enkf_main, current_case);
                free (current_case);
            } else if (enkf_fs_exists( current_mount_point ) && util_is_link( current_mount_point )) {
                /*If the current_case file does not exists, but the 'current' symlink does we use readlink to
                  get hold of the actual target before calling the  enkf_main_select_fs() function. We then
                  write the current_case file and delete the symlink.*/
                char * target_case = util_alloc_atlink_target( ens_path , CURRENT_CASE );
                enkf_main_select_fs( enkf_main , target_case );
                unlink(current_mount_point);
                enkf_main_write_current_case_file(enkf_main, target_case);
                free( target_case );
            } else
                enkf_main_select_fs( enkf_main , DEFAULT_CASE );  // Selecting (a new) default case

            free( current_mount_point );
        } else
            enkf_main_select_fs( enkf_main , input_case );
    } else {
        fprintf(stderr,"Sorry: the filesystem located in %s must be upgraded before the current ERT version can read it.\n" , ens_path);
        exit(1);
    }
}
예제 #8
0
void ert_workflow_list_add_jobs_in_directory( ert_workflow_list_type * workflow_list , const char * path ) {
  DIR * dirH = opendir( path );
  if (dirH) {
    while (true) {
      struct dirent * entry = readdir( dirH );
      if (entry != NULL) {
        if ((strcmp(entry->d_name , ".") != 0) && (strcmp(entry->d_name , "..") != 0)) {
          char * full_path = util_alloc_filename( path , entry->d_name , NULL );

          if (util_is_file( full_path )) {
           if (ert_log_is_open())
              ert_log_add_message( 1 , NULL , util_alloc_sprintf("Adding workflow job:%s " , full_path ), true);

            ert_workflow_list_add_job( workflow_list , entry->d_name , full_path );
          }

          free( full_path );
        }
      } else
        break;
    }
    closedir( dirH );
  } else
    fprintf(stderr, "** Warning: failed to open workflow/jobs directory: %s\n", path);
}
예제 #9
0
파일: enkf_fs.c 프로젝트: shulNN/ert
static enkf_fs_type * enkf_fs_alloc_empty( const char * mount_point , bool read_only) {
  enkf_fs_type * fs          = util_malloc(sizeof * fs );
  UTIL_TYPE_ID_INIT( fs , ENKF_FS_TYPE_ID );
  fs->time_map               = time_map_alloc();
  fs->cases_config           = cases_config_alloc();
  fs->state_map              = state_map_alloc();
  fs->misfit_ensemble        = misfit_ensemble_alloc();
  fs->index                  = NULL;
  fs->eclipse_static         = NULL;
  fs->parameter              = NULL;
  fs->dynamic_forecast       = NULL;
  fs->dynamic_analyzed       = NULL;
  fs->read_only              = read_only;
  fs->mount_point            = util_alloc_string_copy( mount_point );
  fs->refcount               = 0;
  fs->lock_fd                = 0;
  
  if (mount_point == NULL)
    util_abort("%s: fatal internal error: mount_point == NULL \n",__func__);
  {
    char ** path_tmp;
    int     path_len;

    util_path_split( fs->mount_point , &path_len , &path_tmp);
    fs->case_name = util_alloc_string_copy( path_tmp[path_len - 1]);
    fs->root_path = util_alloc_joined_string( (const char **) path_tmp , path_len , UTIL_PATH_SEP_STRING);
    fs->lock_file = util_alloc_filename( fs->mount_point , fs->case_name , "lock");

    util_free_stringlist( path_tmp , path_len );
  }
  return fs;
}
예제 #10
0
파일: ext_joblist.c 프로젝트: agchitu/ert
void ext_joblist_add_jobs_in_directory(ext_joblist_type * joblist  , const char * path, const char * license_root_path, bool user_mode, bool search_path ) {
  DIR * dirH = opendir( path );
  if (dirH) {
    while (true) {
      struct dirent * entry = readdir( dirH );
      if (entry != NULL) {
        if ((strcmp(entry->d_name , ".") != 0) && (strcmp(entry->d_name , "..") != 0)) {
          char * full_path = util_alloc_filename( path , entry->d_name , NULL );
          if (util_is_file( full_path )) {
              ext_job_type * new_job = ext_job_fscanf_alloc(entry->d_name, license_root_path, user_mode, full_path, search_path);
              if (new_job != NULL) {
                ext_joblist_add_job(joblist, entry->d_name, new_job);
              }
              else{
                  fprintf(stderr," Failed to add forward model job: %s \n",full_path);
              }
          }
          free( full_path );
        }
      } else
        break;
    }
    closedir( dirH );
  } else
    fprintf(stderr, "** Warning: failed to open jobs directory: %s\n", path);
}
예제 #11
0
static bool enkf_main_current_case_file_exists( const enkf_main_type * enkf_main) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    char * current_case_file = util_alloc_filename(ens_path, CURRENT_CASE_FILE, NULL);
    bool exists = util_file_exists(current_case_file);
    free(current_case_file);
    return exists;
}
예제 #12
0
파일: hook_manager.c 프로젝트: Thif/ert-1
void hook_manager_set_runpath_list_file( hook_manager_type * hook_manager , const char * basepath, const char * filename) {

  if (filename && util_is_abs_path( filename ))
    hook_manager_set_runpath_list_file__( hook_manager , filename );
  else {
    const char * file = RUNPATH_LIST_FILE;

    if (filename != NULL)
      file = filename;

    char * file_with_path_prefix = NULL;
    if (basepath != NULL) {
      file_with_path_prefix = util_alloc_filename(basepath, file, NULL);
    }
    else
      file_with_path_prefix = util_alloc_string_copy(file);

    {
      char * absolute_path = util_alloc_abs_path(file_with_path_prefix);
      hook_manager_set_runpath_list_file__( hook_manager , absolute_path );
      free( absolute_path );
    }

    free(file_with_path_prefix);
  }
}
예제 #13
0
config_root_path_type * config_root_path_alloc( const char * input_path ) {
  if (input_path == NULL || util_is_directory( input_path )) {
    config_root_path_type * root_path = util_malloc( sizeof * root_path );
    {
      char * cwd = util_alloc_cwd();
      
      root_path->input_path = util_alloc_string_copy( input_path );
      if (input_path == NULL) {
        root_path->rel_path = NULL;
        root_path->abs_path = util_alloc_string_copy( cwd );
      } else {
        if (util_is_abs_path( input_path )) {
          root_path->abs_path = util_alloc_string_copy( input_path );
          root_path->rel_path = util_alloc_rel_path( cwd , root_path->abs_path);
        } else {
          root_path->rel_path = util_alloc_string_copy( input_path );
          {
            char * abs_path = util_alloc_filename( cwd , input_path , NULL );
            root_path->abs_path = util_alloc_realpath( abs_path );
            free( abs_path );
          }
        }
      }
      free( cwd );
    }
    return root_path;
  } else 
    return NULL;
}
예제 #14
0
void ecl_config_set_schedule_file( ecl_config_type * ecl_config , const char * schedule_file ) {
  if (ecl_config->start_date == -1)
    util_abort("%s: must set ecl_data_file first \n",__func__);
  {
    char * base;  /* The schedule target file will be without any path component */
    char * ext;
    util_alloc_file_components(schedule_file , NULL , &base , &ext);
    ecl_config->schedule_target_file = util_alloc_filename(NULL , base , ext);
    free(ext);
    free(base);
  }
  ecl_config->sched_file = sched_file_alloc( ecl_config->start_date );
  
  
  sched_file_parse(ecl_config->sched_file , schedule_file );
  ecl_config->last_history_restart = sched_file_get_num_restart_files( ecl_config->sched_file ) - 1;   /* We keep track of this - so we can stop assimilation at the end of history */
  {
    hash_iter_type * iter = hash_iter_alloc( ecl_config->fixed_length_kw );
    while (!hash_iter_is_complete( iter )) {
      const char * key = hash_iter_get_next_key( iter );
      int length       = hash_get_int( ecl_config->fixed_length_kw , key );
      
      sched_file_add_fixed_length_kw( ecl_config->sched_file , key , length);
    }
    hash_iter_free( iter );
  }
}
예제 #15
0
stringlist_type * enkf_main_alloc_caselist( const enkf_main_type * enkf_main ) {
    stringlist_type * case_list = stringlist_alloc_new( );
    {
        const char * ens_path = model_config_get_enspath( enkf_main->model_config );
        DIR * ens_dir = opendir( ens_path );
        if (ens_dir != NULL) {
            int ens_fd = dirfd( ens_dir );
            if (ens_fd != -1) {
                struct dirent * dp;
                do {
                    dp = readdir( ens_dir );
                    if (dp != NULL) {
                        if (!(util_string_equal( dp->d_name , ".") || util_string_equal(dp->d_name , ".."))) {
                            if (!util_string_equal( dp->d_name , CURRENT_CASE_FILE)) {
                                char * full_path = util_alloc_filename( ens_path , dp->d_name , NULL);
                                if (util_is_directory( full_path ))
                                    stringlist_append_copy( case_list , dp->d_name );
                                free( full_path);
                            }
                        }
                    }
                } while (dp != NULL);
            }
        }
        closedir( ens_dir );
    }
    return case_list;
}
예제 #16
0
char * enkf_main_alloc_mount_point( const enkf_main_type * enkf_main , const char * case_path) {
    char * mount_point;
    if (util_is_abs_path( case_path ))
        mount_point = util_alloc_string_copy( case_path );
    else
        mount_point = util_alloc_filename( model_config_get_enspath( enkf_main->model_config) , case_path , NULL);
    return mount_point;
}
예제 #17
0
파일: gen_data.c 프로젝트: Ensembles/ert
void gen_data_ecl_write(const gen_data_type * gen_data , const char * run_path , const char * eclfile , void * filestream) {
  if (eclfile != NULL) {
    char * full_path = util_alloc_filename( run_path , eclfile  , NULL);

    gen_data_file_format_type export_type = gen_data_config_get_output_format( gen_data->config );
    gen_data_export( gen_data , full_path , export_type , filestream );
    free( full_path );
  }
}
예제 #18
0
static void enkf_main_write_current_case_file( const enkf_main_type * enkf_main, const char * case_path) {
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    const char * base = CURRENT_CASE_FILE;
    char * current_case_file = util_alloc_filename(ens_path , base, NULL);
    FILE * stream = util_fopen( current_case_file  , "w");
    fprintf(stream, "%s", case_path);
    util_fclose(stream);
    free(current_case_file);
}
예제 #19
0
void test_link( const latex_type * latex , const char * link , const char * target) {
  char * latex_link   = util_alloc_filename( latex_get_runpath( latex ) , link , NULL);
  char * latex_target = util_alloc_link_target( latex_link );
  
  test_assert_true( util_same_file( target , latex_target));
  
  free( latex_link );
  free( latex_target);
}
예제 #20
0
static char * __alloc_relocated__(const config_path_elm_type * path_elm , const char * value) {
  char * file;

  if (util_is_abs_path(value))
    file = util_alloc_string_copy( value );
  else
    file = util_alloc_filename(config_path_elm_get_relpath( path_elm ) , value , NULL);

  return file;
}
예제 #21
0
void test_alloc_filename_empty_strings() {
  const char * path = "";
  const char * filename = "file";
  const char * extension = "";

  char * alloc_filename = util_alloc_filename( path, filename , extension);
  test_assert_string_equal( alloc_filename , filename );
  free( alloc_filename );

}
예제 #22
0
char * util_alloc_PATH_executable(const char * executable) {
  if (util_is_abs_path(executable)) {
    if (util_is_executable(executable))
      return util_alloc_string_copy(executable);
    else
      return NULL;
  } else if (strncmp(executable , "./" , 2) == 0) {
    char * cwd = util_alloc_cwd();
    char * path = util_alloc_filename(cwd , &executable[2] , NULL);

    /* The program has been invoked as ./xxxx */
    if (!(util_is_file(path) && util_is_executable( path ))) {
      free( path );
      path = NULL;
    }
    free( cwd );

    return path;
  } else {
    char * full_path  = NULL;
    char ** path_list = util_alloc_PATH_list();
    int ipath = 0;

    while (true) {
      if (path_list[ipath] != NULL)  {
        char * current_attempt = util_alloc_filename(path_list[ipath] , executable , NULL);
      
        if ( util_is_file( current_attempt ) && util_is_executable( current_attempt )) {
          full_path = current_attempt;
          break;
        } else {
          free(current_attempt);
          ipath++;
        }
      } else
        break;
    }
    
    util_free_NULL_terminated_stringlist(path_list);
    return full_path;
  }
}
예제 #23
0
파일: make_grid.c 프로젝트: agchitu/ert
int main(int argc, char ** argv) {
  if (argc != 5) {
    fprintf(stderr,"%s: basename nx ny nz \n",argv[0]);
    exit(1);
  }

  {
    const char    * base_input = argv[1];
    int             nx         = atoi(argv[2]);
    int             ny         = atoi(argv[3]);
    int             nz         = atoi(argv[4]);

    char * path , *basename;
    ecl_grid_type * ecl_grid;
    
    util_alloc_file_components( base_input , &path , &basename , NULL );

    ecl_grid = ecl_grid_alloc_rectangular(nx,ny,nz , 1 ,1 ,1 , NULL );
    {
      char * EGRID_file = util_alloc_filename( path , basename , "EGRID");

      printf("Writing file: %s ...",EGRID_file); fflush(stdout);
      ecl_grid_fwrite_EGRID2( ecl_grid , EGRID_file, ERT_ECL_METRIC_UNITS);
      free( EGRID_file );
    }

    {
      char * grdecl_file = util_alloc_filename( path , basename , "grdecl");
      FILE * stream = util_fopen( grdecl_file , "w");
      printf("\nWriting file: %s ...",grdecl_file); fflush(stdout);
      ecl_grid_fprintf_grdecl( ecl_grid , stream );
      fclose( stream );
      free( grdecl_file );
      printf("\n");
    }
    
    free( basename );
    util_safe_free( path );
    ecl_grid_free( ecl_grid );
  }
}
예제 #24
0
void test_create_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) {
  stringlist_type * args = stringlist_alloc_new();
  stringlist_append_copy( args , "newly_created_case");
  test_assert_true( ert_test_context_install_workflow_job( test_context , job_name , job_file ));
  test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

  char * new_case = util_alloc_filename( "storage" , "newly_created_case" , NULL);
  test_assert_true(util_is_directory(new_case));
  free(new_case);

  stringlist_free( args );
}
예제 #25
0
void test_latex_link( latex_type * latex ) {
  const char * path = "/tmp/linkFarm";
  const char * file1 = util_alloc_filename( path , "File1" , NULL );
  const char * file2 = util_alloc_filename( path , "File2" , NULL );
  const char * file3 = util_alloc_filename( path , "File3" , NULL );
  

  util_make_path( path );
  make_file( file1 );
  make_file( file2 );
  make_file( file3 );
  
  latex_link_path( latex , path );
  latex_link_directory_content( latex , path );
  
  test_link( latex , "File1" , file1);
  test_link( latex , "File2" , file2);
  test_link( latex , "File3" , file3);
  test_link( latex , "linkFarm" , path);
  
  util_clear_directory( path , true , true );
}
예제 #26
0
void test_chdir() {
  test_work_area_type * work_area = test_work_area_alloc("test-area");
  const char * cwd = test_work_area_get_cwd( work_area );

  test_assert_false( util_chdir_file( "/file/does/not/exist"));
  test_assert_false( util_chdir_file( cwd ));
  {
    FILE * stream = util_mkdir_fopen("path/FILE","w");
    fclose( stream );
  }
  test_assert_true( util_chdir_file( "path/FILE" ));
  test_assert_string_equal( util_alloc_cwd() , util_alloc_filename( cwd, "path", NULL));
  test_work_area_free( work_area );
}
예제 #27
0
char* enkf_main_read_alloc_current_case_name(const enkf_main_type * enkf_main) {
    char * current_case = NULL;
    const char * ens_path = model_config_get_enspath( enkf_main->model_config);
    char * current_case_file = util_alloc_filename(ens_path, CURRENT_CASE_FILE, NULL);
    if (enkf_main_current_case_file_exists(enkf_main)) {
        FILE * stream = util_fopen( current_case_file  , "r");
        current_case = util_fscanf_alloc_token(stream);
        util_fclose(stream);
    } else {
        util_abort("%s: File: storage/current_case not found, aborting! \n",__func__);
    }
    free(current_case_file);
    return current_case;
}
예제 #28
0
char * enkf_config_node_alloc_initfile( const enkf_config_node_type * node , const char * path , int iens) {
  if (node->init_file_fmt == NULL)
    return NULL;
  else {
    char * file = path_fmt_alloc_file( node->init_file_fmt , false , iens );
    if (util_is_abs_path( file ))
      return file;
    else {
      char * full_path = util_alloc_filename( path , file , NULL );
      free( file );
      return full_path;
    }
  }
}
예제 #29
0
파일: rms_extract.c 프로젝트: Ensembles/ert
int main (int argc , char **argv) {
  {
    if (argc <= 2) {
      fprintf(stderr,"rms_extract.x filename tag1(=new_tag1)  tag2 ... \n");
      abort();
    }
  }
  {
    const char * filename = argv[1];
    int i;
    rms_tag_type   * dim_tag;
    rms_file_type *file = rms_file_alloc(filename , false);
    printf("Skal laste inn file: %s \n",filename);
    rms_file_fread(file);
    dim_tag = rms_file_get_dim_tag_ref(file);
    
    for (i = 2; i < argc; i++) {
      char * new_name;
      char * old_name;
      char * new_file;
      
      split_name(argv[i] , &old_name , &new_name);
      printf("Exctracting %s -> %s \n" , old_name , new_name); fflush(stdout);
      new_file = util_alloc_filename(NULL , new_name , "ROFF");
      
      {
        rms_tag_type   * tag;
        rms_file_type  * out_file = rms_file_alloc(new_file , false);
        FILE *stream = rms_file_fopen_w(out_file);
        rms_file_init_fwrite(out_file , "parameter");
        rms_tag_fwrite(dim_tag , stream);
        
        tag = rms_file_get_tag_ref(file , "parameter" , "name" , old_name , true);
        rms_tag_fwrite_parameter(new_name, rms_tag_get_datakey(tag) , stream);
        rms_file_complete_fwrite(out_file);
        fclose(stream);
      }
      if (new_name == old_name) 
        free(new_name);
      else {
        free(new_name);
        free(old_name);
      }
    }
    rms_file_free(file);
    return 0;
  }
}
예제 #30
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);
}