- Timestamp:
- Apr 7, 2006, 5:05:28 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c
r6804 r6815 14 14 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 15 15 16 static bool compareConcepts(psMetadataItem * item1, // First item to compare17 psMetadataItem * item2 // Second item to compare16 static bool compareConcepts(psMetadataItem *compare, // Item to compare 17 psMetadataItem *standard // Standard for comparison 18 18 ) 19 19 { 20 20 // First order checks 21 if (! item1 || ! item2) {22 return false; 23 } 24 if (strcasecmp( item1->name, item2->name) != 0) {21 if (! compare || ! standard) { 22 return false; 23 } 24 if (strcasecmp(compare->name, standard->name) != 0) { 25 25 return false; 26 26 } 27 27 28 28 // Check the more boring types 29 switch ( item1->type) {29 switch (compare->type) { 30 30 case PS_TYPE_S32: 31 switch ( item2->type) {31 switch (standard->type) { 32 32 case PS_TYPE_S32: 33 psTrace(__func__, 10, "Comparing %d and %d...\n", item1->data.S32, item2->data.S32);34 return ( item1->data.S32 == item2->data.S32) ? true : false;33 psTrace(__func__, 10, "Comparing %d and %d...\n", compare->data.S32, standard->data.S32); 34 return (compare->data.S32 == standard->data.S32) ? true : false; 35 35 case PS_TYPE_F32: 36 psTrace(__func__, 10, "Comparing %d and %d...\n", item1->data.S32, (int)item2->data.F32);37 return ( item1->data.S32 == (int)item2->data.F32) ? true : false;36 psTrace(__func__, 10, "Comparing %d and %d...\n", compare->data.S32, (int)standard->data.F32); 37 return (compare->data.S32 == (int)standard->data.F32) ? true : false; 38 38 case PS_TYPE_F64: 39 psTrace(__func__, 10, "Comparing %d and %d...\n", item1->data.S32, (int)item2->data.F64);40 return ( item1->data.S32 == (int)item2->data.F64) ? true : false;39 psTrace(__func__, 10, "Comparing %d and %d...\n", compare->data.S32, (int)standard->data.F64); 40 return (compare->data.S32 == (int)standard->data.F64) ? true : false; 41 41 default: 42 42 return false; 43 43 } 44 44 case PS_TYPE_F32: 45 switch ( item2->type) {45 switch (standard->type) { 46 46 case PS_TYPE_S32: 47 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, (float)item2->data.S32);48 return ( item1->data.F32 == (float)item2->data.S32) ? true : false;47 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, (float)standard->data.S32); 48 return (compare->data.F32 == (float)standard->data.S32) ? true : false; 49 49 case PS_TYPE_F32: 50 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, item2->data.F32);51 return ( item1->data.F32 == item2->data.F32) ? true : false;50 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, standard->data.F32); 51 return (compare->data.F32 == standard->data.F32) ? true : false; 52 52 case PS_TYPE_F64: 53 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, (float)item2->data.F64);54 return ( item1->data.F32 == (float)item2->data.F64) ? true : false;53 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, (float)standard->data.F64); 54 return (compare->data.F32 == (float)standard->data.F64) ? true : false; 55 55 default: 56 56 return false; 57 57 } 58 58 case PS_TYPE_F64: 59 switch ( item2->type) {59 switch (standard->type) { 60 60 case PS_TYPE_S32: 61 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, (double)item2->data.S32);62 return ( item1->data.F64 == (double)item2->data.S32) ? true : false;61 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, (double)standard->data.S32); 62 return (compare->data.F64 == (double)standard->data.S32) ? true : false; 63 63 case PS_TYPE_F32: 64 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, (double)item2->data.F32);65 return ( item1->data.F64 == (double)item2->data.F32) ? true : false;64 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, (double)standard->data.F32); 65 return (compare->data.F64 == (double)standard->data.F32) ? true : false; 66 66 case PS_TYPE_F64: 67 psTrace(__func__, 10, "Comparing %f and %f...\n", item1->data.F32, item2->data.F64);68 return ( item1->data.F64 == item2->data.F64) ? true : false;67 psTrace(__func__, 10, "Comparing %f and %f...\n", compare->data.F32, standard->data.F64); 68 return (compare->data.F64 == standard->data.F64) ? true : false; 69 69 default: 70 70 return false; 71 71 } 72 return ( item1->data.F64 == item2->data.F64) ? true : false;72 return (compare->data.F64 == standard->data.F64) ? true : false; 73 73 case PS_DATA_STRING: 74 if ( item2->type != PS_DATA_STRING) {74 if (standard->type != PS_DATA_STRING) { 75 75 return false; 76 76 } 77 psTrace(__func__, 10, "Comparing '%s' and '%s'\n", item1->data.V, item2->data.V); 78 return (strcasecmp(item1->data.V, item2->data.V) == 0) ? true : false; 77 psTrace(__func__, 10, "Comparing '%s' and '%s'\n", compare->data.V, standard->data.V); 78 return (strcasecmp(compare->data.V, standard->data.V) == 0) ? true : false; 79 case PS_DATA_LIST: { // A list of strings 80 // "compare" contains a list of psMetadataItems 81 // "standard" likely contains just a string (but it might possibly be a list of strings) 82 psList *cList = compare->data.V; // The list from comparison item 83 psList *sList = NULL; // The list from standard item 84 switch (standard->type) { 85 case PS_DATA_STRING: 86 sList = psStringSplit(standard->data.V, " ;"); 87 break; 88 case PS_DATA_LIST: 89 sList = psMemIncrRefCounter(standard->data.V); 90 break; 91 default: 92 return false; 93 } 94 if (cList->n != sList->n) { 95 psFree(sList); 96 return false; 97 } 98 psVector *match = psVectorAlloc(cList->n, PS_TYPE_U8); // Array indicating which values match 99 psVectorInit(match, 0); 100 psListIterator *cIter = psListIteratorAlloc(cList, PS_LIST_HEAD, false); // compare iterator 101 psListIterator *sIter = psListIteratorAlloc(sList, PS_LIST_HEAD, false); // standard iterator 102 psMetadataItem *cItem = NULL; // Item from compare list 103 while ((cItem = psListGetAndIncrement(cIter))) { 104 if (cItem->type != PS_DATA_STRING) { 105 psLogMsg(__func__, PS_LOG_WARN, "psMetadataItem from list is of type %x instead of " 106 "%x (PS_DATA_STRING) --- can't interpret.\n", cItem->type, PS_DATA_STRING); 107 psFree(cIter); 108 psFree(sIter); 109 psFree(match); 110 psFree(sList); 111 return false; 112 } 113 psString cString = cItem->data.V; // String from compare list 114 psListIteratorSet(sIter, PS_LIST_HEAD); 115 int index = 0; // Index for list 116 bool found = false; // Found a match? 117 for (psString sString = NULL; (sString = psListGetAndIncrement(sIter)) && !found; index++) { 118 if (strcasecmp(cString, sString) == 0) { 119 match->data.U8[index]++; 120 found = true; 121 } 122 } 123 if (! found) { 124 // Can give up immediately 125 psFree(cIter); 126 psFree(sIter); 127 psFree(match); 128 psFree(sList); 129 return false; 130 } 131 } 132 // Make sure we got 100% matches in both directions 133 bool allMatch = true; // Did all of them match? 134 for (int i = 0; i < match->n && allMatch; i++) { 135 if (!match->data.U8[i]) { 136 allMatch = false; 137 } 138 } 139 psFree(cIter); 140 psFree(sIter); 141 psFree(sList); 142 psFree(match); 143 return allMatch; 144 } 79 145 default: 80 146 return false; … … 82 148 psAbort(__func__, "Should never get here.\n"); 83 149 } 150 84 151 85 152 // Format a single concept … … 216 283 } else if (strcasecmp(source, "VALUE") == 0) { 217 284 psTrace(__func__, 8, "Checking %s against camera format.\n", name); 218 if (! compareConcepts( cameraItem, formatted)) {285 if (! compareConcepts(formatted, cameraItem)) { 219 286 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " 220 287 "format, but the values don't match.\n", name); … … 224 291 "write\n", nameSource); 225 292 } 226 } else if (! compareConcepts( cameraItem, formatted)) {293 } else if (! compareConcepts(formatted, cameraItem)) { 227 294 // Assume it's specified by value 228 295 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " … … 290 357 continue; 291 358 } 292 if (! compareConcepts( defaultItem, formatted)) {359 if (! compareConcepts(formatted, defaultItem)) { 293 360 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera " 294 361 "format, but the values don't match.\n", name);
Note:
See TracChangeset
for help on using the changeset viewer.
