~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to imagery/i.vpoints/analyze.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <string.h>
2
 
#include <unistd.h>
3
 
#include <math.h>
4
 
#include <grass/gis.h>
5
 
#include "globals.h"
6
 
#include <grass/raster.h>
7
 
#include "crs.h"
8
 
 
9
 
#define NLINES 18
10
 
struct box
11
 
{
12
 
    int top, bottom, left, right;
13
 
};
14
 
 
15
 
static int which;
16
 
static struct box more, less, report;
17
 
static int height, size, edge, nlines;
18
 
static int curp, first_point;
19
 
static double rms;
20
 
static double *xres, *yres, *gnd;
21
 
static int pager;
22
 
static int xmax, ymax, gmax;
23
 
static char buf[300];
24
 
 
25
 
static char delete_msg[11] = "delete_off";
26
 
static char pick_msg[40] = " Double click to include/exclude pt. ";
27
 
static int delete_mode;
28
 
static char order_msg[10] = "1st ORDER";
29
 
static int trans_order = 1;
30
 
 
31
 
#define FMT0(buf,n) \
32
 
        sprintf (buf, "%3d ", n)
33
 
#define FMT1(buf,xres,yres,gnd) \
34
 
        sprintf (buf, "%5.1f %5.1f %6.1f ", xres,yres,gnd)
35
 
#define LHEAD1 "        error          "
36
 
#define LHEAD2 "  #   col   row  target"
37
 
 
38
 
#define FMT2(buf,e1,n1,e2,n2) \
39
 
        sprintf (buf, "%9.1f %9.1f %9.1f %9.1f ", e1,n1,e2,n2)
40
 
#define RHEAD1 "         image              target"
41
 
#define RHEAD2 "    east     north      east     north"
42
 
 
43
 
#define BACKGROUND GREY
44
 
 
45
 
static int delete_mark(void);
46
 
static int do_warp(void);
47
 
static int rast_redraw(void);
48
 
static int warp(void);
49
 
static int no_warp(void);
50
 
static int downarrow(struct box *, int);
51
 
static int uparrow(struct box *, int);
52
 
static int pick(int, int);
53
 
static int get_order(void);
54
 
static int show_point(int, int);
55
 
static int printcentered(FILE *, char *, int);
56
 
static int inbox(struct box *, int, int);
57
 
static int cancel_which(void);
58
 
static int done(void);
59
 
static int do_report(FILE *);
60
 
static int to_printer(void);
61
 
static int askfile(void);
62
 
static int to_file(void);
63
 
static int dotext(char *, int, int, int, int, int, int);
64
 
static int compute_transformation(void);
65
 
 
66
 
static int do_1st(void)
67
 
{
68
 
    strcpy(order_msg, "1st ORDER");
69
 
    trans_order = 1;
70
 
    if (compute_transformation())
71
 
        return 1;               /* back to analyze menu */
72
 
 
73
 
    rast_redraw();
74
 
    return 1;
75
 
}
76
 
 
77
 
static int do_2nd(void)
78
 
{
79
 
    strcpy(order_msg, "2nd ORDER");
80
 
    trans_order = 2;
81
 
    if (compute_transformation())
82
 
        return 0;
83
 
 
84
 
    rast_redraw();
85
 
    return 1;
86
 
}
87
 
 
88
 
static int do_3rd(void)
89
 
{
90
 
    strcpy(order_msg, "3rd ORDER");
91
 
    trans_order = 3;
92
 
    if (compute_transformation())
93
 
        return 0;
94
 
 
95
 
    rast_redraw();
96
 
    return 1;
97
 
}
98
 
 
99
 
static int delete_mark(void)
100
 
{
101
 
    if (delete_mode) {
102
 
        strcpy(pick_msg, " Double click to include/exclude point");
103
 
        strcpy(delete_msg, "delete_off");
104
 
        delete_mode = 0;
105
 
    }
106
 
    else {
107
 
        strcpy(pick_msg, " Double click on point to be DELETED   ");
108
 
        strcpy(delete_msg, "DELETE_ON ");
109
 
        delete_mode = 1;
110
 
    }
111
 
    pager = 1;                  /* redisplay entire form */
112
 
 
113
 
    return 1;
114
 
}
115
 
 
116
 
