11#include " module_io/cube_io.h"
2+ #include < limits>
23// #include "module_base/global_variable.h" // GlobalV reference removed
34
45bool ModuleIO::read_cube (
56#ifdef __MPI
6- const Parallel_Grid*const Pgrid,
7+ const Parallel_Grid* const Pgrid,
78#endif
89 const int my_rank,
9- const int is,
1010 std::ofstream& ofs_running,
11- const int nspin,
1211 const std::string& fn,
13- double *const data,
12+ double * const data,
1413 const int nx,
1514 const int ny,
1615 const int nz,
17- double & ef,
18- const UnitCell*const ucell,
19- int & prenspin,
20- const bool warning_flag)
16+ const int natom)
2117{
22- ModuleBase::TITLE (" ModuleIO" ," read_cube" );
18+ ModuleBase::TITLE (" ModuleIO" , " read_cube" );
2319 std::ifstream ifs (fn.c_str ());
2420 if (!ifs)
2521 {
@@ -33,90 +29,33 @@ bool ModuleIO::read_cube(
3329 ofs_running << " Find the file, try to read charge from file." << std::endl;
3430 }
3531
36- bool quit=false ;
37-
38- ifs.ignore (300 , ' \n ' ); // skip the header
39-
40- if (nspin != 4 )
41- {
42- int v_in;
43- ifs >> v_in;
44- if (v_in != nspin)
45- {
46- std::cout << " WARNING: nspin mismatch: " << nspin << " in INPUT parameters but " << v_in << " in " << fn << std::endl;
47- return false ;
48- }
49- }
50- else
51- {
52- ifs >> prenspin;
53- }
54- ifs.ignore (150 , ' )' );
55-
56- ifs >> ef;
57- ofs_running << " read in fermi energy = " << ef << std::endl;
58-
59- ifs.ignore (150 , ' \n ' );
60-
61- ModuleBase::CHECK_INT (ifs, ucell->nat );
62- ifs.ignore (150 , ' \n ' );
32+ // skip the first 3 lines
33+ for (int i = 0 ;i < 3 ;++i) { ifs.ignore (std::numeric_limits<std::streamsize>::max (), ' \n ' ); }
6334
6435 int nx_read = 0 ;
6536 int ny_read = 0 ;
6637 int nz_read = 0 ;
67- double fac = ucell->lat0 ;
6838 std::string temp;
69- if (warning_flag)
70- {
71- ifs >> nx_read;
72- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e11 / double (nx), quit);
73- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e12 / double (nx), quit);
74- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e13 / double (nx), quit);
75- ifs >> ny_read;
76- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e21 / double (ny), quit);
77- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e22 / double (ny), quit);
78- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e23 / double (ny), quit);
79- ifs >> nz_read;
80- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e31 / double (nz), quit);
81- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e32 / double (nz), quit);
82- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->latvec .e33 / double (nz), quit);
83- }
84- else
85- {
86- ifs >> nx_read;
87- ifs >> temp >> temp >> temp;
88- ifs >> ny_read;
89- ifs >> temp >> temp >> temp;
90- ifs >> nz_read;
91- ifs >> temp >> temp >> temp;
92- }
9339
94- for (int it = 0 ; it < ucell->ntype ; it++)
95- {
96- for (int ia = 0 ; ia < ucell->atoms [it].na ; ia++)
97- {
98- ifs >> temp; // skip atomic number
99- ifs >> temp; // skip Z valance
100- if (warning_flag)
101- {
102- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->atoms [it].tau [ia].x , quit);
103- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->atoms [it].tau [ia].y , quit);
104- ModuleBase::CHECK_DOUBLE (ifs, fac * ucell->atoms [it].tau [ia].z , quit);
105- }
106- else
107- {
108- ifs >> temp >> temp >> temp;
109- }
110- }
111- }
40+ ifs >> nx_read;
41+ ifs >> temp >> temp >> temp;
42+ ifs >> ny_read;
43+ ifs >> temp >> temp >> temp;
44+ ifs >> nz_read;
45+ ifs >> temp >> temp >> temp;
46+
47+ std::cout << " xyzread:" << nx_read << " " << ny_read << " " << nz_read << std::endl;
48+
49+ // skip this line and the next natom lines
50+ for (int i = 0 ;i < natom + 1 ;++i) { ifs.ignore (std::numeric_limits<std::streamsize>::max (), ' \n ' ); }
11251
11352#ifdef __MPI
11453 if (nx == nx_read && ny == ny_read && nz == nz_read)
11554 ModuleIO::read_cube_core_match (ifs, Pgrid, (my_rank == 0 ), data, nx * ny, nz);
11655 else
11756 ModuleIO::read_cube_core_mismatch (ifs, Pgrid, (my_rank == 0 ), data, nx, ny, nz, nx_read, ny_read, nz_read);
11857#else
119- ofs_running << " Read SPIN = " << is + 1 << " charge now. " << std::endl;
58+
12059 if (nx == nx_read && ny == ny_read && nz == nz_read)
12160 ModuleIO::read_cube_core_match (ifs, data, nx*ny, nz);
12261 else
0 commit comments