Beispiel #1
0
ecl_unit_enum ecl_util_get_unit_set(const char * data_file) {
  ecl_unit_enum units = ECL_METRIC_UNITS;
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");

  if (parser_fseek_string( parser , stream , "FIELD" , true , true)) {  /* Seeks case insensitive. */
    units = ECL_FIELD_UNITS;
  } else if (parser_fseek_string( parser , stream , "LAB" , true , true)) {  /* Seeks case insensitive. */
    units = ECL_LAB_UNITS;
  }

  parser_free( parser );
  fclose(stream);
  return units;
}
Beispiel #2
0
int ecl_util_get_num_cpu(const char * data_file) { 
  int num_cpu = 1; 
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");
  
  if (parser_fseek_string( parser , stream , "PARALLEL" , true , true)) {  /* Seeks case insensitive. */
    num_cpu = ecl_util_get_num_parallel_cpu__(parser, stream, data_file); 
  } else if (parser_fseek_string( parser , stream , "SLAVES" , true , true)) {  /* Seeks case insensitive. */
    num_cpu = ecl_util_get_num_slave_cpu__(parser, stream, data_file) + 1; 
    fprintf(stderr, "Information: \"SLAVES\" option found, returning %d number of CPUs", num_cpu); 
  }

  parser_free( parser );
  fclose(stream);
  return num_cpu;
}
Beispiel #3
0
static int ecl_util_get_num_slave_cpu__(parser_type* parser, FILE* stream, const char * data_file) {
  int num_cpu = 0;
  int linecount = 0; 

  parser_fseek_string( parser , stream , "\n" , true , true);  /* Go to next line after the SLAVES keyword*/

  while (true) {
    char * buffer = util_fscanf_alloc_line( stream , NULL);
    ++linecount; 
    if (linecount > 10) 
      util_abort("%s: Did not find ending \"/\" character after SLAVES keyword, aborting \n", __func__);

    {
      stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
      if (stringlist_get_size(tokens) > 0 ) {
        
        const char * first_item = stringlist_iget(tokens, 0);
        
        if (first_item[0] == '/') {
          break; 
        }
        else 
          ++num_cpu;
      }
      stringlist_free( tokens );
    }
      
    free( buffer );
  } 
  
  if (0 == num_cpu)
    util_abort("%s: Did not any CPUs after SLAVES keyword, aborting \n", __func__);
  return num_cpu; 
}
Beispiel #4
0
static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, const char * data_file) {
  int num_cpu = 1;
  char * buffer;  
  long int start_pos = util_ftell( stream );
  int buffer_size;

  /* Look for terminating '/' */
  if (!parser_fseek_string( parser , stream , "/" , false , true))
    util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file);

  buffer_size = (util_ftell(stream) - start_pos)  ;
  buffer = util_calloc( buffer_size + 1  , sizeof * buffer );
  util_fseek( stream , start_pos , SEEK_SET);
  util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
  buffer[buffer_size] = '\0';

  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    
    if (stringlist_get_size( tokens ) > 0) {
      const char * num_cpu_string = stringlist_iget( tokens , 0 );
      if (!util_sscanf_int( num_cpu_string , &num_cpu))
        fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU\n",num_cpu_string);
    } else
      fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU\n");

    stringlist_free( tokens );
  }  
  free( buffer );
  return num_cpu; 
}
Beispiel #5
0
time_t ecl_util_get_start_date(const char * data_file) { 
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  time_t start_date  = -1;
  FILE * stream      = util_fopen(data_file , "r");
  char * buffer;
  
  if (!parser_fseek_string( parser , stream , "START" , true , true))   /* Seeks case insensitive. */
    util_abort("%s: sorry - could not find START in DATA file %s \n",__func__ , data_file);
  
  {
    long int start_pos = util_ftell( stream );
    int buffer_size;

    /* Look for terminating '/' */
    if (!parser_fseek_string( parser , stream , "/" , false , true))
      util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file);
    
    buffer_size = (util_ftell(stream) - start_pos)  ;
    buffer = util_calloc( buffer_size + 1 , sizeof * buffer  );
    util_fseek( stream , start_pos , SEEK_SET);
    util_fread( buffer , sizeof * buffer , buffer_size ,stream ,  __func__);
    buffer[buffer_size] = '\0';
  }
  
  
  {
    stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true );
    int day, year, month_nr;
    if ( util_sscanf_int( stringlist_iget( tokens , 0 ) , &day)   &&   util_sscanf_int( stringlist_iget(tokens , 2) , &year)) {
      month_nr   = ecl_util_get_month_nr(stringlist_iget( tokens , 1));
      start_date = ecl_util_make_date(day , month_nr , year );
    } else
      util_abort("%s: failed to parse DAY MONTH YEAR from : \"%s\" \n",__func__ , buffer);
    stringlist_free( tokens );
  }
  
  free( buffer );
  parser_free( parser );
  fclose(stream);
  
  return start_date;
}
Beispiel #6
0
void ecl_config_set_data_file( ecl_config_type * ecl_config , const char * data_file) {
  ecl_config->data_file = util_realloc_string_copy( ecl_config->data_file , data_file );
  {
    FILE * stream        = util_fopen( ecl_config->data_file , "r");
    parser_type * parser = parser_alloc(NULL , NULL , NULL , NULL , "--" , "\n" );
    char * init_tag      = enkf_util_alloc_tagged_string( "INIT" );
    
    ecl_config->can_restart = parser_fseek_string( parser , stream , init_tag , false , true ); 
    
    free( init_tag );
    parser_free( parser );
    fclose( stream );
  }
  ecl_config->start_date = ecl_util_get_start_date( ecl_config->data_file );
  ecl_config->num_cpu    = ecl_util_get_num_cpu( ecl_config->data_file );
}