<commit_before>/*
 * ActivityProbe.cpp
 *
 *  Created on: Oct 20, 2009
 *      Author: travel
 */

#include "ActivityProbe.hpp"
#include "../layers/HyPerLayer.hpp"
#include "io.h"
#include "tiff.h"

static FILE *
pv_tiff_open_frame(const char * filename,
                   const PVLayerLoc * loc, pvdata_t ** imageBuf, long * nextFrame);

static int
pv_tiff_close_frame(FILE * fp, pvdata_t * imageBuf, long nextFrame);

static int
pv_tiff_write_frame(FILE * fp,
                    pvdata_t * data, const PVLayerLoc * loc, pvdata_t * buf, long * nextFrame);



namespace PV {

ActivityProbe::ActivityProbe(const char * filename, HyPerCol * hc, const PVLayerLoc * loc, int f)
{
   outfp = pv_tiff_open_frame(filename, loc, &outBuf, &outFrame);
}

ActivityProbe::~ActivityProbe()
{
   if (outfp != NULL) {
      pv_tiff_close_frame(outfp, outBuf, outFrame);
   }
}

int ActivityProbe::outputState(float time, PVLayer * l)
{
   int status = 0;

   if (outfp != NULL) {
      pvdata_t * data = l->activity->data;
      status = pv_tiff_write_frame(outfp, data, &l->loc, outBuf, &outFrame);
   }

   return 0;
}

} // namespace PV


static int
pv_tiff_close_frame(FILE * fp, pvdata_t * imageBuf, long nextLoc)
{
        tiff_write_finish(fp, nextLoc);
        fclose(fp);
        free(imageBuf);

        return 0;
}

static FILE *
pv_tiff_open_frame(const char * filename, const PVLayerLoc * loc, pvdata_t ** imageBuf, long * nextLoc)
{
   const int nx = loc->nx;
   const int ny = loc->ny;

   pvdata_t * buf = (pvdata_t *) malloc(nx * ny * sizeof(pvdata_t));
   *imageBuf = buf;

   FILE * fp = fopen(filename, "wb");
   if (fp == NULL) {
      fprintf(stderr, "pv_tiff_open_frame_cube: ERROR opening file %s\n", filename);<commit_msg>LayerProbe now uses HyPerLayer rather than just PVLayer.  Also renamed PVLayerProbe to LayerProbe.<commit_after>/*
 * ActivityProbe.cpp
 *
 *  Created on: Oct 20, 2009
 *      Author: travel
 */

#include "ActivityProbe.hpp"
#include "../layers/HyPerLayer.hpp"
#include "io.h"
#include "tiff.h"

static FILE *
pv_tiff_open_frame(const char * filename,
                   const PVLayerLoc * loc, pvdata_t ** imageBuf, long * nextFrame);

static int
pv_tiff_close_frame(FILE * fp, pvdata_t * imageBuf, long nextFrame);

static int
pv_tiff_write_frame(FILE * fp,
                    pvdata_t * data, const PVLayerLoc * loc, pvdata_t * buf, long * nextFrame);



namespace PV {

ActivityProbe::ActivityProbe(const char * filename, HyPerCol * hc, const PVLayerLoc * loc, int f)
{
   outfp = pv_tiff_open_frame(filename, loc, &outBuf, &outFrame);
}

ActivityProbe::~ActivityProbe()
{
   if (outfp != NULL) {
      pv_tiff_close_frame(outfp, outBuf, outFrame);
   }
}

int ActivityProbe::outputState(float time, HyPerLayer * l)
{
   int status = 0;

   if (outfp != NULL) {
      pvdata_t * data = l->clayer->activity->data;
      status = pv_tiff_write_frame(outfp, data, &l->clayer->loc, outBuf, &outFrame);
   }

   return 0;
}

} // namespace PV


static int
pv_tiff_close_frame(FILE * fp, pvdata_t * imageBuf, long nextLoc)
{
        tiff_write_finish(fp, nextLoc);
        fclose(fp);
        free(imageBuf);

        return 0;
}

static FILE *
pv_tiff_open_frame(const char * filename, const PVLayerLoc * loc, pvdata_t ** imageBuf, long * nextLoc)
{
   const int nx = loc->nx;
   const int ny = loc->ny;

   pvdata_t * buf = (pvdata_t *) malloc(nx * ny * sizeof(pvdata_t));
   *imageBuf = buf;

   FILE * fp = fopen(filename, "wb");
   if (fp == NULL) {
      fprintf(stderr, "pv_tiff_open_frame_cube: ERROR opening file %s\n", filename);
{'fraction_non_alphanumeric': 0.125979843225084, 'fraction_numerical': 0.005039193729003359, 'mean_word_length': 3.3786764705882355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4705843', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1297, 'n_words': 319}