1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // Ecut.h
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18 
19 #ifndef ECUT_H
20 #define ECUT_H
21 
22 #include<iostream>
23 #include<iomanip>
24 #include<sstream>
25 #include<stdlib.h>
26 
27 #include "Sample.h"
28 
29 class Ecut : public Var
30 {
31   Sample *s;
32 
33   public:
34 
name(void)35   const char *name ( void ) const { return "ecut"; };
36 
set(int argc,char ** argv)37   int set ( int argc, char **argv )
38   {
39     if ( argc != 2 )
40     {
41       if ( ui->onpe0() )
42       cout << " ecut takes only one value" << endl;
43       return 1;
44     }
45 
46     double v = atof(argv[1]);
47     if ( v < 0.0 )
48     {
49       if ( ui->onpe0() )
50         cout << " ecut must be non-negative" << endl;
51       return 1;
52     }
53 
54     if ( s->wf.ecut() == 0.5 * v )
55       return 0;
56 
57     s->wf.resize(0.5*v);
58     if ( s->wfv != 0 )
59     {
60       s->wfv->resize(0.5*v);
61       s->wfv->clear();
62     }
63 
64     return 0;
65   }
66 
print(void)67   string print (void) const
68   {
69      ostringstream st;
70      st.setf(ios::left,ios::adjustfield);
71      st << setw(10) << name() << " = ";
72      st.setf(ios::right,ios::adjustfield);
73      st << setw(10) << 2 * s->wf.ecut();
74      return st.str();
75   }
76 
Ecut(Sample * sample)77   Ecut(Sample *sample) : s(sample) {};
78 };
79 #endif
80