1
/*=========================================================================
3
Program: Ionization FRont Interactive Tool (IFRIT)
7
Copyright (c) 2002-2006 Nick Gnedin
10
This file may be distributed and/or modified under the terms of the
11
GNU General Public License version 2 as published by the Free Software
12
Foundation and appearing in the file LICENSE.GPL included in the
13
packaging of this file.
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
19
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
=========================================================================*/
1
/*=========================================================================
3
Program: Ionization FRont Interactive Tool (IFRIT)
7
Copyright (c) 2002-2006 Nick Gnedin
10
This file may be distributed and/or modified under the terms of the
11
GNU General Public License version 2 as published by the Free Software
12
Foundation and appearing in the file LICENSE.GPL included in the
13
packaging of this file.
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
19
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
=========================================================================*/
29
29
#include "ifileloader.h"
56
56
iFileLoader_Private::SwapBytes(p); \
58
void iFileLoader::SwapBytesRange(_type_ *p, long count) \
58
void iFileLoader::SwapBytesRange(_type_ *p, vtkIdType count) \
60
60
iFileLoader_Private::SwapBytesRange(p,count); \
63
63
#define IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(_type_) \
64
bool iFileLoader::ReadBlock(iFile& F, _type_ *p, long len, float updateStart, float updateDuration) \
64
bool iFileLoader::ReadBlock(iFile& F, _type_ *p, vtkIdType len, float updateStart, float updateDuration) \
66
66
return iFileLoader_Private::ReadBlockToArray(F,p,len,updateStart,updateDuration,mIsBigEndian!=iSystem::IsBigEndianMachine(),mObserver); \
70
70
return ReadingBuffer(&d,1UL,iFileLoader_Private::TypeIndex(&d),sizeof(_type_)); \
72
iFileLoader::ReadingBuffer iFileLoader::Buffer(_type_ *d, long l) const \
72
iFileLoader::ReadingBuffer iFileLoader::Buffer(_type_ *d, vtkIdType l) const \
74
74
return ReadingBuffer(d,l,iFileLoader_Private::TypeIndex(d),sizeof(_type_)); \
176
176
// Check validity of numbers
178
bool IsNumberValid(int v){ return true; }
179
bool IsNumberValid(long v){ return true; }
180
bool IsNumberValid(float v){ return (-iMath::_FloatMax<=v && v<=iMath::_FloatMax); }
181
bool IsNumberValid(double v){ return (-iMath::_DoubleMax<=v && v<=iMath::_DoubleMax); }
178
bool IsNumberValid(vtkTypeInt32 v){ return true; }
179
bool IsNumberValid(vtkTypeInt64 v){ return true; }
180
bool IsNumberValid(vtkTypeFloat32 v){ return (-iMath::_FloatMax<=v && v<=iMath::_FloatMax); }
181
bool IsNumberValid(vtkTypeFloat64 v){ return (-iMath::_DoubleMax<=v && v<=iMath::_DoubleMax); }
189
const int _Float = 3;
190
const int _Double = 4;
187
const int _Int32 = 1;
188
const int _Int64 = 2;
189
const int _Float32 = 3;
190
const int _Float64 = 4;
192
int TypeIndex(int *){ return _Int; }
193
int TypeIndex(long *){ return _Long; }
194
int TypeIndex(float *){ return _Float; }
195
int TypeIndex(double *){ return _Double; }
192
int TypeIndex(vtkTypeInt32 *){ return _Int32; }
193
int TypeIndex(vtkTypeInt64 *){ return _Int64; }
194
int TypeIndex(vtkTypeFloat32 *){ return _Float32; }
195
int TypeIndex(vtkTypeFloat64 *){ return _Float64; }
199
199
// Read blocks of data from a file
201
201
template<class T>
202
bool ReadBlockToArray(iFile& F, T *p, long len, float updateStart, float updateDuration, bool swapbytes, iProgressEventObserver *observer)
202
bool ReadBlockToArray(iFile& F, T *p, vtkIdType len, float updateStart, float updateDuration, bool swapbytes, iProgressEventObserver *observer)
204
const long nline = 16384L;
205
long nread, l, nstep = (len+nline-1)/nline;
204
const vtkIdType nline = 16384L;
205
vtkIdType nread, l, nstep = (len+nline-1)/nline;
206
206
float ustep = updateDuration/nstep;
208
208
for(l=0; l<nstep; l++)
237
int *d = (int *)b.Data;
238
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
242
long *d = (long *)b.Data;
243
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
247
float *d = (float *)b.Data;
248
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
252
double *d = (double *)b.Data;
237
vtkTypeInt32 *d = (vtkTypeInt32 *)b.Data;
238
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
242
vtkTypeInt64 *d = (vtkTypeInt64 *)b.Data;
243
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
247
vtkTypeFloat32 *d = (vtkTypeFloat32 *)b.Data;
248
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
252
vtkTypeFloat64 *d = (vtkTypeFloat64 *)b.Data;
253
253
return iFileLoader_Private::ReadBlockToArray(F,d,b.Length,updateStart,updateDuration,swapbytes,observer);
605
605
void iFileLoader::ShiftData(double dr[3])
610
610
mObserver->Started(iProgressEventObserver::_Shifting);
611
611
mObserver->SetProgress(0.0);
616
dx[i] = dr[i] - mShift[i];
617
if(fabs(dx[i]) > dxmax) dxmax = fabs(dx[i]);
622
for(i=0; i<this->NumStreams(); i++) if(mStreams[i]->ReleasedData != 0)
624
this->ShiftDataBody(mStreams[i]->ReleasedData,dx);
626
for(i=0; i<3; i++) mShift[i] = dr[i];
613
for(i=0; i<3; i++) dx[i] = dr[i] - mShift[i];
615
for(i=0; i<this->NumStreams(); i++) if(mStreams[i]->ReleasedData != 0)
617
this->ShiftDataBody(mStreams[i]->ReleasedData,dx);
620
for(i=0; i<3; i++) mShift[i] = dr[i];
629
622
mObserver->Finished();
685
678
bool iFileLoader::ReadFortranRecord(iFile& F, const ReadingBuffer &b1, const ReadingBuffer &b2, float updateStart, float updateDuration, bool autoswap)
688
long len = b1.Length*b1.Size + b2.Length*b2.Size;
680
vtkIdType lrec1, lrec2;
681
vtkIdType len = b1.Length*b1.Size + b2.Length*b2.Size;
689
682
float f1 = float(b1.Length*b1.Size)/len;
690
683
float f2 = float(b2.Length*b2.Size)/len;
706
699
bool iFileLoader::ReadFortranRecord(iFile& F, const ReadingBuffer &b1, const ReadingBuffer &b2, const ReadingBuffer &b3, float updateStart, float updateDuration, bool autoswap)
709
long len = b1.Length*b1.Size + b2.Length*b2.Size + b3.Length*b3.Size;
701
vtkIdType lrec1, lrec2;
702
vtkIdType len = b1.Length*b1.Size + b2.Length*b2.Size + b3.Length*b3.Size;
710
703
float f1 = float(b1.Length*b1.Size)/len;
711
704
float f2 = float(b2.Length*b2.Size)/len;
712
705
float f3 = float(b3.Length*b3.Size)/len;
752
bool iFileLoader::ReadFortranHeaderFooter(iFile& F, long &lrec)
745
bool iFileLoader::ReadFortranHeaderFooter(iFile& F, vtkIdType &lrec)
754
747
bool ret = false;
756
if(mFortranHeaderFooterLength == sizeof(long))
749
if(mFortranHeaderFooterLength == 8)
758
ret = F.ReadBlock(&lrec,sizeof(long));
759
if(ret && mIsBigEndian!=iSystem::IsBigEndianMachine()) this->SwapBytes(lrec);
752
ret = F.ReadBlock(<mp,8);
755
if(mIsBigEndian != iSystem::IsBigEndianMachine()) this->SwapBytes(ltmp);
756
if(sizeof(vtkIdType) < 8)
758
IERROR_LOW("VTK is compiled with 32-bit Ids. The record length of this file is 64-bits, it cannot be read with this VTK installation. To be able to read this file you will have to recompile VTK with the advanced option VTK_USE_64BIT_IDS set to ON and then recompile IFrIT.");
761
else if(mFortranHeaderFooterLength == sizeof(int))
764
else if(mFortranHeaderFooterLength == 4)
764
ret = F.ReadBlock(<mp,sizeof(int));
767
ret = F.ReadBlock(<mp,4);
767
770
if(mIsBigEndian != iSystem::IsBigEndianMachine()) this->SwapBytes(ltmp);
780
bool iFileLoader::DetectFortranFileStructure(iFile &F, long len)
783
bool iFileLoader::DetectFortranFileStructure(iFile &F, vtkIdType len)
783
// Try int-sized records
786
// Try 4-byte records
785
if(AnalyzeFirstRecordForType<int>(F,len,mIsBigEndian))
788
if(AnalyzeFirstRecordForType<vtkTypeInt32>(F,len,mIsBigEndian))
787
mFortranHeaderFooterLength = sizeof(int);
790
mFortranHeaderFooterLength = sizeof(vtkTypeInt32);
791
// Try long-sized records
794
// Try 8-byte records
793
if(AnalyzeFirstRecordForType<long>(F,len,mIsBigEndian))
796
if(AnalyzeFirstRecordForType<vtkTypeInt64>(F,len,mIsBigEndian))
795
mFortranHeaderFooterLength = sizeof(long);
798
mFortranHeaderFooterLength = sizeof(vtkTypeInt64);
865
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(int);
866
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(long);
867
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(float);
868
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(double);
869
//IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(unsigned int);
870
//IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(unsigned long);
868
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(vtkTypeInt32);
869
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(vtkTypeInt64);
870
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(vtkTypeFloat32);
871
IDATASUBJECT_DEFINE_SWAP_BYTES_FUNCTIONS(vtkTypeFloat64);
872
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(int);
873
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(long);
874
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(float);
875
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(double);
876
//IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(unsigned int);
877
//IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(unsigned long);
873
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(vtkTypeInt32);
874
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(vtkTypeInt64);
875
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(vtkTypeFloat32);
876
IDATASUBJECT_DEFINE_READ_BLOCK_FUNCTIONS(vtkTypeFloat64);