source: Sophya/trunk/SophyaProg/Tests/tdynl.cc@ 2769

Last change on this file since 2769 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 2.1 KB
RevLine 
[2499]1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4#include <iostream>
5#include <fstream>
6
[2615]7#include "sopnamsp.h"
[2499]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
16double testfunc_dynl(double x, double y)
17{
18 return (exp(-x)+sin(y)*x);
19}
20
21typedef double (* MyDlFunctionOfXY) (double x, double y);
22
23int 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
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
67 catch (PThrowable & exc) {
68 cerr << " Catched Exception " << (string)typeid(exc).name()
69 << " - Msg= " << exc.Msg() << endl;
70 }
71 catch (...) {
72 cerr << " some other exception was caught ! " << endl;
73 }
74
75 PrtTim(" End of tdynl ");
76}
Note: See TracBrowser for help on using the repository browser.