1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include "hecmw_vis_mem_util.h"
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "hecmw_util.h"
11 
HECMW_vis_memory_exit(char * var)12 void HECMW_vis_memory_exit(char *var) {
13   fprintf(stderr,
14           "#### HEC-MW-VIS-E0001:There is no enough memory allocated for "
15           "variable %s\n",
16           var);
17   HECMW_finalize();
18   exit(0);
19 }
20 
HECMW_vis_print_exit(char * var)21 void HECMW_vis_print_exit(char *var) {
22   fprintf(stderr, "%s\n", var);
23   HECMW_finalize();
24   exit(0);
25 }
26 
mfree(void * pointer)27 void mfree(void *pointer) {
28   HECMW_free(pointer);
29   pointer = NULL;
30 }
31 
alloc_verts(int num)32 Point *alloc_verts(int num) {
33   int i;
34   Point *verts;
35 
36   if ((verts = (Point *)HECMW_calloc(num, sizeof(Point))) == NULL) {
37     fprintf(stderr, "There is not enough memory, alloc_verts\n");
38     return NULL;
39   }
40 
41   for (i = 0; i < (num - 1); i++) {
42     (verts + i)->nextpoint = (verts + i + 1);
43     (verts + i)->ident     = 0;
44   }
45   (verts + num - 1)->ident     = 0;
46   (verts + num - 1)->nextpoint = NULL;
47 
48   return verts;
49 }
50 
alloc_polygons(int num)51 Polygon *alloc_polygons(int num) {
52   int i;
53   Polygon *polygons;
54 
55   if ((polygons = (Polygon *)HECMW_calloc(num, sizeof(Polygon))) == NULL) {
56     fprintf(stderr, "There is not enough memory, alloc_polygons\n");
57     return NULL;
58   }
59 
60   for (i = 0; i < (num - 1); i++) {
61     (polygons + i)->nextpolygon = (polygons + i + 1);
62     (polygons + i)->plist       = NULL;
63   }
64   (polygons + num - 1)->nextpolygon = NULL;
65   (polygons + num - 1)->plist       = NULL;
66 
67   return polygons;
68 }
69