Add missing trailing dot in sentences
[viking/guyou.git] / test / test_metatile.c
blob0cc750a4756c4a932c6285c677827174aafb9c1a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
5 * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30 #include <fcntl.h>
32 #include <metatile.h>
34 int main ( int argc, char *argv[] )
36 const int tile_max = METATILE_MAX_SIZE;
37 char err_msg[PATH_MAX];
38 char *buf;
39 int len;
40 int compressed;
42 // Could extend to get values from the command-line.
43 int x = 4051;
44 int y = 2753;
45 int z = 13;
46 //char dir[] = "/var/lib/mod_tile/default";
47 char dir[] = "metatile_example";
48 // Example defaults to a metatile that was pre generated using mod_tile
49 // Equates to 'metatile_example/13/0/0/250/220/0.meta'
50 // which is Brownsea Island, Dorset, UK (50.69N, 1.96W)
52 buf = malloc(tile_max);
53 if (!buf) {
54 return 1;
57 err_msg[0] = 0;
59 if ( argc > 1 )
60 len = metatile_read(argv[1], x, y, z, buf, tile_max, &compressed, err_msg);
61 else
62 len = metatile_read(dir, x, y, z, buf, tile_max, &compressed, err_msg);
64 if (len > 0) {
65 // Do something with buf
66 // Just dump to a file
67 FILE *fp;
68 if (compressed)
69 fp = fopen( "tilefrommeta.gz" , "w" );
70 else
71 fp = fopen( "tilefrommeta.png" , "w" );
73 if ( fp ) {
74 fwrite(buf, 1 , len, fp);
75 fclose(fp);
77 else
78 fprintf(stderr, "Failed to open file because: %s\n", strerror(errno));
80 free(buf);
81 return 0;
83 else
84 fprintf(stderr, "FAILED: %s\n", err_msg);
86 free(buf);
87 return 3;