IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32410


Ignore:
Timestamp:
Sep 16, 2011, 5:11:00 PM (15 years ago)
Author:
bills
Message:

Handle cmf files with empty tables as we did before the rework

Location:
tags/ipp-20110622
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20110622/magic/remove/src/streaksremove.c

    r32398 r32410  
    981981        }
    982982
    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));
    1001983        int numCensored = 0;
    1002 
    1003         for (int i = 0 ; i < table->numRows; i++) {
     984        bool *rowCensored = NULL;
     985        if (table->numRows > 0) {
     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            rowCensored = psAlloc(table->numRows * sizeof(bool));
     1000            memset(rowCensored, 0, table->numRows * sizeof(bool));
     1001
     1002            for (int i = 0 ; i < table->numRows; i++) {
    10041003
    10051004#ifndef GO_SLOWER
    1006             psF32 x = table->columns[xCol].data.F32[i];
    1007             psF32 y = table->columns[yCol].data.F32[i];
     1005                psF32 x = table->columns[xCol].data.F32[i];
     1006                psF32 y = table->columns[yCol].data.F32[i];
    10081007#else
    1009             psF32 x = psFitsTableGetF32(NULL, table, i, "X_PSF");
    1010             psF32 y = psFitsTableGetF32(NULL, table, i, "Y_PSF");
     1008                psF32 x = psFitsTableGetF32(NULL, table, i, "X_PSF");
     1009                psF32 y = psFitsTableGetF32(NULL, table, i, "Y_PSF");
    10111010#endif
    1012             psImageMaskType mask;
    1013             if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x <  0) || (y < 0) || isnan(x) || isnan(y)) {
    1014                 mask = maskStreak;
    1015             } else {
    1016                 mask = maskImage->data.PS_TYPE_IMAGE_MASK_DATA[(int)y][(int)x];
    1017             }
    1018 
    1019             // Key the source if the center pixel is not masked with maskStreak
    1020             if (mask & maskStreak) {
    1021                 rowCensored[i] = true;
    1022                 numCensored++;
    1023             }
    1024         }
    1025 
    1026         // remove the censored rows from the table
    1027         if (!psFitsTableCensor(table, rowCensored)) {
    1028             streaksExit("", PS_EXIT_PROG_ERROR);
    1029         }
    1030 
    1031         addDestreakKeyword(header, true);
     1011                psImageMaskType mask;
     1012                if ((x >= maskImage->numCols) || (y >= maskImage->numRows) || (x <  0) || (y < 0) || isnan(x) || isnan(y)) {
     1013                    mask = maskStreak;
     1014                } else {
     1015                    mask = maskImage->data.PS_TYPE_IMAGE_MASK_DATA[(int)y][(int)x];
     1016                }
     1017
     1018                // Key the source if the center pixel is not masked with maskStreak
     1019                if (mask & maskStreak) {
     1020                    rowCensored[i] = true;
     1021                    numCensored++;
     1022                }
     1023            }
     1024
     1025            // remove the censored rows from the table
     1026            if (!psFitsTableCensor(table, rowCensored)) {
     1027                streaksExit("", PS_EXIT_PROG_ERROR);
     1028            }
     1029
     1030            addDestreakKeyword(header, true);
     1031        }
    10321032
    10331033        if (table->numCols > 0) {
  • tags/ipp-20110622/psLib/src/fits/psFitsTableNew.c

    • Property svn:mergeinfo set to (toggle deleted branches)
      /trunk/psLib/src/fits/psFitsTableNew.cmergedeligible
      /branches/czw_branch/20101203/psLib/src/fits/psFitsTableNew.c29907-30631
      /branches/eam_branches/ipp-20101103/psLib/src/fits/psFitsTableNew.c29657-29920
      /branches/eam_branches/ipp-20101205/psLib/src/fits/psFitsTableNew.c29959-30585
      /branches/eam_branches/ipp-20110213/psLib/src/fits/psFitsTableNew.c30628-31149
      /branches/eam_branches/ipp-20110404/psLib/src/fits/psFitsTableNew.c31166-31444
      /branches/eam_branches/ipp-20110505/psLib/src/fits/psFitsTableNew.c31458-31658
    r32399 r32410  
    117117
    118118psFitsTable* psFitsTableAlloc(int numCols, int numRows) {
    119     if (numCols <= 0) {
     119    if (numCols < 0) {
     120        // empty table
    120121        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    121122                "Can't allocate a psFitsTable with %d columns.", numCols);
     
    127128    table->numRows = numRows;
    128129    table->numCols = numCols;
    129     table->columns = psAlloc(sizeof(psFitsTableColumn) * numCols);
    130     memset(table->columns, sizeof(psFitsTableColumn) * numCols, 0);
     130    if (numCols > 0) {
     131        table->columns = psAlloc(sizeof(psFitsTableColumn) * numCols);
     132        memset(table->columns, sizeof(psFitsTableColumn) * numCols, 0);
     133    } else {
     134        table->columns = NULL;
     135    }
    131136    psMemSetDeallocator(table, (psFreeFunc) freeTable);
    132137
     
    141146    if (!readTableCheck(fits)) {
    142147        if (emptyTableCheck(fits)) {
    143             return NULL;
     148            psFitsTable *table = psFitsTableAlloc(0, 0);
     149            return table;
    144150        }
    145151        psError(PS_ERR_BAD_FITS, true, "Extension is not a table");
Note: See TracChangeset for help on using the changeset viewer.