Beispiel #1
0
void stringlist_insert_stringlist_copy(stringlist_type * stringlist, const stringlist_type * src, int pos) {
  int size_old  = stringlist_get_size(stringlist);

  /** Cannot use assert_index here. */
  if(pos < 0 || pos > size_old)
    util_abort("%s: Position %d is out of bounds. Min: 0 Max: %d\n", pos, size_old);
  {
  stringlist_type * start = stringlist_alloc_new();
  stringlist_type * end   = stringlist_alloc_new();
  stringlist_type * newList   = stringlist_alloc_new();
  int i;

  for( i=0; i<pos; i++)
    stringlist_append_ref(start, stringlist_iget(stringlist, i));

  for( i=pos; i<size_old; i++)
    stringlist_append_ref(end  , stringlist_iget(stringlist, i));

  stringlist_append_stringlist_copy(newList, start);
  stringlist_append_stringlist_copy(newList, src  );
  stringlist_append_stringlist_copy(newList, end  );

  stringlist_clear(stringlist);
  stringlist_append_stringlist_copy(stringlist, newList);

  stringlist_free(newList);
  stringlist_free(start);
  stringlist_free(end);
  }
}
Beispiel #2
0
void test_run_workflow(const char * config_file , const char * job_file) {
  ert_test_context_type * test_context = ert_test_context_alloc("INSTALL_WORKFLOW" , config_file , NULL );
  test_assert_false( ert_test_context_run_worklow( test_context , "No-does.not.exist"));
  
  ert_test_context_install_workflow_job( test_context , "JOB" , job_file );
  {
    FILE * stream1 = util_fopen( "WFLOW1", "w");
    FILE * stream2 = util_fopen( "WFLOW2", "w");
    stringlist_type * args = stringlist_alloc_new( );
    ert_test_context_fwrite_workflow_job( stream1 , "JOB" , args);
    stringlist_append_ref( args , "NewCase");
    ert_test_context_fwrite_workflow_job( stream2 , "JOB" , args);
        
    stringlist_free( args );
    fclose( stream1 );
    fclose( stream2 );
  }
  test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW1" , "WFLOW1"));
  test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW2" , "WFLOW2"));
  
  test_assert_true( ert_test_context_run_worklow( test_context , "WFLOW2"));
  test_assert_false( ert_test_context_run_worklow( test_context , "WFLOW1"));

  ert_test_context_free( test_context );
}
Beispiel #3
0
stringlist_type * stringlist_alloc_argv_ref(const char ** argv , int argc) {
  int iarg;
  stringlist_type * stringlist = stringlist_alloc_empty( true );
  for (iarg = 0; iarg < argc; iarg++)
    stringlist_append_ref( stringlist , argv[iarg]);

  return stringlist;
}
Beispiel #4
0
void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type * option_list) {
  //Add options common for all driver types
  stringlist_append_ref(option_list, MAX_RUNNING);
  
  //Add options for the specific driver type
  if (driver->init_options) 
    driver->init_options(option_list);
  else 
    util_abort("%s: driver:%s does not support run time reading of options\n", __func__, driver->name);
 }
