15 Mille::Mille(
const char *outFileName,
bool asBinary,
bool writeZero) :
16 myOutFile(outFileName, (asBinary ? (std::ios::binary | std::ios::out) : std::ios::out)),
17 myAsBinary(asBinary), myWriteZero(writeZero), myBufferPos(-1), myHasSpecial(false)
24 myBufferFloat[0] = 0.;
26 if (!myOutFile.is_open()) {
27 std::cerr <<
"Mille::Mille: Could not open " << outFileName
28 <<
" as output file." << std::endl;
39 int NGL,
const float *derGl,
const int *label,
40 float rMeas,
float sigma)
42 if (sigma <= 0.)
return;
43 if (myBufferPos == -1) this->newSet();
44 if (!this->checkBufferSize(NLC, NGL))
return;
48 myBufferFloat[myBufferPos] = rMeas;
49 myBufferInt [myBufferPos] = 0;
52 for (
int i = 0; i < NLC; ++i) {
53 if (derLc[i] || myWriteZero) {
55 myBufferFloat[myBufferPos] = derLc[i];
56 myBufferInt [myBufferPos] = i+1;
62 myBufferFloat[myBufferPos] = sigma;
63 myBufferInt [myBufferPos] = 0;
66 for (
int i = 0; i < NGL; ++i) {
67 if (derGl[i] || myWriteZero) {
70 if ((label[i] > 0 || myWriteZero) && label[i] <= myMaxLabel) {
72 myBufferFloat[myBufferPos] = derGl[i];
73 myBufferInt [myBufferPos] = label[i];
75 std::cerr <<
"Mille::mille: Invalid label " << label[i]
76 <<
" <= 0 or > " << myMaxLabel << std::endl;
82 void Mille::special(
int nSpecial,
const float *floatings,
const int *integers)
84 if (nSpecial == 0)
return;
85 if (myBufferPos == -1) this->newSet();
87 std::cerr <<
"Mille::special: Special values already stored for this record."
91 if (!this->checkBufferSize(nSpecial, 0))
return;
101 myBufferFloat[myBufferPos] = 0.;
102 myBufferInt [myBufferPos] = 0;
105 myBufferFloat[myBufferPos] = -nSpecial;
106 myBufferInt [myBufferPos] = 0;
108 for (
int i = 0; i < nSpecial; ++i) {
110 myBufferFloat[myBufferPos] = floatings[i];
111 myBufferInt [myBufferPos] = integers[i];
124 if (myBufferPos > 0) {
125 const int numWordsToWrite = (myBufferPos + 1)*2;
128 myOutFile.write(reinterpret_cast<const char*>(&numWordsToWrite),
129 sizeof(numWordsToWrite));
130 myOutFile.write(reinterpret_cast<char*>(myBufferFloat),
131 (myBufferPos+1) *
sizeof(myBufferFloat[0]));
132 myOutFile.write(reinterpret_cast<char*>(myBufferInt),
133 (myBufferPos+1) *
sizeof(myBufferInt[0]));
136 myOutFile << numWordsToWrite <<
"\n";
137 for (
int i = 0; i < myBufferPos+1; ++i) {
138 myOutFile << myBufferFloat[i] <<
" ";
142 for (
int i = 0; i < myBufferPos+1; ++i) {
143 myOutFile << myBufferInt[i] <<
" ";
168 myHasSpecial =
false;
169 myBufferFloat[0] = 0.0;
173 bool Mille::checkBufferSize(
int nLocal,
int nGlobal)
177 if (myBufferPos + nLocal + nGlobal + 2 >= myBufferSize) {
179 std::cerr <<
"Mille::checkBufferSize: Buffer too short ("
180 << myBufferSize <<
"),"
181 <<
"\n need space for nLocal (" << nLocal<<
")"
182 <<
"/nGlobal (" << nGlobal <<
") local/global derivatives, "
183 << myBufferPos + 1 <<
" already stored!"
Mille(const char *outFileName, bool asBinary=true, bool writeZero=false)
void mille(int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma)
void special(int nSpecial, const float *floatings, const int *integers)