1 /*
2  * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3  * Applied Mathematics, Norway.
4  *
5  * Contact information: E-mail: tor.dokken@sintef.no
6  * SINTEF ICT, Department of Applied Mathematics,
7  * P.O. Box 124 Blindern,
8  * 0314 Oslo, Norway.
9  *
10  * This file is part of SISL.
11  *
12  * SISL is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * SISL is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public
23  * License along with SISL. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  * In accordance with Section 7(b) of the GNU Affero General Public
27  * License, a covered work must retain the producer line in every data
28  * file that is created or manipulated using SISL.
29  *
30  * Other Usage
31  * You can be released from the requirements of the license by purchasing
32  * a commercial license. Buying such a license is mandatory as soon as you
33  * develop commercial activities involving the SISL library without
34  * disclosing the source code of your own applications.
35  *
36  * This file may be used in accordance with the terms contained in a
37  * written agreement between you and SINTEF ICT.
38  */
39 
40 #include "sisl-copyright.h"
41 
42 /*
43  *
44  * $Id: destruct.c,v 1.3 2001-03-19 15:58:40 afr Exp $
45  *
46  */
47 
48 
49 #define DESTRUCT
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
freeCurve(SISLCurve * pcurve)55      freeCurve(SISLCurve *pcurve)
56 #else
57 void freeCurve(pcurve)
58      SISLCurve *pcurve;
59 #endif
60 /*
61 *********************************************************************
62 *
63 *********************************************************************
64 *
65 * PURPOSE    : Free the space occupied by the curve pointed at by
66 *              pcurve.
67 *
68 *
69 *
70 * INPUT      : pcurve - Pointer to curve.
71 *
72 *
73 *
74 * OUTPUT     :
75 *
76 *
77 * METHOD     :
78 *
79 *
80 * REFERENCES :
81 *
82 *-
83 * CALLS      : freearray - Free space occupied by a given array.
84 *
85 * WRITTEN BY : Vibeke Skytt, SI, 88-05. Arne Laksaa, SI, 89-03.
86 *              Vibeke Skytt, SI, 91-01.
87 * Revised by : Paal Fugelli, SINTEF, Oslo, Norway, 94-09.  Added free'ing
88 *              of ecoef for rationals when icopy==0.  ecoef is ALWAYS
89 *              allocated for rationals, regardless of the icopy flag value.
90 *
91 *********************************************************************
92 */
93 {
94   int ki;         /* Counter.  */
95 
96 
97   if ( pcurve->icopy != 0 )
98   {
99 
100     /* Free arrays.  */
101 
102     freearray(pcurve->et);
103     freearray(pcurve->ecoef);
104     if ( pcurve->rcoef != SISL_NULL )  freearray(pcurve->rcoef);
105   }
106   else if ( pcurve->ikind == 2  ||  pcurve->ikind == 4 )
107   {
108     /* VSK, 940902. The array pcurve->ecoef is ALWAYS allocated in the
109        constructor for rationals and must be free'ed.                  */
110 
111     freearray(pcurve->ecoef);
112   }
113 
114   if ( pcurve->pdir )
115   {
116 
117     /* Free direction structure. */
118 
119     if ( pcurve->pdir->ecoef )  freearray(pcurve->pdir->ecoef);
120     if ( pcurve->pdir->esmooth != SISL_NULL )  freearray(pcurve->pdir->esmooth);
121     freearray(pcurve->pdir);
122   }
123 
124   if ( pcurve->pbox )
125   {
126 
127     /* Free surrounded SISLbox structure. */
128 
129     if ( pcurve->pbox->emax )  freearray(pcurve->pbox->emax);
130     if ( pcurve->pbox->emin )  freearray(pcurve->pbox->emin);
131 
132     for ( ki=0;  ki < 3;  ki++ )
133     {
134       if ( pcurve->pbox->e2max[ki] )  freearray(pcurve->pbox->e2max[ki]);
135       if ( pcurve->pbox->e2min[ki] )  freearray(pcurve->pbox->e2min[ki]);
136     }
137     freearray(pcurve->pbox);
138   }
139 
140   /* Free instance of curve. */
141 
142   freearray(pcurve);
143 
144   return;
145 }
146 
147 #if defined(SISLNEEDPROTOTYPES)
148 void
freeEdge(SISLEdge * pedge)149      freeEdge(SISLEdge *pedge)
150 #else
151 void freeEdge(pedge)
152      SISLEdge *pedge;
153 #endif
154 /*
155 *********************************************************************
156 *
157 *********************************************************************
158 *
159 * PURPOSE    : Free the space occupied by an instance of the structure
160 *              Edge. Also free space occupied by instances of Ptedge
161 *              that belongs to pedge.
162 *
163 *
164 *
165 * INPUT      : pedge  - Pointer to the instance.
166 *
167 *
168 *
169 * OUTPUT     :
170 *
171 *
172 * METHOD     :
173 *
174 *
175 * REFERENCES :
176 *
177 *-
178 * CALLS      :
179 *
180 * WRITTEN BY : Vibeke Skytt, SI, 88-05.
181 *
182 *********************************************************************
183 */
184 {
185 
186   SISLPtedge *p1,*p2;  /* Pointers to traverse lists of Ptedge-elements.*/
187   SISLPtedge *(*pel);  /* Pointer to an array element.      */
188   int ki;                 /* Counter.                          */
189 
190   /* First free the space occupied by the lists pointed at by
191      the array prpt.                                           */
192 
193   pel = pedge -> prpt;
194   for (ki=0; ki<pedge->iedge; ki++)
195     {
196 
197       /* Traverse the list connected to edge nr ki and free the elements. */
198 
199       p1 = *pel;
200       while (p1 != SISL_NULL)
201 	{
202 	  p2 = p1 -> pnext;
203 	  freePtedge(p1);
204 	  p1 = p2;
205 	}
206       pel++;
207     }
208 
209   /* Free the space occupied by the prpt array. */
210 
211   freearray(pedge -> prpt);
212 
213   /* Free the space occupied by the instance. */
214 
215   freearray(pedge);
216 
217   return;
218 }
219 
220 #if defined(SISLNEEDPROTOTYPES)
221 void
freeIntcrvlist(SISLIntcurve ** viclist,int icrv)222      freeIntcrvlist(SISLIntcurve **viclist, int icrv)
223 #else
224 void freeIntcrvlist(viclist,icrv)
225      SISLIntcurve **viclist;
226      int      icrv;
227 #endif
228 /*
229 ************************************************************************
230 *
231 * Purpose	: Free a list of Intcurve.
232 *
233 * Input		: viclist  - Array of pointers to pointers to instance
234 *                            of Intcurve.
235 *                 icrv     - # of SISLIntcurve in the list.
236 *
237 * Output	: None.
238 *
239 * Method	:
240 *
241 * References	:
242 *-
243 * Calls		: freeIntcurve - free instance of Intcurve.
244 *
245 *
246 * Written by	: B. O. Hoset, SI, Oslo, Norway, aug. 1989
247 *
248 ************************************************************************
249 */
250 {
251   /*
252    * Local declarations
253    * ------------------
254    */
255 
256   int         ki;
257 
258   /*
259    * Free each SISLIntcurve from bottom of the list and u to the top.
260    * ------------------------------------------------------------
261    */
262 
263   if (viclist)
264     {
265       for ( ki = icrv - 1; ki >= 0; ki --)
266 	{
267 	  if (viclist[ki])
268 	    {
269 	      freeIntcurve(viclist[ki]);
270 	      viclist[ki] = SISL_NULL;
271 	    }
272 	}
273       freearray(viclist);
274       viclist = SISL_NULL;
275     }
276 }
277 
278 #if defined(SISLNEEDPROTOTYPES)
279 void
freeIntcurve(SISLIntcurve * pintc)280      freeIntcurve(SISLIntcurve *pintc)
281 #else
282 void freeIntcurve(pintc)
283      SISLIntcurve *pintc;
284 #endif
285 
286 /*
287 ****************************************************************************
288 *
289 * Purpose    : Free the space occupied by the intersection curve structure.
290 *
291 * Input      : pintc   - Pointer to Intcurve.
292 *
293 *
294 *
295 * Output     :
296 *
297 *
298 * Method     :
299 *
300 *
301 * References :
302 *
303 *-
304 * Calls      : freeCurve - Free space occupied by a curve.
305 *
306 * Written by : Bjoern Olav Hoset, SI, 06-89.
307 *
308 ****************************************************************************
309 */
310 {
311   /* Free whatever is allocated */
312 
313   if (pintc)
314     {
315       if (pintc->epar1) freearray(pintc->epar1);
316       if (pintc->epar2) freearray(pintc->epar2);
317       if (pintc->pgeom) freeCurve(pintc->pgeom);
318       if (pintc->ppar1) freeCurve(pintc->ppar1);
319       if (pintc->ppar2) freeCurve(pintc->ppar2);
320       freearray(pintc);
321     }
322   return;
323 }
324 
325 #if defined(SISLNEEDPROTOTYPES)
326 void
freeIntdat(SISLIntdat * pintdat)327      freeIntdat(SISLIntdat *pintdat)
328 #else
329 void freeIntdat(pintdat)
330      SISLIntdat *pintdat;
331 #endif
332 /*
333 *********************************************************************
334 *
335 *********************************************************************
336 *
337 * PURPOSE    : Free the space occupied by an instance of the structure
338 *              Intdat. Also free space occupied by instances of Intlist
339 *              and SISLIntpt that belongs to intdat.
340 *
341 *
342 *
343 * INPUT      : pintdat - Pointer to the instance.
344 *
345 *
346 *
347 * OUTPUT     :
348 *
349 *
350 * METHOD     :
351 *
352 *
353 * REFERENCES :
354 *
355 *-
356 * CALLS      : freeIntpt
357 *              freeIntlist
358 *
359 * WRITTEN BY : UJK         , SI, 89-04.
360 *
361 *********************************************************************
362 */
363 {
364   int ki;                    /* Counter.                                     */
365 
366   if (pintdat == SISL_NULL) goto out;
367 
368   /* First free the space occupied by the Intpt's pointed at by
369      the array vpoint.                                                       */
370 
371   for (ki=0; ki<pintdat->ipoint; ki++)
372     if (pintdat -> vpoint[ki])   freeIntpt(pintdat -> vpoint[ki]);
373 
374   /* Free the space occupied by the vpoint array. */
375 
376   freearray(pintdat -> vpoint);
377 
378   /* Next free the space occupied by the Intlists pointed at by
379      the array vlist.                                                       */
380 
381   for (ki=0; ki<pintdat->ilist; ki++)
382     if    (pintdat -> vlist[ki])   freeIntlist(pintdat -> vlist[ki]);
383 
384   /* Free the space occupied by the vpoint array. */
385 
386   freearray(pintdat -> vlist);
387 
388   /* Free the space occupied by the instance. */
389 
390   freearray(pintdat);
391 
392  out:
393   return;
394 }
395 
396 #if defined(SISLNEEDPROTOTYPES)
397 void
freeIntlist(SISLIntlist * plist)398      freeIntlist(SISLIntlist *plist)
399 #else
400 void freeIntlist(plist)
401      SISLIntlist *plist;
402 #endif
403 /*
404 *********************************************************************
405 *
406 *********************************************************************
407 *
408 * PURPOSE    : Free the space occupied by an instance of the structure
409 *              Intlist. The instance contains a list of intersection
410 *              points defining an intersection curve.
411 *
412 *
413 *
414 * INPUT      : plist  - The space occupied by this list is to be free.
415 *
416 *
417 *
418 * OUTPUT     :
419 *
420 *
421 * METHOD     :
422 *
423 *
424 * REFERENCES :
425 *
426 *-
427 * CALLS      :
428 *
429 * WRITTEN BY : Vibeke Skytt, SI, 88-05.
430 *
431 *********************************************************************
432 */
433 {
434   /* Free space. */
435 
436   freearray(plist);
437 
438   return;
439 }
440 
441 #if defined(SISLNEEDPROTOTYPES)
442 void
freeIntpt(SISLIntpt * ppt)443      freeIntpt(SISLIntpt *ppt)
444 #else
445 void freeIntpt(ppt)
446      SISLIntpt *ppt;
447 #endif
448 /*
449 *********************************************************************
450 *
451 *********************************************************************
452 *
453 * PURPOSE    : Free the space allocated to keep the instance of Intpt
454 *              pointed at by ppt.
455 *
456 *
457 *
458 * INPUT      : ppt    - Pointer to instance.
459 *
460 *
461 *
462 * OUTPUT     :
463 *
464 *
465 * METHOD     :
466 *
467 *
468 * REFERENCES :
469 *
470 *-
471 * CALLS      :
472 *
473 * WRITTEN BY : Ulf J. Krystad, SI, 91-06.
474 *
475 *********************************************************************
476 */
477 {
478   /* Free the arrays contained in the instance. */
479 
480   if (ppt->ipar)
481     freearray(ppt -> epar);
482   if (ppt->pnext)       freearray(ppt->pnext);
483   if (ppt->curve_dir)   freearray(ppt->curve_dir);
484   if (ppt->left_obj_1)  freearray(ppt->left_obj_1);
485   if (ppt->left_obj_2)  freearray(ppt->left_obj_2);
486   if (ppt->right_obj_1) freearray(ppt->right_obj_1);
487   if (ppt->right_obj_2) freearray(ppt->right_obj_2);
488   if (ppt->geo_data_1)  freearray(ppt->geo_data_1);
489   if (ppt->geo_data_2)  freearray(ppt->geo_data_2);
490 
491   if(ppt->trim[0] != SISL_NULL) freeTrimpar(ppt->trim[0]);
492   if(ppt->trim[1] != SISL_NULL) freeTrimpar(ppt->trim[1]);
493 
494   /* Free the instance pointed at by ppt. */
495 
496   freearray(ppt);
497 }
498 
499 #if defined(SISLNEEDPROTOTYPES)
500 void
freeIntsurf(SISLIntsurf * intsurf)501      freeIntsurf(SISLIntsurf *intsurf)
502 #else
503 void freeIntsurf(intsurf)
504      SISLIntsurf *intsurf;
505 #endif
506 /*
507 *********************************************************************
508 *
509 *********************************************************************
510 *
511 * PURPOSE    : Free the space allocated to keep the instance of Intsurf
512 *              pointed at by intsurf.
513 *
514 *
515 *
516 * INPUT      : intsurf    - Pointer to instance.
517 *
518 *
519 *
520 * OUTPUT     :
521 *
522 *
523 * METHOD     :
524 *
525 *
526 * REFERENCES :
527 *
528 *-
529 * CALLS      :
530 *
531 * WRITTEN BY : Michael Floater, SI, 91-11.
532 *
533 *********************************************************************
534 */
535 {
536 
537   /* Free the arrays if not SISL_NULL. */
538 
539   if(intsurf->epar != SISL_NULL) freearray(intsurf->epar);
540   if(intsurf->const_par != SISL_NULL) freearray(intsurf->const_par);
541 
542   /* Free the instance pointed at by intsurf. */
543 
544   freearray(intsurf);
545 
546   return;
547 }
548 
549 #if defined(SISLNEEDPROTOTYPES)
550 void
freeTrimpar(SISLTrimpar * trimpar)551      freeTrimpar(SISLTrimpar *trimpar)
552 #else
553 void freeTrimpar(trimpar)
554      SISLTrimpar *trimpar;
555 #endif
556 /*
557 *********************************************************************
558 *
559 *********************************************************************
560 *
561 * PURPOSE    : Free the space allocated to keep the instance of Trimpar
562 *              pointed at by trimpar.
563 *
564 *
565 *
566 * INPUT      : trimpar    - Pointer to instance.
567 *
568 *
569 *
570 * OUTPUT     :
571 *
572 *
573 * METHOD     :
574 *
575 *
576 * REFERENCES :
577 *
578 *-
579 * CALLS      :
580 *
581 * WRITTEN BY : Michael Floater, SI, 91-10.
582 *
583 *********************************************************************
584 */
585 {
586 
587 
588   /* Free the instance pointed at by trimpar. */
589 
590   freearray(trimpar);
591 
592   return;
593 }
594 
595 #if defined(SISLNEEDPROTOTYPES)
596 void
freeTrack(SISLTrack * ppt)597      freeTrack(SISLTrack *ppt)
598 #else
599 void freeTrack(ppt)
600      SISLTrack *ppt;
601 #endif
602 /*
603 *********************************************************************
604 *
605 *********************************************************************
606 *
607 * PURPOSE    : Free the space allocated to keep the instance of Track
608 *              pointed at by ppt.
609 *              Curves and surfaces are also removed.
610 *
611 *
612 * INPUT      : ppt    - Pointer to instance.
613 *
614 *
615 *
616 * OUTPUT     :
617 *
618 *
619 * METHOD     :
620 *
621 *
622 * REFERENCES :
623 *
624 *-
625 * CALLS      :
626 *
627 * WRITTEN BY : Ulf J. Krystad, SI, 91-06.
628 *
629 *********************************************************************
630 */
631 {
632   /* Free the arrays contained in the instance. */
633 
634    /*  if (ppt->psurf_1) freeSurf(ppt->psurf_1);
635       if (ppt->ideg == 0 && ppt->psurf_2) freeSurf(ppt->psurf_2); */
636   if (ppt->pcurve_3d) freeCurve(ppt->pcurve_3d);
637   if (ppt->pcurve_2d_1) freeCurve(ppt->pcurve_2d_1);
638   if (ppt->ideg==0 && ppt->pcurve_2d_2) freeCurve(ppt->pcurve_2d_2);
639 
640   /* Free the instance pointed at by ppt. */
641 
642   freearray(ppt);
643 }
644 
645 #if defined(SISLNEEDPROTOTYPES)
646 void
freeObject(SISLObject * pobj)647      freeObject(SISLObject *pobj)
648 #else
649 void freeObject(pobj)
650      SISLObject *pobj;
651 #endif
652 /*
653 *********************************************************************
654 *
655 *********************************************************************
656 *
657 * PURPOSE    : Free the space occupied by the object pointed at by
658 *              pobj. Also free the point, curve or surface that the
659 *              object represents.
660 *
661 *
662 *
663 * INPUT      : pobj   - Pointer to object.
664 *
665 *
666 *
667 * OUTPUT     :
668 *
669 *
670 * METHOD     :
671 *
672 *
673 * REFERENCES :
674 *
675 *-
676 * CALLS      : freePoint - Free space occupied by a point.
677 *              freeCurve - Free space occupied by a curve.
678 *              freeSurf  - Free space occupied by a surface.
679 *
680 * WRITTEN BY : Vibeke Skytt, SI, 88-05.
681 *
682 * MODIFIED   : UJK               89-04.
683 *              The structure SISLPoint is included.
684 *
685 *********************************************************************
686 */
687 {
688   int ki;
689 
690   /* Free point, curve or surface represented by pobj.                */
691 
692   if (pobj -> iobj == SISLPOINT)
693     { if (pobj -> p1 != SISL_NULL) freePoint(pobj -> p1); }
694   else if (pobj -> iobj == SISLCURVE)
695     { if (pobj -> c1 != SISL_NULL) freeCurve(pobj -> c1); }
696   else if (pobj -> iobj == SISLSURFACE)
697     { if (pobj -> s1 != SISL_NULL) freeSurf(pobj -> s1);  }
698 
699   for (ki=0; ki<4; ki++)
700     if (pobj->edg[ki] != SISL_NULL) freeObject(pobj->edg[ki]);
701 
702   /* Free instance of object. */
703 
704   freearray(pobj);
705 
706   return;
707 }
708 
709 #if defined(SISLNEEDPROTOTYPES)
710 void
freePoint(SISLPoint * ppoint)711      freePoint(SISLPoint *ppoint)
712 #else
713 void freePoint(ppoint)
714      SISLPoint *ppoint;
715 #endif
716 /*
717 *********************************************************************
718 *
719 *********************************************************************
720 *
721 * PURPOSE    : Free the space occupied by the point pointed at by
722 *              ppoint.
723 *
724 *
725 *
726 * INPUT      : ppoint - Pointer to point.
727 *
728 *
729 *
730 * OUTPUT     :
731 *
732 *
733 * METHOD     :
734 *
735 *
736 * REFERENCES :
737 *
738 *-
739 * CALLS      :
740 *
741 * WRITTEN BY : UJK, SI, 89-04.   Vibeke Skytt, SI, 91-01.
742 *
743 *********************************************************************
744 */
745 {
746    int ki;   /* Counter.  */
747 
748   if (ppoint != SISL_NULL)
749     {
750       if (ppoint -> pbox != SISL_NULL)
751       {
752 	 if (ppoint->pbox->emax) freearray(ppoint->pbox->emax);
753 	 if (ppoint->pbox->emin) freearray(ppoint->pbox->emin);
754 
755 	 for (ki=0; ki<3; ki++)
756 	 {
757 	    if (ppoint->pbox->e2max[ki]) freearray(ppoint->pbox->e2max[ki]);
758 	    if (ppoint->pbox->e2min[ki]) freearray(ppoint->pbox->e2min[ki]);
759 	 }
760 	 freearray(ppoint->pbox);
761 	}
762 
763       if ((ppoint -> idim > 3) &&
764 	  (ppoint -> icopy != 0) &&
765 	  (ppoint -> ecoef != SISL_NULL))
766 	freearray(ppoint -> ecoef);	/* Free array.  */
767 
768       freearray(ppoint);		/* Free instance of point. */
769     }
770   return;
771 }
772 
773 #if defined(SISLNEEDPROTOTYPES)
774 void
freePtedge(SISLPtedge * p1)775      freePtedge(SISLPtedge *p1)
776 #else
777 void freePtedge(p1)
778      SISLPtedge *p1;
779 #endif
780 /*
781 *********************************************************************
782 *
783 *********************************************************************
784 *
785 * PURPOSE    : Free the space allocated by an instance of the structure
786 *              Ptedge.
787 *
788 *
789 *
790 * INPUT      : p1     - A pointer to the instance.
791 *
792 *
793 *
794 * OUTPUT     :
795 *
796 *
797 * METHOD     :
798 *
799 *
800 * REFERENCES :
801 *
802 *-
803 * CALLS      :
804 *
805 * WRITTEN BY : Vibeke Skytt, SI, 88-05.
806 *
807 *********************************************************************
808 */
809 {
810   /* Free the space that p1 occupies. */
811 
812   freearray(p1);
813 
814   return;
815 }
816 
817 #if defined(SISLNEEDPROTOTYPES)
818 void
freeSurf(SISLSurf * psurf)819      freeSurf(SISLSurf *psurf)
820 #else
821 void freeSurf(psurf)
822      SISLSurf *psurf;
823 #endif
824 /*
825 *********************************************************************
826 *
827 *********************************************************************
828 *
829 * PURPOSE    : Free the space occupied by the surface pointed at by
830 *              psurf.
831 *
832 *
833 *
834 * INPUT      : psurf - Pointer to surface.
835 *
836 *
837 *
838 * OUTPUT     :
839 *
840 *
841 * METHOD     :
842 *
843 *
844 * REFERENCES :
845 *
846 *-
847 * CALLS      : freearray - Free space occupied by a given array.
848 *
849 * WRITTEN BY : Vibeke Skytt, SI, 88-05. Arne Laksaa, SI, 89-03.
850 *              Vibeke Skytt, SI, 91-01.
851 * Revised by : Paal Fugelli, SINTEF, Oslo, Norway, 94-09.  Added free'ing
852 *              of ecoef for rationals when icopy==0.  ecoef is ALWAYS
853 *              allocated for rationals, regardless of the icopy flag value.
854 *
855 *********************************************************************
856 */
857 {
858   int ki;     /* Counter.  */
859 
860 
861   if ( psurf->icopy != 0 )
862   {
863 
864     /* Free arrays.  */
865 
866     freearray(psurf->et1);
867     freearray(psurf->et2);
868     freearray(psurf->ecoef);
869     if ( psurf->rcoef != SISL_NULL )  freearray(psurf->rcoef);
870   }
871   else if ( psurf->ikind == 2  ||  psurf->ikind == 4 )
872   {
873     /* VSK, 940902. The array pcurve->ecoef is ALWAYS allocated in the
874        constructor for rationals and must be free'ed.                  */
875 
876     freearray(psurf->ecoef);
877   }
878 
879 
880   if ( psurf->pdir )
881   {
882 
883     /* Free direction structure. */
884 
885     if ( psurf->pdir->ecoef )  freearray(psurf->pdir->ecoef);
886     if ( psurf->pdir->esmooth != SISL_NULL )  freearray(psurf->pdir->esmooth);
887     freearray(psurf->pdir);
888   }
889 
890   if ( psurf->pbox )
891   {
892 
893     /* Free surrounded SISLbox structure. */
894 
895     if ( psurf->pbox->emax )  freearray(psurf->pbox->emax);
896     if ( psurf->pbox->emin )  freearray(psurf->pbox->emin);
897 
898     for ( ki=0;  ki < 3;  ki++ )
899     {
900       if ( psurf->pbox->e2max[ki] )  freearray(psurf->pbox->e2max[ki]);
901       if ( psurf->pbox->e2min[ki] )  freearray(psurf->pbox->e2min[ki]);
902     }
903     freearray(psurf->pbox);
904   }
905 
906   if (psurf->seg1)
907     freeSegmentation(psurf->seg1);
908   if (psurf->seg2)
909     freeSegmentation(psurf->seg2);
910 
911   /* Free instance of surface. */
912 
913   freearray(psurf);
914 
915   return;
916 }
917 
918 
919 #if defined(SISLNEEDPROTOTYPES)
920 void
freeSegmentation(SISLSegmentation * pseg)921 freeSegmentation(SISLSegmentation *pseg)
922 #else
923 void freeSegmentation(pseg)
924      SISLSegmentation *pseg;
925 #endif
926 /*
927 *********************************************************************
928 *
929 *********************************************************************
930 *
931 * PURPOSE    : Free the space occupied by the segmentation array
932 *
933 *
934 *
935 * INPUT      : psegmentation - Pointer to the segmentation information
936 *
937 *
938 *
939 * OUTPUT     :
940 *
941 *
942 * METHOD     :
943 *
944 *
945 * REFERENCES :
946 *
947 *-
948 * CALLS      : freearray - Free space occupied by a given array.
949 *
950 * WRITTEN BY : Vibeke Skytt, SINTEF, 2018-02
951 *
952 *********************************************************************
953 */
954 {
955   if (pseg->seg_val != NULL) freearray(pseg->seg_val);
956   if (pseg->seg_type != NULL) freearray(pseg->seg_type);
957   freearray(pseg);
958   pseg = NULL;
959 
960   return;
961 }
962