/**************************************************************************\ * These two subroutines together delete the entire fitpars structure. * * The second subroutine deletes just a single object completely, and * * the first subroutine simply links them together. * \**************************************************************************/ #include #include "nrutil.h" #include "structs.h" void del_fitpars_struct (struct fitpars *fpar) { void del_one_obj (struct fitpars *fpar); if (fpar->next != NULL) { del_fitpars_struct (fpar->next); fpar->next = NULL; }; del_one_obj (fpar); } /************************************************************************\ * Delete a single object completely, from the classical parameters * * down to all the high order correction terms. * * * * Setting the 'high' flag to 1, tells the subroutine that it's * * currently within the higher order link structure instead of the main * * structure. It acts like a railroad flow control, diverting the flow * * of the copying in the right direction. * \************************************************************************/ void del_one_obj (struct fitpars *fpar) { static int high = 0; /*---------------------------------------------------------------------\ | Note that the truncation mirror parameters are merely pointers, so | | we don't need to free individual fpar->a, ia, outer, etc.. But, | | we do need to free the structure which holds those parameters. | | Also, we don't need to delete fpar->high->high parameters, because | | it is itself entirely a pointer back to fpar->trunc->high, i.e. | | high order terms for the truncation function. | \---------------------------------------------------------------------*/ if ( fpar != NULL ) { if (fpar->outer != NULL) { free ((int *)fpar->outer); fpar->outer = NULL; }; if (fpar->inner != NULL) { free ((int *)fpar->inner); fpar->inner = NULL; }; if (fpar->a != NULL) { free ((float *)fpar->a); fpar->a = NULL; }; if (fpar->ia != NULL) { free ((int *)fpar->ia); fpar->ia = NULL; }; if (fpar->sig != NULL) { free ((float *)fpar->sig); fpar->sig = NULL; }; } /******************************************************************\ * Recursively go down the higher order linked list till the end. * \******************************************************************/ if (fpar->next != NULL && high == 1) { del_one_obj (fpar->next); fpar->next = NULL; } /****************************************************************\ * If there are higher order terms, enter that list, as long as * * the current component is not just a mirror of the truncation * * component. * \****************************************************************/ if (fpar->high != NULL) { high += 1; del_one_obj (fpar->high); high -= 1; fpar->high = NULL; }; free ((struct fitpars *) fpar); }