From 55da46f3e3a3c287ab2be62fe59bcd50eb5e5105 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 1 Feb 2021 09:39:50 -0500 Subject: [PATCH] add ArgInfo support to some dump styles --- src/dump_cfg.cpp | 23 +- src/dump_custom.cpp | 598 ++++++++++++++++++++------------------------ src/dump_local.cpp | 114 ++++----- 3 files changed, 330 insertions(+), 405 deletions(-) diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index 9829280bb4..ed8df72096 100644 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -17,12 +17,15 @@ ------------------------------------------------------------------------- */ #include "dump_cfg.h" -#include + +#include "arg_info.h" #include "atom.h" #include "domain.h" #include "memory.h" #include "error.h" +#include + using namespace LAMMPS_NS; #define UNWRAPEXPAND 10.0 @@ -67,18 +70,14 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) : int i = 0; for (int iarg = 5; iarg < nfield; iarg++, i++) { - if ((strncmp(earg[iarg],"c_",2) == 0 || - strncmp(earg[iarg],"f_",2) == 0 || - strncmp(earg[iarg],"v_",2) == 0) && strchr(earg[iarg],'[')) { - char *ptr = strchr(earg[iarg],'['); - char *ptr2 = strchr(ptr,']'); - auxname[i] = new char[strlen(earg[iarg])]; - *ptr = '\0'; - *ptr2 = '\0'; - strcpy(auxname[i],earg[iarg]); - strcat(auxname[i],"_"); - strcat(auxname[i],ptr+1); + ArgInfo argi(earg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE + |ArgInfo::DNAME|ArgInfo::INAME); + if (argi.get_dim() == 1) { + std::string newarg(std::to_string(earg[iarg][0])); + newarg += '_' + argi.get_name() + '_' + std::to_string(argi.get_index1()); + auxname[i] = new char[newarg.size()+1]; + strcpy(auxname[i],newarg.c_str()); } else { auxname[i] = new char[strlen(earg[iarg]) + 1]; strcpy(auxname[i],earg[iarg]); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index dab19b2c5f..bacf2a51db 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -13,6 +13,7 @@ #include "dump_custom.h" +#include "arg_info.h" #include "atom.h" #include "compute.h" #include "domain.h" @@ -1252,327 +1253,302 @@ int DumpCustom::parse_fields(int narg, char **arg) { // customize by adding to if statement - int i; for (int iarg = 0; iarg < narg; iarg++) { - i = iarg; if (strcmp(arg[iarg],"id") == 0) { - pack_choice[i] = &DumpCustom::pack_id; - if (sizeof(tagint) == sizeof(smallint)) vtype[i] = Dump::INT; - else vtype[i] = Dump::BIGINT; + pack_choice[iarg] = &DumpCustom::pack_id; + if (sizeof(tagint) == sizeof(smallint)) vtype[iarg] = Dump::INT; + else vtype[iarg] = Dump::BIGINT; } else if (strcmp(arg[iarg],"mol") == 0) { if (!atom->molecule_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_molecule; - if (sizeof(tagint) == sizeof(smallint)) vtype[i] = Dump::INT; - else vtype[i] = Dump::BIGINT; + pack_choice[iarg] = &DumpCustom::pack_molecule; + if (sizeof(tagint) == sizeof(smallint)) vtype[iarg] = Dump::INT; + else vtype[iarg] = Dump::BIGINT; } else if (strcmp(arg[iarg],"proc") == 0) { - pack_choice[i] = &DumpCustom::pack_proc; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_proc; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"procp1") == 0) { - pack_choice[i] = &DumpCustom::pack_procp1; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_procp1; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"type") == 0) { - pack_choice[i] = &DumpCustom::pack_type; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_type; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"element") == 0) { - pack_choice[i] = &DumpCustom::pack_type; - vtype[i] = Dump::STRING; + pack_choice[iarg] = &DumpCustom::pack_type; + vtype[iarg] = Dump::STRING; } else if (strcmp(arg[iarg],"mass") == 0) { - pack_choice[i] = &DumpCustom::pack_mass; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_mass; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"x") == 0) { - pack_choice[i] = &DumpCustom::pack_x; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_x; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"y") == 0) { - pack_choice[i] = &DumpCustom::pack_y; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_y; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"z") == 0) { - pack_choice[i] = &DumpCustom::pack_z; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_z; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"xs") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_xs_triclinic; - else pack_choice[i] = &DumpCustom::pack_xs; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_xs_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_xs; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"ys") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_ys_triclinic; - else pack_choice[i] = &DumpCustom::pack_ys; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_ys_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_ys; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"zs") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_zs_triclinic; - else pack_choice[i] = &DumpCustom::pack_zs; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_zs_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_zs; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"xu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_xu_triclinic; - else pack_choice[i] = &DumpCustom::pack_xu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_xu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_xu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"yu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_yu_triclinic; - else pack_choice[i] = &DumpCustom::pack_yu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_yu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_yu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"zu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_zu_triclinic; - else pack_choice[i] = &DumpCustom::pack_zu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_zu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_zu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"xsu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_xsu_triclinic; - else pack_choice[i] = &DumpCustom::pack_xsu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_xsu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_xsu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"ysu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_ysu_triclinic; - else pack_choice[i] = &DumpCustom::pack_ysu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_ysu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_ysu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"zsu") == 0) { - if (domain->triclinic) pack_choice[i] = &DumpCustom::pack_zsu_triclinic; - else pack_choice[i] = &DumpCustom::pack_zsu; - vtype[i] = Dump::DOUBLE; + if (domain->triclinic) pack_choice[iarg] = &DumpCustom::pack_zsu_triclinic; + else pack_choice[iarg] = &DumpCustom::pack_zsu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"ix") == 0) { - pack_choice[i] = &DumpCustom::pack_ix; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_ix; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"iy") == 0) { - pack_choice[i] = &DumpCustom::pack_iy; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_iy; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"iz") == 0) { - pack_choice[i] = &DumpCustom::pack_iz; - vtype[i] = Dump::INT; + pack_choice[iarg] = &DumpCustom::pack_iz; + vtype[iarg] = Dump::INT; } else if (strcmp(arg[iarg],"vx") == 0) { - pack_choice[i] = &DumpCustom::pack_vx; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_vx; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"vy") == 0) { - pack_choice[i] = &DumpCustom::pack_vy; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_vy; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"vz") == 0) { - pack_choice[i] = &DumpCustom::pack_vz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_vz; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"fx") == 0) { - pack_choice[i] = &DumpCustom::pack_fx; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_fx; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"fy") == 0) { - pack_choice[i] = &DumpCustom::pack_fy; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_fy; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"fz") == 0) { - pack_choice[i] = &DumpCustom::pack_fz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_fz; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"q") == 0) { if (!atom->q_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_q; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_q; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"mux") == 0) { if (!atom->mu_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_mux; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_mux; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"muy") == 0) { if (!atom->mu_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_muy; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_muy; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"muz") == 0) { if (!atom->mu_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_muz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_muz; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"mu") == 0) { if (!atom->mu_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_mu; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_mu; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"radius") == 0) { if (!atom->radius_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_radius; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_radius; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"diameter") == 0) { if (!atom->radius_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_diameter; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_diameter; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"omegax") == 0) { if (!atom->omega_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_omegax; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_omegax; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"omegay") == 0) { if (!atom->omega_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_omegay; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_omegay; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"omegaz") == 0) { if (!atom->omega_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_omegaz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_omegaz; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"angmomx") == 0) { if (!atom->angmom_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_angmomx; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_angmomx; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"angmomy") == 0) { if (!atom->angmom_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_angmomy; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_angmomy; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"angmomz") == 0) { if (!atom->angmom_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_angmomz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_angmomz; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"tqx") == 0) { if (!atom->torque_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_tqx; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_tqx; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"tqy") == 0) { if (!atom->torque_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_tqy; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_tqy; + vtype[iarg] = Dump::DOUBLE; } else if (strcmp(arg[iarg],"tqz") == 0) { if (!atom->torque_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_tqz; - vtype[i] = Dump::DOUBLE; + pack_choice[iarg] = &DumpCustom::pack_tqz; + vtype[iarg] = Dump::DOUBLE; - // compute value = c_ID - // if no trailing [], then arg is set to 0, else arg is int between [] + } else { - } else if (strncmp(arg[iarg],"c_",2) == 0) { - pack_choice[i] = &DumpCustom::pack_compute; - vtype[i] = Dump::DOUBLE; + int n,tmp; + ArgInfo argi(arg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE + |ArgInfo::DNAME|ArgInfo::INAME); + argindex[iarg] = argi.get_index1(); - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); + switch (argi.get_type()) { - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump custom command"); - argindex[i] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[i] = 0; + case ArgInfo::UNKNOWN: + error->all(FLERR,"Invalid attribute in dump custom command"); + break; - n = modify->find_compute(suffix); - if (n < 0) error->all(FLERR,"Could not find dump custom compute ID"); - if (modify->compute[n]->peratom_flag == 0) - error->all(FLERR,"Dump custom compute does not compute per-atom info"); - if (argindex[i] == 0 && modify->compute[n]->size_peratom_cols > 0) - error->all(FLERR, - "Dump custom compute does not calculate per-atom vector"); - if (argindex[i] > 0 && modify->compute[n]->size_peratom_cols == 0) - error->all(FLERR, - "Dump custom compute does not calculate per-atom array"); - if (argindex[i] > 0 && - argindex[i] > modify->compute[n]->size_peratom_cols) - error->all(FLERR,"Dump custom compute vector is accessed out-of-range"); + // compute value = c_ID + // if no trailing [], then arg is set to 0, else arg is int between [] - field2index[i] = add_compute(suffix); - delete [] suffix; + case ArgInfo::COMPUTE: + pack_choice[iarg] = &DumpCustom::pack_compute; + vtype[iarg] = Dump::DOUBLE; - // fix value = f_ID - // if no trailing [], then arg is set to 0, else arg is between [] + n = modify->find_compute(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump custom compute ID"); + if (modify->compute[n]->peratom_flag == 0) + error->all(FLERR,"Dump custom compute does not compute per-atom info"); + if (argi.get_dim() == 0 && modify->compute[n]->size_peratom_cols > 0) + error->all(FLERR, + "Dump custom compute does not calculate per-atom vector"); + if (argi.get_index1() > 0 && modify->compute[n]->size_peratom_cols == 0) + error->all(FLERR, + "Dump custom compute does not calculate per-atom array"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->compute[n]->size_peratom_cols) + error->all(FLERR,"Dump custom compute vector is accessed out-of-range"); - } else if (strncmp(arg[iarg],"f_",2) == 0) { - pack_choice[i] = &DumpCustom::pack_fix; - vtype[i] = Dump::DOUBLE; + field2index[iarg] = add_compute(argi.get_name()); + break; - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); + // fix value = f_ID + // if no trailing [], then arg is set to 0, else arg is between [] - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump custom command"); - argindex[i] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[i] = 0; + case ArgInfo::FIX: + pack_choice[iarg] = &DumpCustom::pack_fix; + vtype[iarg] = Dump::DOUBLE; - n = modify->find_fix(suffix); - if (n < 0) error->all(FLERR,"Could not find dump custom fix ID"); - if (modify->fix[n]->peratom_flag == 0) - error->all(FLERR,"Dump custom fix does not compute per-atom info"); - if (argindex[i] == 0 && modify->fix[n]->size_peratom_cols > 0) - error->all(FLERR,"Dump custom fix does not compute per-atom vector"); - if (argindex[i] > 0 && modify->fix[n]->size_peratom_cols == 0) - error->all(FLERR,"Dump custom fix does not compute per-atom array"); - if (argindex[i] > 0 && - argindex[i] > modify->fix[n]->size_peratom_cols) - error->all(FLERR,"Dump custom fix vector is accessed out-of-range"); + n = modify->find_fix(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump custom fix ID"); + if (modify->fix[n]->peratom_flag == 0) + error->all(FLERR,"Dump custom fix does not compute per-atom info"); + if (argi.get_dim() == 0 && modify->fix[n]->size_peratom_cols > 0) + error->all(FLERR,"Dump custom fix does not compute per-atom vector"); + if (argi.get_index1() > 0 && modify->fix[n]->size_peratom_cols == 0) + error->all(FLERR,"Dump custom fix does not compute per-atom array"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->fix[n]->size_peratom_cols) + error->all(FLERR,"Dump custom fix vector is accessed out-of-range"); - field2index[i] = add_fix(suffix); - delete [] suffix; + field2index[iarg] = add_fix(argi.get_name()); + break; - // variable value = v_name + // variable value = v_name - } else if (strncmp(arg[iarg],"v_",2) == 0) { - pack_choice[i] = &DumpCustom::pack_variable; - vtype[i] = Dump::DOUBLE; + case ArgInfo::VARIABLE: + pack_choice[iarg] = &DumpCustom::pack_variable; + vtype[iarg] = Dump::DOUBLE; - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); + n = input->variable->find(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump custom variable name"); + if (input->variable->atomstyle(n) == 0) + error->all(FLERR,"Dump custom variable is not atom-style variable"); - argindex[i] = 0; + field2index[iarg] = add_variable(argi.get_name()); + break; - n = input->variable->find(suffix); - if (n < 0) error->all(FLERR,"Could not find dump custom variable name"); - if (input->variable->atomstyle(n) == 0) - error->all(FLERR,"Dump custom variable is not atom-style variable"); + // custom per-atom floating point value = d_ID - field2index[i] = add_variable(suffix); - delete [] suffix; + case ArgInfo::DNAME: + pack_choice[iarg] = &DumpCustom::pack_custom; + vtype[iarg] = Dump::DOUBLE; - // custom per-atom floating point value = d_ID + tmp = -1; + n = atom->find_custom(argi.get_name(),tmp); + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID"); - } else if (strncmp(arg[iarg],"d_",2) == 0) { - pack_choice[i] = &DumpCustom::pack_custom; - vtype[i] = Dump::DOUBLE; + if (tmp != 1) + error->all(FLERR,"Custom per-atom property ID is not floating point"); - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); - argindex[i] = 0; + field2index[iarg] = add_custom(argi.get_name(),1); + break; - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if (n < 0) - error->all(FLERR,"Could not find custom per-atom property ID"); + // custom per-atom integer value = i_ID - if (tmp != 1) - error->all(FLERR,"Custom per-atom property ID is not floating point"); + case ArgInfo::INAME: + pack_choice[iarg] = &DumpCustom::pack_custom; + vtype[iarg] = Dump::INT; - field2index[i] = add_custom(suffix,1); - delete [] suffix; + tmp = -1; + n = atom->find_custom(argi.get_name(),tmp); + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID"); - // custom per-atom integer value = i_ID + if (tmp != 0) + error->all(FLERR,"Custom per-atom property ID is not integer"); - } else if (strncmp(arg[iarg],"i_",2) == 0) { - pack_choice[i] = &DumpCustom::pack_custom; - vtype[i] = Dump::INT; + field2index[iarg] = add_custom(argi.get_name(),0); + break; - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); - argindex[i] = 0; - - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if (n < 0) - error->all(FLERR,"Could not find custom per-atom property ID"); - - if (tmp != 0) - error->all(FLERR,"Custom per-atom property ID is not integer"); - - field2index[i] = add_custom(suffix,0); - delete [] suffix; - - } else return iarg; + default: + return iarg; + break; + } + } } return narg; @@ -1897,149 +1873,113 @@ int DumpCustom::modify_param(int narg, char **arg) else if (strcmp(arg[1],"tqy") == 0) thresh_array[nthresh] = TQY; else if (strcmp(arg[1],"tqz") == 0) thresh_array[nthresh] = TQZ; - // compute value = c_ID - // if no trailing [], then arg is set to 0, else arg is between [] - // must grow field2index and argindex arrays, since access is beyond nfield + else { + + // must grow field2index and argindex arrays, since access is beyond nfield - else if (strncmp(arg[1],"c_",2) == 0) { - thresh_array[nthresh] = COMPUTE; memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n = strlen(arg[1]); - char *suffix = new char[n]; - strcpy(suffix,&arg[1][2]); - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump modify command"); - argindex[nfield+nthresh] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[nfield+nthresh] = 0; + int n,tmp; + ArgInfo argi(arg[1],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE + |ArgInfo::DNAME|ArgInfo::INAME); + argindex[nfield+nthresh] = argi.get_index1(); - n = modify->find_compute(suffix); - if (n < 0) error->all(FLERR,"Could not find dump modify compute ID"); + switch (argi.get_type()) { - if (modify->compute[n]->peratom_flag == 0) - error->all(FLERR, - "Dump modify compute ID does not compute per-atom info"); - if (argindex[nfield+nthresh] == 0 && - modify->compute[n]->size_peratom_cols > 0) - error->all(FLERR, - "Dump modify compute ID does not compute per-atom vector"); - if (argindex[nfield+nthresh] > 0 && - modify->compute[n]->size_peratom_cols == 0) - error->all(FLERR, - "Dump modify compute ID does not compute per-atom array"); - if (argindex[nfield+nthresh] > 0 && - argindex[nfield+nthresh] > modify->compute[n]->size_peratom_cols) - error->all(FLERR,"Dump modify compute ID vector is not large enough"); + case ArgInfo::UNKNOWN: + error->all(FLERR,"Invalid attribute in dump modify command"); + break; - field2index[nfield+nthresh] = add_compute(suffix); - delete [] suffix; + // compute value = c_ID + // if no trailing [], then arg is set to 0, else arg is between [] - // fix value = f_ID - // if no trailing [], then arg is set to 0, else arg is between [] - // must grow field2index and argindex arrays, since access is beyond nfield + case ArgInfo::COMPUTE: + thresh_array[nthresh] = COMPUTE; + n = modify->find_compute(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump modify compute ID"); - } else if (strncmp(arg[1],"f_",2) == 0) { - thresh_array[nthresh] = FIX; - memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); - memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n = strlen(arg[1]); - char *suffix = new char[n]; - strcpy(suffix,&arg[1][2]); + if (modify->compute[n]->peratom_flag == 0) + error->all(FLERR, + "Dump modify compute ID does not compute per-atom info"); + if (argi.get_dim() == 0 && modify->compute[n]->size_peratom_cols > 0) + error->all(FLERR, + "Dump modify compute ID does not compute per-atom vector"); + if (argi.get_index1() > 0 && modify->compute[n]->size_peratom_cols == 0) + error->all(FLERR, + "Dump modify compute ID does not compute per-atom array"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->compute[n]->size_peratom_cols) + error->all(FLERR,"Dump modify compute ID vector is not large enough"); - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump modify command"); - argindex[nfield+nthresh] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[nfield+nthresh] = 0; + field2index[nfield+nthresh] = add_compute(argi.get_name()); + break; - n = modify->find_fix(suffix); - if (n < 0) error->all(FLERR,"Could not find dump modify fix ID"); + // fix value = f_ID + // if no trailing [], then arg is set to 0, else arg is between [] - if (modify->fix[n]->peratom_flag == 0) - error->all(FLERR,"Dump modify fix ID does not compute per-atom info"); - if (argindex[nfield+nthresh] == 0 && - modify->fix[n]->size_peratom_cols > 0) - error->all(FLERR,"Dump modify fix ID does not compute per-atom vector"); - if (argindex[nfield+nthresh] > 0 && - modify->fix[n]->size_peratom_cols == 0) + case ArgInfo::FIX: + thresh_array[nthresh] = FIX; + n = modify->find_fix(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump modify fix ID"); + + if (modify->fix[n]->peratom_flag == 0) + error->all(FLERR,"Dump modify fix ID does not compute per-atom info"); + if (argi.get_dim() == 0 && modify->fix[n]->size_peratom_cols > 0) + error->all(FLERR,"Dump modify fix ID does not compute per-atom vector"); + if (argi.get_index1() > 0 && modify->fix[n]->size_peratom_cols == 0) error->all(FLERR,"Dump modify fix ID does not compute per-atom array"); - if (argindex[nfield+nthresh] > 0 && - argindex[nfield+nthresh] > modify->fix[n]->size_peratom_cols) - error->all(FLERR,"Dump modify fix ID vector is not large enough"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->fix[n]->size_peratom_cols) + error->all(FLERR,"Dump modify fix ID vector is not large enough"); - field2index[nfield+nthresh] = add_fix(suffix); - delete [] suffix; + field2index[nfield+nthresh] = add_fix(argi.get_name()); + break; - // variable value = v_ID - // must grow field2index and argindex arrays, since access is beyond nfield + // variable value = v_ID + // must grow field2index and argindex arrays, since access is beyond nfield - } else if (strncmp(arg[1],"v_",2) == 0) { - thresh_array[nthresh] = VARIABLE; - memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); - memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n = strlen(arg[1]); - char *suffix = new char[n]; - strcpy(suffix,&arg[1][2]); + case ArgInfo::VARIABLE: + thresh_array[nthresh] = VARIABLE; + n = input->variable->find(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump modify variable name"); + if (input->variable->atomstyle(n) == 0) + error->all(FLERR,"Dump modify variable is not atom-style variable"); - argindex[nfield+nthresh] = 0; + field2index[nfield+nthresh] = add_variable(argi.get_name()); + break; - n = input->variable->find(suffix); - if (n < 0) error->all(FLERR,"Could not find dump modify variable name"); - if (input->variable->atomstyle(n) == 0) - error->all(FLERR,"Dump modify variable is not atom-style variable"); + // custom per atom floating point value = d_ID - field2index[nfield+nthresh] = add_variable(suffix); - delete [] suffix; + case ArgInfo::DNAME: + thresh_array[nthresh] = DNAME; + tmp = -1; + n = atom->find_custom(argi.get_name(),tmp); + if ((n < 0) || (tmp != 1)) + error->all(FLERR,"Could not find dump modify " + "custom atom floating point property ID"); - // custom per atom floating point value = d_ID - // must grow field2index and argindex arrays, since access is beyond nfield + field2index[nfield+nthresh] = add_custom(argi.get_name(),1); + break; - } else if (strncmp(arg[1],"d_",2) == 0) { - thresh_array[nthresh] = DNAME; - memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); - memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n = strlen(arg[1]); - char *suffix = new char[n]; - strcpy(suffix,&arg[1][2]); - argindex[nfield+nthresh] = 0; + // custom per atom integer value = i_ID - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if ((n < 0) || (tmp != 1)) - error->all(FLERR,"Could not find dump modify " - "custom atom floating point property ID"); + case ArgInfo::INAME: + thresh_array[nthresh] = INAME; + tmp = -1; + n = atom->find_custom(argi.get_name(),tmp); + if ((n < 0) || (tmp != 0)) + error->all(FLERR,"Could not find dump modify " + "custom atom integer property ID"); - field2index[nfield+nthresh] = add_custom(suffix,1); - delete [] suffix; + field2index[nfield+nthresh] = add_custom(argi.get_name(),0); + break; - // custom per atom integer value = i_ID - // must grow field2index and argindex arrays, since access is beyond nfield - - } else if (strncmp(arg[1],"i_",2) == 0) { - thresh_array[nthresh] = INAME; - memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); - memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n = strlen(arg[1]); - char *suffix = new char[n]; - strcpy(suffix,&arg[1][2]); - argindex[nfield+nthresh] = 0; - - int tmp = -1; - n = atom->find_custom(suffix,tmp); - if ((n < 0) || (tmp != 0)) - error->all(FLERR,"Could not find dump modify " - "custom atom integer property ID"); - - field2index[nfield+nthresh] = add_custom(suffix,0); - delete [] suffix; - - } else error->all(FLERR,"Invalid dump_modify thresh attribute"); + default: + error->all(FLERR,"Invalid dump_modify thresh attribute"); + break; + } + } // set operation type of threshold diff --git a/src/dump_local.cpp b/src/dump_local.cpp index 211d50f49b..0041790063 100644 --- a/src/dump_local.cpp +++ b/src/dump_local.cpp @@ -13,6 +13,7 @@ #include "dump_local.h" +#include "arg_info.h" #include "compute.h" #include "domain.h" #include "error.h" @@ -404,85 +405,70 @@ void DumpLocal::parse_fields(int narg, char **arg) // customize by adding to if statement - int i; for (int iarg = 0; iarg < narg; iarg++) { - i = iarg; if (strcmp(arg[iarg],"index") == 0) { - pack_choice[i] = &DumpLocal::pack_index; - vtype[i] = INT; + pack_choice[iarg] = &DumpLocal::pack_index; + vtype[iarg] = INT; - // compute value = c_ID - // if no trailing [], then arg is set to 0, else arg is int between [] - - } else if (strncmp(arg[iarg],"c_",2) == 0) { + } else { + int n; + ArgInfo argi(arg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX); computefixflag = 1; - pack_choice[i] = &DumpLocal::pack_compute; - vtype[i] = DOUBLE; + vtype[iarg] = DOUBLE; + argindex[iarg] = argi.get_index1(); - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); + switch (argi.get_type()) { - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump local command"); - argindex[i] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[i] = 0; + // compute value = c_ID + // if no trailing [], then arg is set to 0, else arg is int between [] - n = modify->find_compute(suffix); - if (n < 0) error->all(FLERR,"Could not find dump local compute ID"); - if (modify->compute[n]->local_flag == 0) - error->all(FLERR,"Dump local compute does not compute local info"); - if (argindex[i] == 0 && modify->compute[n]->size_local_cols > 0) - error->all(FLERR,"Dump local compute does not calculate local vector"); - if (argindex[i] > 0 && modify->compute[n]->size_local_cols == 0) - error->all(FLERR,"Dump local compute does not calculate local array"); - if (argindex[i] > 0 && - argindex[i] > modify->compute[n]->size_local_cols) - error->all(FLERR,"Dump local compute vector is accessed out-of-range"); + case ArgInfo::COMPUTE: + pack_choice[iarg] = &DumpLocal::pack_compute; - field2index[i] = add_compute(suffix); - delete [] suffix; + n = modify->find_compute(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump local compute ID"); + if (modify->compute[n]->local_flag == 0) + error->all(FLERR,"Dump local compute does not compute local info"); + if (argi.get_dim() == 0 && modify->compute[n]->size_local_cols > 0) + error->all(FLERR,"Dump local compute does not calculate local vector"); + if (argi.get_index1() > 0 && modify->compute[n]->size_local_cols == 0) + error->all(FLERR,"Dump local compute does not calculate local array"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->compute[n]->size_local_cols) + error->all(FLERR,"Dump local compute vector is accessed out-of-range"); - // fix value = f_ID - // if no trailing [], then arg is set to 0, else arg is between [] + field2index[iarg] = add_compute(argi.get_name()); + break; - } else if (strncmp(arg[iarg],"f_",2) == 0) { - computefixflag = 1; - pack_choice[i] = &DumpLocal::pack_fix; - vtype[i] = DOUBLE; + // fix value = f_ID + // if no trailing [], then arg is set to 0, else arg is between [] - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][2]); + case ArgInfo::FIX: + pack_choice[iarg] = &DumpLocal::pack_fix; - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump local command"); - argindex[i] = atoi(ptr+1); - *ptr = '\0'; - } else argindex[i] = 0; + n = modify->find_fix(argi.get_name()); + if (n < 0) error->all(FLERR,"Could not find dump local fix ID"); + if (modify->fix[n]->local_flag == 0) + error->all(FLERR,"Dump local fix does not compute local info"); + if (argi.get_dim() == 0 && modify->fix[n]->size_local_cols > 0) + error->all(FLERR,"Dump local fix does not compute local vector"); + if (argi.get_index1() > 0 && modify->fix[n]->size_local_cols == 0) + error->all(FLERR,"Dump local fix does not compute local array"); + if (argi.get_index1() > 0 && + argi.get_index1() > modify->fix[n]->size_local_cols) + error->all(FLERR,"Dump local fix vector is accessed out-of-range"); - n = modify->find_fix(suffix); - if (n < 0) error->all(FLERR,"Could not find dump local fix ID"); - if (modify->fix[n]->local_flag == 0) - error->all(FLERR,"Dump local fix does not compute local info"); - if (argindex[i] == 0 && modify->fix[n]->size_local_cols > 0) - error->all(FLERR,"Dump local fix does not compute local vector"); - if (argindex[i] > 0 && modify->fix[n]->size_local_cols == 0) - error->all(FLERR,"Dump local fix does not compute local array"); - if (argindex[i] > 0 && - argindex[i] > modify->fix[n]->size_local_cols) - error->all(FLERR,"Dump local fix vector is accessed out-of-range"); + field2index[iarg] = add_fix(argi.get_name()); + break; - field2index[i] = add_fix(suffix); - delete [] suffix; - - } else error->all(FLERR,"Invalid attribute in dump local command"); + case ArgInfo::NONE: // fallthrough + case ArgInfo::UNKNOWN: // fallthrough + default: + error->all(FLERR,"Invalid attribute in dump local command"); + break; + } + } } if (computefixflag == 0)