Ejemplo n.º 1
0
int MoviePvp::checkpointWrite(const char * cpDir){
   int status = ImagePvp::checkpointWrite(cpDir);

   parent->writeArrayToFile(cpDir, getName(), "FrameNumState", frameNumbers, parent->getNBatch());

   //Only do a checkpoint TimestampState if there exists a timestamp file
   if (timestampFile) {
      long timestampFilePos = getPV_StreamFilepos(timestampFile);
      parent->writeScalarToFile(cpDir, getName(), "TimestampState", timestampFilePos);
   }

   return status;
}
Ejemplo n.º 2
0
//This function takes care of rewinding for frame files
const char * Movie::advanceFileName(int batchIdx) {
   // IMPORTANT!! This function should only be called by getNextFileName(int), and only by the root process
   assert(parent->columnId()==0);

   //Restore position of batch Idx
   PV_fseek(filenamestream, batchPos[batchIdx], SEEK_SET);

   int c;
   size_t maxlen = PV_PATH_MAX;
   bool reset = false;

   // Ignore blank lines
   bool hasrewound = false;
   bool lineisblank = true;
   while(lineisblank) {
      // if at end of file (EOF), rewind
      if ((c = fgetc(filenamestream->fp)) == EOF) {
         PV_fseek(filenamestream, 0L, SEEK_SET);
         frameNumbers[0] = -1;
         fprintf(stderr, "Movie %s: EOF reached, rewinding file \"%s\"\n", name, inputPath);
         if (hasrewound) {
            fprintf(stderr, "Movie %s: filenamestream \"%s\" does not have any non-blank lines.\n", name, filenamestream->name);
            exit(EXIT_FAILURE);
         }
         hasrewound = true;
         reset = true;
      }
      else {
         ungetc(c, filenamestream->fp);
      }

      //Always do at least once
      int loopCount = 0;
      do{
         char * path = fgets(inputfile, maxlen, filenamestream->fp);
         if (path != NULL) {
            filenamestream->filepos += strlen(path);
            path[PV_PATH_MAX-1] = '\0';
            size_t len = strlen(path);
            if (len > 0) {
               if (path[len-1] == '\n') {
                  path[len-1] = '\0';
                  len--;
               }
            }
            for (size_t n=0; n<len; n++) {
               if (!isblank(path[n])) {
                  frameNumbers[batchIdx]++;
                  lineisblank = false;
                  break;
               }
            }
            loopCount++;
         }
      }while(resetToStartOnLoop && reset && loopCount < startFrameIndex[batchIdx]);

      assert(strlen(inputfile)>(size_t) 0);
      // assert(inputfile && strlen(inputfile)>(size_t) 0);
      // current version of clang generates a warning since inputfile is a member variable declared as an array and therefore always non-null.
      // Keeping the line in case inputfile is changed to be malloc'd instead of declared as an array.
      char * expandedpath = expandLeadingTilde(inputfile);
      if (strlen(expandedpath)>=PV_PATH_MAX) {
         fprintf(stderr, "Movie \"%s\": input line \"%s\" from imageListPath is too long.\n", name, expandedpath);
         exit(EXIT_FAILURE);
      }
      strncpy(inputfile, expandedpath, PV_PATH_MAX);
      free(expandedpath);
   }
   //Save batch position
   batchPos[batchIdx] = getPV_StreamFilepos(filenamestream);
   return inputfile;
}