@@ -109,7 +109,9 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs, Atom_pseudo& pp)
109109
110110void Pseudopot_upf::getnameval (std::ifstream& ifs, int & n, std::string* name, std::string* val)
111111{
112- std::string txt, word;
112+ std::string txt;
113+ std::string word;
114+
113115 // get long txt
114116 ifs >> txt;
115117 while (ifs >> word)
@@ -128,26 +130,32 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st
128130 while (1 )
129131 {
130132 pos = txt.find (" =" , pos);
131- if (pos == std::string::npos)
132- break ;
133- pos++;
133+ if (pos == std::string::npos)
134+ {
135+ break ;
136+ }
137+ pos++;
134138 n++;
135139 }
136140
141+ std::cout << " n=" << n << std::endl;
142+
137143 // get name & value
138144 pos = 0 ;
139- size_t pos2, ll;
145+ size_t pos2=0 ;
146+ size_t ll=0 ;
140147 for (int i = 0 ; i < n; ++i)
141148 {
142149 pos2 = txt.find (" =" , pos);
143150 for (; pos2 > pos; --pos2) // There may be a space before "=";
144151 {
145- if (txt.substr (pos2 - 1 , 1 ) != " " )
146- break ;
152+ if (txt.substr (pos2 - 1 , 1 ) != " " )
153+ {
154+ break ;
155+ }
147156 }
148157 ll = pos2 - pos;
149158 name[i] = txt.substr (pos, ll);
150- // std::cout<<i<<" "<<name[i]<<std::endl;
151159 std::string mark;
152160 bool findmark = false ;
153161 for (int j = 0 ; j < 100 ; ++j) // The mark can be ' or " or .
@@ -160,10 +168,12 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st
160168 break ;
161169 }
162170 }
163- if (!findmark)
164- ModuleBase::WARNING_QUIT (
165- " Pseudopot_upf::getnameval" ,
166- " The values are not in \' or \" . Please improve the program in read_pp_upf201.cpp" );
171+ if (!findmark)
172+ {
173+ ModuleBase::WARNING_QUIT (
174+ " Pseudopot_upf::getnameval" ,
175+ " The values are not in \' or \" . Please improve the program in read_pp_upf201.cpp" );
176+ }
167177 pos = pos2;
168178 pos2 = txt.find (mark, pos);
169179 ll = pos2 - pos;
@@ -172,24 +182,33 @@ void Pseudopot_upf::getnameval(std::ifstream& ifs, int& n, std::string* name, st
172182 val[i] = tmpval;
173183 pos = pos2 + 1 ;
174184 for (int j = 0 ; j < 100 ; ++j)
175- {
176- if (txt.substr (pos, 1 ) == " " || txt.substr (pos, 1 ) == " ," )
177- pos++;
178- else
179- break ;
180- }
181- // std::cout<<name[i]<<"=\""<<val[i]<<"\""<<std::endl;
185+ {
186+ if (txt.substr (pos, 1 ) == " " || txt.substr (pos, 1 ) == " ," )
187+ {
188+ pos++;
189+ }
190+ else
191+ {
192+ break ;
193+ }
194+ }
195+ // std::cout<<name[i]<<"=\""<<val[i]<<"\""<<std::endl;
182196 }
183197 return ;
184198}
185199
186200void Pseudopot_upf::read_pseudo_upf201_header (std::ifstream& ifs, Atom_pseudo& pp)
187201{
188- if (!ModuleBase::GlobalFunc::SCAN_BEGIN (ifs, " <PP_HEADER" ))
189- ModuleBase::WARNING_QUIT (" Pseudopot_upf::read_pseudo_upf201_header" , " Found no PP_HEADER" );
190- std::string name[50 ];
191- std::string val[50 ];
192- int nparameter;
202+ if (!ModuleBase::GlobalFunc::SCAN_BEGIN (ifs, " <PP_HEADER" ))
203+ {
204+ ModuleBase::WARNING_QUIT (" Pseudopot_upf::read_pseudo_upf201_header" , " Found no PP_HEADER" );
205+ }
206+
207+ const int max_n = 100 ;
208+ std::string name[max_n];
209+ std::string val[max_n];
210+ int nparameter=0 ;
211+
193212 this ->getnameval (ifs, nparameter, name, val);
194213
195214 for (int ip = 0 ; ip < nparameter; ++ip)
@@ -347,12 +366,17 @@ void Pseudopot_upf::read_pseudo_upf201_header(std::ifstream& ifs, Atom_pseudo& p
347366
348367void Pseudopot_upf::read_pseudo_upf201_mesh (std::ifstream& ifs, Atom_pseudo& pp)
349368{
350- std::string name[50 ];
351- std::string val[50 ];
352- int nparameter;
369+ const int max_n = 100 ;
370+ std::string name[max_n];
371+ std::string val[max_n];
372+ int nparameter=0 ;
373+
353374 if (ModuleBase::GlobalFunc::SCAN_BEGIN (ifs, " <PP_MESH" , true , false ))
354375 {
355376 this ->getnameval (ifs, nparameter, name, val);
377+
378+ std::cout << " read mesh, nparameter=" << nparameter << std::endl;
379+
356380 for (int ip = 0 ; ip < nparameter; ++ip)
357381 {
358382 if (name[ip] == " dx" )
@@ -362,6 +386,9 @@ void Pseudopot_upf::read_pseudo_upf201_mesh(std::ifstream& ifs, Atom_pseudo& pp)
362386 else if (name[ip] == " mesh" )
363387 {
364388 pp.mesh = atoi (val[ip].c_str ());
389+
390+ std::cout << " mesh=" << pp.mesh << std::endl;
391+
365392 this ->mesh_changed = false ;
366393 if (pp.mesh % 2 == 0 )
367394 {
@@ -437,9 +464,12 @@ void Pseudopot_upf::read_pseudo_upf201_nonlocal(std::ifstream& ifs, Atom_pseudo&
437464 return ;
438465 }
439466 std::string word;
440- std::string name[50 ];
441- std::string val[50 ];
442- int nparameter;
467+
468+ const int max_n = 100 ;
469+ std::string name[max_n];
470+ std::string val[max_n];
471+ int nparameter=0 ;
472+
443473 this ->kbeta = std::vector<int >(pp.nbeta );
444474 pp.lll = std::vector<int >(pp.nbeta );
445475 this ->els_beta = std::vector<std::string>(pp.nbeta );
@@ -680,9 +710,12 @@ void Pseudopot_upf::read_pseudo_upf201_nonlocal(std::ifstream& ifs, Atom_pseudo&
680710void Pseudopot_upf::read_pseudo_upf201_pswfc (std::ifstream& ifs, Atom_pseudo& pp)
681711{
682712 std::string word;
683- std::string name[50 ];
684- std::string val[50 ];
685- int nparameter;
713+
714+ const int max_n = 100 ;
715+ std::string name[max_n];
716+ std::string val[max_n];
717+ int nparameter=0 ;
718+
686719 ModuleBase::GlobalFunc::SCAN_BEGIN (ifs, " <PP_PSWFC>" );
687720 pp.els = std::vector<std::string>(pp.nchi , " " );
688721 pp.lchi = std::vector<int >(pp.nchi , 0 );
@@ -815,9 +848,12 @@ void Pseudopot_upf::read_pseudo_upf201_fullwfc(std::ifstream& ifs)
815848void Pseudopot_upf::read_pseudo_upf201_so (std::ifstream& ifs, Atom_pseudo& pp)
816849{
817850 std::string word;
818- std::string name[50 ];
819- std::string val[50 ];
820- int nparameter;
851+
852+ const int max_n = 100 ;
853+ std::string name[max_n];
854+ std::string val[max_n];
855+ int nparameter=0 ;
856+
821857 ModuleBase::GlobalFunc::SCAN_BEGIN (ifs, " <PP_SPIN_ORB>" );
822858 pp.jchi = std::vector<double >(pp.nchi , 0.0 );
823859 pp.jjj = std::vector<double >(pp.nbeta , 0.0 );
@@ -893,4 +929,4 @@ void Pseudopot_upf::read_pseudo_upf201_so(std::ifstream& ifs, Atom_pseudo& pp)
893929 ModuleBase::GlobalFunc::SCAN_END (ifs, word);
894930 }
895931 ModuleBase::GlobalFunc::SCAN_END (ifs, " </PP_SPIN_ORB>" );
896- }
932+ }
0 commit comments