[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calliung functions from dll by type 61
- Date: Thu, 21 Aug 2003 14:18:56 +0200
- From: Werner Keilholz <werner@xxxxxxx>
- Subject: Re: Calliung functions from dll by type 61
You have two choices:
1. If you want to modify type61.for directly (with a FORTRAN compiler),
you can link your DLL to the TRNLIB workspace and write, inside type61.for :
SUBROUTINE TYPE61(TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*)
...
IF (PAR(1).EQ.1) CALL operation_GasNode_SOFC(...)
ELSE IF (PAR(1).EQ.1) CALL operation_WaterNode_SOFC(...)
etc.
instead of
CALL EXTDLL(Spass,Sarraypass,simarray,xin,out,t,dtdt,par,
&info,icntrl)
2. If you don't want to touch the FORTRAN code (this is what I suggested), you
must export a fifth function from your DLL. This function must be called EXTDLL
and have the arguments defined in C:\trnsys15\UserLib\EXTDLL.FOR (translated to
C, e.g. DOUBLE PRECISION = double etc.).
Inside this function you would write something like
int EXTDLL(
char Spass[], // CHARACTER[80]
float sarraypass[],
float simarraypass[],
double XIN[], // REAL*8 - DOUBLE PRECISION
double OUT[], // REAL*8 - DOUBLE PRECISION
float T, // REAL*4
float DTDT, // REAL*4
float PAR[], // REAL*4
int INFO[], // INTEGER*4
int ICNTRL // INTEGER*4
)
{
if (par[0]==1)
operation_GasNode_SOFC(...);
else if (par[0]==2) operation_GasNode_SOFC(...);
etc.
...
return 1;
}
(note that I write this off the top of my head, you may wnt to check the
argument types, etc.).
All this must be compiled into EXTDLL.DLL and put into \trnsys15.
Werner
PS: I have the impression that your function initiate_SOFCSystem() should be
called only once (at the beginning of the simulation. You can do this by
checking the INFO array.
Selim Ullah wrote:
> Hi Werner
>
> I have a c++ dll with four exportable functions. So this dll don't have
> any argumets but the functions do have the arguments. So here name of
> the dll and the name of the functions are different.
>
> Let the name of the dll is EXTDLL.dll and the functions are
>
> initiate_SOFCSystem(double * param, double * input, int debug_flag);
> kill_SOFCSystem();
> operation_GasNode_SOFC( const double* time , double * input, double *
> output);
> operation_WaterNode_SOFC( const double* time , double * input, double *
> output);
>
> Now if I want to call these functions from type61, what should I writre
> between the interface?
>
> Best regards
>
> Werner Keilholz schrieb:
>
> >Hi Selim,
> >
> >In TRNSYS 15 you can have only one external user- DLL (TRNSYS 16 will
> >allow any number).
> >
> >If you need to call more than one, I would recommend to use Parameter 1 of
> >type 61as a 'mode' indicator.
> >
> >In your DLL, you can then simply write something like
> >
> >if (par[0]==1)
> > function1(...);
> > else if (par[0]==2) function2(...);
> > else if (par[0]==3) function3(...);
> > else if (par[0]==4) function4(...);
> > else printf("Unknown mode: %d", par[0]);
> >
> >Werner
> >
> >Selim Ullah wrote:
> >
> >
> >
> >>Halloo TRNSYS users
> >>
> >>I have c++ dll with four exportable functions. To call these functions
> >>by type 61 what should I change in the type 61 routine?
> >>
> >>Can anybody help with example?
> >>
> >>Thanks in advance
> >>
> >>Selim
> >>
> >>
> >
> >
> >
> >
> >