[TRNSYS-users] using storage c++ type
knut.erik.enerstvedt at niva.no
knut.erik.enerstvedt at niva.no
Mon Apr 21 02:57:08 PDT 2008
Wouter,
I have compiled and tried your C++ component, and it runs without any
"invalid floating point error" on my machine. I use the Microsoft Visual
C++ 2008 Express Edition compiler.
The Type doesn't quite work as you have explained, however. Instead of
adding 1 to the two stored variables for every timestep, it simply sets
them equal to 1 at each timestep. To add 1, write stored[0]+=1 instead of
stored[0]=+1.
I can not see any further errors in your code. By the way, do you know for
sure that you have declared the storage functions correctly in the
"TRNSYS.h" file? I don't think the pointer construction of "nitems" should
be a problem, as it works for me when I use &nitems directly as function
argument.
I hope this was helpful in some way...
Kind regards
Knut Erik Enerstvedt
trnsys-users-requ
est at engr.wisc.edu
To
04/20/2008 07:03 trnsys-users at engr.wisc.edu
PM cc
Subject
Please respond to TRNSYS-users Digest, Vol 40, Issue
trnsys-users at engr 25
.wisc.edu
----- Message from Wouter Lumen <wouter.lumen at ugent.be> on Sat, 19 Apr 2008
19:50:13 +0200 -----
To: trnsys-users at engr.wisc.edu
Subject: [TRNSYS-users] using storage c++ type
Dear trnsys users,
I'm having some troubles with using storage in my new c++ component.
Every time i run the component i get a "invalid floating point error".
I've have read about the possible causes of this error and i have narrowed
it down to a problem with storage.
I have attached a very simple sourcecode:
It reads in 2 numbers (getal1 and getal2) and puts them back out after
adding
a constant to them (in this case, double a and double b).
When i run this component and use hard coded values, such as 1 and 2
for a and b, the
component works flawless.
But when i use storage (as in the attached file), i get the error.
The storage is used in the following way:
Every timestep "1" is added to the stored variables.
So basically, now I add a larger, with timestep increasing, value to getal1
and getal2.
I have tried severall configurations when using the storage such as:
not using the info[12]>0 manipulations,
not using the setstorage at the end of the calculations,
using them both, etc etc...
Maybe the problem is in this, may be not...
Another possible cause (which i think is more likely), is that it has
something
to do with the pointerconstruction for "nitems":
int nitems=2;
int* pitems=&nitems;
double stored[2]={0,0};
so that pitems points to nitems.
This is done because the storage functions take an int* as argument
and not an int.
If anybody has any suggestions on what the problem could be, or could
modify
the sourcefile in a way that it should work. Please let me know.
Thank you very much.
Kind regards,
Wouter Lumen.
----------------------------------------------------------------------------------------------------------------------
NIVAs hovedkontor har flyttet til nye lokaler i CIENS - Forskningssenter
for miljø og samfunn; Gaustadalléen 21, 0349 Oslo. Meld deg på vårt
nyhetsbrev på www.niva.no
More information about the TRNSYS-users
mailing list