00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include "gis.h"
00025 #include "glocale.h"
00026 #include "readsites.h"
00027
00028 int G_readsites (FILE *fdsite, int all, int verbose, int field,
00029 struct Cell_head *window, Z **xyz)
00030
00031
00032 {
00033 int i, strs, dims,map_type,dbls,allocated=1000;
00034 Site *s;
00035
00036 G_sleep_on_error (0);
00037
00038 field -= 1;
00039
00040 if (verbose)
00041 fprintf (stderr, _("Reading sites list ... "));
00042
00043
00044 if (G_site_describe (fdsite, &dims, &map_type, &strs, &dbls)!=0)
00045 G_fatal_error(_("failed to guess format"));
00046 s = G_site_new_struct (map_type, dims, strs, dbls);
00047
00048 if(field >= dbls){
00049 G_fatal_error(_("decimal field %i not present in sites file"), field + 1);
00050 }
00051
00052 if (dbls==0)
00053 {
00054 fprintf(stderr,"\n");
00055 G_warning(_("I'm finding records that do not have a floating point attributes (fields prefixed with '%')."));
00056 }
00057
00058
00059 (*xyz) = (Z *) G_malloc (allocated * sizeof (Z));
00060 if ((*xyz)==NULL) G_fatal_error(_("cannot allocate memory"));
00061
00062 i = 0;
00063 while (G_site_get (fdsite, s) == 0)
00064 {
00065 if (i == allocated)
00066 {
00067 allocated+=1000;
00068 (*xyz) = (Z *) G_realloc ((*xyz), allocated * sizeof (Z));
00069 if ((*xyz)==NULL) G_fatal_error(_("cannot allocate memory"));
00070 }
00071 if (all || (s->east >= window->west && s->east <= window->east &&
00072 s->north <= window->north && s->north >= window->south))
00073 {
00074 (*xyz)[i].z=s->dbl_att[field];
00075 (*xyz)[i].x=s->east;
00076 (*xyz)[i++].y=s->north;
00077 }
00078 }
00079
00080 fclose (fdsite);
00081 G_sleep_on_error (1);
00082 if (verbose)
00083 G_percent (1, 1, 1);
00084 return i;
00085 }