-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynoptic_reader.c
More file actions
56 lines (54 loc) · 1011 Bytes
/
synoptic_reader.c
File metadata and controls
56 lines (54 loc) · 1011 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#define DEFAULT_SIZE 96000
FILE *output;
int lastday = -1;
int
main (int argc, char **argv)
{
FILE *input;
time_t now;
struct tm *gmp;
float *inbuf;
int insize = DEFAULT_SIZE;
int inbufsz;
if ((input = fopen (argv[1], "r")) == NULL)
{
perror ("Opening input file\n");
exit (0);
}
if (argc > 2)
{
insize = atoi(argv[2]);
}
inbufsz = insize * 2 * sizeof(float);
inbuf = (float *)malloc (inbufsz);
while (fread ((void *)inbuf, inbufsz, 1, input) > 0)
{
time (&now);
gmp = gmtime (&now);
if (gmp->tm_wday != lastday)
{
char filename[128];
/*
* New files
*/
lastday = gmp->tm_wday;
if (output != NULL)
{
fclose (output);
}
sprintf (filename, "synoptic-%04d%02d%02d.dat",
gmp->tm_year+1900,
gmp->tm_mon+1,
gmp->tm_mday);
output = fopen (filename, "a");
}
fwrite (inbuf, inbufsz, 1, output);
fflush (output);
}
return (0);
}