[TRNSYS-users] Error in cpp programming
keilholz, werner
werner.keilholz at cstb.fr
Tue Aug 4 09:14:07 PDT 2009
Hi,
Using return values from functions defined in FORTRAN is problematic, due to the different stack model between the 2 languages. I solved the problem like this:
1. Define a new function in TRNDll (basically a copy of the existing one, adapted as SUBROUTINE):
SUBROUTINE GETLABEL2(i,j, outLabel) !i=unit #, j=label #
!dec$ attributes dllexport :: getLabel2
use TrnsysData
use TrnsysConstants
integer :: i,j,k,m,n
character (len=*) :: outLabel
m=0
do k=1,N_LABELS
if(LABEL_UNIT(k).eq.i) then
m=m+1
if(m.eq.j) then
do n=1,maxLabelLength
outLabel(n:n)=LABEL(n,k)
enddo
endif
endif
enddo
end SUBROUTINE GETLABEL2
2. Use it in C++
a) add to Trnsys.H:
extern "C" __declspec(dllimport) void _cdecl GETLABEL2(int* unit, int* label,
char* outLabel, int* lOutLabel);
b) in the code of the type:
char theLabel[2000];
int sizeLabel;
int nLabel =1;
GETLABEL2(&iunit, &nLabel, theLabel, &sizeLabel);
This will yield the name of the 1st (nLabel) special card padded with spaces (you have to scratch it out of "theLabel" by removing all trailing spaces.
If you do not want to modify trndll, you can use the method using External files described in my earlier post.
Werner
________________________________
De : rgaray at labein.es [mailto:rgaray at labein.es]
Envoyé : lundi 3 août 2009 15:01
À : keilholz, werner
Objet : RE: [TRNSYS-users] Error in cpp programming
Dear Keilholtz,
Thank you for your help.
We´re now trying to read the file in the "special card" way, but we´re heving some trouble, but i think this is the correct way.
Could I ask for just some more help?
I attach a proforma file.
Would you please tell me in which way should I call the GetLabel() function?
In cpp I´ve tried with the following:
const char *cadena="";
cadena = getLabel(info[0],1);
But it doesn´t work.
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20090804/3ffa221e/attachment-0005.htm>
More information about the TRNSYS-users
mailing list