Example #1
0
void * enkf_main_rank_on_observations_JOB(void * self, const stringlist_type * args) {
  enkf_main_type * enkf_main  = enkf_main_safe_cast( self );
  const char * ranking_name   = stringlist_iget(args, 0);

  bool step_arguments = false;
  bool obs_arguments  = false;
  int  delimiter      = 0;
  {
    delimiter = stringlist_find_first(args, "|");
    if (delimiter > -1) {
      step_arguments = (delimiter > 1) ? true : false;
      obs_arguments  = (stringlist_get_size(args) > delimiter + 1) ? true : false;
    } else if (stringlist_get_size(args) > 1) {
        step_arguments = true;
        delimiter     = stringlist_get_size(args);
    }
  }

  int_vector_type * steps_vector = NULL;
  {
    char * report_steps = NULL;

    if (step_arguments)
      report_steps = stringlist_alloc_joined_substring(args, 1, delimiter, ",");
    else
      report_steps = util_alloc_sprintf("0-%d", enkf_main_get_history_length(enkf_main));

    steps_vector = string_util_alloc_value_list(report_steps);

    free(report_steps);
  }


  stringlist_type * obs_ranking_keys = NULL;
  {
    char * obs_key_char = NULL;
    if (obs_arguments)
      obs_key_char = stringlist_alloc_joined_substring( args , delimiter+1 , stringlist_get_size(args) , " ");

    enkf_obs_type * enkf_obs = enkf_main_get_obs(enkf_main);
    obs_ranking_keys = enkf_obs_alloc_matching_keylist( enkf_obs , obs_key_char );

    if ((obs_arguments) && (stringlist_get_size(obs_ranking_keys) == 0)) {
      fprintf(stderr,"The input string : \"%s\" did not resolve to any valid observation keys. Job not started\n", obs_key_char);
      return NULL;
    }

    if (obs_arguments)
      free(obs_key_char);
  }


  enkf_main_rank_on_observations(enkf_main, ranking_name, obs_ranking_keys, steps_vector);

  stringlist_free(obs_ranking_keys);
  int_vector_free(steps_vector);
  return NULL;
}
Example #2
0
void * enkf_main_analysis_enkf_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs = enkf_main_get_fs( enkf_main );
  int target_step;
  int_vector_type * step_list;


  // Argument 0: The number of the step to write to
  if (stringlist_get_size(args) > 1)
    util_sscanf_int(stringlist_iget( args , 1) , &target_step);
  else
    target_step = 0;

  // Argument 1 - ??: The timesteps to use in the update
  if (stringlist_get_size( args ) > 2) {
    char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
    step_list = string_util_alloc_active_list( step_args );
    free( step_args );
  } else
    step_list = int_vector_alloc(1,target_step);

  enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

  int_vector_free( step_list );
  return NULL;
}
Example #3
0
void * enkf_main_export_runpath_file_JOB(void * self, const stringlist_type * args)  {
  enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
  int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
  analysis_config_type * analysis_config  = enkf_main_get_analysis_config(enkf_main);
  analysis_iter_config_type * iter_config = analysis_config_get_iter_config(analysis_config);
  int num_iterations                      = analysis_iter_config_get_num_iterations(iter_config);
  const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
  int_vector_type * realizations          = int_vector_alloc(1, 0);
  int_vector_init_range(realizations, 0, ensemble_size, 1);
  int_vector_type * iterations            = int_vector_alloc(1, 0);


  if (stringlist_get_size(args) > 0) {
    int offset = 0;
    while (true) {
      if (offset == stringlist_get_size( args ))
        break;
      if (0 == strcmp("|" , stringlist_iget( args, offset )))
        break;
       ++offset;
    }

    if (0 != strcmp("*", stringlist_iget(args,0))) {
      char * range_str = stringlist_alloc_joined_substring( args, 0, offset, "");
      string_util_init_value_list(range_str, realizations);
      free(range_str);
    }

    if ((offset < stringlist_get_size(args)) && model_config_runpath_requires_iter(model_config)) {
      if (0 == strcmp("*", stringlist_iget(args, (offset+1))))
        int_vector_init_range(iterations, 0, num_iterations, 1);
      else {
        char * range_str = stringlist_alloc_joined_substring( args, offset+1, stringlist_get_size(args), "");
        string_util_init_value_list(range_str, iterations);
        free(range_str);
       }
    }
  }

  enkf_main_export_runpath_file(enkf_main, realizations, iterations);

  int_vector_free(realizations);
  int_vector_free(iterations);

  return NULL;
}
Example #4
0
static bool_vector_type * alloc_iactive_vector_from_range(const stringlist_type * range, int startindex, int ens_size) {
  bool_vector_type * iactive;
  if (stringlist_get_size(range) > startindex) {
    char * arg_string = stringlist_alloc_joined_substring( range, startindex, stringlist_get_size(range), "");
    iactive = bool_vector_alloc(ens_size, false);
    string_util_update_active_mask( arg_string, iactive );
    free ( arg_string );
  } else {
    iactive = bool_vector_alloc(ens_size, true);
  }
  return iactive;
}
void test_join() {
  const char * elt0 = "AAA";
  const char * elt1 = "BBB";
  const char * elt2 = "CCC";
  const char * elt3 = "DDD";
  const char * elt4 = "EEE";
  const char * elt5 = "FFF";

  stringlist_type * s = stringlist_alloc_new();

  {
    // empty join
    const char* empty_join = stringlist_alloc_joined_string(s, "!!!");
    test_assert_not_NULL(empty_join);
    test_assert_string_equal("", empty_join);
  }

  stringlist_append_copy( s , elt0 );
  stringlist_append_copy( s , elt1 );
  stringlist_append_copy( s , elt2 );

  const char * sep0 = "";
  const char * sep1 = "!!!";
  const char * sep2 = " abc ";

  const char * j0 = stringlist_alloc_joined_string( s, sep0);
  const char * j1 = stringlist_alloc_joined_string( s, sep1);
  const char * j2 = stringlist_alloc_joined_string( s, sep2);

  test_assert_string_equal( j0, "AAABBBCCC");
  test_assert_string_equal( j1, "AAA!!!BBB!!!CCC");
  test_assert_string_equal( j2, "AAA abc BBB abc CCC");

  stringlist_type * s1 = stringlist_alloc_new();
  stringlist_append_copy( s1 , elt0 );
  test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep0));
  test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep1));
  test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep2));

  stringlist_type * sub = stringlist_alloc_new();
  stringlist_append_copy( sub , elt0 );
  stringlist_append_copy( sub , elt1 );
  stringlist_append_copy( sub , elt2 );
  stringlist_append_copy( sub , elt3 );
  stringlist_append_copy( sub , elt4 );
  stringlist_append_copy( sub , elt5 );
  test_assert_string_equal( "CCC:DDD:EEE", stringlist_alloc_joined_substring( sub, 2, 5, ":"));
}
Example #6
0
void * enkf_main_analysis_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs;
  int target_step;
  int_vector_type * step_list;
  bool decrease_ref = false;

  // Argument 0: Which case to write to
  if (stringlist_get_size(args)) {
    const char * target_fs_name = stringlist_iget( args , 0 );
    if (strcmp( target_fs_name , CURRENT_CASE_STRING) == 0)
      target_fs = enkf_main_get_fs( enkf_main );
    else {
      target_fs = enkf_main_mount_alt_fs( enkf_main , target_fs_name , true);
      decrease_ref = true;
    }
  } else
      target_fs = enkf_main_get_fs( enkf_main );
  {


    // Argument 1: The number of the step to write to
    if (stringlist_get_size(args) > 1)
      util_sscanf_int(stringlist_iget( args , 1) , &target_step);
    else
      target_step = 0;

    // Argument 2 - ??: The timesteps to use in the update
    if (stringlist_get_size( args ) > 2) {
      char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
      step_list = string_util_alloc_active_list( step_args );
      free( step_args );
    } else {
      int stride = 1;
      time_map_type * time_map = enkf_fs_get_time_map( enkf_main_get_fs( enkf_main ));
      step_list = enkf_main_update_alloc_step_list( enkf_main , 0 , time_map_get_last_step( time_map ) , stride);
    }

    enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

    int_vector_free( step_list );

    if (decrease_ref)
      enkf_fs_decref( target_fs );
  }
  return NULL;
}
Example #7
0
void site_config_init(site_config_type * site_config , const config_type * config, bool user_config) {
  site_config_add_jobs(site_config , config);
  {
    int i;
    for (i = 0; i < config_get_occurences( config , SETENV_KEY); i++) {
      const stringlist_type * tokens = config_iget_stringlist_ref(config , SETENV_KEY , i);
      const char * var               = stringlist_iget( tokens , 0);
      const char * value             = stringlist_iget( tokens , 1);

      site_config_setenv( site_config , var , value );
    }
    
    for (i=0; i < config_get_occurences( config, UPDATE_PATH_KEY); i++) {
      const stringlist_type * tokens = config_iget_stringlist_ref(config , UPDATE_PATH_KEY , i);
      const char * path              = stringlist_iget( tokens , 0);
      const char * value             = stringlist_iget( tokens , 1);
      
      site_config_update_pathvar( site_config , path , value );
    }
  }
  /* 
     When LSF is used several enviroment variables must be set (by the
     site wide file) - i.e.  the calls to SETENV must come first.
  */
  if (!site_config->user_mode) 
    site_config_create_queue_drivers( site_config );   

  /* 
     Set the umask for all file creation. A value of '0' will ensure
     that all files and directories are created with 'equal rights'
     for everyone - might be handy if you are helping someone... The
     default statoil value is 0022, i.e. write access is removed from
     group and others.  

     The string is supposed to be in OCTAL representation (without any
     prefix characters).
  */
  if (config_item_set(config , UMASK_KEY)) {
    const char * string_mask = config_iget( config , UMASK_KEY , 0 , 0);
    mode_t umask_value;
    if (util_sscanf_octal_int( string_mask , &umask_value))
      site_config_set_umask( site_config , umask_value);
    else
      util_abort("%s: failed to parse:\"%s\" as a valid octal literal \n",__func__ , string_mask);
  }

  if (config_item_set(config , MAX_SUBMIT_KEY)) 
    site_config_set_max_submit( site_config , config_get_value_as_int( config , MAX_SUBMIT_KEY ));
  

  /* LSF options */
  {
    if (config_item_set(config , LSF_QUEUE_KEY))
      site_config_set_lsf_queue( site_config , config_iget( config , LSF_QUEUE_KEY , 0 , 0));
    
    if (config_item_set(config , LSF_RESOURCES_KEY)) {
      char * lsf_resource_request = config_alloc_joined_string(config , LSF_RESOURCES_KEY , " ");
      site_config_set_lsf_request( site_config , lsf_resource_request );
      free( lsf_resource_request );
    }
    
    if (config_item_set(config , MAX_RUNNING_LSF_KEY))
      site_config_set_max_running_lsf( site_config , config_iget_as_int( config , MAX_RUNNING_LSF_KEY , 0 , 0));

    if (config_item_set(config , LSF_SERVER_KEY))
      site_config_set_lsf_server( site_config , config_iget( config , LSF_SERVER_KEY , 0 , 0));
  }


  /* RSH options */
  {
    if (config_item_set( config , RSH_COMMAND_KEY ))
      site_config_set_rsh_command( site_config , config_iget(config , RSH_COMMAND_KEY , 0,0));
    
    if (config_item_set( config , MAX_RUNNING_RSH_KEY))
      site_config_set_max_running_rsh( site_config , config_iget_as_int( config , MAX_RUNNING_RSH_KEY , 0,0));

    /* Parsing the "host1:4" strings. */
    if (user_config) {
      if (config_item_set( config , RSH_HOST_KEY)) {
        stringlist_type * rsh_host_list = config_alloc_complete_stringlist(config , RSH_HOST_KEY);
        int i;
        for (i=0; i < stringlist_get_size( rsh_host_list ); i++) 
          site_config_add_rsh_host_from_string( site_config , stringlist_iget( rsh_host_list , i ) );
        
        stringlist_free( rsh_host_list );
      }
    }
  }

  if (config_item_set( config , QUEUE_SYSTEM_KEY)) {
    job_driver_type driver_type;
    {
      const char * queue_system = config_iget(config , QUEUE_SYSTEM_KEY , 0,0);
      if (strcmp(queue_system , LSF_DRIVER_NAME) == 0) {
        driver_type = LSF_DRIVER;
      } else if (strcmp(queue_system , RSH_DRIVER_NAME) == 0) 
        driver_type = RSH_DRIVER;
      else if (strcmp(queue_system , LOCAL_DRIVER_NAME) == 0) 
        driver_type = LOCAL_DRIVER;
      else {
        util_abort("%s: queue system :%s not recognized \n",__func__ , queue_system);
        driver_type = NULL_DRIVER;
      }
    }
    site_config_set_job_queue__( site_config , driver_type );
  }
  
  /* Parsing local options */
  if (config_item_set( config , MAX_RUNNING_LOCAL_KEY))
    site_config_set_max_running_local( site_config , config_iget_as_int( config , MAX_RUNNING_LOCAL_KEY , 0,0));

  if (config_item_set(config , JOB_SCRIPT_KEY))
    site_config_set_job_script( site_config , config_iget( config , JOB_SCRIPT_KEY , 0 , 0));
  
  if (config_item_set(config , LICENSE_PATH_KEY))
    site_config_set_license_root_path( site_config , config_iget( config , LICENSE_PATH_KEY , 0 , 0));
  
  if (user_config) 
    site_config_install_job_queue( site_config );
  
  /* Setting QUEUE_OPTIONS */
  { 
    int i;
    for (i=0; i < config_get_occurences(config , QUEUE_OPTION_KEY); i++) {
      stringlist_type * tokens   = config_iget_stringlist_ref(config , QUEUE_OPTION_KEY , i);
      const char * driver_name   = stringlist_iget( tokens , 0 );
      const char * option_key    = stringlist_iget( tokens , 1 );
      const char * option_value  = stringlist_alloc_joined_substring( tokens , 2 , stringlist_get_size( tokens ), " ");
      /* 
         If it is desirable to keep the exact number of spaces in the
         option_value it should be quoted with "" in the configuration
         file.
      */
      site_config_set_queue_option( site_config , driver_name , option_key , option_value );
    }
  }
}
Example #8
0
char * stringlist_alloc_joined_string(const stringlist_type * s , const char * sep) {
  return stringlist_alloc_joined_substring( s , 0 , stringlist_get_size( s ) , sep );
}