include include # for DEGTORAD include # RTRANSFORMX -- program linear transformations on reseau mark coords # # D. Giaretta, 01-Aug-1987 Original SPP version # Phil Hodge, 20-Mar-1992 Use DEGTORAD for rota; reorder loops. procedure t_rtransformx() char output[SZ_FNAME] # output file - without whitespace char input[SZ_FNAME] # input file - without whitespace char entry[SZ_R_PATTERN] # entry template char action[3] # action - r(otate)/m(agnify)/s(hift) real rota # angle of rotation (radians - but # user parameter in degrees real crota1, crota2 # center for rotation (x,y) real mag1, mag2 # mag. factors along x,y real cmag1, cmag2 # center for magnification (x,y) real shift1, shift2 # shift x,y pointer rpout, rpin # res. structure pointers pointer rentp # res. entry structure int nrows, ncols # rows, cols in grid bool streq() int nowhite() real clgetr() pointer rs_open(), rs_template(), rlist int rs_readr(), rs_list(), rs_num_rows() begin rpin = NULL rpout = NULL call clgstr( "input", input, SZ_FNAME) if ( nowhite(input, input, SZ_FNAME) == 0 ) call error( 0, "input file must be given") call clgstr( "output", output, SZ_FNAME) if ( nowhite(output, output, SZ_FNAME) == 0 ) call error(0, "output file must be given") if ( streq( input, output) ) call error(0, "cannot transform in place") call clgstr( "entry", entry, SZ_R_PATTERN) call clgstr( "action", action, 3) # convert to lower case to make tests easier call strlwr(action) # only ask for what we need if (action[1] == 'r' || action[2] == 'r' || action[3] == 'r'){ rota = DEGTORAD(clgetr("rota")) #convert to radians crota1 = clgetr("crota1") crota2 = clgetr("crota2") } if (action[1] == 'm' || action[2] == 'm' || action[3] == 'm'){ mag1 = clgetr("mag1") mag2 = clgetr("mag2") cmag1 = clgetr("cmag1") cmag2 = clgetr("cmag2") } if (action[1] == 's' || action[2] == 's' || action[3] == 's'){ shift1 = clgetr("shift1") shift2 = clgetr("shift2") } rpin = rs_open( input, READ_ONLY, 0) nrows = RES_NROWS(rpin) ncols = RES_NCOLS(rpin) rpout = rs_open( output, NEW_FILE, rpin) call rs_new( rs_num_rows(rpin), ncols, nrows, ncols, TY_REAL, rpout) # get space for input and output coords call rs_alloc( rpin, TY_REAL, rentp) # set up loop control rlist = rs_template( rpin, entry) while ( rs_readr( rpin, rentp, EOS, rs_list(rlist) ) != RES_F_NONEXTENTRY ) { # transform the new entry call xrstr_coord( rentp, action, rota, crota1, crota2, mag1, mag2, cmag1, cmag2, shift1, shift2, Memr[RES_XPT(rentp)], Memr[RES_YPT(rentp)], Memb[RES_FPT(rentp)], Memr[RES_XPT(rentp)], Memr[RES_YPT(rentp)] ) # update the tracking info call rs_t_update(rentp, "T", SZ_R_TRACKING) # write entry out call rs_write ( rpout, rentp, 0) } # close the files call rs_close(rpout) call rs_close(rpin) end # XRSTR_COORD -- transform the reseau coordinates procedure xrstr_coord( rentp, action, rota, crota1, crota2, mag1, mag2, cmag1, cmag2, shift1, shift2, x, y, f, xout, yout ) pointer rentp char action[3] real rota, crota1, crota2 real mag1, mag2, cmag1, cmag2 real shift1, shift2 real x[ARB], y[ARB] bool f[ARB] real xout[ARB], yout[ARB] real temp1, temp2 int i, j, nels real sinth, costh char mess1[SZ_RES_MESS] begin sinth = sin(rota) costh = cos(rota) nels = RES_ENT_NROWS(rentp)*RES_ENT_NCOLS(rentp) # Do for each "action" specified: rotate, shift, or magnify. for (j = 1; j<=3 && action[j] != EOS; j=j+1){ if (action[j] == 'r'){ # rotate # Do for each reseau position. do i = 1, nels { # Transform current position if not indef. if (f[i]) { xout[i] = x[i] # copy indef yout[i] = y[i] } else { temp1 = crota1 + costh*(xout[i] - crota1) + sinth*(yout[i] - crota2) temp2 = crota2 - sinth*(xout[i] - crota1) + costh*(yout[i] - crota2) xout[i] = temp1 yout[i] = temp2 } } } else if ( action[j] == 's') { # shift do i = 1, nels { if (f[i]) { xout[i] = x[i] # copy indef yout[i] = y[i] } else { xout[i] = xout[i] + shift1 yout[i] = yout[i] + shift2 } } } else if ( action[j] == 'm') { # magnify do i = 1, nels { if (f[i]) { xout[i] = x[i] # copy indef yout[i] = y[i] } else { xout[i] = cmag1 + mag1*(xout[i] - cmag1) yout[i] = cmag2 + mag2*(yout[i] - cmag2) } } } else { call strcpy("illegal option: ", mess1, SZ_RES_MESS) call strcat( action[j], mess1, SZ_RES_MESS) call error(0, mess1) } } end