73 |
|
struct field *outfmt = NULL; /* output record structure */ |
74 |
|
struct strvar *svhead = NULL; /* string variables */ |
75 |
|
|
76 |
+ |
long incnt = 0; /* limit number of input records? */ |
77 |
+ |
long outcnt = 0; /* limit number of output records? */ |
78 |
+ |
|
79 |
|
int blnkeq = 1; /* blanks compare equal? */ |
80 |
|
int igneol = 0; /* ignore end of line? */ |
81 |
|
int passive = 0; /* passive mode (transmit unmatched input) */ |
160 |
|
nbicols = 0; |
161 |
|
readfmt(argv[++i], 0); |
162 |
|
break; |
163 |
+ |
case 'n': |
164 |
+ |
incnt = atol(argv[++i]); |
165 |
+ |
break; |
166 |
|
case 'a': |
167 |
|
itype = 'a'; |
168 |
|
nbicols = 0; |
203 |
|
otype = 'a'; |
204 |
|
readfmt(argv[++i], 1); |
205 |
|
break; |
206 |
+ |
case 'n': |
207 |
+ |
outcnt = atol(argv[++i]); |
208 |
+ |
break; |
209 |
|
case 'a': |
210 |
|
otype = 'a'; |
211 |
|
break; |
281 |
|
if (inpfmt != NULL) |
282 |
|
return(getrec()); |
283 |
|
if (tolower(itype) == 'd') { |
284 |
< |
if (fread(inpbuf, sizeof(double), nbicols, fp) != nbicols) |
284 |
> |
if (getbinary(inpbuf, sizeof(double), nbicols, fp) != nbicols) |
285 |
|
return(0); |
286 |
|
if (itype == 'D') |
287 |
|
swap64(inpbuf, nbicols); |
288 |
|
return(1); |
289 |
|
} |
290 |
|
if (tolower(itype) == 'f') { |
291 |
< |
if (fread(inpbuf, sizeof(float), nbicols, fp) != nbicols) |
291 |
> |
if (getbinary(inpbuf, sizeof(float), nbicols, fp) != nbicols) |
292 |
|
return(0); |
293 |
|
if (itype == 'F') |
294 |
|
swap32(inpbuf, nbicols); |
332 |
|
putout(); |
333 |
|
++nout; |
334 |
|
} |
335 |
+ |
if (incnt && nrecs >= incnt) |
336 |
+ |
break; |
337 |
+ |
if (outcnt && nout >= outcnt) |
338 |
+ |
break; |
339 |
|
} |
340 |
|
fclose(fp); |
341 |
|
} |
466 |
|
float fval = v; |
467 |
|
|
468 |
|
while (++colpos < n) |
469 |
< |
fwrite(zerobuf, |
469 |
> |
putbinary(zerobuf, |
470 |
|
tolower(otype)=='d' ? sizeof(double) : sizeof(float), |
471 |
|
1, stdout); |
472 |
|
switch (otype) { |
474 |
|
swap64((char *)&v, 1); |
475 |
|
/* fall through */ |
476 |
|
case 'd': |
477 |
< |
fwrite(&v, sizeof(double), 1, stdout); |
477 |
> |
putbinary(&v, sizeof(double), 1, stdout); |
478 |
|
break; |
479 |
|
case 'F': |
480 |
|
swap32((char *)&fval, 1); |
481 |
|
/* fall through */ |
482 |
|
case 'f': |
483 |
< |
fwrite(&fval, sizeof(float), 1, stdout); |
483 |
> |
putbinary(&fval, sizeof(float), 1, stdout); |
484 |
|
break; |
485 |
|
} |
486 |
|
} |
814 |
|
static void |
815 |
|
putrec(void) /* output a record */ |
816 |
|
{ |
817 |
< |
char fmt[32], typ[32]; |
817 |
> |
char fmt[32], typ[16]; |
818 |
|
int n; |
819 |
|
struct field *f; |
820 |
|
int adlast, adnext; |
849 |
|
break; |
850 |
|
case T_NUM: |
851 |
|
n = f->type & F_WID; |
839 |
– |
typ[0] = (n <= 6) ? 'g' : 'e'; |
840 |
– |
typ[1] = '\0'; |
852 |
|
dv = evalue(f->f.ne); |
853 |
< |
if ((av = fabs(dv)) < 1L<<31) { |
853 |
> |
av = fabs(dv); |
854 |
> |
if (n <= 9) |
855 |
> |
strcpy(typ, "g"); |
856 |
> |
else |
857 |
> |
sprintf(typ, ".%de", n-5); |
858 |
> |
if (av < 1L<<31) { |
859 |
|
long iv = (int)(av + .5); |
860 |
|
if (iv && fabs(av-iv) <= av*1e-14) |
861 |
|
strcpy(typ, ".0f"); |