Fix message references for inches and feet
[survex.git] / src / imgtest.c
blobaf3e69debb7e703a3172125c9b7b7d9cbe3cedde
1 /* imgtest.c */
2 /* Test img in unhosted mode */
3 /* Copyright (C) 2014,2020 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
24 #include "img.h"
26 int
27 main(int argc, char **argv)
29 char *fnm;
30 char *survey;
31 img *pimg;
32 unsigned long c_stations = 0;
33 unsigned long c_legs = 0;
35 if (argc < 2 || argc > 3) {
36 fprintf(stderr, "Syntax: %s 3DFILE [SURVEY]\n", argv[0]);
37 return 1;
40 fnm = argv[1];
41 survey = argv[2];
43 if (survey) {
44 pimg = img_open_survey(fnm, survey);
45 } else {
46 pimg = img_open(fnm);
48 if (!pimg) {
49 fprintf(stderr, "%s: Failed to open '%s' (error code %d)\n",
50 argv[0], fnm, (int)img_error());
51 return 1;
54 printf("Title: \"%s\"\n", pimg->title);
55 printf("Date: \"%s\"\n", pimg->datestamp);
56 printf("Format-Version: %d\n", pimg->version);
57 printf("Extended-Elevation: %s\n",
58 pimg->is_extended_elevation ? "yes" : "no");
59 while (1) {
60 img_point pt;
61 int code = img_read_item(pimg, &pt);
62 if (code == img_STOP) break;
63 switch (code) {
64 case img_LINE:
65 c_legs++;
66 break;
67 case img_LABEL:
68 c_stations++;
69 break;
70 case img_BAD:
71 img_close(pimg);
72 fprintf(stderr, "%s: img_read_item failed (error code %d)\n",
73 argv[0], (int)img_error());
74 return 1;
78 printf("Stations: %lu\nLegs: %lu\n", c_stations, c_legs);
80 img_close(pimg);
82 return 0;