HΦ  3.1.0
eigenIO.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 /*-------------------------------------------------------------*/
17 #include "eigenIO.h"
18 
19 int comp(const void *p, const void *q) {
20  if(*(double *)p > *(double *)q) return 1;
21  if(*(double *)p < *(double *)q) return -1;
22  return 0;
23 }
24 
25 int OutputRealEigenValue(int xNsize, double *ene, char *filename) {
26  FILE *fp = NULL;
27  int i;
28  double *buffene = (double *) malloc(xNsize * sizeof(double));
29 
30  for(i = 0; i < xNsize; i++)
31  buffene[i] = ene[i];
32 
33  qsort(buffene, xNsize, sizeof(double), comp);
34 
35  fp = fopen(filename, "wb+");
36  if(fp == NULL) {
37  free(buffene);
38  return -1;
39  }
40 
41  fwrite(buffene, sizeof(double), xNsize, fp);
42 
43  fclose(fp);
44  free(buffene);
45 
46  return 0;
47 }
48 
49 int OutputCmpEigenValue(int xNsize, complex double *ene, char *filename) {
50  FILE *fp = NULL;
51  int i;
52  double *buffene = (double *) malloc(xNsize * sizeof(double));
53 
54  for(i = 0; i < xNsize; i++)
55  buffene[i] = creal(ene[i]);
56 
57  qsort(buffene, xNsize, sizeof(double), comp);
58 
59  fp = fopen(filename, "wb+");
60  if(fp == NULL) {
61  free(buffene);
62  return -1;
63  }
64 
65  fwrite(buffene, sizeof(double), xNsize, fp);
66 
67  fclose(fp);
68  free(buffene);
69 
70  return 0;
71 }
72 
73 int OutputRealEigenVec(int xNsize, const int nene, double **vec, const int nproc, char *filename) {
74  FILE *fp = NULL;
75 
76  fp = fopen(filename, "wb+");
77  if(fp == NULL) {
78  return -1;
79  }
80 
81  fwrite(vec[nene], sizeof(double), xNsize, fp);
82 
83  fclose(fp);
84 
85  return 0;
86 }
87 
88 int OutputCmpEigenVec(int xNsize, const int nene, complex double **vec, const int nproc, char *filename) {
89  FILE *fp = NULL;
90 
91  fp = fopen(filename, "wb+");
92  if(fp == NULL) {
93  return -1;
94  }
95 
96  fwrite(vec[nene], sizeof(complex double), xNsize, fp);
97 
98  fclose(fp);
99 
100  return 0;
101 }
102 
103 int InputRealEigenValue(int xNsize, double *ene, char *filename) {
104  FILE *fp = NULL;
105 
106  fp = fopen(filename, "rb+");
107  if(fp == NULL) {
108  return -1;
109  }
110 
111  fread(ene, sizeof(double), xNsize, fp);
112 
113  fclose(fp);
114 
115  return 0;
116 }
117 
118 int InputCmpEigenValue(int xNsize, complex double *ene, char *filename) {
119  FILE *fp = NULL;
120  int i = 0;
121 
122  fp = fopen(filename, "rb+");
123  if(fp == NULL) {
124  return -1;
125  }
126 
127  fread(ene, sizeof(complex double), xNsize, fp);
128 
129  fclose(fp);
130 
131  return 0;
132 }
133 
134 int InputRealEigenVec(int xNsize, const int nene, double **vec, const int nproc, char *filename) {
135  FILE *fp = NULL;
136 
137  fp = fopen(filename, "rb+");
138  if(fp == NULL) {
139  return -1;
140  }
141 
142  fread(vec[nene], sizeof(double), xNsize, fp);
143 
144  fclose(fp);
145 
146  return 0;
147 }
148 
149 int InputCmpEigenVec(int xNsize, const int nene, complex double **vec, const int nproc, char *filename) {
150  FILE *fp = NULL;
151 
152  fp = fopen(filename, "rb+");
153  if(fp == NULL) {
154  return -1;
155  }
156 
157  fread(vec[nene], sizeof(complex double), xNsize, fp);
158 
159  fclose(fp);
160 
161  return 0;
162 }
163 
int InputCmpEigenValue(int xNsize, complex double *ene, char *filename)
Definition: eigenIO.c:118
double complex ** vec
Definition: global.h:45
int OutputCmpEigenValue(int xNsize, complex double *ene, char *filename)
Definition: eigenIO.c:49
int OutputCmpEigenVec(int xNsize, const int nene, complex double **vec, const int nproc, char *filename)
Definition: eigenIO.c:88
int InputCmpEigenVec(int xNsize, const int nene, complex double **vec, const int nproc, char *filename)
Definition: eigenIO.c:149
int nproc
Number of processors, defined in InitializeMPI()
Definition: global.h:161
int InputRealEigenVec(int xNsize, const int nene, double **vec, const int nproc, char *filename)
Definition: eigenIO.c:134
int OutputRealEigenVec(int xNsize, const int nene, double **vec, const int nproc, char *filename)
Definition: eigenIO.c:73
int OutputRealEigenValue(int xNsize, double *ene, char *filename)
Definition: eigenIO.c:25
int comp(const void *p, const void *q)
Definition: eigenIO.c:19
int InputRealEigenValue(int xNsize, double *ene, char *filename)
Definition: eigenIO.c:103