コード例 #1
0
char * basic_parser_fread_alloc_file_content(const char * filename , const char * quote_set , const char * delete_set , const char * comment_start , const char * comment_end) {
  basic_parser_type * parser = basic_parser_alloc( NULL , quote_set , NULL , delete_set , comment_start , comment_end);
  char * buffer              = util_fread_alloc_file_content( filename , NULL);
  
  basic_parser_strip_buffer( parser , &buffer );
  basic_parser_free( parser );
  return buffer;
}
コード例 #2
0
ファイル: sched_file.c プロジェクト: YingfangZhou/ert
static stringlist_type * sched_file_tokenize( const char * filename ) {
  stringlist_type  * token_list;
  basic_parser_type     * parser    = basic_parser_alloc(" \t"  ,      /* Splitters */
                                             "\'\"" ,      /* Quoters   */
                                             "\n"   ,      /* Specials - splitters which will be kept. */  
                                             "\r"   ,      /* Delete set - these are just deleted. */
                                             "--"   ,      /* Comment start */
                                             "\n");        /* Comment end */  
  bool strip_quote_marks = false;
  token_list             = basic_parser_tokenize_file( parser , filename , strip_quote_marks  );
  basic_parser_free( parser );
  
  return token_list;
}
コード例 #3
0
ファイル: ecl_util.c プロジェクト: atgeirr/ert
ert_ecl_unit_enum ecl_util_get_unit_set(const char * data_file) {
  ert_ecl_unit_enum units = ECL_METRIC_UNITS;
  basic_parser_type * parser = basic_parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");

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

  basic_parser_free( parser );
  fclose(stream);
  return units;
}
コード例 #4
0
ファイル: ecl_util.c プロジェクト: atgeirr/ert
int ecl_util_get_num_cpu(const char * data_file) {
  int num_cpu = 1;
  basic_parser_type * parser = basic_parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");

  if (basic_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 (basic_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);
  }

  basic_parser_free( parser );
  fclose(stream);
  return num_cpu;
}
コード例 #5
0
ファイル: ecl_config.c プロジェクト: Ensembles/ert
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");
    basic_parser_type * parser = basic_parser_alloc(NULL, NULL, NULL, NULL, "--", "\n");
    char * init_tag = enkf_util_alloc_tagged_string("INIT");
    
    ecl_config->can_restart = basic_parser_fseek_string(parser, stream, init_tag, false, true);
    
    free(init_tag);
    basic_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);
  ecl_config->unit_system = ecl_util_get_unit_set(ecl_config->data_file);
}
コード例 #6
0
ファイル: ecl_util.c プロジェクト: atgeirr/ert
time_t ecl_util_get_start_date(const char * data_file) {
  basic_parser_type * parser = basic_parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  time_t start_date  = -1;
  FILE * stream      = util_fopen(data_file , "r");
  char * buffer;

  if (!basic_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 (!basic_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 = basic_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 );
  basic_parser_free( parser );
  fclose(stream);

  return start_date;
}