int delete_control_point(int n)
117
 
{
118
 
    int i;
119
 
    char msg[80];
120
 
 
121
 
    if ((n < 0) | (n > group.points.count - 1)) {
122
 
        sprintf(msg, "%d is an invalid control point index value.", n);
123
 
        G_warning(msg);
124
 
        return 1;
125
 
    }
126
 
    for (i = n; i < group.points.count - 1; i++) {
127
 
        G_copy(&group.points.e1[i], &group.points.e1[i + 1],
128
 
               sizeof(group.points.e1[0]));
129
 
        G_copy(&group.points.n1[i], &group.points.n1[i + 1],
130
 
               sizeof(group.points.n1[0]));
131
 
        G_copy(&group.points.e2[i], &group.points.e2[i + 1],
132
 
               sizeof(group.points.e2[0]));
133
 
        G_copy(&group.points.n2[i], &group.points.n2[i + 1],
134
 
               sizeof(group.points.n2[0]));
135
 
        G_copy(&group.points.status[i], &group.points.status[i + 1],
136
 
               sizeof(group.points.status[0]));
137
 
    }
138
 
    group.points.count -= 1;
139
 
    if (I_put_control_points(group.name, &group.points) < 0) {
140
 
        G_fatal_error("bad return on I_put_control_points");
141
 
        return 1;
142
 
    }
143
 
    return 0;
144
 
}
145
 
 
146
 
/*---------------------------------------------------------------
147
 
*/
148
 
static int do_warp(void)
149
 
{
150
 
    static int use = 1;
151
 
    int x, y;
152
 
 
153
 
    static Objects objects[] = {
154
 
        MENU("RASTER REDRAW", rast_redraw, &use),
155
 
        INFO("Overlay vectors on raster image? ", &use),
156
 
        MENU("NO", no_warp, &use),
157
 
        MENU("YES", warp, &use),
158
 
        {0}
159
 
    };
160
 
    x = (SCREEN_LEFT + SCREEN_RIGHT) / 2;
161
 
    y = SCREEN_BOTTOM;
162
 
    Set_mouse_xy(x, y);
163
 
    Input_pointer(objects);
164
 
    return 1;
165
 
}
166
 
 
167
 
static int no_warp(void)
168
 
{
169
 
    return -1;
170
 
}
171
 
 
172
 
static int warp(void)
173
 
{
174
 
    warpvect(group.E21, group.N21, trans_order);
175
 
    return -1;
176
 
}
177
 
 
178
 
static int rast_redraw(void)
179
 
{
180
 
    Erase_view(VIEW_MAP1);
181
 
    drawcell(VIEW_MAP1, 0);     /* 0 means don't initialize VIEW_MAP2 */
182
 
    display_points(1);
183
 
    return 0;
184
 
}
185
 
 
186
 
 
187
 
static int uparrow(struct box *box, int color)
188
 
{
189
 
    R_standard_color(color);
190
 
    Uparrow(box->top + edge, box->bottom - edge, box->left + edge,
191
 
            box->right - edge);
192
 
 
193
 
    return 0;
194
 
}
195
 
 
196
 
static int downarrow(struct box *box, int color)
197
 
{
198
 
    R_standard_color(color);
199
 
    Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
200
 
              box->right - edge);
201
 
 
202
 
    return 0;
203
 
}
204
 
 
205
 
static int pick(int x, int y)
206
 
