static ecl_sum_tstep_type * ecl_sum_tstep_alloc( int report_step , int ministep_nr , const ecl_smspec_type * smspec) { ecl_sum_tstep_type * tstep = util_malloc( sizeof * tstep ); UTIL_TYPE_ID_INIT( tstep , ECL_SUM_TSTEP_ID); tstep->smspec = smspec; tstep->report_step = report_step; tstep->ministep = ministep_nr; tstep->data_size = ecl_smspec_get_params_size( smspec ); tstep->data = util_calloc( tstep->data_size , sizeof * tstep->data ); return tstep; }
ecl_sum_tstep_type * ecl_sum_tstep_alloc_remap_copy( const ecl_sum_tstep_type * src , const ecl_smspec_type * new_smspec, float default_value , const int * params_map) { int params_size = ecl_smspec_get_params_size( new_smspec ); ecl_sum_tstep_type * target = util_alloc_copy(src , sizeof * src ); target->smspec = new_smspec; target->data = util_malloc( params_size * sizeof * target->data ); target->data_size = params_size; for (int i=0; i < params_size; i++) { if (params_map[i] >= 0) target->data[i] = src->data[ params_map[i] ]; else target->data[i] = default_value; } return target; }
ecl_sum_tstep_type * ecl_sum_tstep_alloc_from_file( int report_step , int ministep_nr , const ecl_kw_type * params_kw , const char * src_file , const ecl_smspec_type * smspec) { int data_size = ecl_kw_get_size( params_kw ); if (data_size == ecl_smspec_get_params_size( smspec )) { ecl_sum_tstep_type * ministep = ecl_sum_tstep_alloc( report_step , ministep_nr , smspec); ecl_kw_get_memcpy_data( params_kw , ministep->data ); ecl_sum_tstep_set_time_info( ministep , smspec ); return ministep; } else { /* This is actually a fatal error / bug; the difference in smspec header structure should have been detected already in the ecl_smspec_load_restart() function and the restart case discarded. */ fprintf(stderr , "** Warning size mismatch between timestep loaded from:%s and header:%s - timestep discarded.\n" , src_file , ecl_smspec_get_header_file( smspec )); return NULL; } }