source: git/src/diffpos.c @ bd283cf6

RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereowalls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since bd283cf6 was 73a8a94, checked in by Olly Betts <olly@…>, 26 years ago

fettled layout

git-svn-id: file:///home/survex-svn/survex/trunk@31 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/* > diffpos.c */
2
3/* (Originally quick and dirty) program to compare two SURVEX .pos files */
4/* Copyright (C) 1994,1996,1998 Olly Betts */
5
6/*
71994.04.16 Written
81994.11.22 Now displays names of stations added/deleted at end of .pos file
9           Now displays and skips lines which it can't parse (eg headers)
10           Negative thresholds allowed (to force a "full" compare)
11           Syntax expanded
121996.04.04 fixed Borland C warning
131996.05.06 fixed STRING() macro to correct Syntax: message
141998.06.09 fettled layout
15*/
16
17/* size of line buffer */
18#define BUFLEN 256
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <math.h>
24
25#define sqrd(X) ((X)*(X))
26
27/* macro to just convert argument to a string */
28#define STRING(X) _STRING(X)
29#define _STRING(X) #X
30
31/* very small value for comparing floating point numbers with */
32/* (ought to use a real epsilon value) */
33#define EPSILON 0.00001
34
35/* default threshold is 1cm */
36#define DFLT_MAX_THRESHOLD 0.01
37
38static void diff_pos(FILE *fh1, FILE *fh2, double threshold);
39static int read_line(FILE *fh, double *px, double *py, double *pz, char *id);
40
41int main( int argc, char *argv[] ) {
42   double threshold = DFLT_MAX_THRESHOLD;
43   char *fnm1, *fnm2;
44   FILE *fh1, *fh2;
45   if (argc != 3) {
46      char *p;
47      if (argc == 4)
48         threshold = strtod(argv[3], &p);
49      if (argc != 4 || *p) {
50         /* complain if not 4 args, or threshold didn't parse cleanly */
51         printf("Syntax: %s <pos file> <pos file> [<threshold>]\n", argv[0]);
52         printf(" where <threshold> is the max. permitted change along "
53                "any axis in metres\n"
54                " (default <threshold> is "STRING(DFLT_MAX_THRESHOLD)"m)\n");
55         exit(1);
56      }
57   }
58   fnm1 = argv[1];
59   fnm2 = argv[2];
60   fh1 = fopen(fnm1, "rb");
61   if (!fh1) {
62      printf("Can't open file '%s'\n", fnm1);
63      exit(1);
64   }
65   fh2 = fopen(fnm2, "rb");
66   if (!fh2) {
67      printf("Can't open file '%s'\n", fnm2);
68      exit(1);
69   }
70   diff_pos(fh1, fh2, threshold);
71   return 0;
72}
73
74static void diff_pos( FILE *fh1, FILE *fh2, double threshold ) {
75   double x1, y1, z1, x2, y2, z2;
76   int cmp;
77   char id1[BUFLEN], id2[BUFLEN];
78   int fRead1 = 1, fRead2 = 1;
79   while (!feof(fh1) && !feof(fh2)) {
80      if (fRead1) {
81         if (!read_line(fh1, &x1, &y1, &z1, id1)) continue;
82         fRead1 = 0;
83      }
84      if (fRead2) {
85         if (!read_line(fh2, &x2, &y2, &z2, id2)) continue;
86         fRead2 = 0;
87      }
88      cmp = strcmp(id1, id2);
89      if (cmp == 0) {
90         if (fabs(x1 - x2) - threshold > EPSILON
91             || fabs(y1 - y2) - threshold > EPSILON
92             || fabs(z1 - z2) - threshold > EPSILON) {
93            printf("Moved by (%3.2f,%3.2f,%3.2f): %s\n", x1 - x2, y1 - y2,
94                   z1 - z2, id1);
95         }
96         fRead1 = fRead2 = 1;
97      } else {
98         if (cmp < 0) {
99            printf("Deleted: %s\n", id1);
100            fRead1 = 1;
101         } else {
102            printf("Added: %s\n", id2);
103            fRead2 = 1;
104         }
105      }
106   }
107   while (!feof(fh1) && read_line(fh1, &x1, &y1, &z1, id1))
108      printf("Deleted: %s (at end of file)\n", id1);
109   while (!feof(fh2) && read_line(fh2, &x2, &y2, &z2, id2))
110      printf("Added: %s (at end of file)\n", id2);
111}
112
113static int read_line(FILE *fh, double *px, double *py, double *pz,
114                     char *id) {
115   char buf[BUFLEN];
116   if (!fgets(buf, BUFLEN, fh)) return 0;
117   if (sscanf(buf, "(%lf,%lf,%lf )%s", px, py, pz, id) < 4) {
118      printf("Ignoring line: %s\n", buf);
119      return 0;
120   }
121   return 1;
122}
Note: See TracBrowser for help on using the repository browser.