From ae6c38854685706aa3f5474e8a2b48a57278c959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Tue, 6 Nov 2012 20:45:49 +0100 Subject: [PATCH] Fix incorrect size in ecl_kw_alloc() call. Also, add more checks to ensure sanity. --- opm/core/utility/writeECLData.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/opm/core/utility/writeECLData.cpp b/opm/core/utility/writeECLData.cpp index b5120ee5..6baadb2a 100644 --- a/opm/core/utility/writeECLData.cpp +++ b/opm/core/utility/writeECLData.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -44,8 +45,12 @@ namespace Opm const std::vector * data , int offset , int stride ) { - - ecl_kw_type * ecl_kw = ecl_kw_alloc( kw_name.c_str() , data->size() / stride , ECL_FLOAT_TYPE ); + const int ecl_data_size = grid.cartdims[0]*grid.cartdims[1]*grid.cartdims[2]; + if (ecl_data_size < int(data->size()) / stride) { + THROW("Logical cartesian size claimed to be " << ecl_data_size << ", while active data size is " << data->size() + << "\n --- check if the grid is really a corner-point grid or other logical cartesian grid."); + } + ecl_kw_type * ecl_kw = ecl_kw_alloc( kw_name.c_str() , ecl_data_size , ECL_FLOAT_TYPE ); if (grid.global_cell == NULL) { for (int i=0; i < grid.number_of_cells; i++) ecl_kw_iset_float( ecl_kw , i , (*data)[i*stride + offset]); @@ -97,6 +102,9 @@ namespace Opm { DataMap::const_iterator i = data.find("saturation"); if (i != data.end()) { + if (int(i->second->size()) != 2 * grid.number_of_cells) { + THROW("writeECLData() requires saturation field to have two phases."); + } ecl_kw_type * swat_kw = ecl_kw_wrapper( grid , "SWAT" , i->second , 0 , 2); ecl_rst_file_add_kw( rst_file , swat_kw ); ecl_kw_free( swat_kw );