summaryrefslogtreecommitdiffstats
path: root/fiz/naloga/suženjstvo/lokacije.c
blob: bc9e2e1ca26fc45ef4186d3b1bd4be8e63b9a87b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>	// to je bilo napisano 12 ur pred predstavitvijo in NI VARNO
#include <stdlib.h>	// datoteka se mora začeti s prvim frameom - prižgana lučka
#include <math.h>
#define STR0(x) (x ? x : "")
int main (int argc, char ** argv) {
	long double kalibracijske_vrednosti[] = { 14.20, -2.35, 2.25 };
	if (argc < 1+1+7) {
		fprintf(stderr, "%s timestamps.txt `grep \"2A1	\" podatki.tsv`\n", STR0(argv[0]));
		return 1;
	}
#define TIMESTAMPS argv[1]
	char * cp;
	int merilo_leva_šir = strtol(argv[5], &cp, 10);
	cp++;
	int merilo_leva_viš = strtol(cp, NULL, 10);
	int merilo_desna_šir = strtol(argv[6], &cp, 10);
	cp++;
	int merilo_desna_viš = strtol(cp, NULL, 10);
	int središče_šir = strtol(argv[7], &cp, 10);
	cp++;
	int središče_viš = strtol(cp, NULL, 10);
	int kotna_točka_šir = strtol(argv[8], &cp, 10);
	cp++;
	int kotna_točka_viš = strtol(cp, NULL, 10);
	long double pikslov_v_1m = 10*sqrtl(powl(labs(merilo_leva_šir-merilo_desna_šir), 2)+powl(labs(merilo_leva_viš-merilo_desna_viš), 2));
	fprintf(stderr, "pikslov v 1m je %Lf\n", pikslov_v_1m);
	char buf[512];
	fgets(buf, 512, stdin);
	int i = 0;
	unsigned long int starting_frame;
	unsigned int starting_milliseconds;
	FILE * timestamps = fopen(TIMESTAMPS, "r");
	while (!feof(stdin) && !ferror(stdin)) {
		unsigned long int frame = strtoul(buf, &cp, 10);
		if (!i++) {
			starting_frame = frame;
			char starting_millis[512];
			rewind(timestamps);
			for (unsigned int j = 0; j <= frame+1; j++)
				fgets(starting_millis, 512, timestamps);
			starting_milliseconds = strtoul(starting_millis, NULL, 10);
		}
		cp++;
		long double piksel_šir = strtold(cp, &cp);
		cp++;
		long double piksel_viš = strtold(cp, NULL);
		piksel_šir -= središče_šir;
		piksel_viš -= središče_viš;
		piksel_viš /= pikslov_v_1m;
		piksel_šir /= pikslov_v_1m;
		rewind(timestamps);
		char millis[512];
		for (unsigned int j = 0; j <= frame+1; j++)
			fgets(millis, 512, timestamps);
		unsigned int milliseconds = strtoul(millis, NULL, 10);
		fprintf(stdout, "%lu\t%u\t%Lf\t%Lf\n", frame - starting_frame, milliseconds - starting_milliseconds, piksel_šir, piksel_viš);
		fgets(buf, 512, stdin);
	}
}