Commit 541678e5 by trkall

ilmajaam

parent 1b30055b
1339 100 0 Guatemala
1340 -18 10 Helsinki
1341 0 20 Tallinn
1342 -30 18 Rovaniemi
1343 120 50 Kuwait
1344 50 14 London
1345 31 47 Edinburgh
1346 32 20 Riga
1347 33 40 Gotland
1348 -100 60 Testsite#1
1349 -465 10 Area51
1350 14 8 Paris
1351 -200 4 Testsite#2
1352 52 40 Sarajevo
1353 66 23 Baku
1354 47 19 Kiev
1353 31 11 Dublin
1342 -30 18 Rovaniemi
1343 120 50 Kuwait
1344 50 14 London
1345 31 47 Stockholm
1346 32 20 Oslo
1347 33 40 Gotland
1348 -100 60 Testsite#1
1349 14 8 Tallinn
1350 -200 4 Testsite#2
1351 52 40 Sarajevo
1352 47 19 Kiev
1353 31 11 Dublin
double FCONST1 = 1.8; // Fahrenheitist Celsiusesse teisendamisel vajalik jagamis konstant
int FCONST2 = 32; // Fahrenheitist Celsiusesse teisendamisel vajalik lahutamis konstant
double SCONST = 0.51444444444; //1 kt = 0.51444444444 mps
double TCONST = -274.15; // 1 C = 274.15 K
int MAXSPD = 20; // tormihoiatus
int MAXTEMP = 30; // kuumalaine
int MINTEMP = 0; // mustjää
typedef struct
{
int ID;
double Ftemp;
double Ctemp;
int knots;
double v;
char *loc;
} m66tmised;
int FailistSisse(FILE* file, m66tmised andmed[], int i)
{
int chk;
if ((chk = chkFile(file)) == 0)
{
while(!feof(file))
{
andmed = (m66tmised*)realloc(andmed, sizeof(m66tmised*));
//fscanf(file, "%d %lf %d %s", &andmed[i].ID, &andmed[i].Ftemp, &andmed[i].knots, andmed[i].loc);
fscanf(file, "%d %lf %d %s", &(andmed +i)->ID, &(andmed +i)->Ftemp, &(andmed +i)->knots, (andmed +i)->loc);
i++;
}
} else {
printf("Fail on puudu\n");
return 0;
}
return i-1;
}
void tempconv(m66tmised andmed[], int pikkus)
{
int i;
for(i=0;i<pikkus;i++)
{
(andmed +i)->Ctemp = ((andmed +i)->Ftemp - FCONST2) / FCONST1;
}
}
void spdconv(m66tmised andmed[], int pikkus)
{
int i;
for(i=0;i<pikkus;i++)
{
(andmed +i)->v = (andmed +i)->knots * SCONST;
}
}
void warnings(m66tmised andmed[], int i, FILE* file3)
{
if((andmed +i)->v >= MAXSPD)
{
printf(" - Tormihoiatus");
fprintf(file3, " - Tormihoiatus");
}
if((andmed +i)->Ctemp >= MAXTEMP)
{
printf(" - Kuumalaine");
fprintf(file3, " - Kuumalaine");
}
if((andmed +i)->Ctemp <= MINTEMP)
{
printf(" - Must j22");
fprintf(file3, " - Must j22");
}
}
int chkTemp(m66tmised andmed[], int i)
{
if ((andmed +i)->Ctemp <= TCONST)
{
return 1;
}
return 0;
}
void v2ljund (m66tmised andmed[], int pikkus, FILE* file3)
{
int i;
int chk;
for(i=0;i<pikkus;i++)
{
if (chk=chkTemp(andmed, i) == 0)
{
printf("ID:%d, T:%0.2f C, Kiirus:%0.2f m/s, Asukoht:%s", (andmed +i)->ID, (andmed +i)->Ctemp, (andmed +i)->v, (andmed +i)->loc);
fprintf(file3, "ID:%d, T:%0.2f C, Kiirus:%0.2f m/s, Asukoht:%s", (andmed +i)->ID, (andmed +i)->Ctemp, (andmed +i)->v, (andmed +i)->loc);
warnings(andmed, i, file3);
printf("\n");
fprintf(file3, "\n");
}
}
}
int chkFile(FILE* file)
{
if (file == NULL)
{
return 1;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "functions.c"
int main(void)
{
FILE* file1;
FILE* file2;
FILE *file3;
char* F1 = "020.txt";
char* F2 = "021.txt";
char* F3 = "F3.txt";
m66tmised *andmed = (m66tmised*)malloc(sizeof(m66tmised*)*30);
int pikkus = 0;
file3 = fopen(F3, "w"); // tyhendab faili
fclose(file3);
file1 = fopen(F1, "r");
pikkus = FailistSisse(file1, andmed, pikkus);
fclose(file1);
file2 = fopen(F2, "r");
pikkus = FailistSisse(file2, andmed, pikkus);
fclose(file2);
if(pikkus == 0)
{
printf("Andmeid pole\n");
return -1;
}
tempconv(andmed, pikkus);
spdconv(andmed, pikkus);
file3 = fopen(F3, "a");
v2ljund(andmed, pikkus, file3);
fclose(file3);
free(andmed);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment