bool fortio_is_fortio_file(fortio_type * fortio) { offset_type init_pos = fortio_ftell(fortio); int elm_read; bool is_fortio_file = false; elm_read = fread(&fortio->active_header , sizeof(fortio->active_header) , 1 , fortio->stream); if (elm_read == 1) { int trailer; if (fortio->endian_flip_header) util_endian_flip_vector(&fortio->active_header , sizeof fortio->active_header , 1); if (fortio_fseek(fortio , (offset_type) fortio->active_header , SEEK_CUR) == 0) { if (fread(&trailer , sizeof(fortio->active_header) , 1 , fortio->stream) == 1) { if (fortio->endian_flip_header) util_endian_flip_vector(&trailer , sizeof trailer , 1); if (trailer == fortio->active_header) is_fortio_file = true; } } } fortio_fseek(fortio , init_pos , SEEK_SET); return is_fortio_file; }
static void ecl_sum_data_fwrite_unified_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , int report_step) { char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 ); fortio_type * fortio = fortio_open_readwrite( filename , fmt_case , ECL_ENDIAN_FLIP ); int current_step = 1; if (report_step > 1) { while (true) { if (ecl_kw_fseek_kw( SEQHDR_KW , false , false , fortio )) { if (current_step == report_step) break; current_step++; } else { current_step++; break; } } } if (current_step == report_step) { // We found the position: long size = fortio_ftell( fortio ); util_ftruncate( fortio_get_FILE( fortio ) , size ); ecl_sum_data_fwrite_report__( data , report_step , fortio ); } else util_abort("%s: hmm could not locate the position for report step:%d in summary file:%s \n",__func__ , report_step , filename); fortio_fclose( fortio ); free( filename ); }