User Tools

Site Tools


documentation:java-c_connection

A Java - C++ connection with JNA for the Phelib library in Capsis

This work is under progress

These are working notes for the Phelib connection to Capsis, made in June 2015 (Isabelle chuine, Yassine Motié, Inaki Garcia, Gallian Colombeau, Hendrik Davi, Hélène Raynal, Eric Casellas, F. de Coligny)

Preparation notes:

  • Phelib source files in /home/coligny/des-trucs/phelib
  • Downloaded jdk 7 windows 32 and 64 bits
  • Compile the dll for windows 64 bits
  • copy the dll to capsis4/ext/windows64/
  • make sure the dll path is in java.library.path AND in the system PATH variable
  • Add in capsis.bat : PATH=%jlp%;$PATH

Notes de fin de réunion 30 juin 2015 Avignon

fonctions interface possibles :

String getVersion ()

init (String path_xml_file)
    appelle execute () de phelib

int getPhaseCount ()
    retoure le nombre de phases gérées par le métamodèle
    utilisable pour tailler les tableaux float[] de la fonction f(), en fin de signature

f (site, year, doy, latitude, 

    float[] climat_t, 
	Dans l'ordre attendu par Phelib (recompilation si changelent de modèle Phelib)
	Exemple : 
	tmoy, 
	tmin, 
	tmax, 
	pre, 
	wind
    float[] climat_t+1, 
	Idem, même ordre (incluant tmin_t+1, Option 2)

    int[] prevId, float[] prevValue,  -> valeurs retournées la veille
    int[] newId, float[] newValue); -> resultats : phases et valeurs

Quelques erreurs rouges dans Dependency Walker

2 fics: dll et dlla

Localisation du projet, sources Phelib: C:/tmp

dans standalone/src/CmakeList SHARED → dll (sinon STATIC)

c:/boost_include c:/mingw

compilation c:/Users/051E999/local/lib → libPhelib.dll

La méthode getVersion n'est pas trouvée par Java Phelib.java

Commandes de compilation de libPhelib.dll

fc - 1.7.2015

Notes suite a la reunion Phelib d'Avignon avec Hélène Raynal, EricCasellas, Gallian Colombeau, Isabelle Chuine, Yassine Motié, fc

Effectué sur le portable collectif AMAP CIRE999 sous Windows 64 bits

> cd /tmp/phelib/build

>C:\tmp\phelib\build>cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX='%HOMEDRIV
E%%HOMEPATH%\local\' -DBoost_INCLUDE_DIR="C://boost_include" -DBUILD_VLE_SOURCE_
PKGS=OFF ..

C:\tmp\phelib\build>mingw32-make.exe -j 4

C:\tmp\phelib\build>mingw32-make.exe install

Sources Phelib : dans c:\tmp\phelib

Arborescence de Gallian et Eric : 

c:/tmp/
    boost_1_55_0/
    phelib/
    PhelibInterface.cpp
    PhelibInterface.hpp
    

Travail du 2.7.2015

Des exemples de functions interfaces à la fonction compute en place dans Phelib (modification différée pou qu'elle renvoie plusieurs phases en cours).

// PhelibInterface.hpp
 
#ifndef PHELIB_CORE_PHELIBINTERFACE_HPP_
#define PHELIB_CORE_PHELIBINTERFACE_HPP_
 
#include<phelib/core/MetaModel.hpp>
#include<string>
 
namespace phelib{
/**
 * @brief Module core, contient tous les composants de base.
 */
namespace core{
 
/**
 * An front-end to Phelib, with public functions in a Dll.
 * These functions can be called from other languages 
 * (e.g. Java through JNA).
 * 
 * Yassine Motié, Isabelle Chuine, Francois de Coligny - July 2015
 */
class PhelibInterface
{
	// Reference to the MetaModel created in init()
	MetaModel metamodel;
 
	public:
	PhelibInterface();
 
	// Returns the version of Phelib
	std::string getVersion() const { return "5.0"; }
 
	// Inits the metamodel with the given xml file name
	void init(const &std::string);
 
	// Returns the number of Phases this MetaModel manages
	int getPhaseCount() const;
 
	// A link function to compute () with only simple types
	void f1(int site, int year, int doy, float latitude, unsigned int nVariables, 
		float* climateDoy, float* climateDayAfter, float prevValue,
		float & newValue);
 
	// LATER: a link function to the new compute () returning one or several
	// active phases for a given doy
//	void f2(int site, int year, int doy, float latitude, unsigned int nVariables, 
//		float* climateDoy, float* climateDayAfter, int* prevIds, float* prevValues,
//		int* phaseIds, float* phaseValues);
 
};
 
}
}
 
#endif
// PhelibInterface.cpp
#include<phelib/core/PhelibInterface.hpp>
#include<phelib/io/XMLFormat.hpp>
 
 
namespace phelib{
/**
 * @brief Module core, contient tous les composants de base.
 */
namespace core{ 
 
// Inits the metamodel with the given xml file name
void PhelibInterface::init(const &std::string filename)
{
	metamodel.execute<io::InputXMLFormat>(filename);
}
 
// Returns the number of Phases this MetaModel manages
int Phelib::getPhaseCount() const
{
	return metamodel.getPhaseCount();
}
 
 
 
// A link function to compute () with only simple types
void f1(int site, int year, int doy, float latitude, int nVariables, 
	float* climateDoy, float* climateDayAfter, float prevValue,
	float & newValue) 
{
	// Créer un WeatherDay
	pb::weather::WeatherDay day;
 
	day.station = site;
	day.latitude = latitude;
	day.year = year;
	day.doy = doy;
	day.tmean = climateDoy[0];
	day.tmin = climateDoy[1];
	day.tmax = climateDoy[2];
 
	if (nVariables > 3) {
		for (int i = 3; i < nVariables; i++) {
			day->push(climateDoy[i]);
		}
	}
 
	// Le mettre dans un WeatherSlider
	pb::weather::WeatherSlider slider(day);
 
	double v = metamodel.compute(slider, (double) prevValue);
 
	newValue = (float) v;
 
}
 
 
 
}
}
documentation/java-c_connection.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1