{
207
 
    int n;
208
 
    int cur;
209
 
 
210
 
    cur = which;
211
 
    cancel_which();
212
 
    if (inbox(&more, x, y)) {
213
 
        if (curp >= group.points.count)
214
 
            return 0;
215
 
        first_point = curp;
216
 
        pager = 1;
217
 
        return 1;
218
 
    }
219
 
    if (inbox(&less, x, y)) {
220
 
        if (first_point == 0)
221
 
            return 0;
222
 
        first_point -= nlines;
223
 
        if (first_point < 0)
224
 
            first_point = 0;
225
 
        pager = 1;
226
 
        return 1;
227
 
    }
228
 
    if (!inbox(&report, x, y)) {
229
 
        return 0;
230
 
    }
231
 
 
232
 
    n = (y - report.top) / height;
233
 
    if (n == cur) {             /* second click! */
234
 
        if (!delete_mode) {
235
 
            group.points.status[first_point + n] =
236
 
                !group.points.status[first_point + n];
237
 
            compute_transformation();
238
 
            show_point(first_point + n, 1);
239
 
            return 1;
240
 
        }
241
 
        else {
242
 
            delete_control_point(first_point + n);
243
 
            first_point = 0;
244
 
            compute_transformation();
245
 
            pager = 1;
246
 
            return 1;
247
 
        }
248
 
    }
249
 
 
250
 
    /* first click */
251
 
    which = n;
252
 
    show_point(first_point + n, 0);
253
 
    if (!delete_mode)
254
 
        R_standard_color(RED);
255
 
    else
256
 
        R_standard_color(ORANGE);
257
 
 
258
 
    Outline_box((report.top + n * height) + 1, report.top + (n + 1) * height,
259
 
                report.left, report.right - 1);
260
 
 
261
 
    R_flush();
262
 
 
263
 
    return 0;                   /* ignore first click */
264
 
 
265
 
}
266
 
 
267
 
static int done(void)
268
 
{
269
 
    cancel_which();
270
 
    return -1;
271
 
}
272
 
 
273
 
static int cancel_which(void)
274
 
{
275
 
    if (which >= 0) {
276
 
        R_standard_color(BACKGROUND);
277
 
        Outline_box((report.top + which * height) + 1,
278
 
                    report.top + (which + 1) * height, report.left,
279
 
                    report.right - 1);
280
 
        show_point(first_point + which, 1);
281
 
    }
282
 
    which = -1;
283
 
 
284
 
    return 0;
285
 
}
286
 
 
287
 
static int inbox(struct box *box, int x, int y)
288
 
{
289
 
    return (x > box->left && x < box->right && y > box->top &&
290
 
            y < box->bottom);
291
 
}
292
 
 
293
 
static int dotext(char *text, int top, int bottom, int left, int right,
294
 
                  int centered, int color)
295
 
{
296
 
    R_standard_color(BACKGROUND);
297
 
    R_box_abs(left, top, right, bottom);
298
 
    R_standard_color(color);
299
 
    R_move_abs(left + 1 + edge, bottom - 1 - edge);
300
 
    if (centered)
301
 
        R_move_rel((right - left - strlen(text) * size) / 2, 0);
302
 
    R_set_window(top, bottom, left, right);     /* for text clipping */
303
 
    R_text(text);
304
 
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);
305
 
 
306
 
    return 0;
307
 
}
308
 
 
309
 
static int compute_transformation(void)
310
 
