예제 #1
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;
}
예제 #2
0
파일: ecl_config.c 프로젝트: Ensembles/ert
void ecl_config_set_init_section(ecl_config_type * ecl_config, const char * input_init_section) {
  if (ecl_config->can_restart)  { 
    /* The <INIT> tag is set. */
    ecl_config->input_init_section = util_realloc_string_copy(ecl_config->input_init_section, input_init_section); /* input_init_section = path/to/init_section         */
    if (util_file_exists(ecl_config->input_init_section))
    { /* init_section       = $CWD/path/to/init_section */
      util_safe_free(ecl_config->init_section);
      ecl_config->init_section = util_alloc_realpath(input_init_section);
    }
    else
    {
      char * path;

      util_alloc_file_components(ecl_config->input_init_section, &path, NULL, NULL );
      if (path != NULL )
        fprintf(stderr,
            "** Warning: %s: When INIT_SECTION:%s points to a non-existing file - you can not have any path components.\n",
            __func__, input_init_section);
      else
        ecl_config->init_section = util_alloc_string_copy(input_init_section);

      util_safe_free(path);
    }
  }
  else
    /* 
       The <INIT> tag is not set - we can not utilize the
       input_init_section info, and we just ignore it.
     */
    fprintf(stderr,
        "** Warning: <INIT> tag was not found in datafile - can not utilize INIT_SECTION keyword - ignored.\n");
}
예제 #3
0
void site_config_set_job_script( site_config_type * site_config , const char * job_script ) {
  char * job_script_full_path = util_alloc_realpath( job_script );
  {
    site_config->job_script = util_realloc_string_copy( site_config->job_script , job_script_full_path );
    if (!site_config->user_mode) 
      site_config->job_script_site = util_realloc_string_copy( site_config->job_script_site , site_config->job_script );
  }
  free( job_script_full_path );
}
예제 #4
0
파일: main.c 프로젝트: pgdr/ert
/*
  GIT_COMMIT and COMPILE_TIME_STAMP are env variables set by the
  makefile. Will exit if the config file does not exist.
*/
void enkf_welcome(const char * config_file) {
  if (util_file_exists(config_file)) {
    char * abs_path              = util_alloc_realpath(config_file);
    char * config_file_msg       = util_alloc_sprintf("Configuration file...: %s \n",abs_path);

    /* This will be printed if/when util_abort() is called on a later stage. */
    /* The svn_version and compile_time are added with the functione enkf_main_init_debug(). */
    util_abort_append_version_info(config_file_msg);

    free(config_file_msg);
    free(abs_path);
  } else util_exit(" ** Sorry: can not locate configuration file: %s \n\n", config_file);
}
예제 #5
0
파일: site_config.c 프로젝트: edbru/ert
bool site_config_set_job_script(site_config_type * site_config, const char * job_script) {
  if (util_is_executable(job_script)) {
    char * job_script_full_path = util_alloc_realpath(job_script);
    {
      site_config->job_script = util_realloc_string_copy(site_config->job_script, job_script_full_path);
      if (!site_config->user_mode)
        site_config->job_script_site = util_realloc_string_copy(site_config->job_script_site, site_config->job_script);
    }
    free(job_script_full_path);
    return true;
  } else
    return false;
}
예제 #6
0
파일: main.c 프로젝트: pgdr/ert
int main (int argc, char ** argv) {
  text_splash();
  init_debug(argv[0]);
  printf("\n");
  printf("Documentation : %s \n","http://ert.nr.no");
  printf("git commit    : %s \n",ert_version_get_git_commit( ));
  printf("compile time  : %s \n",ert_version_get_build_time( ));
  printf("site config   : %s \n", site_config_get_location());

  enkf_main_install_SIGNALS();                     /* Signals common to both tui and gui. */
  signal(SIGINT, util_abort_signal);              /* Control C - tui only.               */
  if (argc < 2) {
    enkf_usage();
    exit(1);
  } else {
    const char * model_config_file = argv[1];
    stringlist_type * workflow_list = stringlist_alloc_new();

    parse_workflows(argc, argv, workflow_list);
    if (!(util_entry_readable(model_config_file) && util_is_file(model_config_file)))
      util_exit("Can not read file %s - exiting \n", model_config_file);

    {
      char * abs_config = util_alloc_realpath(model_config_file);
      printf("model config  : %s \n\n", abs_config);
      free(abs_config);
    }
    enkf_welcome(model_config_file);
    {
      res_config_type * res_config = res_config_alloc_load(model_config_file);
      util_chdir( res_config_get_config_directory( res_config ));
      {
        enkf_main_type * enkf_main = enkf_main_alloc(res_config, true, true);
        enkf_main_run_workflows(enkf_main, workflow_list);
        enkf_tui_main_menu(enkf_main);
        enkf_main_free(enkf_main);
        res_config_free(res_config);
      }
    }

    stringlist_free(workflow_list);
    util_abort_free_version_info(); /* No f*****g leaks ... */
  }
  exit(0);
}
예제 #7
0
void site_config_set_license_root_path( site_config_type * site_config , const char * license_root_path) {
  util_make_path( license_root_path );
  {
    char * full_license_root_path = util_alloc_realpath( license_root_path );
    {
      /**
         Appending /user/pid to the license root path. Everything
         including the pid is removed when exiting (gracefully ...).
         
         Dangling license directories after a crash can just be removed.
      */
      site_config->license_root_path   = util_realloc_string_copy( site_config->license_root_path , full_license_root_path );
      site_config->__license_root_path = util_realloc_sprintf(site_config->__license_root_path , "%s%c%s%c%d" , full_license_root_path , UTIL_PATH_SEP_CHAR , getenv("USER") , UTIL_PATH_SEP_CHAR , getpid());
      
      if (!site_config->user_mode)
        site_config->license_root_path_site = util_realloc_string_copy( site_config->license_root_path_site , full_license_root_path );
    }
    free( full_license_root_path );
  }
}
예제 #8
0
void ecl_config_set_init_section( ecl_config_type * ecl_config , const char * input_init_section ) {
  /* The semantic regarding INIT_SECTION is as follows:
  
       1. If the INIT_SECTION points to an existing file - the
          ecl_config->input_init_section is set to the absolute path of
          this file.

       2. If the INIT_SECTION points to a not existing file:

          a. We assert that INIT_SECTION points to a pure filename,
             i.e. /some/path/which/does/not/exist is NOT accepted. In
             the case the input argument contain a path a error message
             will be printed on stderr and the ->init_section will not
             be set.
          b. The ecl_config->input_init_section is set to point to this
             file.
          c. WE TRUST THE USER TO SUPPLY CONTENT (THROUGH SOME FUNKY
             FORWARD MODEL) IN THE RUNPATH. This can unfortunately not
             be checked/verified before the ECLIPSE simulation fails.


     The INIT_SECTION keyword and <INIT> in the datafile (checked with
     ecl_config->can_restart) interplay as follows: 


     CASE   |   INIT_SECTION  |  <INIT>    | OK ?
     ---------------------------------------------
     0      |   Present       | Present    |  Yes 
     1      |   Not Present   | Present    |  No    
     2      |   Present       | Not present|  No
     3      |   Not Present   | Not present|  Yes
     ---------------------------------------------


     Case 0: This is the most flexible case, which can do arbitrary
        restart.

     Case 1: In this case the datafile will contain a <INIT> tag, we
        we do not have the info to replace that tag with for
        initialisation, and ECLIPSE will fail. Strictly speaking this
        case can actually restart, but that is not enough - we let
        this case fail hard.

     Case 2: We have some INIT_SECTION infor, but no tag in he
        datafile to update. If the datafile has embedded
        initialisation info this case will work for init; but it is
        logically flawed, and not accepted. Currently only a warning.

     Case 3: This case has just the right amount of information for
        initialisation, but it is 'consistently unable' to restart.
     
  */
  if (ecl_config->can_restart) {  /* The <INIT> tag is set. */
    ecl_config->input_init_section = util_realloc_string_copy( ecl_config->input_init_section , input_init_section );   /* input_init_section = path/to/init_section         */
    if (util_file_exists( ecl_config->input_init_section )) {                                                           /* init_section       = $CWD/path/to/init_section */ 
      util_safe_free( ecl_config->init_section );
      ecl_config->init_section = util_alloc_realpath(input_init_section);
    } else {
      char * path;
      
      util_alloc_file_components( ecl_config->input_init_section , &path , NULL , NULL );
      if (path != NULL) 
        fprintf(stderr,"** Warning: %s: When INIT_SECTION:%s points to a non-existing file - you can not have any path components.\n",__func__ , input_init_section);
      else 
        ecl_config->init_section = util_alloc_string_copy(input_init_section);
      
      util_safe_free( path );
    }
  } else
    /* 
       The <INIT> tag is not set - we can not utilize the
       input_init_section info, and we just ignore it.
    */
    fprintf(stderr,"** Warning: <INIT> tag was not found in datafile - can not utilize INIT_SECTION keyword - ignored.\n");
}
예제 #9
0
job_queue_node_type * job_queue_node_alloc( const char * job_name ,
                                            const char * run_path ,
                                            const char * run_cmd ,
                                            int argc ,
                                            const char ** argv,
                                            int num_cpu,
                                            const char * ok_file,
                                            const char * exit_file,
                                            job_callback_ftype * done_callback,
                                            job_callback_ftype * retry_callback,
                                            job_callback_ftype * exit_callback,
                                            void * callback_arg) {

  if (util_is_directory( run_path )) {
    job_queue_node_type * node = util_malloc(sizeof * node );

    UTIL_TYPE_ID_INIT( node , JOB_QUEUE_NODE_TYPE_ID );
    {
      /* The data initialized in this block should *NEVER* change. */
      node->job_name       = util_alloc_string_copy( job_name );

      if (util_is_abs_path(run_path))
        node->run_path = util_alloc_string_copy( run_path );
      else
        node->run_path = util_alloc_realpath( run_path );

      node->run_cmd        = util_alloc_string_copy( run_cmd );
      node->argc           = argc;
      node->argv           = util_alloc_stringlist_copy( argv , argc );
      node->num_cpu        = num_cpu;

      if (ok_file)
        node->ok_file = util_alloc_filename(node->run_path , ok_file , NULL);
      else
        node->ok_file = NULL;

      if (exit_file)
        node->exit_file = util_alloc_filename(node->run_path , exit_file , NULL);
      else
        node->exit_file = NULL;

      node->exit_callback  = exit_callback;
      node->retry_callback = retry_callback;
      node->done_callback  = done_callback;
      node->callback_arg   = callback_arg;
    }
    {
      node->error_reason   = NULL;
      node->stderr_capture = NULL;
      node->stderr_file    = NULL;
      node->failed_job     = NULL;
    }
    {
      node->job_status     = JOB_QUEUE_NOT_ACTIVE;
      node->queue_index    = INVALID_QUEUE_INDEX;
      node->submit_attempt = 0;
      node->job_data       = NULL;                                    /* The allocation is run in single thread mode - we assume. */
      node->sim_start      = 0;
      node->sim_end        = 0;
      node->submit_time    = time( NULL );
    }

    pthread_mutex_init( &node->data_mutex , NULL );
    return node;
  } else
    return NULL;
}