Be compatible with older version of the parameter file (without is_observation)

This commit is contained in:
Guilhem Lavaux 2013-01-21 21:38:38 -05:00
parent 361ab5b617
commit 64e226c786

View file

@ -1,3 +1,4 @@
#include <cstdlib>
#include <netcdfcpp.h> #include <netcdfcpp.h>
#include <CosmoTool/fortran.hpp> #include <CosmoTool/fortran.hpp>
#include "particleInfo.hpp" #include "particleInfo.hpp"
@ -5,6 +6,34 @@
using namespace std; using namespace std;
using namespace CosmoTool; 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, bool loadParticleInfo(ParticleInfo& info,
const std::string& particles, const std::string& particles,
const std::string& extra_info) const std::string& extra_info)
@ -13,18 +42,19 @@ bool loadParticleInfo(ParticleInfo& info,
int isObservation; int isObservation;
NcFile f_info(extra_info.c_str()); NcFile f_info(extra_info.c_str());
NcError nerr(NcError::verbose_nonfatal);
if (!f_info.is_valid()) if (!f_info.is_valid())
return false; return false;
info.ranges[0][0] = f_info.get_att("range_x_min")->as_double(0); info.ranges[0][0] = retrieve_attr_safe_double<true>(f_info, "range_x_min", 0);
info.ranges[0][1] = f_info.get_att("range_x_max")->as_double(0); info.ranges[0][1] = retrieve_attr_safe_double<true>(f_info, "range_x_max", 0);
info.ranges[1][0] = f_info.get_att("range_y_min")->as_double(0); info.ranges[1][0] = retrieve_attr_safe_double<true>(f_info, "range_y_min", 0);
info.ranges[1][1] = f_info.get_att("range_y_max")->as_double(0); info.ranges[1][1] = retrieve_attr_safe_double<true>(f_info, "range_y_max", 0);
info.ranges[2][0] = f_info.get_att("range_z_min")->as_double(0); info.ranges[2][0] = retrieve_attr_safe_double<true>(f_info, "range_z_min", 0);
info.ranges[2][1] = f_info.get_att("range_z_max")->as_double(0); info.ranges[2][1] = retrieve_attr_safe_double<true>(f_info, "range_z_max", 0);
info.mask_index = f_info.get_att("mask_index")->as_int(0); //PMS info.mask_index = retrieve_attr_safe_int<true>(f_info, "mask_index", 0);
isObservation = f_info.get_att("is_observation")->as_int(0); //PMS isObservation = retrieve_attr_safe_int<false>(f_info, "is_observation", 0);
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
info.length[i] = info.ranges[i][1] - info.ranges[i][0]; info.length[i] = info.ranges[i][1] - info.ranges[i][0];