Changeset 18146 for trunk/psModules/src/imcombine/pmSubtractionKernels.c
- Timestamp:
- Jun 16, 2008, 11:59:43 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionKernels.c
r16607 r18146 612 612 613 613 614 // Intermediate string parsing functions required because of different APIs for strtol and strtof 615 static inline int parseStringInt(const char *string) 616 { 617 return strtol(string, NULL, 10); 618 } 619 static inline float parseStringFloat(const char *string) 620 { 621 return strtof(string, NULL); 622 } 623 624 625 // Parse a string of a number, up to some delimiter, and advance past the delimiter 626 #define PARSE_STRING_NUMBER(TARGET, STRING, DELIM, PARSEFUNC) { \ 627 char *start = STRING; /* Start of string */ \ 628 char *end = strchr(STRING, DELIM); /* End of string */ \ 629 if (!end) { \ 630 psAbort("End of string encountered"); \ 631 } \ 632 int stringSize = end - STRING; /* Size of string with value, NOT including \0 */ \ 633 char value[stringSize + 1]; /* String to parse */ \ 634 strncpy(value, start, stringSize); \ 635 value[stringSize] = '\0'; \ 636 TARGET = PARSEFUNC(value); \ 637 STRING += stringSize + 1; /* Advance past delimiter */ \ 638 } 639 640 641 pmSubtractionKernels *pmSubtractionKernelsFromDescription(const char *description, int bgOrder, 642 pmSubtractionMode mode) 643 { 644 PS_ASSERT_STRING_NON_EMPTY(description, NULL); 645 646 if (bgOrder != 0) { 647 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Background order %d is not yet supported.", bgOrder); 648 return false; 649 } 650 651 pmSubtractionKernelsType type = PM_SUBTRACTION_KERNEL_NONE; // Type of kernel 652 int size = 0; // Half-size of kernel 653 int spatialOrder = 0; // Order of spatial variations 654 const psVector *fwhms = NULL; // FWHM of Gaussians 655 const psVector *orders = NULL; // Polynomial order for each FWHM 656 int inner = 0; // Size of inner region 657 int binning = 0; // Binning to use 658 int ringsOrder = 0; // Polynomial order for rings 659 660 if (strncmp(description, "ISIS", 4) == 0) { 661 // XXX Support for GUNK 662 if (strstr(description, "+POIS")) { 663 type = PM_SUBTRACTION_KERNEL_GUNK; 664 psAbort("Deciphering GUNK kernels (%s) is not currently supported.", description); 665 } else { 666 type = PM_SUBTRACTION_KERNEL_ISIS; 667 char *ptr = (char*)description + 5; // Eat "ISIS(" 668 PARSE_STRING_NUMBER(size, ptr, ',', parseStringInt); 669 670 // Count the number of Gaussians 671 int numGauss = 0; 672 for (char *string = ptr; string; string = strchr(string, '(')) { 673 numGauss++; 674 } 675 676 fwhms = psVectorAlloc(numGauss, PS_TYPE_F32); 677 orders = psVectorAlloc(numGauss, PS_TYPE_S32); 678 679 for (int i = 0; i < numGauss; i++) { 680 ptr++; // Eat the '(' 681 PARSE_STRING_NUMBER(fwhms->data.F32[i], ptr, ',', parseStringFloat); // Eat "1.234," 682 PARSE_STRING_NUMBER(orders->data.S32[i], ptr, ')', parseStringInt); // Eat "3)" 683 } 684 685 ptr++; // Eat ',' 686 spatialOrder = parseStringInt(ptr); 687 } 688 } else if (strncmp(description, "RINGS", 5) == 0) { 689 type = PM_SUBTRACTION_KERNEL_RINGS; 690 char *ptr = (char*)description + 6; 691 PARSE_STRING_NUMBER(size, ptr, ',', parseStringInt); 692 PARSE_STRING_NUMBER(inner, ptr, ',', parseStringInt); 693 PARSE_STRING_NUMBER(ringsOrder, ptr, ',', parseStringInt); 694 PARSE_STRING_NUMBER(spatialOrder, ptr, ')', parseStringInt); 695 } else { 696 psAbort("Deciphering kernels other than ISIS and RINGS is not currently supported."); 697 } 698 699 700 return pmSubtractionKernelsGenerate(type, size, spatialOrder, fwhms, orders, 701 inner, binning, ringsOrder, mode); 702 } 703 704 614 705 pmSubtractionKernelsType pmSubtractionKernelsTypeFromString(const char *type) 615 706 {
Note:
See TracChangeset
for help on using the changeset viewer.