{                               /* returns 0 on success, 1 on fail */
311
 
    int n, count;
312
 
    double d, d1, d2, sum;
313
 
    double e1, e2, n1, n2;
314
 
    double xval, yval, gval;
315
 
    static int order_pnts[3] = { 3, 6, 10 };
316
 
    char msg[40];
317
 
 
318
 
    xmax = ymax = gmax = 0;
319
 
    xval = yval = gval = 0.0;
320
 
 
321
 
    CRS_Compute_equation(trans_order);
322
 
    if (group.equation_stat <= 0) {
323
 
        if (group.equation_stat == 0) {
324
 
            sprintf(msg, "Not Enough Points -- %d are required.",
325
 
                    order_pnts[trans_order - 1]);
326
 
            Menu_msg(msg);
327
 
            G_sleep(2);
328
 
        }
329
 
        return 1;
330
 
    }
331
 
 
332
 
 
333
 
    /* compute the row,col error plus ground error 
334
 
     * keep track of largest and second largest error
335
 
     */
336
 
    sum = 0.0;
337
 
    rms = 0.0;
338
 
    count = 0;
339
 
    for (n = 0; n < group.points.count; n++) {
340
 
        if (group.points.status[n] <= 0)
341
 
            continue;
342
 
        count++;
343
 
        CRS_georef(group.points.e2[n], group.points.n2[n], &e1, &n1,
344
 
                   group.E21, group.N21, trans_order);
345
 
        CRS_georef(group.points.e1[n], group.points.n1[n], &e2, &n2,
346
 
                   group.E12, group.N12, trans_order);
347
 
 
348
 
        if ((d = xres[n] = e1 - group.points.e1[n]) < 0)
349
 
            d = -d;
350
 
        if (d > xval) {
351
 
            xmax = n;
352
 
            xval = d;
353
 
        }
354
 
 
355
 
        if ((d = yres[n] = n1 - group.points.n1[n]) < 0)
356
 
            d = -d;
357
 
        if (d > yval) {
358
 
            ymax = n;
359
 
            yval = d;
360
 
        }
361
 
 
362
 
        /* compute ground error (ie along diagonal) */
363
 
        d1 = e2 - group.points.e2[n];
364
 
        d2 = n2 - group.points.n2[n];
365
 
        d = d1 * d1 + d2 * d2;
366
 
        sum += d;               /* add it to rms sum, before taking sqrt */
367
 
        d = sqrt(d);
368
 
        gnd[n] = d;
369
 
        if (d > gval) {         /* is this one the max? */
370
 
            gmax = n;
371
 
            gval = d;
372
 
        }
373
 
    }
374
 
 
375
 
    /* compute overall rms error */
376
 
    if (count)
377
 
        rms = sqrt(sum / count);
378
 
 
379
 
    return 0;
380
 
}
381
 
 
382
 
static int to_file(void)
383
 
{
384
 
    FILE *fd;
385
 
    char msg[1024];
386
 
 
387
 
    cancel_which();
388
 
    if (Input_other(askfile, "Keyboard") < 0) {
389
 
        return 0;
390
 
    }
391
 
 
392
 
    fd = fopen(buf, "w");
393
 
    if (fd == NULL) {
394
 
        sprintf(msg, "** Unable to create file %s\n", buf);
395
 
        Beep();
396
 
        Curses_write_window(PROMPT_WINDOW, 2, 1, msg);
397
 
    }
398
 
    else {
399
 
        do_report(fd);
400
 
        fclose(fd);
401
 
        sprintf(msg, "Report saved in file %s\n", buf);
402
 
        Curses_write_window(PROMPT_WINDOW, 2, 1, msg);
403
 
    }
404
 
    return 0;
405
 
}
406
 
 
407
 
static int askfile(void)
408
 
{
409
 
    char file[GNAME_MAX];
410
 
 
411
 
    while (1) {
412
 
        Curses_prompt_gets("Enter file to hold report: ", file);
413
 
        G_strip(file);
414
 
        if (*file == 0)
415
 
            return -1;
416
 
        if (G_index(file, '/'))
417
 
            strcpy(buf, file);
418
 
        else
419
 
            sprintf(buf, "%s/%s", G_home(), file);
420
 
        if (access(buf, 0) != 0)
421
 
            return 1;
422
 
        sprintf(buf, "** %s already exists. choose another file", file);
423
 
        Beep();
424
 
        Curses_write_window(PROMPT_WINDOW, 2, 1, buf);
425
 
    }
426
 
 
427
 
    return 0;
428
 
}
429
 
 
430
 
static int to_printer(void)
431
 
{
432
 
    FILE *fd;
433
 
 
434
 
    cancel_which();
435
 
    Menu_msg("Sending report to printer ...");
436
 
    Curses_write_window(PROMPT_WINDOW, 1, 1, "Sending report to printer ...");
437
 
    fd = popen("lp", "w");
438
 
    do_report(fd);
439
 
    pclose(fd);
440
 
    return 0;
441
 
}
442
 
 
443
 
static int do_report(FILE * fd)
444
 
