Child pages
  • Integrating a Non-Java Program As An Algorithm

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Figure 9: Adding the input parameter. Image Added

Figure 10: The Algorithm Parameters page with the input parameter specified.
Click Next >.


The example algorithm in this tutorial expects one item off of the Data Manager, so click the Add button under the Input Data section to add a new input data item. For the Mime Type, input text/nwb. Image Added
Figure 11: Adding the input data item.

The example algorithm in this tutorial also outputs one item on to the Data Manager, so click the Add button under the Output Data section to add a new output data item. Give the output data item the following values: File Name: output.txt Label: Example Non-Java Algorithm Output File Data Type: Text Mime Type: text/plain Image Added
Figure 12: Adding the output data item. Image Added
Figure 13: The Input and Output Data page with the input and output data items specified.

The seventh page is the Template String page. The template string tells CIShell what command-line string to use when invoking your compiled program. It can contain placeholders that correspond to either values specified by the end-user (as input parameters) or the files chosen from the Data Manager by the end-user (as input data items). A placeholder is specified in the template string by the text _$


(quotes included) should appear in the Template String field. Image Added
Figure 14: The first template string placeholder has been inserted.

Repeat this process again, except this time select the second item in the Template String Placeholders table (which should be the text/nwb File entry). After that, append the text "platform.txt" and "output.txt" (quotes included) to the template string. Image Added
Figure 15: The final template string, containing the input parameter placeholder; the input data item placeholder; the platform file; and the fourth argument the example program expects, which the name of the file to output to.

The eighth and final page is the Source Code Files page. It lets you choose a single file for your source code, if you wish to include your source code in the CIShell algorithm. Most likely, your source code will consist of multiple files, so you will need to archive them into a single file first. For this tutorial, however, the .cpp source file can be chosen since it is the only one involved in compiling the example program. Image Added
Figure 16: The .cpp source code file has been chosen.

You should now have a new project in your Eclipse workspace. Image Added
Figure 17: The new project in the Eclipse workspace.


Now that you have an Eclipse project for your algorithm, the next step is to build the project. Fortunately, it is just a matter of running the build.xml Ant script that was created with your project. Right-click on the build.xml file and select Run As->Ant Build to build the project. Image Added
Figure 18: Building the Eclipse project.

Your project should build successfully, and you should see output in your console that reflects this.


Now that your project has been built, it can be exported as a plugin for Network Workbench. Refresh your workspace. (You can do this by right-clicking on your project in the Package Explorer and selecting Refresh.) You should see a new build directory. Expand it. Inside of it should be an out directory and a file called projectName_bundleVersion.jar, where projectName and bundleVersion were specified in the wizard. (For this tutorial, the file would be called example.nonjava.algorithm_0.0.1.jar.) Right-click on this file, and select Export... Image Added
Figure 19: Exporting the built Network Workbench plugin.

The Export window should open. Select General->File System, and click Next >. Image Added
Figure 20: Exporting the built Network Workbench plugin.

The next page will allow you to select the files you want to export and where on your file system to export them. On the left hand side, select the build directory, and make sure the appropriate jar file (i.e. example.nonjava.algorithm_0.0.1.jar) on the right hand side is checked. Both of these should be done by default.

Select the plugins directory inside your Network Workbench installation (e.g. C:\Program Files\NWB\plugins), and then click Finish. (Note: If this plugin already exists in your Network Workbench installation, you will be prompted to overwrite the already-existing file. Just click Yes.) Image Added
Figure 21: Exporting the built Network Workbench plugin.

Once your algorithm plugin has been exported and you have loaded Network Workbench, your algorithm will be on the menu that you specified. When you run the algorithm, a window should open that displays the file selection input parameter you specified on the Input Parameters page.


Code Block
\#include <iostream>
\#include <fstream>

\#define PROGRAM_NAME "NonJavaAlgorithmWizardExample"

std::string readUserFile(const std::string& userFileName)
std::string readNWBFile(const std::string& nwbFileName) throw(std::exception);
std::string readPlatformFile(const std::string& platformFileName)
std::string readFileContents(std::ifstream& inputFileStream);

void outputCombinedContentsToFile(const std::string& userFileContents,
const std::string& nwbFileContents,
const std::string& platformFileContents,
const std::string& fileName)

