Changeset 32232
- Timestamp:
- Aug 30, 2011, 5:09:24 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/streaksremove.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/streaksremove.c
r31716 r32232 9 9 10 10 #include "streaksremove.h" 11 12 #include "psFitsTableNew.h" 11 13 12 14 static pmConfig *parseArguments(int argc, char **argv); … … 302 304 psLibFinalize(); 303 305 304 fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "streaksremove"); 306 int leaks = psMemCheckLeaks (0, NULL, stdout, false); 307 308 fprintf(stderr, "Found %d leaks at %s\n", leaks, "streaksremove"); 305 309 306 310 return 0; … … 917 921 sFile *out = sfiles->outSources; 918 922 919 920 923 // Primary header, should be "something.hdr" 921 924 { … … 960 963 } 961 964 962 psArray *inTable = psFitsReadTable(in->fits); 963 if (!inTable) { 965 #ifdef CHECK_MEM_USE 966 bool printStats = false; 967 size_t allocated = 0; 968 size_t persistent = 0; 969 size_t allocatedBefore = psMemStats(printStats, &allocated, &persistent); 970 printf("Before: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedBefore); 971 #endif 972 973 psFitsTable *table = psFitsReadTableNew(in->fits); 974 975 #ifdef CHECK_MEM_USE 976 size_t allocatedAfter = psMemStats(printStats, &allocated, &persistent); 977 printf("After: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedAfter); 978 printf("Change: %12lld\n", (long long) allocatedAfter - allocatedBefore); 979 #endif 980 981 if (!table) { 964 982 psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name); 965 983 streaksExit("", PS_EXIT_DATA_ERROR); 966 984 } 967 985 968 psArray *outTable = psArrayAllocEmpty(inTable->n); 969 int j = 0; 986 // XXX: Handle case where numCols == 0 Can that happen? 987 // Previously we were writing a blank extension 988 int xCol = psFitsTableGetColumnIndex(table, "X_PSF"); 989 assert(xCol >= 0 && xCol < table->numCols); 990 991 int yCol = psFitsTableGetColumnIndex(table, "Y_PSF"); 992 assert(yCol >= 0 && yCol < table->numCols); 993 994 bool *rowCensored = psAlloc(table->numRows * sizeof(bool)); 970 995 int numCensored = 0; 971 for (int i = 0 ; i < inTable->n; i++) { 972 psMetadata *row = inTable->data[i]; 973 974 psF32 x = psMetadataLookupF32(NULL, row, "X_PSF"); 975 psF32 y = psMetadataLookupF32(NULL, row, "Y_PSF"); 996 997 for (int i = 0 ; i < table->numRows; i++) { 998 psF32 x = psFitsTableGetCellF32(table, i, xCol); 999 psF32 y = psFitsTableGetCellF32(table, i, yCol); 976 1000 977 1001 psImageMaskType mask; … … 984 1008 // Key the source if the center pixel is not masked with maskStreak 985 1009 if (!(mask & maskStreak) ) { 986 psArraySet(outTable, j++, row); 1010 // psArraySet(outTable, j++, row); 1011 rowCensored[i] = false; 987 1012 } else { 1013 rowCensored[i] = true; 988 1014 numCensored++; 989 1015 } 990 1016 } 991 1017 992 // get rid of unused elements (don't know if this is necessary) 993 psArrayRealloc(outTable, j); 1018 if (!psFitsTableCensor(table, rowCensored)) { 1019 streaksExit("", PS_EXIT_PROG_ERROR); 1020 } 994 1021 995 1022 addDestreakKeyword(header, true); 996 if (psArrayLength(outTable) > 0) { 1023 1024 if (table->numCols > 0) { 997 1025 printf("Censored %d sources\n", numCensored); 998 if (! psFitsWriteTable (out->fits, header, outTable, extname)) {1026 if (! psFitsWriteTableNew(out->fits, header, table, extname)) { 999 1027 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 1000 1028 streaksExit("", PS_EXIT_DATA_ERROR); 1001 1029 } 1002 } else if (psArrayLength(inTable) == 0){1030 } else { 1003 1031 printf("No input sources\n"); 1004 1032 // We'd like to write a blank table, but this is as good as it gets without more work to parse the … … 1008 1036 streaksExit("", PS_EXIT_DATA_ERROR); 1009 1037 } 1010 } else {1011 printf("Censored ALL %d sources\n", numCensored);1012 if (! psFitsWriteTableEmpty(out->fits, header, inTable->data[0], extname)) {1013 psErrorStackPrint(stderr, "failed to write empty table to %s", out->resolved_name);1014 streaksExit("", PS_EXIT_DATA_ERROR);1015 }1016 1038 } 1017 1039 psFree(header); 1018 psFree( outTable);1019 psFree( inTable);1040 psFree(table); 1041 psFree(rowCensored); 1020 1042 } 1021 1043 … … 1049 1071 } 1050 1072 1051 1052 1073 if (!psFitsClose(out->fits)) { 1053 1074 psErrorStackPrint(stderr, "failed to close table %s", out->resolved_name); 1054 1075 streaksExit("", PS_EXIT_DATA_ERROR); 1055 1076 } 1056 } 1077 out->fits = NULL; 1078 }
Note:
See TracChangeset
for help on using the changeset viewer.
