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

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

#include "ppStats.h"

psMetadata *ppStats(psMetadata *out,    // Output metadata
                    pmFPA *fpa,         // FPA for which to get statistics
                    pmFPAview *view,    // View for analysis
                    pmConfig *config    // Configuration
    )
{
    // Get the options, open the files
    ppStatsData *data = ppStatsSetupFromRecipe(NULL, config);

    if (data->fpa) {
        psFree(data->fpa);
    }
    data->fpa = psMemIncrRefCounter(fpa);

    if (data->view) {
        psFree(data->view);
    }
    data->view = psMemIncrRefCounter(view);

    // Go through the FPA and do the hard work
    out = ppStatsLoop(out, data, config);

    psFree(data);

    return out;
}
