00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef CLIPPER_HKL_DATATYPES
00046 #define CLIPPER_HKL_DATATYPES
00047
00048 #include <complex>
00049 #include "hkl_data.h"
00050
00051
00052 namespace clipper
00053 {
00054
00055
00056
00057
00058 namespace datatypes
00059 {
00060
00062
00065 template<class dtype> class I_sigI : private Datatype_base
00066 {
00067 public:
00068 I_sigI() { Util::set_null(I_); Util::set_null(sigI_); }
00069 I_sigI( const dtype& I, const dtype& sigI ) : I_(I), sigI_(sigI) {}
00070 void set_null() { Util::set_null(I_); Util::set_null(sigI_); }
00071 static String type() { return "I_sigI"; }
00072 void friedel() {}
00073 void shift_phase(const ftype& dphi) {}
00074 bool missing() const { return (Util::is_nan(I_) || Util::is_nan(sigI_)); }
00075 static int data_size() { return 2; }
00076 static String data_names() { return "I sigI"; }
00077 void data_export( xtype array[] ) const
00078 { array[0] = I(); array[1] = sigI(); }
00079 void data_import( const xtype array[] )
00080 { I() = array[0]; sigI() = array[1]; }
00082 void scale(const ftype& s) { I_ *= (s*s); sigI_ *= (s*s); }
00083
00084 const dtype& I() const { return I_; }
00085 const dtype& sigI() const { return sigI_; }
00086 dtype& I() { return I_; }
00087 dtype& sigI() { return sigI_; }
00088
00089 const dtype& I_pl() const { return I_; }
00090 const dtype& sigI_pl() const { return sigI_; }
00091 const dtype& I_mi() const { return I_; }
00092 const dtype& sigI_mi() const { return sigI_; }
00093 dtype cov() const { return 1.0; }
00094 private:
00095 dtype I_,sigI_;
00096 };
00097
00099
00102 template<class dtype> class I_sigI_ano : private Datatype_base
00103 { public:
00104 I_sigI_ano() { set_null(); }
00105 void set_null() { Util::set_null(I_pl_); Util::set_null(I_mi_); Util::set_null(sigI_pl_); Util::set_null(sigI_mi_); Util::set_null(cov_); }
00106 static String type() { return "I_sigI_ano"; }
00107 void friedel() { dtype I=I_pl_; I_pl_=I_mi_; I_mi_=I;
00108 I=sigI_pl_; sigI_pl_=sigI_mi_; sigI_mi_=I; }
00109 void shift_phase(const ftype& dphi) {}
00110 bool missing() const { return (Util::is_nan(I_pl_) && Util::is_nan(I_mi_)); }
00111 static int data_size() { return 5; }
00112 static String data_names() { return "I+ sigI+ I- sigI- covI+-"; }
00113 void data_export( xtype a[] ) const { a[0] = I_pl(); a[1] = sigI_pl(); a[2] = I_mi(); a[3] = sigI_mi(); a[4] = cov(); }
00114 void data_import( const xtype a[] ) { I_pl() = a[0]; sigI_pl() = a[1]; I_mi() = a[2]; sigI_mi() = a[3]; cov() = a[4]; }
00116 void scale(const ftype& s) { I_pl_ *= (s*s); sigI_pl_ *= (s*s); I_mi_ *= (s*s); sigI_mi_ *= (s*s); cov_ *= (s*s); }
00117
00118 const dtype& I_pl() const { return I_pl_; }
00119 const dtype& sigI_pl() const { return sigI_pl_; }
00120 const dtype& I_mi() const { return I_mi_; }
00121 const dtype& sigI_mi() const { return sigI_mi_; }
00122 const dtype& cov() const { return cov_; }
00123 dtype& I_pl() { return I_pl_; }
00124 dtype& sigI_pl() { return sigI_pl_; }
00125 dtype& I_mi() { return I_mi_; }
00126 dtype& sigI_mi() { return sigI_mi_; }
00127 dtype& cov() { return cov_; }
00128
00129 dtype I() const { return Util::mean(I_pl_,I_mi_); }
00130 dtype sigI() const { return Util::sig_mean(sigI_pl_,sigI_mi_,cov_); }
00131 private:
00132 dtype I_pl_, I_mi_, sigI_pl_, sigI_mi_, cov_;
00133 };
00134
00136
00139 template<class dtype> class F_sigF : private Datatype_base
00140 {
00141 public:
00142 F_sigF() { Util::set_null(f_); Util::set_null(sigf_); }
00143 F_sigF( const dtype& f, const dtype& sigf ) : f_(f), sigf_(sigf) {}
00144 void set_null() { Util::set_null(f_); Util::set_null(sigf_); }
00145 static String type() { return "F_sigF"; }
00146 void friedel() {}
00147 void shift_phase(const ftype& dphi) {}
00148 bool missing() const { return (Util::is_nan(f_) || Util::is_nan(sigf_)); }
00149 static int data_size() { return 2; }
00150 static String data_names() { return "F sigF"; }
00151 void data_export( xtype array[] ) const
00152 { array[0] = f(); array[1] = sigf(); }
00153 void data_import( const xtype array[] )
00154 { f() = array[0]; sigf() = array[1]; }
00156 void scale(const ftype& s) { f_ *= s; sigf_ *= s; }
00157
00158 const dtype& f() const { return f_; }
00159 const dtype& sigf() const { return sigf_; }
00160 dtype& f() { return f_; }
00161 dtype& sigf() { return sigf_; }
00162
00163 const dtype& f_pl() const { return f_; }
00164 const dtype& sigf_pl() const { return sigf_; }
00165 const dtype& f_mi() const { return f_; }
00166 const dtype& sigf_mi() const { return sigf_; }
00167 dtype cov() const { return 1.0; }
00168 private:
00169 dtype f_,sigf_;
00170 };
00171
00173
00176 template<class dtype> class F_sigF_ano : private Datatype_base
00177 { public:
00178 F_sigF_ano() { set_null(); }
00179 void set_null() { Util::set_null(f_pl_); Util::set_null(f_mi_); Util::set_null(sigf_pl_); Util::set_null(sigf_mi_); Util::set_null(cov_); }
00180 static String type() { return "F_sigF_ano"; }
00181 void friedel() { dtype f=f_pl_; f_pl_=f_mi_; f_mi_=f;
00182 f=sigf_pl_; sigf_pl_=sigf_mi_; sigf_mi_=f; }
00183 void shift_phase(const ftype& dphi) {}
00184 bool missing() const { return (Util::is_nan(f_pl_) && Util::is_nan(f_mi_)); }
00185 static int data_size() { return 5; }
00186 static String data_names() { return "F+ sigF+ F- sigF- covF+-"; }
00187 void data_export( xtype a[] ) const { a[0] = f_pl(); a[1] = sigf_pl(); a[2] = f_mi(); a[3] = sigf_mi(); a[4] = cov(); }
00188 void data_import( const xtype a[] ) { f_pl() = a[0]; sigf_pl() = a[1]; f_mi() = a[2]; sigf_mi() = a[3]; cov() = a[4]; }
00190 void scale(const ftype& s) { f_pl_ *= s; sigf_pl_ *= s; f_mi_ *= s; sigf_mi_ *= s; cov_ *= (s*s); }
00191
00192 const dtype& f_pl() const { return f_pl_; }
00193 const dtype& sigf_pl() const { return sigf_pl_; }
00194 const dtype& f_mi() const { return f_mi_; }
00195 const dtype& sigf_mi() const { return sigf_mi_; }
00196 const dtype& cov() const { return cov_; }
00197 dtype& f_pl() { return f_pl_; }
00198 dtype& sigf_pl() { return sigf_pl_; }
00199 dtype& f_mi() { return f_mi_; }
00200 dtype& sigf_mi() { return sigf_mi_; }
00201 dtype& cov() { return cov_; }
00202
00203 dtype f() const { return Util::mean(f_pl_,f_mi_); }
00204 dtype sigf() const { return Util::sig_mean(sigf_pl_,sigf_mi_,cov_); }
00205 private:
00206 dtype f_pl_, f_mi_, sigf_pl_, sigf_mi_, cov_;
00207 };
00208
00210
00222 template<class dtype> class E_sigE : private Datatype_base
00223 {
00224 public:
00225 E_sigE() { Util::set_null(E_); Util::set_null(sigE_); }
00226 E_sigE( const dtype& E, const dtype& sigE ) : E_(E), sigE_(sigE) {}
00227 void set_null() { Util::set_null(E_); Util::set_null(sigE_); }
00228 static String type() { return "E_sigE"; }
00229 void friedel() {}
00230 void shift_phase(const ftype& dphi) {}
00231 bool missing() const { return (Util::is_nan(E_) || Util::is_nan(sigE_)); }
00232 static int data_size() { return 2; }
00233 static String data_names() { return "E sigE"; }
00234 void data_export( xtype array[] ) const
00235 { array[0] = E(); array[1] = sigE(); }
00236 void data_import( const xtype array[] )
00237 { E() = array[0]; sigE() = array[1]; }
00239 void scale(const ftype& s) { E_ *= s; sigE_ *= s; }
00240
00241 const dtype& E() const { return E_; }
00242 const dtype& sigE() const { return sigE_; }
00243 dtype& E() { return E_; }
00244 dtype& sigE() { return sigE_; }
00245
00246 const dtype& E_pl() const { return E_; }
00247 const dtype& sigE_pl() const { return sigE_; }
00248 const dtype& E_mi() const { return E_; }
00249 const dtype& sigE_mi() const { return sigE_; }
00250 dtype cov() const { return 1.0; }
00251 private:
00252 dtype E_,sigE_;
00253 };
00254
00256
00257 template<class dtype> class E_sigE_ano : private Datatype_base
00258 { public:
00259 E_sigE_ano() { set_null(); }
00260 void set_null() { Util::set_null(E_pl_); Util::set_null(E_mi_); Util::set_null(sigE_pl_); Util::set_null(sigE_mi_); Util::set_null(cov_); }
00261 static String type() { return "E_sigE_ano"; }
00262 void friedel() { dtype e=E_pl_; E_pl_=E_mi_; E_mi_=e;
00263 e=sigE_pl_; sigE_pl_=sigE_mi_; sigE_mi_=e; }
00264 void shift_phase(const ftype& dphi) {}
00265 bool missing() const { return (Util::is_nan(E_pl_) && Util::is_nan(E_mi_)); }
00266 static int data_size() { return 5; }
00267 static String data_names() { return "E+ sigE+ E- sigE- covE+-"; }
00268 void data_export( xtype a[] ) const { a[0] = E_pl(); a[1] = sigE_pl(); a[2] = E_mi(); a[3] = sigE_mi(); a[4] = cov(); }
00269 void data_import( const xtype a[] ) { E_pl() = a[0]; sigE_pl() = a[1]; E_mi() = a[2]; sigE_mi() = a[3]; cov() = a[4]; }
00271 void scale(const ftype& s) { E_pl_ *= s; sigE_pl_ *= s; E_mi_ *= s; sigE_mi_ *= s; cov_ *= (s*s); }
00272
00273 const dtype& E_pl() const { return E_pl_; }
00274 const dtype& sigE_pl() const { return sigE_pl_; }
00275 const dtype& E_mi() const { return E_mi_; }
00276 const dtype& sigE_mi() const { return sigE_mi_; }
00277 const dtype& cov() const { return cov_; }
00278 dtype& E_pl() { return E_pl_; }
00279 dtype& sigE_pl() { return sigE_pl_; }
00280 dtype& E_mi() { return E_mi_; }
00281 dtype& sigE_mi() { return sigE_mi_; }
00282 dtype& cov() { return cov_; }
00283
00284 dtype E() const { return Util::mean(E_pl_,E_mi_); }
00285 dtype sigE() const { return Util::sig_mean(sigE_pl_,sigE_mi_,cov_); }
00286 private:
00287 dtype E_pl_, E_mi_, sigE_pl_, sigE_mi_, cov_;
00288 };
00289
00291 template<class dtype> class F_phi : private Datatype_base
00292 {
00293 public:
00294 F_phi() { Util::set_null(f_); Util::set_null(phi_); }
00295 F_phi( const dtype& f, const dtype& phi ) : f_(f), phi_(phi) {}
00296 void set_null() { Util::set_null(f_); Util::set_null(phi_); }
00297 static String type() { return "F_phi"; }
00298 void friedel()
00299 { if (!Util::is_nan(phi_)) phi_=-phi_; }
00300 void shift_phase(const ftype& dphi)
00301 { if (!Util::is_nan(phi_)) phi_+=dphi; }
00302 bool missing() const
00303 { return (Util::is_nan(f_) || Util::is_nan(phi_)); }
00304 static int data_size() { return 2; }
00305 static String data_names() { return "F phi"; }
00306 void data_export( xtype array[] ) const
00307 { array[0] = f(); array[1] = phi(); }
00308 void data_import( const xtype array[] )
00309 { f() = array[0]; phi() = array[1]; }
00311 void scale(const ftype& s) { f_ *= s; }
00312
00313 const dtype& f() const { return f_; }
00314 const dtype& phi() const { return phi_; }
00315 dtype& f() { return f_; }
00316 dtype& phi() { return phi_; }
00318 dtype a() const { return f_ * cos( phi_ ); }
00320 dtype b() const { return f_ * sin( phi_ ); }
00322 F_phi(const std::complex<dtype> c) { f_=std::abs(c); phi_=std::arg(c); }
00324 operator std::complex<dtype>() const { return std::polar(f_, phi_); }
00326 dtype resolve(const dtype phi) { return f_ * cos( phi_ - phi ); }
00328 const F_phi<dtype>& norm() { if ( f_ < 0.0 ) { f_ = -f_; phi_ += Util::pi(); } phi_ = Util::mod( phi_, Util::twopi() ); return *this; }
00329 private:
00330 dtype f_,phi_;
00331 };
00332
00334 template<class dtype> class Phi_fom : private Datatype_base
00335 {
00336 public:
00337 Phi_fom() { Util::set_null(phi_); Util::set_null(fom_); }
00338 Phi_fom( const dtype& phi, const dtype& fom ) : phi_(phi), fom_(fom) {}
00339 void set_null() { Util::set_null(phi_); Util::set_null(fom_); }
00340 static String type() { return "Phi_fom"; }
00341 void friedel()
00342 { if (!Util::is_nan(phi_)) phi_=-phi_; }
00343 void shift_phase(const ftype& dphi)
00344 { if (!Util::is_nan(phi_)) phi_+=dphi; }
00345 bool missing() const
00346 { return (Util::is_nan(phi_) || Util::is_nan(fom_)); }
00347 static int data_size() { return 2; }
00348 static String data_names() { return "phi fom"; }
00349 void data_export( xtype array[] ) const
00350 { array[0] = phi(); array[1] = fom(); }
00351 void data_import( const xtype array[] )
00352 { phi() = array[0]; fom() = array[1]; }
00353
00354 const dtype& phi() const { return phi_; }
00355 const dtype& fom() const { return fom_; }
00356 dtype& phi() { return phi_; }
00357 dtype& fom() { return fom_; }
00358 private:
00359 dtype phi_,fom_;
00360 };
00361
00363 template<class dtype> class ABCD : private Datatype_base
00364 {
00365 public:
00366 ABCD() { Util::set_null(a_); Util::set_null(b_); Util::set_null(c_); Util::set_null(d_); }
00367 ABCD( const dtype& a, const dtype& b, const dtype& c, const dtype& d ) : a_(a), b_(b), c_(c), d_(d) {}
00368 void set_null() { Util::set_null(a_); Util::set_null(b_); Util::set_null(c_); Util::set_null(d_); }
00369 static String type() { return "ABCD"; }
00370 void friedel() { if ( !missing() ) { b_=-b_; d_=-d_; } }
00371 void shift_phase(const ftype& dphi)
00372 {
00373 if ( !missing() ) {
00374 ftype cosd,sind;
00375 dtype a1, b1, c1, d1;
00376 cosd = cos(dphi);
00377 sind = sin(dphi);
00378 a1 = a_*cosd - b_*sind;
00379 b1 = a_*sind + b_*cosd;
00380 cosd = cos(2.0*dphi);
00381 sind = sin(2.0*dphi);
00382 c1 = c_*cosd - d_*sind;
00383 d1 = c_*sind + d_*cosd;
00384 a_ = a1; b_ = b1; c_ = c1; d_ = d1;
00385 }
00386 }
00387 bool missing() const { return (Util::is_nan(a_) || Util::is_nan(b_) || Util::is_nan(c_) || Util::is_nan(d_)); }
00388 static int data_size() { return 4; }
00389 static String data_names() { return "A B C D"; }
00390 void data_export( xtype array[] ) const
00391 { array[0] = a(); array[1] = b(); array[2] = c(); array[3] = d(); }
00392 void data_import( const xtype array[] )
00393 { a() = array[0]; b() = array[1]; c() = array[2]; d() = array[3]; }
00394
00395 const dtype& a() const { return a_; }
00396 const dtype& b() const { return b_; }
00397 const dtype& c() const { return c_; }
00398 const dtype& d() const { return d_; }
00399 dtype& a() { return a_; }
00400 dtype& b() { return b_; }
00401 dtype& c() { return c_; }
00402 dtype& d() { return d_; }
00403 private:
00404 dtype a_,b_,c_,d_;
00405 };
00406
00408 class Flag : private Datatype_base
00409 {
00410 public:
00411 Flag() { flag_ = -1; }
00412 explicit Flag( const int& flag ) : flag_(flag) {}
00413 void set_null() { flag_ = -1; }
00414 static String type() { return "Flag"; }
00415 void friedel() {}
00416 void shift_phase(const ftype& dphi) {}
00417 bool missing() const { return (flag_ < 0); }
00418 static int data_size() { return 1; }
00419 static String data_names() { return "flag"; }
00420 void data_export( xtype array[] ) const
00421 { array[0] = xtype(flag()); }
00422 void data_import( const xtype array[] )
00423 { flag() = int(array[0]); }
00424
00425 const int& flag() const { return flag_; }
00426 int& flag() { return flag_; }
00427 private:
00428 int flag_;
00429 };
00430
00432 class Flag_bool : private Datatype_base
00433 {
00434 public:
00435 Flag_bool() : flag_(false) {}
00436 void set_null() { flag_ = false; }
00437 static String type() { return "Flag_bool"; }
00438 void friedel() {}
00439 void shift_phase(const ftype& dphi) {}
00440 bool missing() const { return (!flag_); }
00441 static int data_size() { return 1; }
00442 static String data_names() { return "flag"; }
00443 void data_export( xtype array[] ) const
00444 { array[0] = xtype(flag()); }
00445 void data_import( const xtype array[] )
00446 { flag() = bool(array[0]); }
00447
00448 const bool& flag() const { return flag_; }
00449 bool& flag() { return flag_; }
00450 private:
00451 bool flag_;
00452 };
00453
00455
00456 template<class dtype> class D_sigD : private Datatype_base
00457 {
00458 public:
00459 D_sigD() { Util::set_null(d_); Util::set_null(sigd_); }
00460 D_sigD( const dtype& d, const dtype& sigd ) : d_(d), sigd_(sigd) {}
00461 void set_null() { Util::set_null(d_); Util::set_null(sigd_); }
00462 static String type() { return "D_sigD"; }
00463 void friedel() { d_ = -d_; }
00464 void shift_phase(const ftype& dphi) {}
00465 bool missing() const { return (Util::is_nan(d_) || Util::is_nan(sigd_)); }
00466 static int data_size() { return 2; }
00467 static String data_names() { return "Dano sigDano"; }
00468 void data_export( xtype array[] ) const
00469 { array[0] = d(); array[1] = sigd(); }
00470 void data_import( const xtype array[] )
00471 { d() = array[0]; sigd() = array[1]; }
00473 void scale(const ftype& s) { d_ *= s; sigd_ *= s; }
00474
00475 const dtype& d() const { return d_; }
00476 const dtype& sigd() const { return sigd_; }
00477 dtype& d() { return d_; }
00478 dtype& sigd() { return sigd_; }
00479 private:
00480 dtype d_,sigd_;
00481 };
00482
00483 }
00484
00485
00486 namespace data32
00487 {
00488 typedef clipper::datatypes::I_sigI<ftype32> I_sigI;
00489 typedef clipper::datatypes::I_sigI_ano<ftype32> I_sigI_ano;
00490 typedef clipper::datatypes::F_sigF<ftype32> F_sigF;
00491 typedef clipper::datatypes::F_sigF_ano<ftype32> F_sigF_ano;
00492 typedef clipper::datatypes::E_sigE<ftype32> E_sigE;
00493 typedef clipper::datatypes::F_phi<ftype32> F_phi;
00494 typedef clipper::datatypes::Phi_fom<ftype32> Phi_fom;
00495 typedef clipper::datatypes::ABCD<ftype32> ABCD;
00496 typedef clipper::datatypes::Flag Flag;
00497 typedef clipper::datatypes::Flag_bool Flag_bool;
00498 typedef clipper::datatypes::D_sigD<ftype32> D_sigD;
00499 }
00500
00501 namespace data64
00502 {
00503 typedef clipper::datatypes::I_sigI<ftype64> I_sigI;
00504 typedef clipper::datatypes::I_sigI_ano<ftype64> I_sigI_ano;
00505 typedef clipper::datatypes::F_sigF<ftype64> F_sigF;
00506 typedef clipper::datatypes::F_sigF_ano<ftype64> F_sigF_ano;
00507 typedef clipper::datatypes::E_sigE<ftype64> E_sigE;
00508 typedef clipper::datatypes::F_phi<ftype64> F_phi;
00509 typedef clipper::datatypes::Phi_fom<ftype64> Phi_fom;
00510 typedef clipper::datatypes::ABCD<ftype64> ABCD;
00511 typedef clipper::datatypes::Flag Flag;
00512 typedef clipper::datatypes::Flag_bool Flag_bool;
00513 typedef clipper::datatypes::D_sigD<ftype64> D_sigD;
00514 }
00515
00516
00517
00518 }
00519
00520 #endif