- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Use day, hours minutes and second...
Page Start Prev 1 Next End
Use day, hours minutes and second from PC
Re: Use day, hours minutes and second from PC
Sep-01-15 08:21:03
external c function?
- lochel
- 45 Posts
Re: Use day, hours minutes and second from PC
Sep-01-15 09:31:56
If I got you right, you want to get the current time within your Modelica model. That can be done easily using external functions. The following is a brief example that extracts the current hours information:
Code:
model TimeTest
impure function getHours
output Integer x;
external "C" x = _getHours() annotation(Include = "#include <stdio.h>
#include <time.h>
int _getHours()
{
time_t now;
struct tm *ts;
/* Get the current time */
now = time(NULL);
ts = localtime(&now);
return ts->tm_hour;
}");
end getHours;
parameter Integer h = getHours();
end TimeTest;
- lochel
- 45 Posts
Re: Use day, hours minutes and second from PC
Sep-01-15 09:46:46
All these information is available from the struct tm:
year: tm->tm_year+1900
month: tm->tm_mon
day: tm->tm_mday
hour tm->tm_hour
minute: tm->tm_min
second: tm->tm_sec
- lochel
- 45 Posts
Page Start Prev 1 Next End
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Use day, hours minutes and second...
There are 0 guests and 0 other users also viewing this topic