{
445
 
    char buf[100];
446
 
    int n;
447
 
    int width;
448
 
 
449
 
    fprintf(fd, "LOCATION: %-20s GROUP: %-20s MAPSET: %s\n\n",
450
 
            G_location(), group.name, G_mapset());
451
 
    fprintf(fd, "%15sAnalysis of control point registration\n\n", "");
452
 
    fprintf(fd, "%s   %s\n", LHEAD1, RHEAD1);
453
 
    fprintf(fd, "%s   %s\n", LHEAD2, RHEAD2);
454
 
 
455
 
    FMT1(buf, 0.0, 0.0, 0.0);
456
 
    width = strlen(buf);
457
 
 
458
 
    for (n = 0; n < group.points.count; n++) {
459
 
        FMT0(buf, n + 1);
460
 
        fprintf(fd, "%s", buf);
461
 
        if (group.equation_stat > 0 && group.points.status[n] > 0) {
462
 
            FMT1(buf, xres[n], yres[n], gnd[n]);
463
 
            fprintf(fd, "%s", buf);
464
 
        }
465
 
        else if (group.points.status[n] > 0)
466
 
            printcentered(fd, "?", width);
467
 
        else
468
 
            printcentered(fd, "not used", width);
469
 
        FMT2(buf,
470
 
             group.points.e1[n],
471
 
             group.points.n1[n], group.points.e2[n], group.points.n2[n]);
472
 
        fprintf(fd, "   %s\n", buf);
473
 
    }
474
 
    fprintf(fd, "\n");
475
 
    if (group.equation_stat < 0)
476
 
        fprintf(fd, "Poorly place control points\n");
477
 
    else if (group.equation_stat == 0)
478
 
        fprintf(fd, "No active control points\n");
479
 
    else
480
 
        fprintf(fd,
481
 
                "Overall rms error: %.2f                %s Transformation\n",
482
 
                rms, order_msg);
483
 
 
484
 
    return 0;
485
 
}
486
 
 
487
 
static int printcentered(FILE * fd, char *buf, int width)
488
 
{
489
 
    int len;
490
 
    int n;
491
 
    int i;
492
 
 
493
 
    len = strlen(buf);
494
 
    n = (width - len) / 2;
495
 
 
496
 
    for (i = 0; i < n; i++)
497
 
        fprintf(fd, " ");
498
 
    fprintf(fd, "%s", buf);
499
 
    i += len;
500
 
    while (i++ < width)
501
 
        fprintf(fd, " ");
502
 
 
503
 
    return 0;
504
 
}
505
 
 
506
 
static int show_point(int n, int true_color)
507
 
{
508
 
    if (!true_color)
509
 
        R_standard_color(ORANGE);
510
 
    else if (group.points.status[n])
511
 
        R_standard_color(GREEN);
512
 
    else
513
 
        R_standard_color(RED);
514
 
 
515
 
    display_one_point(VIEW_MAP1, group.points.e1[n], group.points.n1[n]);
516
 
 
517
 
    return 0;
518
 
}
519
 
 
520
 
static int get_order(void)
521
 
{
522
 
    static int use = 1;
523
 
 
524
 
    static Objects objects[] = {
525
 
        INFO("Select order of transformation->", &use),
526
 
        MENU("1st Order", do_1st, &use),
527
 
        MENU("2nd Order", do_2nd, &use),
528
 
        MENU("3rd Order", do_3rd, &use),
529
 
        {0}
530
 
    };
531
 
 
532
 
    if (Input_pointer(objects) < 0)
533
 
        return -1;
534
 
 
535
 
    return 1;
536
 
 
537
 
}
538
 
 
539
 
int analyze(void)
540
 
