Changes between Initial Version and Version 1 of ExampleOldWrapperScilab


Ignore:
Timestamp:
07/23/09 14:25:46 (8 years ago)
Author:
regis.lebrun@…
Comment:

Old version of the scilab wrapper

Legend:

Unmodified
Added
Removed
Modified
  • ExampleOldWrapperScilab

    v1 v1  
     1= Wrapper Scilab (old version) = 
     2 
     3== Prerequisite == 
     4 
     5 * Scilab 
     6 
     7 * OpenTURNS (this tutorial was done with the 0.10.0 version) installed in the ''/usr'' folder (Tutorial made with Ubuntu 7.10). 
     8 
     9 * Make sure you have automake, build-essential and libtool: 
     10{{{ 
     11aptitude install build-essential libtool automake 
     12}}} 
     13 
     14== Modification of the source files == 
     15 
     16 * Copy the folder ''/usr/share/openturns/WrapperTemplate/'' in your home folder for example 
     17 
     18 * Change the ''WrapperTemplate'' folder to ''ScilabWrapper'' 
     19  
     20 * Go to the ''ScilabWrapper'' folder 
     21 
     22 * Save ''wcode.f'' as ''ScilabWrappedCode.f'' : 
     23{{{ 
     24c                                              -*- Fortran -*- 
     25c 
     26c   @file  ScilabWrappedCode.f 
     27c   @brief The code that actually does the computation 
     28c  
     29c   (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     30c  
     31c   This library is free software; you can redistribute it and/or 
     32c   modify it under the terms of the GNU Lesser General Public 
     33c   License as published by the Free Software Foundation; either 
     34c   version 2.1 of the License. 
     35c  
     36c   This library is distributed in the hope that it will be useful 
     37c   but WITHOUT ANY WARRANTY; without even the implied warranty of 
     38c   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     39c   Lesser General Public License for more details. 
     40c  
     41c   You should have received a copy of the GNU Lesser General Public 
     42c   License along with this library; if not, write to the Free Software 
     43c   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     44c  
     45c   @author: $LastChangedBy: dutka $ 
     46c   @date:   $LastChangedDate: 2007-10-04 12:23:01 +0200 (jeu, 04 oct 2007) $ 
     47c   Id:      $Id: wcode.f 554 2007-10-04 10:23:01Z dutka $ 
     48c 
     49 
     50      SUBROUTINE SCILAB(R,F,G) 
     51      IMPLICIT NONE 
     52 
     53c     INPUT PARAMETERS 
     54      REAL*8 R,F 
     55 
     56c     OUTPUT PARAMETERS 
     57      REAL*8 G 
     58      REAL*8 RES 
     59 
     60      INTEGER STATUS 
     61 
     62      CALL WRITEINPUT(R,F) 
     63      STATUS = SYSTEM('./RunScilab.sh') 
     64      CALL GETRESULT(RES) 
     65 
     66      G = RES 
     67 
     68      RETURN 
     69      END 
     70 
     71      SUBROUTINE WRITEINPUT(I1,I2) 
     72      IMPLICIT NONE 
     73 
     74c     INPUT PARAMETERS 
     75      REAL*8  I1,I2 
     76 
     77      OPEN(10,file='input.txt',status='UNKNOWN') 
     78 
     79      WRITE(10,20) 'R= ',I1 
     80      WRITE(10,20) 'F= ',I2 
     81 
     82      CLOSE(10) 
     83 
     84 20   FORMAT(A,F12.3,A) 
     85 
     86      RETURN 
     87      END 
     88 
     89      SUBROUTINE GETRESULT(RES) 
     90      IMPLICIT NONE 
     91 
     92c     OUTPUT PARAMETERS 
     93      REAL*8  RES 
     94 
     95c     LOCAL PARAMETERS 
     96      INTEGER NB_LIGNS, I 
     97      CHARACTER*256 STRING 
     98      REAL*8 TEMP 
     99 
     100      NB_LIGNS = 0 
     101      OPEN(10,file='output.txt',status='UNKNOWN') 
     102      DO I=1,NB_LIGNS 
     103         READ(10,'(A)') STRING 
     104      ENDDO 
     105      READ(10,*) STRING, RES 
     106      CLOSE(10) 
     107 
     108      RETURN 
     109      END 
     110}}} 
     111 
     112 * Save ''wrapper.c'' as ''ScilabWrapper.c'' : 
     113{{{ 
     114/*                                               -*- C -*- */ 
     115/** 
     116 *  @file  ScilabWrapper.c 
     117 *  @brief The wrapper adapts the interface of OpenTURNS and of the wrapped code 
     118 * 
     119 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     120 * 
     121 *  This library is free software; you can redistribute it and/or 
     122 *  modify it under the terms of the GNU Lesser General Public 
     123 *  License as published by the Free Software Foundation; either 
     124 *  version 2.1 of the License. 
     125 * 
     126 *  This library is distributed in the hope that it will be useful 
     127 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     128 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     129 *  Lesser General Public License for more details. 
     130 * 
     131 *  You should have received a copy of the GNU Lesser General Public 
     132 *  License along with this library; if not, write to the Free Software 
     133 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     134 * 
     135 *  @author: $LastChangedBy: dutka $ 
     136 *  @date:   $LastChangedDate: 2007-10-05 23:15:55 +0200 (ven, 05 oct 2007) $ 
     137 *  Id:      $Id: wrapper.c 556 2007-10-05 21:15:55Z dutka $ 
     138 */ 
     139 
     140#include <stdio.h> 
     141#include "WrapperInterface.h" 
     142#include "WrapperCommon.h" 
     143 
     144/* WARNING : Please read the following lines 
     145 * 
     146 * In this program, we make the assumption that the end user wishes to 
     147 * call a function (aka NumericalMathFunction) named "wcode" (wcode stands 
     148 * for wrapped code). 
     149 * In order to individualize the wrapper to the user's needs, we encourage 
     150 * you (as the developer of this wrapper) to renamed any occurence of "wcode" 
     151 * (in either case) to the real name of the function. 
     152 * It will also avoid any confusion with other "wcode"s written by other entities 
     153 * or developers. 
     154 */ 
     155 
     156 
     157/* If you plan to link this wrapper against a FORTRAN library, 
     158 * remember to change the name WCODE for your actual FORTRAN subroutine name. 
     159 * Otherwise you can ignore these lines. 
     160 * 
     161 * Remember that FORTRAN passes its arguments by reference, not by value as C and C++ 
     162 * usually do. So you need to pass the pointer to the arguments rather than its value. 
     163 * This is true for single values (integers, reals, etc.) but not for arrays that are 
     164 * already pointers in the C/C++ environment. Those ones can directly be passed as 
     165 * "values" though they are pointers indeed. 
     166 * Be careful that C and C++ arrays start from 0 and FORTRAN from 1! 
     167 * Be also very careful with the size of the value your plan to pass. Integers in C/C++ 
     168 * are not INTEGER*8 in many cases. Float or doubles do not necessarily match REAL*4 
     169 * or REAL*8 in FORTRAN. 
     170 * 
     171 * FORTRAN gives no clue for preventing const values from being altered. So you need to 
     172 * protect them by copying them before calling the FORTRAN subroutine if this import 
     173 * to you. 
     174 * 
     175 * Summary: there are only exceptions to the rule and you need to 
     176 * know exactly what you are doing! You may be desappointed at first, but it will keep 
     177 * you away from segmentation violation and other similar fantasies. ;-) 
     178 */ 
     179#define SCILAB_F77 F77_FUNC(scilab,SCILAB) 
     180#ifdef __cplusplus 
     181extern "C"  /* prevent C++ name mangling */ 
     182#endif 
     183void SCILAB_F77(double * R, double * F, double * G); 
     184 
     185 
     186/* NOTE: all the 'dbg_' function are for debugging needs */ 
     187 
     188 
     189/* 
     190 *  This is the declaration of function named 'SCILAB' into the wrapper. 
     191 */ 
     192 
     193#ifdef __cplusplus 
     194extern "C" { 
     195#endif 
     196 
     197  /* 
     198********************************************************************************* 
     199*                                                                               * 
     200*                             SCILAB function                                    * 
     201*                                                                               * 
     202********************************************************************************* 
     203*/ 
     204 
     205 
     206  /* The wrapper information informs the NumericalMathFunction object that loads the wrapper of the 
     207   * signatures of the wrapper functions. In particular, it hold the size of the input NumericalPoint 
     208   * (inSize_) and of the output NumericalPoint (outSize_). 
     209   * Those information are also used by the gradient and hessian functions to set the correct size 
     210   * of the returned matrix and tensor. 
     211   */ 
     212 
     213  /* The getInfo function is mandatory */ 
     214  enum WrapperErrorCode func_getInfo_scilab(void * p_state, struct WrapperInformation * p_info) 
     215  { 
     216    dbg_printEntrance("func_getInfo_scilab"); 
     217    dbg_printState("func_getInfo_scilab", p_state); 
     218 
     219    struct WrapperExchangedData * p_exchangedData = p_state; 
     220 
     221    p_info->inSize_  = getNumberOfVariables(p_exchangedData, WRAPPER_IN); 
     222    p_info->outSize_ = getNumberOfVariables(p_exchangedData, WRAPPER_OUT); 
     223 
     224    dbg_printExit("func_getInfo_scilab"); 
     225 
     226    return WRAPPER_OK; 
     227  } 
     228 
     229 
     230  /* The state creation/deletion functions allow the wrapper to create or delete a memory location 
     231   * that it will manage itself. It can save in this location any information it needs. The OpenTURNS 
     232   * platform only ensures that the wrapper will receive the state (= the memory location) it works 
     233   * with. If many wrappers are working simultaneously or if the same wrapper is called concurrently, 
     234   * this mechanism will avoid any collision or confusion. 
     235   * The consequence is that NO STATIC DATA should be used in the wrapper OR THE WRAPPER WILL BREAKE 
     236   * one day. You may think that you can't do without static data, but in general this is the footprint 
     237   * of a poor design. But if you persist to use static data, do your work correctly and make use 
     238   * of mutex (for instance) to protect your data against concurrent access. But don't complain about 
     239   * poor computational performance!  
     240   */ 
     241 
     242  /* The createState function is optional */ 
     243  enum WrapperErrorCode func_createState_scilab(void ** p_p_state, const struct WrapperExchangedData * p_exchangedData) 
     244  { 
     245    dbg_printEntrance("func_createState_scilab"); 
     246    dbg_printWrapperExchangedData("func_createState_scilab", p_exchangedData); 
     247 
     248    /* Here we copy the data read in the WML description file into the state */ 
     249    copyWrapperExchangedData( (struct WrapperExchangedData **) p_p_state, p_exchangedData); 
     250 
     251    dbg_printState("func_createState_scilab", *p_p_state); 
     252    dbg_printExit("func_createState_scilab"); 
     253 
     254    return WRAPPER_OK; 
     255  } 
     256 
     257  /* The deleteState function is optional */ 
     258  enum WrapperErrorCode func_deleteState_scilab(void * p_state) 
     259  { 
     260    dbg_printEntrance("func_deleteState_scilab"); 
     261    dbg_printState("func_deleteState_scilab", p_state); 
     262 
     263    /* We free the memory allocated for the state*/ 
     264    freeWrapperExchangedData( (struct WrapperExchangedData *) p_state); 
     265 
     266    dbg_printExit("func_deleteState_scilab"); 
     267 
     268    return WRAPPER_OK; 
     269  } 
     270 
     271 
     272 
     273 
     274 
     275 
     276  /* Any function declared into the wrapper may declare three actual function prefixed with 
     277   * 'init_', 'exec_' and 'finalize_' folowed by the name of the function, here 'wcode'. 
     278   * 
     279   * The 'init_' function is only called once when the NumericalMathFunction object is created. 
     280   * It allows the wrapper to set some internal state, read some external file, prepare the function 
     281   * to run, etc. It takes only one argument, the internal state as created by the  
     282   * 
     283   * The 'exec_' function is intended to execute what the wrapper is done for: compute an mathematical 
     284   * function or anything else. It takes the internal state pointer as its first argument, the input 
     285   * NumericalPoint pointer as the second and the output NumericalPoint pointer as the third. 
     286   * 
     287   * The 'finalize_' function is only called once when the NumericalMathFunction object is destroyed. 
     288   * It allows the wrapper to flush anything before unloading. 
     289   * 
     290   * Only the 'exec_' function is mandatory. 
     291   */ 
     292 
     293 
     294  /** 
     295   * Initialization function 
     296   * This function is called once just before the wrapper first called to initialize 
     297   * it, ie create a temparary subdirectory (remember that the wrapper may be called 
     298   * concurrently), store exchanged data in some internal repository, do some 
     299   * pre-computational operation, etc. 
     300   */ 
     301  enum WrapperErrorCode func_init_scilab(void * p_state) 
     302  { 
     303    dbg_printEntrance("func_init_scilab"); 
     304    dbg_printState("func_init_scilab", p_state); 
     305 
     306    /* Do something if you need to initialize the wrapper or its environment. 
     307     * If not, you can remove the entire function. 
     308     */ 
     309 
     310    dbg_printExit("func_init_scilab"); 
     311 
     312   return WRAPPER_OK; 
     313  } 
     314 
     315 
     316 
     317 
     318  /** 
     319   * Execution function 
     320   * This function is called by the platform to do the real work of the wrapper. It may be 
     321   * called concurrently, so be aware of not using shared or global data not protected by 
     322   * a critical section. 
     323   * This function has a mathematical meaning. It operates on one vector (aka point) and 
     324   * returns another vector. 
     325   */ 
     326  enum WrapperErrorCode func_exec_scilab(void * p_state, const struct point * inPoint, struct point * outPoint) 
     327  { 
     328    dbg_printEntrance("func_exec_scilab"); 
     329    dbg_printState("func_exec_scilab", p_state); 
     330    dbg_printPoint("func_exec_scilab", inPoint); 
     331 
     332 
     333 
     334 
     335    /* The real computation is here */ 
     336 
     337    /* Call to the FORTRAN subroutine named SCILAB. 
     338     * We have made the assumption that the inputs values won't be touched by the call, 
     339     * so we pass the arguments directly without any protection (copy). 
     340     */ 
     341    SCILAB_F77(&(inPoint->data_[0])  /* R */ , 
     342              &(inPoint->data_[1])  /* F */ , 
     343              &(outPoint->data_[0]) /* G */ ); 
     344 
     345 
     346 
     347    dbg_printPoint("func_exec_scilab", outPoint); 
     348    dbg_printExit("func_exec_scilab"); 
     349 
     350    return WRAPPER_OK; 
     351  } 
     352 
     353 
     354 
     355 
     356  /** 
     357   * Finalization function 
     358   * This function is called once just before the wrapper is unloaded. It is the place to flush 
     359   * any output file or free any allocated memory. When this function returns, the wrapper is supposed 
     360   * to have all its work done, so it is not possible to get anymore information from it after that. 
     361   */ 
     362  enum WrapperErrorCode func_finalize_scilab(void * p_state) 
     363  { 
     364    dbg_printEntrance("func_finalize_scilab"); 
     365    dbg_printState("func_finalize_scilab", p_state); 
     366 
     367    /* Do something if you need to clean the wrapper or its environment. 
     368     * If not, you can remove the entire function. 
     369     */ 
     370 
     371    dbg_printExit("func_finalize_scilab"); 
     372 
     373    return WRAPPER_OK; 
     374  } 
     375 
     376 
     377 
     378 
     379#ifdef __cplusplus 
     380} /* end extern "C" */ 
     381#endif 
     382}}} 
     383 
     384 
     385 * Save ''wcode.xml.in'' as ''ScilabWrapper.xml.in'' : 
     386{{{ 
     387<?xml version="1.0" encoding="ISO-8859-1"?> 
     388<!--  
     389 @file  ScilabWrapper.xml.in 
     390 @brief The description file of the wrapper 
     391 
     392 (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     393 
     394 This library is free software; you can redistribute it and/or 
     395 modify it under the terms of the GNU Lesser General Public 
     396 License as published by the Free Software Foundation; either 
     397 version 2.1 of the License. 
     398 
     399 This library is distributed in the hope that it will be useful 
     400 but WITHOUT ANY WARRANTY; without even the implied warranty of 
     401 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     402 Lesser General Public License for more details. 
     403 
     404 You should have received a copy of the GNU Lesser General Public 
     405 License along with this library; if not, write to the Free Software 
     406 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     407 
     408 @author: $LastChangedBy: dutka $ 
     409 @date:   $LastChangedDate: 2007-10-05 23:15:55 +0200 (ven, 05 oct 2007) $ 
     410 Id:      $Id: wcode.xml.in 556 2007-10-05 21:15:55Z dutka $ 
     411--> 
     412<!DOCTYPE wrapper SYSTEM "@OPENTURNS_WRAPPER_DTD_PATH@/wrapper.dtd"> 
     413 
     414<wrapper> 
     415  <library> 
     416 
     417    <!-- The path of the shared object --> 
     418    <path>ScilabWrapper.so</path> 
     419 
     420 
     421 
     422    <!-- This section describes all exchanges data between the wrapper and the platform --> 
     423    <description> 
     424 
     425      <!-- Those variables are substituted in the files above --> 
     426      <!-- The order of variables is the order of the arguments of the function --> 
     427      <variable-list> 
     428 
     429        <!-- The definition of a variable --> 
     430        <variable id="R" type="in"> 
     431          <comment>Yield strength</comment> 
     432          <unit>MPa</unit> 
     433          <regexp>R=.*</regexp> 
     434          <format>R=%10.5g</format> 
     435        </variable> 
     436 
     437        <!-- The definition of a variable --> 
     438        <variable id="F" type="in"> 
     439          <comment>Axial Force</comment> 
     440          <unit>N</unit> 
     441          <regexp>F=.*</regexp> 
     442          <format>F=%10.5g</format> 
     443        </variable> 
     444 
     445        <!-- The definition of a variable --> 
     446        <variable id="G" type="out"> 
     447          <comment>Limit State</comment> 
     448          <unit>MPa</unit> 
     449          <regexp>G=.*</regexp> 
     450          <format>G=%10.5g</format> 
     451        </variable> 
     452 
     453      </variable-list> 
     454       
     455 
     456 
     457      <!-- The function that we try to execute through the wrapper --> 
     458      <function provided="yes">scilab</function> 
     459 
     460      <!-- the gradient is  defined  --> 
     461      <gradient provided="no"></gradient> 
     462 
     463      <!--  the hessian is  defined  --> 
     464      <hessian provided="no"></hessian> 
     465 
     466    </description> 
     467 
     468 
     469  </library> 
     470 
     471  <external-code> 
     472    <!-- Those data are external to the platform (input files, etc.)--> 
     473    <data></data> 
     474 
     475    <wrap-mode type="static-link" state="shared"> 
     476      <in-data-transfer mode="arguments" /> 
     477      <out-data-transfer mode="arguments" /> 
     478    </wrap-mode> 
     479 
     480    <command># no command</command> 
     481 
     482  </external-code> 
     483 
     484</wrapper> 
     485}}} 
     486 
     487 * Save ''test_wcode.py'' as ''test_ScilabWrapper.py'' : 
     488{{{ 
     489#                                               -*- Python -*- 
     490# 
     491#  @file  test_ScilabWrapper.py 
     492#  @brief A test file for the wrapper code 
     493# 
     494#  (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     495# 
     496#  This library is free software; you can redistribute it and/or 
     497#  modify it under the terms of the GNU Lesser General Public 
     498#  License as published by the Free Software Foundation; either 
     499#  version 2.1 of the License. 
     500# 
     501#  This library is distributed in the hope that it will be useful 
     502#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     503#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     504#  Lesser General Public License for more details. 
     505# 
     506#  You should have received a copy of the GNU Lesser General Public 
     507#  License along with this library; if not, write to the Free Software 
     508#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     509# 
     510#  @author: $LastChangedBy: dutka $ 
     511#  @date:   $LastChangedDate: 2007-10-05 23:15:55 +0200 (ven, 05 oct 2007) $ 
     512#  Id:      $Id: test_wcode.py 556 2007-10-05 21:15:55Z dutka $ 
     513# 
     514#  This script imports the OpenTURNS environment in Python, loads 
     515#  ths wrapper and the wrapped code, and then calls it. 
     516# 
     517from openturns import * 
     518 
     519f = NumericalMathFunction("ScilabWrapper") 
     520print "f = ", f 
     521 
     522inP = NumericalPoint(f.getInputNumericalPointDimension()) 
     523for i in range(inP.getDimension()): 
     524    inP[i] = 10. * (i + 1) 
     525print "inP = ", inP 
     526 
     527outP = f(inP) 
     528print "outP = ", outP 
     529}}} 
     530 
     531 * Modify ''configure.ac'' : 
     532{{{ 
     533#                                               -*- Autoconf -*- 
     534# 
     535#  configure.ac 
     536# 
     537#  (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     538# 
     539#  This library is free software; you can redistribute it and/or 
     540#  modify it under the terms of the GNU Lesser General Public 
     541#  License as published by the Free Software Foundation; either 
     542#  version 2.1 of the License. 
     543# 
     544#  This library is distributed in the hope that it will be useful 
     545#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     546#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     547#  Lesser General Public License for more details. 
     548# 
     549#  You should have received a copy of the GNU Lesser General Public 
     550#  License along with this library; if not, write to the Free Software 
     551#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     552# 
     553#  @author: $LastChangedBy: dutka $ 
     554#  @date:   $LastChangedDate: 2007-10-04 12:23:01 +0200 (jeu, 04 oct 2007) $ 
     555#  Id:      $Id: configure.ac 554 2007-10-04 10:23:01Z dutka $ 
     556# 
     557#  Process this file with autoconf to produce a configure script. 
     558#  Set minimal version of Autoconf for configure to work 
     559# 
     560AC_INIT(ScilabWrapper.c) 
     561AC_CONFIG_AUX_DIR(.) 
     562AM_INIT_AUTOMAKE(ScilabWrapper, 0.0) 
     563AC_DISABLE_STATIC 
     564AC_PROG_LIBTOOL 
     565 
     566# You need C compiler to build the wrapper 
     567AC_PROG_CC 
     568 
     569# If you don't need FORTRAN, comment the lines below 
     570AC_PROG_F77 
     571AC_F77_LIBRARY_LDFLAGS 
     572AC_F77_WRAPPERS 
     573 
     574OT_CHECK_OPENTURNS 
     575 
     576AC_OUTPUT([Makefile ScilabWrapper.xml]) 
     577}}} 
     578 
     579 * Modify ''Makefile.am'' : 
     580{{{ 
     581#                                               -*- Makefile -*- 
     582# 
     583#  Makefile.am 
     584# 
     585#  (C) Copyright 2005-2007 EDF-EADS-Phimeca 
     586# 
     587#  This library is free software; you can redistribute it and/or 
     588#  modify it under the terms of the GNU Lesser General Public 
     589#  License as published by the Free Software Foundation; either 
     590#  version 2.1 of the License. 
     591# 
     592#  This library is distributed in the hope that it will be useful 
     593#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     594#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     595#  Lesser General Public License for more details. 
     596# 
     597#  You should have received a copy of the GNU Lesser General Public 
     598#  License along with this library; if not, write to the Free Software 
     599#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
     600# 
     601#  @author: $LastChangedBy: dutka $ 
     602#  @date:   $LastChangedDate: 2007-10-05 23:15:55 +0200 (ven, 05 oct 2007) $ 
     603#  Id:      $Id: Makefile.am 556 2007-10-05 21:15:55Z dutka $ 
     604# 
     605ACLOCAL_AMFLAGS = -I m4 
     606 
     607wrapperdir          = $(prefix)/wrappers 
     608 
     609wrapper_LTLIBRARIES = ScilabWrapper.la 
     610ScilabWrapper_la_SOURCES    = ScilabWrapper.c ScilabWrappedCode.f 
     611ScilabWrapper_la_CPPFLAGS   = $(OPENTURNS_WRAPPER_CPPFLAGS) 
     612ScilabWrapper_la_LDFLAGS    = -module -no-undefined -version-info 0:0:0 
     613ScilabWrapper_la_LDFLAGS   += $(OPENTURNS_WRAPPER_LDFLAGS) 
     614ScilabWrapper_la_LIBADD     = $(OPENTURNS_WRAPPER_LIBS) 
     615 
     616# This line is useful only if you compile FORTRAN files 
     617ScilabWrapper_la_LDFLAGS   += $(FLIBS) 
     618 
     619XMLWRAPPERFILE      = ScilabWrapper.xml 
     620wrapper_DATA        = $(XMLWRAPPERFILE) 
     621EXTRA_DIST          = $(XMLWRAPPERFILE).in test_ScilabWrapper.py 
     622}}} 
     623 
     624== Building the wrapper == 
     625 
     626 * Run the bootstrap : 
     627{{{ 
     628./bootstrap 
     629}}} 
     630 
     631 * Run : 
     632{{{ 
     633./configure --prefix=/home/%your home folder%/openturns --with-openturns=/usr 
     634}}} 
     635 
     636 * Build the wrapper : 
     637{{{ 
     638make 
     639}}} 
     640 
     641 * Install your wrapper in ''/home/%your home folder%/openturns/wrappers'' : 
     642{{{ 
     643make install 
     644}}} 
     645 
     646 * The wrapper will be seen by OpenTURNS automatically, as it was configured to be placed in a standard folder, where OpenTURNS checks by default the presence of wrappers. 
     647 
     648 
     649 * To solve a bug of the 0.10.0 version, you also have to copy the file ''/etc/openturns/openturns.conf'' to the folder ''/home/%your home folder%/openturns/etc/''. 
     650 
     651 
     652== Running a stochastic analysis using the wrapper == 
     653 
     654The same physic example as [wiki:ExampleAxialStressedBeam here] is used and programmed on a Scilab script, ''StressedBeam.sci'' : 
     655{{{ 
     656// Input file 
     657u=mopen('input.txt','r') 
     658R=mfscanf(u,'%s') 
     659R=mfscanf(u,'%f') 
     660F=mfscanf(u,'%s') 
     661F=mfscanf(u,'%f') 
     662mclose(u); 
     663 
     664// Output calculation 
     665G=R-F/(3.14159*100.0) ; 
     666 
     667// Output file 
     668u=file('open','output.txt',"unknown") 
     669fprintf(u,'G= %6.9f',G) 
     670file('close',u)  
     671 
     672exit 
     673}}} 
     674 
     675 
     676Some scripts are needed to launch Scilab : 
     677 
     678 * ''RunScilab.sh'' : 
     679{{{ 
     680#!/bin/sh 
     681scilab -nw -f StressedBeam.sci 
     682}}} 
     683 
     684 * ''Clean.sh'' : 
     685{{{ 
     686#!/bin/sh 
     687rm input.txt 
     688rm output.txt 
     689}}} 
     690 
     691Don't forget to make the scripts executables : 
     692{{{ 
     693chmod +x Scilab.sh 
     694chmod +x Clean.sh 
     695}}} 
     696 
     697The analysis is done using the TUI : 
     698{{{ 
     699from openturns import * 
     700from math import *  
     701 
     702stochasticDimension = 2 
     703RandomGenerator().SetSeed(0) 
     704 
     705# Definition of the function to use : Scilab Coupling 
     706LimitState = NumericalMathFunction("ScilabWrapper") 
     707dim = LimitState.getInputNumericalPointDimension() 
     708 
     709# Mean 
     710mean = NumericalPoint(dim, 0.0) 
     711mean[0] = 300.0 
     712mean[1] = 75000.0 
     713 
     714# Standard deviation 
     715sigma = NumericalPoint(dim, 0.0) 
     716sigma[0] = 30.0 
     717sigma[1] = 5000.0 
     718 
     719# Parameters for the lognormal distribution: 
     720MuLog = NumericalPoint(dim, 0) 
     721SigmaLog = NumericalPoint(dim, 0) 
     722 
     723MuLog[0] = log(mean[0]*mean[0]/(sqrt(mean[0]*mean[0]+sigma[0]*sigma[0]))) 
     724SigmaLog[0] = sqrt(log(1.0+(sigma[0]*sigma[0]/(mean[0]*mean[0])))) 
     725print "MuLog=" , MuLog 
     726print "SigmaLog=", SigmaLog 
     727 
     728component = Description(1) 
     729BorneInf = 0.0 
     730 
     731# Initialization of the distribution collection: 
     732aCollection = DistributionCollection() 
     733 
     734# Create a first marginal : distribution 1D 
     735marginal = LogNormal(MuLog[0], SigmaLog[0], BorneInf) 
     736marginal.setName("Yield strength") 
     737component[0] = "R" 
     738marginal.setDescription(component) 
     739# Graphical output of the PDF 
     740pdfgraph=marginal.drawPDF() 
     741pdfgraph.draw("/tmp", "pdf_R", 640, 480) 
     742# Fill the first marginal of aCollection 
     743aCollection.add( Distribution(marginal, "Yield strength") ) 
     744 
     745# Create a second marginal : distribution 1D 
     746marginal = Normal(mean[1], sigma[1]) 
     747marginal.setName("Traction_load") 
     748component[0] = "F" 
     749marginal.setDescription(component) 
     750# Graphical output of the PDF 
     751pdfgraph=marginal.drawPDF() 
     752pdfgraph.draw("/tmp", "pdf_F", 640, 480) 
     753# Fill the second marginal of aCollection 
     754aCollection.add( Distribution(marginal, "Traction_load") ) 
     755 
     756# Create a copula : IndependentCopula (no correlation) 
     757aCopula = IndependentCopula(aCollection.getSize()) 
     758aCopula.setName("Independent copula") 
     759 
     760# Instanciate one distribution object 
     761myDistribution = ComposedDistribution(aCollection, Copula(aCopula)) 
     762myDistribution.setName("myDist") 
     763 
     764# We create a 'usual' RandomVector from the Distribution 
     765vect = RandomVector(Distribution(myDistribution)) 
     766 
     767# We create a composite random vector 
     768G = RandomVector(LimitState, vect) 
     769 
     770# We create an Event from this RandomVector 
     771myEvent = Event(G, ComparisonOperator(Less()), 0.0, "Event 1") 
     772 
     773cv = 0.10 
     774NbSim = 100 
     775 
     776myAlgo = MonteCarlo(myEvent) 
     777myAlgo.setMaximumOuterSampling(NbSim) 
     778myAlgo.setBlockSize(1) 
     779myAlgo.setMaximumCoefficientOfVariation(cv) 
     780 
     781myAlgo.run() 
     782 
     783result = myAlgo.getResult() 
     784probability = result.getProbabilityEstimate() 
     785print "MonteCarlo result=" , result.str() 
     786print "Number of executed iterations =" , result.getOuterSampling() 
     787print "Pf = " , probability 
     788print "CV =" , sqrt(result.getVarianceEstimate()) 
     789}}}