IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18146


Ignore:
Timestamp:
Jun 16, 2008, 11:59:43 AM (18 years ago)
Author:
Paul Price
Message:

Adding I/O functions for pmSubtractionKernels, so we can read/write the created kernels.

Location:
trunk/psModules/src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/Makefile.am

    r15839 r18146  
    1010        pmSubtraction.c         \
    1111        pmSubtractionEquation.c \
     12        pmSubtractionIO.c       \
    1213        pmSubtractionKernels.c  \
    1314        pmSubtractionMask.c     \
     
    2425        pmSubtraction.h         \
    2526        pmSubtractionEquation.h \
     27        pmSubtractionIO.h       \
    2628        pmSubtractionKernels.h  \
    2729        pmSubtractionMask.h     \
  • trunk/psModules/src/imcombine/pmSubtractionKernels.c

    r16607 r18146  
    612612
    613613
     614// Intermediate string parsing functions required because of different APIs for strtol and strtof
     615static inline int parseStringInt(const char *string)
     616{
     617    return strtol(string, NULL, 10);
     618}
     619static 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
     641pmSubtractionKernels *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
    614705pmSubtractionKernelsType pmSubtractionKernelsTypeFromString(const char *type)
    615706{
  • trunk/psModules/src/imcombine/pmSubtractionKernels.h

    r17297 r18146  
    177177    );
    178178
     179/// Generate a kernel using the description
     180pmSubtractionKernels *pmSubtractionKernelsFromDescription(
     181    const char *description,            ///< Description of kernel
     182    int bgOrder,                        ///< Polynomial order for background fitting
     183    pmSubtractionMode mode              ///< Mode for subtraction
     184    );
     185
    179186/// Return the appropriate type from a string
    180187pmSubtractionKernelsType pmSubtractionKernelsTypeFromString(const char *string // String name for kernel type
  • trunk/psModules/src/psmodules.h

    r17036 r18146  
    8686#include <pmSubtractionKernels.h>
    8787#include <pmSubtractionMatch.h>
     88#include <pmSubtractionIO.h>
    8889#include <pmSubtractionParams.h>
    8990#include <pmSubtractionMask.h>
Note: See TracChangeset for help on using the changeset viewer.