Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ CFLAGS ?= -O5
# have_inline defined for gsl to use extern inline functions when possible:
CXXFLAGS ?= -O5 -DHAVE_INLINE $(OSDEFS)

TARGET = wsflux
TARGETS = weight_int wsflux

INCLUDES = *.H
# INCLUDES = io.H multipoly.H eam.H

.PHONY: all clean archive

all: $(TARGET)
all: $(TARGETS)

weight_int: weight_int.C $(INCLUDES)

wslux: wsflux.C $(INCLUDES)

Expand Down
94 changes: 62 additions & 32 deletions chgcar.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ void read_grid(FILE* infile, double* rho, int Ng)
if (infile==NULL) return;

int n, line, nl;
char dump[512];
char dump[512], *p_fgets;

if (Ng == 0) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
return;
}

nl = Ng/READ_stride;
n=0;

for (line=0, n=0; line<nl; ++line, n+=READ_stride) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%lf %lf %lf %lf %lf",
rho+n, rho+n+1, rho+n+2, rho+n+3, rho+n+4);
}

if (n!=Ng) {
// last line...
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
char *strp, *endp;
for (strp=dump; n<Ng; ++n, strp=endp)
rho[n] = strtod(strp, &endp);
Expand All @@ -73,25 +73,25 @@ void read_grid(FILE* infile, double* rho, int Ng, int* index)
if (infile==NULL) return;

int n, line, nl;
char dump[512];
char dump[512], *p_fgets;

if (Ng == 0) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
return;
}

nl = Ng/READ_stride;
n=0;

for (line=0, n=0; line<nl; ++line, n+=READ_stride) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%lf %lf %lf %lf %lf",
rho+index[n], rho+index[n+1], rho+index[n+2], rho+index[n+3], rho+index[n+4]);
}

