Ok, so I broke it. And my backup is broken, too. I'm going to start from the source I used above (doesn't print into multiple files).
I'll delete the weather section alltogether. It contains one bug (doesn't register light rain if it's the only weather).
Besides, Gnuplot doesn't plot files which have two points at same x coordinate. So if I REALLY want to show what weather there was (most of the time none), and want to show it even when there are 2 at same time, i have to create one extra data file. Forget it, I'm not doing it. Thre's little weather data anyway.
I'll use x++ as x coordinate. THEN, if it works, I _may_ change it to print actual date. I need to kill all bugs first.
#include <stdio.h>
#include <string.h>
/*clear sky*/
#define vis1 0
#define vis2 1
#define vis3 2
#define vis4 3
#define maxl 80
/*mist*/
#define wea1 0
/*fog*/
#define wea2 1
/*freezing fog*/
#define wea3 2
/*shallow fog*/
#define wea4 3
/*patches of fog*/
#define wea5 4
/* light rain, zeby sie odroznialo od zgrai mgiel */
#define wea6 8
/* chmurki, zeby sie odroznialo */
#define wea7 12
/* light rain showers, zeby sie odroznialo od zgrai mgiel */
#define wea8 9
int main(int argc, char *argv[])
{
int ismiec;
int rok;
int miesiac;
int dzien;
int godzina;
int i;
int x = 0;
/* char ssmiec[20]; */
char line[80];
char word1[20];
char word2[20];
char word3[20];
char csmiec[40];
FILE *pFile;
FILE *pWdi = fopen("1winddir.dat", "w");
FILE *pWsp = fopen("2windspd.dat", "w");
FILE *pVis = fopen("3visibil.dat", "w");
FILE *pSky = fopen("4sky.dat", "w");
FILE *pWea = fopen("5weather.dat", "w");
FILE *pTem = fopen("6tempera.dat", "w");
FILE *pWic = fopen("7windchi.dat", "w");
FILE *pDew = fopen("8dewpoin.dat", "w");
FILE *pHum = fopen("9humidit.dat", "w");
FILE *pPre = fopen("0pressur.dat", "w");
for (i = 1; i < argc; i++) {
pFile = fopen(argv, "r");
if (pFile == NULL) {
printf("Argumenty musza byc poprawnymi nazwami plikow\\n");
printf("1");
fclose(pWdi);
fclose(pWsp);
fclose(pVis);
fclose(pSky);
fclose(pWea);
fclose(pTem);
fclose(pWic);
fclose(pDew);
fclose(pHum);
fclose(pPre);
} else
while (fgets(line, maxl, pFile) != NULL) {
printf("%s \\n", argv);
if (sscanf(argv[1], "%s",csmiec) == 1) {
printf("%s \\n",csmiec);
}
/* zczytywanie i przepisywanie wiatru */
else if (sscanf
(line, "Wind: from the %*s (%s degrees) at %s", word1,
word2) == 2) {
fprintf(pWdi, "%d %s \\n",x, word1);
fprintf(pWsp, "%d %s \\n",x, word2);
}
/* ...gdy wiatr zmienny */
else if (sscanf(line, "Wind: Variable at %s", word1) == 1) {
fprintf(pWsp,"%d %s \\n",x, word1);
}
/* Widocznosc - wiecej niz... */
else if (sscanf(line, "Visibility: greater than %s", word1)
== 1) {
fprintf(pVis, "%d %s \\n",x, word1);
/* Widocznosc - mniej niz 1 */
} else if (sscanf(line, "Visibility: less than %s", word1)
== 1) {
fprintf(pVis, "%d %s \\n",x, word1);
/* widocznosc */
} else if (sscanf(line, "Visibility: %s", word1) == 1) {
fprintf(pVis, "%d %s \\n",x, word1);
/* niebo */
} else
if ((sscanf
(line, "Sky conditions: %s %s", word1,
word2) == 2)
||
(sscanf
(line, "Sky conditions: %s %s", word1, word2)
== 1)) {
if (strcmp(word1, "clear") == 0)
fprintf(pSky, "%d %d \\n",x, vis1);
else if ((strcmp(word1, "mostly") == 0)
&& (strcmp(word2, "clear") == 0))
fprintf(pSky, "%d %d \\n",x, vis2);
else if ((strcmp(word1, "partly") == 0)
&& (strcmp(word2, "cloudy") == 0))
fprintf(pSky, "%d %d \\n",x, vis3);
else if ((strcmp(word1, "mostly") == 0)
&& (strcmp(word2, "cloudy") == 0))
fprintf(pSky, "%d %d \\n",x, vis4);
else
printf("Nieznane zachmurzenie");
/* pogoda */
} else
if (sscanf
(line, "Weather: %s %s %s", word1, word2, word3)
>= 1) {
if (strncmp(line, "Weather: mist", 13) == 0) {
if ((strcmp(word2, "shallow") == 0)
&& (strcmp(word3, "fog") == 0)) {
fprintf(pWea, "%d %d \\n",x, wea1);
fprintf(pWea, "%d %d \\n",x, wea4);
}
else
fprintf(pWea, "%d %d \\n",x, wea1);
}
if (strncmp(line, "Weather: fog", 12) == 0)
fprintf(pWea, "%d %d \\n",x, wea2);
if (strncmp(line, "Weather: freezing fog", 21) == 0)
fprintf(pWea, "%d %d \\n",x, wea3);
if (strncmp(line, "Weather: shallow fog", 20) == 0)
fprintf(pWea, "%d %d \\n",x, wea4);
if (strncmp(line, "Weather: patches of fog", 23) == 0)
fprintf(pWea, "%d %d \\n",x, wea5);
if (strncmp(line, "Weather: light rain", 19) == 0) {
if (strcmp(word3, "showers") == 0)
fprintf(pWea, "%d %d \\n",x, wea8);
else if (strcmp(word3, "mist") == 0) {
fprintf(pWea, "%d %d \\n",x, wea6);
fprintf(pWea, "%d %d \\n",x, wea1);}
else
fprintf(pWea, "!!!! %d %d \\n",x, wea6);
}
if (strncmp
(line, "Weather: Cumulonimbus clouds observed", 37)
== 0)
fprintf(pWea, "%d %d \\n",x, wea7);
/* Temperatura w stopniach Fahrenheita, zeby bylo dokladniej */
} else if (sscanf(line, "Temperature: %s", word1) == 1) {
fprintf(pTem, "%d %s \\n",x, word1);
/* Windchill jakis... */
} else if (sscanf(line, "Windchill: %s", word1) == 1) {
fprintf(pWic, "%d %s \\n",x, word1);
/* Punkt rosy, cokolwiek by to bylo */
} else if (sscanf(line, "Dew Point: %s", word1) == 1) {
fprintf(pDew, "%d %s \\n",x, word1);
/* wilgotnosc */
} else
if (sscanf(line, "Relative Humidity: %d%*s", &ismiec)
== 1) {
fprintf(pHum, "%d %d \\n",x, ismiec);
/* cisnienie */
} else
if (sscanf(line, "Pressure %*s %*s %*s %*s (%s", word1)
== 1) {
fprintf(pPre, "%d %s \\n",x, word1);
}
}
printf("test");
fclose(pFile);
}
fclose(pWdi);
fclose(pWsp);
fclose(pVis);
fclose(pSky);
fclose(pWea);
fclose(pTem);
fclose(pWic);
fclose(pDew);
fclose(pHum);
fclose(pPre);
return 0;
}
[Edited by b0rsuk at
Local Time:03-01-2005 at 06:04 PM]
____________________________
http://www.gamasutra.com/features/20051128/adams_01.shtml