[GRASS-SVN] r49217 - grass/trunk/lib/sites
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 14 02:57:15 EST 2011
Author: martinl
Date: 2011-11-13 23:57:15 -0800 (Sun, 13 Nov 2011)
New Revision: 49217
Modified:
grass/trunk/lib/sites/sites.c
Log:
siteslib: remove unused functions
modules which are still using siteslib should be updated to use vlib
only v.in.sites is designed to use siteslib (G_oldsites_*)
Modified: grass/trunk/lib/sites/sites.c
===================================================================
--- grass/trunk/lib/sites/sites.c 2011-11-14 07:55:45 UTC (rev 49216)
+++ grass/trunk/lib/sites/sites.c 2011-11-14 07:57:15 UTC (rev 49217)
@@ -1,16 +1,18 @@
+/*!
+ \brief Old sites library
-/*-
- * These functions and definitions support the site format for 5.0
- * (format proposed by Dave Gerdes):
- *
- * easting|northing|[z|[d4|]...][#category_int] [ [@attr_text OR %flt] ... ]
- *
- * to allow multidimensions (everything preceding the last '|') and any
- * number of text or numeric attribute fields.
- *
- * Author: James Darrell McCauley <mccauley at ecn.purdue.edu>
- * 31 Jan 1994
- */
+ These functions and definitions support the site format for 5.0
+ (format proposed by Dave Gerdes):
+
+ <pre>
+ easting|northing|[z|[d4|]...][#category_int] [ [@attr_text OR %flt] ... ]
+ </pre>
+
+ to allow multidimensions (everything preceding the last '|') and any
+ number of text or numeric attribute fields.
+
+ \author James Darrell McCauley <mccauley at ecn.purdue.edu> (31 Jan 1994)
+*/
#include <ctype.h>
#include <string.h>
@@ -23,7 +25,6 @@
#include <grass/vector.h>
#include <grass/glocale.h>
-
#define DQUOTE '"'
#define SPACE ' '
#define BSLASH 92
@@ -31,12 +32,16 @@
#define ispipe(c) (c==PIPE)
#define isnull(c) (c=='\0')
-#define isquote(c) (c==DQUOTE)
-#define isbslash(c) (c==BSLASH)
-static int format_double(double, char *);
+#define FOUND_ALL(s,n,dim,c,d) (((s->cattype != -1 && !n) || \
+ (dim < s->dim_alloc) || \
+ (c < s->str_alloc) || \
+ (d < s->dbl_alloc))?0:1)
+
+
static char *next_att(const char *);
static int cleanse_string(char *);
+static int G__oldsite_get(FILE *, Site *, int);
static int site_att_cmp(const void *pa, const void *pb)
{
@@ -45,13 +50,17 @@
return a->cat - b->cat;
}
+/*!
+ \brief Get site
+
+ \param Map
+ \param s
-/*-
- * Reads ptr and returns 0 on success,
- * -1 on EOF,
- * -2 on other fatal error or insufficient data,
- * 1 on format mismatch (extra data)
- */
+ \return 0 on success
+ \return -1 on EOF
+ \return -2 on other fatal error or insufficient data,
+ \return 1 on format mismatch (extra data)
+*/
int G_site_get(struct Map_info *Map, Site * s)
{
int i, type, cat;
@@ -112,8 +121,14 @@
}
}
+/*!
+ \brief Writes a site to file open on fptr
-/* Writes a site to file open on fptr. */
+ \param Map
+ \param s
+
+ \return
+*/
int G_site_put(struct Map_info *Map, const Site * s)
{
static struct line_pnts *Points = NULL;
@@ -143,15 +158,17 @@
return 0;
}
+/*!
+ \brief Tries to guess the format of a sites list
-/*-
- * Tries to guess the format of a sites list (the dimensionality,
- * the presence/type of a category, and the number of string and decimal
- * attributes) by reading the first record in the file.
- * Reads ptr and returns 0 on success,
- * -1 on EOF,
- * -2 for other error.
- */
+ The dimensionality, the presence/type of a category, and the number
+ of string and decimal attributes) by reading the first record in
+ the file.
+
+ \return 0 on success
+ \return -1 on EOF
+ \return -2 for other error
+*/
int G_site_describe(struct Map_info *Map, int *dims, int *cat, int *strs,
int *dbls)
{
@@ -173,10 +190,9 @@
return 0;
}
-
-/*-
- * Writes site_head struct.
- */
+/*!
+ \brief Writes site_head struct
+*/
int G_site_put_head(struct Map_info *Map, Site_head * head)
{
static char buf[128];
@@ -221,63 +237,6 @@
return 0;
}
-
-/*-
- * Fills in site_head struct.
- */
-int G_site_get_head(struct Map_info *Map, Site_head * head)
-{
- head->name = Vect_get_name(Map);
- head->desc = Vect_get_comment(Map);
- head->form = NULL;
- head->labels = NULL;
- /* head->stime = Vect_get_date(Map); *//* crashes, G_scan_timestamp() needed? */
- head->stime = NULL;
- head->time = NULL;
-
- if (head->stime && strlen(head->stime) > 0) {
- if ((head->time =
- (struct TimeStamp *)G_malloc(sizeof(struct TimeStamp))) == NULL)
- G_fatal_error(_("Memory error in allocating timestamp"));
- if (G_scan_timestamp(head->time, head->stime) < 0) {
- G_warning(datetime_error_msg());
-
- head->time = NULL;
- head->stime = NULL;
- }
- }
-
- return 0;
-}
-
-/*-************************************************************************
- *
- * struct Map_info *
- * G_sites_open_old (name, mapset)
- * opens the existing site list file 'name' in the 'mapset'
- *
- * struct Map_info *
- * G_sites_open_new (name)
- * opens a new site list file 'name' in the current mapset
- *
- * parms
- * char *name map file name
- * char *mapset mapset containing map "name"
- *
- **********************************************************************/
-
-const char *G_find_sites(char *name, const char *mapset)
-{
- return G_find_vector(name, mapset);
-}
-
-
-const char *G_find_sites2(const char *name, const char *mapset)
-{
- return G_find_vector2(name, mapset);
-}
-
-
struct Map_info *G_sites_open_old(const char *name, const char *mapset)
{
struct Map_info *Map;
@@ -436,71 +395,22 @@
return Map;
}
-
-void G_sites_close(struct Map_info *Map)
-{
- int i, j;
-
- if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)
- Vect_build(Map);
-
- Vect_close(Map);
-
- for (i = 0; i < Map->n_site_att; i++) {
- free(Map->site_att[i].dbl);
-
- for (j = 0; j < Map->n_site_str; j++)
- free(Map->site_att[i].str[j]);
-
- free(Map->site_att[i].str);
- }
- free(Map->site_att);
-
- G_free(Map);
-}
-
-
-/*********************************************/
-/* The following functions are obsolete. */
-/* They are retained here only for backwards */
-/* compatability while porting applications */
-
-/*********************************************/
struct Map_info *G_fopen_sites_old(const char *name, const char *mapset)
{
return G_sites_open_old(name, mapset);
}
-
struct Map_info *G_fopen_sites_new(const char *name)
{
return G_sites_open_new(name);
}
+/*!
+ \brief Free memory for a Site struct
-int G_get_site(struct Map_info *fd, double *east, double *north, char **desc)
-{
- /* TODO ? */
- G_fatal_error("G_get_site() not yet updated.");
-
- return -1;
-}
-
-
-int G_put_site(struct Map_info *fd, double east, double north,
- const char *desc)
-{
- /* TODO ? */
- G_fatal_error("G_put_site() not yet updated.");
-
- return 0;
-}
-
-
-/* Functions moved here from lib/gis/sites.c */
-
+ \param s
+*/
void G_site_free_struct(Site * s)
-/* Free memory for a Site struct */
{
if (s->dim_alloc)
G_free(s->dim);
@@ -513,12 +423,15 @@
return;
}
+/*!
+ \brief Allocate memory for a Site struct.
+
+ cattype= -1 (no cat), CELL_TYPE, FCELL_TYPE, or DCELL_TYPE
+
+ \return properly allocated site struct or NULL on error.
+*/
Site *G_site_new_struct(RASTER_MAP_TYPE cattype,
int n_dim, int n_s_att, int n_d_att)
-/* Allocate memory for a Site struct. Returns a properly allocated
- site struct or NULL on error.
- cattype= -1 (no cat), CELL_TYPE, FCELL_TYPE, or DCELL_TYPE
- */
{
int i;
Site *s;
@@ -583,26 +496,23 @@
return s;
}
-#define FOUND_ALL(s,n,dim,c,d) (((s->cattype != -1 && !n) || \
- (dim < s->dim_alloc) || \
- (c < s->str_alloc) || \
- (d < s->dbl_alloc))?0:1)
-
+/*!
+ \brief Writes a site to file open on fptr
+*/
int G_oldsite_get(FILE * fptr, Site * s)
-/* Writes a site to file open on fptr. */
{
return G__oldsite_get(fptr, s, G_projection());
}
+/*!
+ \brief Get site (old version)
+ \return 0 on success,
+ \return -1 on EOF,
+ \return -2 on other fatal error or insufficient data,
+ \return 1 on format mismatch (extra data)
+*/
int G__oldsite_get(FILE * ptr, Site * s, int fmt)
-
-/*-
- * Reads ptr and returns 0 on success,
- * -1 on EOF,
- * -2 on other fatal error or insufficient data,
- * 1 on format mismatch (extra data)
- */
{
char sbuf[MAX_SITE_LEN], *buf, *last, *p1, *p2;
char ebuf[128], nbuf[128];
@@ -735,16 +645,18 @@
return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
}
-int G_oldsite_describe(FILE * ptr, int *dims, int *cat, int *strs, int *dbls)
+/*!
+ \brief Tries to guess the format of a sites list (old version)
-/*-
- * Tries to guess the format of a sites list (the dimensionality,
- * the presence/type of a category, and the number of string and decimal
- * attributes) by reading the first record in the file.
- * Reads ptr and returns 0 on success,
- * -1 on EOF,
- * -2 for other error.
- */
+ The dimensionality, the presence/type of a category, and the number
+ of string and decimal attributes) by reading the first record in the
+ file.
+
+ \return 0 on success,
+ \return -1 on EOF,
+ \return -2 for other error
+*/
+int G_oldsite_describe(FILE * ptr, int *dims, int *cat, int *strs, int *dbls)
{
char sbuf[MAX_SITE_LEN], *buf;
char ebuf[128], nbuf[128];
@@ -753,9 +665,8 @@
float ftmp;
if (G_ftell(ptr) != 0L) {
- fprintf(stderr,
- "\nPROGRAMMER ERROR: G_oldsite_describe() must be called\n");
- fprintf(stderr, " immediately after G_fopen_sites_old()\n");
+ G_warning(_("G_oldsite_describe() must be called "
+ "immediately after G_fopen_sites_old()."));
return -2;
}
@@ -778,7 +689,7 @@
buf[strlen(buf) - 1] = '\0';
if ((err = sscanf(buf, "%[^|]|%[^|]|%*[^\n]", ebuf, nbuf)) < 2) {
- fprintf(stderr, "ERROR: ebuf %s nbuf %s\n", ebuf, nbuf);
+ G_debug(1, "ebuf %s nbuf %s", ebuf, nbuf);
rewind(ptr);
return -2;
}
@@ -885,8 +796,13 @@
return 0;
}
+/*!
+ \brief Test if site is in region
+
+ \return 1 if site is contained within region
+ \return 0 otherwise
+*/
int G_site_in_region(const Site * site, const struct Cell_head *region)
-/* returns 1 if site is contained within region, 0 otherwise */
{
/* northwest corner is in region, southeast corner is not. */
double e_ing;
@@ -900,13 +816,6 @@
return 0;
}
-static int format_double(double value, char *buf)
-{
- sprintf(buf, "%.8f", value);
- G_trim_decimal(buf);
- return 0;
-}
-
int cleanse_string(char *buf)
{
char *stop, *p, *p2;
@@ -956,7 +865,7 @@
return (int)(stop - buf);
}
-static char *next_att(const char *buf)
+char *next_att(const char *buf)
{
while (!isspace(*buf) && !isnull(*buf))
buf++;
@@ -969,46 +878,6 @@
return (char *)buf;
}
-int G_site_c_cmp(const void *a, const void *b)
-/* qsort() comparison function for sorting an array of
- site structures by category. */
-{
- int result = 0; /* integer to be returned */
- double diff = 0;
-
- switch ((*(Site **) a)->cattype) {
- case CELL_TYPE:
- diff = (double)(*(Site **) a)->ccat - (*(Site **) b)->ccat;
- break;
- case FCELL_TYPE:
- diff = (double)(*(Site **) a)->fcat - (*(Site **) b)->fcat;
- break;
- case DCELL_TYPE:
- diff = (double)(*(Site **) a)->dcat - (*(Site **) b)->dcat;
- break;
- }
- if (diff < 0.0)
- result = -1;
- else if (diff > 0.0)
- result = 1;
- return result;
-}
-
-int G_site_d_cmp(const void *a, const void *b)
-/* qsort() comparison function for sorting an array of
- site structures by first decimal attribute. */
-{
- int result = 0; /* integer to be returned */
- double diff;
-
- diff = (*(Site **) a)->dbl_att[0] - (*(Site **) b)->dbl_att[0];
- if (diff < 0.0)
- result = -1;
- else if (diff > 0.0)
- result = 1;
- return result;
-}
-
int G_oldsite_s_cmp(const void *a, const void *b)
/* qsort() comparison function for sorting an array of
site structures by first decimal attribute. */
@@ -1017,256 +886,17 @@
(*(char **)((*(Site **) b)->str_att)));
}
-/*-************************************************************************
- *
- * FILE *
- * G_oldsites_open_old (name, mapset)
- * opens the existing site list file 'name' in the 'mapset'
- *
- * parms
- * char *name map file name
- * char *mapset mapset containing map "name"
- *
- **********************************************************************/
+/*!
+ \brief Open site list (old version)
+ Opens the existing site list file 'name' in the 'mapset'.
+
+ \param name
+ \param mapset mapset (empty for search path)
+
+ \return pointer to FILE
+*/
FILE *G_oldsites_open_old(const char *name, const char *mapset)
{
return G_fopen_old("site_lists", name, mapset);
}
-
-FILE *G_oldsites_open_new(const char *name)
-{
- return G_fopen_new("site_lists", name);
-}
-
-/*********************************************/
-/* The following functions are obsolete. */
-/* They are retained here only for backwards */
-/* compatability while porting applications */
-
-/*********************************************/
-
-char *G_site_format(const Site * s, const char *fs, int id)
-/* sprintf analog to G_site_put with the addition of a field separator fs
- and option of printing site attribute identifiers
- */
-{
- char ebuf[MAX_SITE_STRING], nbuf[MAX_SITE_STRING];
- char xbuf[MAX_SITE_STRING];
- const char *nfs;
- char *buf;
- int fmt, i, j, k;
-
- buf = (char *)G_malloc(MAX_SITE_LEN * sizeof(char));
-
- fmt = G_projection();
-
- G_format_northing(s->north, nbuf, fmt);
- G_format_easting(s->east, ebuf, fmt);
-
- nfs = (char *)((fs == (char *)NULL) ? "|" : fs);
-
- sprintf(buf, "%s%s%s", ebuf, nfs, nbuf);
-
- for (i = 0; i < s->dim_alloc; ++i) {
- format_double(s->dim[i], nbuf);
- sprintf(xbuf, "%s%s", nfs, nbuf);
- strcat(buf, xbuf);
- }
-
- nfs = (fs == NULL) ? " " : fs;
-
- switch (s->cattype) {
- case CELL_TYPE:
- sprintf(xbuf, "%s%s%d ", nfs, ((id == 0) ? "" : "#"), (int)s->ccat);
- strcat(buf, xbuf);
- break;
- case FCELL_TYPE:
- case DCELL_TYPE:
- sprintf(xbuf, "%s%s%g ", nfs, ((id == 0) ? "" : "#"), (float)s->fcat);
- strcat(buf, xbuf);
- break;
- }
-
- for (i = 0; i < s->dbl_alloc; ++i) {
- format_double(s->dbl_att[i], nbuf);
- sprintf(xbuf, "%s%s%s", nfs, ((id == 0) ? "" : "%"), nbuf);
- strcat(buf, xbuf);
- }
-
- for (i = 0; i < s->str_alloc; ++i) {
- if (strlen(s->str_att[i]) != 0) {
- /* escape double quotes */
- j = k = 0;
-
- /* do not uncomment this code because sites file was created
- * as we want. So it's enough to print them out as it is.
- *
- if (strchr (s->str_att[i], DQUOTE) != (char *) NULL)
- {
- while (!isnull(s->str_att[i][j]))
- {
- if (isquote(s->str_att[i][j]))
- {
- xbuf[k++] = BSLASH;
- xbuf[k++] = DQUOTE;
- }
- else
- xbuf[k++] = s->str_att[i][j];
- j++;
- }
- xbuf[k] = (char) NULL;
- }
- else
- */
-
- strcpy(xbuf, s->str_att[i]);
-
- strcpy(s->str_att[i], xbuf);
-
- if (strchr(s->str_att[i], SPACE) != (char *)NULL)
- sprintf(xbuf, "%s%s\"%s\"", nfs, ((id == 0) ? "" : "@"),
- s->str_att[i]);
- else
- sprintf(xbuf, "%s%s%s", nfs, ((id == 0) ? "" : "@"),
- s->str_att[i]);
- strcat(buf, xbuf);
- }
- }
- return buf;
-}
-
-/*******************************************************************************/
-
-/*******************************************************************************/
-
-/*** ACS_MODIFY_BEGIN - sites_attribute management *****************************/
-/*
- These functions are used in visualization/nviz/src/site_attr_commands.c
-
- Functions to obtain fields in order to draw sites with each point having a
- geometric property depending from database values.
- */
-
-/*
- Returns a pointer to the struct site_att in Map_info *ptr and with category cat
- */
-struct site_att *G_sites_get_atts(struct Map_info * Map, int *cat)
-{
- return (struct site_att *) bsearch((void *)cat, (void *)Map->site_att,
- Map->n_site_att, sizeof(struct site_att),
- site_att_cmp);
-}
-
-/*
- Returns field names, types and indexes in double and string Map_info arrays
-
- WARNING: user is responsible to free allocated memory, directly or calling G_sites_free_fields()
- */
-int G_sites_get_fields(struct Map_info *Map, char ***cnames, int **ctypes,
- int **ndx)
-{
- struct field_info *fi;
- int nrows, row, ncols, col, ndbl, nstr, ctype;
-
- const char *name;
- dbDriver *driver;
- dbString stmt;
- dbCursor cursor;
- dbTable *table;
- dbColumn *column;
-
- /*dbValue *value; */
-
- /* warning: we are using "1" as cat field in Vect_get_field because G_sites_open_old
- (in lib/sites/sites.c), that we use here to open sites, does the same and then
- queries the db in the same way we do here.
- Should it be not true in the future, maybe we'll have to change this by choosing
- appropriate fields and multiple categories */
-
- fi = (struct field_info *)Vect_get_field(Map, 1);
-
-
- if (fi == NULL) { /* not attribute table */
- G_debug(1, "No attribute table");
- return -1;
- }
-
- driver = db_start_driver_open_database(fi->driver, fi->database);
- if (driver == NULL)
- G_fatal_error(_("Cannot open database %s by driver %s"), fi->database,
- fi->driver);
-
- db_init_string(&stmt);
- db_set_string(&stmt, "select * from ");
- db_append_string(&stmt, fi->table);
-
- if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
- G_fatal_error(_("Cannot select attributes"));
-
- nrows = db_get_num_rows(&cursor);
- G_debug(1, "%d rows selected from vector attribute table", nrows);
-
- table = db_get_cursor_table(&cursor);
- ncols = db_get_table_number_of_columns(table);
-
- if (ncols <= 0)
- return ncols;
-
- row = 0;
-
- /* Get number of each type */
- ndbl = nstr = 0;
-
- *cnames = (char **)malloc(ncols * sizeof(char *));
- *ctypes = (int *)malloc(ncols * sizeof(int));
- *ndx = (int *)malloc(ncols * sizeof(int));
-
- for (col = 0; col < ncols; col++) {
- column = db_get_table_column(table, col);
- ctype = db_sqltype_to_Ctype(db_get_column_sqltype(column));
-
- name = db_get_column_name(column);
-
- *(*cnames + col) = (char *)malloc(strlen(name) + 1);
- strcpy(*(*cnames + col), db_get_column_name(column));
-
- /* ctypes is 'c' for cat, 'd' for double, 's' for string */
- if (strcmp(name, fi->key) == 0) {
- *(*ctypes + col) = 'c';
- *(*ndx + col) = -1;
- }
- else {
- switch (ctype) {
- case DB_C_TYPE_INT:
- case DB_C_TYPE_DOUBLE:
- *(*ctypes + col) = 'd';
- *(*ndx + col) = ndbl;
- ndbl++;
- break;
- case DB_C_TYPE_STRING:
- case DB_C_TYPE_DATETIME:
- *(*ctypes + col) = 's';
- *(*ndx + col) = nstr;
- nstr++;
- break;
- }
- }
- }
-
- db_close_database_shutdown_driver(driver);
- return ncols;
-}
-
-
-/* Frees fields allocated with G_sites_get_fields */
-void G_sites_free_fields(int ncols, char **cnames, int *ctypes, int *ndx)
-{
- for (; ncols > 0; ncols--)
- free(*(cnames + ncols - 1));
- free(cnames);
- free(ctypes);
- free(ndx);
-}
-
-/*** ACS_MODIFY_END - sites_attribute management *******************************/
More information about the grass-commit
mailing list