1 /*
2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
3 LLNL-CODE-425250.
4 All rights reserved.
5
6 This file is part of Silo. For details, see silo.llnl.gov.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the disclaimer below.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the disclaimer (as noted
16 below) in the documentation and/or other materials provided with
17 the distribution.
18 * Neither the name of the LLNS/LLNL nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE
26 LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35 This work was produced at Lawrence Livermore National Laboratory under
36 Contract No. DE-AC52-07NA27344 with the DOE.
37
38 Neither the United States Government nor Lawrence Livermore National
39 Security, LLC nor any of their employees, makes any warranty, express
40 or implied, or assumes any liability or responsibility for the
41 accuracy, completeness, or usefulness of any information, apparatus,
42 product, or process disclosed, or represents that its use would not
43 infringe privately-owned rights.
44
45 Any reference herein to any specific commercial products, process, or
46 services by trade name, trademark, manufacturer or otherwise does not
47 necessarily constitute or imply its endorsement, recommendation, or
48 favoring by the United States Government or Lawrence Livermore
49 National Security, LLC. The views and opinions of authors expressed
50 herein do not necessarily state or reflect those of the United States
51 Government or Lawrence Livermore National Security, LLC, and shall not
52 be used for advertising or product endorsement purposes.
53 */
54
55 #include "silo_private.h"
56
57 /*======================================================================
58 *||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 *======================================================================
60 * File alloc.c
61 *
62 * Purpose
63 *
64 * Source file for allocating and freeing DB data structures.
65 *
66 * Author
67 *
68 * Jeff Long
69 *
70 * Routine Summary
71 *
72 * mmesh = DBAllocMultimesh (num)<< Multi-block mesh >>
73 * mvar = DBAllocMultivar (num) << Multi-block var >>
74 * qmesh = DBAllocQuadmesh () << Quad mesh >>
75 * umesh = DBAllocUcdmesh () << UCD mesh >>
76 * pmesh = DBAllocPointmesh () << Point mesh >>
77 * qvar = DBAllocQuadvar () << Quad var >>
78 * uvar = DBAllocUcdvar () << UCD var >>
79 * var = V_Alloc () << Mesh var >>
80 * elist = DBAllocEdgelist () << Edgelist >>
81 * flist = DBAllocFacelist () << Facelist >>
82 * zlist = DBAllocZonelist () << Zonelist >>
83 * mat = DBAllocMaterial() << Material >>
84 * species = DBAllocMatspecies() << Matspecies >>
85 * array = DBAllocCompoundarray()<< Compoundarray >>
86 *
87 * Also, corresponding routines for 'free'.
88 *
89 *======================================================================
90 *||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 *=====================================================================*/
92
93 /*
94 * Modification History
95 *
96 * Robb Matzke, Tue Oct 25 08:13:04 PDT 1994
97 * Added routines for Compound Arrays.
98 *
99 * Robb Matzke, Thu Nov 3 15:33:48 PST 1994
100 * Restructured for device independence.
101 *
102 * Al Leibee, Tue Jul 26 08:44:01 PDT 1994
103 * Replaced composition by species.
104 *
105 */
106
107 /*----------------------------------------------------------------------
108 * Function DBAllocDefvars
109 *
110 * Purpose
111 *
112 * Allocate and initialize a defvars object.
113 *
114 * Programmer:
115 * Mark C. Miller
116 * August 8, 2005
117 *
118 *----------------------------------------------------------------------*/
119 PUBLIC DBdefvars *
DBAllocDefvars(int num)120 DBAllocDefvars(int num)
121 {
122 DBdefvars *defv;
123
124 API_BEGIN("DBAllocDefvars", DBdefvars *, NULL) {
125 if (NULL == (defv = ALLOC(DBdefvars)))
126 API_ERROR(NULL, E_NOMEM);
127
128 /* Initialize all memory to zero. */
129 memset(defv, 0, sizeof(DBdefvars));
130
131 defv->ndefs = num;
132
133 /* Allocate sub-arrays of requested lengths */
134 if (num > 0) {
135 defv->names = ALLOC_N(char *, num);
136 defv->types = ALLOC_N(int, num);
137 defv->defns = ALLOC_N(char *, num);
138
139 if (!defv->names || !defv->types || !defv->defns)
140 {
141 DBFreeDefvars(defv);
142 API_ERROR(NULL, E_NOMEM);
143 }
144 }
145 }
146 API_END;
147
148 return (defv);
149 }
150
151 /*----------------------------------------------------------------------
152 * Function DBAllocMultimesh
153 *
154 * Purpose
155 *
156 * Allocate and initialize a multi-block mesh object.
157 *
158 * Modified
159 *
160 * Robb Matzke, Tue Nov 8 07:12:09 PST 1994
161 * Added error mechanism.
162 *
163 * Eric Brugger, Wed Jul 2 13:19:07 PDT 1997
164 * Added code to allocate the dirids array.
165 *
166 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
167 * Added code to initialize the block and group origins to 1.
168 *
169 * Mark C. Miller, Wed Jul 27 19:04:00 PDT 2005
170 * Initialized nblocks member
171 *
172 *----------------------------------------------------------------------*/
173 PUBLIC DBmultimesh *
DBAllocMultimesh(int num)174 DBAllocMultimesh(int num)
175 {
176 DBmultimesh *msh;
177
178 API_BEGIN("DBAllocMultimesh", DBmultimesh *, NULL) {
179 if (NULL == (msh = ALLOC(DBmultimesh)))
180 API_ERROR(NULL, E_NOMEM);
181
182 /* Initialize all memory to zero. */
183 memset(msh, 0, sizeof(DBmultimesh));
184
185 msh->nblocks = num;
186 msh->blockorigin = 1;
187 msh->grouporigin = 1;
188
189 /* Allocate sub-arrays of requested lengths */
190 if (num > 0) {
191 msh->meshids = ALLOC_N(int, num);
192 msh->meshnames = ALLOC_N(char *, num);
193 msh->meshtypes = ALLOC_N(int, num);
194 msh->dirids = ALLOC_N(int, num);
195
196 if (!msh->meshids || !msh->meshtypes || !msh->meshnames ||
197 !msh->dirids) {
198 DBFreeMultimesh(msh);
199 API_ERROR(NULL, E_NOMEM);
200 }
201 }
202 }
203 API_END;
204
205 return (msh);
206 }
207
208 /*----------------------------------------------------------------------
209 * Function DBAllocMultimeshadj
210 *
211 * Purpose
212 *
213 * Allocate and initialize a multi-block mesh adjacency object.
214 *
215 * Modified
216 *
217 * Robb Matzke, Tue Nov 8 07:12:09 PST 1994
218 * Added error mechanism.
219 *
220 * Eric Brugger, Wed Jul 2 13:19:07 PDT 1997
221 * Added code to allocate the dirids array.
222 *
223 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
224 * Added code to initialize the block and group origins to 1.
225 *
226 * Mark C. Miller, Wed Jul 27 19:04:00 PDT 2005
227 * Initialized nblocks member
228 *
229 *----------------------------------------------------------------------*/
230 PUBLIC DBmultimeshadj *
DBAllocMultimeshadj(int num)231 DBAllocMultimeshadj(int num)
232 {
233 DBmultimeshadj *mshadj;
234
235 API_BEGIN("DBAllocMultimeshadj", DBmultimeshadj *, NULL) {
236 if (NULL == (mshadj = ALLOC(DBmultimeshadj)))
237 API_ERROR(NULL, E_NOMEM);
238
239 /* Initialize all memory to zero. */
240 memset(mshadj, 0, sizeof(DBmultimeshadj));
241
242 mshadj->nblocks = num;
243 mshadj->blockorigin = 1;
244
245 /* Allocate sub-arrays of requested lengths */
246 if (num > 0) {
247 mshadj->meshtypes = ALLOC_N(int, num);
248 mshadj->nneighbors = ALLOC_N(int, num);
249
250 if (!mshadj->meshtypes || !mshadj->nneighbors) {
251 DBFreeMultimeshadj(mshadj);
252 API_ERROR(NULL, E_NOMEM);
253 }
254 }
255 }
256 API_END;
257
258 return (mshadj);
259 }
260 /*----------------------------------------------------------------------
261 * Function DBAllocMultivar
262 *
263 * Purpose
264 *
265 * Allocate and initialize a multi-block mesh object.
266 *
267 * Modified
268 *
269 * Robb Matzke, Tue Nov 8 07:13:34 PST 1994
270 * Added error mechanism
271 *
272 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
273 * Added code to initialize the block and group origins to 1.
274 *
275 * Mark C. Miller, Wed Jul 27 19:04:00 PDT 2005
276 * Initialized nvars member
277 *----------------------------------------------------------------------*/
278 PUBLIC DBmultivar *
DBAllocMultivar(int num)279 DBAllocMultivar(int num)
280 {
281 DBmultivar *var;
282
283 API_BEGIN("DBAllocMultivar", DBmultivar *, NULL) {
284 if (NULL == (var = ALLOC(DBmultivar)))
285 API_ERROR(NULL, E_NOMEM);
286
287 /* Initialize all memory to zero. */
288 memset(var, 0, sizeof(DBmultivar));
289
290 var->nvars = num;
291 var->blockorigin = 1;
292 var->grouporigin = 1;
293
294 /* Allocate sub-arrays of requested lengths */
295 if (num > 0) {
296 var->varnames = ALLOC_N(char *, num);
297 var->vartypes = ALLOC_N(int, num);
298
299 if (!var->varnames || !var->vartypes) {
300 DBFreeMultivar(var);
301 API_ERROR(NULL, E_NOMEM);
302 }
303 }
304 }
305 API_END;
306
307 return (var);
308 }
309
310 /*----------------------------------------------------------------------
311 * Function DBAllocMultimat
312 *
313 * Purpose
314 *
315 * Allocate and initialize a multi-material object.
316 *
317 * Modified
318 *
319 * Robb Matzke, Tue Nov 8 07:13:34 PST 1994
320 * Added error mechanism
321 *
322 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
323 * Added code to initialize the block and group origins to 1.
324 *
325 * Mark C. Miller, Wed Jul 27 19:04:00 PDT 2005
326 * Initialized nmats member
327 *----------------------------------------------------------------------*/
328 PUBLIC DBmultimat *
DBAllocMultimat(int num)329 DBAllocMultimat(int num)
330 {
331 DBmultimat *mat;
332
333 API_BEGIN("DBAllocMultimat", DBmultimat *, NULL) {
334 if (NULL == (mat = ALLOC(DBmultimat)))
335 API_ERROR(NULL, E_NOMEM);
336
337 /* Initialize all memory to zero. */
338 memset(mat, 0, sizeof(DBmultimat));
339
340 mat->nmats = num;
341 mat->blockorigin = 1;
342 mat->grouporigin = 1;
343
344 /* Allocate sub-arrays of requested lengths */
345 if (num > 0) {
346 mat->matnames = ALLOC_N(char *, num);
347
348 if (!mat->matnames) {
349 DBFreeMultimat(mat);
350 API_ERROR(NULL, E_NOMEM);
351 }
352 }
353 }
354 API_END;
355
356 return (mat);
357 }
358
359 /*----------------------------------------------------------------------
360 * Function DBAllocMultimatspecies
361 *
362 * Programmer
363 * Jeremy Meredith, Sept 18 1998
364 *
365 * Purpose
366 *
367 * Allocate and initialize a multi-species object.
368 *
369 * Modified
370 *
371 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
372 * Added code to initialize the block and group origins to 1.
373 *
374 * Mark C. Miller, Wed Jul 27 19:04:00 PDT 2005
375 * Initialized nspec member
376 *----------------------------------------------------------------------*/
377 PUBLIC DBmultimatspecies *
DBAllocMultimatspecies(int num)378 DBAllocMultimatspecies(int num)
379 {
380 DBmultimatspecies *spec;
381
382 API_BEGIN("DBAllocMultimatspecies", DBmultimatspecies *, NULL) {
383 if (NULL == (spec = ALLOC(DBmultimatspecies)))
384 API_ERROR(NULL, E_NOMEM);
385
386 /* Initialize all memory to zero. */
387 memset(spec, 0, sizeof(DBmultimatspecies));
388
389 spec->nspec = num;
390 spec->blockorigin = 1;
391 spec->grouporigin = 1;
392
393 /* Allocate sub-arrays of requested lengths */
394 if (num > 0) {
395 spec->specnames = ALLOC_N(char *, num);
396
397 if (!spec->specnames) {
398 DBFreeMultimatspecies(spec);
399 API_ERROR(NULL, E_NOMEM);
400 }
401 }
402 }
403 API_END;
404
405 return (spec);
406 }
407
408 /*----------------------------------------------------------------------
409 * Function DBFreeDefvars
410 *
411 * Purpose
412 *
413 * Free the space used by the given defvars object. Also frees
414 * items pointed to by the structure.
415 *
416 *----------------------------------------------------------------------*/
417 PUBLIC void
DBFreeDefvars(DBdefvars * defv)418 DBFreeDefvars(DBdefvars *defv)
419 {
420 int i;
421
422 if (defv == NULL)
423 return;
424
425 for (i = 0; i < defv->ndefs; i++) {
426 FREE(defv->names[i]);
427 FREE(defv->defns[i]);
428 }
429
430 FREE(defv->names);
431 FREE(defv->types);
432 FREE(defv->defns);
433 FREE(defv->guihides);
434 FREE(defv);
435 }
436
437 /*----------------------------------------------------------------------
438 * Function DBFreeMultimesh
439 *
440 * Purpose
441 *
442 * Free the space used by the given multi mesh object. Also frees
443 * items pointed to by the structure.
444 *
445 * Modificaitions:
446 * Eric Brugger, Wed Jul 2 13:19:07 PDT 1997
447 * I added code to free msh->meshnames to close a memory leak.
448 *
449 * Mark C. Miller, Wed Jul 14 20:26:09 PDT 2010
450 * Added support for namescheme options on multi-block objects.
451 * When these options are in use, the ...names member can be null.
452 * So, modified to only delete the ...names member if it is non-null.
453 *----------------------------------------------------------------------*/
454 PUBLIC void
DBFreeMultimesh(DBmultimesh * msh)455 DBFreeMultimesh(DBmultimesh *msh)
456 {
457 int i;
458
459 if (msh == NULL)
460 return;
461
462 if (msh->meshnames_alloc)
463 {
464 FREE(msh->meshnames_alloc);
465 }
466 else if (msh->meshnames)
467 {
468 for (i = 0; i < msh->nblocks; i++) {
469 FREE(msh->meshnames[i]);
470 }
471 }
472
473 if (msh->groupnames)
474 {
475 for(i=0;i<msh->lgroupings;i++)
476 FREE(msh->groupnames[i]);
477 FREE(msh->groupnames);
478 }
479 if (msh->groupings)
480 FREE(msh->groupings);
481
482 FREE(msh->extents);
483 FREE(msh->zonecounts);
484 FREE(msh->has_external_zones);
485 FREE(msh->meshids);
486 FREE(msh->meshnames);
487 FREE(msh->meshtypes);
488 FREE(msh->dirids);
489 FREE(msh->mrgtree_name);
490 FREE(msh->file_ns);
491 FREE(msh->block_ns);
492 FREE(msh->empty_list);
493 FREE(msh);
494 }
495
496 /*----------------------------------------------------------------------
497 * Function DBFreeMultimeshadj
498 *
499 * Purpose
500 *
501 * Free the space used by the given multi mesh adjacency object. Also
502 * frees items pointed to by the structure.
503 *
504 *----------------------------------------------------------------------*/
505 PUBLIC void
DBFreeMultimeshadj(DBmultimeshadj * mshadj)506 DBFreeMultimeshadj(DBmultimeshadj *mshadj)
507 {
508 int i;
509 int lneighbors = 0;
510
511 if (mshadj == NULL)
512 return;
513
514 /* compute how long various arrays are */
515 for (i = 0; i < mshadj->nblocks; i++)
516 lneighbors += mshadj->nneighbors[i];
517
518 if (mshadj->nodelists) {
519 for (i = 0; i < lneighbors; i++)
520 FREE(mshadj->nodelists[i]);
521 FREE(mshadj->nodelists);
522 }
523
524 if (mshadj->zonelists) {
525 for (i = 0; i < lneighbors; i++)
526 FREE(mshadj->zonelists[i]);
527 FREE(mshadj->zonelists);
528 }
529
530 FREE(mshadj->meshtypes);
531 FREE(mshadj->nneighbors);
532 FREE(mshadj->neighbors);
533 FREE(mshadj->back);
534 FREE(mshadj->lnodelists);
535 FREE(mshadj->lzonelists);
536 FREE(mshadj);
537 }
538
539 /*----------------------------------------------------------------------
540 * Function DBFreeMultivar
541 *
542 * Purpose
543 *
544 * Free the space used by the given multi variable object. Also frees
545 * items pointed to by the structure.
546 *
547 * Modificaitions:
548 * Eric Brugger, Wed Jul 2 13:19:07 PDT 1997
549 * I added code to free mv->varnames to close a memory leak.
550 *
551 * Mark C. Miller, Thu Oct 29 15:55:34 PDT 2009
552 * Added free for mmesh_name
553 *
554 * Mark C. Miller, Wed Jul 14 20:26:09 PDT 2010
555 * Added support for namescheme options on multi-block objects.
556 * When these options are in use, the ...names member can be null.
557 * So, modified to only delete the ...names member if it is non-null.
558 *----------------------------------------------------------------------*/
559 PUBLIC void
DBFreeMultivar(DBmultivar * mv)560 DBFreeMultivar (DBmultivar *mv)
561 {
562 int i;
563
564 if (mv == NULL)
565 return;
566
567 if (mv->varnames_alloc)
568 {
569 FREE(mv->varnames_alloc);
570 }
571 else if (mv->varnames)
572 {
573 for (i = 0; i < mv->nvars; i++) {
574 FREE(mv->varnames[i]);
575 }
576 }
577
578 if (mv->region_pnames)
579 {
580 for (i = 0; mv->region_pnames[i]; i++)
581 free(mv->region_pnames[i]);
582 free(mv->region_pnames);
583 }
584
585 FREE(mv->varnames);
586 FREE(mv->vartypes);
587 FREE(mv->mmesh_name);
588 FREE(mv->extents);
589 FREE(mv->file_ns);
590 FREE(mv->block_ns);
591 FREE(mv->empty_list);
592 FREE(mv);
593 }
594
595 /*----------------------------------------------------------------------
596 * Function DBFreeMultimat
597 *
598 * Purpose
599 *
600 * Free the space used by the given multi material object. Also frees
601 * items pointed to by the structure.
602 *
603 * Modifications
604 * Sean Ahern, Fri Jun 21 10:56:49 PDT 1996
605 * Freed a pointer we were forgetting about.
606 *
607 * Mark C. Miller, Mon Aug 7 17:03:51 PDT 2006
608 * Added code to deal with material_names, matcolors and other
609 * stuff that has been added in past several years
610 *
611 * Mark C. Miller, Thu Oct 29 15:55:34 PDT 2009
612 * Added free for mmesh_name
613 *
614 * Mark C. Miller, Wed Jul 14 20:26:09 PDT 2010
615 * Added support for namescheme options on multi-block objects.
616 * When these options are in use, the ...names member can be null.
617 * So, modified to only delete the ...names member if it is non-null.
618 *----------------------------------------------------------------------*/
619 PUBLIC void
DBFreeMultimat(DBmultimat * mat)620 DBFreeMultimat (DBmultimat *mat)
621 {
622 int i;
623
624 if (mat == NULL)
625 return;
626
627 if (mat->matnames_alloc)
628 {
629 FREE(mat->matnames_alloc);
630 }
631 else if (mat->matnames)
632 {
633 for (i = 0; i < mat->nmats; i++) {
634 FREE(mat->matnames[i]);
635 }
636 }
637 FREE(mat->matnames);
638 if (mat->material_names)
639 {
640 for (i = 0; i < mat->nmatnos; i++)
641 FREE(mat->material_names[i]);
642 FREE(mat->material_names);
643 }
644 if (mat->matcolors)
645 {
646 for (i = 0; i < mat->nmatnos; i++)
647 FREE(mat->matcolors[i]);
648 FREE(mat->matcolors);
649 }
650
651 FREE(mat->mixlens);
652 FREE(mat->matcounts);
653 FREE(mat->matlists);
654 FREE(mat->matnos);
655 FREE(mat->mmesh_name);
656 FREE(mat->file_ns);
657 FREE(mat->block_ns);
658 FREE(mat->empty_list);
659 FREE(mat);
660 }
661
662 /*----------------------------------------------------------------------
663 * Function DBFreeMultimatspecies
664 *
665 * Programmer
666 * Jeremy Meredith, Sept 18 1998
667 *
668 * Purpose
669 *
670 * Free the space used by the given multi material species object.
671 * Also frees items pointed to by the structure.
672 *
673 * Modifications
674 *
675 * Mark C. Miller, Mon Aug 7 17:03:51 PDT 2006
676 * Added code to free nmatspec
677 *
678 * Mark C. Miller, Tue Sep 8 15:40:51 PDT 2009
679 * Added names and colors for species.
680 *
681 * Mark C. Miller, Wed Jul 14 20:26:09 PDT 2010
682 * Added support for namescheme options on multi-block objects.
683 * When these options are in use, the ...names member can be null.
684 * So, modified to only delete the ...names member if it is non-null.
685 *----------------------------------------------------------------------*/
686 PUBLIC void
DBFreeMultimatspecies(DBmultimatspecies * spec)687 DBFreeMultimatspecies (DBmultimatspecies *spec)
688 {
689 int i, j, k;
690
691 if (spec == NULL)
692 return;
693
694 if (spec->species_names)
695 {
696 for(i=0,k=0;i<spec->nmat;i++)
697 {
698 for(j=0;j<spec->nmatspec[i];j++,k++)
699 FREE(spec->species_names[k]);
700 }
701 FREE(spec->species_names);
702 }
703
704 if (spec->speccolors)
705 {
706 for(i=0,k=0;i<spec->nmat;i++)
707 {
708 for(j=0;j<spec->nmatspec[i];j++,k++)
709 FREE(spec->speccolors[k]);
710 }
711 FREE(spec->speccolors);
712 }
713
714 if (spec->specnames_alloc)
715 {
716 FREE(spec->specnames_alloc);
717 }
718 else if (spec->specnames)
719 {
720 for (i = 0; i < spec->nspec; i++) {
721 FREE(spec->specnames[i]);
722 }
723 }
724 FREE(spec->specnames);
725
726 FREE(spec->nmatspec);
727 FREE(spec->file_ns);
728 FREE(spec->block_ns);
729 FREE(spec->empty_list);
730 FREE(spec);
731 }
732
733 /*----------------------------------------------------------------------
734 * Function DBAllocCsgmesh
735 *
736 * Purpose
737 *
738 * Allocate and initialize a CSG mesh object.
739 *
740 * Programmer: Mark C. Miller
741 * Wed Jul 27 14:22:03 PDT 2005
742 *----------------------------------------------------------------------*/
743 PUBLIC DBcsgmesh *
DBAllocCsgmesh(void)744 DBAllocCsgmesh(void)
745 {
746 DBcsgmesh *msh;
747
748 API_BEGIN("DBAllocCsgmesh", DBcsgmesh *, NULL) {
749 if (NULL == (msh = ALLOC(DBcsgmesh)))
750 API_ERROR(NULL, E_NOMEM);
751
752 /* Initialize all memory to zero. */
753 memset(msh, 0, sizeof(DBcsgmesh));
754
755 msh->block_no = -1;
756 msh->group_no = -1;
757 }
758 API_END;
759
760 return (msh);
761 }
762
763 /*----------------------------------------------------------------------
764 * Function DBFreeCsgmesh
765 *
766 * Purpose
767 *
768 * Free the space used by the given CSG mesh object. Also frees
769 * items pointed to by the structure.
770 *
771 * Programmer: Mark C. Miller
772 * Wed Jul 27 14:22:03 PDT 2005
773 *
774 *----------------------------------------------------------------------*/
775 PUBLIC void
DBFreeCsgmesh(DBcsgmesh * msh)776 DBFreeCsgmesh(DBcsgmesh *msh)
777 {
778 int i;
779
780 if (msh == NULL)
781 return;
782
783 for (i = 0; i < msh->ndims; i++) {
784 FREE(msh->labels[i]);
785 FREE(msh->units[i]);
786 }
787
788 if (msh->bndnames && msh->nbounds)
789 {
790 for (i = 0; i < msh->nbounds; i++)
791 FREE(msh->bndnames[i]);
792 }
793
794 FREE(msh->typeflags);
795 FREE(msh->bndids);
796 FREE(msh->coeffs);
797 FREE(msh->coeffidx);
798 FREE(msh->bndnames);
799 FREE(msh->name);
800 FREE(msh->mrgtree_name);
801
802 DBFreeCSGZonelist(msh->zones);
803
804 FREE(msh);
805 }
806
807 PUBLIC int
DBIsEmptyCsgmesh(DBcsgmesh const * msh)808 DBIsEmptyCsgmesh(DBcsgmesh const *msh)
809 {
810 if (msh && msh->nbounds!=0) return 0;
811 return 1;
812 }
813
814 /*----------------------------------------------------------------------
815 * Function DBAllocQuadmesh
816 *
817 * Purpose
818 *
819 * Allocate and initialize a quad mesh object.
820 *
821 * Modified
822 *
823 * Robb Matzke, Tue Nov 8 07:14:44 PST 1994
824 * Added error mechanism
825 *
826 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
827 * Added code to initialize the block and group numbers to -1.
828 *
829 *----------------------------------------------------------------------*/
830 PUBLIC DBquadmesh *
DBAllocQuadmesh(void)831 DBAllocQuadmesh(void)
832 {
833 DBquadmesh *msh;
834
835 API_BEGIN("DBAllocQuadmesh", DBquadmesh *, NULL) {
836 if (NULL == (msh = ALLOC(DBquadmesh)))
837 API_ERROR(NULL, E_NOMEM);
838
839 /* Initialize all memory to zero. */
840 memset(msh, 0, sizeof(DBquadmesh));
841
842 msh->block_no = -1;
843 msh->group_no = -1;
844 }
845 API_END;
846
847 return (msh);
848 }
849
850 /*----------------------------------------------------------------------
851 * Function DBFreeQuadmesh
852 *
853 * Purpose
854 *
855 * Free the space used by the given quad mesh object. Also frees
856 * items pointed to by the structure.
857 *
858 *----------------------------------------------------------------------*/
859 PUBLIC void
DBFreeQuadmesh(DBquadmesh * msh)860 DBFreeQuadmesh(DBquadmesh *msh)
861 {
862 int i;
863
864 if (msh == NULL)
865 return;
866
867 for (i = 0; i < 3; i++) {
868 FREE(msh->coords[i]);
869 FREE(msh->labels[i]);
870 FREE(msh->units[i]);
871 }
872
873 FREE(msh->name);
874 FREE(msh->mrgtree_name);
875 FREE(msh);
876 }
877
878 PUBLIC int
DBIsEmptyQuadmesh(DBquadmesh const * msh)879 DBIsEmptyQuadmesh(DBquadmesh const *msh)
880 {
881 int i, is_empty = 1;
882
883 for (i = 0; msh && i < msh->ndims; i++)
884 {
885 if (msh->dims[i] > 0)
886 {
887 is_empty = 0;
888 break;
889 }
890 }
891 return is_empty;
892 }
893
894 /*----------------------------------------------------------------------
895 * Function DBAllocPointmesh
896 *
897 * Purpose
898 *
899 * Allocate and initialize a point mesh object.
900 *
901 * Modified
902 *
903 * Robb Matzke, Tue Nov 8 07:16:44 PST 1994
904 * Added error mechanism
905 *
906 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
907 * Added code to initialize the block and group numbers to -1.
908 *
909 *----------------------------------------------------------------------*/
910 PUBLIC DBpointmesh *
DBAllocPointmesh(void)911 DBAllocPointmesh(void)
912 {
913 DBpointmesh *msh;
914
915 API_BEGIN("DBAllocPointmesh", DBpointmesh *, NULL) {
916 if (NULL == (msh = ALLOC(DBpointmesh)))
917 API_ERROR(NULL, E_NOMEM);
918
919 /* Initialize all memory to zero. */
920 memset(msh, 0, sizeof(DBpointmesh));
921
922 msh->block_no = -1;
923 msh->group_no = -1;
924 }
925 API_END;
926
927 return (msh);
928 }
929
930 /*----------------------------------------------------------------------
931 * Function DBFreePointmesh
932 *
933 * Purpose
934 *
935 * Free the space used by the given point mesh object. Also frees
936 * items pointed to by the structure.
937 *
938 *----------------------------------------------------------------------*/
939 PUBLIC void
DBFreePointmesh(DBpointmesh * msh)940 DBFreePointmesh(DBpointmesh *msh)
941 {
942 int i;
943
944 if (msh == NULL)
945 return;
946
947 for (i = 0; i < 3; i++) {
948 FREE(msh->coords[i]);
949 FREE(msh->labels[i]);
950 FREE(msh->units[i]);
951 }
952
953 FREE(msh->gnodeno);
954 FREE(msh->name);
955 FREE(msh->title);
956 FREE(msh->mrgtree_name);
957 FREE(msh);
958 }
959
960 PUBLIC int
DBIsEmptyPointmesh(DBpointmesh const * msh)961 DBIsEmptyPointmesh(DBpointmesh const *msh)
962 {
963 if (msh && msh->nels!=0) return 0;
964 return 1;
965 }
966
967 /*----------------------------------------------------------------------
968 * Function DBAllocMeshvar
969 *
970 * Purpose
971 *
972 * Allocate and initialize a generic mesh variable object.
973 *
974 * Modified
975 *
976 * Robb Matzke, Tue Nov 8 07:18:20 PST 1994
977 * Added error mechanism
978 *----------------------------------------------------------------------*/
979 PUBLIC DBmeshvar *
DBAllocMeshvar(void)980 DBAllocMeshvar(void)
981 {
982 DBmeshvar *var;
983
984 API_BEGIN("DBAllocMeshvar", DBmeshvar *, NULL) {
985 if (NULL == (var = ALLOC(DBmeshvar)))
986 API_ERROR(NULL, E_NOMEM);
987
988 /* Initialize all memory to zero. */
989 memset(var, 0, sizeof(DBmeshvar));
990 }
991 API_END;
992
993 return (var);
994 }
995
996 /*----------------------------------------------------------------------
997 * Function DBFreeMeshvar
998 *
999 * Purpose
1000 *
1001 * Free the space used by the given mesh var object. Also frees
1002 * items pointed to by the structure.
1003 *
1004 *
1005 * Modifications:
1006 * Sean Ahern, Fri Aug 3 12:53:04 PDT 2001
1007 * Fixed a problem with freeing a partially-retried object.
1008 *----------------------------------------------------------------------*/
1009 PUBLIC void
DBFreeMeshvar(DBmeshvar * var)1010 DBFreeMeshvar(DBmeshvar *var)
1011 {
1012 int i;
1013
1014 if (var == NULL)
1015 return;
1016
1017 if (var->vals != NULL)
1018 {
1019 for (i = 0; i < var->nvals; i++) {
1020 FREE(var->vals[i]);
1021 }
1022 }
1023
1024 FREE(var->vals);
1025 FREE(var->name);
1026 FREE(var->units);
1027 FREE(var->label);
1028 FREE(var->meshname);
1029 FREE(var);
1030 }
1031
1032 PUBLIC int
DBIsEmptyMeshvar(DBmeshvar const * var)1033 DBIsEmptyMeshvar(DBmeshvar const *var)
1034 {
1035 if (var && var->nels!=0) return 0;
1036 return 1;
1037 }
1038
1039 PUBLIC DBpointvar *
DBAllocPointvar()1040 DBAllocPointvar()
1041 {
1042 return DBAllocMeshvar();
1043 }
1044
1045 PUBLIC void
DBFreePointvar(DBpointvar * var)1046 DBFreePointvar(DBpointvar *var)
1047 {
1048 DBFreeMeshvar(var);
1049 }
1050
1051 PUBLIC int
DBIsEmptyPointvar(DBpointvar const * pv)1052 DBIsEmptyPointvar(DBpointvar const *pv)
1053 {
1054 return DBIsEmptyMeshvar(pv);
1055 }
1056
1057 /*----------------------------------------------------------------------
1058 * Function DBAllocUcdmesh
1059 *
1060 * Purpose
1061 *
1062 * Allocate and initialize a ucd mesh object.
1063 *
1064 * Modified
1065 *
1066 * Robb Matzke, Tue Nov 8 07:19:21 PST 1994
1067 * Added error mechanism.
1068 *
1069 * Jeremy Meredith, Fri May 21 09:58:34 PDT 1999
1070 * Added code to initialize the block and group numbers to -1.
1071 *
1072 *----------------------------------------------------------------------*/
1073 PUBLIC DBucdmesh *
DBAllocUcdmesh(void)1074 DBAllocUcdmesh(void)
1075 {
1076 DBucdmesh *msh;
1077
1078 API_BEGIN("DBAllocUcdmesh", DBucdmesh *, NULL) {
1079 if (NULL == (msh = ALLOC(DBucdmesh)))
1080 API_ERROR(NULL, E_NOMEM);
1081
1082 /* Initialize all memory to zero. */
1083 memset(msh, 0, sizeof(DBucdmesh));
1084
1085 msh->block_no = -1;
1086 msh->group_no = -1;
1087 }
1088 API_END;
1089
1090 return (msh);
1091 }
1092
1093 /*----------------------------------------------------------------------
1094 * Function DBFreeUcdmesh
1095 *
1096 * Purpose
1097 *
1098 * Free the space used by the given ucd mesh object. Also frees
1099 * items pointed to by the structure.
1100 *
1101 * Modifications:
1102 *
1103 * Lisa J. Roberts, Tue Mar 30 17:10:11 PST 1999
1104 * I added code to free the new nodeno array.
1105 *
1106 * Mark C. Miller, Wed Jul 28 11:09:42 PDT 2004
1107 * Added missing call to free optional gnodeno array
1108 * Added call to free new, optional, polyhedral zonelist
1109 *
1110 *----------------------------------------------------------------------*/
1111 PUBLIC void
DBFreeUcdmesh(DBucdmesh * msh)1112 DBFreeUcdmesh(DBucdmesh *msh)
1113 {
1114 int i;
1115
1116 if (msh == NULL)
1117 return;
1118
1119 for (i = 0; i < 3; i++) {
1120 FREE(msh->coords[i]);
1121 FREE(msh->labels[i]);
1122 FREE(msh->units[i]);
1123 }
1124
1125 DBFreeFacelist(msh->faces);
1126 DBFreeZonelist(msh->zones);
1127 DBFreeEdgelist(msh->edges);
1128 DBFreePHZonelist(msh->phzones);
1129
1130 FREE(msh->nodeno);
1131 FREE(msh->gnodeno);
1132 FREE(msh->name);
1133 FREE(msh->mrgtree_name);
1134 FREE(msh);
1135 }
1136
1137 PUBLIC int
DBIsEmptyUcdmesh(DBucdmesh const * msh)1138 DBIsEmptyUcdmesh(DBucdmesh const *msh)
1139 {
1140 if (msh && msh->nnodes!=0) return 0;
1141 return 1;
1142 }
1143
1144 /*----------------------------------------------------------------------
1145 * Function DBAllocCsgvar
1146 *
1147 * Purpose
1148 *
1149 * Allocate and initialize a CSG var object.
1150 *
1151 * Programmer: Mark C. Miller
1152 * Wed Jul 27 14:22:03 PDT 2005
1153 *----------------------------------------------------------------------*/
1154 PUBLIC DBcsgvar *
DBAllocCsgvar(void)1155 DBAllocCsgvar(void)
1156 {
1157 DBcsgvar *csgvar;
1158
1159 API_BEGIN("DBAllocCsgvar", DBcsgvar *, NULL) {
1160 if (NULL == (csgvar = ALLOC(DBcsgvar)))
1161 API_ERROR(NULL, E_NOMEM);
1162
1163 /* Initialize all memory to zero. */
1164 memset(csgvar, 0, sizeof(DBcsgvar));
1165 }
1166 API_END;
1167
1168 return (csgvar);
1169 }
1170
1171 /*----------------------------------------------------------------------
1172 * Function DBFreeCsgvar
1173 *
1174 * Purpose
1175 *
1176 * Free the space used by the given CSG var object.
1177 *
1178 * Programmer: Mark C. Miller
1179 * Wed Jul 27 14:22:03 PDT 2005
1180 *----------------------------------------------------------------------*/
1181 PUBLIC void
DBFreeCsgvar(DBcsgvar * var)1182 DBFreeCsgvar(DBcsgvar *var)
1183 {
1184 int i;
1185
1186 if (var == NULL)
1187 return;
1188
1189 if (var->vals != NULL) {
1190 for (i = 0; i < var->nvals; i++) {
1191 FREE(var->vals[i]);
1192 }
1193 }
1194
1195 FREE(var->vals);
1196 FREE(var->name);
1197 FREE(var->label);
1198 FREE(var->units);
1199 FREE(var->meshname);
1200 FREE(var);
1201 }
1202
1203 PUBLIC int
DBIsEmptyCsgvar(DBcsgvar const * var)1204 DBIsEmptyCsgvar(DBcsgvar const *var)
1205 {
1206 if (var && var->nels!=0) return 0;
1207 return 1;
1208 }
1209
1210 /*----------------------------------------------------------------------
1211 * Function DBAllocQuadvar
1212 *
1213 * Purpose
1214 *
1215 * Allocate and initialize a quad var object.
1216 *
1217 * Modified
1218 *
1219 * Robb Matzke, Tue Nov 8 07:20:11 PST 1994
1220 * Added error mechanism
1221 *----------------------------------------------------------------------*/
1222 PUBLIC DBquadvar *
DBAllocQuadvar(void)1223 DBAllocQuadvar(void)
1224 {
1225 DBquadvar *qvar;
1226
1227 API_BEGIN("DBAllocQuadvar", DBquadvar *, NULL) {
1228 if (NULL == (qvar = ALLOC(DBquadvar)))
1229 API_ERROR(NULL, E_NOMEM);
1230
1231 /* Initialize all memory to zero. */
1232 memset(qvar, 0, sizeof(DBquadvar));
1233 }
1234 API_END;
1235
1236 return (qvar);
1237 }
1238
1239 /*----------------------------------------------------------------------
1240 * Function DBResetQuadvar
1241 *
1242 * Purpose
1243 *
1244 * Reset a quad variable.
1245 *
1246 *----------------------------------------------------------------------*/
1247 PUBLIC void
DBResetQuadvar(DBquadvar * qv)1248 DBResetQuadvar(DBquadvar *qv)
1249 {
1250
1251 memset(qv, 0, sizeof(DBquadvar));
1252 }
1253
1254 /*----------------------------------------------------------------------
1255 * Function DBFreeQuadvar
1256 *
1257 * Purpose
1258 *
1259 * Free the space used by the given quad mesh object. Also frees
1260 * items pointed to by the structure.
1261 *
1262 * Modifications:
1263 * Sean Ahern, Thu Jul 9 16:18:51 PDT 1998
1264 * Freed the mixvals, fixing a memory leak.
1265 *
1266 * Sean Ahern, Thu Aug 2 12:51:36 PDT 2001
1267 * Fixed the case where the variable might only be partially filled,
1268 * due to the read mask.
1269 *
1270 *----------------------------------------------------------------------*/
1271 PUBLIC void
DBFreeQuadvar(DBquadvar * var)1272 DBFreeQuadvar(DBquadvar *var)
1273 {
1274 int i;
1275
1276 if (var == NULL)
1277 return;
1278
1279 if (var->vals != NULL) {
1280 for (i = 0; i < var->nvals; i++) {
1281 FREE(var->vals[i]);
1282 if (var->mixvals != NULL)
1283 FREE(var->mixvals[i]);
1284 }
1285 }
1286
1287 FREE(var->vals);
1288 FREE(var->mixvals);
1289 FREE(var->name);
1290 FREE(var->label);
1291 FREE(var->units);
1292 FREE(var->meshname);
1293 FREE(var);
1294 }
1295
1296 PUBLIC int
DBIsEmptyQuadvar(DBquadvar const * var)1297 DBIsEmptyQuadvar(DBquadvar const *var)
1298 {
1299 int i, is_empty = 1;
1300
1301 for (i = 0; var && i < var->ndims; i++)
1302 {
1303 if (var->dims[i] > 0)
1304 {
1305 is_empty = 0;
1306 break;
1307 }
1308 }
1309 return is_empty;
1310 }
1311
1312 /*----------------------------------------------------------------------
1313 * Function DBAllocUcdvar
1314 *
1315 * Purpose
1316 *
1317 * Allocate and initialize a ucd variable object.
1318 *
1319 * Modified
1320 *
1321 * Robb Matzke, Tue Nov 8 07:21:11 PST 1994
1322 * Added error mechanism
1323 *----------------------------------------------------------------------*/
1324 PUBLIC DBucdvar *
DBAllocUcdvar(void)1325 DBAllocUcdvar(void)
1326 {
1327 DBucdvar *uvar;
1328
1329 API_BEGIN("DBAllocUcdvar", DBucdvar *, NULL) {
1330 if (NULL == (uvar = ALLOC(DBucdvar)))
1331 API_ERROR(NULL, E_NOMEM);
1332
1333 /* Initialize all memory to zero. */
1334 DBResetUcdvar(uvar);
1335 }
1336 API_END;
1337
1338 return (uvar);
1339 }
1340
1341 /*----------------------------------------------------------------------
1342 * Function DBResetUcdvar
1343 *
1344 * Purpose
1345 *
1346 * Reset a ucd variable.
1347 *
1348 *----------------------------------------------------------------------*/
1349 PUBLIC void
DBResetUcdvar(DBucdvar * uv)1350 DBResetUcdvar(DBucdvar *uv)
1351 {
1352
1353 memset(uv, 0, sizeof(DBucdvar));
1354 }
1355
1356 /*----------------------------------------------------------------------
1357 * Function DBFreeUcdvar
1358 *
1359 * Purpose
1360 *
1361 * Free the space used by the given ucd var object. Also frees
1362 * items pointed to by the structure.
1363 *
1364 * Modifications
1365 * Eric Brugger, Wed Sep 1 11:35:24 PDT 1999
1366 * Freed the mixvals, fixing a memory leak.
1367 *
1368 * Sean Ahern, Fri Aug 3 12:53:31 PDT 2001
1369 * Fixed a problem with freeing a partially-read object.
1370 *
1371 *----------------------------------------------------------------------*/
1372 PUBLIC void
DBFreeUcdvar(DBucdvar * var)1373 DBFreeUcdvar(DBucdvar *var)
1374 {
1375 int i;
1376
1377 if (var == NULL)
1378 return;
1379
1380 if (var->vals != NULL)
1381 {
1382 for (i = 0; i < var->nvals; i++) {
1383 FREE(var->vals[i]);
1384 if (var->mixvals != NULL)
1385 FREE(var->mixvals[i]);
1386 }
1387 }
1388
1389 FREE(var->vals);
1390 FREE(var->mixvals);
1391 FREE(var->name);
1392 FREE(var->label);
1393 FREE(var->units);
1394 FREE(var->meshname);
1395 FREE(var);
1396 }
1397
1398 PUBLIC int
DBIsEmptyUcdvar(DBucdvar const * var)1399 DBIsEmptyUcdvar(DBucdvar const *var)
1400 {
1401 if (var && var->nels!=0) return 0;
1402 return 1;
1403 }
1404
1405 /*----------------------------------------------------------------------
1406 * Function DBAllocZonelist
1407 *
1408 * Purpose
1409 *
1410 * Allocate and initialize a zonelist object.
1411 *
1412 * Modified
1413 *
1414 * Robb Matzke, Tue Nov 8 07:22:06 PST 1994
1415 * Added error mechanism
1416 *----------------------------------------------------------------------*/
1417 PUBLIC DBzonelist *
DBAllocZonelist(void)1418 DBAllocZonelist(void)
1419 {
1420 DBzonelist *zl;
1421
1422 API_BEGIN("DBAllocZonelist", DBzonelist *, NULL) {
1423 if (NULL == (zl = ALLOC(DBzonelist)))
1424 API_ERROR(NULL, E_NOMEM);
1425
1426 /* Initialize all memory to zero. */
1427 memset(zl, 0, sizeof(DBzonelist));
1428 }
1429 API_END;
1430
1431 return (zl);
1432 }
1433
1434 PUBLIC int
DBIsEmptyZonelist(DBzonelist const * zl)1435 DBIsEmptyZonelist(DBzonelist const *zl)
1436 {
1437 if (zl && zl->nzones!=0) return 0;
1438 return 1;
1439 }
1440
1441 /*----------------------------------------------------------------------
1442 * Function DBAllocPHZonelist
1443 *
1444 * Purpose
1445 *
1446 * Allocate and initialize a DBphzonelist object.
1447 *
1448 *----------------------------------------------------------------------*/
1449 PUBLIC DBphzonelist *
DBAllocPHZonelist(void)1450 DBAllocPHZonelist(void)
1451 {
1452 DBphzonelist *phzl;
1453
1454 API_BEGIN("DBAllocPHZonelist", DBphzonelist *, NULL) {
1455 if (NULL == (phzl = ALLOC(DBphzonelist)))
1456 API_ERROR(NULL, E_NOMEM);
1457
1458 /* Initialize all memory to zero. */
1459 memset(phzl, 0, sizeof(DBphzonelist));
1460 }
1461 API_END;
1462
1463 return (phzl);
1464 }
1465
1466 PUBLIC int
DBIsEmptyPHZonelist(DBphzonelist const * zl)1467 DBIsEmptyPHZonelist(DBphzonelist const *zl)
1468 {
1469 if (zl && zl->nfaces!=0) return 0;
1470 return 1;
1471 }
1472
1473 /*----------------------------------------------------------------------
1474 * Function DBAllocCSGZonelist
1475 *
1476 * Purpose
1477 *
1478 * Allocate and initialize a DBcsgzonelist object.
1479 *
1480 *----------------------------------------------------------------------*/
1481 PUBLIC DBcsgzonelist *
DBAllocCSGZonelist(void)1482 DBAllocCSGZonelist(void)
1483 {
1484 DBcsgzonelist *csgzl;
1485
1486 API_BEGIN("DBAllocCSGZonelist", DBcsgzonelist *, NULL) {
1487 if (NULL == (csgzl = ALLOC(DBcsgzonelist)))
1488 API_ERROR(NULL, E_NOMEM);
1489
1490 /* Initialize all memory to zero. */
1491 memset(csgzl, 0, sizeof(DBcsgzonelist));
1492 }
1493 API_END;
1494
1495 return (csgzl);
1496 }
1497
1498 PUBLIC int
DBIsEmptyCSGZonelist(DBcsgzonelist const * zl)1499 DBIsEmptyCSGZonelist(DBcsgzonelist const *zl)
1500 {
1501 if (zl && zl->nzones!=0) return 0;
1502 return 1;
1503 }
1504
1505 /*----------------------------------------------------------------------
1506 * Function DBFreeZonelist
1507 *
1508 * Purpose
1509 *
1510 * Release all storage associated with the given zonelist.
1511 *
1512 * Modified
1513 *
1514 * Mark C. Miller, Wed Jul 28 10:53:35 PDT 2004
1515 * Added missing free for gzoneno
1516 *----------------------------------------------------------------------*/
1517 PUBLIC void
DBFreeZonelist(DBzonelist * list)1518 DBFreeZonelist(DBzonelist *list)
1519 {
1520 if (list == NULL)
1521 return;
1522
1523 FREE(list->shapecnt);
1524 FREE(list->shapesize);
1525 FREE(list->shapetype);
1526 FREE(list->nodelist);
1527 FREE(list->zoneno);
1528 FREE(list->gzoneno);
1529 FREE(list);
1530 }
1531
1532 /*----------------------------------------------------------------------
1533 * Function DBFreePHZonelist
1534 *
1535 * Purpose
1536 *
1537 * Release all storage associated with the given DBphzonelist.
1538 *
1539 *----------------------------------------------------------------------*/
1540 PUBLIC void
DBFreePHZonelist(DBphzonelist * list)1541 DBFreePHZonelist(DBphzonelist *list)
1542 {
1543 if (list == NULL)
1544 return;
1545
1546 FREE(list->nodecnt);
1547 FREE(list->nodelist);
1548 FREE(list->extface);
1549 FREE(list->facecnt);
1550 FREE(list->facelist);
1551 FREE(list->zoneno);
1552 FREE(list->gzoneno);
1553 FREE(list);
1554 }
1555
1556 /*----------------------------------------------------------------------
1557 * Function DBFreeCSGZonelist
1558 *
1559 * Purpose
1560 *
1561 * Release all storage associated with the given DBcsgzonelist.
1562 *
1563 *----------------------------------------------------------------------*/
1564 PUBLIC void
DBFreeCSGZonelist(DBcsgzonelist * list)1565 DBFreeCSGZonelist(DBcsgzonelist *list)
1566 {
1567 if (list == NULL)
1568 return;
1569
1570 if (list->zonenames && list->nzones)
1571 {
1572 int i;
1573 for (i = 0; i < list->nzones; i++)
1574 FREE(list->zonenames[i]);
1575 }
1576
1577 if (list->regnames && list->nregs)
1578 {
1579 int i;
1580 for (i = 0; i < list->nregs; i++)
1581 FREE(list->regnames[i]);
1582 }
1583
1584 FREE(list->typeflags);
1585 FREE(list->leftids);
1586 FREE(list->rightids);
1587 FREE(list->xform);
1588 FREE(list->zonelist);
1589 FREE(list->zonenames);
1590 FREE(list->regnames);
1591
1592 FREE(list);
1593 }
1594
1595 /*----------------------------------------------------------------------
1596 * Function DBAllocEdgelist
1597 *
1598 * Purpose
1599 *
1600 * Allocate and initialize a edgelist object.
1601 *
1602 * Modified
1603 *
1604 * Robb Matzke, Tue Nov 8 07:22:55 PST 1994
1605 * Added error mechanism
1606 *----------------------------------------------------------------------*/
1607 PUBLIC DBedgelist *
DBAllocEdgelist(void)1608 DBAllocEdgelist(void)
1609 {
1610 DBedgelist *el;
1611
1612 API_BEGIN("DBAllocEdgelist", DBedgelist *, NULL) {
1613 if (NULL == (el = ALLOC(DBedgelist)))
1614 API_ERROR(NULL, E_NOMEM);
1615
1616 /* Initialize all memory to zero. */
1617 memset(el, 0, sizeof(DBedgelist));
1618 }
1619 API_END;
1620
1621 return (el);
1622 }
1623
1624 /*----------------------------------------------------------------------
1625 * Function DBFreeEdgelist
1626 *
1627 * Purpose
1628 *
1629 * Release all storage associated with the given edgelist.
1630 *
1631 *----------------------------------------------------------------------*/
1632 PUBLIC void
DBFreeEdgelist(DBedgelist * list)1633 DBFreeEdgelist(DBedgelist *list)
1634 {
1635 if (list == NULL)
1636 return;
1637
1638 FREE(list->edge_beg);
1639 FREE(list->edge_end);
1640 FREE(list);
1641 }
1642
1643 /*----------------------------------------------------------------------
1644 * Function DBAllocFacelist
1645 *
1646 * Purpose
1647 *
1648 * Allocate and initialize a facelist object.
1649 *
1650 * Modified
1651 *
1652 * Robb Matzke, Tue Nov 8 07:23:59 PST 1994
1653 * Added error mechanism
1654 *----------------------------------------------------------------------*/
1655 PUBLIC DBfacelist *
DBAllocFacelist(void)1656 DBAllocFacelist(void)
1657 {
1658 DBfacelist *fl;
1659
1660 API_BEGIN("DBAllocFacelist", DBfacelist *, NULL) {
1661 if (NULL == (fl = ALLOC(DBfacelist)))
1662 API_ERROR(NULL, E_NOMEM);
1663
1664 /* Initialize all memory to zero. */
1665 memset(fl, 0, sizeof(DBfacelist));
1666 }
1667 API_END;
1668
1669 return (fl);
1670 }
1671
1672 PUBLIC int
DBIsEmptyFacelist(DBfacelist const * fl)1673 DBIsEmptyFacelist(DBfacelist const *fl)
1674 {
1675 if (fl && fl->nfaces!=0) return 0;
1676 return 1;
1677 }
1678
1679 /*----------------------------------------------------------------------
1680 * Function DBFreeFacelist
1681 *
1682 * Purpose
1683 *
1684 * Release all storage associated with the given facelist.
1685 *
1686 *----------------------------------------------------------------------*/
1687 PUBLIC void
DBFreeFacelist(DBfacelist * list)1688 DBFreeFacelist(DBfacelist *list)
1689 {
1690 if (list == NULL)
1691 return;
1692
1693 FREE(list->shapecnt);
1694 FREE(list->shapesize);
1695 FREE(list->nodelist);
1696 FREE(list->types);
1697 FREE(list->typelist);
1698 FREE(list->nodeno);
1699 FREE(list->zoneno);
1700 FREE(list);
1701 }
1702
1703 /*----------------------------------------------------------------------
1704 * Function DBAllocMaterial
1705 *
1706 * Purpose
1707 *
1708 * Allocate and initialize a material-data object.
1709 *
1710 * Modified
1711 *
1712 * Robb Matzke, Tue Nov 8 07:24:51 PST 1994
1713 * Added error mechanism
1714 *----------------------------------------------------------------------*/
1715 PUBLIC DBmaterial *
DBAllocMaterial(void)1716 DBAllocMaterial(void)
1717 {
1718 DBmaterial *mats;
1719
1720 API_BEGIN("DBAllocMaterial", DBmaterial *, NULL) {
1721 if (NULL == (mats = ALLOC(DBmaterial)))
1722 API_ERROR(NULL, E_NOMEM);
1723
1724 /* Initialize all memory to zero. */
1725 memset(mats, 0, sizeof(DBmaterial));
1726 }
1727 API_END;
1728
1729 return (mats);
1730 }
1731 /*----------------------------------------------------------------------
1732 * Function DBFreeMaterial
1733 *
1734 * Purpose
1735 *
1736 * Release all storage associated with the given material object.
1737 *
1738 *----------------------------------------------------------------------*/
1739 PUBLIC void
DBFreeMaterial(DBmaterial * mats)1740 DBFreeMaterial(DBmaterial *mats)
1741 {
1742 int i;
1743 if (mats == NULL)
1744 return;
1745
1746 if (mats->matnames)
1747 {
1748 for(i=0;i<mats->nmat;i++)
1749 FREE(mats->matnames[i]);
1750 FREE(mats->matnames);
1751 }
1752
1753 if (mats->matcolors)
1754 {
1755 for(i=0;i<mats->nmat;i++)
1756 FREE(mats->matcolors[i]);
1757 FREE(mats->matcolors);
1758 }
1759
1760 FREE(mats->name);
1761 FREE(mats->matnos);
1762 FREE(mats->matlist);
1763 FREE(mats->mix_vf);
1764 FREE(mats->mix_next);
1765 FREE(mats->mix_zone);
1766 FREE(mats->mix_mat);
1767 FREE(mats->meshname);
1768 FREE(mats);
1769 }
1770
1771 PUBLIC int
DBIsEmptyMaterial(DBmaterial const * mats)1772 DBIsEmptyMaterial(DBmaterial const *mats)
1773 {
1774 int i, is_empty = 1;
1775
1776 for (i = 0; mats && i < mats->ndims; i++)
1777 {
1778 if (mats->dims[i] > 0)
1779 {
1780 is_empty = 0;
1781 break;
1782 }
1783 }
1784 return is_empty;
1785 }
1786
1787 /*----------------------------------------------------------------------
1788 * Function DBAllocMatspecies
1789 *
1790 * Purpose
1791 *
1792 * Allocate and initialize a matspecies-data object.
1793 *
1794 * Modified
1795 *
1796 * Robb Matzke, Tue Nov 8 07:25:42 PST 1994
1797 * Added error mechanism
1798 *----------------------------------------------------------------------*/
1799 PUBLIC DBmatspecies *
DBAllocMatspecies(void)1800 DBAllocMatspecies(void)
1801 {
1802 DBmatspecies *species;
1803
1804 API_BEGIN("DBAllocMatspecies", DBmatspecies *, NULL) {
1805 if (NULL == (species = ALLOC(DBmatspecies)))
1806 API_ERROR(NULL, E_NOMEM);
1807
1808 /* Initialize all memory to zero. */
1809 memset(species, 0, sizeof(DBmatspecies));
1810 }
1811 API_END;
1812
1813 return (species);
1814 }
1815
1816 /*----------------------------------------------------------------------
1817 * Function DBFreeMatspecies
1818 *
1819 * Purpose
1820 *
1821 * Release all storage associated with the given matspecies object.
1822 *
1823 * Modifications:
1824 *
1825 * Mark C. Miller, Tue Sep 8 15:40:51 PDT 2009
1826 * Added names and colors for species.
1827 *----------------------------------------------------------------------*/
1828 PUBLIC void
DBFreeMatspecies(DBmatspecies * species)1829 DBFreeMatspecies(DBmatspecies *species)
1830 {
1831 int i, j, k;
1832
1833 if (species == NULL)
1834 return;
1835
1836 if (species->specnames)
1837 {
1838 for(i=0,k=0;i<species->nmat;i++)
1839 {
1840 for(j=0;j<species->nmatspec[i];j++,k++)
1841 FREE(species->specnames[k]);
1842 }
1843 FREE(species->specnames);
1844 }
1845
1846 if (species->speccolors)
1847 {
1848 for(i=0,k=0;i<species->nmat;i++)
1849 {
1850 for(j=0;j<species->nmatspec[i];j++,k++)
1851 FREE(species->speccolors[k]);
1852 }
1853 FREE(species->speccolors);
1854 }
1855
1856 FREE(species->name);
1857 FREE(species->matname);
1858 FREE(species->nmatspec);
1859 FREE(species->species_mf);
1860 FREE(species->speclist);
1861 FREE(species->mix_speclist);
1862 FREE(species);
1863 }
1864
1865 PUBLIC int
DBIsEmptyMatspecies(DBmatspecies const * species)1866 DBIsEmptyMatspecies(DBmatspecies const *species)
1867 {
1868 int i, is_empty = 1;
1869
1870 if (species->nspecies_mf == 0)
1871 return 1;
1872
1873 for (i = 0; species && i < species->ndims; i++)
1874 {
1875 if (species->dims[i] > 0)
1876 {
1877 is_empty = 0;
1878 break;
1879 }
1880 }
1881 return is_empty;
1882 }
1883
1884 /*-------------------------------------------------------------------------
1885 * Function: DBAllocCompoundarray
1886 *
1887 * Purpose: Allocate a compound array object
1888 *
1889 * Return: Success: pointer to object
1890 *
1891 * Failure: NULL
1892 *
1893 * Programmer: matzke@viper
1894 * Tue Nov 8 07:26:44 PST 1994
1895 *
1896 * Modifications:
1897 *
1898 *-------------------------------------------------------------------------
1899 */
1900 PUBLIC DBcompoundarray *
DBAllocCompoundarray(void)1901 DBAllocCompoundarray(void)
1902 {
1903
1904 DBcompoundarray *array;
1905
1906 API_BEGIN("DBAllocCompoundarray", DBcompoundarray *, NULL) {
1907 if (NULL == (array = ALLOC(DBcompoundarray)))
1908 API_ERROR(NULL, E_NOMEM);
1909
1910 memset(array, 0, sizeof(DBcompoundarray));
1911 }
1912 API_END;
1913
1914 return array;
1915 }
1916
1917 /*----------------------------------------------------------------------
1918 * Function DBFreeCompoundarray
1919 *
1920 * Purpose
1921 *
1922 * Release all storage associated with the given compound array.
1923 *
1924 *----------------------------------------------------------------------*/
1925 PUBLIC void
DBFreeCompoundarray(DBcompoundarray * array)1926 DBFreeCompoundarray(DBcompoundarray *array)
1927 {
1928
1929 int i;
1930
1931 if (array) {
1932 FREE(array->name);
1933 if (array->elemnames) {
1934 for (i = 0; i < array->nelems; i++)
1935 FREE(array->elemnames[i]);
1936 FREE(array->elemnames);
1937 }
1938 FREE(array->elemlengths);
1939 FREE(array->values);
1940 FREE(array);
1941 }
1942 }
1943
1944 /*-------------------------------------------------------------------------
1945 * Function: DBAllocCurve
1946 *
1947 * Purpose: Allocate a curve array object.
1948 *
1949 * Return: Success:
1950 *
1951 * Failure:
1952 *
1953 * Programmer: Robb Matzke
1954 * robb@callisto.nuance.com
1955 * May 16, 1996
1956 *
1957 * Modifications:
1958 *
1959 *-------------------------------------------------------------------------
1960 */
1961 PUBLIC DBcurve *
DBAllocCurve(void)1962 DBAllocCurve (void)
1963 {
1964
1965 DBcurve *cu ;
1966
1967 API_BEGIN ("DBAllocCurve", DBcurve *, NULL) {
1968 if (NULL==(cu=ALLOC(DBcurve)))
1969 API_ERROR (NULL, E_NOMEM) ;
1970 memset (cu, 0, sizeof(DBcurve)) ;
1971 } API_END ;
1972
1973 return cu ;
1974 }
1975
1976 PUBLIC int
DBIsEmptyCurve(DBcurve const * crv)1977 DBIsEmptyCurve(DBcurve const *crv)
1978 {
1979 if (crv && crv->npts!=0) return 0;
1980 return 1;
1981 }
1982
1983 /*-------------------------------------------------------------------------
1984 * Function: DBFreeCurve
1985 *
1986 * Purpose: Release all storage associated with the given curve object.
1987 *
1988 * Return: void
1989 *
1990 * Programmer: Robb Matzke
1991 * robb@callisto.nuance.com
1992 * May 16, 1996
1993 *
1994 * Modifications:
1995 *
1996 *-------------------------------------------------------------------------
1997 */
1998 PUBLIC void
DBFreeCurve(DBcurve * cu)1999 DBFreeCurve (DBcurve *cu)
2000 {
2001
2002 if (cu) {
2003 FREE (cu->title) ;
2004 FREE (cu->xvarname) ;
2005 FREE (cu->yvarname) ;
2006 FREE (cu->xlabel) ;
2007 FREE (cu->ylabel) ;
2008 FREE (cu->xunits) ;
2009 FREE (cu->yunits) ;
2010 FREE (cu->x) ;
2011 FREE (cu->y) ;
2012 FREE (cu) ;
2013 }
2014 }
2015
2016 PUBLIC void
DBFreeGroupelmap(DBgroupelmap * map)2017 DBFreeGroupelmap(DBgroupelmap *map)
2018 {
2019 int i;
2020
2021 if (map == 0)
2022 return;
2023
2024 FREE(map->name);
2025 FREE(map->groupel_types);
2026 FREE(map->segment_lengths);
2027 FREE(map->segment_ids);
2028
2029 for (i = 0; i < map->num_segments; i++)
2030 FREE(map->segment_data[i]);
2031 FREE(map->segment_data);
2032
2033 if (map->segment_fracs)
2034 {
2035 for (i = 0; i < map->num_segments; i++)
2036 FREE(map->segment_fracs[i]);
2037 FREE(map->segment_fracs);
2038 }
2039 FREE(map);
2040 }
2041
2042 PUBLIC void
DBFreeMrgvar(DBmrgvar * mrgv)2043 DBFreeMrgvar(DBmrgvar *mrgv)
2044 {
2045 int i;
2046
2047 if (mrgv == 0)
2048 return;
2049
2050 if (mrgv->compnames)
2051 {
2052 for (i = 0; i < mrgv->ncomps; i++)
2053 FREE(mrgv->compnames[i]);
2054 FREE(mrgv->compnames);
2055 }
2056
2057 if (strchr(mrgv->reg_pnames[0], '%') == 0)
2058 {
2059 for (i = 0; i < mrgv->nregns; i++)
2060 FREE(mrgv->reg_pnames[i]);
2061 }
2062 else
2063 {
2064 FREE(mrgv->reg_pnames[0]);
2065 }
2066 FREE(mrgv->reg_pnames);
2067
2068 for (i = 0; i < mrgv->ncomps; i++)
2069 FREE(mrgv->data[i]);
2070 FREE(mrgv->data);
2071
2072 FREE(mrgv);
2073 }
2074
2075 PUBLIC void
DBFreeNamescheme(DBnamescheme * ns)2076 DBFreeNamescheme(DBnamescheme *ns)
2077 {
2078 int i,k;
2079
2080 if (ns->arralloc)
2081 {
2082 for (i = 0, k = 0; i < ns->narrefs; i++)
2083 {
2084 while (ns->fmt[k] != '\0' && ns->fmt[k] != '$' && ns->fmt[k] != '#') k++;
2085 if (ns->fmt[k] == '#')
2086 {
2087 FREE(ns->arrvals[i]);
2088 }
2089 else
2090 {
2091 int j;
2092 for (j = 0; j < ns->arrsizes[i]; j++)
2093 {
2094 FREE(((char **)(ns->arrvals[i]))[j]);
2095 }
2096 FREE(ns->arrvals[i]);
2097 }
2098 }
2099 }
2100 FREE(ns->arrvals);
2101 for (i = 0; i < ns->narrefs; i++)
2102 FREE(ns->arrnames[i]);
2103 FREE(ns->arrnames);
2104 FREE(ns->arrsizes);
2105 FREE(ns->fmt);
2106 FREE(ns->fmtptrs);
2107 for (i = 0; i < DB_MAX_EXPSTRS; i++)
2108 FREE(ns->embedstrs[i]);
2109 for (i = 0; i < ns->ncspecs; i++)
2110 FREE(ns->exprstrs[i]);
2111 FREE(ns->exprstrs);
2112 FREE(ns);
2113 }
2114
2115 PUBLIC DBnamescheme *
DBAllocNamescheme()2116 DBAllocNamescheme()
2117 {
2118 DBnamescheme *ns;
2119
2120 API_BEGIN("DBAllocNamescheme", DBnamescheme*, NULL) {
2121 if (NULL == (ns = ALLOC(DBnamescheme)))
2122 API_ERROR(NULL, E_NOMEM);
2123
2124 /* Initialize all memory to zero. */
2125 memset(ns, 0, sizeof(DBnamescheme));
2126
2127 }
2128 API_END;
2129
2130 return (ns);
2131 }
2132
2133 PUBLIC DBgroupelmap *
DBAllocGroupelmap(int num_segs,DBdatatype frac_type)2134 DBAllocGroupelmap(int num_segs, DBdatatype frac_type)
2135 {
2136 DBgroupelmap *gm;
2137
2138 API_BEGIN("DBAllocGroupelmap", DBgroupelmap*, NULL) {
2139 if (NULL == (gm = ALLOC(DBgroupelmap)))
2140 API_ERROR(NULL, E_NOMEM);
2141
2142 /* Initialize all memory to zero. */
2143 memset(gm, 0, sizeof(DBgroupelmap));
2144
2145 /* initialize all the arrays */
2146 gm->num_segments = num_segs;
2147 gm->groupel_types = ALLOC_N(int, num_segs);
2148 gm->segment_lengths = ALLOC_N(int, num_segs);
2149 gm->segment_ids = ALLOC_N(int, num_segs);
2150 gm->segment_data = ALLOC_N(int *, num_segs);
2151 switch (frac_type)
2152 {
2153 case DB_CHAR:
2154 gm->segment_fracs = (void**) ALLOC_N(char*, num_segs);
2155 break;
2156 case DB_INT:
2157 gm->segment_fracs = (void**) ALLOC_N(int*, num_segs);
2158 break;
2159 case DB_SHORT:
2160 gm->segment_fracs = (void**) ALLOC_N(short*, num_segs);
2161 break;
2162 case DB_LONG:
2163 gm->segment_fracs = (void**) ALLOC_N(long*, num_segs);
2164 break;
2165 case DB_LONG_LONG:
2166 gm->segment_fracs = (void**) ALLOC_N(long long*, num_segs);
2167 break;
2168 case DB_FLOAT:
2169 gm->segment_fracs = (void**) ALLOC_N(float*, num_segs);
2170 break;
2171 case DB_DOUBLE:
2172 gm->segment_fracs = (void**) ALLOC_N(double*, num_segs);
2173 break;
2174 default:
2175 gm->segment_fracs = 0;
2176 break;
2177 }
2178
2179 if (!gm->groupel_types || ! gm->segment_lengths ||
2180 !gm->segment_ids || !gm->segment_data ||
2181 (frac_type != DB_NOTYPE && !gm->segment_fracs))
2182 {
2183 DBFreeGroupelmap(gm);
2184 API_ERROR(NULL, E_NOMEM);
2185 }
2186 }
2187
2188 API_END;
2189
2190 return (gm);
2191 }
2192