From fe9b4862250ffb9e709b61fc8a58bd0ee6cd700b Mon Sep 17 00:00:00 2001 From: ydan Date: Wed, 8 Jan 2025 20:31:59 -0600 Subject: [PATCH 1/3] update chgcar.H to handle file formats in newer VASP versions --- chgcar.H | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/chgcar.H b/chgcar.H index d0da7ca..91b1f8a 100644 --- a/chgcar.H +++ b/chgcar.H @@ -199,10 +199,25 @@ void read_CHGCAR_header(FILE* infile, char* comment, double& a0, sscanf(dump, "%lf %lf %lf", latt+i, latt+3+i, latt+6+i); } - //++ number of atoms + /* + * 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 + */ 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 = strtol(strp, &endp, 10); + if (endp == strp) { // skip the current line and read the next line if we see a list of element names + 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; @@ -249,13 +264,28 @@ void skip_CHGCAR_header(FILE* infile) //++ lattice vectors for (int i=0; i<3; ++i) fgets(dump, sizeof(dump), infile); - //++ number of atoms + /* + * 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 + */ 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 = strtol(strp, &endp, 10); + if (endp == strp) { // skip the current line and read the next line if we see a list of element names + fgets(dump, sizeof(dump), infile); + } + endp = dump; + // Modification ends here. --Yang + + //++ number of atoms do { strp=endp; - int i = strtol(strp, &endp, 10); + i = strtol(strp, &endp, 10); if (strp!=endp) Natoms += i; } while (strp!=endp); From 9a16a0638cbe5a19ca1ae1ec01655ae5d5d9778d Mon Sep 17 00:00:00 2001 From: ydan Date: Wed, 8 Jan 2025 23:10:24 -0600 Subject: [PATCH 2/3] minor updates to address warnings raised by current GCC compilers, tested on GCC 13 --- chgcar.H | 66 ++++++++++++++++++++++++++-------------------------- weight_int.C | 2 +- wsflux.C | 8 +++---- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/chgcar.H b/chgcar.H index 91b1f8a..6b49061 100644 --- a/chgcar.H +++ b/chgcar.H @@ -40,10 +40,10 @@ 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; } @@ -51,14 +51,14 @@ void read_grid(FILE* infile, double* rho, int Ng) n=0; for (line=0, n=0; line= 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;} @@ -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 Date: Thu, 9 Jan 2025 01:21:07 -0600 Subject: [PATCH 3/3] update weight_int.C and Makefile --- Makefile | 6 ++++-- weight_int.C | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5ef9ee1..58de1a5 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/weight_int.C b/weight_int.C index 3ca6b69..c07271a 100644 --- a/weight_int.C +++ b/weight_int.C @@ -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; @@ -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) { @@ -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]) ||