Add Julie's changes for AFWA ice fields, including a new Vtable just for the ice.
[WPS.git] / geogrid / src / cio.c
blob58c92a2c33a282922740e2ee7ce8c966bde7a9ee
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
5 #ifdef _UNDERSCORE
6 #define cio_set_log_filename cio_set_log_filename_
7 #define cio_prints cio_prints_
8 #define cio_printf cio_printf_
9 #define cio_printi cio_printi_
10 #endif
11 #ifdef _DOUBLEUNDERSCORE
12 #define cio_set_log_filename cio_set_log_filename__
13 #define cio_prints cio_prints__
14 #define cio_printf cio_printf__
15 #define cio_printi cio_printi__
16 #endif
18 char * logfilename = 0;
19 FILE * cio_out = 0;
21 void cio_set_log_filename(char * s, int * n)
23 /* Allow changes to the log filename so long as
24 * we haven't actually opened the file (and written
25 * to it).
27 if (!cio_out && logfilename)
29 free(logfilename);
30 logfilename = 0;
33 if (!logfilename)
35 logfilename = (char *)malloc(*n+1);
36 strncpy(logfilename, s, *n);
37 logfilename[*n] = '\0';
41 void cio_printf(int * fd, float * f)
43 if (!logfilename) return;
45 if (*fd != 0)
47 if (!cio_out) cio_out = fopen(logfilename,"w");
48 fprintf(cio_out, "%f", *f);
49 fflush(cio_out);
51 else
53 fprintf(stdout, "%f", *f);
54 fflush(stdout);
58 void cio_printi(int * fd, int * i)
60 if (!logfilename) return;
62 if (*fd != 0)
64 if (!cio_out) cio_out = fopen(logfilename,"w");
65 fprintf(cio_out, "%i", *i);
66 fflush(cio_out);
68 else
70 fprintf(stdout, "%i", *i);
71 fflush(stdout);
75 void cio_prints(int * fd, char * s, int * n)
77 if (!logfilename) return;
79 if (*fd != 0)
81 s[*n] = '\0';
82 if (!cio_out) cio_out = fopen(logfilename,"w");
83 fprintf(cio_out, "%s", s);
84 fflush(cio_out);
86 else
88 s[*n] = '\0';
89 fprintf(stdout, "%s", s);
90 fflush(stdout);