git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15426 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2016-08-03 16:09:38 +00:00
parent 56502c7c09
commit 38226b8086
11 changed files with 284 additions and 86 deletions

View File

@ -180,6 +180,7 @@ Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
sprintf(format_bigint_one_def,"%%8%s",&bigint_format[1]);
sprintf(format_bigint_multi_def,"%%14%s",&bigint_format[1]);
format_line_user = NULL;
format_float_user = NULL;
format_int_user = NULL;
format_bigint_user = NULL;
@ -195,7 +196,8 @@ Thermo::~Thermo()
deallocate();
// format strings
delete [] format_line_user;
delete [] format_float_user;
delete [] format_int_user;
delete [] format_bigint_user;
@ -225,22 +227,37 @@ void Thermo::init()
// add '/n' every 3 values if lineflag = MULTILINE
// add trailing '/n' to last value
char *ptr;
char *format_line = NULL;
if (format_line_user) {
int n = strlen(format_line_user) + 1;
format_line = new char[n];
strcpy(format_line,format_line_user);
}
char *ptr,*format_line_ptr;
for (i = 0; i < nfield; i++) {
format[i][0] = '\0';
if (lineflag == MULTILINE && i % 3 == 0) strcat(format[i],"\n");
if (format_user[i]) ptr = format_user[i];
if (format_line) {
if (i == 0) format_line_ptr = strtok(format_line," \0");
else format_line_ptr = strtok(NULL," \0");
}
if (format_column_user[i]) ptr = format_column_user[i];
else if (vtype[i] == FLOAT) {
if (format_float_user) ptr = format_float_user;
else if (format_line_user) ptr = format_line_ptr;
else if (lineflag == ONELINE) ptr = format_float_one_def;
else if (lineflag == MULTILINE) ptr = format_float_multi_def;
} else if (vtype[i] == INT) {
if (format_int_user) ptr = format_int_user;
else if (format_line_user) ptr = format_line_ptr;
else if (lineflag == ONELINE) ptr = format_int_one_def;
else if (lineflag == MULTILINE) ptr = format_int_multi_def;
} else if (vtype[i] == BIGINT) {
if (format_bigint_user) ptr = format_bigint_user;
else if (format_line_user) ptr = format_line_ptr;
else if (lineflag == ONELINE) ptr = format_bigint_one_def;
else if (lineflag == MULTILINE) ptr = format_bigint_multi_def;
}
@ -248,9 +265,10 @@ void Thermo::init()
n = strlen(format[i]);
if (lineflag == ONELINE) sprintf(&format[i][n],"%s ",ptr);
else sprintf(&format[i][n],"%-8s = %s ",keyword[i],ptr);
if (i == nfield-1) strcat(format[i],"\n");
}
strcat(format[nfield-1],"\n");
delete [] format_line;
// find current ptr for each Compute ID
@ -540,22 +558,50 @@ void Thermo::modify_params(int narg, char **arg)
iarg += 2;
} else if (strcmp(arg[iarg],"format") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command");
if (strcmp(arg[iarg+1],"none") == 0) {
delete [] format_line_user;
delete [] format_int_user;
delete [] format_bigint_user;
delete [] format_float_user;
format_line_user = NULL;
format_int_user = NULL;
format_bigint_user = NULL;
format_float_user = NULL;
for (int i = 0; i < nfield_initial; i++) {
delete [] format_column_user[i];
format_column_user[i] = NULL;
}
iarg += 2;
continue;
}
if (iarg+3 > narg) error->all(FLERR,"Illegal thermo_modify command");
if (strcmp(arg[iarg+1],"int") == 0) {
if (strcmp(arg[iarg+1],"line") == 0) {
delete [] format_line_user;
int n = strlen(arg[iarg+2]) + 1;
format_line_user = new char[n];
strcpy(format_line_user,arg[iarg+2]);
} else if (strcmp(arg[iarg+1],"int") == 0) {
if (format_int_user) delete [] format_int_user;
int n = strlen(arg[iarg+2]) + 1;
format_int_user = new char[n];
strcpy(format_int_user,arg[iarg+2]);
if (format_bigint_user) delete [] format_bigint_user;
n = strlen(format_int_user) + 3;
n = strlen(format_int_user) + 8;
format_bigint_user = new char[n];
// replace "d" in format_int_user with bigint format specifier
// use of &str[1] removes leading '%' from BIGINT_FORMAT string
char *ptr = strchr(format_int_user,'d');
if (ptr == NULL)
error->all(FLERR,
"Thermo_modify int format does not contain d character");
char str[8];
sprintf(str,"%s",BIGINT_FORMAT);
*ptr = '\0';
sprintf(format_bigint_user,"%s%s%s",format_int_user,
BIGINT_FORMAT,ptr+1);
sprintf(format_bigint_user,"%s%s%s",format_int_user,&str[1],ptr+1);
*ptr = 'd';
} else if (strcmp(arg[iarg+1],"float") == 0) {
if (format_float_user) delete [] format_float_user;
@ -566,10 +612,10 @@ void Thermo::modify_params(int narg, char **arg)
int i = force->inumeric(FLERR,arg[iarg+1]) - 1;
if (i < 0 || i >= nfield_initial)
error->all(FLERR,"Illegal thermo_modify command");
if (format_user[i]) delete [] format_user[i];
if (format_column_user[i]) delete [] format_column_user[i];
int n = strlen(arg[iarg+2]) + 1;
format_user[i] = new char[n];
strcpy(format_user[i],arg[iarg+2]);
format_column_user[i] = new char[n];
strcpy(format_column_user[i],arg[iarg+2]);
}
iarg += 3;
@ -594,8 +640,8 @@ void Thermo::allocate()
format = new char*[n];
for (int i = 0; i < n; i++) format[i] = new char[32];
format_user = new char*[n];
for (int i = 0; i < n; i++) format_user[i] = NULL;
format_column_user = new char*[n];
for (int i = 0; i < n; i++) format_column_user[i] = NULL;
field2index = new int[n];
argindex1 = new int[n];
@ -632,8 +678,8 @@ void Thermo::deallocate()
for (int i = 0; i < n; i++) delete [] format[i];
delete [] format;
for (int i = 0; i < n; i++) delete [] format_user[i];
delete [] format_user;
for (int i = 0; i < n; i++) delete [] format_column_user[i];
delete [] format_column_user;
delete [] field2index;
delete [] argindex1;