site.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*-
  2. * easting|northing|[z|[d4|]...][#category] [ [@attr_text OR %flt] ... ]
  3. *
  4. * to allow multidimensions (everything preceding the last '|') and any
  5. * number of text or numeric attribute fields.
  6. */
  7. #include <grass/raster.h>
  8. #define MAX_SITE_STRING 1024
  9. #define MAX_SITE_LEN 4096
  10. typedef struct
  11. {
  12. double east, north;
  13. double *dim;
  14. int dim_alloc;
  15. RASTER_MAP_TYPE cattype;
  16. CELL ccat;
  17. FCELL fcat;
  18. DCELL dcat;
  19. int str_alloc;
  20. char **str_att;
  21. int dbl_alloc;
  22. double *dbl_att;
  23. } Site;
  24. typedef struct
  25. {
  26. const char *name, *desc, *form, *labels, *stime;
  27. struct TimeStamp *time;
  28. } Site_head;
  29. /* ========================================================================== *
  30. * G_readsites_xyz(): New implementation of the readsites() library *
  31. * function limited generating an xyz array SITE_XYZ. *
  32. * ========================================================================== *
  33. * Copyright (c) 2000 Eric G. Miller <egm2@jps.net> *
  34. * -------------------------------------------------------------------------- *
  35. * This program is free software; you can redistribute it and/or modify *
  36. * it under the terms of the GNU General Public License as published by *
  37. * the Free Software Foundation; either version 2 of the License, or *
  38. * (at your option) any later version. *
  39. * *
  40. * This program is distributed in the hope that it will be useful, *
  41. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  42. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  43. * GNU General Public License for more details. *
  44. * *
  45. * You should have received a copy of the GNU General Public License *
  46. * along with this program; if not, write to the Free Software *
  47. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
  48. * -------------------------------------------------------------------------- *
  49. */
  50. /* Some defines for which column type to use */
  51. #define SITE_COL_NUL 0
  52. #define SITE_COL_DIM 1
  53. #define SITE_COL_DBL 2
  54. #define SITE_COL_STR 3
  55. /* The XYZ site struct. Note the use of a union for the cat value is
  56. * different than the Site struct.
  57. */
  58. typedef struct
  59. {
  60. double x, y, z;
  61. RASTER_MAP_TYPE cattype;
  62. union
  63. {
  64. double d;
  65. float f;
  66. int c;
  67. } cat;
  68. } SITE_XYZ;
  69. /* Allocate 'num' SITE_XYZ structs. Returns NULL on failure */
  70. SITE_XYZ *G_alloc_site_xyz(size_t);
  71. /* Free the array of SITE_XYZ struct */
  72. void G_free_site_xyz(SITE_XYZ *);
  73. /* G_readsites_xyz: Reads a sites file converting to a site struct of xyz
  74. * values and the cat value. The Z value can come from one of the
  75. * n-dimensions, a double attribute, or a string attribute converted to a
  76. * double with strtod(). The 'size' must not be greater than the number
  77. * of elements in the SITE_XYZ array, or bad things will happen. The number
  78. * of records read is returned or EOF on end of file. NOTE: EOF won't be
  79. * returned unless no records are read and the EOF bit is set. It's safe
  80. * to assume that if the number of records read is less than the size of
  81. * the array, that there aren't any more records.
  82. */
  83. int G_readsites_xyz(FILE *, /* The FILE stream to the sites file */
  84. int, /* Attribute type: SITE_COL_DIM, etc... */
  85. int, /* The field index (1 based) for the attribute */
  86. int, /* Size of the array */
  87. struct Cell_head *, /* Respect region if not NULL */
  88. SITE_XYZ * xyz /* The site array of size 'size' */
  89. );
  90. #include <grass/P_site.h>