Beispiel #1
0
void test_wrapper( const char * filename ) {
  FILE * stream = util_fopen( filename , "r");
  fortio_type * fortio = fortio_alloc_FILE_wrapper( filename , false , false , stream );
  test_assert_not_NULL( fortio );
  test_assert_false( fortio_fclose_stream( fortio ));
  test_assert_false( fortio_fopen_stream( fortio ));
  test_assert_true( fortio_stream_is_open( fortio ));
  fortio_free_FILE_wrapper( fortio );
  fclose( stream );
}
void ecl_kw_fprintf_grdecl__(const ecl_kw_type * ecl_kw , const char * special_header , FILE * stream) { 
  if (special_header)
    fprintf(stream,"%s\n" , special_header); 
  else 
    fprintf(stream,"%s\n" , ecl_kw_get_header(ecl_kw));

  {
    fortio_type * fortio = fortio_alloc_FILE_wrapper(NULL , false , true , stream);   /* Endian flip should *NOT* be used */
    ecl_kw_fwrite_data(ecl_kw , fortio);
    fortio_free_FILE_wrapper( fortio );
  }
  fprintf(stream,"/\n"); 
}
Beispiel #3
0
/**
This function takes in a filename and tries to guess the type of the
file. It can determine the following three types of files:

  ecl_kw_file: This is a file containg ecl_kw instances in the form found
     in eclipse restart files.

  rms_roff_file: An rms roff file - obviously.

  ecl_grdecl_file: This is a file containing a parameter of the form
     found in eclipse grid declaration files, i.e. formatted, one
     keyword and all elements (active and not).

  The latter test is the weakest. Observe that the function will
  happily return unkown_file if none of these types are recognized,
  i.e. it is *essential* to check the return value.

*/
field_file_format_type field_config_guess_file_type(const char * filename ) {
    bool fmt_file = util_fmt_bit8(filename );
    FILE * stream = util_fopen(filename , "r");
    fortio_type * fortio = fortio_alloc_FILE_wrapper(NULL , ECL_ENDIAN_FLIP , fmt_file , false , stream);
    field_file_format_type file_type;

    if (ecl_kw_is_kw_file(fortio))
        file_type = ECL_KW_FILE;
    else if (rms_file_is_roff(stream))
        file_type = RMS_ROFF_FILE;
    else if (ecl_kw_is_grdecl_file(stream))  /* This is the weakest test - and should be last in a cascading if / else hierarchy. */
        file_type = ECL_GRDECL_FILE;
    else
        file_type = UNDEFINED_FORMAT;              /* MUST Check on this return value */

    fortio_free_FILE_wrapper( fortio );
    fclose(stream);
    return file_type;
}