GLYLIB  0.3.0b
deallocate_analysis_structures.c
Go to the documentation of this file.
00001 #include "../inc/mylib.h"
00002 #include "../inc/molecules.h"
00003 #include "../inc/modes.h"
00004 #include "../inc/stats.h"
00005 
00006 /** \file deallocate_analysis_structures.c 
00007 \addtogroup MEMORY_MANAGEMENT
00008 \brief   Dealloction routines for structures relevant to analysis.
00009 
00010 Begun on 20100304 by BLFoley 
00011 
00012 Notes regarding these functions:
00013 
00014 * If a structure does not contain any pointers, it can just be freed.
00015 * Structures that contain pointers must have a deallocation function.
00016 * Single-pointers to arrays of simple types (e.g. int) may be freed.
00017 * Single-pointers to arrays of structures might need individual deallocation.
00018 * Double-pointers
00019         * Be very careful before freeing double-pointed structures
00020         *       -- they might point somewhere you don't want freed
00021         * Freeing the top-level pointer should not interfere with data below 
00022 */
00023 /********** structures from modes.h ****************/
00024 void deallocateVibaddr(vibaddr *va){
00025  // free top
00026  if(va[0].vi != NULL && va[0].vi != 0x0){free(va[0].vi);}
00027  return ;
00028 }
00029 void deallocateStretch(stretch *s){
00030  if(s[0].Desc != NULL && s[0].Desc != 0x0){free(s[0].Desc);}
00031  return ;
00032 }
00033 void deallocateBend(bend *b){
00034  if(b[0].Desc != NULL && b[0].Desc != 0x0){free(b[0].Desc);}
00035  return ;
00036 }
00037 void deallocateTorsion(torsion *t){
00038  if(t[0].Desc != NULL && t[0].Desc != 0x0){free(t[0].Desc);}
00039  return ;
00040 }
00041 void deallocateRingmotion(ringmotion *rm){
00042  // free top
00043  if(rm[0].Desc != NULL && rm[0].Desc != 0x0){free(rm[0].Desc);}
00044  if(rm[0].mi != NULL && rm[0].mi != 0x0){free(rm[0].mi);}
00045  if(rm[0].c != NULL && rm[0].c != 0x0){free(rm[0].c);}
00046  return ;
00047 }
00048 void deallocateVibmode(vibmode *vm){
00049  int i;
00050  // deallocate each
00051  if(vm[0].s != NULL && vm[0].s != 0x0){
00052         for(i=0;i<vm[0].ns;i++){deallocateStretch(&vm[0].s[i]);}
00053         free(vm[0].s);}
00054  if(vm[0].b != NULL && vm[0].b != 0x0){
00055         for(i=0;i<vm[0].nb;i++){deallocateBend(&vm[0].b[i]);}
00056         free(vm[0].b);}
00057  if(vm[0].t != NULL && vm[0].t != 0x0){
00058         for(i=0;i<vm[0].nt;i++){deallocateTorsion(&vm[0].t[i]);}
00059         free(vm[0].t);}
00060  if(vm[0].r != NULL && vm[0].r != 0x0){
00061         for(i=0;i<vm[0].nr;i++){deallocateRingmotion(&vm[0].r[i]);}
00062         free(vm[0].r);}
00063  // free top
00064  if(vm[0].Desc != NULL && vm[0].Desc != 0x0){free(vm[0].Desc);}
00065  return ;
00066 }
00067 void deallocateTwoassign(twoassign *ta){
00068  // free top
00069  if(ta[0].s2 != NULL && ta[0].s2 != 0x0){free(ta[0].s2);}
00070  if(ta[0].b2 != NULL && ta[0].b2 != 0x0){free(ta[0].b2);}
00071  if(ta[0].t2 != NULL && ta[0].t2 != 0x0){free(ta[0].t2);}
00072  if(ta[0].s2s != NULL && ta[0].s2s != 0x0){free(ta[0].s2s);}
00073  if(ta[0].b2s != NULL && ta[0].b2s != 0x0){free(ta[0].b2s);}
00074  if(ta[0].t2s != NULL && ta[0].t2s != 0x0){free(ta[0].t2s);}
00075  if(ta[0].s2a != NULL && ta[0].s2a != 0x0){free(ta[0].s2a);}
00076  if(ta[0].b2a != NULL && ta[0].b2a != 0x0){free(ta[0].b2a);}
00077  if(ta[0].t2a != NULL && ta[0].t2a != 0x0){free(ta[0].t2a);}
00078  return ;
00079 }
00080 void deallocateRingassign(ringassign *ra){
00081  // free top
00082  if(ra[0].opsA != NULL && ra[0].opsA != 0x0){free(ra[0].opsA);}
00083  if(ra[0].opss != NULL && ra[0].opss != 0x0){free(ra[0].opss);}
00084  if(ra[0].opsa != NULL && ra[0].opsa != 0x0){free(ra[0].opsa);}
00085  if(ra[0].opdA != NULL && ra[0].opdA != 0x0){free(ra[0].opdA);}
00086  if(ra[0].opdA1G != NULL && ra[0].opdA1G != 0x0){free(ra[0].opdA1G);}
00087  if(ra[0].opdOth != NULL && ra[0].opdOth != 0x0){free(ra[0].opdOth);}
00088  if(ra[0].rbA != NULL && ra[0].rbA != 0x0){free(ra[0].rbA);}
00089  if(ra[0].rbs != NULL && ra[0].rbs != 0x0){free(ra[0].rbs);}
00090  if(ra[0].rba != NULL && ra[0].rba != 0x0){free(ra[0].rba);}
00091  if(ra[0].roA != NULL && ra[0].roA != 0x0){free(ra[0].roA);}
00092  if(ra[0].ros != NULL && ra[0].ros != 0x0){free(ra[0].ros);}
00093  if(ra[0].roa != NULL && ra[0].roa != 0x0){free(ra[0].roa);}
00094  if(ra[0].rpA != NULL && ra[0].rpA != 0x0){free(ra[0].rpA);}
00095  if(ra[0].rps != NULL && ra[0].rps != 0x0){free(ra[0].rps);}
00096  if(ra[0].rpa != NULL && ra[0].rpa != 0x0){free(ra[0].rpa);}
00097  if(ra[0].rso != NULL && ra[0].rso != 0x0){free(ra[0].rso);}
00098  return ;
00099 }
00100 void deallocateAssignment(assignment *a){
00101  int i;
00102  // deallocate each
00103  if(a[0].r != NULL && a[0].r != 0x0){
00104         for(i=0;i<a[0].nr;i++){deallocateRingassign(&a[0].r[i]);}
00105         free(a[0].r);}
00106  if(a[0].two != NULL && a[0].two != 0x0){
00107         for(i=0;i<a[0].ntwo;i++){deallocateTwoassign(&a[0].two[i]);}
00108         free(a[0].two);}
00109  // free top
00110  if(a[0].Desc != NULL && a[0].Desc != 0x0){free(a[0].Desc);}
00111  if(a[0].s != NULL && a[0].s != 0x0){free(a[0].s);}
00112  if(a[0].b != NULL && a[0].b != 0x0){free(a[0].b);}
00113  if(a[0].t != NULL && a[0].t != 0x0){free(a[0].t);}
00114  if(a[0].w != NULL && a[0].w != 0x0){free(a[0].w);}
00115  if(a[0].rk != NULL && a[0].rk != 0x0){free(a[0].rk);}
00116  return ;
00117 }
00118 void deallocateAssnBrief(assn_brief *ab){
00119  if(ab[0].Desc != NULL && ab[0].Desc != 0x0){free(ab[0].Desc);}
00120  return ;
00121 }
00122 void deallocateAtommode(atommode *a){
00123  if(a[0].s != NULL && a[0].s != 0x0){free(a[0].s);}
00124  if(a[0].b != NULL && a[0].b != 0x0){free(a[0].b);}
00125  if(a[0].t != NULL && a[0].t != 0x0){free(a[0].t);}
00126  return ;
00127 }
00128 /********** structures from stats.h ****************/
00129 void deallocateStatsarray(statsarray *s){
00130  if(s[0].d != NULL && s[0].d != 0x0){free(s[0].d);}
00131  return ;
00132 }
00133 void deallocateAutocorr(autocorr *a){
00134  if(a[0].a != NULL && a[0].a != 0x0){free(a[0].a);}
00135  return ;
00136 } 
 All Classes Files Functions Variables Typedefs Defines