#include "structs.h" int istrunc (char *objtype); void copy_fitstruct_elem (struct fitpars *to, struct fitpars *from); void realign_compnum (int compnum, struct fitpars *fpar); void realign_trunc_mirrors (struct fitpars *fpar) { void recopy_pars (struct fitpars *to, struct fitpars *from); struct fitpars *trptr, *objptr, *base_obj; int i, j, tr_num; trptr = fpar; while (trptr != NULL) { if (istrunc (trptr->objtype)) { for (i=1; i <= trptr->inner[0]; i++) { objptr = fpar; for (j=1; j < trptr->inner[i]; j++) objptr = objptr->next; base_obj = objptr; objptr = objptr->high; while (objptr->tr_num != trptr->compnum) objptr=objptr->next; /* Kludge to remember tr_num, because it gets *\ \* overwritten in recopy_pars */ tr_num = objptr->tr_num; recopy_pars (objptr, trptr); objptr->tr_num = tr_num; if (objptr->ia[1] == -1 || objptr->ia[2] == -1) { objptr->a[1] = base_obj->a[1]; objptr->a[2] = base_obj->a[2]; }; }; for (i=1; i <= trptr->outer[0]; i++) { objptr = fpar; for (j=1; j < trptr->outer[i]; j++) objptr = objptr->next; base_obj = objptr; objptr = objptr->high; while (objptr->tr_num != trptr->compnum) objptr=objptr->next; /* Kludge to remember tr_num, because it gets *\ \* overwritten in recopy_pars */ tr_num = objptr->tr_num; recopy_pars (objptr, trptr); objptr->tr_num = tr_num; if (objptr->ia[1] == -1 || objptr->ia[2] == -1) { objptr->a[1] = base_obj->a[1]; objptr->a[2] = base_obj->a[2]; }; }; }; trptr = trptr->next; }; /*---------------------------------------------------------------\ | For truncation purposes, the following makes sure that all | | cfpar->high->compnum = cfpar->compnum, i.e. base component | | number of the light profile. This realignment is needed by | | trunc_pars.c. | \---------------------------------------------------------------*/ while (fpar != NULL) { if (fpar->high != NULL) realign_compnum (fpar->compnum, fpar); fpar = fpar->next; }; }; /********************************************************************\ * Do a byte-by-byte copy of the parameters in the input structures * \********************************************************************/ void recopy_pars (struct fitpars *to, struct fitpars *from) { static int high = 0; /*-----------------------------------------------------------------------\ | Go down to the very end of the main and high order structures first. | \-----------------------------------------------------------------------*/ if (from->high != NULL) { high++; recopy_pars (to->high, from->high); high--; }; if (high && from->next != NULL) recopy_pars (to->next, from->next); copy_fitstruct_elem (to, from); } /*************************************************************************\ * Align the component numbers so that all the structures in fpar->high * * have the same component number as the base. This is important for * * matching up light profile with truncation models. * \*************************************************************************/ void realign_compnum (int compnum, struct fitpars *fpar) { static int high = 0; if (fpar->high != NULL) { high++; realign_compnum (compnum, fpar->high); high--; }; if (high && fpar->next != NULL) realign_compnum (compnum, fpar->next); fpar->compnum = compnum; };