lib/io/parser.cc
/**
 ********************************************************************************************************************************************
 * \brief   Function to parse the probeCoords string
 *
 *          The user specifies probeCoords in NumPy's linspace style with colons
 *          This function extracts the coordinates of the probes from the given string.
 ********************************************************************************************************************************************
 */
\brief   Function to parse the probeCoords string
The user specifies probeCoords in NumPy's linspace style with colons
This function extracts the coordinates of the probes from the given string.
\ brief Function to parse the probeCoords string The user specifies probeCoords in NumPy ' s linspace style with colons This function extracts the coordinates of the probes from the given string .
void parser::parseProbes() {
    std::string errorProbe;
    while (true) {
        std::vector<std::vector<int> > indexList;
        std::string oneSet = probeCoords.substr(probeCoords.find('[') + 1, probeCoords.find(']') - 1);
        errorProbe = oneSet;
        oneSet.append(",");
        while (true) {
            std::vector<int> indexVector;
            std::istringstream iss;
            std::string indexData = oneSet.substr(oneSet.find_first_not_of(' '), oneSet.find(',') - oneSet.find_first_not_of(' '));
            indexData.erase(indexData.find_last_not_of(' ') + 1, indexData.length());
            oneSet.erase(0, oneSet.find(',') + 1);
            if (indexData.find(":") == std::string::npos) {
                int indexVal;
                iss.str(indexData);
                iss >> indexVal;
                indexVector.push_back(indexVal);
                indexList.push_back(indexVector);
            } else {
                unsigned int strIndex, endIndex, numIndex;
                std::string rangeStart = indexData.substr(0, indexData.find(':'));
                indexData.erase(0, indexData.find(':') + 1);
                iss.clear();
                iss.str(rangeStart);
                iss >> strIndex;
                std::string rangeEnd = indexData.substr(0, indexData.find(':'));
                indexData.erase(0, indexData.find(':') + 1);
                iss.clear();
                iss.str(rangeEnd);
                iss >> endIndex;
                iss.clear();
                iss.str(indexData);
                iss >> numIndex;
                if ((strIndex == endIndex) or (numIndex == 1)) {
                    indexVector.push_back(strIndex);
                } else {
                    for (unsigned int i = 0; i < numIndex; i++) {
                        real incIndex = ((real)endIndex - (real)strIndex)/((real)numIndex - 1);
                        int probeIndex = strIndex + (int)round((real)i*incIndex);
                        indexVector.push_back(probeIndex);
                    }
                }
                indexList.push_back(indexVector);
            }
            if (oneSet.length() < 2) {
                break;
            }
        }
        probeCoords.erase(0, probeCoords.find(']') + 1);
        probeCoords.erase(0, probeCoords.find_first_not_of(' '));
#ifdef PLANAR
        if (indexList.size() == 2) {
            for (unsigned int iX = 0; iX < indexList[0].size(); iX++) {
                for (unsigned int iZ = 0; iZ < indexList[1].size(); iZ++) {
                    blitz::TinyVector<int, 3> probeLoc;
                    probeLoc = indexList[0][iX], 0, indexList[1][iZ];
                    probesList.push_back(probeLoc);
                }
            }
        } else if (indexList.size() == 3) {
            for (unsigned int iX = 0; iX < indexList[0].size(); iX++) {
                for (unsigned int iZ = 0; iZ < indexList[2].size(); iZ++) {
                    blitz::TinyVector<int, 3> probeLoc;
                    probeLoc = indexList[0][iX], 0, indexList[2][iZ];
                    probesList.push_back(probeLoc);
                }
            }
        } else {
            std::cout << "WARNING: Number of indices for the probe(s) " << errorProbe << " does not match dimensionality of problem." << std::endl;
        }
#else
        if (indexList.size() == 3) {
            for (unsigned int iX = 0; iX < indexList[0].size(); iX++) {
                for (unsigned int iY = 0; iY < indexList[1].size(); iY++) {
                    for (unsigned int iZ = 0; iZ < indexList[2].size(); iZ++) {
                        blitz::TinyVector<int, 3> probeLoc;
                        probeLoc = indexList[0][iX], indexList[1][iY], indexList[2][iZ];
                        probesList.push_back(probeLoc);
                    }
                }
            }
        } else {
            std::cout << "ERROR: Number of indices for the probe(s) [" << errorProbe << "] does not match dimensionality of problem. ABORTING" << std::endl;
            MPI_Finalize();
            exit(0);
        }
#endif
        if (probeCoords.length() < 3) {
            break;
        }
    }
}
void parser :: parseProbes ( ) { std :: string errorProbe ; while ( true ) { std :: vector < std :: vector < int > > indexList ; std :: string oneSet = probeCoords . substr ( probeCoords . find ( ' ' ) + 1 , probeCoords . find ( ' ' ) - 1 ) ; errorProbe = oneSet ; oneSet . append ( " " ) ; while ( true ) { std :: vector < int > indexVector ; std :: istringstream iss ; std :: string indexData = oneSet . substr ( oneSet . find_first_not_of ( ' ' ) , oneSet . find ( ' ' ) - oneSet . find_first_not_of ( ' ' ) ) ; indexData . erase ( indexData . find_last_not_of ( ' ' ) + 1 , indexData . length ( ) ) ; oneSet . erase ( 0 , oneSet . find ( ' ' ) + 1 ) ; if ( indexData . find ( " " ) == std :: string :: npos ) { int indexVal ; iss . str ( indexData ) ; iss >> indexVal ; indexVector . push_back ( indexVal ) ; indexList . push_back ( indexVector ) ; } else { unsigned int strIndex , endIndex , numIndex ; std :: string rangeStart = indexData . substr ( 0 , indexData . find ( ' ' ) ) ; indexData . erase ( 0 , indexData . find ( ' ' ) + 1 ) ; iss . clear ( ) ; iss . str ( rangeStart ) ; iss >> strIndex ; std :: string rangeEnd = indexData . substr ( 0 , indexData . find ( ' ' ) ) ; indexData . erase ( 0 , indexData . find ( ' ' ) + 1 ) ; iss . clear ( ) ; iss . str ( rangeEnd ) ; iss >> endIndex ; iss . clear ( ) ; iss . str ( indexData ) ; iss >> numIndex ; if ( ( strIndex == endIndex ) or ( numIndex == 1 ) ) { indexVector . push_back ( strIndex ) ; } else { for ( unsigned int i = 0 ; i < numIndex ; i ++ ) { real incIndex = ( ( real ) endIndex - ( real ) strIndex ) / ( ( real ) numIndex - 1 ) ; int probeIndex = strIndex + ( int ) round ( ( real ) i * incIndex ) ; indexVector . push_back ( probeIndex ) ; } } indexList . push_back ( indexVector ) ; } if ( oneSet . length ( ) < 2 ) { break ; } } probeCoords . erase ( 0 , probeCoords . find ( ' ' ) + 1 ) ; probeCoords . erase ( 0 , probeCoords . find_first_not_of ( ' ' ) ) ; #ifdef PLANAR if ( indexList . size ( ) == 2 ) { for ( unsigned int iX = 0 ; iX < indexList [ 0 ] . size ( ) ; iX ++ ) { for ( unsigned int iZ = 0 ; iZ < indexList [ 1 ] . size ( ) ; iZ ++ ) { blitz :: TinyVector < int , 3 > probeLoc ; probeLoc = indexList [ 0 ] [ iX ] , 0 , indexList [ 1 ] [ iZ ] ; probesList . push_back ( probeLoc ) ; } } } else if ( indexList . size ( ) == 3 ) { for ( unsigned int iX = 0 ; iX < indexList [ 0 ] . size ( ) ; iX ++ ) { for ( unsigned int iZ = 0 ; iZ < indexList [ 2 ] . size ( ) ; iZ ++ ) { blitz :: TinyVector < int , 3 > probeLoc ; probeLoc = indexList [ 0 ] [ iX ] , 0 , indexList [ 2 ] [ iZ ] ; probesList . push_back ( probeLoc ) ; } } } else { std :: cout << " " << errorProbe << " " << std :: endl ; } #else if ( indexList . size ( ) == 3 ) { for ( unsigned int iX = 0 ; iX < indexList [ 0 ] . size ( ) ; iX ++ ) { for ( unsigned int iY = 0 ; iY < indexList [ 1 ] . size ( ) ; iY ++ ) { for ( unsigned int iZ = 0 ; iZ < indexList [ 2 ] . size ( ) ; iZ ++ ) { blitz :: TinyVector < int , 3 > probeLoc ; probeLoc = indexList [ 0 ] [ iX ] , indexList [ 1 ] [ iY ] , indexList [ 2 ] [ iZ ] ; probesList . push_back ( probeLoc ) ; } } } } else { std :: cout << " " << errorProbe << " " << std :: endl ; MPI_Finalize ( ) ; exit ( 0 ) ; } #endif if ( probeCoords . length ( ) < 3 ) { break ; } } }
\brief   Function to parse the probeCoords string
          The user specifies probeCoords in NumPy's linspace style with colons
          This function extracts the coordinates of the probes from the given string.
\ brief Function to parse the probeCoords string The user specifies probeCoords in NumPy ' s linspace style with colons This function extracts the coordinates of the probes from the given string .
// Extract the leading set enclosed by square brackets // Erase the extracted set // Only a single integer // Further processing necessary to extract range // Erase the extracted set // Remove possible white-spaces between the sets // Add the coordinates from the extracted set to global coordinates list // The number 3 is randomly chosen. Ideally if the string is smaller than that, it has no more info