static int compareVectors(mwvector a, mwvector b) { int rc; real ar, br; ar = mw_absv(a); br = mw_absv(b); if (ar > br) return 1; else if (ar < br) return -1; else { /* Resort to comparing by each component */ if ((rc = compareComponents(X(a), X(b)))) return rc; if ((rc = compareComponents(Y(a), Y(b)))) return rc; if ((rc = compareComponents(Z(a), Z(b)))) return rc; } return 0; /* Equal */ }
/* Function for sorting bodies */ static int compareBodies(const void* _a, const void* _b) { const Body* a = (const Body*) _a; const Body* b = (const Body*) _b; int rc; char* bufA; char* bufB; if ((rc = compareComponents(Mass(a), Mass(b)))) return rc; /* Masses equal, compare positions */ rc = compareVectors(Pos(a), Pos(b)); if (rc == 0) { bufA = showBody(a); bufB = showBody(b); mw_panic("Comparing bodies with equal positions: %s, %s\n", bufA, bufB); free(bufA); /* Never reached */ free(bufB); } return rc; }
void MHL7Compare::compareFields(const MString& segName) { if (mLogLevel >= 3) { cout << segName << endl; } // assumes we are sitting on valid segments // first get the number of fields in both segments int nofExist = HL7GetNmbrOfFlds(mMsgExist); int nofNew = HL7GetNmbrOfFlds(mMsgNew); int fExist, fNew; // Each segment can have one or more '|' indicating empty trailing fields. Their numbers // do not have to match for the segments to be considered the same. We, therefore, need to // start from the last field if (nofExist != nofNew) { // find the last non-empty fields in segments of both the messages for (fExist = nofExist; fExist > 0; fExist--) { char *pFldExist = HL7GetFld(mMsgExist, fExist); if (pFldExist) break; } for (fNew = nofNew; fNew > 0; fNew--) { char *pFldNew = HL7GetFld(mMsgNew, fNew); if (pFldNew) break; } if (fExist != fNew) { DIFF diff; diff.fldNum = 0; diff.existValue = segName; diff.newValue = segName; diff.comment = "Different number of fields"; mDiff.insert (MDiff::value_type (segName, diff)); mCount++; } } else { fExist = nofExist; fNew = nofNew; } if ( fExist && fNew ) { int nof = (fExist > fNew ? fExist : fNew); for (int f = 1; f <= nof; f++) { char *pFldExist, *pFldNew; if (f <= fExist) pFldExist = HL7GetFld(mMsgExist, f); else pFldExist = NULL; if (f <= fNew) pFldNew = HL7GetFld(mMsgNew, f); else pFldNew = NULL; if (pFldExist && pFldNew) { if (mLogLevel >= 3) { cout << setw(3) << nof << "<" << pFldExist << "> " << "<" << pFldNew << ">" << endl; } // if both fields look exactly the same, then no need for further analysis if (strcmp(pFldExist, pFldNew) != 0) { if (!compareComponents(segName, pFldExist, pFldNew)) { DIFF diff; diff.fldNum = f; diff.existValue = pFldExist; diff.newValue = pFldNew; diff.comment = "Different field values"; mDiff.insert (MDiff::value_type (segName, diff) ); mCount++; } } } else { if ((!pFldExist && pFldNew) || (pFldExist && !pFldNew)) { // report the difference DIFF diff; diff.fldNum = f; if (pFldExist) diff.existValue = pFldExist; else diff.existValue = ""; if (pFldNew) diff.newValue = pFldNew; else diff.newValue = ""; diff.comment = "Different number of fields"; mDiff.insert (MDiff::value_type (segName, diff) ); mCount++; } //endif } //endelse } } else // no need to analyze any further if at least one of the segments is completely empty return; }