GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
raster_metadata.c
Go to the documentation of this file.
1 /* raster_metadata.c
2  *
3  * PURPOSE: functions to read and write raster "units" and "vertical datum"
4  * meta-data info
5  *
6  * Copyright (C) 2007 by Hamish Bowman, and the GRASS Development Team
7  * Author(s): Hamish Bowman, Dunedin, New Zealand
8  *
9  * This program is free software under the GNU General Public
10  * License (>=v2). Read the file COPYING that comes with GRASS
11  * for details.
12  */
13 #include <stdio.h>
14 #include <string.h>
15 #include <grass/gis.h>
16 #include <grass/glocale.h>
17 
18 
30 int G_read_raster_units(const char *name, const char *mapset, char *str)
31 {
32  return G__raster_misc_read_line("units", name, mapset, str);
33 }
34 
35 
46 int G_write_raster_units(const char *name, const char *str)
47 {
48  return G__raster_misc_write_line("units", name, str);
49 }
50 
51 
63 int G_read_raster_vdatum(const char *name, const char *mapset, char *str)
64 {
65  return G__raster_misc_read_line("vertical_datum", name, mapset, str);
66 }
67 
68 
79 int G_write_raster_vdatum(const char *name, const char *str)
80 {
81  return G__raster_misc_write_line("vertical_datum", name, str);
82 }
83 
84 
85 
98 int G__raster_misc_read_line(const char *elem, const char *name,
99  const char *mapset, char *str)
100 {
101  FILE *fd;
102  char buff[GNAME_MAX];
103 
104  buff[0] = '\0';
105 
106  if (G_find_file2_misc("cell_misc", elem, name, mapset) == NULL)
107  return -1;
108 
109  fd = G_fopen_old_misc("cell_misc", elem, name, mapset);
110  if (!fd) {
111  G_warning(_("Can't read %s for [%s in %s]"), elem, name, mapset);
112  return -1;
113  }
114  if (G_getl2(buff, sizeof(buff) - 1, fd) == 0) {
115  /* file is empty */
116  strcpy(str, "");
117  return fclose(fd);
118  }
119 
120  strcpy(str, buff);
121 
122  return fclose(fd);
123 }
124 
125 
138 int G__raster_misc_write_line(const char *elem, const char *name,
139  const char *str)
140 {
141  FILE *fd;
142 
143  fd = G_fopen_new_misc("cell_misc", elem, name);
144  if (fd == NULL) {
145  G_warning(_("Can't create %s metadata file for [%s in %s]"),
146  elem, name, G_mapset());
147  return -1;
148  }
149 
150  fprintf(fd, "%s", str);
151 
152  return fclose(fd);
153 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
FILE * fd
Definition: g3dcolor.c:368
string name
Definition: render.py:1314
char * G_find_file2_misc(const char *dir, const char *element, const char *name, const char *mapset)
Definition: find_file.c:196
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
Definition: open_misc.c:200
int G_read_raster_units(const char *name, const char *mapset, char *str)
Get a raster map&#39;s units metadata string.
int G__raster_misc_write_line(const char *elem, const char *name, const char *str)
Write a line to a raster map metadata file.
char buff[1024]
Definition: g3dcats.c:89
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
int G_write_raster_units(const char *name, const char *str)
Write a string to a raster map&#39;s units metadata file.
int G_read_raster_vdatum(const char *name, const char *mapset, char *str)
Get a raster map&#39;s vertical datum metadata string.
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
fclose(fd)
FILE * G_fopen_new_misc(const char *dir, const char *element, const char *name)
open a new database file
Definition: open_misc.c:172
int G_write_raster_vdatum(const char *name, const char *str)
Write a string into a raster&#39;s vertical datum metadata file.
int G__raster_misc_read_line(const char *elem, const char *name, const char *mapset, char *str)
Read the first line of a file in cell_misc/.