void test_truncated() { test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" ); { ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL); ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS ); ecl_grid_free( grid ); } { ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 ); test_assert_true( ecl_file_is_instance( ecl_file ) ); ecl_file_close( ecl_file ); } { offset_type file_size = util_file_size( "TEST.EGRID"); FILE * stream = util_fopen("TEST.EGRID" , "r+"); util_ftruncate( stream , file_size / 2 ); fclose( stream ); } { ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 ); test_assert_NULL( ecl_file ); } test_work_area_free( work_area ); }
void EclipseIO::Impl::writeEGRIDFile( const NNC& nnc ) const { const auto& ioConfig = this->es.getIOConfig(); std::string egridFile( ERT::EclFilename( this->outputDir, this->baseName, ECL_EGRID_FILE, ioConfig.getFMTOUT() )); { int idx = 0; auto* ecl_grid = const_cast< ecl_grid_type* >( this->grid.c_ptr() ); for (const NNCdata& n : nnc.nncdata()) ecl_grid_add_self_nnc( ecl_grid, n.cell1, n.cell2, idx++); ecl_grid_fwrite_EGRID2(ecl_grid, egridFile.c_str(), this->es.getDeckUnitSystem().getEclType() ); } }
int main(int argc, char ** argv) { if (argc != 5) { fprintf(stderr,"%s: basename nx ny nz \n",argv[0]); exit(1); } { const char * base_input = argv[1]; int nx = atoi(argv[2]); int ny = atoi(argv[3]); int nz = atoi(argv[4]); char * path , *basename; ecl_grid_type * ecl_grid; util_alloc_file_components( base_input , &path , &basename , NULL ); ecl_grid = ecl_grid_alloc_rectangular(nx,ny,nz , 1 ,1 ,1 , NULL ); { char * EGRID_file = util_alloc_filename( path , basename , "EGRID"); printf("Writing file: %s ...",EGRID_file); fflush(stdout); ecl_grid_fwrite_EGRID2( ecl_grid , EGRID_file, ERT_ECL_METRIC_UNITS); free( EGRID_file ); } { char * grdecl_file = util_alloc_filename( path , basename , "grdecl"); FILE * stream = util_fopen( grdecl_file , "w"); printf("\nWriting file: %s ...",grdecl_file); fflush(stdout); ecl_grid_fprintf_grdecl( ecl_grid , stream ); fclose( stream ); free( grdecl_file ); printf("\n"); } free( basename ); util_safe_free( path ); ecl_grid_free( ecl_grid ); } }