1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
/**********************************************************************
intensity_map.c:
intensity_map.c is a code to generate data for intensity map of the
unfolded spectral weight obtained by the unfolding procedure for bands.
The unfolded spectral weight w is smeared out by a Lorentzian function
w/((k/hk)^2+(e/he)^2+1), where k is momentum, and e is energy.
This code follows GNU-GPL.
Compile: gcc intensity_map.c -lm -o intensity_map
Usage: ./intensity_map file -c 3 -k 0.2 -e 0.1 -l -10 -u 10 > outputfile
-c column of spectral weight you analyze
-k degree of smearing (Bohr^{-1}) in k-vector
-e degree of smearing (eV) in energy
-l lower bound of energy for drawing the map
-u upper bound of energy for drawing the map
Log of intensity_map.c:
04/Feb/2016 Released by T. Ozaki
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i,j,q,po_c,po_k,po_e,n,po,ret;
int po_l,po_u,l_i,u_i;
int c_i,k_i,e_i,nline,nelement,tnelement;
int column_index;
int kmesh,emesh;
double dk,de,hk,he,tmp,eu,el;
double *momentum,*energy,*weight;
double kmin,kmax,emin,emax;
double kv,ev,sum,se,sk;
char *buf,*token;
FILE *fp1,*fp2;
/***********************************
analyze the arguments
************************************/
po_c = 0;
po_k = 0;
po_e = 0;
po_l = 0;
po_u = 0;
for (i=1; i<argc; i++){
if (strcmp(argv[i],"-c")==0){
po_c = 1;
c_i = i;
}
if (strcmp(argv[i],"-k")==0){
po_k = 1;
k_i = i;
}
if (strcmp(argv[i],"-e")==0){
po_e = 1;
e_i = i;
}
if (strcmp(argv[i],"-l")==0){
po_l = 1;
l_i = i;
}
if (strcmp(argv[i],"-u")==0){
po_u = 1;
u_i = i;
}
}
if ( po_c==0 || po_k==0 || po_e==0 || po_l==0 || po_u==0 || argc!=12 ){
printf("Invalid argument\n");
exit(0);
}
/* -c */
column_index = atoi(argv[c_i+1]);
/* -k */
hk = atof(argv[k_i+1]);
/* -e */
he = atof(argv[e_i+1]);
/* -l */
el = atof(argv[l_i+1]);
/* -u */
eu = atof(argv[u_i+1]);
/***********************************
read the file
************************************/
if ((fp1 = fopen(argv[1],"r")) != NULL){
/* get the length of one line */
po = 0;
n = 0;
do {
if (( q=fgetc(fp1))=='\n') po = 1;
n++;
} while (po==0);
buf = (char*)malloc(sizeof(char)*(n+100));
/* get the nline by reading line by line */
rewind( fp1 );
nline = 0;
while ( fgets(buf, n+30, fp1) != NULL ) {
nline++;
}
/* allocate arrays */
momentum = (double*)malloc(sizeof(double)*nline);
energy = (double*)malloc(sizeof(double)*nline);
weight = (double*)malloc(sizeof(double)*nline);
/* get nelement by reading the file again */
rewind( fp1 );
tnelement = 0;
while(( ret = fscanf( fp1 , "%lf" , buf )) != EOF ) {
tnelement++;
}
nelement = tnelement/nline;
/* get momentum, energy, and weight */
rewind( fp1 );
for (i=0; i<nline; i++){
for (j=0; j<nelement; j++){
fscanf(fp1,"%lf",&tmp);
if (j==0) momentum[i] = tmp;
else if (j==1) energy[i] = tmp;
else if (j==(column_index-1)) weight[i] = tmp;
}
}
/* close fp1 */
fclose(fp1);
}
else{
printf("could not find %s\n",argv[1]);
}
/***********************************
calculate the intensity map
************************************/
/* find min and max */
kmin = 100000.0;
kmax =-100000.0;
emin = 100000.0;
emax =-100000.0;
for (i=0; i<nline; i++){
if (momentum[i]<kmin) kmin = momentum[i];
if (kmax<momentum[i]) kmax = momentum[i];
if (energy[i]<emin) emin = energy[i];
if (emax<energy[i]) emax = energy[i];
}
/* determine kmesh and emesh */
kmesh = 200;
emesh = 200;
/* calculated dk and ek */
dk = (kmax-kmin)/kmesh;
de = (eu-el)/emesh;
/* loop for kmesh and emesh */
for (i=0; i<=kmesh; i++){
kv = kmin + dk*(double)i;
for (j=0; j<=emesh; j++){
ev = el + de*(double)j;
/* loop for nline */
sum = 0.0;
for (q=0; q<nline; q++){
se = (ev - energy[q])/hk;
sk = (kv - momentum[q])/he;
sum += weight[q]/(se*se+sk*sk+1);
}
printf("%15.12f %15.12f %15.12f\n",kv,ev,sum);
}
printf("\n");
}
}
|