if (n!=Ng) {
// last line...
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
char *strp, *endp;
for (strp=dump; n<Ng; ++n, strp=endp)
rho[index[n]] = strtod(strp, &endp);
Expand All @@ -110,7 +110,7 @@ void fort_printf(char* str, const double& x)
if (x >= 0) str[0] = '0';
// fix the exponent (only if non-zero)
if (x != 0) {
int expon = strtol(str+14, (char**)NULL, 10);
int expon = (int)strtol(str+14, (char**)NULL, 10);
expon++;
if (expon>=0) str[14] = '+';
else {str[14] = '-'; expon = -expon;}
Expand All @@ -131,7 +131,7 @@ void write_grid(FILE* outfile, double* rho, int Ng)
return;
}
int n;
char dump[18];
char dump[28];
for (n=0; n<Ng; ++n) {
fort_printf(dump, rho[n]);
fprintf(outfile, " %s", dump);
Expand All @@ -150,7 +150,7 @@ void write_grid(FILE* outfile, double* rho, int Ng, int* index)
return;
}
int n;
char dump[18];
char dump[28];
for (n=0; n<Ng; ++n) {
fort_printf(dump, rho[index[n]]);
fprintf(outfile, " %s", dump);
Expand Down Expand Up @@ -180,33 +180,48 @@ void read_CHGCAR_header(FILE* infile, char* comment, double& a0,
{
if (infile==NULL) return;

char dump[512];
char dump[512], *p_fgets;
int i;

//++ comment line
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
char *p =
stpcpy(comment, dump);
(p-1)[0] = '\0'; // remove the newline at the end of dump.

//++ a0
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%lf", &a0);

//++ lattice vectors
for (i=0; i<3; ++i) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%lf %lf %lf", latt+i, latt+3+i, latt+6+i);
}

//++ number of atoms
fgets(dump, sizeof(dump), infile);
/*
* In VASP 5 or later versions one should see a line of text specifying the element names here
* whereas in older versions no such line exists, but atom numbers are written here.
* I modified Dallas's original code so that it works with both versions. --Yang
*/
p_fgets = fgets(dump, sizeof(dump), infile);
char *strp, *endp=dump;
int types = 0, Natoms=0;

// check to see if this line is a list of element names or atom numbers
strp = endp;
i = (int)strtol(strp, &endp, 10);
if (endp == strp) { // skip the current line and read the next line if we see a list of element names
p_fgets = fgets(dump, sizeof(dump), infile);
}
endp = dump;
// Modification ends here. --Yang

//++ number of atoms
if (READATOMS && (Natom==NULL)) Natom=new int[128];
do {
strp=endp;
i = strtol(strp, &endp, 10);
i = (int)strtol(strp, &endp, 10);
if (strp!=endp) {
Natoms += i;
if (READATOMS) Natom[types] = i;
Expand All @@ -216,12 +231,12 @@ void read_CHGCAR_header(FILE* infile, char* comment, double& a0,
if (READATOMS) Natom[types] = -1;

//++ direct coord. (CHGCAR should always be output with "Direct")
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);

//++ atom positions
if (READATOMS) uatom = new double*[Natoms];
for (i=0; i<Natoms; ++i) {
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
if (READATOMS) {
uatom[i] = new double[3];
double* in_vect = uatom[i];
Expand All @@ -230,44 +245,59 @@ void read_CHGCAR_header(FILE* infile, char* comment, double& a0,
}

//++ blank line
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
}


void skip_CHGCAR_header(FILE* infile)
{
if (infile==NULL) return;

char dump[512];
char dump[512], *p_fgets;

//++ comment line
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);

//++ a0
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);

//++ lattice vectors
for (int i=0; i<3; ++i) fgets(dump, sizeof(dump), infile);

//++ number of atoms
fgets(dump, sizeof(dump), infile);
for (int i=0; i<3; ++i) p_fgets = fgets(dump, sizeof(dump), infile);

/*
* In VASP 5 or later versions one should see a line of text specifying the element names here
* whereas in older versions no such line exists, but atom numbers are written here.
* I modified Dallas's original code so that it works with both versions. --Yang
*/
p_fgets = fgets(dump, sizeof(dump), infile);
char *strp, *endp=dump;
int Natoms=0;

// check to see if this line is a list of element names or atom numbers
strp = endp;
int i = (int)strtol(strp, &endp, 10);
if (endp == strp) { // skip the current line and read the next line if we see a list of element names
p_fgets = fgets(dump, sizeof(dump), infile);
}
endp = dump;
// Modification ends here. --Yang

//++ number of atoms
do {
strp=endp;
int i = strtol(strp, &endp, 10);
i = (int)strtol(strp, &endp, 10);
if (strp!=endp) Natoms += i;
} while (strp!=endp);

//++ direct coord. (CHGCAR should always be output with "Direct")
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);

//++ atom positions
for (int i=0; i<Natoms; ++i)
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);

//++ blank line
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
}


Expand Down
8 changes: 4 additions & 4 deletions weight_int.C
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int main ( int argc, char **argv )
char* OUTBASE = NULL; // basename for output

char ch;
while ((ch = getopt(argc, argv, "Vaso:n:hvtm:")) != -1) {
while ((ch = (char)getopt(argc, argv, "Vaso:n:hvtm:")) != -1) {
switch (ch) {
case 'V':
VORONOI = 1;
Expand Down Expand Up @@ -235,7 +235,7 @@ int main ( int argc, char **argv )
if (TESTING) fprintf(stderr, "## reading %s\n", infile_name);

// parse that file...
char dump[512];
char dump[600];
char comment[512];
double a0, alatt[9], gridlatt[9], metric[9];

Expand All @@ -248,7 +248,7 @@ int main ( int argc, char **argv )
for (int d=0; d<9; ++d) metric[d] *= a0*a0;
int Natoms=0;
for (int nt=0; Natom[nt]>=0; ++nt) Natoms += Natom[nt];
fgets(dump, sizeof(dump), infile);
char *p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%d %d %d", Ngrid, Ngrid+1, Ngrid+2);

if (TESTING) {
Expand Down Expand Up @@ -338,7 +338,7 @@ int main ( int argc, char **argv )
continue;
}
skip_CHGCAR_header(infile);
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
int Ntemp[3];
sscanf(dump, "%d %d %d", Ntemp, Ntemp+1, Ntemp+2);
if ( (Ngrid[0] != Ntemp[0]) ||
Expand Down
8 changes: 4 additions & 4 deletions wsflux.C
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const char COMMENT_CHAR = '#';
const char EOF_CHAR = '&';

inline void nextnoncomment (FILE* infile, char* dump, const int &size)
{ do {fgets(dump, size, infile);}
{ do {char *p_fgets = fgets(dump, size, infile);}
while ((!feof(infile)) && (dump[0] == COMMENT_CHAR)); }


Expand Down Expand Up @@ -110,7 +110,7 @@ int main ( int argc, char **argv )
int MEMORY = 128; // Our default storage (not used)

char ch;
while ((ch = getopt(argc, argv, "hvtm:")) != -1) {
while ((ch = (char)getopt(argc, argv, "hvtm:")) != -1) {
switch (ch) {
case 'm':
MEMORY = (int)strtol(optarg, (char**)NULL, 10);
Expand Down Expand Up @@ -156,12 +156,12 @@ int main ( int argc, char **argv )
if (ERROR) exit(ERROR);

// parse that file...
char dump[512];
char dump[512], *p_fgets;
double a0, alatt[9];
int Ngrid[3];

read_CHGCAR_header(infile, dump, a0, alatt);
fgets(dump, sizeof(dump), infile);
p_fgets = fgets(dump, sizeof(dump), infile);
sscanf(dump, "%d %d %d", Ngrid, Ngrid+1, Ngrid+2);

if (TESTING) {
Expand Down