mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 23:31:12 +00:00
Be compatible with older version of the parameter file (without is_observation)
This commit is contained in:
parent
361ab5b617
commit
64e226c786
1 changed files with 38 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
#include <cstdlib>
|
||||
#include <netcdfcpp.h>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "particleInfo.hpp"
|
||||
|
@ -5,6 +6,34 @@
|
|||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
template<bool failure>
|
||||
double retrieve_attr_safe_double(NcFile& f, const char *name, double defval)
|
||||
{
|
||||
NcAtt *a = f.get_att(name);
|
||||
if (a == 0)
|
||||
{
|
||||
if (failure)
|
||||
abort();
|
||||
return defval;
|
||||
}
|
||||
return a->as_double(0);
|
||||
}
|
||||
|
||||
template<bool failure>
|
||||
int retrieve_attr_safe_int(NcFile& f, const char *name, int defval)
|
||||
{
|
||||
NcAtt *a = f.get_att(name);
|
||||
if (a == 0)
|
||||
{
|
||||
if (failure)
|
||||
abort();
|
||||
return defval;
|
||||
}
|
||||
return a->as_int(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool loadParticleInfo(ParticleInfo& info,
|
||||
const std::string& particles,
|
||||
const std::string& extra_info)
|
||||
|
@ -13,18 +42,19 @@ bool loadParticleInfo(ParticleInfo& info,
|
|||
int isObservation;
|
||||
|
||||
NcFile f_info(extra_info.c_str());
|
||||
NcError nerr(NcError::verbose_nonfatal);
|
||||
|
||||
if (!f_info.is_valid())
|
||||
return false;
|
||||
|
||||
info.ranges[0][0] = f_info.get_att("range_x_min")->as_double(0);
|
||||
info.ranges[0][1] = f_info.get_att("range_x_max")->as_double(0);
|
||||
info.ranges[1][0] = f_info.get_att("range_y_min")->as_double(0);
|
||||
info.ranges[1][1] = f_info.get_att("range_y_max")->as_double(0);
|
||||
info.ranges[2][0] = f_info.get_att("range_z_min")->as_double(0);
|
||||
info.ranges[2][1] = f_info.get_att("range_z_max")->as_double(0);
|
||||
info.mask_index = f_info.get_att("mask_index")->as_int(0); //PMS
|
||||
isObservation = f_info.get_att("is_observation")->as_int(0); //PMS
|
||||
info.ranges[0][0] = retrieve_attr_safe_double<true>(f_info, "range_x_min", 0);
|
||||
info.ranges[0][1] = retrieve_attr_safe_double<true>(f_info, "range_x_max", 0);
|
||||
info.ranges[1][0] = retrieve_attr_safe_double<true>(f_info, "range_y_min", 0);
|
||||
info.ranges[1][1] = retrieve_attr_safe_double<true>(f_info, "range_y_max", 0);
|
||||
info.ranges[2][0] = retrieve_attr_safe_double<true>(f_info, "range_z_min", 0);
|
||||
info.ranges[2][1] = retrieve_attr_safe_double<true>(f_info, "range_z_max", 0);
|
||||
info.mask_index = retrieve_attr_safe_int<true>(f_info, "mask_index", 0);
|
||||
isObservation = retrieve_attr_safe_int<false>(f_info, "is_observation", 0);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
info.length[i] = info.ranges[i][1] - info.ranges[i][0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue