HΦ  3.2.0
input.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 #include "input.h"
17 #include "FileIO.h"
18 #include "wrapperMPI.h"
19 
20 int inputHam(struct BindStruct *X){
21  //Input Ham
22  long int i=0;
23  long int ham_i=0;
24  long int ham_j=0;
25  long int imax = X->Check.idim_max;
26  long int ihermite=0;
27  long int itmp;
28  double dHam_re, dHam_im;
29  char ctmp[256], ctmp2[256];
30 
31  FILE *fp;
32  char sdt[D_FileNameMax];
33 
35  if(childfopenMPI(sdt,"r",&fp)!=0){
36  return -1;
37  }
38 
39  //skip: header
40  fgetsMPI(ctmp, sizeof(ctmp) / sizeof(char), fp);
41  //skip: read imax, imax, ihermite
42  fgetsMPI(ctmp, sizeof(ctmp) / sizeof(char), fp);
43  sscanf(ctmp, "%ld %ld %ld\n", &itmp, &itmp, &ihermite);
44  if(itmp != imax){
45  fprintf(stdoutMPI, "Error: The dimension of input Hamiltonian is wrong: input=%ld, idim=%ld.\n", itmp, imax);
46  return -1;
47  }
48  for(i=1; i<= ihermite; i++){
49  fgetsMPI(ctmp2, sizeof(ctmp2) / sizeof(char), fp);
50  sscanf(ctmp2, "%ld %ld %lf %lf\n",
51  &ham_i, &ham_j, &dHam_re, &dHam_im);
52  Ham[ham_i][ham_j]=dHam_re+I*dHam_im;
53  Ham[ham_j][ham_i]=conj(Ham[ham_i][ham_j]);
54  }
55  fclose(fp);
56  return 0;
57 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
#define D_FileNameMax
Definition: global.h:23
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.c:27
int inputHam(struct BindStruct *X)
Definition: input.c:20
Bind.
Definition: struct.h:409
double complex ** Ham
Definition: global.h:73
const char * cFileNamePhys_FullDiag_Ham
Definition: global.c:78
struct EDMainCalStruct X
Definition: struct.h:432
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
Definition: wrapperMPI.c:122
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.h:42
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165