[TRNSYS-users] assign a n external file to a new type

Yoshihiro Yamaguchi yamaguti at alpha-net.ne.jp
Wed Aug 10 02:22:07 PDT 2005


Dear Werner,

Did it work with the way you sugguested?  
I have not succeeded yet.  I compiled my DLL written in C++
with the consistent runtime library with trnlib.dll.
(The distributed trnlib.dll is compiled with Debug mode,
though the manual says it is release mode.)

Basically, logical unit in Fortran can share in another
DLL, if the DLL links same runtime library.  In the case of
CVF, the runtime is dforrt.dll in release mode and dforrtd.dll
in debug mode.  So, user dll have to link the same runtime
libary as that of trnlib.dll.

But, in the case of writing a TYPE in C++, it is different.
I think file handle in C++ library is not compatible with
logical unit in Fortran library, although I am not sure. 

In my case, _read function always returns -1.

When I try to open and close in my TYPE, I noticed 
there is no (official) way to get the filename defined in proforma.
Even if I can get the filename, the TRNSYS kernel opens the file, too.
Opening one file by two places is not so good.

If your idea works, it is the best solution in writing a TYPE
in C++.

> Javier, 
> 
> In principle, it works in C++ just like in FORTRAN:
> You have to retries the logical file number from the right parameter (an
> interger) and then use that as a C file descriptor. 
> 
> For example, if your component has only one parameter, the File/Export to
> C++ wizard will create a line like 
> 
>       double Logical_unit_number;
> ...
>       Logical_unit_number=par[0];
> 
> You have to convert Logical_unit_number to integer and then use it in
> commands like 
> 
>   char buffer[6000];
> ...
>   bytesread = _read(fh,buffer,6000);
> 
> (if you use the C low level I/O). 
> 
> For this to work, your DLL must be compiled exactly in the same mode as the
> TrnDll.dll of the TRNSYS package (static vs. dynamic, debug vs. release,
> etc.).
> 
> If you have trouble getting it to work (i.e. the file handle is invalid in
> your C DLL), you can use a combination with Michael' idea of accessing the
> labels to pass filename(s), and add _open and _close statements as needed.
> 
> Werner

=====================================
  Yoshihiro Yamaguchi    山口 芳弘  
  yamaguti at alpha-net.ne.jp
=====================================




More information about the TRNSYS-users mailing list