[Genabel-commits] r1455 - pkg/filevector/fvlib
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 9 01:02:51 CET 2013
Author: lckarssen
Date: 2013-12-09 01:02:51 +0100 (Mon, 09 Dec 2013)
New Revision: 1455
Modified:
pkg/filevector/fvlib/AbstractMatrix.cpp
pkg/filevector/fvlib/AbstractMatrix.h
pkg/filevector/fvlib/CastUtils.cpp
pkg/filevector/fvlib/CastUtils.h
pkg/filevector/fvlib/FileVector.cpp
pkg/filevector/fvlib/FileVector.h
pkg/filevector/fvlib/FilteredMatrix.cpp
pkg/filevector/fvlib/FilteredMatrix.h
pkg/filevector/fvlib/Logger.cpp
pkg/filevector/fvlib/Logger.h
pkg/filevector/fvlib/RealHandlerWrapper.cpp
pkg/filevector/fvlib/RealHandlerWrapper.h
pkg/filevector/fvlib/ReusableFileHandle.cpp
pkg/filevector/fvlib/ReusableFileHandle.h
pkg/filevector/fvlib/Transposer.cpp
pkg/filevector/fvlib/Transposer.h
pkg/filevector/fvlib/convert_util.cpp
pkg/filevector/fvlib/convert_util.h
pkg/filevector/fvlib/frutil.cpp
pkg/filevector/fvlib/frutil.h
Log:
In filevector/fvlib/*: fixed code layout.
- remove spaces at end of line
- replace tabs with space
- insert spaces after commas and around operators
- split long lines into parts.
- inserted a few {} in if-statements
Now the code is more in line with our coding standards (and we should less cpplint errors/warnings in Jenkins).
No functional changes!
Modified: pkg/filevector/fvlib/AbstractMatrix.cpp
===================================================================
--- pkg/filevector/fvlib/AbstractMatrix.cpp 2013-12-08 21:58:38 UTC (rev 1454)
+++ pkg/filevector/fvlib/AbstractMatrix.cpp 2013-12-09 00:02:51 UTC (rev 1455)
@@ -3,18 +3,18 @@
set<string> AbstractMatrix::fileNamesOpenForWriting;
void AbstractMatrix::checkOpenForWriting(const string fileName){
- deepDbg << "checkOpenForWriting("<< fileName << ")" << endl;
- if (AbstractMatrix::fileNamesOpenForWriting.find(fileName) != fileNamesOpenForWriting.end()) {
+ deepDbg << "checkOpenForWriting(" << fileName << ")" << endl;
+ if (AbstractMatrix::fileNamesOpenForWriting.find(fileName) !=
+ fileNamesOpenForWriting.end()) {
errorLog << "File " << fileName << " is already opened." << endl;
throw 1;
} else {
AbstractMatrix::fileNamesOpenForWriting.insert(fileName);
}
}
+
+
void AbstractMatrix::closeForWriting(const string fileName){
- fmDbg << "closeForWriting("<< fileName << ")" << endl;
+ fmDbg << "closeForWriting(" << fileName << ")" << endl;
AbstractMatrix::fileNamesOpenForWriting.erase(fileName);
}
-
-
-
Modified: pkg/filevector/fvlib/AbstractMatrix.h
===================================================================
--- pkg/filevector/fvlib/AbstractMatrix.h 2013-12-08 21:58:38 UTC (rev 1454)
+++ pkg/filevector/fvlib/AbstractMatrix.h 2013-12-09 00:02:51 UTC (rev 1455)
@@ -14,48 +14,52 @@
// See filteredMatrix.h for detailed comments
class AbstractMatrix {
-public:
+ public:
virtual ~AbstractMatrix(){};
template <class DT>
- void writeVariableAs(unsigned long varIdx, DT * outvec)
+ void writeVariableAs(unsigned long varIdx, DT * outvec)
{
char* tmp = new (nothrow) char [getNumObservations()*getElementSize()];
- if(!tmp)
+ if (!tmp)
errorLog << "writeVariableAs allocation error" << errorExit;
- for(unsigned long int i = 0; i< getNumObservations();i++){
- performCast(&tmp[i*getElementSize()],outvec[i],getElementType(), warningIsShown);
+ for (unsigned long int i = 0; i < getNumObservations(); i++){
+ performCast(&tmp[i * getElementSize()], outvec[i], getElementType(),
+ warningIsShown);
}
writeVariable(varIdx, tmp);
delete[] tmp;
}
template <class DT>
- void addVariableAs(DT * outvec, string varname)
+ void addVariableAs(DT * outvec, string varname)
{
char* tmp = new (nothrow) char [getNumObservations()*getElementSize()];
- if(!tmp)
+ if (!tmp)
errorLog << "add_variable_as allocation error" << errorExit;
- for(unsigned long int i = 0; i< getNumObservations();i++){
- performCast(&tmp[i*getElementSize()],outvec[i],getElementType(), warningIsShown);
+ for (unsigned long int i = 0; i < getNumObservations(); i++){
+ performCast(&tmp[i * getElementSize()], outvec[i], getElementType(),
+ warningIsShown);
}
- addVariable (tmp, varname);
+ addVariable (tmp, varname);
delete[] tmp;
}
template<class DT>
- void readVariableAs(unsigned long varIdx, DT * outvec)
+ void readVariableAs(unsigned long varIdx, DT * outvec)
{
- char * tmp = new (nothrow) char[getNumObservations()*getElementSize()];
- readVariable(varIdx, tmp);
- for(unsigned long int i = 0; i< getNumObservations();i++) {
- performCast(outvec[i],&tmp[i*getElementSize()],getElementType(),warningIsShown);
- }
- delete[] tmp;
+ char * tmp = new (nothrow) char[getNumObservations()*getElementSize()];
+ readVariable(varIdx, tmp);
+ for (unsigned long int i = 0; i < getNumObservations(); i++) {
+ performCast(outvec[i], &tmp[i*getElementSize()], getElementType(),
+ warningIsShown);
+ }
+ delete[] tmp;
}
template<class DT>
- void readElementAs(unsigned long varNumber, unsigned long obsNumber, DT & element){
+ void readElementAs(unsigned long varNumber, unsigned long obsNumber,
+ DT & element){
char *ret= new char [getElementSize()];
readElement(varNumber, obsNumber, ret);
performCast(element, ret, getElementType(), warningIsShown);
@@ -63,14 +67,16 @@
}
template <class DT>
- void writeElementAs(unsigned long varNumber, unsigned long obsNumber, DT& element){
- deepDbg << "AbstractMatrix.writeElementAs(" << varNumber << "," << obsNumber << "," << element <<")";
- deepDbg << "Alloc getElementSize() = " << getElementSize() << endl;
- char *ret = new char [getElementSize()];
- deepDbg << "Perform cast" << endl;
- performCast(ret, element, getElementType(), warningIsShown);
- writeElement(varNumber, obsNumber, ret);
- delete [] ret;
+ void writeElementAs(unsigned long varNumber, unsigned long obsNumber,
+ DT& element){
+ deepDbg << "AbstractMatrix.writeElementAs(" << varNumber << ","
+ << obsNumber << "," << element <<")";
+ deepDbg << "Alloc getElementSize() = " << getElementSize() << endl;
+ char *ret = new char [getElementSize()];
+ deepDbg << "Perform cast" << endl;
+ performCast(ret, element, getElementType(), warningIsShown);
+ writeElement(varNumber, obsNumber, ret);
+ delete [] ret;
}
virtual string getFileName() = 0;
@@ -78,18 +84,23 @@
virtual unsigned long getNumVariables() = 0;
virtual unsigned long getNumObservations() = 0;
- virtual void saveAs( string newFilename ) = 0;
- virtual void saveVariablesAs( string newFilename, unsigned long nvars, unsigned long * varindexes) = 0;
- virtual void saveObservationsAs( string newFilename, unsigned long nobss, unsigned long * obsindexes) = 0;
+ virtual void saveAs(string newFilename) = 0;
+ virtual void saveVariablesAs(string newFilename, unsigned long nvars,
+ unsigned long * varindexes) = 0;
+ virtual void saveObservationsAs(string newFilename, unsigned long nobss,
+ unsigned long * obsindexes) = 0;
- virtual void saveAs(string newFilename, unsigned long nvars, unsigned long nobss, unsigned long * varindexes, unsigned long * obsindexes) = 0;
- virtual void saveAsText(string newFilename, bool saveVarNames, bool saveObsNames, string nanString) = 0;
+ virtual void saveAs(string newFilename, unsigned long nvars,
+ unsigned long nobss, unsigned long * varindexes,
+ unsigned long * obsindexes) = 0;
+ virtual void saveAsText(string newFilename, bool saveVarNames,
+ bool saveObsNames, string nanString) = 0;
virtual void readObservation(unsigned long obsIdx, void * outvec) = 0;
virtual void writeObservation(unsigned long obsIdx, void * invec) = 0;
- virtual void writeVariableName(unsigned long varIdx, FixedChar newname) = 0; // todo loooong future -- control that name is unique
- virtual void writeObservationName(unsigned long obsIdx, FixedChar newname)= 0; //todo loooong future -- control that name is unique!
+ virtual void writeVariableName(unsigned long varIdx, FixedChar newname) = 0; // todo loooong future -- control that name is unique
+ virtual void writeObservationName(unsigned long obsIdx, FixedChar newname)= 0; //todo loooong future -- control that name is unique!
virtual unsigned long getCacheSizeInMb() = 0;
virtual void setCacheSizeInMb( unsigned long cachesizeMb ) = 0;
@@ -99,25 +110,27 @@
virtual void cacheAllNames(bool) = 0;
virtual void setUpdateNamesOnWrite(bool bUpdate) = 0;
- virtual short unsigned getElementSize() = 0;
- virtual short unsigned getElementType() = 0;
- virtual void readVariable(unsigned long varIdx, void * outvec) = 0;
- virtual void readElement(unsigned long varIdx, unsigned long obsIdx, void * elem) = 0;
- virtual void writeVariable(unsigned long varIdx, void * datavec) = 0;
- virtual void writeElement(unsigned long varIdx, unsigned long obsIdx, void * data) = 0;
- virtual AbstractMatrix* castToAbstractMatrix() = 0;
- virtual bool setReadOnly(bool readOnly) = 0;
+ virtual short unsigned getElementSize() = 0;
+ virtual short unsigned getElementType() = 0;
+ virtual void readVariable(unsigned long varIdx, void * outvec) = 0;
+ virtual void readElement(unsigned long varIdx, unsigned long obsIdx,
+ void * elem) = 0;
+ virtual void writeVariable(unsigned long varIdx, void * datavec) = 0;
+ virtual void writeElement(unsigned long varIdx, unsigned long obsIdx,
+ void * data) = 0;
+ virtual AbstractMatrix* castToAbstractMatrix() = 0;
+ virtual bool setReadOnly(bool readOnly) = 0;
- static set<string> fileNamesOpenForWriting;
- static void checkOpenForWriting(const string fileName);
- static void closeForWriting(const string fileName);
+ static set<string> fileNamesOpenForWriting;
+ static void checkOpenForWriting(const string fileName);
+ static void closeForWriting(const string fileName);
- bool &getWarningIsShown(){ return warningIsShown;}
-private:
+ bool &getWarningIsShown(){ return warningIsShown;}
+ private:
// HIGH -- here I see the possibility to make these functions faster then "random" access functions
// adds variable at the end = writeVariable with varIdx=NVARS?
- // todo loooong future -- control that name is unique!
+ // todo loooong future -- control that name is unique!
virtual void addVariable(void * invec, string varname) = 0;
// virtual void add_observation(void * invec, string obsname) = 0;
// write single element
@@ -126,5 +139,3 @@
};
#endif
-
-
Modified: pkg/filevector/fvlib/CastUtils.cpp
===================================================================
--- pkg/filevector/fvlib/CastUtils.cpp 2013-12-08 21:58:38 UTC (rev 1454)
+++ pkg/filevector/fvlib/CastUtils.cpp 2013-12-09 00:02:51 UTC (rev 1455)
@@ -16,111 +16,119 @@
unsigned char UNSIGNED_CHAR_NAN;
char const* parseFormats[9];
+
int initConsts(){
- int i;
- unsigned int ui;
- sscanf("32767","%hi",&SHORT_INT_NAN);
- sscanf("65535","%hu",&UNSIGNED_SHORT_INT_NAN);
- sscanf("2147483647","%i",&INT_NAN);
- sscanf("4294967295","%u",&UNSIGNED_INT_NAN);
- sscanf("127","%i",&i); CHAR_NAN = i;
- sscanf("255","%u",&ui); UNSIGNED_CHAR_NAN = ui;
+ int i;
+ unsigned int ui;
+ sscanf("32767", "%hi", &SHORT_INT_NAN);
+ sscanf("65535", "%hu", &UNSIGNED_SHORT_INT_NAN);
+ sscanf("2147483647", "%i", &INT_NAN);
+ sscanf("4294967295", "%u", &UNSIGNED_INT_NAN);
+ sscanf("127", "%i", &i); CHAR_NAN = i;
+ sscanf("255", "%u", &ui); UNSIGNED_CHAR_NAN = ui;
- parseFormats[UNSIGNED_SHORT_INT] = "%hu";
- parseFormats[SHORT_INT] = "%hd";
- parseFormats[UNSIGNED_INT] = "%u";
- parseFormats[INT] = "%d";
- parseFormats[FLOAT] = "%f";
- parseFormats[DOUBLE] = "%lf";
- parseFormats[SIGNED_CHAR] = "%i";
- parseFormats[UNSIGNED_CHAR] = "%i";
- return 0;
+ parseFormats[UNSIGNED_SHORT_INT] = "%hu";
+ parseFormats[SHORT_INT] = "%hd";
+ parseFormats[UNSIGNED_INT] = "%u";
+ parseFormats[INT] = "%d";
+ parseFormats[FLOAT] = "%f";
+ parseFormats[DOUBLE] = "%lf";
+ parseFormats[SIGNED_CHAR] = "%i";
+ parseFormats[UNSIGNED_CHAR] = "%i";
+ return 0;
}
+
int dummy = initConsts();
-void parseStringToArbType(string s, int destType, void *destData, string nanString) {
+
+void parseStringToArbType(string s, int destType, void *destData,
+ string nanString) {
+
char const *format = parseFormats[destType];
- int result;
- // no proper format specifier exists for char
- if (destType == SIGNED_CHAR || destType == UNSIGNED_CHAR) {
- int i;
- result = sscanf(s.c_str(), format, &i);
- if (nanString == s || result !=1){
- setNan(destData, destType);
- return;
- } else {
- if (destType == SIGNED_CHAR) *(char*) destData = i;
- if (destType == UNSIGNED_CHAR) *(unsigned char*) destData = i;
- }
+ int result;
+ // no proper format specifier exists for char
+ if (destType == SIGNED_CHAR || destType == UNSIGNED_CHAR) {
+ int i;
+ result = sscanf(s.c_str(), format, &i);
+ if (nanString == s || result !=1){
+ setNan(destData, destType);
+ return;
+ } else {
+ if (destType == SIGNED_CHAR) *(char*) destData = i;
+ if (destType == UNSIGNED_CHAR) *(unsigned char*) destData = i;
+ }
- } else {
- result = sscanf(s.c_str(), format, destData);
- if (nanString == s || result !=1){
- setNan(destData, destType);
- return;
- }
- }
+ } else {
+ result = sscanf(s.c_str(), format, destData);
+ if (nanString == s || result !=1){
+ setNan(destData, destType);
+ return;
+ }
+ }
}
+
unsigned short int dataTypeFromString(string type){
- if (type == "UNSIGNED_SHORT_INT") return 1;
- if (type == "SHORT_INT") return 2;
- if (type == "UNSIGNED_INT") return 3;
- if (type == "INT") return 4;
- if (type == "FLOAT") return 5;
- if (type == "DOUBLE") return 6;
- if (type == "CHAR") return 7;
- if (type == "UNSIGNED_CHAR") return 8;
- return 0;
+ if (type == "UNSIGNED_SHORT_INT") return 1;
+ if (type == "SHORT_INT") return 2;
+ if (type == "UNSIGNED_INT") return 3;
+ if (type == "INT") return 4;
+ if (type == "FLOAT") return 5;
+ if (type == "DOUBLE") return 6;
+ if (type == "CHAR") return 7;
+ if (type == "UNSIGNED_CHAR") return 8;
+ return 0;
}
+
string dataTypeToString(int type){
- if (type == 1) return "UNSIGNED_SHORT_INT";
- if (type == 2) return "SHORT_INT";
- if (type == 3) return "UNSIGNED_INT";
- if (type == 4) return "INT";
- if (type == 5) return "FLOAT";
- if (type == 6) return "DOUBLE";
- if (type == 7) return "CHAR";
- if (type == 8) return "UNSIGNED_CHAR";
- return 0;
+ if (type == 1) return "UNSIGNED_SHORT_INT";
+ if (type == 2) return "SHORT_INT";
+ if (type == 3) return "UNSIGNED_INT";
+ if (type == 4) return "INT";
+ if (type == 5) return "FLOAT";
+ if (type == 6) return "DOUBLE";
+ if (type == 7) return "CHAR";
+ if (type == 8) return "UNSIGNED_CHAR";
+ return 0;
}
+
string bufToString(short int dataType, char *data, string nanString){
- char ret[500];
- switch(dataType){
- case UNSIGNED_SHORT_INT:
- sprintf(ret, "%hu", *(unsigned short int*)data);
- break;
- case SHORT_INT:
- sprintf(ret, "%hd", *(short int*)data);
- break;
- case UNSIGNED_INT:
- sprintf(ret, "%u", *(unsigned int*)data);
- break;
- case INT:
- sprintf(ret, "%d", *(int*)data);
- break;
- case FLOAT:
- sprintf(ret, "%f", *(float*)data);
- break;
- case DOUBLE: // changed to "%f" from %lf [not ISO C++]
- sprintf(ret, "%f", *(double*)data);
- break;
- case SIGNED_CHAR: // changed to "%f" from %lf [not ISO C++]
- sprintf(ret, "%d", (int)*(char*)data);
- break;
- case UNSIGNED_CHAR: // changed to "%f" from %lf [not ISO C++]
- sprintf(ret, "%d", (int)*(unsigned char*)data);
- break;
- }
- if (checkNan(data,dataType)) {
- return nanString;
- }
+ char ret[500];
+ switch(dataType){
+ case UNSIGNED_SHORT_INT:
+ sprintf(ret, "%hu", *(unsigned short int*)data);
+ break;
+ case SHORT_INT:
+ sprintf(ret, "%hd", *(short int*)data);
+ break;
+ case UNSIGNED_INT:
+ sprintf(ret, "%u", *(unsigned int*)data);
+ break;
+ case INT:
+ sprintf(ret, "%d", *(int*)data);
+ break;
+ case FLOAT:
+ sprintf(ret, "%f", *(float*)data);
+ break;
+ case DOUBLE: // changed to "%f" from %lf [not ISO C++]
+ sprintf(ret, "%f", *(double*)data);
+ break;
+ case SIGNED_CHAR: // changed to "%f" from %lf [not ISO C++]
+ sprintf(ret, "%d", (int)*(char*)data);
+ break;
+ case UNSIGNED_CHAR: // changed to "%f" from %lf [not ISO C++]
+ sprintf(ret, "%d", (int)*(unsigned char*)data);
+ break;
+ }
+ if (checkNan(data,dataType)) {
+ return nanString;
+ }
- return string(ret);
+ return string(ret);
}
void setNan(unsigned short int &i){setNan(&i, UNSIGNED_SHORT_INT);}
@@ -144,68 +152,73 @@
void setNan(void *data, int dataType){
double dZero = 0.;
float fZero = 0.;
+
switch (dataType) {
- case UNSIGNED_SHORT_INT:
- (*(unsigned short int*) data) = UNSIGNED_SHORT_INT_NAN;
- break;
- case SHORT_INT:
- (*(short int*) data) = SHORT_INT_NAN;
- break;
- case UNSIGNED_INT:
- (*(unsigned int*) data) = UNSIGNED_INT_NAN;
- break;
- case INT:
- (*(int*) data) = INT_NAN;
- break;
- case FLOAT:
- (*(float*) data) = fZero/fZero;
- break;
- case DOUBLE:
- (*(double*) data) = dZero/dZero;
- break;
- case SIGNED_CHAR:
- (*(char*) data) = CHAR_NAN;
- break;
- case UNSIGNED_CHAR:
- (*(unsigned char*) data) = UNSIGNED_CHAR_NAN;
- break;
- default:
- errorLog << "file contains data of unknown type " << dataType << endl << errorExit;
- }
+ case UNSIGNED_SHORT_INT:
+ (*(unsigned short int*) data) = UNSIGNED_SHORT_INT_NAN;
+ break;
+ case SHORT_INT:
+ (*(short int*) data) = SHORT_INT_NAN;
+ break;
+ case UNSIGNED_INT:
+ (*(unsigned int*) data) = UNSIGNED_INT_NAN;
+ break;
+ case INT:
+ (*(int*) data) = INT_NAN;
+ break;
+ case FLOAT:
+ (*(float*) data) = fZero/fZero;
+ break;
+ case DOUBLE:
+ (*(double*) data) = dZero/dZero;
+ break;
+ case SIGNED_CHAR:
+ (*(char*) data) = CHAR_NAN;
+ break;
+ case UNSIGNED_CHAR:
+ (*(unsigned char*) data) = UNSIGNED_CHAR_NAN;
+ break;
+ default:
+ errorLog << "file contains data of unknown type " << dataType
+ << endl << errorExit;
+ }
}
+
bool checkNan(void *data, int dataType){
switch (dataType) {
- case UNSIGNED_SHORT_INT:
- return (*(unsigned short int*) data) == UNSIGNED_SHORT_INT_NAN;
- case SHORT_INT:
- return (*(short int*) data) == SHORT_INT_NAN;
- case UNSIGNED_INT:
- return (*(unsigned int*) data) == UNSIGNED_INT_NAN;
- case INT:
- return (*(int*) data) == INT_NAN;
- case FLOAT:
+ case UNSIGNED_SHORT_INT:
+ return (*(unsigned short int*) data) == UNSIGNED_SHORT_INT_NAN;
+ case SHORT_INT:
+ return (*(short int*) data) == SHORT_INT_NAN;
+ case UNSIGNED_INT:
+ return (*(unsigned int*) data) == UNSIGNED_INT_NAN;
+ case INT:
+ return (*(int*) data) == INT_NAN;
+ case FLOAT:
#ifdef _NOT_R_FILEVECTOR
- return std::isnan(*(float*) data);
+ return std::isnan(*(float*) data);
#else
- return ISNAN(*(float*) data);
+ return ISNAN(*(float*) data);
#endif
- case DOUBLE:
+ case DOUBLE:
#ifdef _NOT_R_FILEVECTOR
- return std::isnan(*(double*)data);
+ return std::isnan(*(double*)data);
#else
- return ISNAN(*(double*)data);
+ return ISNAN(*(double*)data);
#endif
- case UNSIGNED_CHAR:
- return (*(unsigned char*) data) == UNSIGNED_CHAR_NAN;
- case SIGNED_CHAR:
- return (*(char*) data) == CHAR_NAN;
- default:
- errorLog << "file contains data of unknown type " << dataType << endl << errorExit;
- return false;
- }
+ case UNSIGNED_CHAR:
+ return (*(unsigned char*) data) == UNSIGNED_CHAR_NAN;
+ case SIGNED_CHAR:
+ return (*(char*) data) == CHAR_NAN;
+ default:
+ errorLog << "file contains data of unknown type " << dataType
+ << endl << errorExit;
+ return false;
+ }
}
+
int getDataType(unsigned short int){return UNSIGNED_SHORT_INT;}
int getDataType(short int){return SHORT_INT;}
int getDataType(unsigned int){return UNSIGNED_INT;}
Modified: pkg/filevector/fvlib/CastUtils.h
===================================================================
--- pkg/filevector/fvlib/CastUtils.h 2013-12-08 21:58:38 UTC (rev 1454)
+++ pkg/filevector/fvlib/CastUtils.h 2013-12-09 00:02:51 UTC (rev 1455)
@@ -35,89 +35,96 @@
extern unsigned char UNSIGNED_CHAR_NAN;
-#define COPY_AND_COMPARE(dest,src,warningIsShown) \
- dest=src; \
- if(warningIsShown == false && (dest!=src || checkNan(dest) != checkNan(src))) \
- { \
- errorLog << "Loss of precision / loss of data during conversion from "; \
- errorLog << dataTypeToString(getDataType(src)) << " to "; \
- errorLog << dataTypeToString(getDataType(dest)) << "." << endl; \
- errorLog << "Futher conversion warnings omitted." << endl; \
- warningIsShown = true; \
- }
+#define COPY_AND_COMPARE(dest,src,warningIsShown) \
+ dest=src; \
+ if(warningIsShown == false && (dest!=src || checkNan(dest) != checkNan(src))) \
+ { \
+ errorLog << "Loss of precision / loss of data during conversion from "; \
+ errorLog << dataTypeToString(getDataType(src)) << " to "; \
+ errorLog << dataTypeToString(getDataType(dest)) << "." << endl; \
+ errorLog << "Futher conversion warnings omitted." << endl; \
+ warningIsShown = true; \
+ }
-template <class DT> void performCast(DT &dest, void*src, int srcType, bool &warningIsShown) {
- if (checkNan(src,srcType)){
+template <class DT> void performCast(DT &dest, void*src, int srcType,
+ bool &warningIsShown) {
+ if (checkNan(src, srcType)){
setNan(dest);
return;
}
+
switch (srcType) {
- case UNSIGNED_SHORT_INT:
- COPY_AND_COMPARE(dest, (DT)*((unsigned short int*) src), warningIsShown);
- break;
- case SHORT_INT:
- COPY_AND_COMPARE(dest, (DT)*((short int*) src), warningIsShown);
- break;
- case UNSIGNED_INT:
- COPY_AND_COMPARE(dest, (DT)*((unsigned int*) src), warningIsShown);
- break;
- case INT:
- COPY_AND_COMPARE(dest, (DT)*((int*) src), warningIsShown);
- break;
- case FLOAT:
- COPY_AND_COMPARE(dest, (DT)*((float*) src), warningIsShown);
- break;
- case DOUBLE:
- COPY_AND_COMPARE(dest, (DT)*((double*) src), warningIsShown);
- break;
- case SIGNED_CHAR:
- COPY_AND_COMPARE(dest, (DT)*((char*) src), warningIsShown);
- break;
- case UNSIGNED_CHAR:
- COPY_AND_COMPARE(dest, (DT)*((unsigned char*) src), warningIsShown);
- break;
- default:
- errorLog << "file contains data of unknown type " << srcType << endl << errorExit;
- }
+ case UNSIGNED_SHORT_INT:
+ COPY_AND_COMPARE(dest, (DT)*((unsigned short int*) src), warningIsShown);
+ break;
+ case SHORT_INT:
+ COPY_AND_COMPARE(dest, (DT)*((short int*) src), warningIsShown);
+ break;
+ case UNSIGNED_INT:
+ COPY_AND_COMPARE(dest, (DT)*((unsigned int*) src), warningIsShown);
+ break;
+ case INT:
+ COPY_AND_COMPARE(dest, (DT)*((int*) src), warningIsShown);
+ break;
+ case FLOAT:
+ COPY_AND_COMPARE(dest, (DT)*((float*) src), warningIsShown);
+ break;
+ case DOUBLE:
+ COPY_AND_COMPARE(dest, (DT)*((double*) src), warningIsShown);
+ break;
+ case SIGNED_CHAR:
+ COPY_AND_COMPARE(dest, (DT)*((char*) src), warningIsShown);
+ break;
+ case UNSIGNED_CHAR:
+ COPY_AND_COMPARE(dest, (DT)*((unsigned char*) src), warningIsShown);
+ break;
+ default:
+ errorLog << "file contains data of unknown type " << srcType
+ << endl << errorExit;
+ }
}
-template <class DT> void performCast(void*dest, DT&src, int destType, bool &warningIsShown) {
+template <class DT> void performCast(void*dest, DT&src, int destType,
+ bool &warningIsShown) {
if (checkNan(src)){
setNan(dest,destType);
return;
}
+
switch (destType) {
- case UNSIGNED_SHORT_INT:
- COPY_AND_COMPARE(*((unsigned short int*)dest), src, warningIsShown);
- break;
- case SHORT_INT:
- COPY_AND_COMPARE(*((short int*)dest), src, warningIsShown);
- break;
- case UNSIGNED_INT:
- COPY_AND_COMPARE(*((unsigned int*)dest), src, warningIsShown);
- break;
- case INT:
- COPY_AND_COMPARE(*((int*)dest), src, warningIsShown);
- break;
- case FLOAT:
- COPY_AND_COMPARE(*((float*)dest), src, warningIsShown);
- break;
- case DOUBLE:
- COPY_AND_COMPARE(*((double*)dest), src, warningIsShown);
- break;
- case SIGNED_CHAR:
- COPY_AND_COMPARE(*((char*)dest), src, warningIsShown);
- break;
- case UNSIGNED_CHAR:
- COPY_AND_COMPARE(*((unsigned char*)dest), src, warningIsShown);
- break;
- default:
- errorLog << "file contains data of unknown type " << destType << endl << errorExit;
+ case UNSIGNED_SHORT_INT:
+ COPY_AND_COMPARE(*((unsigned short int*)dest), src, warningIsShown);
+ break;
+ case SHORT_INT:
+ COPY_AND_COMPARE(*((short int*)dest), src, warningIsShown);
+ break;
+ case UNSIGNED_INT:
+ COPY_AND_COMPARE(*((unsigned int*)dest), src, warningIsShown);
+ break;
+ case INT:
+ COPY_AND_COMPARE(*((int*)dest), src, warningIsShown);
+ break;
+ case FLOAT:
+ COPY_AND_COMPARE(*((float*)dest), src, warningIsShown);
+ break;
+ case DOUBLE:
+ COPY_AND_COMPARE(*((double*)dest), src, warningIsShown);
+ break;
+ case SIGNED_CHAR:
+ COPY_AND_COMPARE(*((char*)dest), src, warningIsShown);
+ break;
+ case UNSIGNED_CHAR:
+ COPY_AND_COMPARE(*((unsigned char*)dest), src, warningIsShown);
+ break;
+ default:
+ errorLog << "file contains data of unknown type " << destType
+ << endl << errorExit;
}
}
-void parseStringToArbType(string s, int destType, void *destData, string nanString);
+void parseStringToArbType(string s, int destType, void *destData,
+ string nanString);
unsigned short int dataTypeFromString(string type);
string bufToString(short int dataType, char *data, string nanString);
Modified: pkg/filevector/fvlib/FileVector.cpp
===================================================================
--- pkg/filevector/fvlib/FileVector.cpp 2013-12-08 21:58:38 UTC (rev 1454)
+++ pkg/filevector/fvlib/FileVector.cpp 2013-12-09 00:02:51 UTC (rev 1455)
@@ -7,183 +7,222 @@
#include "FileVector.h"
#include "frutil.h"
+
void FileVector::saveIndexFile() {
-
if (readOnly)
return;
- indexFile.fseek(0);
- indexFile.blockWriteOrRead(sizeof(fileHeader),(char*)&fileHeader, true);
- indexFile.fseek(sizeof(fileHeader));
+ indexFile.fseek(0);
+ indexFile.blockWriteOrRead(sizeof(fileHeader), (char*)&fileHeader, true);
+ indexFile.fseek(sizeof(fileHeader));
- if (observationNames && variableNames) {
- indexFile.blockWriteOrRead(sizeof(FixedChar)*fileHeader.numObservations,(char*)observationNames,true);
- indexFile.fseek(sizeof(fileHeader)+sizeof(FixedChar)*fileHeader.numObservations);
- indexFile.blockWriteOrRead(sizeof(FixedChar)*fileHeader.numVariables,(char*)variableNames,true);
- }
+ if (observationNames && variableNames) {
+ indexFile.blockWriteOrRead(sizeof(FixedChar) * fileHeader.numObservations,
+ (char*)observationNames, true);
+ indexFile.fseek(sizeof(fileHeader) + sizeof(FixedChar) *
+ fileHeader.numObservations);
+ indexFile.blockWriteOrRead(sizeof(FixedChar) * fileHeader.numVariables,
+ (char*)variableNames, true);
+ }
}
+
void FileVector::deInitialize(){
- saveIndexFile();
- delete [] cacheBuffer;
- cacheBuffer = 0;
- delete [] observationNames;
- observationNames = 0;
- delete [] variableNames;
- variableNames = 0;
- indexFile.close();
- dataFile.close();
- AbstractMatrix::closeForWriting(filename);
+ saveIndexFile();
+ delete [] cacheBuffer;
+ cacheBuffer = 0;
+ delete [] observationNames;
+ observationNames = 0;
+ delete [] variableNames;
+ variableNames = 0;
+ indexFile.close();
+ dataFile.close();
+ AbstractMatrix::closeForWriting(filename);
}
+
FileVector::~FileVector() {
- deInitialize();
+ deInitialize();
}
+
void FileVector::initialize(unsigned long cachesizeMb) {
- //Rprintf("initialize, open file %s\n",filename.c_str());
- dbg << "Opening FileVector '" << filename.c_str() <<"'."<< endl;
+ //Rprintf("initialize, open file %s\n",filename.c_str());
+ dbg << "Opening FileVector '" << filename.c_str() <<"'."<< endl;
- if (!readOnly) {
- AbstractMatrix::checkOpenForWriting(filename);
- }
+ if (!readOnly) {
+ AbstractMatrix::checkOpenForWriting(filename);
+ }
- indexFilename = extract_base_file_name(filename) + FILEVECTOR_INDEX_FILE_SUFFIX;
- dataFilename = extract_base_file_name(filename) + FILEVECTOR_DATA_FILE_SUFFIX;
+ indexFilename = extract_base_file_name(filename) +
+ FILEVECTOR_INDEX_FILE_SUFFIX;
+ dataFilename = extract_base_file_name(filename) +
+ FILEVECTOR_DATA_FILE_SUFFIX;
- if(!file_exists(indexFilename)) {
- errorLog <<"Index file not exists: " << indexFilename << endl << errorExit;
- }
+ if (!file_exists(indexFilename)) {
+ errorLog << "Index file not exists: " << indexFilename
+ << endl << errorExit;
+ }
- dataFilename = extract_base_file_name(filename) + FILEVECTOR_DATA_FILE_SUFFIX;
- if(!file_exists(dataFilename))
- errorLog <<"Data file not exists: " << dataFilename.c_str() << endl <<errorExit;
+ dataFilename = extract_base_file_name(filename) + FILEVECTOR_DATA_FILE_SUFFIX;
+ if (!file_exists(dataFilename))
+ errorLog << "Data file not exists: " << dataFilename.c_str()
+ << endl <<errorExit;
- struct stat data_filestatus;
- stat(dataFilename.c_str(), &data_filestatus);
+ struct stat data_filestatus;
+ stat(dataFilename.c_str(), &data_filestatus);
- struct stat index_filestatus;
- stat(indexFilename.c_str(), &index_filestatus);
+ struct stat index_filestatus;
+ stat(indexFilename.c_str(), &index_filestatus);
indexFile = ReusableFileHandle::getHandle(indexFilename, readOnly);
- if (!indexFile) {
- errorLog << "Opening file "<< indexFilename <<" for write & read failed\n" << errorExit;
- }
+ if (!indexFile) {
+ errorLog << "Opening file " << indexFilename
+ << " for write & read failed\n" << errorExit;
+ }
dataFile = ReusableFileHandle::getHandle(dataFilename, readOnly);
- if (!dataFile) {
- errorLog << "Opening file "<< dataFilename << " for write & read failed\n" << errorExit;
- }
+ if (!dataFile) {
+ errorLog << "Opening file " << dataFilename
+ << " for write & read failed\n" << errorExit;
+ }
- indexFile.blockWriteOrRead(sizeof(fileHeader),(char*)&fileHeader, false);
- if (!indexFile){
- errorLog << "Failed to read datainfo from file:" << indexFilename << endl;
- }
+ indexFile.blockWriteOrRead(sizeof(fileHeader), (char*)&fileHeader, false);
+ if (!indexFile){
+ errorLog << "Failed to read datainfo from file:"
+ << indexFilename << endl;
+ }
- // some integrity checks
- if (getElementSize() != fileHeader.bytesPerRecord) {
- errorLog << "System data type size ("<<getElementSize();
- errorLog <<") and file data type size ("<<fileHeader.bytesPerRecord<<") do not match.\n";
- }
+ // some integrity checks
+ if (getElementSize() != fileHeader.bytesPerRecord) {
+ errorLog << "System data type size (" << getElementSize();
+ errorLog <<") and file data type size ("
+ << fileHeader.bytesPerRecord <<") do not match.\n";
+ }
- //!!! nelements should actually be long to ensure !!!
- if (fileHeader.nelements != (fileHeader.numObservations*fileHeader.numVariables)) {
- errorLog << "Number of variables ("<<fileHeader.numVariables;
- errorLog << ") and observations ("<<fileHeader.numObservations<<") do not multiply to nelements";
- errorLog << "("<< fileHeader.nelements<<") (file integrity issue?)\n";
- errorLog << errorExit;
- }
+ //!!! nelements should actually be long to ensure !!!
+ if (fileHeader.nelements !=
+ (fileHeader.numObservations * fileHeader.numVariables)) {
+ errorLog << "Number of variables (" << fileHeader.numVariables;
+ errorLog << ") and observations (" << fileHeader.numObservations
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/genabel -r 1455
More information about the Genabel-commits
mailing list