Skip to content

Commit

Permalink
Merge pull request #913 from alhom/vlsvExtract_std
Browse files Browse the repository at this point in the history
vlsvExtract std containers dis-ambiguation
  • Loading branch information
ykempf authored Feb 12, 2024
2 parents 676f26a + 9c26a86 commit bf62caa
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions tools/vlsvextract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool convertSlicedVelocityMesh(vlsvinterface::Reader& vlsvReader,const string& f
return false;
}

vector<uint64_t> cellIDs;
std::vector<uint64_t> cellIDs;
if (vlsvReader.getCellIds(cellIDs) == false) {
cerr << "ERROR: failed to get cell IDs in " << __FILE__ << ' ' << __LINE__ << endl;
return false;
Expand Down Expand Up @@ -165,13 +165,13 @@ bool convertSlicedVelocityMesh(vlsvinterface::Reader& vlsvReader,const string& f
uint64_t vectorSize;
uint64_t dataSize;
};
vector<BlockVarInfo> varInfo;
std::vector<BlockVarInfo> varInfo;

// Assume that two of the coordinates are spatial, i.e., that the first
// sliced coordinate is a spatial one
vector<float> nodeCoords;
vector<int> connectivity;
vector<vector<char> > variables;
std::vector<float> nodeCoords;
std::vector<int> connectivity;
std::vector<std::vector<char> > variables;
for (size_t cell=0; cell<cellIDs.size(); ++cell) {
uint64_t cellId = cellIDs[cell]-1;
uint64_t cellIndices[3];
Expand All @@ -188,7 +188,7 @@ bool convertSlicedVelocityMesh(vlsvinterface::Reader& vlsvReader,const string& f
if (cellCrds[cellStruct.slicedCoords[0]+3] < cellStruct.slicedCoordValues[0]) continue;

// Buffer all velocity mesh variables
vector<char*> varBuffer(blockVarNames.size());
std::vector<char*> varBuffer(blockVarNames.size());
int counter=0;
for (set<string>::const_iterator var=blockVarNames.begin(); var!=blockVarNames.end(); ++var) {
varBuffer[counter] = NULL;
Expand All @@ -214,7 +214,7 @@ bool convertSlicedVelocityMesh(vlsvinterface::Reader& vlsvReader,const string& f
}
if (varInfo.size() > variables.size()) variables.resize(varInfo.size());

vector<uint64_t> blockIDs;
std::vector<uint64_t> blockIDs;
if (vlsvReader.getBlockIds(cellIDs[cell],blockIDs,popName) == false) {
for (size_t v=0; v<varBuffer.size(); ++v) delete [] varBuffer[v];
continue;
Expand Down Expand Up @@ -783,7 +783,7 @@ bool convertVelocityBlocks2(
}

// Read velocity block global IDs and write them out
vector<uint64_t> blockIds;
std::vector<uint64_t> blockIds;
if (vlsvReader.getBlockIds(cellID,blockIds,popName) == false ) {
cerr << "Trying older Vlasiator file format..." << endl;
if (vlsvReader.getBlockIds(cellID,blockIds,"") == false) {
Expand Down Expand Up @@ -812,7 +812,7 @@ bool convertVelocityBlocks2(

// Create array of phase-space mesh cell IDs, this is needed to make
// vlsvdiff work with extracted velocity meshes
vector<uint64_t> cellIDs(blockIds.size()*64);
std::vector<uint64_t> cellIDs(blockIds.size()*64);
for (size_t b=0; b<blockIds.size(); ++b) {
for (int c=0; c<64; ++c) cellIDs[b*64+c] = blockIds[b]*64+c;
}
Expand All @@ -828,7 +828,7 @@ bool convertVelocityBlocks2(
attributes["mesh"] = outputMeshName;
if (out.writeArray("MESH_DOMAIN_SIZES",attributes,1,2,domainSize) == false) success = false;
{
vector<uint64_t> ().swap(blockIds);
std::vector<uint64_t> ().swap(blockIds);
}

attributes["mesh"] = "VelBlocks_" + popName;
Expand All @@ -854,7 +854,7 @@ bool convertVelocityBlocks2(
if (out.writeArray("MESH_BBOX",attributes,6,1,bbox) == false) success = false;

// Make node coordinate arrays
vector<float> coords;
std::vector<float> coords;
for (int crd=0; crd<3; ++crd) {
// crd enumerates the coordinate: 0 = vx, 1 = vy, 2 = vz
coords.clear();
Expand Down Expand Up @@ -884,7 +884,7 @@ bool convertVelocityBlocks2(
}
}
{
vector<float> ().swap(coords);
std::vector<float> ().swap(coords);
}

for (int crd=0; crd<3; ++crd) {
Expand All @@ -906,7 +906,7 @@ bool convertVelocityBlocks2(
}
}
{
vector<float> ().swap(coords);
std::vector<float> ().swap(coords);
}

// Write dummy ghost zone data (not applicable here):
Expand Down Expand Up @@ -1188,7 +1188,7 @@ uint64_t searchForBestCellId( const CellStructure & cellStruct,
//[0] Returns the closest cell id to the given coordinates
uint64_t searchForBestCellId( const CellStructure & cellStruct,
const unordered_set<uint64_t> & cellIdList,
const array<Real, 3> coordinates ) {
const std::array<Real, 3> coordinates ) {
//Check for null pointer:
if( coordinates.empty() ) {
cerr << "ERROR, PASSED AN EMPTY COORDINATES AT " << __FILE__ << " " << __LINE__ << endl;
Expand Down Expand Up @@ -1464,7 +1464,7 @@ bool setSpatialCellVariables(Reader& vlsvReader,CellStructure& cellStruct) {
//[0] Returns the cell id in uint64_t
uint64_t getCellIdFromCoords( const CellStructure & cellStruct,
const unordered_set<uint64_t> cellIdList,
const array<Real, 3> coords) {
const std::array<Real, 3> coords) {
if( coords.empty() ) {
cerr << "ERROR, PASSED AN EMPTY STD::ARRAY FOR COORDINATES AT " << __FILE__ << " " << __LINE__ << endl;
}
Expand Down Expand Up @@ -1518,12 +1518,12 @@ bool retrieveOptions( const int argn, char *args[], UserOptions & mainOptions )
bool & rotateVectors = mainOptions.rotateVectors;
bool & plasmaFrame = mainOptions.plasmaFrame;
uint64_t & cellId = mainOptions.cellId;
vector<uint64_t> & cellIdList = mainOptions.cellIdList;
std::vector<uint64_t> & cellIdList = mainOptions.cellIdList;
uint32_t & numberOfCoordinatesInALine = mainOptions.numberOfCoordinatesInALine;
vector<string> & outputDirectoryPath = mainOptions.outputDirectoryPath;
array<Real, 3> & coordinates = mainOptions.coordinates;
array<Real, 3> & point1 = mainOptions.point1;
array<Real, 3> & point2 = mainOptions.point2;
std::vector<string> & outputDirectoryPath = mainOptions.outputDirectoryPath;
std::array<Real, 3> & coordinates = mainOptions.coordinates;
std::array<Real, 3> & point1 = mainOptions.point1;
std::array<Real, 3> & point2 = mainOptions.point2;

//By default every bool input should be false and vectors should be empty
if( getCellIdFromCoordinates == true || rotateVectors == true || plasmaFrame == true || getCellIdFromInput == true || getCellIdFromLine == true || outputDirectoryPath.empty() == false ) {
Expand All @@ -1538,15 +1538,15 @@ bool retrieveOptions( const int argn, char *args[], UserOptions & mainOptions )
("help", "display help")
("debug", "write debugging info to stderr")
("cellid", po::value<uint64_t>(), "Set cell id")
("cellidlist", po::value< vector<uint64_t>>()->multitoken(), "Set list of cell ids")
("cellidlist", po::value< std::vector<uint64_t>>()->multitoken(), "Set list of cell ids")
("rotate", "Rotate velocities so that they face z-axis")
("plasmaFrame", "Shift the distribution so that the bulk velocity is 0")
("coordinates", po::value< vector<Real> >()->multitoken(), "Set spatial coordinates x y z")
("coordinates", po::value< std::vector<Real> >()->multitoken(), "Set spatial coordinates x y z")
("unit", po::value<string>(), "Sets the units. Options: re, km, m (OPTIONAL)")
("point1", po::value< vector<Real> >()->multitoken(), "Set the starting point x y z of a line")
("point2", po::value< vector<Real> >()->multitoken(), "Set the ending point x y z of a line")
("point1", po::value< std::vector<Real> >()->multitoken(), "Set the starting point x y z of a line")
("point2", po::value< std::vector<Real> >()->multitoken(), "Set the ending point x y z of a line")
("pointamount", po::value<unsigned int>(), "Number of points along a line (OPTIONAL)")
("outputdirectory", po::value< vector<string> >(), "The directory where the file is saved (default current folder) (OPTIONAL)");
("outputdirectory", po::value< std::vector<string> >(), "The directory where the file is saved (default current folder) (OPTIONAL)");

//For mapping input
po::variables_map vm;
Expand All @@ -1561,20 +1561,20 @@ bool retrieveOptions( const int argn, char *args[], UserOptions & mainOptions )
}
//Check if coordinates have been input and make sure there's only 3 coordinates
const size_t _size = 3;
if( !vm["coordinates"].empty() && vm["coordinates"].as< vector<Real> >().size() == _size ) {
if( !vm["coordinates"].empty() && vm["coordinates"].as< std::vector<Real> >().size() == _size ) {
//Save input into coordinates vector (later on the values are stored into a *Real pointer
vector<Real> _coordinates = vm["coordinates"].as< vector<Real> >();
std::vector<Real> _coordinates = vm["coordinates"].as< std::vector<Real> >();
for( uint i = 0; i < 3; ++i ) {
coordinates[i] = _coordinates[i];
}
//Let the program know we want to get the cell id from coordinates
getCellIdFromCoordinates = true;
}
if( !vm["point1"].empty() && vm["point1"].as< vector<Real> >().size() == _size
&& !vm["point2"].empty() && vm["point2"].as< vector<Real> >().size() == _size ) {
if( !vm["point1"].empty() && vm["point1"].as< std::vector<Real> >().size() == _size
&& !vm["point2"].empty() && vm["point2"].as< std::vector<Real> >().size() == _size ) {
//Save input into point vector (later on the values are stored into a *Real pointer
vector<Real> _point1 = vm["point1"].as< vector<Real> >();
vector<Real> _point2 = vm["point2"].as< vector<Real> >();
std::vector<Real> _point1 = vm["point1"].as< std::vector<Real> >();
std::vector<Real> _point2 = vm["point2"].as< std::vector<Real> >();
//Input the values
for( uint i = 0; i < 3; ++i ) {
point1[i] = _point1[i];
Expand Down Expand Up @@ -1612,12 +1612,12 @@ bool retrieveOptions( const int argn, char *args[], UserOptions & mainOptions )
getCellIdFromInput = true;
}
if( vm.count("cellidlist") ) {
cellIdList = vm["cellidlist"].as< vector<uint64_t> >();
cellIdList = vm["cellidlist"].as< std::vector<uint64_t> >();
getCellIdFromInput = true;
}
if( vm.count("outputdirectory") ) {
//Save input
outputDirectoryPath = vm["outputdirectory"].as< vector<string> >();
outputDirectoryPath = vm["outputdirectory"].as< std::vector<string> >();
//Make sure the vector is of length 1:
if( outputDirectoryPath.size() != 1 ) {
return false;
Expand Down Expand Up @@ -1733,8 +1733,8 @@ bool retrieveOptions( const int argn, char *args[], UserOptions & mainOptions )
//output
void setCoordinatesAlongALine(
const CellStructure & cellStruct,
const array<Real, 3> & start, const array<Real, 3> & end, uint32_t numberOfCoordinates,
vector< array<Real, 3> > & outputCoordinates
const std::array<Real, 3> & start, const std::array<Real, 3> & end, uint32_t numberOfCoordinates,
std::vector< std::array<Real, 3> > & outputCoordinates
) {
//Used in calculations in place of numberOfCoordinates
uint32_t _numberOfCoordinates;
Expand Down Expand Up @@ -1778,15 +1778,15 @@ void setCoordinatesAlongALine(
_numberOfCoordinates = numberOfCoordinates;
}
//Store the unit of line vector ( the vector from start to end divided by the numberOfCoordinates ) into line_unit
array<Real, 3> line_unit;
std::array<Real, 3> line_unit;
for( uint i = 0; i < 3; ++i ) {
line_unit[i] = (end[i] - start[i]) / (Real)(_numberOfCoordinates - 1);
}

//Insert the coordinates:
outputCoordinates.reserve(_numberOfCoordinates);
for( uint j = 0; j < _numberOfCoordinates; ++j ) {
const array<Real, 3> input{{start[0] + j * line_unit[0],
const std::array<Real, 3> input{{start[0] + j * line_unit[0],
start[1] + j * line_unit[1],
start[2] + j * line_unit[2],}};
outputCoordinates.push_back(input);
Expand Down Expand Up @@ -1815,7 +1815,7 @@ void extractDistribution( const string & fileName, const UserOptions & mainOptio
setSpatialCellVariables( vlsvReader, cellStruct );

//Declare a vector for holding multiple cell ids (Note: Used only if we want to calculate the cell id along a line)
vector<uint64_t> cellIdList;
std::vector<uint64_t> cellIdList;

//Determine how to get the cell id:
//(getCellIdFromCoords might as well take a vector parameter but since I have not seen many vectors used, I'm keeping to
Expand Down Expand Up @@ -1850,19 +1850,19 @@ void extractDistribution( const string & fileName, const UserOptions & mainOptio
//but now for multiple cell ids

//Declare a vector for storing coordinates:
vector< array<Real, 3> > coordinateList;
std::vector< std::array<Real, 3> > coordinateList;
//Store cell ids into coordinateList:
//Note: All mainOptions are user-input
setCoordinatesAlongALine( cellStruct, mainOptions.point1, mainOptions.point2, mainOptions.numberOfCoordinatesInALine, coordinateList );
//Note: (getCellIdFromCoords might as well take a vector parameter but since I have not seen many vectors used,
// I'm keeping to previously used syntax)
//Declare an iterator
vector< array<Real, 3> >::iterator it;
std::vector< std::array<Real, 3> >::iterator it;
//Calculate every cell id in coordinateList
for( it = coordinateList.begin(); it != coordinateList.end(); ++it ) {
//NOTE: since this code is nearly identical to the code for calculating single coordinates, it could be smart to create a separate function for this
//declare coordinates array
const array<Real, 3> & coords = *it;
const std::array<Real, 3> & coords = *it;
//Get the cell id from coordinates
const uint64_t cellID = getCellIdFromCoords( cellStruct, cellIdList_velocity, coords );
if( cellID != numeric_limits<uint64_t>::max() ) {
Expand All @@ -1880,7 +1880,7 @@ void extractDistribution( const string & fileName, const UserOptions & mainOptio
} else if( mainOptions.getCellIdFromInput ) {
//Declare cellID and set it if the cell id is specified by the user
//bool getCellIdFromLine equals true) -- this is done later on in the code ( After the file has been opened)
for(vector<uint64_t>::const_iterator id = mainOptions.cellIdList.begin(); id != mainOptions.cellIdList.end() ; id++) {
for(std::vector<uint64_t>::const_iterator id = mainOptions.cellIdList.begin(); id != mainOptions.cellIdList.end() ; id++) {
//store the cell id in the list of cell ids (This is only used because it makes the code for
//calculating the cell ids from a line clearer)
cellIdList.push_back( *id );
Expand All @@ -1900,7 +1900,7 @@ void extractDistribution( const string & fileName, const UserOptions & mainOptio

//Next task is to iterate through the cell ids and save files:
//Save all of the cell ids' velocities into files:
vector<uint64_t>::iterator it;
std::vector<uint64_t>::iterator it;
//declare extractNum for keeping track of which extraction is going on and informing the user (used in the iteration)
int extractNum = 1;
//Give some info on how many extractions there are and what the save path is:
Expand Down Expand Up @@ -1993,7 +1993,7 @@ int main(int argn, char* args[]) {

//Get the file name
const string mask = args[1];
vector<string> fileList = toolutil::getFiles(mask);
std::vector<string> fileList = toolutil::getFiles(mask);

//Retrieve options variables:
UserOptions mainOptions;
Expand Down

0 comments on commit bf62caa

Please sign in to comment.