/**************************************************************************\ * Hybrid parameters are stored in their own hybrid structures. But, * * because the components are coupled, and because of convolution issues * * when you have high resolution images, each component needs to have its * * own derivative images for the break and softening radii; they are * * stored in 'fpar->high' structures. However, the fit parameter block * * in 'fpar->high' is only linked back to the hybrid structure, which is * * stored in the main object structure, 'fpar' as one of the components. * \**************************************************************************/ #include #include #include "structs.h" void link_hybrid_fpar (struct fitpars *fpar) { void link_fpar_high (struct fitpars *fpar, struct fitpars *hptr, int comps[]); struct fitpars *hptr, *fptr; int i, j; hptr = fpar; /* Hybrid pointer */ while (hptr != NULL) { if (strncmp (hptr->objtype, "hybrid", 6) == 0) { link_fpar_high (fpar, hptr, hptr->outer); link_fpar_high (fpar, hptr, hptr->inner); }; hptr = hptr->next; }; } /******************************************************************************\ * Creates a new hybrid storage space in fpar->high for each object which * * is involved in linking. This new space does *not* store independent * * parameters to be optimized. Instead, it stores *pointers* which refer * * back to the main 'fpar' structure of the corresponding hybrid component. * * For instance, if the second Sersic component is involved in linking, and * * the information about the link is stored as the 4th component in the main * * fpar object structure (i.e. fpar->objtype="hybrid"), then the Sersic * * component will have a high order struct, i.e. fpar->high->objtype="hybrid", * * which refers back to that 4th component. * * * * The reason why this is necessary is explained above. * \******************************************************************************/ void link_fpar_high (struct fitpars *fpar, struct fitpars *hptr, int comps[]) { int i, j; struct fitpars *fptr, *tptr; for (i=1; i <= comps[0]; i++) { tptr = (struct fitpars *) malloc (sizeof (struct fitpars)); tptr->npars = hptr->npars; tptr->inner = hptr->inner; tptr->outer = hptr->outer; tptr->a = hptr->a; tptr->ia = hptr->ia; tptr->sig = hptr->sig; tptr->next = NULL; /*-------------------------------------------------------------------\ | The hybrid "mirror" in fpar->high struct needs to keep track of | | the corresponding comp where the main hybrid pars are stored. | \-------------------------------------------------------------------*/ tptr->hybnum = hptr->compnum; /*------------------------------------------------------------------\ | If the hybrid parameters have high order modes themselves, the | | subcomponents being linked will inherit the high order struct | | wholesale. Note that the struct is being inherited rather than | | that the elements in the struct are copied one-by-one. | \------------------------------------------------------------------*/ if (hptr->high != NULL) tptr->high = hptr->high; else tptr->high = NULL; strcpy (tptr->objtype, hptr->objtype); /*-----------------------------------------------------------------\ | Now advance down the list to the components that are involved | | in linking. The component numbers are stored in comps[i]. | \-----------------------------------------------------------------*/ fptr = fpar; /* fitpar pointer */ for (j=1; j < comps[i]; j++) fptr = fptr->next; tptr->compnum = fptr->compnum; /*------------------------------------------------------------------\ | This new structure now holding the hybrid information is tacked | | on to THE END of the fpar->high structure, of the component | | involved in linking. | \------------------------------------------------------------------*/ if (fptr->high != NULL) { fptr = fptr->high; while (fptr->next != NULL) /* Go to the end */ fptr = fptr->next; fptr->next = tptr; } else fptr->high = tptr; }; }