Exemplo n.º 1
0
/*
 * Notes:
 * - writeImages, offsetX, offsetY are initialized by Image::initialize()
 */
int MoviePvp::initialize(const char * name, HyPerCol * hc) {
   int status = ImagePvp::initialize(name, hc);
   if (status != PV_SUCCESS) {
      fprintf(stderr, "Image::initialize failed on Movie layer \"%s\".  Exiting.\n", name);
      exit(PV_FAILURE);
   }

   //Update on first timestep
   setNextUpdateTime(parent->simulationTime() + hc->getDeltaTime());

   //PVParams * params = hc->parameters();

   //assert(!params->presentAndNotBeenRead(name, "randomMovie")); // randomMovie should have been set in ioParams
   //if (randomMovie) return status; // Nothing else to be done until data buffer is allocated, in allocateDataStructures


   ////If not pvp file, open fileOfFileNames 
   //assert(!params->presentAndNotBeenRead(name, "readPvpFile")); // readPvpFile should have been set in ioParams
   //if( getParent()->icCommunicator()->commRank()==0 && !readPvpFile) {
   //   filenamestream = PV_fopen(fileOfFileNames, "r", false/*verifyWrites*/);
   //   if( filenamestream == NULL ) {
   //      fprintf(stderr, "Movie::initialize error opening \"%s\": %s\n", fileOfFileNames, strerror(errno));
   //      abort();
   //   }
   //}

   //if (startFrameIndex <= 1){
   //   frameNumber = 0;
   //}
   //else{
   //   frameNumber = startFrameIndex - 1;
   //}
   ////Set filename as param
   //Grab number of frames from header
   
   //PV_Stream * pvstream = NULL;
   //if (getParent()->icCommunicator()->commRank()==0) {
   //   pvstream = PV::PV_fopen(inputPath, "rb", false/*verifyWrites*/);
   //}
   //int numParams = NUM_PAR_BYTE_PARAMS;
   //int params[numParams];
   //pvp_read_header(pvstream, getParent()->icCommunicator(), params, &numParams);
   //PV::PV_fclose(pvstream); pvstream = NULL;
   //fileNumFrames = params[INDEX_NBANDS]; 
   //fileNumBatches = params[INDEX_NBATCH];

   // set output path for movie frames
   if(writeImages){
      status = parent->ensureDirExists(movieOutputPath);
   }

   if(writeFrameToTimestamp){
      std::string timestampFilename = std::string(parent->getOutputPath());
      timestampFilename += "/timestamps/";
      parent->ensureDirExists(timestampFilename.c_str());
      timestampFilename += name;
      timestampFilename += ".txt";
      if(getParent()->icCommunicator()->commRank()==0){
          //If checkpoint read is set, append, otherwise, clobber
          if(getParent()->getCheckpointReadFlag()){
             struct stat statbuf;
             if (PV_stat(timestampFilename.c_str(), &statbuf) != 0) {
                fprintf(stderr, "%s \"%s\" warning: timestamp file \"%s\" unable to be found.  Creating new file.\n",
                      getKeyword(), name, timestampFilename.c_str());
                timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites());
             }
             else {
                timestampFile = PV::PV_fopen(timestampFilename.c_str(), "r+", false/*verifyWrites*/);
             }
          }
          else{
             timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites());
          }
          assert(timestampFile);
      }
   }
   return PV_SUCCESS;
}
Exemplo n.º 2
0
/*
 * Notes:
 * - writeImages, offsetX, offsetY are initialized by Image::initialize()
 */
int Movie::initialize(const char * name, HyPerCol * hc) { int status = Image::initialize(name, hc);
   if (status != PV_SUCCESS) {
      fprintf(stderr, "Image::initialize failed on Movie layer \"%s\".  Exiting.\n", name);
      exit(PV_FAILURE);
   }

   //Update on first timestep
   setNextUpdateTime(parent->simulationTime() + hc->getDeltaTime());

   PVParams * params = hc->parameters();

   //assert(!params->presentAndNotBeenRead(name, "randomMovie")); // randomMovie should have been set in ioParams
   //if (randomMovie) return status; // Nothing else to be done until data buffer is allocated, in allocateDataStructures


   //If not pvp file, open fileOfFileNames 
   //assert(!params->presentAndNotBeenRead(name, "readPvpFile")); // readPvpFile should have been set in ioParams
   if (hc->columnId()==0) {
      filenamestream = PV_fopen(inputPath, "r", false/*verifyWrites*/);
      if( filenamestream == NULL ) {
         fprintf(stderr, "Movie::initialize error opening \"%s\": %s\n", inputPath, strerror(errno));
         exit(EXIT_FAILURE);
      }
   }

   //if (!randomMovie) {
   //   //frameNumber handled here
   //   //imageFilename = strdup(getNextFileName(startFrameIndex));
   //   //assert(imageFilename != NULL);
   //}

   // set output path for movie frames
   if(writeImages){
      status = parent->ensureDirExists(movieOutputPath);
   }

   if(writeFrameToTimestamp){
      std::string timestampFilename = std::string(parent->getOutputPath());
      timestampFilename += "/timestamps/";
      parent->ensureDirExists(timestampFilename.c_str());
      timestampFilename += name;
      timestampFilename += ".txt";
      if(getParent()->icCommunicator()->commRank()==0){
          //If checkpoint read is set, append, otherwise, clobber
          if(getParent()->getCheckpointReadFlag()){
             struct stat statbuf;
             if (PV_stat(timestampFilename.c_str(), &statbuf) != 0) {
                fprintf(stderr, "%s \"%s\" warning: timestamp file \"%s\" unable to be found.  Creating new file.\n",
                      getKeyword(), name, timestampFilename.c_str());
                timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites());
             }
             else {
                timestampFile = PV::PV_fopen(timestampFilename.c_str(), "r+", false/*verifyWrites*/);
             }
          }
          else{
             timestampFile = PV::PV_fopen(timestampFilename.c_str(), "w", parent->getVerifyWrites());
          }
          assert(timestampFile);
      }
   }


   return PV_SUCCESS;
}