Beispiel #5
0
stringlist_type * gen_kw_config_alloc_name_list( const gen_kw_config_type * config ) {
  
  stringlist_type * name_list = stringlist_alloc_new();
  int i;
  for (i=0; i < vector_get_size( config->parameters ); i++) {
    const gen_kw_parameter_type * parameter = vector_iget_const( config->parameters , i );
    stringlist_append_ref( name_list , parameter->name );    /* If the underlying parameter goes out scope - whom bang .. */
  }

  return name_list;
}
Beispiel #6
0
stringlist_type * ert_run_context_alloc_runpath_list(const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) {
  stringlist_type * runpath_list = stringlist_alloc_new();
  for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {

    if (bool_vector_iget( iactive , iens ))
      stringlist_append_owned_ref( runpath_list , ert_run_context_alloc_runpath(iens , runpath_fmt , subst_list , iter));
    else
      stringlist_append_ref( runpath_list , NULL );

  }
  return runpath_list;
}
Beispiel #7
0
void sched_kw_gruptree_init_child_parent_list( const sched_kw_gruptree_type * kw , stringlist_type * child , stringlist_type * parent) {
  stringlist_clear( child );
  stringlist_clear( parent );
  {
    hash_iter_type * iter = hash_iter_alloc( kw->gruptree_hash );
    while (!hash_iter_is_complete( iter )) {
      const char * child_group  = hash_iter_get_next_key( iter );
      const char * parent_group = hash_get_string( kw->gruptree_hash , child_group );
      
      stringlist_append_copy( child , child_group );       /* <- The iterator keys go out of scope when hash_iter_free() is called. */
      stringlist_append_ref( parent , parent_group );
    }
    hash_iter_free( iter );
  }
}
Beispiel #8
0
void test_install_workflow( const char * config_file , const char * job_file ) {
  ert_test_context_type * test_context = ert_test_context_alloc("INSTALL_WORKFLOW" , config_file , NULL );
  const char * wf_file = "WFLOW";

  ert_test_context_install_workflow_job( test_context , "JOB" , job_file );
  {
    FILE * stream = util_fopen( wf_file , "w");
    stringlist_type * args = stringlist_alloc_new( );
    stringlist_append_ref( args , "NewCase");
    ert_test_context_fwrite_workflow_job( stream , "JOB" , args);
    stringlist_free( args );
    fclose( stream );
  }
  test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW" , wf_file ));
  ert_test_context_free( test_context );
}
Beispiel #9
0
void test_run_workflow_job( const char * config_file , const char * job_file ) {
  ert_test_context_type * test_context = ert_test_context_alloc("CREATE_CONTEXT_JOB" , config_file , NULL );
  stringlist_type * args0 = stringlist_alloc_new( );
  stringlist_type * args1 = stringlist_alloc_new( );

  stringlist_append_ref( args1 , "NewCase");
  test_assert_false( ert_test_context_run_worklow_job( test_context , "NO-this-does-not-exist" , args1));
  ert_test_context_install_workflow_job( test_context , "JOB" , job_file );
  
  test_assert_false( ert_test_context_run_worklow_job( test_context , "JOB" , args0));
  test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args1));
  
  stringlist_free( args0 );
  stringlist_free( args1 );
  ert_test_context_free( test_context );
}
Beispiel #10
0
static stringlist_type * ert_run_context_alloc_runpath_list(const bool_vector_type * iactive , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) {
  stringlist_type * runpath_list = stringlist_alloc_new();
  for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
    if (bool_vector_iget( iactive , iens )) {
      char * tmp1 = path_fmt_alloc_path(runpath_fmt , false , iens, iter);    /* 1: Replace first %d with iens, if a second %d replace with iter */
      char * tmp2 = tmp1;

      if (subst_list)
        tmp2 = subst_list_alloc_filtered_string( subst_list , tmp1 );         /* 2: Filter out various magic strings like <CASE> and <CWD>. */

      stringlist_append_copy( runpath_list , tmp2 );

      if (subst_list)
        free( tmp2 );
      free( tmp1 );
    } else
      stringlist_append_ref( runpath_list , NULL );
  }
  return runpath_list;
}
Beispiel #11
0
sched_file_type * sched_file_alloc_copy(const sched_file_type * src , bool deep_copy) {
  int ikw;
  sched_file_type * target = sched_file_alloc(src->start_time);
  
  for (ikw = 0; ikw < vector_get_size( src->kw_list ); ikw++) {
    sched_kw_type * kw = vector_iget( src->kw_list , ikw );
    sched_file_add_kw( target , kw );
  }
                                                                
  
  {
    int i;
    for (i = 0; i < stringlist_get_size( src->files ); i++) {
      if (deep_copy)
        stringlist_append_copy( target->files , stringlist_iget(src->files , i));
      else
        stringlist_append_ref( target->files , stringlist_iget(src->files , i));
    }
  }

  sched_file_update_index( target );
  return target;
}
Beispiel #12
0
trans_func_type * trans_func_alloc( const char * func_name ) {
  trans_func_type * trans_func = trans_func_alloc_empty( func_name );
  {
    if (util_string_equal(func_name , "NORMAL")) {
      stringlist_append_ref( trans_func->param_names , "MEAN");
      stringlist_append_ref( trans_func->param_names , "STD" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_normal;
    }  
    
    if (util_string_equal( func_name , "LOGNORMAL")) {
      stringlist_append_ref( trans_func->param_names , "MEAN");
      stringlist_append_ref( trans_func->param_names , "STD" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_lognormal;
    }
    
    if (util_string_equal( func_name , "UNIFORM")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_unif;
    }


    if (util_string_equal( func_name , "DUNIF")) {
      stringlist_append_ref( trans_func->param_names , "STEPS");
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      arg_pack_append_int( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      
      trans_func->func = trans_dunif;
    }


    if (util_string_equal( func_name , "ERRF")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      stringlist_append_ref( trans_func->param_names , "SKEWNESS");
      stringlist_append_ref( trans_func->param_names , "WIDTH" );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );

      trans_func->func = trans_errf;
    }
    

    if (util_string_equal( func_name , "DERRF")) {
      stringlist_append_ref( trans_func->param_names , "STEPS");
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      stringlist_append_ref( trans_func->param_names , "SKEWNESS");
      stringlist_append_ref( trans_func->param_names , "WIDTH" );
      arg_pack_append_int( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );

      trans_func->func = trans_derrf;
    }


    if (util_string_equal( func_name , "LOGUNIF")) {
      stringlist_append_ref( trans_func->param_names , "MIN");
      stringlist_append_ref( trans_func->param_names , "MAX" );
      
      arg_pack_append_double( trans_func->params , 0 );
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_logunif;
    }


    if (util_string_equal( func_name , "CONST")) {
      stringlist_append_ref( trans_func->param_names , "VALUE");
      arg_pack_append_double( trans_func->params , 0 );
      trans_func->func = trans_const;
    }
    
    if (util_string_equal( func_name , "NONE")) 
      trans_func->func = trans_const;


    if (trans_func->func == NULL) 
      util_exit("%s: Sorry: function name:%s not recognized \n",__func__ , func_name);
  }
  return trans_func;
}
Beispiel #13
0
void path_stack_push_cwd( path_stack_type * path_stack ) {
    char * cwd = util_alloc_cwd();
    stringlist_append_owned_ref( path_stack->storage , cwd);
    stringlist_append_ref( path_stack->stack , cwd );
}
Beispiel #14
0
void stringlist_append_stringlist_ref(stringlist_type * stringlist , const stringlist_type * src) {
  int i;
  for (i = 0; i < stringlist_get_size( src ); i++)
    stringlist_append_ref(stringlist , stringlist_iget(src , i));
}