[TRNSYS-users] Call external file through special cards with C++

keilholz, werner werner.keilholz at cstb.fr
Mon Jun 7 00:47:24 PDT 2010


Hi Xingbin,

 

If you just want to know the name of the file, you can use the code example below. 

(However, you will not be able to open that file during a TRNSYS simulation, except if you use the new FILE keyword in Trnsys 17; in the other cases, the file is opened by TRNSYS and thus locked).

 

Werner

 

#include "TRNSYS.h" //TRNSYS acess functions (allow to acess TIME etc.) 

extern "C" __declspec(dllimport) int     _cdecl TRNSYSFUNCTIONS_mp_GETEXTFILEPATH(int *unitNum, int *fileNum, char* extFilePath);

#define getExtFilePath TRNSYSFUNCTIONS_mp_GETEXTFILEPATH

 

...

 

//    DO ALL THE VERY FIRST CALL OF THE SIMULATION MANIPULATIONS HERE

if (info[6]== -1) // first call of this component in the simulation

{

 

    // open external file and compute sum

       const int maxPathLength      =       300; //  ! Maximum length of variables containing path- and filenames

                                                 // (adapt this number if it has been changed in TrnsysConstants.f90,

                                                 // or FORTRAN will screw up the stack)

       int fileNameLength=-1;

       char name[maxPathLength];

       int fileNumber = 1; // use first FILE attached to this type

       

       fileNameLength = getExtFilePath(&iunit, &fileNumber, name);

       name[fileNameLength] = 0x0; // FORTRAN doesn't use end-of-string marks



 

De : xingbin lin [mailto:lynxingbin at gmail.com] 
Envoyé : samedi 5 juin 2010 08:39
À : keilholz, werner
Cc : TRNSYS-users at cae.wisc.edu
Objet : Re: [TRNSYS-users] Call external file through special cards with C++

 

Dear Werner:

Thank you for your help so much,Your solution is that to provide a dll which is programmed by fortran,then I can build a C++ class to read the file content according to the logical unit number,this is very smart.

However,what I just want to get the file path which is assigned in the specail cards in the new type.That is to say,I would like to get the path of the file in my type,not the content.

Can you provide me more advices? Thanks a lot!

Xingbin Lin

2010/6/4 keilholz, werner <werner.keilholz at cstb.fr>

Hi Xingbin,

 

I once proposed this solution :

https://www-old.cae.wisc.edu/pipermail/trnsys-users/2010/005500.html <https://www-old.cae.wisc.edu/pipermail/trnsys-users/2010/005500.html> 

 

It does not use the special cards, but the external file tab, like FORTRAN components. 

 

In TRNSYS 17, there is a special FILE keyword, which solves this problem. I attach a sample component with source code using it (but this requires Trnsys 17, does not work with 16).

 

Werner

 

 

De : xingbin lin [mailto:lynxingbin at gmail.com] 
Envoyé : vendredi 4 juin 2010 15:31
À : TRNSYS-users at cae.wisc.edu
Objet : [TRNSYS-users] Call external file through special cards with C++

 

Hello everyone,

 

I built a new type in which I need call external file through special cards in trnsys 16,and I exported it as C++,in this type,I wanted to get the path of external file by using the access  function getLabel(int,int) which was defined in TRNSYS.h header file.

 

But when I runned the simulation,it  prompted "Access  violation at address ###### in module 'dforrt.dll'".The function getLabel(int,int)  defined in "TRNSYS.h" is that "extern "C" __declspec(dllimport) char* _cdecl  TRNSYSFUNCTIONS_mp_GETLABEL(int , int );#define getLabel       TRNSYSFUNCTIONS_mp_GETLABEL".

 

I searched this problem in internet,somebody said maybe the reason existed in the process of calling the dll between  C++ and Fortran. 
Please tell me how can I solve this exception and any suggestions.

 

Thanks.

 

Xingbin Lin 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20100607/5a6846ca/attachment-0001.htm>


More information about the TRNSYS-users mailing list