Changeset 8965
- Timestamp:
- Sep 25, 2006, 3:41:29 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) (9 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
r8808 r8965 7 7 * @author David Robbins, MHPCC 8 8 * 9 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09- 13 21:11:11$9 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 01:41:29 $ 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> 18 #include <inttypes.h> 19 15 #include<stdio.h> 16 #include<stdarg.h> 17 #include<string.h> 20 18 #include "psArguments.h" 21 19 #include "fitsio.h" … … 317 315 // Print the value 318 316 switch (item->type) { 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");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"); 329 327 case PS_DATA_BOOL: 330 328 if (item->data.B) { -
trunk/psLib/src/types/psArray.c
r8816 r8965 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.5 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-09- 15 14:38:25$11 * @version $Revision: 1.53 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-09-26 01:41:29 $ 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 < 0 || position >=array->n) {166 if (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 --; // reset the array size to indicate the removed item176 array->n = --i; // reset the array size to indicate the removed item(s) 177 177 178 178 return true; -
trunk/psLib/src/types/psBitSet.c
r8627 r8965 11 11 * @author Robert DeSonia, MHPCC 12 12 * 13 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-0 8-26 04:34:28$13 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-09-26 01:41:29 $ 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" 29 30 30 31 … … 60 61 static void bitSetFree(psBitSet* inBitSet) 61 62 { 62 if (inBitSet == NULL) {63 return;64 }65 63 psFree(inBitSet->bits); 66 64 } … … 77 75 psBitSet* psBitSetAlloc(long nalloc) 78 76 { 77 if (nalloc < 0) { 78 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 79 _("The number of bit in a psBitSet (%ld) must be greater than zero."), 80 nalloc); 81 return NULL; 82 } 83 79 84 psS32 numBytes = 0; 80 85 psBitSet* newObj = NULL; 81 82 if (nalloc < 0) {83 psError(PS_ERR_BAD_PARAMETER_VALUE, true,84 _("The number of bit in a psBitSet (%ld) must be greater than zero."),85 nalloc);86 return NULL;87 }88 86 89 87 numBytes = ceil(nalloc / 8.0); … … 174 172 const psBitSet* inBitSet2) 175 173 { 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 } 176 186 psS32 i = 0; 177 187 psS32 n = 0; … … 181 191 psS32 op = UNKNOWN_OP; 182 192 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 }189 193 inBits1 = inBitSet1->bits; 190 194 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 }197 195 198 196 // parse the operator … … 257 255 break; 258 256 case NOT_OP: 257 default: 259 258 for (i = 0; i < n; i++) { 260 259 outBits[i] = ~inBits1[i]; 261 260 } 262 261 break; 263 default:264 psAbort("psBitSetOp",265 "Unexpected error - operator parsed successfully but not valid?");266 262 } 267 263 … … 281 277 outBitSet = psBitSetOp(outBitSet,inBitSet,"NOT",NULL); 282 278 283 if (outBitSet == NULL) {284 psError(PS_ERR_UNKNOWN, false,285 _("Could not perform NOT operation."));286 }287 288 279 return outBitSet; 289 280 } … … 291 282 psString psBitSetToString(const psBitSet* bitSet) 292 283 { 284 PS_ASSERT_PTR_NON_NULL(bitSet, NULL); 293 285 psS32 i = 0; 294 286 psS32 numBits = bitSet->n * 8; 295 char *outString = psAlloc((size_t) numBits + 1); 287 // char *outString = psAlloc((size_t) numBits + 1); 288 psString outString = psStringAlloc(numBits + 1); 296 289 297 290 for (i = 0; i < numBits; i++) { -
trunk/psLib/src/types/psBitSet.h
r5057 r8965 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $15 * @date $Date: 200 5-09-15 21:22:22$14 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 01:41:29 $ 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 byte. The bits are 35 * arranged with the LSB in first (right most) position of the first array element. 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. 36 37 */ 37 38 typedef struct … … 51 52 * Uses the appropriate deallocation function in psMemBlock to check the ptr datatype. 52 53 * 53 * @return bool: True if the pointer matches a psBitSet structure, false otherwise.54 * @return bool: True if the pointer matches a psBitSet structure, false otherwise. 54 55 */ 55 56 bool psMemCheckBitSet( … … 60 61 /** Allocate a psBitSet. 61 62 * 62 * Create a psBitSet with the number of bits specified by the user. All bits are set to zero upon63 * allocation.63 * Create a psBitSet with the number of bits specified by the user. All bits are set 64 * to zero upon allocation. 64 65 * 65 66 * @return psBitSet* : Pointer to struct containing array of bits and size of array. 66 67 */ 67 68 psBitSet* psBitSetAlloc( 68 long nalloc ///< Number of bits in psBitSet array69 long nalloc ///< Number of bits in psBitSet array 69 70 ); 70 71 … … 72 73 * 73 74 * Sets a bit at a given bit location. The bit is set based on a zero index with the 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. 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. 76 78 * 77 79 * @return psBitSet* : Pointer to struct containing psBitSet. … … 97 99 /** Test the value of a bit. 98 100 * 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. 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. 103 106 * 104 107 * @return bool: True if successful, otherwise false 105 108 */ 106 107 109 bool psBitSetTest( 108 110 const psBitSet* bitSet, ///< Pointer psBitSet to be tested. … … 112 114 /** Perform a binary operation on two psBitSets 113 115 * 114 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, the operation will not115 * be performed and an error message will be logged.116 * Perform an AND, OR, or XOR on two psBitSets. If the BitMasks are not the same size, 117 * the operation will not be performed and an error message will be logged. 116 118 * 117 119 * @return psBitSet* : Pointer to struct containing result of binary operation. 118 120 */ 119 121 psBitSet* psBitSetOp( 120 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation121 const psBitSet* inBitSet1, ///< First psBitSet on which to operate122 const char *operator, ///< Bit operation123 const psBitSet* inBitSet2 ///< FirstpsBitSet on which to operate122 psBitSet* outBitSet, ///< Resulting psBitSet from binary operation 123 const psBitSet* inBitSet1, ///< First psBitSet on which to operate 124 const char *operator, ///< Bit operation 125 const psBitSet* inBitSet2 ///< Second psBitSet on which to operate 124 126 ); 125 127 126 128 /** Perform a not operation on a psBitSet 127 129 * 128 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set to zero. 130 * Toggles bits in a psBitset. All zero bits are set to one and all one bits are set 131 * to zero. 129 132 * 130 133 * @return psBitSet* : Pointer to struct containing result of operation. 131 134 */ 132 133 135 psBitSet* psBitSetNot( 134 136 psBitSet* outBitSet, ///< Resulting psBitSet from operation … … 138 140 /** Convert the psBitSet to a string of ones and zeros. 139 141 * 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. 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. 142 145 * 143 * @return char*:Pointer to character array containing string data.146 * @return psString: Pointer to character array containing string data. 144 147 */ 145 146 148 psString psBitSetToString( 147 const psBitSet* bitSet ///< psBitSet to convert */149 const psBitSet* bitSet ///< psBitSet to convert 148 150 ); 149 151 -
trunk/psLib/src/types/psHash.c
r8668 r8965 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.3 0$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-0 8-29 20:23:54$14 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 01:41:29 $ 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); 49 50 psS32 i = 0; // Loop index variable 50 51 psList* myLinkList = NULL; // The output data structure 51 52 psHashBucket* ptr = NULL; // Used to step thru linked list. 52 53 53 if (hash == NULL) {54 return NULL;55 }56 54 // Create the linked list 57 55 myLinkList = psListAlloc(NULL); … … 98 96 bucket->key = psStringCopy(key); 99 97 100 if (data == NULL) { 101 // NOTE: Should we flag a warning message? 102 bucket->data = NULL; 103 } else { 104 bucket->data = psMemIncrRefCounter(data); 105 } 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 // } 106 106 107 107 bucket->next = next; … … 120 120 static void hashBucketFree(psHashBucket* bucket) 121 121 { 122 if (bucket == NULL) {123 return;124 }125 126 122 psFree(bucket->key); 127 128 123 psFree(bucket->data); 129 124 } … … 139 134 psHash* psHashAlloc(long nalloc) // initial number of buckets 140 135 { 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 } 141 142 psS32 i = 0; // loop index variable 142 143 … … 185 186 psS32 i = 0; // Loop index variable. 186 187 187 if (table == NULL) {188 return;189 }190 188 // Loop through each bucket in the hash table. If that bucket is not 191 189 // NULL, then free the bucket via a function call to hashBucketFree(); … … 225 223 static psPtr doHashWork(psHash* table, 226 224 const char *key, 227 psPtr data, psBool remove 225 psPtr data, 226 psBool remove 228 227 ) 229 228 { … … 240 239 // function, but I'm checking it anyway since future coders might change 241 240 // the way this procedure is called. 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 } 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 */ 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; 255 257 tmpchar = (char *)key; 256 258 for (hash = 0; *tmpchar != '\0'; tmpchar++) { … … 260 262 // NOTE: This should not be necessary, but for now, I'm checking bounds 261 263 // anyway. 262 if ((hash < 0) || (hash >= table->n)) { 263 psError(PS_ERR_UNKNOWN, true, 264 "Internal hash function out of range (%" PRId64 ")", hash); 265 } 264 /* if ((hash < 0) || (hash >= table->n)) { 265 psError(PS_ERR_UNKNOWN, true, 266 "Internal hash function out of range (%" PRId64 ")", hash); 267 } 268 */ 266 269 // ptr will have the correct hash bucket. 267 270 ptr = table->buckets[hash]; … … 397 400 const char *key) 398 401 { 402 PS_ASSERT_PTR_NON_NULL(hash, false); 403 PS_ASSERT_PTR_NON_NULL(key, false); 404 399 405 psPtr data = NULL; 400 406 psBool retVal = false; 401 402 PS_ASSERT_PTR_NON_NULL(hash, false);403 PS_ASSERT_PTR_NON_NULL(key, false);404 407 405 408 data = doHashWork(hash, key, NULL, true); … … 421 424 int nElements = 0; 422 425 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. 423 428 for (int i = 0; i < nbucket; i++) { 424 429 psHashBucket* tmpBucket = hash->buckets[i]; -
trunk/psLib/src/types/psHash.h
r8839 r8965 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-09- 19 23:54:43$13 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-09-26 01:41:29 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/types/psMetadata.c
r8846 r8965 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.13 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-09-2 0 02:08:43$14 * @version $Revision: 1.134 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-09-26 01:41:29 $ 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 size %ld>\n", ((psList*)item->data.V)->n);1317 fprintf(fd, "<a list of unknown contents>\n"); 1318 1318 break; 1319 1319 case PS_DATA_TIME: { -
trunk/psLib/src/types/psMetadataConfig.c
r8837 r8965 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.9 0$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-09- 19 03:45:24$12 * @version $Revision: 1.91 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-09-26 01:41:29 $ 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 1159 1161 // Attempt to open specified file 1160 1162 int fd = 0; … … 1162 1164 // XXX really should return strerror() here 1163 1165 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 file1168 if (fstat(fd, &buf) != 0) {1169 psError(PS_ERR_IO, true, _("Unable to stat file '%s'.\n"), filename);1170 close(fd);1171 1166 return NULL; 1172 1167 } … … 1334 1329 break; 1335 1330 case PS_DATA_BOOL: 1336 psStringAppend (&content, "%-15s %-8s %-15s",1331 psStringAppend (&content, "%-15s %-8s -%15s", 1337 1332 item->name, "BOOL", item->data.B ? "T" : "F"); 1338 1333 if (item->comment && strncmp(item->comment, "", 2)) { … … 1372 1367 break; 1373 1368 case PS_DATA_STRING: 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 } 1369 psStringAppend(&content, "%-15s %-8s -%15s", 1370 item->name, "STR", item->data.str); 1381 1371 if (item->comment && strncmp(item->comment,"",2)) { 1382 1372 psStringAppend(&content, " # %s", item->comment); -
trunk/psLib/src/types/psPixels.c
r8839 r8965 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09- 19 23:54:43$9 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 01:41:29 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/types/psPixels.h
r8839 r8965 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-09- 19 23:54:43$9 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-09-26 01:41:29 $ 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.
