IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26174 for trunk/psastro


Ignore:
Timestamp:
Nov 17, 2009, 4:43:05 PM (17 years ago)
Author:
Paul Price
Message:

Fixing "variable used uninitialised".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastroLoadCrosstalk.c

    r26173 r26174  
    11/** @file psastroMaskUpdates.c
    22 *
    3  *  @brief 
     3 *  @brief
    44 *
    55 *  @ingroup libpsastro
     
    4242}
    4343
    44                          
     44
    4545bool psastroLoadCrosstalk (pmConfig *config) {
    4646
     
    5050  pmReadout *readout = NULL;
    5151
     52  pmFPAview *view = pmFPAviewAlloc (0);
     53  pmFPAview *viewMask = pmFPAviewAlloc (0);
     54
    5255  float zeropt, exptime, MAX_MAG;
    53  
     56
    5457  psLogMsg ("psastro", PS_LOG_INFO, "determine crosstalk positions");
    5558
     
    6669    return(true);
    6770  }
    68  
     71
    6972  // select the input astrometry data (also carries the refstars)
    7073  pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     
    8285  }
    8386  // Activate teh reference mask to generate an FPA structure we can use to map stars down to cells
    84  
     87
    8588  pmFPAfileActivate (config->files, true, "PSASTRO.REFMASK");
    86  
     89
    8790  //  pmFPA *refFPA = refMask->fpa;
    88 
    89   pmFPAview *view = pmFPAviewAlloc (0);
    90   pmFPAview *viewMask = pmFPAviewAlloc (0); 
    9191
    9292  if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
     
    103103  float MagOffset = zeropt + 2.5*log10(exptime);
    104104  MAX_MAG += MagOffset;
    105  
     105
    106106  psTrace("psastro.crosstalk",2,"%f %f %f %f\n",zeropt,exptime,MAX_MAG,MagOffset);
    107  
    108   // Load each chip. 
     107
     108  // Load each chip.
    109109  while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
    110110    psTrace ("psastro.crosstalk", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     
    122122    // Read each cell (at this stage, we should only have one of them)
    123123      while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    124         psTrace ("psastro.crosstalk", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    125        
    126         if (!cell->process || !cell->file_exists) { continue; }
    127        
    128         // Read each readout (similarly, we should only have one of these, too)
    129         while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
    130           if (! readout->data_exists) { continue; }
    131 
    132           // If this chip doesn't crosstalk, skip to the next one.
    133           if (! ((X == 2)||(X == 3)||(X == 4)||(X == 5))) {
    134             psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y);
    135             continue;
    136           }
    137 
    138           // Get the array of reference stars we're concerned with.
    139           psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");
    140           if (refstars == NULL) { return(true); }
    141 
    142           // Check each reference star
    143           for (int i = 0; i < refstars->n; i++) {
    144             pmAstromObj *ref = refstars->data[i];
    145            
    146             if (ref->Mag > MAX_MAG) {
    147               continue;
    148             }
    149 
    150             // Identify which cell holds the cell
    151             pmChip *CTsourceChip = refChip;
    152             pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y);
    153            
    154             if (!CTsourceCell) {
    155               continue;
    156             }
    157 
    158             psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n",
    159                      i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y);
    160 
    161            
    162             const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME");
    163             int U = cellName[2] - '0';
    164             int V = cellName[3] - '0';
    165 
    166             int Xt = X,Yt = Y,Ut = U,Vt = V;
    167             float x_cell,y_cell;
    168             float x_t_cell,y_t_cell;
    169            
    170             float x_t_chip,y_t_chip;
    171 
    172             pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y);
    173            
    174             x_t_cell = x_cell;
    175             y_t_cell = y_cell;
    176 
    177             // Determine if this combination of chip and cell produces a crosstalk artifact
    178             if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
    179               psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
    180               continue;
    181             }
    182             if ((X == 3)&&(! ((U == 3)))) {
    183               psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
    184               continue;
    185             }
    186             if ((X == 4)&&(! ((U == 3)))) {
    187               psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
    188               continue;
    189             }
    190             if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
    191               psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
    192               continue;
    193             }
    194            
    195             // Calculate destination positions
    196             if (X == 2) {
    197               if (U == 3) {
    198                 Xt = 3;
    199               }
    200               if (U == 5) {
    201                 Ut = 6;
    202               }
    203               if (U == 6) {
    204                 Ut = 5;
    205               }
    206             }
    207             else if (X == 3) {
    208               Xt = 2;
    209             }
    210             else if (X == 4) {
    211               Xt = 5;
    212             }
    213             if (X == 5) {
    214               if (U == 3) {
    215                 Xt = 4;
    216               }
    217               if (U == 5) {
    218                 Ut = 6;
    219               }
    220               if (U == 6) {
    221                 Ut = 5;
    222               }
    223             }
    224 
    225             // Convert target cell coordinates to target chip coordinates
    226             psString targetChipName = NULL;
    227             psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
    228             psString targetCellName = NULL;
    229             psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
    230            
    231             psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
    232                      X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,
    233                      targetChipName,targetCellName);
    234            
    235             pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
    236             if (!CTtargetCell) continue;
    237            
    238             pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
    239            
    240             psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
    241                      X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
    242 
    243             // Hunt down the readout for the target, and save the chip position and magnitude of source star.
    244             pmChip *targetChip = getChipByName(fpa,targetChipName);
    245             if (!targetChip) continue;
    246             if (!targetChip->cells) continue;
    247             if (!targetChip->cells->n) continue;
    248            
    249             pmCell *targetCell = targetChip->cells->data[0];
    250             if (!targetCell) continue;
    251             if (!targetCell->readouts) continue;
    252             if (!targetCell->readouts->n) continue;
    253             pmReadout *targetReadout = targetCell->readouts->data[0];
    254             if (!targetReadout) continue;
    255 
    256             pmAstromObj *crosstalk = pmAstromObjAlloc();
    257            
    258             crosstalk->Mag = ref->Mag - MagOffset;
    259             crosstalk->chip->x = x_t_chip;
    260             crosstalk->chip->y = y_t_chip;
    261            
    262             psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
    263             if (crosstalks == NULL) {
    264               crosstalks = psArrayAllocEmpty(100);
    265               if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
    266                 psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
    267                 goto escape;
    268               }
    269               psFree(crosstalks);
    270             }
    271             psArrayAdd(crosstalks,100,crosstalk);
    272 
    273             psFree(targetChipName);
    274             psFree(targetCellName);
    275             psFree(crosstalk);
    276           } // refstars
    277         } // readout
     124        psTrace ("psastro.crosstalk", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     125
     126        if (!cell->process || !cell->file_exists) { continue; }
     127
     128        // Read each readout (similarly, we should only have one of these, too)
     129        while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
     130          if (! readout->data_exists) { continue; }
     131
     132          // If this chip doesn't crosstalk, skip to the next one.
     133          if (! ((X == 2)||(X == 3)||(X == 4)||(X == 5))) {
     134            psTrace ("psastro.crosstalk",2,"Chip (%d%d) not a known crosstalk source.",X,Y);
     135            continue;
     136          }
     137
     138          // Get the array of reference stars we're concerned with.
     139          psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS");
     140          if (refstars == NULL) { return(true); }
     141
     142          // Check each reference star
     143          for (int i = 0; i < refstars->n; i++) {
     144            pmAstromObj *ref = refstars->data[i];
     145
     146            if (ref->Mag > MAX_MAG) {
     147              continue;
     148            }
     149
     150            // Identify which cell holds the cell
     151            pmChip *CTsourceChip = refChip;
     152            pmCell *CTsourceCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y);
     153
     154            if (!CTsourceCell) {
     155              continue;
     156            }
     157
     158            psTrace ("psastro.crosstalk",2,"REF: %d %f (%f %f) %f %f :: %f %f\n",
     159                     i,ref->Mag, ref->sky->r,ref->sky->d, ref->FP->x,ref->FP->y, ref->chip->x,ref->chip->y);
     160
     161
     162            const char *cellName = psMetadataLookupStr(NULL,CTsourceCell->concepts, "CELL.NAME");
     163            int U = cellName[2] - '0';
     164            int V = cellName[3] - '0';
     165
     166            int Xt = X,Yt = Y,Ut = U,Vt = V;
     167            float x_cell,y_cell;
     168            float x_t_cell,y_t_cell;
     169
     170            float x_t_chip,y_t_chip;
     171
     172            pmCellCoordsForChip(&x_cell,&y_cell,CTsourceCell,ref->chip->x,ref->chip->y);
     173
     174            x_t_cell = x_cell;
     175            y_t_cell = y_cell;
     176
     177            // Determine if this combination of chip and cell produces a crosstalk artifact
     178            if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
     179              psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
     180              continue;
     181            }
     182            if ((X == 3)&&(! ((U == 3)))) {
     183              psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
     184              continue;
     185            }
     186            if ((X == 4)&&(! ((U == 3)))) {
     187              psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
     188              continue;
     189            }
     190            if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
     191              psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
     192              continue;
     193            }
     194
     195            // Calculate destination positions
     196            if (X == 2) {
     197              if (U == 3) {
     198                Xt = 3;
     199              }
     200              if (U == 5) {
     201                Ut = 6;
     202              }
     203              if (U == 6) {
     204                Ut = 5;
     205              }
     206            }
     207            else if (X == 3) {
     208              Xt = 2;
     209            }
     210            else if (X == 4) {
     211              Xt = 5;
     212            }
     213            if (X == 5) {
     214              if (U == 3) {
     215                Xt = 4;
     216              }
     217              if (U == 5) {
     218                Ut = 6;
     219              }
     220              if (U == 6) {
     221                Ut = 5;
     222              }
     223            }
     224
     225            // Convert target cell coordinates to target chip coordinates
     226            psString targetChipName = NULL;
     227            psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
     228            psString targetCellName = NULL;
     229            psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
     230
     231            psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
     232                     X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,
     233                     targetChipName,targetCellName);
     234
     235            pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
     236            if (!CTtargetCell) continue;
     237
     238            pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
     239
     240            psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
     241                     X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
     242
     243            // Hunt down the readout for the target, and save the chip position and magnitude of source star.
     244            pmChip *targetChip = getChipByName(fpa,targetChipName);
     245            if (!targetChip) continue;
     246            if (!targetChip->cells) continue;
     247            if (!targetChip->cells->n) continue;
     248
     249            pmCell *targetCell = targetChip->cells->data[0];
     250            if (!targetCell) continue;
     251            if (!targetCell->readouts) continue;
     252            if (!targetCell->readouts->n) continue;
     253            pmReadout *targetReadout = targetCell->readouts->data[0];
     254            if (!targetReadout) continue;
     255
     256            pmAstromObj *crosstalk = pmAstromObjAlloc();
     257
     258            crosstalk->Mag = ref->Mag - MagOffset;
     259            crosstalk->chip->x = x_t_chip;
     260            crosstalk->chip->y = y_t_chip;
     261
     262            psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS");
     263            if (crosstalks == NULL) {
     264              crosstalks = psArrayAllocEmpty(100);
     265              if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
     266                psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
     267                goto escape;
     268              }
     269              psFree(crosstalks);
     270            }
     271            psArrayAdd(crosstalks,100,crosstalk);
     272
     273            psFree(targetChipName);
     274            psFree(targetCellName);
     275            psFree(crosstalk);
     276          } // refstars
     277        } // readout
    278278      } // cell
    279279      //    }
    280    
     280
    281281      // File cleanup code.
    282     *viewMask = *view; 
     282    *viewMask = *view;
    283283    while ((cell = pmFPAviewNextCell (viewMask, refMask->fpa, 1)) != NULL) {
    284284      psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process);
    285285      if (!cell->process || !cell->file_exists) { continue; }
    286      
     286
    287287      while ((readout = pmFPAviewNextReadout (viewMask, refMask->fpa, 1)) != NULL) {
    288         if (! readout->data_exists) { continue; }
    289         if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
     288        if (! readout->data_exists) { continue; }
     289        if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
    290290      }
    291291      if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
     
    303303 escape:
    304304  psFree(view);
     305  psFree(viewMask);
    305306  return(false);
    306307}
Note: See TracChangeset for help on using the changeset viewer.