include include include define LEN_FIT 30 define SZ_KEYVAL 11 # size of string for a keyword value # This task reads a list of (x,y) positions of reseau marks from an ascii # file, evaluates a polynomial fit (either forward or inverse), and writes # the (x,y) positions to an output ascii file. # Comments and blank lines are also copied to output. # Phil Hodge, 14-Mar-1991 Task created based on revalfitx. procedure tevalfit() char input[SZ_FNAME] # input text file char output[SZ_FNAME] # output text file char inpoly[SZ_FNAME] # polynomial database file char entry[SZ_R_PATTERN] # transform entry to use char dir[SZ_KEYVAL] # direction for evaluating fit #-- pointer sp pointer dt pointer fit pointer ibuf, obuf # scratch for input & output line buffers real x, y # coordinates read from input file real xout, yout # evaluated positions to write to output file int ifd, ofd # fd for input & output files int npts int ip # for ctor int direction # Direction number,1=f/w,2=b/w int axis int rec # record number of the entry in database bool badpt pointer dtmap() int clgwrd(), db_readr() int open(), getline(), ctor() begin call smark (sp) call salloc (ibuf, SZ_LINE, TY_CHAR) call salloc (obuf, SZ_LINE, TY_CHAR) call clgstr ("input", input, SZ_FNAME) call clgstr ("output", output, SZ_FNAME) if (output[1] == EOS) call error (1, "output file name must be given") # Get name of polynomial coefficients file, and map it. call clgstr ("inpoly", inpoly, SZ_FNAME) dt = dtmap (inpoly, READ_ONLY) # Get name of entry to process call clgstr ("entry", entry, SZ_R_PATTERN) # Allocate space for fit pointers call salloc (fit, LEN_FIT, TY_STRUCT) # Get the direction of the transformation. direction = clgwrd ("direction", dir, SZ_KEYVAL, "|forwards|backwards|") # Read the polynomial parameters into the fit struct. if (db_readr (dt, direction, entry, rec, axis, fit) == RES_F_NONEXTENTRY) call error (1, "entry not found") # Open input & output files. ifd = open (input, READ_ONLY, TEXT_FILE) ofd = open (output, NEW_FILE, TEXT_FILE) # Read input, evaluate the fit, write to output. badpt = false # each point is OK npts = 1 while (getline (ifd, Memc[ibuf]) != EOF) { # Read x & y values from input line. ip = 1 if (ctor (Memc[ibuf], ip, x) < 1) { # comment or blank line call putline (ofd, Memc[ibuf]) next } if (ctor (Memc[ibuf], ip, y) < 1) { call eprintf ("error reading this line:\n") call eprintf (Memc[ibuf]) call strcat ("# bad line", Memc[ibuf], SZ_LINE) call putline (ofd, Memc[ibuf]) next } # Evaluate the polynomial (or its inverse) at current point. call revalfitx (fit, axis, npts, x, y, badpt, xout, yout) # Write the evaluated coordinates to an output buffer. call sprintf (Memc[obuf], SZ_LINE, "%10.4f %10.4f") call pargr (xout) call pargr (yout) # Append the rest of the input string, which will include # at least a newline and may also have an in-line comment. if (ip < SZ_LINE) call strcat (Memc[ibuf+ip-1], Memc[obuf], SZ_LINE) call putline (ofd, Memc[obuf]) } # Close the database file. call dtunmap (dt) # Close the ascii files. call close (ofd) call close (ifd) call sfree (sp) end