IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 6, 2011, 11:00:22 AM (15 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20110710/magic/remove/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110710/magic/remove/src/streaksio.c

    r30404 r32337  
    752752        return;
    753753    }
    754     psArray *table = psFitsReadTable(in->fits);
     754    psFitsTable *table = psFitsReadTableNew(in->fits);
    755755    if (!table) {
    756756        psError(PS_ERR_UNKNOWN, false, "failed to read table in extension %d from in->resolved name", extnum);
     
    758758    }
    759759
    760     if (!psFitsWriteTable(out->fits, out->header, table, extname)) {
     760    if (!psFitsWriteTableNew(out->fits, out->header, table, extname)) {
    761761        psError(PS_ERR_UNKNOWN, false, "failed to copy table in extension %d", extnum);
    762762        streaksExit("", PS_EXIT_DATA_ERROR);
    763763    }
     764    psFree(table);
    764765}
    765766
     
    839840    psFree(sfile->name);
    840841    psFree(sfile->resolved_name);
     842    psFree(sfile->fits);
    841843    psFree(sfile);
    842844}
     
    915917        sFileFree(sf->outWeight);
    916918        sFileFree(sf->recWeight);
     919    }
     920    if (sf->inSources) {
     921        sFileFree(sf->inSources);
     922        sFileFree(sf->outSources);
    917923    }
    918924}
     
    13011307                streaksExit("", PS_EXIT_UNKNOWN_ERROR);
    13021308            }
     1309            psFree(compress);
    13031310        } else {
    13041311            copyTable(out, in, extnum);
  • branches/eam_branches/ipp-20110710/magic/remove/src/streaksremove.c

    r31716 r32337  
    278278
    279279    if (statsFileName) {
    280     // Write out
    281280        psString resolved = pmConfigConvertFilename(statsFileName, config, true, true); // Resolved filename
    282281        if (!resolved) {
     
    292291    }
    293292
    294     // all done. Clean up to look for memory leaks.
     293    // all done. Clean up and look for memory leaks.
    295294
    296295    psFree(sfiles);
     
    302301    psLibFinalize();
    303302
    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");
    305306
    306307    return 0;
     
    917918    sFile *out = sfiles->outSources;
    918919
    919 
    920920    // Primary header, should be "something.hdr"
    921921    {
     
    960960        }
    961961
    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) {
    964979            psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name);
    965980            streaksExit("", PS_EXIT_DATA_ERROR);
    966981        }
    967982
    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));
    9701001        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
    9771012            psImageMaskType mask;
    9781013            if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x <  0) || (y < 0) || isnan(x) || isnan(y)) {
     
    9831018
    9841019            // 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;
    9881022                numCensored++;
    9891023            }
    9901024        }
    9911025
    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        }
    9941030
    9951031        addDestreakKeyword(header, true);
    996         if (psArrayLength(outTable) > 0) {
     1032
     1033        if (table->numCols > 0) {
    9971034            printf("Censored %d sources\n", numCensored);
    998             if (! psFitsWriteTable(out->fits, header, outTable, extname)) {
     1035            if (! psFitsWriteTableNew(out->fits, header, table, extname)) {
    9991036                psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name);
    10001037                streaksExit("", PS_EXIT_DATA_ERROR);
    10011038            }
    1002         } else if (psArrayLength(inTable) == 0) {
     1039        } else {
    10031040            printf("No input sources\n");
    10041041            // We'd like to write a blank table, but this is as good as it gets without more work to parse the
     
    10081045                streaksExit("", PS_EXIT_DATA_ERROR);
    10091046            }
    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             }
    10161047        }
    10171048        psFree(header);
    1018         psFree(outTable);
    1019         psFree(inTable);
     1049        psFree(table);
     1050        psFree(rowCensored);
    10201051    }
    10211052
     
    10381069        }
    10391070
    1040         psArray *inTable = psFitsReadTable(in->fits);
    1041         if (!inTable) {
     1071        psFitsTable *table = psFitsReadTableNew(in->fits);
     1072        if (!table) {
    10421073            psErrorStackPrint(stderr, "failed to read table in %s", in->resolved_name);
    10431074            streaksExit("", PS_EXIT_DATA_ERROR);
    10441075        }
    1045         if (! psFitsWriteTable(out->fits, header, inTable, extname)) {
     1076        if (! psFitsWriteTableNew(out->fits, header, table, extname)) {
    10461077            psErrorStackPrint(stderr, "failed to write table to %s", out->resolved_name);
    10471078            streaksExit("", PS_EXIT_DATA_ERROR);
    10481079        }
    1049     }
    1050 
     1080        psFree(header);
     1081        psFree(table);
     1082    }
    10511083
    10521084    if (!psFitsClose(out->fits)) {
     
    10541086        streaksExit("", PS_EXIT_DATA_ERROR);
    10551087    }
    1056 }
     1088    out->fits = NULL;   // freed by psFitsclose()
     1089}
Note: See TracChangeset for help on using the changeset viewer.