use scoped enums from Dump and Thermo classes instead of replicating them, reformat
This commit is contained in:
@ -44,9 +44,6 @@
|
|||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
using namespace MathConst;
|
using namespace MathConst;
|
||||||
|
|
||||||
enum{THERMO_INT,THERMO_FLOAT,THERMO_BIGINT}; // same as in thermo.cpp
|
|
||||||
enum{DUMP_INT,DUMP_DOUBLE,DUMP_STRING,DUMP_BIGINT}; // same as in DumpCFG
|
|
||||||
|
|
||||||
static const char NC_FRAME_STR[] = "frame";
|
static const char NC_FRAME_STR[] = "frame";
|
||||||
static const char NC_SPATIAL_STR[] = "spatial";
|
static const char NC_SPATIAL_STR[] = "spatial";
|
||||||
static const char NC_VOIGT_STR[] = "Voigt";
|
static const char NC_VOIGT_STR[] = "Voigt";
|
||||||
@ -60,8 +57,8 @@ static const char NC_CELL_ORIGIN_STR[] = "cell_origin";
|
|||||||
static const char NC_CELL_LENGTHS_STR[] = "cell_lengths";
|
static const char NC_CELL_LENGTHS_STR[] = "cell_lengths";
|
||||||
static const char NC_CELL_ANGLES_STR[] = "cell_angles";
|
static const char NC_CELL_ANGLES_STR[] = "cell_angles";
|
||||||
|
|
||||||
const char NC_UNITS_STR[] = "units";
|
static const char NC_UNITS_STR[] = "units";
|
||||||
const char NC_SCALE_FACTOR_STR[] = "scale_factor";
|
static const char NC_SCALE_FACTOR_STR[] = "scale_factor";
|
||||||
|
|
||||||
static constexpr int THIS_IS_A_FIX = -1;
|
static constexpr int THIS_IS_A_FIX = -1;
|
||||||
static constexpr int THIS_IS_A_COMPUTE = -2;
|
static constexpr int THIS_IS_A_COMPUTE = -2;
|
||||||
@ -400,9 +397,9 @@ void DumpNetCDF::openfile()
|
|||||||
nc_type xtype;
|
nc_type xtype;
|
||||||
|
|
||||||
// Type mangling
|
// Type mangling
|
||||||
if (vtype[perat[i].field[0]] == DUMP_INT) {
|
if (vtype[perat[i].field[0]] == Dump::INT) {
|
||||||
xtype = NC_INT;
|
xtype = NC_INT;
|
||||||
} else if (vtype[perat[i].field[0]] == DUMP_BIGINT) {
|
} else if (vtype[perat[i].field[0]] == Dump::BIGINT) {
|
||||||
xtype = NC_INT64;
|
xtype = NC_INT64;
|
||||||
} else {
|
} else {
|
||||||
if (double_precision)
|
if (double_precision)
|
||||||
@ -435,13 +432,13 @@ void DumpNetCDF::openfile()
|
|||||||
if (thermo) {
|
if (thermo) {
|
||||||
Thermo *th = output->thermo;
|
Thermo *th = output->thermo;
|
||||||
for (int i = 0; i < th->nfield; i++) {
|
for (int i = 0; i < th->nfield; i++) {
|
||||||
if (th->vtype[i] == THERMO_FLOAT) {
|
if (th->vtype[i] == Thermo::FLOAT) {
|
||||||
NCERRX( nc_def_var(ncid, th->keyword[i], NC_DOUBLE, 1, dims,
|
NCERRX( nc_def_var(ncid, th->keyword[i], NC_DOUBLE, 1, dims,
|
||||||
&thermovar[i]), th->keyword[i] );
|
&thermovar[i]), th->keyword[i] );
|
||||||
} else if (th->vtype[i] == THERMO_INT) {
|
} else if (th->vtype[i] == Thermo::INT) {
|
||||||
NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT, 1, dims,
|
NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT, 1, dims,
|
||||||
&thermovar[i]), th->keyword[i] );
|
&thermovar[i]), th->keyword[i] );
|
||||||
} else if (th->vtype[i] == THERMO_BIGINT) {
|
} else if (th->vtype[i] == Thermo::BIGINT) {
|
||||||
#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG)
|
#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG)
|
||||||
NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT64, 1, dims,
|
NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT64, 1, dims,
|
||||||
&thermovar[i]), th->keyword[i] );
|
&thermovar[i]), th->keyword[i] );
|
||||||
@ -454,77 +451,50 @@ void DumpNetCDF::openfile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "Conventions",
|
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "Conventions",5, "AMBER") );
|
||||||
5, "AMBER") );
|
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "ConventionVersion",3, "1.0") );
|
||||||
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "ConventionVersion",
|
|
||||||
3, "1.0") );
|
|
||||||
|
|
||||||
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "program",
|
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "program",6, "LAMMPS") );
|
||||||
6, "LAMMPS") );
|
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "programVersion",strlen(lmp->version), lmp->version) );
|
||||||
NCERR( nc_put_att_text(ncid, NC_GLOBAL, "programVersion",
|
|
||||||
strlen(lmp->version), lmp->version) );
|
|
||||||
|
|
||||||
// units
|
// units
|
||||||
if (!strcmp(update->unit_style, "lj")) {
|
if (!strcmp(update->unit_style, "lj")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,2, "lj") );
|
||||||
2, "lj") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,2, "lj") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,2, "lj") );
|
||||||
2, "lj") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
2, "lj") );
|
|
||||||
} else if (!strcmp(update->unit_style, "real")) {
|
} else if (!strcmp(update->unit_style, "real")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,11, "femtosecond") );
|
||||||
11, "femtosecond") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,8, "Angstrom") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,8, "Angstrom") );
|
||||||
8, "Angstrom") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
8, "Angstrom") );
|
|
||||||
} else if (!strcmp(update->unit_style, "metal")) {
|
} else if (!strcmp(update->unit_style, "metal")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,10, "picosecond") );
|
||||||
10, "picosecond") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,8, "Angstrom") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,8, "Angstrom") );
|
||||||
8, "Angstrom") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
8, "Angstrom") );
|
|
||||||
} else if (!strcmp(update->unit_style, "si")) {
|
} else if (!strcmp(update->unit_style, "si")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,6, "second") );
|
||||||
6, "second") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,5, "meter") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,5, "meter") );
|
||||||
5, "meter") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
5, "meter") );
|
|
||||||
} else if (!strcmp(update->unit_style, "cgs")) {
|
} else if (!strcmp(update->unit_style, "cgs")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,6, "second") );
|
||||||
6, "second") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,10, "centimeter") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,10, "centimeter") );
|
||||||
10, "centimeter") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
10, "centimeter") );
|
|
||||||
} else if (!strcmp(update->unit_style, "electron")) {
|
} else if (!strcmp(update->unit_style, "electron")) {
|
||||||
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, time_var, NC_UNITS_STR,11, "femtosecond") );
|
||||||
11, "femtosecond") );
|
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,4, "Bohr") );
|
||||||
NCERR( nc_put_att_text(ncid, cell_origin_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,4, "Bohr") );
|
||||||
4, "Bohr") );
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_lengths_var, NC_UNITS_STR,
|
|
||||||
4, "Bohr") );
|
|
||||||
} else {
|
} else {
|
||||||
char errstr[1024];
|
char errstr[1024];
|
||||||
sprintf(errstr, "Unsupported unit style '%s'", update->unit_style);
|
error->all(FLERR,"Unsupported unit style '{}", update->unit_style);
|
||||||
error->all(FLERR,errstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NCERR( nc_put_att_text(ncid, cell_angles_var, NC_UNITS_STR,
|
NCERR( nc_put_att_text(ncid, cell_angles_var, NC_UNITS_STR,6, "degree") );
|
||||||
6, "degree") );
|
|
||||||
|
|
||||||
d[0] = update->dt;
|
d[0] = update->dt;
|
||||||
NCERR( nc_put_att_double(ncid, time_var, NC_SCALE_FACTOR_STR,
|
NCERR( nc_put_att_double(ncid, time_var, NC_SCALE_FACTOR_STR,NC_DOUBLE, 1, d) );
|
||||||
NC_DOUBLE, 1, d) );
|
|
||||||
d[0] = 1.0;
|
d[0] = 1.0;
|
||||||
NCERR( nc_put_att_double(ncid, cell_origin_var, NC_SCALE_FACTOR_STR,
|
NCERR( nc_put_att_double(ncid, cell_origin_var, NC_SCALE_FACTOR_STR,NC_DOUBLE, 1, d) );
|
||||||
NC_DOUBLE, 1, d) );
|
|
||||||
d[0] = 1.0;
|
d[0] = 1.0;
|
||||||
NCERR( nc_put_att_double(ncid, cell_lengths_var, NC_SCALE_FACTOR_STR,
|
NCERR( nc_put_att_double(ncid, cell_lengths_var, NC_SCALE_FACTOR_STR,NC_DOUBLE, 1, d) );
|
||||||
NC_DOUBLE, 1, d) );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finished with definition
|
* Finished with definition
|
||||||
@ -663,14 +633,14 @@ void DumpNetCDF::write()
|
|||||||
for (int i = 0; i < th->nfield; i++) {
|
for (int i = 0; i < th->nfield; i++) {
|
||||||
th->call_vfunc(i);
|
th->call_vfunc(i);
|
||||||
if (filewriter) {
|
if (filewriter) {
|
||||||
if (th->vtype[i] == THERMO_FLOAT) {
|
if (th->vtype[i] == Thermo::FLOAT) {
|
||||||
NCERRX( nc_put_var1_double(ncid, thermovar[i], start,
|
NCERRX( nc_put_var1_double(ncid, thermovar[i], start,
|
||||||
&th->dvalue),
|
&th->dvalue),
|
||||||
th->keyword[i] );
|
th->keyword[i] );
|
||||||
} else if (th->vtype[i] == THERMO_INT) {
|
} else if (th->vtype[i] == Thermo::INT) {
|
||||||
NCERRX( nc_put_var1_int(ncid, thermovar[i], start, &th->ivalue),
|
NCERRX( nc_put_var1_int(ncid, thermovar[i], start, &th->ivalue),
|
||||||
th->keyword[i] );
|
th->keyword[i] );
|
||||||
} else if (th->vtype[i] == THERMO_BIGINT) {
|
} else if (th->vtype[i] == Thermo::BIGINT) {
|
||||||
NCERRX( nc_put_var1_bigint(ncid, thermovar[i], start, &th->bivalue),
|
NCERRX( nc_put_var1_bigint(ncid, thermovar[i], start, &th->bivalue),
|
||||||
th->keyword[i] );
|
th->keyword[i] );
|
||||||
}
|
}
|
||||||
@ -799,7 +769,7 @@ void DumpNetCDF::write_data(int n, double *mybuf)
|
|||||||
for (int i = 0; i < n_perat; i++) {
|
for (int i = 0; i < n_perat; i++) {
|
||||||
int iaux = perat[i].field[0];
|
int iaux = perat[i].field[0];
|
||||||
|
|
||||||
if (vtype[iaux] == DUMP_INT || vtype[iaux] == DUMP_BIGINT) {
|
if (vtype[iaux] == Dump::INT || vtype[iaux] == Dump::BIGINT) {
|
||||||
// integers
|
// integers
|
||||||
if (perat[i].dims > 1) {
|
if (perat[i].dims > 1) {
|
||||||
|
|
||||||
@ -807,11 +777,11 @@ void DumpNetCDF::write_data(int n, double *mybuf)
|
|||||||
iaux = perat[i].field[idim];
|
iaux = perat[i].field[idim];
|
||||||
|
|
||||||
if (iaux >= 0) {
|
if (iaux >= 0) {
|
||||||
if (vtype[iaux] == DUMP_INT) {
|
if (vtype[iaux] == Dump::INT) {
|
||||||
for (int j = 0; j < n; j++, iaux+=size_one) {
|
for (int j = 0; j < n; j++, iaux+=size_one) {
|
||||||
int_buffer[j] = static_cast<int>(mybuf[iaux]);
|
int_buffer[j] = static_cast<int>(mybuf[iaux]);
|
||||||
}
|
}
|
||||||
} else { // DUMP_BIGINT
|
} else { // Dump::BIGINT
|
||||||
for (int j = 0; j < n; j++, iaux+=size_one) {
|
for (int j = 0; j < n; j++, iaux+=size_one) {
|
||||||
int_buffer[j] = static_cast<bigint>(mybuf[iaux]);
|
int_buffer[j] = static_cast<bigint>(mybuf[iaux]);
|
||||||
}
|
}
|
||||||
@ -821,22 +791,19 @@ void DumpNetCDF::write_data(int n, double *mybuf)
|
|||||||
|
|
||||||
if (perat[i].constant) {
|
if (perat[i].constant) {
|
||||||
if (perat[i].ndumped < ntotalgr) {
|
if (perat[i].ndumped < ntotalgr) {
|
||||||
NCERR( nc_put_vars_bigint(ncid, perat[i].var,
|
NCERR( nc_put_vars_bigint(ncid, perat[i].var,start+1, count+1, stride+1,int_buffer) );
|
||||||
start+1, count+1, stride+1,
|
|
||||||
int_buffer) );
|
|
||||||
perat[i].ndumped += n;
|
perat[i].ndumped += n;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
NCERR( nc_put_vars_bigint(ncid, perat[i].var, start, count, stride,
|
NCERR( nc_put_vars_bigint(ncid, perat[i].var, start, count, stride,int_buffer) );
|
||||||
int_buffer) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (vtype[iaux] == DUMP_INT) {
|
if (vtype[iaux] == Dump::INT) {
|
||||||
for (int j = 0; j < n; j++, iaux+=size_one) {
|
for (int j = 0; j < n; j++, iaux+=size_one) {
|
||||||
int_buffer[j] = static_cast<int>(mybuf[iaux]);
|
int_buffer[j] = static_cast<int>(mybuf[iaux]);
|
||||||
}
|
}
|
||||||
} else { // DUMP_BIGINT
|
} else { // Dump::BIGINT
|
||||||
for (int j = 0; j < n; j++, iaux+=size_one) {
|
for (int j = 0; j < n; j++, iaux+=size_one) {
|
||||||
int_buffer[j] = static_cast<bigint>(mybuf[iaux]);
|
int_buffer[j] = static_cast<bigint>(mybuf[iaux]);
|
||||||
}
|
}
|
||||||
@ -844,13 +811,11 @@ void DumpNetCDF::write_data(int n, double *mybuf)
|
|||||||
|
|
||||||
if (perat[i].constant) {
|
if (perat[i].constant) {
|
||||||
if (perat[i].ndumped < ntotalgr) {
|
if (perat[i].ndumped < ntotalgr) {
|
||||||
NCERR( nc_put_vara_bigint(ncid, perat[i].var, start+1, count+1,
|
NCERR( nc_put_vara_bigint(ncid, perat[i].var, start+1, count+1,int_buffer) );
|
||||||
int_buffer) );
|
|
||||||
perat[i].ndumped += n;
|
perat[i].ndumped += n;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
NCERR( nc_put_vara_bigint(ncid, perat[i].var, start, count,
|
NCERR( nc_put_vara_bigint(ncid, perat[i].var, start, count,int_buffer) );
|
||||||
int_buffer) );
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// doubles
|
// doubles
|
||||||
|
|||||||
Reference in New Issue
Block a user