{
541
 
    static int use = 1;
542
 
 
543
 
    static Objects objects[] = {
544
 
        MENU("DONE", done, &use),
545
 
        MENU("PRINT", to_printer, &use),
546
 
        MENU("FILE", to_file, &use),
547
 
        MENU("OVERLAY", do_warp, &use),
548
 
        MENU(delete_msg, delete_mark, &use),
549
 
        INFO("Transform->", &use),
550
 
        MENU(order_msg, get_order, &use),
551
 
        INFO(pick_msg, &use),
552
 
        OTHER(pick, &use),
553
 
        {0}
554
 
    };
555
 
 
556
 
    int color;
557
 
    int tsize;
558
 
    int cury;
559
 
    int len;
560
 
    int line;
561
 
    int top, bottom, left, right, width, middle, nums;
562
 
 
563
 
    /* to give user a response of some sort */
564
 
    Menu_msg("Preparing analysis ...");
565
 
 
566
 
    /*
567
 
     * build a popup window at center of the screen.
568
 
     * 35% the height and wide enough to hold the report
569
 
     *
570
 
     */
571
 
 
572
 
    /* height of 1 line, based on NLINES taking up 35% vertical space */
573
 
    height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;
574
 
 
575
 
    /* size of text, 80% of line height */
576
 
    tsize = .8 * height;
577
 
    size = tsize - 2;           /* fudge for computing pixels width of text */
578
 
 
579
 
    /* indent for the text */
580
 
    edge = .1 * height + 1;
581
 
 
582
 
    /* determine the length, in chars, of printed line */
583
 
    FMT0(buf, 0);
584
 
    nums = strlen(buf) * size;
585
 
    FMT1(buf, 0.0, 0.0, 0.0);
586
 
    len = strlen(buf);
587
 
    middle = len * size;
588
 
    FMT2(buf, 0.0, 0.0, 0.0, 0.0);
589
 
    len += strlen(buf);
590
 
 
591
 
    /* width is for max chars plus sidecar for more/less */
592
 
    width = len * size + nums + 2 * height;
593
 
    if ((SCREEN_RIGHT - SCREEN_LEFT) < width)
594
 
        width = SCREEN_RIGHT - SCREEN_LEFT;
595
 
 
596
 
 
597
 
    /* define the window */
598
 
    bottom = VIEW_MENU->top - 1;
599
 
    top = bottom - height * NLINES;
600
 
 
601
 
 
602
 
    left = SCREEN_LEFT;
603
 
    right = left + width;
604
 
    middle += left + nums;
605
 
    nums += left;
606
 
 
607
 
    /* save what is under this area, so it can be restored */
608
 
    R_panel_save(tempfile1, top, bottom + 1, left, right + 1);
609
 
 
610
 
 
611
 
    /* fill it with white */
612
 
    R_standard_color(BACKGROUND);
613
 
    R_box_abs(left, top, right, bottom);
614
 
 
615
 
    right -= 2 * height;        /* reduce it to exclude sidecar */
616
 
 
617
 
    /* print messages in message area */
618
 
    R_text_size(tsize, tsize);
619
 
 
620
 
 
621
 
    /* setup the more/less boxes in the sidecar */
622
 
    R_standard_color(BLACK);
623
 
    less.top = top;
624
 
    less.bottom = top + 2 * height;
625
 
    less.left = right;
626
 
    less.right = right + 2 * height;
627
 
    Outline_box(less.top, less.bottom, less.left, less.right);
628
 
 
629
 
    more.top = bottom - 2 * height;
630
 
    more.bottom = bottom;
631
 
    more.left = right;
632
 
    more.right = right + 2 * height;
633
 
    Outline_box(more.top, more.bottom, more.left, more.right);
634
 
 
635
 
    /*
636
 
     * top two lines are for column labels
637
 
     * last two line is for overall rms error.
638
 
     */
639
 
    nlines = NLINES - 3;
640
 
    first_point = 0;
641
 
 
642
 
    /* allocate predicted values */
643
 
    xres = (double *)G_calloc(group.points.count, sizeof(double));
644
 
    yres = (double *)G_calloc(group.points.count, sizeof(double));
645
 
    gnd = (double *)G_calloc(group.points.count, sizeof(double));
646
 
 
647
 
    /* compute transformation for the first time */
648
 
    compute_transformation();
649
 
 
650
 
    /* put head on the report */
651
 
    cury = top;
652
 
    dotext(LHEAD1, cury, cury + height, left, middle, 0, BLACK);
653
 
    dotext(RHEAD1, cury, cury + height, middle, right - 1, 0, BLACK);
654
 
    cury += height;
655
 
    dotext(LHEAD2, cury, cury + height, left, middle, 0, BLACK);
656
 
    dotext(RHEAD2, cury, cury + height, middle, right - 1, 0, BLACK);
657
 
    cury += height;
658
 
    R_move_abs(left, cury - 1);
659
 
    R_cont_abs(right, cury - 1);
660
 
 
661
 
    /* isolate the sidecar */
662
 
    R_move_abs(right, top);
663
 
    R_cont_abs(right, bottom);
664
 
 
665
 
    /* define report box */
666
 
    report.top = cury;
667
 
    report.left = left;
668
 
    report.right = right;
669
 
 
670
 
    /* lets do it */
671
 
 
672
 
    pager = 1;
673
 
    while (1) {
674
 
        R_text_size(tsize, tsize);
675
 
        line = 0;
676
 
        curp = first_point;
677
 
        cury = top + 2 * height;
678
 
        while (1) {
679
 
            if (line >= nlines || curp >= group.points.count)
680
 
                break;
681
 
            line++;
682
 
 
683
 
            if (!delete_mode)
684
 
                color = BLACK;
685
 
            else
686
 
                color = BLUE;
687
 
 
688
 
            if (group.equation_stat > 0 && group.points.status[curp] > 0) {
689
 
                /* color = BLACK; */
690
 
                FMT1(buf, xres[curp], yres[curp], gnd[curp]);
691
 
                if (curp == xmax || curp == ymax || curp == gmax)
692
 
                    color = RED;
693
 
                dotext(buf, cury, cury + height, nums, middle, 0, color);
694
 
            }
695
 
            else if (group.points.status[curp] > 0)
696
 
                dotext("?", cury, cury + height, nums, middle, 1, color);
697
 
            else
698
 
                dotext("not used", cury, cury + height, nums, middle, 1,
699
 
                       color);
700
 
 
701
 
            if (pager) {
702
 
                FMT0(buf, curp + 1);
703
 
                dotext(buf, cury, cury + height, left, nums, 0, color);
704
 
                FMT2(buf,
705
 
                     group.points.e1[curp],
706
 
                     group.points.n1[curp],
707
 
                     group.points.e2[curp], group.points.n2[curp]);
708
 
                dotext(buf, cury, cury + height, middle, right - 1, 0, color);
709
 
            }
710
 
            cury += height;
711
 
            curp++;
712
 
        }
713
 
        report.bottom = cury;
714
 
        downarrow(&more, curp < group.points.count ? color : BACKGROUND);
715
 
        uparrow(&less, first_point > 0 ? color : BACKGROUND);
716
 
        R_standard_color(BACKGROUND);
717
 
        R_box_abs(left, cury, right - 1, bottom);
718
 
        if (group.equation_stat < 0) {
719
 
 
720
 
            if (group.equation_stat == -1) {
721
 
                color = RED;
722
 
                strcpy(buf, "Poorly placed control points");
723
 
            }
724
 
            else {
725
 
                if (group.equation_stat == -2)
726
 
                    G_fatal_error("NOT ENOUGH MEMORY");
727
 
                else
728
 
                    G_fatal_error("PARAMETER ERROR");
729
 
            }
730
 
 
731
 
        }
732
 
        else if (group.equation_stat == 0) {
733
 
            color = RED;
734
 
            strcpy(buf, "No active control points");
735
 
        }
736
 
        else {
737
 
            color = BLACK;
738
 
            sprintf(buf, "Overall rms error: %.2f", rms);
739
 
        }
740
 
        dotext(buf, bottom - height, bottom, left, right - 1, 0, color);
741
 
        R_standard_color(BLACK);
742
 
        R_move_abs(left, bottom - height);
743
 
        R_cont_abs(right - 1, bottom - height);
744
 
 
745
 
        pager = 0;
746
 
        which = -1;
747
 
        if (Input_pointer(objects) < 0)
748
 
            break;
749
 
        display_points(1);
750
 
    }
751
 
 
752
 
    /* all done. restore what was under the window */
753
 
    right += 2 * height;        /* move it back over the sidecar */
754
 
    R_standard_color(BACKGROUND);
755
 
    R_box_abs(left, top, right, bottom);
756
 
    R_panel_restore(tempfile1);
757
 
    R_panel_delete(tempfile1);
758
 
    R_flush();
759
 
 
760
 
    G_free(xres);
761
 
    G_free(yres);
762
 
    G_free(gnd);
763
 
    I_put_control_points(group.name, &group.points);
764
 
    display_points(1);
765
 
    return 0;                   /* return but don't QUIT */
766
 
}