コード例 #1
0
/** Execute function */
RevPtr<RevVariable> Func_write::execute( void )
{
    
    // get the information from the arguments for reading the file
    const std::string& fn = static_cast<const RlString&>( args[1].getVariable()->getRevObject() ).getValue();
    bool  append = static_cast<const RlBoolean&>( args[2].getVariable()->getRevObject() ).getValue();
    const std::string& separator = static_cast<const RlString&>( args[3].getVariable()->getRevObject() ).getValue();
    
    if ( processID == 0 )
    {
    if ( fn != "" ) 
    {
        
        RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(fn);
        fm.createDirectoryForFile();
        
        std::ofstream outStream;
        
        if ( append == true )
        {
            
            // open the stream to the file
            outStream.open(fn.c_str(), std::fstream::out | std::fstream::app);
        }
        else 
        {
            
            // open the stream to the file
            outStream.open(fn.c_str(), std::fstream::out);
        }
        
        // print the arguments
        args[0].getVariable()->getRevObject().printValue(outStream, false);
        for (size_t i = 4; i < args.size(); i++) 
        {
            outStream << separator;
            args[i].getVariable()->getRevObject().printValue( outStream , false );
        }
        
        outStream.close();
    }
    else
    {
        
        std::ostream& o = std::cout;
        
        // print the arguments
        args[0].getVariable()->getRevObject().printValue( o, false );
        for (size_t i = 4; i < args.size(); i++) 
        {
            o << separator;
            args[i].getVariable()->getRevObject().printValue( o, false );
        }
        o << std::endl;
    }
    }

    return NULL;
}
コード例 #2
0
std::vector<std::string> getFileList(const std::string &path)
{
    std::vector<std::string> v;
    
    RbSettings& s = RbSettings::userSettings();
    const std::string& wd = s.getWorkingDirectory();
    
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(wd, path);
    fm.setStringWithNamesOfFilesInDirectory( v );
    
    return v;
}
コード例 #3
0
void RbSettings::setWorkingDirectory(const std::string &wd)
{
    
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager( wd );
    
    if ( !fm.isDirectory() )
    {
        throw RbException("Cannot set the current directory to '" + wd + "'.");
    }
    
    workingDirectory = fm.getFullFilePath();
    
    // save the current settings for the future.
    writeUserSettings();
}
コード例 #4
0
void RbSettings::setModuleDir(const std::string &md)
{
    
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(md);
    
    if ( !fm.isDirectory() )
    {
        throw RbException("Cannot set the help directory to '" + md + "'.");
    }
    
    moduleDir = fm.getFullFilePath();
    
    // save the current settings for the future.
    writeUserSettings();
}
コード例 #5
0
ファイル: Help.cpp プロジェクト: SylerWang/RevBayes
/** Initialize the help from an XML file */
void Help::initializeHelp(std::string helpDir)
{

    // find the path to the directory containing the help files
    RevBayesCore::RbFileManager fMngr = RevBayesCore::RbFileManager();
    //pathToHelpDir = fMngr.getCurrentDirectory();

   
    fMngr.setFilePath(this->helpDir);
    if (fMngr.testDirectory() == false)
    {
        RBOUT("Warning: Cannot find directory containing help files. User help is unavailable. Path = " + this->helpDir);
        return;
    }
    
    
}
コード例 #6
0
/** Format the error exception string for problems specifying the file/path name */
void Func_readCharacterDataUniversal::formatError(RevBayesCore::RbFileManager& fm, std::string& errorStr) {
    
    bool fileNameProvided    = fm.isFileNamePresent();
    bool isFileNameGood      = fm.testFile();
    bool isDirectoryNameGood = fm.testDirectory();
    
    if ( fileNameProvided == false && isDirectoryNameGood == false )
        errorStr += "Could not read contents of directory \"" + fm.getFilePath() + "\" because the directory does not exist";
    else if (fileNameProvided == true && (isFileNameGood == false || isDirectoryNameGood == false))
        {
        errorStr += "Could not read file named \"" + fm.getFileName() + "\" in directory named \"" + fm.getFilePath() + "\" ";
        if (isFileNameGood == false && isDirectoryNameGood == true)
            errorStr += "because the file does not exist";
        else if (isFileNameGood == true && isDirectoryNameGood == false)
            errorStr += "because the directory does not exist";
        else
            errorStr += "because neither the directory nor the file exist";
        }
}
コード例 #7
0
void RbSettings::writeUserSettings( void )
{
    std::string user_dir = RevBayesCore::RbFileManager::expandUserDir("~");
    
    // open the ini file
    std::string settings_file_name = ".RevBayes.ini";
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(user_dir, settings_file_name);

    std::ofstream writeStream;
    fm.openFile( writeStream );
    writeStream << "moduledir=" << moduleDir << std::endl;
    writeStream << "printNodeIndex=" << (printNodeIndex ? "TRUE" : "FALSE") << std::endl;
    writeStream << "tolerance=" << tolerance << std::endl;
    writeStream << "linewidth=" << lineWidth << std::endl;
    writeStream << "useScaling=" << useScaling << std::endl;
    writeStream << "scalingDensity=" << scalingDensity << std::endl;
    writeStream << "collapseSampledAncestors=" << (collapseSampledAncestors ? "TRUE" : "FALSE") << std::endl;
    fm.closeFile( writeStream );

}
コード例 #8
0
ファイル: Module.cpp プロジェクト: hscarter/revbayes
Module::Module(const std::string &fn)
{
    // first we need to load the file
    std::ifstream readStream;
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(fn);
    fm.openFile( readStream );
    
    /* File-processing loop */
    while ( readStream.good() )
    {
        
        // Read a line
        std::string line;
        getline( readStream, line );
        
        commandLines.push_back( line );
        
    }

}
コード例 #9
0
/** Initialize the help from an XML file */
void RbHelpSystem::initializeHelp(const std::string &helpDir)
{
    
    // find the path to the directory containing the help files
    RevBayesCore::RbFileManager fMngr = RevBayesCore::RbFileManager();
    
    fMngr.setFilePath(helpDir);
    if (fMngr.testDirectory() == false)
    {
        throw RbException("Warning: Cannot find directory containing help files. User help is unavailable. Path = " + helpDir);
    }
    
    // get a help parser instance
    RbHelpParser parser = RbHelpParser();
    
    // get the files contained in the directory

    // gather all xml files in help dir, filtered by '.ext'
    std::string ext = "xml";
    std::vector<std::string> files;
    std::vector<std::string> fileNames;
    fMngr.setStringWithNamesOfFilesInDirectory( files );
    for (std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it)
    {
        RevBayesCore::RbFileManager tmpFM = RevBayesCore::RbFileManager( *it );
        if ( tmpFM.getFileExtension() == ext)
        {
            fileNames.push_back( *it );
        }
    }

    for (std::vector<std::string>::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
    {
        
        if ( parser.testHelpEntry( *it ) == RbHelpParser::FUNCTION )
        {
            
            RbHelpFunction h = parser.parseHelpFunction( *it );
            helpForFunctions.insert( std::pair<std::string,RbHelpFunction>( h.getName() , h) );
            helpFunctionNames.insert( h.getName() );
            
            
            // also add all aliases
            const std::vector<std::string>& aliases = h.getAliases();
            for (std::vector<std::string>::const_iterator alias = aliases.begin(); alias != aliases.end(); ++alias)
            {
                helpForFunctions.insert( std::pair<std::string,RbHelpFunction>( *alias , h) );
            }
            
        }
        
        
        
        if ( parser.testHelpEntry( *it ) == RbHelpParser::TYPE || parser.testHelpEntry( *it ) == RbHelpParser::DISTRIBUTION || parser.testHelpEntry( *it ) == RbHelpParser::MONITOR || parser.testHelpEntry( *it ) == RbHelpParser::MOVE )
        {
            
            RbHelpType* h = NULL;
            if ( parser.testHelpEntry( *it ) == RbHelpParser::TYPE )
            {
                h = parser.parseHelpType( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::DISTRIBUTION )
            {
                h = parser.parseHelpDistribution( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::MONITOR )
            {
                h = parser.parseHelpMonitor( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::MOVE )
            {
                h = parser.parseHelpMove( *it );
            }

            helpForTypes.insert( std::pair<std::string,RbHelpType*>( h->getName() , h) );
            helpTypeNames.insert( h->getName() );
            
            
            // create a map for all methods for this type
            std::map<std::string, RbHelpFunction> methodsHelp;
            const std::vector<RbHelpFunction>& method = h->getMethods();
            for (std::vector<RbHelpFunction>::const_iterator m = method.begin(); m != method.end(); ++m)
            {
                methodsHelp.insert( std::pair<std::string,RbHelpFunction>( m->getName() , *m) );
            }
            
            // add the methods to our global map
            helpForMethods.insert( std::pair<std::string, std::map<std::string,RbHelpFunction> >(h->getName(),methodsHelp) );
            
            
            // also add all aliases
            const std::vector<std::string>& aliases = h->getAliases();
            for (std::vector<std::string>::const_iterator alias = aliases.begin(); alias != aliases.end(); ++alias)
            {
                helpForTypes.insert( std::pair<std::string,RbHelpType*>( *alias , h->clone() ) );
                helpForMethods.insert( std::pair<std::string, std::map<std::string,RbHelpFunction> >(*alias,methodsHelp) );
            }
        }
        
        
    }
    
    
}
コード例 #10
0
void RbSettings::initializeUserSettings(void)
{
    moduleDir = "modules";      // the default module directory
    useScaling = false;          // the default useScaling
    scalingDensity = 4;         // the default scaling density
    lineWidth = 160;            // the default line width
    tolerance = 10E-10;         // set default value for tolerance comparing doubles
    printNodeIndex = true;      // print node indices of tree nodes as comments
    collapseSampledAncestors = true;
    
    std::string user_dir = RevBayesCore::RbFileManager::expandUserDir("~");
    
    // read the ini file, override defaults if applicable
    std::string settings_file_name = ".RevBayes.ini";
    RevBayesCore::RbFileManager fm = RevBayesCore::RbFileManager(user_dir, settings_file_name);

 	
    //    bool failed = false; //unused
    if ( fm.isFile() )
    {
        std::ifstream readStream;
        fm.openFile( readStream );
        std::string readLine = "";
        while ( std::getline(readStream,readLine) )
        {
            std::vector<std::string> tokens = std::vector<std::string>();
            StringUtilities::stringSplit(readLine, "=", tokens);
            if (tokens.size() > 1)
            {
                setOption(tokens[0], tokens[1], false);
            }
        }
        
        fm.closeFile(readStream);
    }

    // initialize the current directory to be the directory the binary is sitting in
#	ifdef RB_WIN
    
    char buffer[MAX_DIR_PATH];
    GetModuleFileName( NULL, buffer, MAX_DIR_PATH );
    std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" );
    workingDirectory = std::string( buffer ).substr( 0, pos);

#	else

    char cwd[MAX_DIR_PATH+1];
	if ( getcwd(cwd, MAX_DIR_PATH+1) )
    {
        std::string pathSeparator = "/";
        
        std::string curdir = cwd;
        
        if ( curdir.at( curdir.length()-1 ) == pathSeparator[0] )
        {
            curdir.erase( curdir.length()-1 );
        }
        
        workingDirectory = curdir;
	}
    else
    {
        workingDirectory = "";
    }
    
#   endif

    
    // save the current settings for the future.
//    writeUserSettings();
}