errorHandling.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /****************************************************************************
  2. *
  3. * MODULE: r3.out.vtk
  4. *
  5. * AUTHOR(S): Original author
  6. * Soeren Gebbert soerengebbert at gmx de
  7. * 27 Feb 2006 Berlin
  8. * PURPOSE: Converts 3D raster maps (G3D) into the VTK-Ascii format
  9. *
  10. * COPYRIGHT: (C) 2005 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <grass/gis.h>
  21. #include <grass/raster.h>
  22. #include <grass/raster3d.h>
  23. #include <grass/glocale.h>
  24. #include "globalDefs.h"
  25. #include "errorHandling.h"
  26. /* prototypes ************************************************************* */
  27. int close_input_raster3d_map(void *map);
  28. /* ************************************************************************* */
  29. /* Error handling ********************************************************** */
  30. /* ************************************************************************* */
  31. void fatal_error(char *errorMsg, input_maps * in)
  32. {
  33. G_warning("%s\n", errorMsg);
  34. /*close all open maps and free memory */
  35. release_input_maps_struct(in);
  36. G3d_fatalError("Break because of errors.");
  37. }
  38. /* ************************************************************************* */
  39. /* Close the raster input map ********************************************** */
  40. /* ************************************************************************* */
  41. int CloseInputRasterMap(int fd)
  42. {
  43. if (fd != -1)
  44. Rast_close(fd);
  45. return 0;
  46. }
  47. /* ************************************************************************* */
  48. /* Close the raster g3d input map ****************************************** */
  49. /* ************************************************************************* */
  50. int close_input_raster3d_map(void *map)
  51. {
  52. if (map != NULL) {
  53. if (!G3d_closeCell(map)) {
  54. G_warning(_("unable to close input 3d raster map"));
  55. return 1;
  56. }
  57. }
  58. map = NULL;
  59. return 0;
  60. }
  61. /* ************************************************************************* */
  62. /* Close alls open raster and 3d raster maps and free memory ********************* */
  63. /* ************************************************************************* */
  64. void release_input_maps_struct(input_maps * in)
  65. {
  66. int error = 0; /*0 == true, 1 = false */
  67. int i;
  68. error += close_input_raster3d_map(in->map);
  69. error += close_input_raster3d_map(in->map_r);
  70. error += close_input_raster3d_map(in->map_g);
  71. error += close_input_raster3d_map(in->map_b);
  72. error += close_input_raster3d_map(in->map_x);
  73. error += close_input_raster3d_map(in->map_y);
  74. error += close_input_raster3d_map(in->map_z);
  75. error += CloseInputRasterMap(in->top);
  76. error += CloseInputRasterMap(in->bottom);
  77. for (i = 0; i < in->numelevmaps; i++) {
  78. if (in->elevmaps && in->elevmaps[i])
  79. error += CloseInputRasterMap(in->elevmaps[i]);
  80. }
  81. if (in->elevmaps)
  82. free(in->elevmaps);
  83. free(in);
  84. if (error > 0)
  85. G3d_fatalError("Error while closing the input maps");
  86. return;
  87. }