Newer
Older
Gigg, Martyn Anthony
committed
}
Gigg, Martyn Anthony
committed
void LoadRawHelper::loadSpectra(FILE* file,const int& period,const int& total_specs,
Gigg, Martyn Anthony
committed
DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec)
Gigg, Martyn Anthony
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);
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
//loop through spectra
for (specid_t i = 1; i <= m_numberOfSpectra; ++i)
Gigg, Martyn Anthony
committed
{
int64_t histToRead = i + period * (m_numberOfSpectra + 1);
Gigg, Martyn Anthony
committed
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)
{
Gigg, Martyn Anthony
committed
}
interruption_point();
}
}
else
{
skipData(file, histToRead);
}
Gigg, Martyn Anthony
committed
}
}
Sofia Antony
committed
Sofia Antony
committed
Gigg, Martyn Anthony
committed
/**
* 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) )
{
Gigg, Martyn Anthony
committed
return true;
Gigg, Martyn Anthony
committed
}
else return false;
}
Sofia Antony
committed
Gigg, Martyn Anthony
committed
/**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 )
Gigg, Martyn Anthony
committed
{
Gigg, Martyn Anthony
committed
return true;
Gigg, Martyn Anthony
committed
}
else
{
Gigg, Martyn Anthony
committed
return false;
Gigg, Martyn Anthony
committed
}
}
/**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)
{
Gigg, Martyn Anthony
committed
return bret;
Gigg, Martyn Anthony
committed
}
file_header header;
int nread(static_cast<int>(fread(
&header,sizeof(unsigned char), IDataFileChecker::g_hdr_bytes, fp)));
Gigg, Martyn Anthony
committed
header.full_hdr[IDataFileChecker::g_hdr_bytes] = '\0';
Sofia Antony
committed
Gigg, Martyn Anthony
committed
if (fclose(fp) != 0)
{
}
if( isRawFileHeader(nread, header.full_hdr) )
{
Gigg, Martyn Anthony
committed
bret=80;
Gigg, Martyn Anthony
committed
}
return bret;
}
Sofia Antony
committed
Sofia Antony
committed
Gigg, Martyn Anthony
committed
} // namespace DataHandling
Russell Taylor
committed
} // namespace Mantid