Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge
swh:1:cnt:5bba6b43ee326324a0300dc93c10ed840038998d

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
#include <eigen/dense>
using namespace Eigen;

#include "matlab_utils.h"

#ifdef ENABLE_MATLAB

MatlabEngine gMatEngine;

// Matlab engine
#pragma comment(lib, "libeng.lib")
#pragma comment(lib, "libmx.lib")

bool MatlabEngine::connect(const std::string &dir, bool closeAll)
{
    if (eng)
        return true;

    if (0) {
		// 0 = success
		// -2 = error - second argument must be NULL
		// -3 = error - engOpenSingleUse failed
		int retstatus;
		if ( !(eng = engOpenSingleUse("\0", NULL, &retstatus)) ) {
            fprintf(stderr, "Can't start MATLAB engine: %d\n", retstatus);
			return false;
		}
    }
    else {
        printf( "Starting MATLAB engine ... " );
        if (!(eng = engOpen("\0"))) {
            fprintf(stderr, "Failed!\n");
			return false;
		}
        printf( "Succeed!\n");
	}

	engBuffer[lenEngBuffer-1] = '\0';
	engOutputBuffer(eng, engBuffer, lenEngBuffer); 

	// set current path
    engEvalString(eng, ("cd " + dir).c_str());

	//engEvalString(eng, "clear all; clc; rehash;"); 
    if (closeAll)
		engEvalString(eng, "close all;"); 

	return true;
}

void MatlabEngine::eval(const std::string &cmd, bool PrintInfo)
{
    ensure(connected(), "Not connected to Matlab!");

    if (consoleOutput) 
        engOutputBuffer(eng, engBuffer, lenEngBuffer);
    else
        engOutputBuffer(eng, nullptr, 0);

    //engEvalString(eng, "dbclear all;");
    //engEvalString(eng, "if ~isempty(dbstatus), warning('Clear all breakpoint, Matlab cannot be debugged from C++!'); dbclear all; end"); // debug will cause matlab to crash
    if (consoleOutput && *engBuffer) fprintf(stderr, "%s\n", engBuffer);

    int r = engEvalString(eng, cmd.c_str());
    if (r != 0) {
        if (r == 1) fprintf(stderr, "Engine session no longer running!\n");

        fprintf(stderr, "engEvalString error!\n");
    }

    if (consoleOutput && *engBuffer) {
		if(PrintInfo)
			fprintf(stdout, "--------------\n%s\n--------------\n%s\n", cmd.c_str(), engBuffer);
		else
			fprintf(stdout, "--------------\n%s\n", engBuffer);
	}
}


void MatlabEngine::close()
{
    printf( "Shutting down MATLAB engine ... " );
	engClose(eng);
	printf( "done!\n" );
	eng = nullptr;
}

MatlabEngine& getMatEngine() 
{	
	return gMatEngine; 
}

#endif

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API