#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <strings.h>
#include <pslib.h>

#include "pmFPALevel.h"

static const char *NameNONE = "NONE";   ///< Name for PM_FPA_LEVEL_NONE
static const char *NameFPA = "FPA";     ///< Name for PM_FPA_LEVEL_FPA
static const char *NameCHIP = "CHIP";   ///< Name for PM_FPA_LEVEL_CHIP
static const char *NameCELL = "CELL";   ///< Name for PM_FPA_LEVEL_CELL
static const char *NameREADOUT = "READOUT"; ///< Name for PM_FPA_LEVEL_READOUT

const char *pmFPALevelToName(pmFPALevel level)
{

    switch (level) {
    case PM_FPA_LEVEL_NONE:
        return NameNONE;
    case PM_FPA_LEVEL_FPA:
        return NameFPA;
    case PM_FPA_LEVEL_CHIP:
        return NameCHIP;
    case PM_FPA_LEVEL_CELL:
        return NameCELL;
    case PM_FPA_LEVEL_READOUT:
        return NameREADOUT;
    default:
        psAbort("You can't get here; level = %d", level);
    }
    return NULL;
}

pmFPALevel pmFPALevelFromName(const char *name)
{
    pmFPALevel val;

    if (name == NULL) {
        val = PM_FPA_LEVEL_NONE;
    } else if (!strcasecmp(name, "FPA"))     {
        val = PM_FPA_LEVEL_FPA;
    } else if (!strcasecmp(name, "CHIP"))    {
        val = PM_FPA_LEVEL_CHIP;
    } else if (!strcasecmp(name, "CELL"))    {
        val = PM_FPA_LEVEL_CELL;
    } else if (!strcasecmp(name, "READOUT")) {
        val = PM_FPA_LEVEL_READOUT;
    } else {
        val = PM_FPA_LEVEL_NONE;
    }

    return val;
}


