Changeset 8973
- Timestamp:
- Sep 25, 2006, 4:55:34 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 10 edited
-
psArguments.c (modified) (2 diffs)
-
psArray.c (modified) (3 diffs)
-
psBitSet.c (modified) (10 diffs)
-
psBitSet.h (modified) (8 diffs)
-
psHash.c (modified) (12 diffs)
-
psHash.h (modified) (1 diff)
-
psMetadata.c (modified) (3 diffs)
-
psMetadataConfig.c (modified) (5 diffs)
-
psPixels.c (modified) (1 diff)
-
psPixels.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psArguments.c
r8965 r8973 7 7 * @author David Robbins, MHPCC 8 8 * 9 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09-26 0 1:41:29$9 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 02:55:34 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 13 13 */ 14 14 15 #include<stdio.h> 16 #include<stdarg.h> 17 #include<string.h> 15 #include <stdio.h> 16 #include <stdarg.h> 17 #include <string.h> 18 #include <inttypes.h> 19 18 20 #include "psArguments.h" 19 21 #include "fitsio.h" … … 315 317 // Print the value 316 318 switch (item->type) { 317 PRINT_CASE(U8, "%u");318 PRINT_CASE(U16, "%u");319 PRINT_CASE(U32, "%u");320 PRINT_CASE(U64, "%lu");321 PRINT_CASE(S8, "%d");322 PRINT_CASE(S16, "%d");323 PRINT_CASE(S32, "%d");324 PRINT_CASE(S64, "%ld");325 PRINT_CASE(F32, "%.6e");326 PRINT_CASE(F64, "%.6e");319 PRINT_CASE(U8, "%u"); 320 PRINT_CASE(U16, "%u"); 321 PRINT_CASE(U32, "%u"); 322 PRINT_CASE(U64, "%" PRIu64); 323 PRINT_CASE(S8, "%d"); 324 PRINT_CASE(S16, "%d"); 325 PRINT_CASE(S32, "%d"); 326 PRINT_CASE(S64, "%" PRId64); 327 PRINT_CASE(F32, "%.6e"); 328 PRINT_CASE(F64, "%.6e"); 327 329 case PS_DATA_BOOL: 328 330 if (item->data.B) { -
trunk/psLib/src/types/psArray.c
r8965 r8973 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.5 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-09-26 0 1:41:29$11 * @version $Revision: 1.54 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-09-26 02:55:34 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 164 164 PS_ASSERT_PTR_NON_NULL(array, false); 165 165 166 if (position >array->n) {166 if (position < 0 || position >= array->n) { 167 167 psError(PS_ERR_BAD_PARAMETER_NULL, true, 168 168 _("position > then the number of elements in the array.")); … … 174 174 psFree(array->data[i]); 175 175 memmove(&array->data[i], &array->data[i + 1], (n - i - 1) * sizeof(psPtr)); 176 array->n = --i; // reset the array size to indicate the removed item(s)176 array->n--; // reset the array size to indicate the removed item 177 177 178 178 return true; -
trunk/psLib/src/types/psBitSet.c
r8965 r8973 11 11 * @author Robert DeSonia, MHPCC 12 12 * 13 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-09-26 0 1:41:29$13 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-09-26 02:55:34 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 27 27 #include "psAbort.h" 28 28 #include "psString.h" 29 #include "psAssert.h"30 29 31 30 … … 61 60 static void bitSetFree(psBitSet* inBitSet) 62 61 { 62 if (inBitSet == NULL) { 63 return; 64 } 63 65 psFree(inBitSet->bits); 64 66 } … … 75 77 psBitSet* psBitSetAlloc(long nalloc) 76 78 { 79 psS32 numBytes = 0; 80 psBitSet* newObj = NULL; 81 77 82 if (nalloc < 0) { 78 83 psError(PS_ERR_BAD_PARAMETER_VALUE, true, … … 81 86 return NULL; 82 87 } 83 84 psS32 numBytes = 0;85 psBitSet* newObj = NULL;86 88 87 89 numBytes = ceil(nalloc / 8.0); … … 172 174 const psBitSet* inBitSet2) 173 175 { 174 if (inBitSet1 == NULL) {175 psError(PS_ERR_BAD_PARAMETER_NULL, true,176 _("First psBitSet operand can not be NULL."));177 psFree(outBitSet);178 return NULL;179 }180 if (operator == NULL) {181 psError(PS_ERR_BAD_PARAMETER_NULL, true,182 _("Specified operator is NULL. Must specify desired operator."));183 psFree(outBitSet);184 return NULL;185 }186 176 psS32 i = 0; 187 177 psS32 n = 0; … … 191 181 psS32 op = UNKNOWN_OP; 192 182 183 if (inBitSet1 == NULL) { 184 psError(PS_ERR_BAD_PARAMETER_NULL, true, 185 _("First psBitSet operand can not be NULL.")); 186 psFree(outBitSet); 187 return NULL; 188 } 193 189 inBits1 = inBitSet1->bits; 194 190 191 if (operator == NULL) { 192 psError(PS_ERR_BAD_PARAMETER_NULL, true, 193 _("Specified operator is NULL. Must specify desired operator.")); 194 psFree(outBitSet); 195 return NULL; 196 } 195 197 196 198 // parse the operator … … 255 257 break; 256 258 case NOT_OP: 257 default:258 259 for (i = 0; i < n; i++) { 259 260 outBits[i] = ~inBits1[i]; 260 261 } 261 262 break; 263 default: 264 psAbort("psBitSetOp", 265 "Unexpected error - operator parsed successfully but not valid?"); 262 266 } 263 267 … … 277 281 outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL); 278 282 283 if (outBitSet == NULL) { 284 psError(PS_ERR_UNKNOWN, false, 285 _("Could not perform NOT operation.")); 286 } 287 279 288 return outBitSet; 280 289 } … … 282 291 psString psBitSetToString(const psBitSet* bitSet) 283 292 { 284 PS_ASSERT_PTR_NON_NULL(bitSet, NULL);285 293 psS32 i = 0; 286 294 psS32 numBits = bitSet->n * 8; 287 // char *outString = psAlloc((size_t) numBits + 1); 288 psString outString = psStringAlloc(numBits + 1); 295 char *outString = psAlloc((size_t) numBits + 1); 289 296 290 297 for (i = 0; i < numBits; i++) { -
trunk/psLib/src/types/psBitSet.h
r8965 r8973 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-09-26 0 1:41:29$14 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 02:55:34 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 32 32 /** Struct containing array of bytes to hold bit data and corresponding array length. 33 33 * 34 * The bits in the struct are assembled in as an array of bytes with eight bits per 35 * byte. The bits are arranged with the LSB in first (right most) position of the 36 * first array element. 34 * The bits in the struct are assembled in as an array of bytes with eight bits per byte. The bits are 35 * arranged with the LSB in first (right most) position of the first array element. 37 36 */ 38 37 typedef struct … … 52 51 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 53 52 * 54 * @return bool: True if the pointer matches a psBitSet structure, false otherwise.53 * @return bool: True if the pointer matches a psBitSet structure, false otherwise. 55 54 */ 56 55 bool psMemCheckBitSet( … … 61 60 /** Allocate a psBitSet. 62 61 * 63 * Create a psBitSet with the number of bits specified by the user. All bits are set 64 * to zero uponallocation.62 * Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon 63 * allocation. 65 64 * 66 65 * @return psBitSet* : Pointer to struct containing array of bits and size of array. 67 66 */ 68 67 psBitSet* psBitSetAlloc( 69 long nalloc ///< Number of bits in psBitSet array68 long nalloc ///< Number of bits in psBitSet array 70 69 ); 71 70 … … 73 72 * 74 73 * Sets a bit at a given bit location. The bit is set based on a zero index with the 75 * first bit set in the zero bit slot of the zero element of the byte array. As an 76 * example, setting bit 3 in an array with two elements would result in an psBitSet 77 * that looks like 00000000 00001000. 74 * first bit set in the zero bit slot of the zero element of the byte array. As an example, setting bit 3 in 75 * an array with two elements would result in an psBitSet that looks like 00000000 00001000. 78 76 * 79 77 * @return psBitSet* : Pointer to struct containing psBitSet. … … 99 97 /** Test the value of a bit. 100 98 * 101 * Prints the value of a bit at a given bit location, either one or zero. The resulting 102 * bit is based on a zero index format with the first bit set in the zero bit slot of 103 * the zero element of the byte array. As an example, testing bit 3 in a psBitSet with 104 * two bytes that looks like 00000000 00001000 would return a value of one, since that 105 * is the value that was set. 99 * Prints the value of a bit at a given bit location, either one or zero. The resulting bit is based on a 100 * zero index format with the first bit set in the zero bit slot of the zero element of the byte array 101 * As an example, testing bit 3 in a psBitSet with two bytes that looks like 00000000 00001000 would return a 102 * value of one, since that is the value that was set. 106 103 * 107 104 * @return bool: True if successful, otherwise false 108 105 */ 106 109 107 bool psBitSetTest( 110 108 const psBitSet* bitSet, ///< Pointer psBitSet to be tested. … … 114 112 /** Perform a binary operation on two psBitSets 115 113 * 116 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, 117 * the operation will notbe performed and an error message will be logged.114 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not 115 * be performed and an error message will be logged. 118 116 * 119 117 * @return psBitSet* : Pointer to struct containing result of binary operation. 120 118 */ 121 119 psBitSet* psBitSetOp( 122 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation123 const psBitSet* inBitSet1, ///< First psBitSet on which to operate124 const char *operator, ///< Bit operation125 const psBitSet* inBitSet2 ///< SecondpsBitSet on which to operate120 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation 121 const psBitSet* inBitSet1, ///< First psBitSet on which to operate 122 const char *operator, ///< Bit operation 123 const psBitSet* inBitSet2 ///< First psBitSet on which to operate 126 124 ); 127 125 128 126 /** Perform a not operation on a psBitSet 129 127 * 130 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set 131 * to zero. 128 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero. 132 129 * 133 130 * @return psBitSet* : Pointer to struct containing result of operation. 134 131 */ 132 135 133 psBitSet* psBitSetNot( 136 134 psBitSet* outBitSet, ///< Resulting psBitSet from operation … … 140 138 /** Convert the psBitSet to a string of ones and zeros. 141 139 * 142 * Converts the contents of a psBitSet to a string representation of its binary form of 143 * ones and zeros. The LSB is the right-most chracter. Each set of eight characters 144 * represents one byte. 140 * Converts the contents of a psBitSet to a string representation of its binary form of ones and zeros. The 141 * LSB is the right-most chracter. Each set of eight characters represents one byte. 145 142 * 146 * @return psString:Pointer to character array containing string data.143 * @return char*: Pointer to character array containing string data. 147 144 */ 145 148 146 psString psBitSetToString( 149 const psBitSet* bitSet ///< psBitSet to convert 147 const psBitSet* bitSet ///< psBitSet to convert */ 150 148 ); 151 149 -
trunk/psLib/src/types/psHash.c
r8965 r8973 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-09-26 0 1:41:29$14 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 02:55:34 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 47 47 psList* psHashKeyList(const psHash* hash) 48 48 { 49 PS_ASSERT_PTR_NON_NULL(hash, NULL);50 49 psS32 i = 0; // Loop index variable 51 50 psList* myLinkList = NULL; // The output data structure 52 51 psHashBucket* ptr = NULL; // Used to step thru linked list. 53 52 53 if (hash == NULL) { 54 return NULL; 55 } 54 56 // Create the linked list 55 57 myLinkList = psListAlloc(NULL); … … 96 98 bucket->key = psStringCopy(key); 97 99 98 //XXX: Since this function is static and only called by doHashWork, 99 //data can never be NULL here. 100 // if (data == NULL) { 101 // NOTE: Should we flag a warning message? 102 // bucket->data = NULL; 103 // } else { 104 bucket->data = psMemIncrRefCounter(data); 105 // } 100 if (data == NULL) { 101 // NOTE: Should we flag a warning message? 102 bucket->data = NULL; 103 } else { 104 bucket->data = psMemIncrRefCounter(data); 105 } 106 106 107 107 bucket->next = next; … … 120 120 static void hashBucketFree(psHashBucket* bucket) 121 121 { 122 if (bucket == NULL) { 123 return; 124 } 125 122 126 psFree(bucket->key); 127 123 128 psFree(bucket->data); 124 129 } … … 134 139 psHash* psHashAlloc(long nalloc) // initial number of buckets 135 140 { 136 if (nalloc < 0)137 {138 psError(PS_ERR_BAD_PARAMETER_VALUE, true,139 "Can't allocate a psHash of negative size.");140 return NULL;141 }142 141 psS32 i = 0; // loop index variable 143 142 … … 186 185 psS32 i = 0; // Loop index variable. 187 186 187 if (table == NULL) { 188 return; 189 } 188 190 // Loop through each bucket in the hash table. If that bucket is not 189 191 // NULL, then free the bucket via a function call to hashBucketFree(); … … 223 225 static psPtr doHashWork(psHash* table, 224 226 const char *key, 225 psPtr data, 226 psBool remove 227 psPtr data, psBool remove 227 228 ) 228 229 { … … 239 240 // function, but I'm checking it anyway since future coders might change 240 241 // the way this procedure is called. 241 /* if ((table == NULL) || (key == NULL)) { 242 psError(PS_ERR_BAD_PARAMETER_NULL, true, 243 _("Input key can not be NULL.")); 244 return NULL; 245 } 246 */ 242 if ((table == NULL) || (key == NULL)) { 243 psError(PS_ERR_BAD_PARAMETER_NULL, true, 244 _("Input key can not be NULL.")); 245 return NULL; 246 } 247 247 // NOTE: This is the originally supplied hash function. 248 248 // for (psS32 i = 0, len = strlen(key); i < len; i++) { … … 253 253 // This hash algorithm is from Sedgewick. NOTE: must reread to ensure that 254 254 // the size of the hash table is not required to be a prime number. 255 if (table->n <= 0)256 return NULL;257 255 tmpchar = (char *)key; 258 256 for (hash = 0; *tmpchar != '\0'; tmpchar++) { … … 262 260 // NOTE: This should not be necessary, but for now, I'm checking bounds 263 261 // anyway. 264 /* if ((hash < 0) || (hash >= table->n)) { 265 psError(PS_ERR_UNKNOWN, true, 266 "Internal hash function out of range (%" PRId64 ")", hash); 267 } 268 */ 262 if ((hash < 0) || (hash >= table->n)) { 263 psError(PS_ERR_UNKNOWN, true, 264 "Internal hash function out of range (%" PRId64 ")", hash); 265 } 269 266 // ptr will have the correct hash bucket. 270 267 ptr = table->buckets[hash]; … … 400 397 const char *key) 401 398 { 399 psPtr data = NULL; 400 psBool retVal = false; 401 402 402 PS_ASSERT_PTR_NON_NULL(hash, false); 403 403 PS_ASSERT_PTR_NON_NULL(key, false); 404 405 psPtr data = NULL;406 psBool retVal = false;407 404 408 405 data = doHashWork(hash, key, NULL, true); … … 424 421 int nElements = 0; 425 422 int nbucket = hash->n; 426 //XXX: If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data)427 //we can eliminate the 2nd for loop below.428 423 for (int i = 0; i < nbucket; i++) { 429 424 psHashBucket* tmpBucket = hash->buckets[i]; -
trunk/psLib/src/types/psHash.h
r8965 r8973 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-09-26 0 1:41:29$13 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-09-26 02:55:34 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/types/psMetadata.c
r8965 r8973 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.13 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-09-26 0 1:41:29$14 * @version $Revision: 1.135 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 02:55:34 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 605 605 // Node doesn't exist - Add new metadata item to metadata collection's hash 606 606 /* The following is unneeded. HashAdd can't return false with non-null inputs. 607 607 608 608 if(!psHashAdd(mdTable, key, (psPtr)item)) { 609 609 psError(PS_ERR_UNKNOWN,false, … … 1315 1315 } 1316 1316 case PS_DATA_LIST: 1317 fprintf(fd, "<a list of unknown contents>\n");1317 fprintf(fd, "<a list of size %ld>\n", ((psList*)item->data.V)->n); 1318 1318 break; 1319 1319 case PS_DATA_TIME: { -
trunk/psLib/src/types/psMetadataConfig.c
r8965 r8973 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.9 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-09-26 0 1:41:29$12 * @version $Revision: 1.92 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-09-26 02:55:34 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 1157 1157 PS_ASSERT_PTR_NON_NULL(filename,NULL); 1158 1158 1159 struct stat buf;1160 1161 1159 // Attempt to open specified file 1162 1160 int fd = 0; … … 1164 1162 // XXX really should return strerror() here 1165 1163 psError(PS_ERR_IO, true, _("Failed to open file '%s'. Check if it exists and it has the proper permissions."), filename); 1164 return NULL; 1165 } 1166 1167 struct stat buf; // Results of stat() for file 1168 if (fstat(fd, &buf) != 0) { 1169 psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename); 1170 close(fd); 1166 1171 return NULL; 1167 1172 } … … 1329 1334 break; 1330 1335 case PS_DATA_BOOL: 1331 psStringAppend (&content, "%-15s %-8s -%15s",1336 psStringAppend (&content, "%-15s %-8s %-15s", 1332 1337 item->name, "BOOL", item->data.B ? "T" : "F"); 1333 1338 if (item->comment && strncmp(item->comment, "", 2)) { … … 1367 1372 break; 1368 1373 case PS_DATA_STRING: 1369 psStringAppend(&content, "%-15s %-8s -%15s", 1370 item->name, "STR", item->data.str); 1374 if (item->data.str && strlen(item->data.str) > 0) { 1375 psStringAppend(&content, "%-15s %-8s %-15s", 1376 item->name, "STR", item->data.str); 1377 } else { 1378 psStringAppend(&content, "%-15s %-8s %-15s", 1379 item->name, "STR", "NULL"); 1380 } 1371 1381 if (item->comment && strncmp(item->comment,"",2)) { 1372 1382 psStringAppend(&content, " # %s", item->comment); -
trunk/psLib/src/types/psPixels.c
r8965 r8973 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09-26 0 1:41:29$9 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 02:55:34 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/types/psPixels.h
r8965 r8973 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09-26 0 1:41:29$9 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 02:55:34 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
Note:
See TracChangeset
for help on using the changeset viewer.
