Skip to content
Snippets Groups Projects
LoadRawHelper.cpp 43 KiB
Newer Older
    void LoadRawHelper::loadSpectra(FILE* file,const int& period,const int& total_specs,
      DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec)
Peterson, Peter's avatar
Peterson, Peter committed
      int64_t histCurrent = -1;
      int64_t wsIndex=0;
      int64_t numberOfPeriods=static_cast<int64_t>(isisRaw->t_nper);
      double histTotal = static_cast<double>(total_specs * numberOfPeriods);
      int64_t noTimeRegimes=getNumberofTimeRegimes();
      int64_t lengthIn = static_cast<int64_t>(isisRaw->t_ntc1+1);
      for (specid_t i = 1; i <= m_numberOfSpectra; ++i)
Peterson, Peter's avatar
Peterson, Peter committed
        int64_t histToRead = i + period * (m_numberOfSpectra + 1);
        if ((i >= m_spec_min && i < m_spec_max) || 
           (m_list && find(m_spec_list.begin(), m_spec_list.end(),i) != m_spec_list.end()))
        {
          progress(m_prog, "Reading raw file data...");

          //read spectrum from raw file
          readData(file, histToRead);
          //set worksapce data
          setWorkspaceData(ws_sptr, timeChannelsVec, wsIndex, i,noTimeRegimes,lengthIn,1);
          ++wsIndex;

          if (numberOfPeriods == 1)
          {
            if (++histCurrent % 100 == 0)
            {
Peterson, Peter's avatar
Peterson, Peter committed
              m_prog = static_cast<double>(histCurrent) / histTotal;
    /** 
     * 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) )
      {
    /**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(static_cast<int>(nread), header.full_hdr) || braw )
      }
    }
    /**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)
      {
      int nread(static_cast<int>(fread(
        &header,sizeof(unsigned char), IDataFileChecker::g_hdr_bytes, fp)));
      header.full_hdr[IDataFileChecker::g_hdr_bytes] = '\0';
      if (fclose(fp) != 0)
      {
      } 
      
      if( isRawFileHeader(nread, header.full_hdr) )
      {