00001 #ifndef CCTBX_ELTBX_FP_FDP_H
00002 #define CCTBX_ELTBX_FP_FDP_H
00003
00004 #include <cctbx/eltbx/basic.h>
00005 #include <complex>
00006 #include <ctype.h>
00007
00008 namespace cctbx { namespace eltbx {
00009
00010 namespace anomalous {
00011
00012 struct e_fp_fdp
00013 {
00014 float e;
00015 float fp;
00016 float fdp;
00017 };
00018
00019 struct label_z_e_fp_fdp
00020 {
00021 const char* label;
00022 int z;
00023 const e_fp_fdp* data;
00024 };
00025
00026 struct iterator_init_tag {};
00027
00028 }
00029
00031 static const float fp_fdp_undefined = -9999.00;
00032
00034 class fp_fdp
00035 {
00036 public:
00038 explicit
00039 fp_fdp(float fp = fp_fdp_undefined,
00040 float fdp = fp_fdp_undefined)
00041 : fp_(fp), fdp_(fdp)
00042 {}
00043
00045 bool is_valid_fp() const { return fp_ != fp_fdp_undefined; }
00046
00048 bool is_valid_fdp() const { return fdp_ != fp_fdp_undefined; }
00049
00051 bool is_valid() const { return is_valid_fp() && is_valid_fdp(); }
00052
00054 float fp() const { return fp_; }
00055
00057 float fdp() const { return fdp_; }
00058
00060
00062 std::complex<float> as_complex_float() const
00063 {
00064 return std::complex<float>(fp_, fdp_);
00065 }
00066
00068
00070 std::complex<double> as_complex_double() const
00071 {
00072 return std::complex<double>(fp_, fdp_);
00073 }
00074
00075 private:
00076 float fp_;
00077 float fdp_;
00078 };
00079
00080 namespace anomalous {
00081
00082 template <typename TableType>
00083 const TableType*
00084 find_entry(const TableType* tables,
00085 std::string const& work_label,
00086 bool exact,
00087 bool exception_if_no_match)
00088 {
00089
00090 std::string wl = work_label;
00091 if (wl == "D") wl = "H";
00092 int m = 0;
00093 const TableType* m_entry = 0;
00094 for (const TableType* entry = tables; entry->label; entry++)
00095 {
00096 int i = basic::match_labels(wl, entry->label);
00097 if (i < 0) return entry;
00098 if (i > m && !isdigit(entry->label[i - 1])) {
00099 m = i;
00100 m_entry = entry;
00101 }
00102 }
00103 if (exception_if_no_match && (exact || !m_entry)) {
00104 throw error(
00105 "Unknown scattering type label: " + std::string(work_label));
00106 }
00107 return m_entry;
00108 }
00109
00110 fp_fdp interpolate(const label_z_e_fp_fdp* m_label_z_e_fp_fdp,
00111 double energy);
00112
00113 }
00114
00115 }}
00116
00117 #endif // CCTBX_ELTBX_FP_FDP_H