• R/O
  • HTTP
  • SSH
  • HTTPS

fermisurfer: Commit

fermisurfer Git


Commit MetaInfo

Revision1571a002adf3f28c9b9a604758dfad6b2ca85b46 (tree)
Zeit2019-05-27 10:52:07
Autormitsuaki1987 <kawamitsuaki@gmai...>
Commitermitsuaki1987

Log Message

Backup

Ändern Zusammenfassung

Diff

--- a/src/bxsf2frmsf.cpp
+++ b/src/bxsf2frmsf.cpp
@@ -51,7 +51,7 @@ static void read_dat(
5151 if ((fp = fopen(fname, "r")) == NULL) {
5252 printf("file open error!!\n");
5353 printf(" Press any key to exit.\n");
54- getchar();
54+ ierr = getchar();
5555 exit(EXIT_FAILURE);
5656 }
5757 printf("\n##### Reading BXSF file %s #####\n\n", fname);
@@ -85,13 +85,13 @@ static void read_dat(
8585 printf(" Bvec %d : %f %f %f \n", ii + 1, Bvec[0][ii], Bvec[1][ii], Bvec[2][ii]);
8686 }
8787
88- Eig = (double****)malloc(Nb * sizeof(double***));
88+ Eig = new double***[Nb];
8989 for (ib = 0; ib < Nb; ib++) {
90- Eig[ib] = (double***)malloc((Ng[0] + 1) * sizeof(double**));
90+ Eig[ib] = new double**[Ng[0] + 1];
9191 for (ik0 = 0; ik0 <= Ng[0]; ik0++) {
92- Eig[ib][ik0] = (double**)malloc((Ng[1] + 1) * sizeof(double*));
92+ Eig[ib][ik0] = new double*[Ng[1] + 1];
9393 for (ik1 = 0; ik1 <= Ng[1]; ik1++) {
94- Eig[ib][ik0][ik1] = (double*)malloc((Ng[2] + 1) * sizeof(double));
94+ Eig[ib][ik0][ik1] = new double[Ng[2] + 1];
9595 }/*for (ik1 = 0; ik1 < Ng[1]; ik1++)*/
9696 }/*for (ik0 = 0; ik0 < Ng[0]; ik0++)*/
9797 }/*for (ib = 0; ib < Nb; ib++)*/
@@ -154,15 +154,15 @@ static void fvel() {
154154 /*
155155 malloc fermi velocity
156156 */
157- vf = (double*****)malloc(Nb * sizeof(double****));
157+ vf = new double****[Nb];
158158 for (ib = 0; ib < Nb; ib++) {
159- vf[ib] = (double****)malloc(Ng[0] * sizeof(double***));
159+ vf[ib] = new double***[Ng[0]];
160160 for (ik0 = 0; ik0 < Ng[0]; ik0++) {
161- vf[ib][ik0] = (double***)malloc(Ng[1] * sizeof(double**));
161+ vf[ib][ik0] = new double**[Ng[1]];
162162 for (ik1 = 0; ik1 < Ng[1]; ik1++) {
163- vf[ib][ik0][ik1] = (double**)malloc(Ng[2] * sizeof(double*));
163+ vf[ib][ik0][ik1] = new double*[Ng[2]];
164164 for (ik2 = 0; ik2 < Ng[2]; ik2++) {
165- vf[ib][ik0][ik1][ik2] = (double*)malloc(7 * sizeof(double));
165+ vf[ib][ik0][ik1][ik2] = new double[7];
166166 }
167167 }/*for (ik1 = 0; ik1 < Ng[1]; ik1++)*/
168168 }/*for (ik0 = 0; ik0 < Ng[0]; ik0++)*/
@@ -235,7 +235,7 @@ static void write_file(
235235 else {
236236 printf("ERROR! Extension shoud be .bxsf, .BXSF, or .Bxsf !\n");
237237 printf(" Press any key to exit.\n");
238- getchar();
238+ ierr = getchar();
239239 exit(-1);
240240 }
241241 sprintf(&fname2[ii], "%s", ext);
@@ -279,10 +279,12 @@ int main(
279279 char *argv[] //!< [in] Input file name
280280 )
281281 {
282+ int ierr;
283+
282284 if (argc < 2) {
283285 printf("\n\nInput file is not specified !\n");
284286 printf(" Press any key to exit.\n");
285- getchar();
287+ ierr = getchar();
286288 exit(-1);
287289 }
288290
@@ -302,5 +304,5 @@ int main(
302304
303305 printf("\n##### DONE #####\n");
304306 printf(" Press any key to exit.\n");
305- getchar();
307+ ierr = getchar();
306308 }
--- a/src/calc_nodeline.cpp
+++ b/src/calc_nodeline.cpp
@@ -123,19 +123,19 @@ void calc_nodeline() {
123123 /*
124124 Allocation of nodeline
125125 */
126- kvnl = (GLfloat****)malloc(nb * sizeof(GLfloat***));
127- kvnl_rot = (GLfloat**)malloc(nb * sizeof(GLfloat*));
128- nmlnl = (GLfloat**)malloc(nb * sizeof(GLfloat*));
129- clrnl = (GLfloat**)malloc(nb * sizeof(GLfloat*));
126+ kvnl = new GLfloat***[nb];
127+ kvnl_rot = new GLfloat*[nb];
128+ nmlnl = new GLfloat*[nb];
129+ clrnl = new GLfloat*[nb];
130130 for (ib = 0; ib < nb; ++ib) {
131- kvnl[ib] = (GLfloat***)malloc(nnl[ib] * sizeof(GLfloat**));
132- kvnl_rot[ib] = (GLfloat*)malloc(6 * nnl[ib] * sizeof(GLfloat));
133- nmlnl[ib] = (GLfloat*)malloc(6 * nnl[ib] * sizeof(GLfloat));
134- clrnl[ib] = (GLfloat*)malloc(8 * nnl[ib] * sizeof(GLfloat));
131+ kvnl[ib] = new GLfloat**[nnl[ib]];
132+ kvnl_rot[ib] = new GLfloat[6*nnl[ib]];
133+ nmlnl[ib] = new GLfloat[6*nnl[ib]];
134+ clrnl[ib] = new GLfloat[8 * nnl[ib]];
135135 for (itri = 0; itri < nnl[ib]; ++itri) {
136- kvnl[ib][itri] = (GLfloat**)malloc(2 * sizeof(GLfloat*));
136+ kvnl[ib][itri] = new GLfloat * [2];
137137 for (i = 0; i < 2; ++i) {
138- kvnl[ib][itri][i] = (GLfloat*)malloc(3 * sizeof(GLfloat));
138+ kvnl[ib][itri][i] = new GLfloat[3];
139139 for (j = 0; j < 2; ++j)nmlnl[ib][j + 3 * i + 6 * itri] = 0.0f;
140140 nmlnl[ib][2 + 3 * i + 6 * itri] = 1.0f;
141141 for (j = 0; j < 4; ++j)clrnl[ib][j + 4 * i + 8 * itri] = black[j];
--- a/src/equator.cpp
+++ b/src/equator.cpp
@@ -126,19 +126,19 @@ void equator() {
126126 /*
127127 Allocation of nodeline
128128 */
129- kveq = (GLfloat****)malloc(nb * sizeof(GLfloat***));
130- kveq_rot = (GLfloat**)malloc(nb * sizeof(GLfloat*));
131- nmleq = (GLfloat**)malloc(nb * sizeof(GLfloat*));
132- clreq = (GLfloat**)malloc(nb * sizeof(GLfloat*));
129+ kveq = new GLfloat***[nb];
130+ kveq_rot = new GLfloat*[nb];
131+ nmleq = new GLfloat*[nb];
132+ clreq = new GLfloat*[nb];
133133 for (ib = 0; ib < nb; ++ib) {
134- kveq[ib] = (GLfloat***)malloc(nequator[ib] * sizeof(GLfloat**));
135- kveq_rot[ib] = (GLfloat*)malloc(6 * nequator[ib] * sizeof(GLfloat));
136- nmleq[ib] = (GLfloat*)malloc(6 * nequator[ib] * sizeof(GLfloat));
137- clreq[ib] = (GLfloat*)malloc(8 * nequator[ib] * sizeof(GLfloat));
134+ kveq[ib] = new GLfloat**[nequator[ib]];
135+ kveq_rot[ib] = new GLfloat[6 * nequator[ib]];
136+ nmleq[ib] = new GLfloat[6 * nequator[ib]];
137+ clreq[ib] = new GLfloat[8 * nequator[ib]];
138138 for (itri = 0; itri < nequator[ib]; ++itri) {
139- kveq[ib][itri] = (GLfloat**)malloc(2 * sizeof(GLfloat*));
139+ kveq[ib][itri] = new GLfloat*[2];
140140 for (i = 0; i < 2; ++i) {
141- kveq[ib][itri][i] = (GLfloat*)malloc(3 * sizeof(GLfloat));
141+ kveq[ib][itri][i] = new GLfloat[3];
142142 for (j = 0; j < 2; ++j)nmleq[ib][j + 3 * i + 6 * itri] = 0.0f;
143143 nmleq[ib][2 + 3 * i + 6 * itri] = 1.0f;
144144 for (j = 0; j < 4; ++j)clreq[ib][j + 4 * i + 8 * itri] = black[j];
--- a/src/fermi_patch.cpp
+++ b/src/fermi_patch.cpp
@@ -583,27 +583,27 @@ void fermi_patch()
583583 /*
584584 Allocation of triangler patches
585585 */
586- matp = (GLfloat****)malloc(nb * sizeof(GLfloat***));
587- clr = (GLfloat**)malloc(nb * sizeof(GLfloat*));
588- kvp = (GLfloat****)malloc(nb * sizeof(GLfloat***));
589- nmlp = (GLfloat****)malloc(nb * sizeof(GLfloat***));
590- kvp_rot = (GLfloat**)malloc(nb * sizeof(GLfloat*));
591- nmlp_rot = (GLfloat**)malloc(nb * sizeof(GLfloat*));
586+ matp = new GLfloat***[nb];
587+ clr = new GLfloat*[nb];
588+ kvp = new GLfloat***[nb];
589+ nmlp = new GLfloat***[nb];
590+ kvp_rot = new GLfloat*[nb];
591+ nmlp_rot = new GLfloat*[nb];
592592 for (ib = 0; ib < nb; ++ib) {
593- matp[ib] = (GLfloat***)malloc(ntri[ib] * sizeof(GLfloat**));
594- clr[ib] = (GLfloat*)malloc(12 * ntri[ib] * sizeof(GLfloat));
595- kvp[ib] = (GLfloat***)malloc(ntri[ib] * sizeof(GLfloat**));
596- nmlp[ib] = (GLfloat***)malloc(ntri[ib] * sizeof(GLfloat**));
597- kvp_rot[ib] = (GLfloat*)malloc(9 * ntri[ib] * sizeof(GLfloat));
598- nmlp_rot[ib] = (GLfloat*)malloc(9 * ntri[ib] * sizeof(GLfloat));
593+ matp[ib] = new GLfloat**[ntri[ib]];
594+ clr[ib] = new GLfloat[12 * ntri[ib]];
595+ kvp[ib] = new GLfloat**[ntri[ib]];
596+ nmlp[ib] = new GLfloat**[ntri[ib]];
597+ kvp_rot[ib] = new GLfloat[9 * ntri[ib]];
598+ nmlp_rot[ib] = new GLfloat[9 * ntri[ib]];
599599 for (i0 = 0; i0 < ntri[ib]; ++i0) {
600- matp[ib][i0] = (GLfloat**)malloc(3 * sizeof(GLfloat*));
601- kvp[ib][i0] = (GLfloat**)malloc(3 * sizeof(GLfloat*));
602- nmlp[ib][i0] = (GLfloat**)malloc(3 * sizeof(GLfloat*));
600+ matp[ib][i0] = new GLfloat*[3];
601+ kvp[ib][i0] = new GLfloat*[3];
602+ nmlp[ib][i0] = new GLfloat*[3];
603603 for (i1 = 0; i1 < 3; ++i1) {
604- matp[ib][i0][i1] = (GLfloat*)malloc(3 * sizeof(GLfloat));
605- kvp[ib][i0][i1] = (GLfloat*)malloc(3 * sizeof(GLfloat));
606- nmlp[ib][i0][i1] = (GLfloat*)malloc(3 * sizeof(GLfloat));
604+ matp[ib][i0][i1] = new GLfloat[3];
605+ kvp[ib][i0][i1] = new GLfloat[3];
606+ nmlp[ib][i0][i1] = new GLfloat[3];
607607 }/*for (i1 = 0; i1 < 3; ++i1)*/
608608 }/*for (i0 = 0; i0 < ntri[ib]; ++i0)*/
609609 }/*for (ib = 0; ib < nb; ++ib)*/
--- a/src/fermisurfer.cpp
+++ b/src/fermisurfer.cpp
@@ -278,6 +278,8 @@ int main(
278278 char *argv[] //!< [in] Input file name
279279 )
280280 {
281+ int ierr;
282+
281283 printf("\n");
282284 printf("###########################################\n");
283285 printf("## ##\n");
@@ -289,7 +291,7 @@ int main(
289291 printf("\n");
290292 printf(" Input file is not specified !\n");
291293 printf(" Press any key to exit.\n");
292- getchar();
294+ ierr = getchar();
293295 exit(-1);
294296 }
295297 /**/
@@ -305,7 +307,9 @@ int main(
305307 printf(" Initialize variables ...\n");
306308 printf("\n");
307309 /**/
308- read_file(argv[1]);
310+ color_scale = read_file(argv[1]);
311+ if (color_scale == 0)color_scale = 4;
312+ printf("debug %d\n", color_scale);
309313 interpol_energy();
310314 init_corner();
311315 bragg_vector();
--- a/src/free_patch.cpp
+++ b/src/free_patch.cpp
@@ -44,76 +44,76 @@ void free_patch() {
4444 for (ib = 0; ib < nb; ++ib) {
4545 for (i0 = 0; i0 < ntri[ib]; ++i0) {
4646 for (i1 = 0; i1 < 3; ++i1) {
47- free(nmlp[ib][i0][i1]);
48- free(matp[ib][i0][i1]);
49- free(kvp[ib][i0][i1]);
47+ delete[] nmlp[ib][i0][i1];
48+ delete[] matp[ib][i0][i1];
49+ delete[] kvp[ib][i0][i1];
5050 }
51- free(nmlp[ib][i0]);
52- free(matp[ib][i0]);
53- free(kvp[ib][i0]);
51+ delete[] nmlp[ib][i0];
52+ delete[] matp[ib][i0];
53+ delete[] kvp[ib][i0];
5454 }
55- free(nmlp[ib]);
56- free(matp[ib]);
57- free(clr[ib]);
58- free(kvp[ib]);
59- free(nmlp_rot[ib]);
60- free(kvp_rot[ib]);
55+ delete[] nmlp[ib];
56+ delete[] matp[ib];
57+ delete[] clr[ib];
58+ delete[] kvp[ib];
59+ delete[] nmlp_rot[ib];
60+ delete[] kvp_rot[ib];
6161 }
62- free(nmlp);
63- free(matp);
64- free(clr);
65- free(kvp);
66- free(nmlp_rot);
67- free(kvp_rot);
62+ delete[] nmlp;
63+ delete[] matp;
64+ delete[] clr;
65+ delete[] kvp;
66+ delete[] nmlp_rot;
67+ delete[] kvp_rot;
6868 /*
6969 Nodal line
7070 */
7171 for (ib = 0; ib < nb; ++ib) {
7272 for (i0 = 0; i0 < nnl[ib]; ++i0) {
7373 for (i1 = 0; i1 < 2; ++i1) {
74- free(kvnl[ib][i0][i1]);
74+ delete[] kvnl[ib][i0][i1];
7575 }/*for (i1 = 0; i1 < 2; ++i1)*/
76- free(kvnl[ib][i0]);
76+ delete[] kvnl[ib][i0];
7777 }/*for (i0 = 0; i0 < nnl[ib]; ++i0)*/
78- free(kvnl[ib]);
79- free(kvnl_rot[ib]);
80- free(nmlnl[ib]);
81- free(clrnl[ib]);
78+ delete[] kvnl[ib];
79+ delete[] kvnl_rot[ib];
80+ delete[] nmlnl[ib];
81+ delete[] clrnl[ib];
8282 }/*for (ib = 0; ib < nb; ++ib)*/
83- free(kvnl);
84- free(kvnl_rot);
85- free(nmlnl);
86- free(clrnl);
83+ delete[] kvnl;
84+ delete[] kvnl_rot;
85+ delete[] nmlnl;
86+ delete[] clrnl;
8787 /*
8888 2D Fermi line
8989 */
9090 for (ib = 0; ib < nb; ++ib) {
91- free(kv2d[ib]);
92- free(clr2d[ib]);
93- free(nml2d[ib]);
91+ delete[] kv2d[ib];
92+ delete[] clr2d[ib];
93+ delete[] nml2d[ib];
9494 }/*for (ib = 0; ib < nb; ++ib)*/
95- free(kv2d);
96- free(clr2d);
97- free(nml2d);
95+ delete[] kv2d;
96+ delete[] clr2d;
97+ delete[] nml2d;
9898 /*
9999 equator
100100 */
101101 for (ib = 0; ib < nb; ++ib) {
102102 for (i0 = 0; i0 < nequator[ib]; ++i0) {
103103 for (i1 = 0; i1 < 2; ++i1) {
104- free(kveq[ib][i0][i1]);
104+ delete[] kveq[ib][i0][i1];
105105 }/*for (i1 = 0; i1 < 2; ++i1)*/
106- free(kveq[ib][i0]);
106+ delete[] kveq[ib][i0];
107107 }/*for (i0 = 0; i0 < nequator[ib]; ++i0)*/
108- free(kveq[ib]);
109- free(kveq_rot[ib]);
110- free(nmleq[ib]);
111- free(clreq[ib]);
108+ delete[] kveq[ib];
109+ delete[] kveq_rot[ib];
110+ delete[] nmleq[ib];
111+ delete[] clreq[ib];
112112 }/*for (ib = 0; ib < nb; ++ib)*/
113- free(kveq);
114- free(kveq_rot);
115- free(nmleq);
116- free(clreq);
113+ delete[] kveq;
114+ delete[] kveq_rot;
115+ delete[] nmleq;
116+ delete[] clreq;
117117
118118 }/*void free_patch()*/
119119 /**
@@ -127,11 +127,11 @@ void max_and_min()
127127 int itri, ithread;
128128 GLfloat **max_th, **min_th;
129129
130- max_th = (GLfloat**)malloc(nthreads * sizeof(GLfloat*));
131- min_th = (GLfloat**)malloc(nthreads * sizeof(GLfloat*));
130+ max_th = new GLfloat*[nthreads];
131+ min_th = new GLfloat*[nthreads];
132132 for (ithread = 0; ithread < nthreads; ithread++) {
133- max_th[ithread] = (GLfloat*)malloc(3 * sizeof(GLfloat));
134- min_th[ithread] = (GLfloat*)malloc(3 * sizeof(GLfloat));
133+ max_th[ithread] = new GLfloat[3];
134+ min_th[ithread] = new GLfloat[3];
135135 }
136136
137137 printf("\n");
@@ -268,8 +268,8 @@ shared(nb,ntri,nmlp,max_th,min_th) private(itri,ithread)
268268 }
269269 }/*if (color_scale == 5 || color_scale == 6)*/
270270
271- free(max_th);
272- free(min_th);
271+ delete[] max_th;
272+ delete[] min_th;
273273
274274 if (color_scale == 1 || color_scale == 4
275275 || color_scale == 6 || color_scale == 7) {
--- a/src/kumo.cpp
+++ b/src/kumo.cpp
@@ -76,38 +76,38 @@ void interpol_energy() {
7676 for (i0 = 0; i0 < ng[0]; i0++) {
7777 for (i1 = 0; i1 < ng[1]; i1++) {
7878 for (i2 = 0; i2 < ng[2]; i2++) {
79- free(vf[ib][i0][i1][i2]);
80- free(mat[ib][i0][i1][i2]);
79+ delete[] vf[ib][i0][i1][i2];
80+ delete[] mat[ib][i0][i1][i2];
8181 }
82- free(eig[ib][i0][i1]);
83- free(mat[ib][i0][i1]);
84- free(vf[ib][i0][i1]);
82+ delete[] eig[ib][i0][i1];
83+ delete[] mat[ib][i0][i1];
84+ delete[] vf[ib][i0][i1];
8585 }/*for (i1 = 0; i1 < ng[1]; i1++)*/
86- free(eig[ib][i0]);
87- free(mat[ib][i0]);
88- free(vf[ib][i0]);
86+ delete[] eig[ib][i0];
87+ delete[] mat[ib][i0];
88+ delete[] vf[ib][i0];
8989 }/*for (i0 = 0; i0 < ng[0]; i0++)*/
90- free(eig[ib]);
91- free(mat[ib]);
92- free(vf[ib]);
90+ delete[] eig[ib];
91+ delete[] mat[ib];
92+ delete[] vf[ib];
9393 }/*for (ib = 0; ib < nb; ib++)*/
9494 for (ii = 0; ii < 3; ii++)ng[ii] = ng0[ii] * interpol;
9595 /**/
9696 for (ib = 0; ib < nb; ib++) {
97- eig[ib] = (GLfloat***)malloc(ng[0] * sizeof(GLfloat**));
98- mat[ib] = (GLfloat****)malloc(ng[0] * sizeof(GLfloat***));
99- vf[ib] = (GLfloat****)malloc(ng[0] * sizeof(GLfloat***));
97+ eig[ib] = new GLfloat**[ng[0]];
98+ mat[ib] = new GLfloat***[ng[0]];
99+ vf[ib] = new GLfloat***[ng[0]];
100100 for (i0 = 0; i0 < ng[0]; i0++) {
101- eig[ib][i0] = (GLfloat**)malloc(ng[1] * sizeof(GLfloat*));
102- mat[ib][i0] = (GLfloat***)malloc(ng[1] * sizeof(GLfloat**));
103- vf[ib][i0] = (GLfloat***)malloc(ng[1] * sizeof(GLfloat**));
101+ eig[ib][i0] = new GLfloat*[ng[1]];
102+ mat[ib][i0] = new GLfloat**[ng[1]];
103+ vf[ib][i0] = new GLfloat**[ng[1]];
104104 for (i1 = 0; i1 < ng[1]; i1++) {
105- eig[ib][i0][i1] = (GLfloat*)malloc(ng[2] * sizeof(GLfloat));
106- mat[ib][i0][i1] = (GLfloat**)malloc(ng[2] * sizeof(GLfloat*));
107- vf[ib][i0][i1] = (GLfloat**)malloc(ng[2] * sizeof(GLfloat*));
105+ eig[ib][i0][i1] = new GLfloat[ng[2]];
106+ mat[ib][i0][i1] = new GLfloat*[ng[2]];
107+ vf[ib][i0][i1] = new GLfloat*[ng[2]];
108108 for (i2 = 0; i2 < ng[2]; i2++) {
109- mat[ib][i0][i1][i2] = (GLfloat*)malloc(3 * sizeof(GLfloat));
110- vf[ib][i0][i1][i2] = (GLfloat*)malloc(3 * sizeof(GLfloat));
109+ mat[ib][i0][i1][i2] = new GLfloat[3];
110+ vf[ib][i0][i1][i2] = new GLfloat[3];
111111 }
112112 }/*for (i1 = 0; i1 < ng[1]; i1++)*/
113113 }/*for (i0 = 0; i0 < ng[0]; i0++)*/
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -216,19 +216,19 @@ static void menu_equator(
216216 for (ib = 0; ib < nb; ++ib) {
217217 for (ii = 0; ii < nequator[ib]; ++ii) {
218218 for (jj = 0; jj < 2; ++jj) {
219- free(kveq[ib][ii][jj]);
219+ delete[] kveq[ib][ii][jj];
220220 }/*for (i1 = 0; i1 < 2; ++i1)*/
221- free(kveq[ib][ii]);
221+ delete[] kveq[ib][ii];
222222 }/*for (i0 = 0; i0 < nequator[ib]; ++i0)*/
223- free(kveq[ib]);
224- free(kveq_rot[ib]);
225- free(nmleq[ib]);
226- free(clreq[ib]);
223+ delete[] kveq[ib];
224+ delete[] kveq_rot[ib];
225+ delete[] nmleq[ib];
226+ delete[] clreq[ib];
227227 }/*for (ib = 0; ib < nb; ++ib)*/
228- free(kveq);
229- free(kveq_rot);
230- free(nmleq);
231- free(clreq);
228+ delete[] kveq;
229+ delete[] kveq_rot;
230+ delete[] nmleq;
231+ delete[] clreq;
232232
233233 query = 1; equator();
234234 query = 0; equator();
@@ -370,13 +370,13 @@ static void menu_section(
370370 Free variables for Fermi line
371371 */
372372 for (ib = 0; ib < nb; ++ib) {
373- free(kv2d[ib]);
374- free(clr2d[ib]);
375- free(nml2d[ib]);
373+ delete[] kv2d[ib];
374+ delete[] clr2d[ib];
375+ delete[] nml2d[ib];
376376 }/*for (ib = 0; ib < nb; ++ib)*/
377- free(kv2d);
378- free(clr2d);
379- free(nml2d);
377+ delete[] kv2d;
378+ delete[] clr2d;
379+ delete[] nml2d;
380380
381381 calc_2dbz();
382382 query = 1; calc_section();
--- a/src/read_file.cpp
+++ b/src/read_file.cpp
@@ -43,14 +43,14 @@ THE SOFTWARE.
4343 /**
4444 @brief Input from Fermi surface file
4545 */
46-void read_file(
46+int read_file(
4747 char *fname//!<[in] Input file name
4848 )
4949 {
50- int ib, i, j, i0, i1, i2, ii0, ii1, ii2, ierr;
50+ int ib, i, j, i0, i1, i2, ii0, ii1, ii2, ierr, iaxis;
5151 FILE *fp;
5252 char* ctemp1;
53- char ctemp2[256], rct;
53+ char ctemp2[256];
5454 int lshift; //!< Switch for shifted Brillouin zone
5555 /*
5656 Open input file.
@@ -59,7 +59,7 @@ void read_file(
5959 if ((fp = fopen(fname, "r")) == NULL) {
6060 printf("file open error!!\n");
6161 printf(" Press any key to exit.\n");
62- getchar();
62+ ierr = getchar();
6363 exit(EXIT_FAILURE);
6464 }
6565 printf("\n");
@@ -69,25 +69,7 @@ void read_file(
6969 k-point grid
7070 */
7171 ctemp1 = fgets(ctemp2, 256, fp);
72- ierr = sscanf(ctemp2, "%d%d%d%s", &ng0[0], &ng0[1], &ng0[2], &rct);
73- rct = tolower(rct);
74- if (ierr <= 3) rct = 'r';
75- if (rct == 'r') {
76- printf(" Real k-dependent quantity.\n");
77- color_scale = 1;
78- }
79- else if (rct == 'c') {
80- printf(" Complex k-dependent quantity.\n");
81- color_scale = 2;
82- }
83- else if (rct == 't') {
84- printf(" Tri-number k-dependent quantity.\n");
85- color_scale = 3;
86- }
87- else {
88- printf(" Error! r or c is allowed. Input %c\n", rct);
89- exit(-1);
90- }
72+ ierr = sscanf(ctemp2, "%d%d%d", &ng0[0], &ng0[1], &ng0[2]);
9173
9274 if (ierr == 0) printf("error ! reading ng");
9375 printf(" k point grid : %d %d %d \n", ng0[0], ng0[1], ng0[2]);
@@ -119,13 +101,13 @@ void read_file(
119101 ierr = fscanf(fp, "%d", &nb);
120102 if (ierr == 0) printf("error ! reading nb");
121103 printf(" # of bands : %d\n", nb);
122- ntri = (int*)malloc(nb * sizeof(int));
123- ntri_th = (int**)malloc(nb * sizeof(int*));
124- for (ib = 0; ib < nb; ib++) ntri_th[ib] = (int*)malloc(nthreads * sizeof(int));
125- nnl = (int*)malloc(nb * sizeof(int));
126- n2d = (int*)malloc(nb * sizeof(int));
127- nequator = (int*)malloc(nb * sizeof(int));
128- draw_band = (int*)malloc(nb * sizeof(int));
104+ ntri = new int[nb];
105+ ntri_th = new int*[nb];
106+ for (ib = 0; ib < nb; ib++) ntri_th[ib] = new int[nthreads];
107+ nnl = new int[nb];
108+ n2d = new int[nb];
109+ nequator = new int[nb];
110+ draw_band = new int[nb];
129111 for (ib = 0; ib < nb; ib++) draw_band[ib] = 1;
130112 /*
131113 Reciplocal lattice vectors
@@ -154,33 +136,33 @@ void read_file(
154136 /*
155137 Allocation of Kohn-Sham energies $ matrix elements
156138 */
157- eig0 = (GLfloat****)malloc(nb * sizeof(GLfloat***));
158- eig = (GLfloat****)malloc(nb * sizeof(GLfloat***));
159- mat0 = (GLfloat*****)malloc(nb * sizeof(GLfloat****));
160- mat = (GLfloat*****)malloc(nb * sizeof(GLfloat****));
161- vf = (GLfloat*****)malloc(nb * sizeof(GLfloat****));
139+ eig0 = new GLfloat * **[nb];
140+ eig = new GLfloat * **[nb];
141+ mat0 = new GLfloat * ***[nb];
142+ mat = new GLfloat * ***[nb];
143+ vf = new GLfloat * ***[nb];
162144 for (ib = 0; ib < nb; ib++) {
163- eig0[ib] = (GLfloat***)malloc(ng0[0] * sizeof(GLfloat**));
164- eig[ib] = (GLfloat***)malloc(ng0[0] * sizeof(GLfloat**));
165- mat0[ib] = (GLfloat****)malloc(ng0[0] * sizeof(GLfloat***));
166- mat[ib] = (GLfloat****)malloc(ng0[0] * sizeof(GLfloat***));
167- vf[ib] = (GLfloat****)malloc(ng0[0] * sizeof(GLfloat***));
145+ eig0[ib] = new GLfloat**[ng0[0]];
146+ eig[ib] = new GLfloat**[ng0[0]];
147+ mat0[ib] = new GLfloat***[ng0[0]];
148+ mat[ib] = new GLfloat***[ng0[0]];
149+ vf[ib] = new GLfloat***[ng0[0]];
168150 for (i0 = 0; i0 < ng0[0]; i0++) {
169- eig0[ib][i0] = (GLfloat**)malloc(ng0[1] * sizeof(GLfloat*));
170- eig[ib][i0] = (GLfloat**)malloc(ng0[1] * sizeof(GLfloat*));
171- mat0[ib][i0] = (GLfloat***)malloc(ng0[1] * sizeof(GLfloat**));
172- mat[ib][i0] = (GLfloat***)malloc(ng0[1] * sizeof(GLfloat**));
173- vf[ib][i0] = (GLfloat***)malloc(ng0[1] * sizeof(GLfloat**));
151+ eig0[ib][i0] = new GLfloat*[ng0[1]];
152+ eig[ib][i0] = new GLfloat*[ng0[1]];
153+ mat0[ib][i0] = new GLfloat**[ng0[1]];
154+ mat[ib][i0] = new GLfloat**[ng0[1]];
155+ vf[ib][i0] = new GLfloat**[ng0[1]];
174156 for (i1 = 0; i1 < ng0[1]; i1++) {
175- eig0[ib][i0][i1] = (GLfloat*)malloc(ng0[2] * sizeof(GLfloat));
176- eig[ib][i0][i1] = (GLfloat*)malloc(ng0[2] * sizeof(GLfloat));
177- mat0[ib][i0][i1] = (GLfloat**)malloc(ng0[2] * sizeof(GLfloat*));
178- mat[ib][i0][i1] = (GLfloat**)malloc(ng0[2] * sizeof(GLfloat*));
179- vf[ib][i0][i1] = (GLfloat**)malloc(ng0[2] * sizeof(GLfloat*));
157+ eig0[ib][i0][i1] = new GLfloat[ng0[2]];
158+ eig[ib][i0][i1] = new GLfloat[ng0[2]];
159+ mat0[ib][i0][i1] = new GLfloat*[ng0[2]];
160+ mat[ib][i0][i1] = new GLfloat*[ng0[2]];
161+ vf[ib][i0][i1] = new GLfloat*[ng0[2]];
180162 for (i2 = 0; i2 < ng0[2]; ++i2) {
181- mat0[ib][i0][i1][i2] = (GLfloat*)malloc(3 * sizeof(GLfloat));
182- mat[ib][i0][i1][i2] = (GLfloat*)malloc(3 * sizeof(GLfloat));
183- vf[ib][i0][i1][i2] = (GLfloat*)malloc(3 * sizeof(GLfloat));
163+ mat0[ib][i0][i1][i2] = new GLfloat[3];
164+ mat[ib][i0][i1][i2] = new GLfloat[3];
165+ vf[ib][i0][i1][i2] = new GLfloat[3];
184166 }
185167 }
186168 }
@@ -206,33 +188,29 @@ void read_file(
206188 /*
207189 Matrix elements
208190 */
209- for (ib = 0; ib < nb; ++ib) {
210- for (i0 = 0; i0 < ng0[0]; ++i0) {
211- if (lshift != 0) ii0 = i0;
212- else ii0 = modulo(i0 + (ng0[0] + 1) / 2, ng0[0]);
213- for (i1 = 0; i1 < ng0[1]; ++i1) {
214- if (lshift != 0) ii1 = i1;
215- else ii1 = modulo(i1 + (ng0[1] + 1) / 2, ng0[1]);
216- for (i2 = 0; i2 < ng0[2]; ++i2) {
217- if (lshift != 0) ii2 = i2;
218- else ii2 = modulo(i2 + (ng0[2] + 1) / 2, ng0[2]);
219- if (rct == 'r') {
220- ierr = fscanf(fp, "%e", &mat0[ib][ii0][ii1][ii2][0]);
221- mat0[ib][ii0][ii1][ii2][1] = 0.0;
222- mat0[ib][ii0][ii1][ii2][2] = 0.0;
223- }
224- else if (rct == 'c') {
225- ierr = fscanf(fp, "%e%e", &mat0[ib][ii0][ii1][ii2][0], &mat0[ib][ii0][ii1][ii2][1]);
226- mat0[ib][ii0][ii1][ii2][2] = 0.0;
227- }
228- else
229- ierr = fscanf(fp, "%e%e%e",
230- &mat0[ib][ii0][ii1][ii2][0], &mat0[ib][ii0][ii1][ii2][1], &mat0[ib][ii0][ii1][ii2][2]);
231- }/*for (i2 = 0; i2 < ng0[2]; ++i2)*/
232- }/*for (i1 = 0; i1 < ng0[1]; ++i1)*/
233- }/*for (i0 = 0; i0 < ng0[0]; ++i0)*/
234- }/*for (ib = 0; ib < nb; ++ib)*/
191+ for (iaxis = 0; iaxis < 3; iaxis++) {
192+ for (ib = 0; ib < nb; ++ib) {
193+ for (i0 = 0; i0 < ng0[0]; ++i0) {
194+ if (lshift != 0) ii0 = i0;
195+ else ii0 = modulo(i0 + (ng0[0] + 1) / 2, ng0[0]);
196+ for (i1 = 0; i1 < ng0[1]; ++i1) {
197+ if (lshift != 0) ii1 = i1;
198+ else ii1 = modulo(i1 + (ng0[1] + 1) / 2, ng0[1]);
199+ for (i2 = 0; i2 < ng0[2]; ++i2) {
200+ if (lshift != 0) ii2 = i2;
201+ else ii2 = modulo(i2 + (ng0[2] + 1) / 2, ng0[2]);
202+ ierr = fscanf(fp, "%e", &mat0[ib][ii0][ii1][ii2][iaxis]);
203+ if (ierr == EOF) {
204+ fclose(fp);
205+ return iaxis;
206+ }
207+ }/*for (i2 = 0; i2 < ng0[2]; ++i2)*/
208+ }/*for (i1 = 0; i1 < ng0[1]; ++i1)*/
209+ }/*for (i0 = 0; i0 < ng0[0]; ++i0)*/
210+ }/*for (ib = 0; ib < nb; ++ib)*/
211+ }
235212 fclose(fp);
213+ return 3;
236214 } /* read_file */
237215 /*
238216 @brief Make all characters lower
@@ -261,7 +239,7 @@ int read_batch(
261239 if ((fp = fopen(batch_name, "r")) == NULL) {
262240 printf("file open error!!\n");
263241 printf(" Press any key to exit.\n");
264- getchar();
242+ ierr = getchar();
265243 exit(EXIT_FAILURE);
266244 }
267245
--- a/src/read_file.hpp
+++ b/src/read_file.hpp
@@ -33,5 +33,5 @@ THE SOFTWARE.
3333 #include <OpenGL/gl.h>
3434 #endif
3535
36-void read_file(char *fname/**<[in] fname Input file name*/);
36+int read_file(char *fname/**<[in] fname Input file name*/);
3737 int read_batch(GLfloat minmax[3][2]);
--- a/src/section.cpp
+++ b/src/section.cpp
@@ -367,13 +367,13 @@ void calc_section() {
367367 /*
368368 Allocation of Fermi-lines
369369 */
370- kv2d = (GLfloat**)malloc(nb * sizeof(GLfloat*));
371- clr2d = (GLfloat**)malloc(nb * sizeof(GLfloat*));
372- nml2d = (GLfloat**)malloc(nb * sizeof(GLfloat*));
370+ kv2d = new GLfloat*[nb];
371+ clr2d = new GLfloat*[nb];
372+ nml2d = new GLfloat*[nb];
373373 for (ib = 0; ib < nb; ++ib) {
374- kv2d[ib] = (GLfloat*)malloc(6 * n2d[ib] * sizeof(GLfloat));
375- nml2d[ib] = (GLfloat*)malloc(6 * n2d[ib] * sizeof(GLfloat));
376- clr2d[ib] = (GLfloat*)malloc(8 * n2d[ib] * sizeof(GLfloat));
374+ kv2d[ib] = new GLfloat[6 * n2d[ib]];
375+ nml2d[ib] = new GLfloat[6 * n2d[ib]];
376+ clr2d[ib] = new GLfloat[8 * n2d[ib]];
377377 for (itri = 0; itri < n2d[ib]; itri++) {
378378 for (i = 0; i < 6; i++)nml2d[ib][i + itri * 6] = 0.0f;
379379 for (i = 0; i < 2; i++)nml2d[ib][2 + i * 3 + itri * 6] = 1.0f;
Show on old repository browser