Skip to content
Snippets Groups Projects
LoadRawHelper.cpp 41.3 KiB
Newer Older
          //set worksapce data
          setWorkspaceData(ws_sptr, timeChannelsVec, wsIndex, i,noTimeRegimes,lengthIn,1);
          ++wsIndex;

          if (numberOfPeriods == 1)
          {
            if (++histCurrent % 100 == 0)
            {
              m_prog = double(histCurrent) / histTotal;
            }
            interruption_point();
          }

        }
        else
        {
          skipData(file, histToRead);
        }
    /** 
     * Check if the buffer looks like a RAW file header by looking at
     * at the "address of RUN and INST section" attribute - if there, it's an ISIS raw file.
     * @param nread The number of bytes in the buffer
     * @param buffer A buffer of nread bytes of the file
     * @returns True if this looks like an ISIS raw file
     */
    bool LoadRawHelper::isRawFileHeader(const int nread, const unsigned char* buffer) const
    {
      if( nread > 88 && (buffer[84] == 32) && (buffer[88] == 126) )
      {
	return true;
      }
      else return false;
    }
    
    /**This method does a quick file check by checking the no.of bytes read nread params and header buffer
     *  @param filePath- path of the file including name.
     *  @param nread :: no.of bytes read
     *  @param header :: The first 100 bytes of the file as a union
     *  @return true if the given file is of type which can be loaded by this algorithm
     */
    bool LoadRawHelper::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header)
    {
      std::string extn=extension(filePath);
      bool braw = (!extn.compare("raw")||!extn.compare("add")||extn[0]=='s') ? true : false;
      if( isRawFileHeader(nread, header.full_hdr) || braw )
      {
	return true;
      }
      else
      {
	return false;
      }
    }
    /**Checks the file by opening it and reading few lines 
     *  @param filePath :: name of the file inluding its path
     *  @return an integer value how much this algorithm can load the file 
     */
    int LoadRawHelper::fileCheck(const std::string& filePath)
    {
      /* Open the file and read in the first bufferSize bytes - these will
       * be used to determine the type of the file
       */
      int bret=0;
      FILE* fp = fopen(filePath.c_str(), "rb");
      if (fp == NULL)
      {
	return bret;
      }
      file_header header;
      int nread = fread(&header,sizeof(unsigned char), IDataFileChecker::g_hdr_bytes, fp);
      header.full_hdr[IDataFileChecker::g_hdr_bytes] = '\0';
      if (nread == -1)
      {
	fclose(fp);
	return bret;
      }
      if (fclose(fp) != 0)
      {
      } 
      
      if( isRawFileHeader(nread, header.full_hdr) )
      {
	bret=80;
      }
      return bret;
    }