int main (int argumentCount, char\* arguments\[\]) {
if (argumentCount < EXPECTED_ARGUMENT_COUNT) {
        std::cerr << "You must provide " << EXPECTED_ARGUMENT_COUNT - 1;
        std::cerr << " arguments to the program." << std::endl;
        std::cerr << "Expected format:" << std::endl;
        std::cerr << "user_file nwb_file platform_file output_file";
        std::cerr << std::endl;
    } else {
// Process the end-user-specified file.

std::string userFileName = arguments[USER_FILE_ARGUMENT_INDEX|USER_FILE_ARGUMENT_INDEX];
std::string userFileContents;

try {
            userFileContents = readUserFile(userFileName);

            std::cout << "Successfully read the file you specified \'";
            std::cout << userFileName << "\'." << std::endl;
        } catch (std::exception& readUserFileException) {
            std::cerr << "There was an error reading your file \'";
            std::cerr << userFileName << "\': \"";
            std::cerr << readUserFileException.what() << "\"" << std::endl;

            return 1;

// Process the NWB file.

std::string nwbFileName = arguments[NWB_FILE_ARGUMENT_INDEX|NWB_FILE_ARGUMENT_INDEX];
std::string nwbFileContents;

try {
            nwbFileContents = readNWBFile(nwbFileName);

            std::cout << "Successfully read the NWB file you selected off of ";
            std::cout << "the Data Manager (\'" << nwbFileName << "\').";
            std::cout << std:: endl;
        } catch (std::exception& readNWBFileException) {
            std::cerr << "There was an error reading the NWB file \'";
            std::cerr << nwbFileName << "\': \"";
            std::cerr << readNWBFileException.what() << "\"" << std::endl;

// Process the platform file.

std::string platformFileContents;

try {
            platformFileContents = readPlatformFile(platformFileName);

            std::cout << "Successfully read the platform file \'";
            std::cout << platformFileName << "\'." << std::endl;
        } catch (std::exception& readPlatformFileException) {
            std::cerr << "There was an error reading the platform file \'";
            std::cerr << platformFileName << "\': \"";
            std::cerr << readPlatformFileException.what() << "\"" << std::endl;

            return 1;

* Combine the user-specified file contents and the platform file into
* the user-specified output file.


try {

            std::cout << "Successfully wrote the combined contents to the ";
            std::cout << "file \'" << outputFileName << "\'." << std::endl;
        } catch (std::exception& outputCombinedContentsToFileException) {
            std::cerr << "There was an error outputting the combined contents";
            std::cerr << " of the file you specified and the platform file ";
            std::cerr << "to the file \'" << outputFileName << "\': \"";
            std::cerr << outputCombinedContentsToFileException.what();
            std::cerr << "\"" << std::endl;

return 0;

std::string readUserFile(const std::string& userFileName)
throw(std::exception) {
std::ifstream userFileStream(userFileName.c_str(), std::ifstream::in);

if (\!userFileStream.is_open()) {
        throw std::ios_base::failure("Unable to open user file for reading.");

std::string userFileContents = readFileContents(userFileStream);

return userFileContents;

std::string readNWBFile(const std::string& nwbFileName) throw(std::exception) {
std::ifstream nwbFileStream(nwbFileName.c_str(), std::ifstream::in);

if (\!nwbFileStream.is_open()) {
        throw std::ios_base::failure("Unable to open NWB file for reading.");

std::string nwbFileContents = readFileContents(nwbFileStream);

return nwbFileContents;

std::string readPlatformFile(const std::string& platformFileName)
throw(std::exception) {
std::ifstream platformFileStream(platformFileName.c_str(),

if (\!platformFileStream.is_open()) {
        throw std::ios_base::failure(
            "Unable to open platform file for reading.");

std::string platformFileContents = readFileContents(platformFileStream);

return platformFileContents;

std::string readFileContents(std::ifstream& inputFileStream) {
std::string fileContents;

while (inputFileStream.good()) {
        fileContents += inputFileStream.get();

return fileContents;

void outputCombinedContentsToFile(const std::string& userFileContents,
const std::string& nwbFileContents,
const std::string& platformFileContents,
const std::string& fileName)
throw(std::exception) {
std::ofstream outputFileStream(fileName.c_str(), std::ofstream::out);

if (\!outputFileStream.is_open()) {
        throw std::ios_base::failure(
            "Unable to open output file for writing.");

outputFileStream << "User file contents:" << std::endl;
outputFileStream << userFileContents << std::endl;

outputFileStream << "NWB file contents:" << std::endl;
outputFileStream << nwbFileContents << std::endl;

outputFileStream << "Platform:" << std::endl;
outputFileStream << platformFileContents << std::endl;