#include #include #include #include "nrutil.h" #include "structs.h" /*****************************************************************************\ * Extract the Banana-fana parameter values that the user wants to fit. * \*****************************************************************************/ void bending_pars (char *string, struct fitpars *fpar) { int npars, i, mode, oldnpars; char dum[10]; struct fitpars *b, *bt, *begin; sscanf (string, " %c%d)", &dum, &mode); /*************************************************************\ * Check to see if the Banana-fana array is already active. * * First, check the fitpar tree for higher order terms * \*************************************************************/ begin = fpar; b = fpar->high; while (b!= NULL && strncmp (b->objtype, "bend", 4) != 0) b = b->next; if (b == NULL) { /* No bending terms, create new */ bt = (struct fitpars *) malloc ((size_t) (sizeof (struct fitpars))); bt->a = (float *) NULL; bt->ia = (int *) NULL; bt->sig = (float *) NULL; bt->inner = (int *) NULL; bt->outer = (int *) NULL; bt->high = (struct fitpars *) NULL; bt->next = (struct fitpars *) NULL; bt->compnum = 0; bt->npars = 0; bt->tr_num = 0; bt->outtype = 0; bt->normtype = 0; oldnpars = 0; sprintf (bt->objtype, "bend"); if (fpar->high == NULL) /* First in the list */ fpar->high = bt; else{ /* Not the first in the list; must advance downward */ fpar = fpar->high; while (fpar->next != NULL) fpar = fpar->next; fpar->next = bt; }; b = bt; } else oldnpars = b->npars; /********************************************************************\ * Note that the number of parameters is always the largest * * mode being fitted, even if some of the modes are not being used. * \********************************************************************/ npars = mode; if (npars > b->npars) { b->a = (float *) realloc (b->a, (size_t)(sizeof (float) * (npars + OFFSET))); b->ia = (int *) realloc (b->ia, (size_t)(sizeof (int) * (npars + OFFSET))); b->sig = (float *) realloc (b->sig, (size_t)(sizeof (float) * (npars + OFFSET))); b->npars = npars; /*********************************************\ * Set unused mode a's to 0 and ia's to -1. * \*********************************************/ for (i=oldnpars+1; i <= npars; i++) { b->a[i] = 0.; b->ia[i] = -1; b->sig[i] = 0.; }; } b->a[0] = 0.; b->ia[0] = -1; b->sig[0] = 0.; /*****************************************************************\ * Read input. Sometimes the user may forget to specify toggle * * mode. Set them to 1 by default. * \*****************************************************************/ b->ia[mode] = 1; sscanf (string, " %s %f %d", dum, &b->a[mode], &b->ia[mode]); if (b->a[mode] == 0. && b->ia[mode] == 1) b->a[mode] = 0.01 ; /* Initial guess of 1e-2 is for stability. *\ * Also need to do this so galfit doesn't * \* crash when the amplitude = 0. */ /*****************************************************************\ * Lastly, check to see if both a[i] and ia[i] are 0. If so, * * that effectively means this parameter is disabled. We should * * set ia[i] = -1 so this item is not listed as being fitted. * * On the other hand, we should reduce f->npars to make sure it * * accurately reflects the number of highest parameter. * \*****************************************************************/ oldnpars = 0; for (i=1; i <= b->npars; i++) { if (b->a[i] == 0. && b->ia[i] == 0) b->ia[i] = -1; if (b->a[i] != 0. || b->ia[i] == 1) oldnpars = i+1; }; if (oldnpars < b->npars) { b->npars = oldnpars; b->a = (float *) realloc (b->a, (size_t)(sizeof (float) * (oldnpars + OFFSET))); b->ia = (int *) realloc (b->ia, (size_t)(sizeof (int) * (oldnpars + OFFSET))); b->sig = (float *) realloc (b->sig, (size_t)(sizeof (float) * (oldnpars + OFFSET))); }; /*****************************************************\ * If everything's deleted, delete structure as well * \*****************************************************/ if (b->npars == 0) { fpar = begin; if (strncmp (fpar->high->objtype, "bend", 4) == 0) { free (fpar->high); fpar->high = NULL; } else { fpar = fpar->high; while (strncmp (fpar->next->objtype, "bend", 4) != 0) fpar = fpar->next; free (fpar->next); fpar->next = NULL; }; }; }