--- ray/src/cal/total.c 2016/03/24 18:48:28 1.11 +++ ray/src/cal/total.c 2021/11/16 03:30:45 1.15 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: total.c,v 1.11 2016/03/24 18:48:28 greg Exp $"; +static const char RCSid[] = "$Id: total.c,v 1.15 2021/11/16 03:30:45 greg Exp $"; #endif /* * total.c - program to reduce columns of data. @@ -7,11 +7,11 @@ static const char RCSid[] = "$Id: total.c,v 1.11 2016/ * 5/18/88 */ -#include #include #include #include #include "platform.h" +#include "rtio.h" #define MAXCOL 8192 /* maximum number of columns */ @@ -170,11 +170,11 @@ getrecord( /* read next input record */ int nf; /* reading binary input? */ if (nbicols > 0) - return(fread(field, sizeof(double), nbicols, fp)); + return(getbinary(field, sizeof(double), nbicols, fp)); if (nbicols < 0) { float *fbuf = (float *)buf; int i; - nf = fread(fbuf, sizeof(float), -nbicols, fp); + nf = getbinary(fbuf, sizeof(float), -nbicols, fp); for (i = nf; i-- > 0; ) field[i] = fbuf[i]; return(nf); @@ -211,14 +211,14 @@ putrecord( /* write out results record */ { /* binary output? */ if (bocols > 0) { - fwrite(field, sizeof(double), n, fp); + putbinary(field, sizeof(double), n, fp); return; } if (bocols < 0) { float fv; while (n-- > 0) { fv = *field++; - fwrite(&fv, sizeof(float), 1, fp); + putbinary(&fv, sizeof(float), 1, fp); } return; } @@ -228,6 +228,8 @@ putrecord( /* write out results record */ if (n) fputc(tabc, fp); } fputc('\n', fp); + if (!subtotal) + fflush(fp); /* flush unless -r */ } @@ -327,7 +329,9 @@ char *fname break; if (!subtotal) ltotal = 0; + if (incnt > 0 && nlin >= incnt) + break; } /* close input */ - return(fclose(fp)); + return(fclose(fp) == EOF ? 1 : 0); }