/** @file  psConfigure.c
 *
 *  @brief Contains the declarations for initialization, memory finalization,
 *   and configuration.
 *
 *  These functions initalize psLib data before the beginning of a run and
 *  remove (finalize) the same data after the run is complete. A function is
 *  also provided to return the current psLib version.
 *
 *  @ingroup Configure
 *
 *  @author Ross Harman, MHPCC
 *  @author Robert DeSonia, MHPCC
 *
 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2005-11-16 20:52:23 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 */
#include "psString.h"
#include "psTime.h"
#include "psEarthOrientation.h"
#include "psError.h"
#include "psConfigure.h"
#include "psErrorText.h"
#include "config.h"

char* psLibVersion(void)
{
    char version[80];
    snprintf(version,80,"%s-v%s",PACKAGE_NAME,PACKAGE_VERSION);

    return(psStringCopy(version));
}

void psLibInit(const char* timeConfig)
{
    // XXX: Still needs error codes to be set
    // XXX: Still needs random number generator initialization

    if(!p_psTimeInit(timeConfig)) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psTime");
        return;
    }
    if(!p_psEOCInit()) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psEOC");
        return;
    }
}

void psLibFinalize(void)
{
    // Users of persistent memory should free them in this function

    if(!p_psTimeFinalize()) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psTime");
        return;
    }
    if(!p_psEOCFinalize()) {
        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psEOC");
        return;
    }
}
