| 1 | #include <stdio.h>
 | 
|---|
| 2 | #include <stdlib.h>
 | 
|---|
| 3 | #include <math.h>
 | 
|---|
| 4 | #include <iostream>
 | 
|---|
| 5 | #include <fstream>
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include "sopnamsp.h"
 | 
|---|
| 8 | #include "tarrinit.h"
 | 
|---|
| 9 | #include "array.h"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include "pdlmgr.h"
 | 
|---|
| 12 | #include "pexceptions.h"
 | 
|---|
| 13 | #include "timing.h"
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // Fonction de test qu'on reproduit dans le fichier CTestFileName
 | 
|---|
| 16 | double testfunc_dynl(double x, double y)
 | 
|---|
| 17 | {
 | 
|---|
| 18 |   return (exp(-x)+sin(y)*x);
 | 
|---|
| 19 | }
 | 
|---|
| 20 | 
 | 
|---|
| 21 | typedef double (* MyDlFunctionOfXY) (double x, double y);
 | 
|---|
| 22 | 
 | 
|---|
| 23 | int main(int narg, char *arg[])
 | 
|---|
| 24 | {
 | 
|---|
| 25 |   SophyaInit();
 | 
|---|
| 26 |   InitTim();
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   if (narg < 3) {
 | 
|---|
| 29 |     cout << " --- tdynl -- test de la classe PDynLinkMgr --- \n " 
 | 
|---|
| 30 |          << " Usage: tdynl TmpDirName/ CTestFileName\n" 
 | 
|---|
| 31 |          << " Exemple: tdynl /tmp/ toto.c \n" << endl;
 | 
|---|
| 32 |    return(0);
 | 
|---|
| 33 |   }
 | 
|---|
| 34 | 
 | 
|---|
| 35 |   try {
 | 
|---|
| 36 |     string TmpDirName = arg[1];
 | 
|---|
| 37 |     string CTestFileName = arg[2];
 | 
|---|
| 38 |     string cfilename = TmpDirName + CTestFileName;
 | 
|---|
| 39 |     {
 | 
|---|
| 40 |       ofstream of(cfilename.c_str());
 | 
|---|
| 41 |       of << "#include <math.h> \n "
 | 
|---|
| 42 |          << "double myf_dyl(double x, double y) \n"
 | 
|---|
| 43 |          << "{ \n" 
 | 
|---|
| 44 |          << " return (exp(-x)+sin(y)*x); \n"
 | 
|---|
| 45 |          << "} \n" << endl;
 | 
|---|
| 46 |       cout << " File " << cfilename << "created ... " << endl;
 | 
|---|
| 47 |       }
 | 
|---|
| 48 | 
 | 
|---|
| 49 |     cout << " Calling PDynLinkMgr::BuildFromCFile(" << cfilename << ")" << endl;
 | 
|---|
| 50 |     PDynLinkMgr::SetTmpDir(TmpDirName);
 | 
|---|
| 51 |     PDynLinkMgr * dyl = PDynLinkMgr::BuildFromCFile(cfilename);
 | 
|---|
| 52 |     PrtTim(" End of Compile-Link ");
 | 
|---|
| 53 |     if (dyl != NULL) {
 | 
|---|
| 54 |       MyDlFunctionOfXY f = (MyDlFunctionOfXY)dyl->GetFunction("myf_dyl");  
 | 
|---|
| 55 |       if (f != NULL) {
 | 
|---|
| 56 |         cout << " DlFunction f dyl.GetFunction(myf_dyl) linked OK - calling f() " << endl;
 | 
|---|
| 57 |         cout << "f(0,1)= " << f(0.,1.) << "  ?= testfunc_dynl(0,1)= " << testfunc_dynl(0.,1.) << endl;
 | 
|---|
| 58 |         cout << "f(1,1)= " << f(1.,1.) << "  ?= testfunc_dynl(1,1)= " << testfunc_dynl(1.,1.) << endl;
 | 
|---|
| 59 |         cout << "f(-1,2.5)= " << f(-1.,2.5) << "  ?= testfunc_dynl(-1,2.5)= " << testfunc_dynl(-1.,2.5) << endl;
 | 
|---|
| 60 |       } 
 | 
|---|
| 61 |       else {
 | 
|---|
| 62 |         cout << " ERROR linking DlFunction f !!! " << endl;
 | 
|---|
| 63 |       }
 | 
|---|
| 64 |     delete dyl;
 | 
|---|
| 65 |     }
 | 
|---|
| 66 |     else cout << " ERROR Creating shared object !!! " << endl;
 | 
|---|
| 67 |   }
 | 
|---|
| 68 |  
 | 
|---|
| 69 |   catch (PThrowable & exc) {
 | 
|---|
| 70 |     cerr << " Catched Exception " << (string)typeid(exc).name()
 | 
|---|
| 71 |          << " - Msg= " << exc.Msg() << endl;
 | 
|---|
| 72 |   }
 | 
|---|
| 73 |   catch (...) {
 | 
|---|
| 74 |     cerr << " some other exception was caught ! " << endl;
 | 
|---|
| 75 |   }
 | 
|---|
| 76 | 
 | 
|---|
| 77 |   PrtTim(" End of tdynl ");
 | 
|---|
| 78 | }
 | 
|---|