Changeset 32337 for branches/eam_branches/ipp-20110710/magic
- Timestamp:
- Sep 6, 2011, 11:00:22 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110710/magic/remove/src
- Files:
-
- 2 edited
-
streaksio.c (modified) (5 diffs)
-
streaksremove.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110710/magic/remove/src/streaksio.c
r30404 r32337 752 752 return; 753 753 } 754 ps Array *table = psFitsReadTable(in->fits);754 psFitsTable *table = psFitsReadTableNew(in->fits); 755 755 if (!table) { 756 756 psError(PS_ERR_UNKNOWN, false, "failed to read table in extension %d from in->resolved name", extnum); … … 758 758 } 759 759 760 if (!psFitsWriteTable (out->fits, out->header, table, extname)) {760 if (!psFitsWriteTableNew(out->fits, out->header, table, extname)) { 761 761 psError(PS_ERR_UNKNOWN, false, "failed to copy table in extension %d", extnum); 762 762 streaksExit("", PS_EXIT_DATA_ERROR); 763 763 } 764 psFree(table); 764 765 } 765 766 … … 839 840 psFree(sfile->name); 840 841 psFree(sfile->resolved_name); 842 psFree(sfile->fits); 841 843 psFree(sfile); 842 844 } … … 915 917 sFileFree(sf->outWeight); 916 918 sFileFree(sf->recWeight); 919 } 920 if (sf->inSources) { 921 sFileFree(sf->inSources); 922 sFileFree(sf->outSources); 917 923 } 918 924 } … … 1301 1307 streaksExit("", PS_EXIT_UNKNOWN_ERROR); 1302 1308 } 1309 psFree(compress); 1303 1310 } else { 1304 1311 copyTable(out, in, extnum); -
branches/eam_branches/ipp-20110710/magic/remove/src/streaksremove.c
r31716 r32337 278 278 279 279 if (statsFileName) { 280 // Write out281 280 psString resolved = pmConfigConvertFilename(statsFileName, config, true, true); // Resolved filename 282 281 if (!resolved) { … … 292 291 } 293 292 294 // all done. Clean up tolook for memory leaks.293 // all done. Clean up and look for memory leaks. 295 294 296 295 psFree(sfiles); … … 302 301 psLibFinalize(); 303 302 304 fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "streaksremove"); 303 int leaks = psMemCheckLeaks (0, NULL, stdout, false); 304 305 fprintf(stderr, "Found %d leaks at %s\n", leaks, "streaksremove"); 305 306 306 307 return 0; … … 917 918 sFile *out = sfiles->outSources; 918 919 919 920 920 // Primary header, should be "something.hdr" 921 921 { … … 960 960 } 961 961 962 psArray *inTable = psFitsReadTable(in->fits); 963 if (!inTable) { 962 #ifdef CHECK_MEM_USE 963 bool printStats = false; 964 size_t allocated = 0; 965 size_t persistent = 0; 966 size_t allocatedBefore = psMemStats(printStats, &allocated, &persistent); 967 printf("Before: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedBefore); 968 #endif 969 970 psFitsTable *table = psFitsReadTableNew(in->fits); 971 972 #ifdef CHECK_MEM_USE 973 size_t allocatedAfter = psMemStats(printStats, &allocated, &persistent); 974 printf("After: %12lld %12lld %12lld\n", (long long) allocated, (long long) persistent, (long long) allocatedAfter); 975 printf("Change: %12lld\n", (long long) allocatedAfter - allocatedBefore); 976 #endif 977 978 if (!table) { 964 979 psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name); 965 980 streaksExit("", PS_EXIT_DATA_ERROR); 966 981 } 967 982 968 psArray *outTable = psArrayAllocEmpty(inTable->n); 969 int j = 0; 983 // XXX: Handle case where numCols == 0 Can that happen? 984 // Previously we were writing a blank extension 985 986 // For speed we get intimate with the table 987 // avoid 2 * numRows lookups of the column number by looking 988 // it up ahead of time and verifying that the type is what we 989 // expect. 990 int xCol = psFitsTableGetColumnNumber(table, "X_PSF"); 991 assert(xCol >= 0 && xCol < table->numCols); 992 assert(table->columns[xCol].type == PS_DATA_F32); 993 994 int yCol = psFitsTableGetColumnNumber(table, "Y_PSF"); 995 assert(yCol >= 0 && yCol < table->numCols); 996 assert(table->columns[yCol].type == PS_DATA_F32); 997 998 // We mark censored rows in this array. 999 bool *rowCensored = psAlloc(table->numRows * sizeof(bool)); 1000 memset(rowCensored, 0, table->numRows * sizeof(bool)); 970 1001 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"); 976 1002 1003 for (int i = 0 ; i < table->numRows; i++) { 1004 1005 #ifndef GO_SLOWER 1006 psF32 x = table->columns[xCol].data.F32[i]; 1007 psF32 y = table->columns[yCol].data.F32[i]; 1008 #else 1009 psF32 x = psFitsTableGetF32(NULL, table, i, "X_PSF"); 1010 psF32 y = psFitsTableGetF32(NULL, table, i, "Y_PSF"); 1011 #endif 977 1012 psImageMaskType mask; 978 1013 if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x < 0) || (y < 0) || isnan(x) || isnan(y)) { … … 983 1018 984 1019 // Key the source if the center pixel is not masked with maskStreak 985 if (!(mask & maskStreak) ) { 986 psArraySet(outTable, j++, row); 987 } else { 1020 if (mask & maskStreak) { 1021 rowCensored[i] = true; 988 1022 numCensored++; 989 1023 } 990 1024 } 991 1025 992 // get rid of unused elements (don't know if this is necessary) 993 psArrayRealloc(outTable, j); 1026 // remove the censored rows from the table 1027 if (!psFitsTableCensor(table, rowCensored)) { 1028 streaksExit("", PS_EXIT_PROG_ERROR); 1029 } 994 1030 995 1031 addDestreakKeyword(header, true); 996 if (psArrayLength(outTable) > 0) { 1032 1033 if (table->numCols > 0) { 997 1034 printf("Censored %d sources\n", numCensored); 998 if (! psFitsWriteTable (out->fits, header, outTable, extname)) {1035 if (! psFitsWriteTableNew(out->fits, header, table, extname)) { 999 1036 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 1000 1037 streaksExit("", PS_EXIT_DATA_ERROR); 1001 1038 } 1002 } else if (psArrayLength(inTable) == 0){1039 } else { 1003 1040 printf("No input sources\n"); 1004 1041 // We'd like to write a blank table, but this is as good as it gets without more work to parse the … … 1008 1045 streaksExit("", PS_EXIT_DATA_ERROR); 1009 1046 } 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 1047 } 1017 1048 psFree(header); 1018 psFree( outTable);1019 psFree( inTable);1049 psFree(table); 1050 psFree(rowCensored); 1020 1051 } 1021 1052 … … 1038 1069 } 1039 1070 1040 ps Array *inTable = psFitsReadTable(in->fits);1041 if (! inTable) {1071 psFitsTable *table = psFitsReadTableNew(in->fits); 1072 if (!table) { 1042 1073 psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name); 1043 1074 streaksExit("", PS_EXIT_DATA_ERROR); 1044 1075 } 1045 if (! psFitsWriteTable (out->fits, header, inTable, extname)) {1076 if (! psFitsWriteTableNew(out->fits, header, table, extname)) { 1046 1077 psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name); 1047 1078 streaksExit("", PS_EXIT_DATA_ERROR); 1048 1079 } 1049 } 1050 1080 psFree(header); 1081 psFree(table); 1082 } 1051 1083 1052 1084 if (!psFitsClose(out->fits)) { … … 1054 1086 streaksExit("", PS_EXIT_DATA_ERROR); 1055 1087 } 1056 } 1088 out->fits = NULL; // freed by psFitsclose() 1089 }
Note:
See TracChangeset
for help on using the changeset viewer.
