<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>Yuichi -</p>
<p>The immediate problem I see in this coding is if there is a space in the deckfile name then the trim function will cut off the name at the first space. I have found it to be more robust to pass the length of the string and then trim to that exact length.</p>
<p>Regards,</p>
<p>Tim</p>
<p> </p>
<div>
<pre>---<br />Timothy P. McDowell
Executive Vice President
Thermal Energy System Specialists, LLC
22 N Carroll St, Suite 370
Madison, WI 53703
office: 608-274-2577
cell: 608-225-5250</pre>
</div>
<p>On 2017-04-15 02:00, Yuichi Yasuda via TRNSYS-users wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<div class="moz-cite-prefix">FYI<br /><br /> Finally I found a way to call the getDeckFileName() function  from C/C++ directly.<br /> See example below.<br /><br /> TRNSYS.h<br /> extern "C" __declspec(dllimport) int    _cdecl TRNSYSFUNCTIONS_mp_GETMAXPATHLENGTH(void);<br /> extern "C" __declspec(dllimport) char*    _cdecl TRNSYSFUNCTIONS_mp_GETDECKFILENAME(char* dck, size_t len);<br /> #define getMaxPathLength                TRNSYSFUNCTIONS_mp_GETMAXPATHLENGTH  <br /> #define getDeckFileName                TRNSYSFUNCTIONS_mp_GETDECKFILENAME<br /><br /> Example<br /> std::string trim(const std::string& str)<br /> {<br />     size_t first = str.find_first_not_of(' ');<br />     if (std::string::npos == first)<br />     {<br />         return str;<br />     }<br />     size_t last = str.find_last_not_of(' ');<br />     return str.substr(first, (last - first + 1));<br /> }<br /><br /> size_t maxlen = getMaxPathLength();<br /> char *fname= new char[maxlen]; <br /> getDeckFileName(fname, maxlen);<br /> std::string deckFileName = trim(std::string(fname,0,maxlen)); // trimming the string, just in case<br /> delete[] fname; <br /><br /> cheers,<br /><br /> Yuichi <br /><br /> On 2016/05/26 14:17, Yuichi Yasuda via TRNSYS-users wrote:</div>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px">
<div class="moz-cite-prefix">Michael,<br /><br /> I assume you are using TRNSYS16 coding style in your component. I'm not sure that the getMaxLabelLength() function works with the coding style.However, the function works fine in my TRNSYS'17' coding style component.<br /><br /> The getDeckFileName() seems to me that the function does not care about C/C++ strings. I have got exactly same error.<br /> Unless, you modified the function to cope with C/C++ style, I think that you can not avoid the access violation error.<br /> For example, I have added the following new function in the TrnsysFunction.f90 to avoid the error.<br /><br /> -TrnsysFunction.f90<br /><br /> Function getDeckFileNameEx() bind(c,name="getDeckFileNameEx")<br />  !dec$ attributes dllexport :: getDeckFileNameEx<br />  Use TrnsysData<br />  Use, intrinsic :: iso_c_binding<br />  type(C_ptr) :: getDeckFileNameEx<br />  Character(len=maxPathLength) ret  <br />  ret = trim(deckn1)//CHAR(0)<br />  getDeckFileNameEx = C_LOC(ret)<br /> End Function getDeckFileNameEx<br /><br /> - C/C++ Component sourcecode<br /> extern "C" __declspec(dllimport) char*    _cdecl getDeckFileNameEx(void);<br /><br />       char *dckfilename;<br />       dckfilename = getDeckFileNameEx(); <br /><br /> I do not like this idea because an expensive Fortran compiler is needed to build.<br /> Does anyone know that how to call FORTRAN function returns characters?<br /><br /> Best regards,<br /><br /> Yuichi Yasuda<br /> quattro corporate design co.,ltd<br /> T2000 Bld. 4F, 1-11-29 Mita, Meguro-ku, Tokyo, 153-0062, Japan<br /><a class="moz-txt-link-freetext" href="Tel:+81">Tel:+81</a> (0)3 5768 6744 Fax:+81 (0)3 5768 6745<br /> Email: <a class="moz-txt-link-abbreviated" href="mailto:yasuda@qcd.co.jp">yasuda@qcd.co.jp</a><br /><a class="moz-txt-link-freetext" href="http://www.qcd.co.jp/">http://www.qcd.co.jp/</a><br /><br /><br /><br />  <br /><br /><br /> On 2016/05/21 0:22, Michael Holzhauser via TRNSYS-users wrote:</div>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px">Hello all,
<div> </div>
<div>I managed to build a customized TRNSYS Type in C++ by extending the Type202 example that is delivered with TRNSYS 17. I can access the input values and return the corresponding output values without any problems. However, the communication with the TRNSYS Core functions somehow don’t work. Whenever I invoke some function that returns an integer value (like getMaxLabelLength()), the result is NaN. Whenever I try to invoke some function that returns characters (like getDeckFileName()), TRNSYS crashes with something like „Access violation at address XXXXX in module ‚TRNDLL.DLL‘. Write of address XXXXX.“ or with „forttrl: severe (408): fort: (18): Dummy character variable ‚GETLABEL@0‘ has length 300 which is greater than actual variable length 1“ (in case of getLabel).</div>
<div> </div>
<div>As I read in other topics like this one, there seemed to be several issues in the TRNSYS.h header file and the library files long ago: </div>
<div><a href="https://www.mail-archive.com/trnsys-users@engr.wisc.edu/msg00005.html">https://www.mail-archive.com/trnsys-users@engr.wisc.edu/msg00005.html</a></div>
<div> </div>
<div>However, 11 years later, is there a workaround for this problem?</div>
<div> </div>
<div>Thanks in advance.</div>
<div>
<div>
<div style="color: #000000; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; orphans: 2; widows: 2;"><br class="Apple-interchange-newline" /> --</div>
<div style="color: #000000; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; orphans: 2; widows: 2;"> </div>
<div style="color: #000000; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; orphans: 2; widows: 2;">M.Sc. Michael Holzhauser<br /> AG Optimization<br /> University of Kaiserslautern<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><br /><br /> Paul-Ehrlich-Str. 14 - 451<br /> 67663 Kaiserslautern, Germany<br /><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><br /> Phone: <span class="Apple-tab-span" style="white-space: pre;"> </span>+49 (631) 205-2511<br /> E-mail: <a href="mailto:holzhauser@mathematik.uni-kl.de">holzhauser@mathematik.uni-kl.de</a><br /><br /></div>
<div style="color: #000000; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; orphans: 2; widows: 2;"><a href="http://www.mathematik.uni-kl.de/%7Eholzhauser">www.mathematik.uni-kl.de/~holzhauser</a></div>
</div>
</div>
<br /><fieldset class="mimeAttachmentHeader"></fieldset><br />
<pre>_______________________________________________
TRNSYS-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:TRNSYS-users@lists.onebuilding.org">TRNSYS-users@lists.onebuilding.org</a>
<a class="moz-txt-link-freetext" href="http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org">http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org</a>
</pre>
</blockquote>
<p> </p>
<br /><fieldset class="mimeAttachmentHeader"></fieldset><br />
<pre>_______________________________________________
TRNSYS-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:TRNSYS-users@lists.onebuilding.org">TRNSYS-users@lists.onebuilding.org</a>
<a class="moz-txt-link-freetext" href="http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org">http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org</a>
</pre>
</blockquote>
<p> </p>
<div class="moz-signature">-- <br />
<p>株式会社クアトロ<br /><a href="http://qcd.co.jp/">http://qcd.co.jp/</a><br /> 安田 雄市<br /> TEL 03-5768-6744<br /> FAX 03-5768-6745<br /> e-mail: <a class="moz-txt-link-abbreviated" href="mailto:yasuda@qcd.co.jp">yasuda@qcd.co.jp</a></p>
</div>
<!-- html ignored --><br />
<pre>_______________________________________________
TRNSYS-users mailing list
<a href="mailto:TRNSYS-users@lists.onebuilding.org">TRNSYS-users@lists.onebuilding.org</a>
<a href="http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org">http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org</a>
</pre>
</blockquote>
</body></html>