root / logic / trunk / simulacija / simulation_function.c @ 61
History | View | Annotate | Download (1.27 KB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <stdlib.h> |
3 |
#include <time.h> |
4 |
#include <string.h> |
5 |
double measure();
|
6 |
|
7 |
|
8 |
int main(void) { |
9 |
//testiranje funkcije
|
10 |
double x= measure();
|
11 |
printf("trenutna meritev = \"%f\"\n", x);
|
12 |
|
13 |
return 0; |
14 |
} |
15 |
|
16 |
|
17 |
//funkcija:
|
18 |
double measure() {
|
19 |
// nastavitev, minimalne in maksimalne temperature:
|
20 |
//funkcija, torej od ure 00:00 raste od minimalne do maximalne, ki jo dose?e pri uri 12:00 in nato spet pada do minimalne pri 24:00
|
21 |
|
22 |
double minimum=20; |
23 |
double maximum=27; |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
time_t now; |
29 |
struct tm *ts;
|
30 |
char buf1[80]; |
31 |
|
32 |
now = time(NULL);
|
33 |
|
34 |
ts = localtime(&now); |
35 |
strcpy(buf1, asctime(ts)); |
36 |
|
37 |
int x1 = buf1[11]-48; |
38 |
int x2 = buf1[12]-48; |
39 |
int m1 = buf1[14]-48; |
40 |
int m2 = buf1[15]-48; |
41 |
|
42 |
//printf("%d%d:%d%d \n",x1,x2,m1,m2);
|
43 |
|
44 |
int minutes = (x1*10+x2)*60 + m1*10+m2; |
45 |
int variable = minutes;
|
46 |
|
47 |
if(variable>720) { |
48 |
variable= 720-(variable-720); |
49 |
} |
50 |
|
51 |
double k = ((double)variable)/((double)720); |
52 |
//printf("%f",k);
|
53 |
double meritev=0; |
54 |
meritev = minimum + k * (maximum-minimum); |
55 |
//int x1 = atoi(&buf[1]);
|
56 |
/*int x2 = atoi(&buf[16]);
|
57 |
int m1 = atoi(&buf[17]);
|
58 |
int m2 = atoi(&buf[18]);*/
|
59 |
//printf("%d minut\n", minutes);
|
60 |
//printf("%s, %s, %s ,%s, %d ur in %d minut\n",buf[0], buf[1], buf[2], buf[3], hour, minute);
|
61 |
|
62 |
|
63 |
return meritev;
|
64 |
} |