ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/rcalc.c
(Generate patch)

Comparing ray/src/cal/rcalc.c (file contents):
Revision 1.22 by greg, Thu Dec 19 16:38:12 2013 UTC vs.
Revision 1.26 by greg, Thu Mar 24 18:48:28 2016 UTC

# Line 73 | Line 73 | struct field  *inpfmt = NULL;   /* input record format
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) */
# Line 157 | Line 160 | char  *argv[]
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;
# Line 197 | Line 203 | char  *argv[]
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;
# Line 225 | Line 234 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
234                  }
235          if (otype != 'a')
236                  SET_FILE_BINARY(stdout);
237 + #ifdef getc_unlocked            /* avoid lock/unlock overhead */
238 +        flockfile(stdout);
239 + #endif
240          if (noinput) {          /* produce a single output record */
241                  if (i < argc) {
242                          eputs(argv[0]);
# Line 235 | Line 247 | eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e
247                  putout();
248                  quit(0);
249          }
238        if (itype != 'a')
239                SET_FILE_BINARY(stdin);
240
250          if (blnkeq)             /* for efficiency */
251                  nbsynch();
252  
# Line 306 | Line 315 | char  *file
315                  eputs(": cannot open\n");
316                  quit(1);
317          }
318 +        if (itype != 'a')
319 +                SET_FILE_BINARY(fp);
320 + #ifdef getc_unlocked            /* avoid lock/unlock overhead */
321 +        flockfile(fp);
322 + #endif
323          if (inpfmt != NULL)
324                  initinp(fp);
325          
# Line 318 | Line 332 | char  *file
332                          putout();
333                          ++nout;
334                  }
335 +                if (incnt && nrecs >= incnt)
336 +                        break;
337 +                if (outcnt && nout >= outcnt)
338 +                        break;
339          }
340          fclose(fp);
341   }
# Line 345 | Line 363 | static double
363   l_in(char *funame)      /* function call for $channel */
364   {
365          int  n;
366 <        register char  *cp;
366 >        char  *cp;
367                          /* get argument as integer */
368          n = (int)(argument(1) + .5);
369          if (n != 0)     /* return channel value */
# Line 377 | Line 395 | int  n
395   )
396   {
397          int  i;
398 <        register char  *cp;
398 >        char  *cp;
399  
400          if (noinput || inpfmt != NULL) {
401                  eputs("no column input\n");
# Line 478 | Line 496 | int  output
496          char  *inptr;
497          struct field  fmt;
498          int  res;
499 <        register struct field  *f;
499 >        struct field  *f;
500                                                  /* check for inline format */
501          for (inptr = spec; *inptr; inptr++)
502                  if (*inptr == '$')
# Line 538 | Line 556 | int  output
556  
557   static int
558   readfield(                   /* get next field in format */
559 < register char  **pp
559 > char  **pp
560   )
561   {
562          int  type = F_NUL;
563          int  width = 0;
564 <        register char  *cp;
564 >        char  *cp;
565          
566          cp = inpbuf;
567          while (cp < &inpbuf[INBSIZ-1] && **pp != '\0') {
# Line 608 | Line 626 | getsvar(                         /* get string variabl
626   char  *svname
627   )
628   {
629 <        register struct strvar  *sv;
629 >        struct strvar  *sv;
630          
631          for (sv = svhead; sv != NULL; sv = sv->next)
632                  if (!strcmp(sv->name, svname))
# Line 627 | Line 645 | svpreset(                    /* preset a string variab
645   char  *eqn
646   )
647   {
648 <        register struct strvar  *sv;
649 <        register char  *val;
648 >        struct strvar  *sv;
649 >        char  *val;
650  
651          for (val = eqn; *val != '='; val++)
652                  if (!*val)
# Line 647 | Line 665 | char  *eqn
665   static void
666   clearrec(void)                  /* clear input record variables */
667   {
668 <        register struct field  *f;
668 >        struct field  *f;
669  
670          for (f = inpfmt; f != NULL; f = f->next)
671                  switch (f->type & F_TYP) {
# Line 668 | Line 686 | static int
686   getrec(void)                            /* get next record from file */
687   {
688          int  eatline;
689 <        register struct field  *f;
689 >        struct field  *f;
690  
691          while (ipb.chr != EOF) {
692                  if (blnkeq) {           /* beware of nbsynch() */
# Line 702 | Line 720 | getrec(void)                           /* get next record from file */
720  
721   static int
722   getfield(                             /* get next field */
723 < register struct field  *f
723 > struct field  *f
724   )
725   {
726          static char  buf[RMAXWORD+1];            /* no recursion! */
727          int  delim, inword;
728          double  d;
729          char  *np;
730 <        register char  *cp;
730 >        char  *cp;
731  
732          switch (f->type & F_TYP) {
733          case T_LIT:
# Line 796 | Line 814 | register struct field  *f
814   static void
815   putrec(void)                                /* output a record */
816   {
817 <        char  fmt[32];
818 <        register int  n;
819 <        register struct field  *f;
817 >        char  fmt[32], typ[16];
818 >        int  n;
819 >        struct field  *f;
820          int  adlast, adnext;
821 +        double  dv, av;
822          
823          adlast = 0;
824          for (f = outfmt; f != NULL; f = f->next) {
# Line 830 | Line 849 | putrec(void)                                /* output
849                          break;
850                  case T_NUM:
851                          n = f->type & F_WID;
852 +                        dv = evalue(f->f.ne);
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");
862 +                        }
863                          if (adlast && adnext)
864 <                                strcpy(fmt, "%g");
864 >                                sprintf(fmt, "%%%s", typ);
865                          else if (adlast)
866 <                                sprintf(fmt, "%%-%dg", n);
866 >                                sprintf(fmt, "%%-%d%s", n, typ);
867                          else
868 <                                sprintf(fmt, "%%%dg", n);
869 <                        printf(fmt, evalue(f->f.ne));
868 >                                sprintf(fmt, "%%%d%s", n, typ);
869 >                        printf(fmt, dv);
870                          adlast = 1;
871                          break;
872                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines