16 static LoggerPtr logger(Logger::getLogger(
"pz.frontal.tpzfileeqnstorage"));
33 if(fCurrentBlock==0) {
34 int64_t basepos = ftell(fIOStream);
35 fBlockPos.Push(basepos);
37 if (logger->isDebugEnabled())
39 std::stringstream sout;
40 sout <<
"basepos = " << basepos;
45 int64_t tempaddress = ftell(fIOStream);
46 fBlockPos.Push(tempaddress);
49 int64_t firstpos = ftell(fIOStream);
53 if (logger->isDebugEnabled())
55 std::stringstream sout;
56 sout <<
"Writing the position of the headers, numheaders " << fNumHeaders <<
" position ";
57 for(
int i=0; i<fNumHeaders; i++) sout << Position[i] <<
' ';
62 fwrite(Position.
begin(),
sizeof(int64_t),fNumHeaders,fIOStream);
65 int64_t firstaddress = ftell(fIOStream);
68 fseek(fIOStream,firstpos,SEEK_SET);
69 fwrite(&firstaddress,
sizeof(int64_t),1,fIOStream);
71 if (logger->isDebugEnabled())
73 std::stringstream sout;
74 sout <<
"At position " << firstpos <<
" writing the first address " << firstaddress;
79 fCurBlockPosition = firstaddress;
83 if (logger->isDebugEnabled())
85 std::stringstream sout;
86 sout <<
"Setting the file position at " << firstaddress;
90 fseek(fIOStream,firstaddress,SEEK_SET);
99 FILE *out_file = fopen(name,
"wb");
102 int64_t fPos[5] = {0};
103 int64_t firstpos = ftell(out_file);
104 fwrite(fPos,
sizeof(int64_t),5,out_file);
105 double readvec[4][100];
109 for(iblock=0; iblock<4; iblock++) {
110 int64_t currentpos = ftell(out_file);
111 fseek(out_file,firstpos+iblock*
sizeof(int64_t),SEEK_SET);
112 fwrite(¤tpos,
sizeof(int64_t),1,out_file);
113 fseek(out_file,currentpos,SEEK_SET);
114 for(i=0;i<loop_limit;i++){
115 val=number*i*(iblock+1);
116 fwrite(&val,
sizeof(
double), 1, out_file);
120 out_file = fopen(name,
"rb");
121 sizereturn = fread(fPos,
sizeof(int64_t),5,out_file);
125 for(iblock = 0; iblock<4; iblock++) {
126 fseek(out_file,fPos[iblock],SEEK_SET);
127 sizereturn = fread(readvec[iblock],
sizeof(
double),loop_limit,out_file);
129 if (sizereturn != loop_limit)
DebugStop();
138 for(int64_t i=0;i<fBlockPos.NElements();i++) {
140 if(fseek(fIOStream,fBlockPos[i],SEEK_SET)){
141 cout <<
"fseek fail on Element " << i <<
" Position " << fBlockPos[i] << endl;
145 if(!fread(&position,
sizeof(int64_t),1,fIOStream)){
146 cout <<
"fread fail on Element " << i <<
" Position " << position << endl;
147 cout <<
"EOF " << feof(fIOStream) << endl;
148 cout <<
"Error Number " << ferror(fIOStream) << endl;
151 if(fseek(fIOStream,position,SEEK_SET)){
152 cout <<
"fseek fail on Element " << i <<
" Position " << position << endl;
156 REqnArray.
Read(fIOStream);
169 for(i=fBlockPos.NElements()-1;i>=0;i--){
171 fseek(fIOStream,fBlockPos[i],SEEK_SET);
173 sizereturn = fread(&position,
sizeof(int64_t),1,fIOStream);
177 fseek(fIOStream,position,SEEK_SET);
178 REqnArray.
Read(fIOStream);
194 out <<
"Number of entries on File "<< fBlockPos.NElements() << endl;
195 for(i=0;i<fBlockPos.NElements();i++) {
197 fseek(fIOStream,fBlockPos[i],SEEK_SET);
198 REqnArray.
Read(fIOStream);
199 REqnArray.
Print(name, out);
209 if (logger->isDebugEnabled())
211 std::stringstream sout;
212 sout <<
"fCurrentBlock "<< fCurrentBlock <<
" fNumHeaders " << fNumHeaders;
217 if(fCurrentBlock%(fNumHeaders-1)==0) {
219 if (logger->isDebugEnabled()) {
226 }
else if(fCurrentBlock!=0){
228 if (logger->isDebugEnabled())
230 std::stringstream sout;
231 sout <<
"fCurrentBlock " << fCurrentBlock <<
" fBlockPos[fCurrentBlock-1] "<< fBlockPos[fCurrentBlock-1] << fBlockPos;
235 fBlockPos.Push(fBlockPos[fCurrentBlock-1]+
sizeof(int64_t));
238 EqnArray->
Write(fIOStream);
241 int64_t nextaddress=ftell(fIOStream);
248 fseek(fIOStream,fBlockPos[fCurrentBlock]+
sizeof(int64_t),SEEK_SET);
249 fCurBlockPosition=ftell(fIOStream);
250 fwrite(&nextaddress,
sizeof(int64_t),1,fIOStream);
252 if (logger->isDebugEnabled())
254 std::stringstream sout;
255 sout <<
"nextaddress " << nextaddress <<
" fCurBlockPosition " << fCurBlockPosition;
260 fseek(fIOStream,nextaddress,SEEK_SET);
291 }
else if(option==
'w'){
317 filename =
"testbinary.txt\0";
322 ifstream
input(
"MatrizInversa.txt");
326 for(i=0;i<Loop_Limit;i++){
327 for(j=0;j<Loop_Limit;j++){
333 for(i=0;i<Loop_Limit;i++){
335 for(j=i;j<Loop_Limit;j++){
337 EqnArray.
AddTerm(j,DecMat(i,j));
348 ofstream output(
"testeFileBin.txt");
350 FileStoreW.
Print(
"Teste",output);
354 for(i=0;i<Loop_Limit;i++) {
355 f(i,0) = (TVar)(
float)((i+1.)*2.1/23.);
370 strcpy(filenamestorage,
"/tmp/binary_frontalXXXXXX");
373 _mktemp(filenamestorage);
375 fdtmp = mkstemp(filenamestorage);
403 strcpy(filenamestorage,
"/tmp/binary_frontalXXXXXX");
405 _mktemp(filenamestorage);
408 fdtmp = mkstemp(filenamestorage);
438 strcpy(filenamestorage,
"/tmp/binary_frontalXXXXXX");
442 _mktemp(filenamestorage);
444 fdtmp = mkstemp(filenamestorage);
446 cout <<
"Temporary file name " << filenamestorage << endl;
474 if (logger->isDebugEnabled())
LOGPZ_DEBUG(logger,
"reopening the file")
520 }
else if(option==
'w'){
536 if(logger->isDebugEnabled())
LOGPZ_DEBUG(logger,
"Closing the binary file")
550 if(logger->isDebugEnabled() )
LOGPZ_DEBUG(logger,
"Reading block positions")
555 cout <<
"Reading Block Positions\n";
563 cout << 100*i/fNumBlocks <<
"% Read\n";
582 return "File Storage";
Has the same porpouse of EqnStack but stores the EqnArrays in a different form (binary files)...
void EqnForward(TPZFMatrix< TVar > &F, DecomposeType dec)
Forward substitution on equations stored in EqnArray.
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
void ReadBlockPositions()
Method used for binary input/output.
void Forward(TPZFMatrix< TVar > &f, DecomposeType dec) const
Executes a Forward substitution.
It is an equation array, generally in its decomposed form. Frontal.
void Backward(TPZFMatrix< TVar > &f, DecomposeType dec) const
Executes a Backward substitution.
int fNumBlocks
Used with binary input/output aritimethics.
void Write(char *outputfile)
Writes on disk.
clarg::argString input("-if", "input file", "cube1.txt")
REAL val(STATE &number)
Returns value of the variable.
void OpenGeneric(char option, const char *name)
Sets file name and if it is for input or output, the second term can be either 'r' for input and 'w' ...
void BeginEquation(int eq)
It starts an equation storage.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
void Print(const char *name, std::ostream &out)
It prints all terms stored in TPZEqnArray.
void Read(char *inputfile)
Reads from disk.
std::string fFileName
file name containing binary data
std::string GetStorage()
Type of Storage.
~TPZFileEqnStorage()
Simple destructor.
TPZFileEqnStorage()
Simple constructor.
TPZStack< int64_t > fBlockPos
Stack containing block positions.
#define DebugStop()
Returns a message to user put a breakpoint in.
void EqnBackward(TPZFMatrix< TVar > &U, DecomposeType dec)
Backward substitution on equations stored in EqnArray.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
void AddTerm(int col, TVar val)
Add a term to the current equation.
T * begin() const
Casting operator. Returns The fStore pointer.
void Print(const char *name, std::ostream &out) const
It prints TPZEqnStorage data.
Full matrix class. Matrix.
Contains the TPZFileEqnStorage class which implements an equation array and stores the EqnArrays...
int fNumHeaders
Indicates the number of headers for the object.
void EndEquation()
Ends the current equation.
void AddEqnArray(TPZEqnArray< TVar > *EqnArray)
Adds an EqnArray.
static char filenamestorage[256]
FILE * fIOStream
binary file itself
void Store(int ieq, int jeq, const char *name)
Stores from ieq to jeq equations on a binary file.
int fCurrentBlock
Used with binary input/output aritimethics.
virtual void Print(std::ostream &out) const
int ClassId() const override
Define the class id associated with the class.
void WriteHeaders()
Writes the header of the binary file.
void ReOpen()
Reopens an binary file with its current fFileName.
void Zero()
Reinitialize the object.
int fCurBlockPosition
Used with binary input/output aritimethics.
void FinishWriting()
Method used for binary input/output.
DecomposeType
Defines decomposition type for any matrix classes.