Globals Class Reference

special object for accessing system resources More...

List of all members.

Public Member Functions

string system (string command)
string loadTextFile (string filename)
bool fileExists (string filename)
void saveTextFile (string filename, string content)

Static Public Attributes

static string caseStudyId
static string currentDir
static string status
static integer simulationRunId
static bool logging


Detailed Description

special object for accessing system resources

The Globals class is a special object which allows access to some special and system functions. The scripting environment contains a valid instance of Globals automatically, so no need to explicitely create an Globals object.

Use the Globals object for handling files and directories (e.g., the currentDir property and the loadTextFile() and saveTextFile() functions) and for issuing system calls (the system() function).


Member Function Documentation

bool Globals::fileExists ( string  filename  )  [inline]

returns 'true' if the file filename exists.

Parameters:
filename the filename to check for existance
Returns:
true if the filename exists.

string Globals::loadTextFile ( string  filename  )  [inline]

Loads an existing file denoted by filename and returns the content of the file as a single string. If the file does not exist an empty string is returned.

Parameters:
filename to be loaded
Returns:
the content of the loaded file or an empty string.

void Globals::saveTextFile ( string  filename,
string  content 
) [inline]

Saves the string content to the file filename. If the file already exists, it is overwritten.

Parameters:
filename target file name
content the content to be written

string Globals::system ( string  command  )  [inline]

Executes a shell command and returns after the command finishes (or after a timeout period of 60 seconds). The command can be programs or shell scripts including arguments.

Note that the available commands and syntax depend on the target operating system. A special note for windows users: some commands like dir are executed within the command shell (in many cases cmd.exe), for example:

function showDir() {
  print ('directory listing on windows:');
  var output = Globals.system('cmd.exe /C dir'); // use the /C flag of cmd.exe to force immediate return after execution
  print(output);
  p('***********************'); // use the libary shortcut function 'p()'
  p('calling a R script on windows');
  Globals.system('E:/Programme/R/R-2.10.0/bin/R.exe CMD BATCH --no-restore --no-save test.r');
  print(Globals.loadTextFile('test.r.Rout')); // print output of the R batch

}

R scripts can also be executed using the system() call. See the example and also platform specific R documentation for details.

Parameters:
command the command to execute
Returns:
the output of the shell command


Member Data Documentation

string Globals::caseStudyId [static]

The caseStudyId is a read-only property with the value of the case study ID selected within the client. See the client documentation on information on how to change or modify the selected case study. The case study ID provided by this property is used for all data manipulation operations in the MOTIVE database.

string Globals::currentDir [static]

Use the currentDir property to read or set the current dir used for relative adressing of file paths. On startup, currentDir is set to the path of the directory containing the script file. This property can be used to write code that does not rely on absolute file paths.

bool Globals::logging [static]

The logging property controls the amount of log messages produced by the processing engine. A value of 'true' produces more verbose debug messages. Default is 'false'.

integer Globals::simulationRunId [static]

The simulationRunId is the ID of the currently active "simulation run". If no valid simulation run is set, the value of simulationRunId is -1. When importing simulation result data into the MOTIVE database, all data is linked to the simulationRunId, i.e., a valid simulationRunId is the prerequisite for successful import operations.

There are several options how a simulation run can be set active: # creating a new simulation run by calling GlobalScope::simulationrun() with a JSON definition of the simulation run # creating a new simulation run using the MOTIVE client GUI # setting this simulationRunId property: if the id is not valid, an error is thrown # setting an exisiting simulation run by calling GlobalScope::simulationrun() with an ID.

string Globals::status [static]

The status property is used to set a user-visible status message that is shown in the Motive GUI. The Motive GUI shows the status in the status bar at the bottom of the main window.

    function testStatus() {
        // show a running number in the GUI status bar
        for (var i=0;i<1000;i++)
           Globals.status = "reached " + i;
    }


The documentation for this class was generated from the following file:

Generated on Tue Jun 26 09:45:50 2012 for Motive Database Client API by  doxygen 1.5.9