file_in.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "watershed.h"
  5. int ar_file_in(char *file_name, OUTPUT * output)
  6. {
  7. FILE *ar_file;
  8. int bas_num, down_bas, i1, i2, bas_alloc;
  9. char s1[7], s2[5], s3[3];
  10. double northing, easting, str_slope, str_length;
  11. if ((ar_file = fopen(file_name, "r")) == NULL) {
  12. G_fatal_error(_("unable to open ARMSED file"));
  13. }
  14. output->num_basins = 0;
  15. bas_alloc = INCR;
  16. output->basin_facts = (B_FACTS *) G_malloc(INCR * sizeof(B_FACTS));
  17. while (!feof(ar_file)) {
  18. fscanf(ar_file, "%d %s %s %d %s %d %d %lf %lf %lf %lf",
  19. &bas_num, s1, s2, &down_bas, s3, &i1, &i2,
  20. &easting, &northing, &str_slope, &str_length);
  21. if (output->num_basins >= bas_alloc) {
  22. bas_alloc += INCR;
  23. output->basin_facts =
  24. (B_FACTS *) G_realloc(output->basin_facts,
  25. bas_alloc * sizeof(B_FACTS));
  26. }
  27. output->basin_facts[output->num_basins].num_cells = 0;
  28. output->basin_facts[output->num_basins].str_length = str_length;
  29. output->basin_facts[output->num_basins].str_slope = str_slope;
  30. output->basin_facts[output->num_basins].easting = easting;
  31. output->basin_facts[output->num_basins].northing = northing;
  32. output->basin_facts[output->num_basins].down_basin = down_bas / 2 - 1;
  33. output->basin_facts[output->num_basins].valid = 1;
  34. output->num_basins++;
  35. }
  36. fclose(ar_file);
  37. return 0;
  38. }