27 int i, n, frameNr, yy, mm, dd, h, m, s;
33 if(
SIF_TEST) printf(
"sifRead(%s, *sif)\n", filename);
34 if(filename==NULL || data==NULL)
return(1);
42 if(ret>2) {strcpy(
siferrmsg,
"cannot read file");
return(5);}
43 else if(ret>0) {strcpy(
siferrmsg,
"cannot open file");
return(2);}
45 printf(
"lineNr:=%d\n", tlst.
token_nr);
46 for(
int i=0; i<tlst.
token_nr; i++) printf(
"token[%d] := '%s'\n", i, tlst.
tok[i]);
62 strcpy(
siferrmsg,
"wrong format");
return(4);
65 printf(
"lineNr:=%d\n", tlst.
token_nr);
67 printf(
"token[%d] := '%s'\n", i, tlst.
tok[i]);
71 if(
SIF_TEST) printf(
"SIF title := '%s'\n", tlst.
tok[0]);
72 n=sscanf(tlst.
tok[0],
"%d/%d/%d %d:%d:%d %d %d %d %255s %7s",
73 &dd, &mm, &yy, &h, &m, &s, &frameNr, &data->
colNr, &data->
version,
76 if(n<9 || frameNr<1 || data->colNr<2 || data->version!=1) {
77 if(
SIF_TEST) printf(
"invalid SIF title line\n");
82 timet=time(NULL); st=gmtime(&timet);
84 st->tm_mday=dd; st->tm_mon=mm-1; st->tm_year=yy-1900;
85 st->tm_hour=h; st->tm_min=m; st->tm_sec=s; st->tm_isdst=-1;
95 strcpy(
siferrmsg,
"cannot allocate SIF");
return(6);
100 while(i<data->frameNr && i<tlst.
token_nr-1) {
103 n=sscanf(tlst.
tok[1+i],
"%lf %lf %lf %lf", &data->
x1[i], &data->
x2[i],
113 if(data->
x2[i]<data->
x1[i]) {
114 strcpy(
siferrmsg,
"invalid time frames");
152 int i, n, req_decimals=0;
157 if(
SIF_TEST) printf(
"sifWrite(*sif, %s)\n", filename);
164 if(strcasecmp(filename,
"STDOUT")==0) {
165 fp=stdout; intofile=0;
168 fp=fopen(filename,
"w");
169 if(fp==NULL) {strcpy(
siferrmsg,
"cannot open file");
return 2;}
174 if(!
gmtime_r((time_t*)&data->
scantime, &tm) || !strftime(buf, 1024,
"%d/%m/%Y %H:%M:%S", &tm))
175 strcpy(buf,
"1/1/1900 00:00:00");
179 strcpy(
siferrmsg,
"cannot write file");
if(intofile) fclose(fp);
184 if(strlen(data->
studynr)==0) fprintf(fp,
" .");
else fprintf(fp,
" %s", data->
studynr);
190 for(i=1, req_decimals=0; i<data->
frameNr; i++) {
191 if(round(data->
x1[i])==round(data->
x1[i-1])) {req_decimals=1;
break;}
192 if(round(data->
x2[i])==round(data->
x2[i-1])) {req_decimals=1;
break;}
196 for(i=0; i<data->
frameNr; i++) {
197 if(req_decimals==0) n=fprintf(fp,
"%.0f %.0f", data->
x1[i], data->
x2[i]);
198 else n=fprintf(fp,
"%.1f %.1f", data->
x1[i], data->
x2[i]);
200 strcpy(
siferrmsg,
"cannot write file");
if(intofile) fclose(fp);
203 if(data->
colNr<=2) {n=fprintf(fp,
"\n");
continue;}
206 strcpy(
siferrmsg,
"cannot write file");
if(intofile) fclose(fp);
209 if(data->
colNr<5) {n=fprintf(fp,
"\n");
continue;}
210 n=fprintf(fp,
" %.0f", data->
trues[i]);
212 strcpy(
siferrmsg,
"cannot write file");
if(intofile) fclose(fp);
215 if(data->
colNr<6) {n=fprintf(fp,
"\n");
continue;}
216 n=fprintf(fp,
" %.5f\n", data->
weights[i]);
218 strcpy(
siferrmsg,
"cannot write file");
if(intofile) fclose(fp);
224 if(intofile) fclose(fp);
241 strcpy(buf,
"1900-01-01 00:00:00");
242 printf(
"Scan time: %s\n", buf);
244 printf(
"Frame start end Prompts Randoms Trues Weight\n");
245 for(
int i=0; i<data->
frameNr; i++) {
246 printf(
" %03d %6.1f %6.1f %10.0f %10.0f %10.0f %8.6f\n", i+1,
char * ctime_r_int(const time_t *t, char *buf)
Convert calendard time t into a null-terminated string of the form YYYY-MM-DD hh:mm:ss,...
time_t timegm(struct tm *tm)
Inverse of gmtime, converting struct tm to time_t.
struct tm * gmtime_r(const time_t *t, struct tm *tm)
Convert time_t to GMT struct tm.
Header file for libtpcimgio.
int sifSetmem(SIF *data, int frameNr)
void str_token_list_empty(STR_TOKEN_LIST *lst)
int str_token_list_del(STR_TOKEN_LIST *lst, int item)
int textfileReadLines(const char *filename, STR_TOKEN_LIST *lst)
void str_token_list_init(STR_TOKEN_LIST *lst)
size_t strnlen(const char *s, size_t n)
int asciiCommentLine(const char *line, int *cont)
int sifWrite(SIF *data, char *filename)
int sifRead(char *filename, SIF *data)
char studynr[MAX_STUDYNR_LEN+1]