IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8002


Ignore:
Timestamp:
Jul 27, 2006, 4:51:49 PM (20 years ago)
Author:
eugene
Message:

fixing leaks, adding some optimizations

Location:
trunk/Ohana/src/addstar/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/addstar/src/SEDfit.c

    r7714 r8002  
    11# include "sedstar.h"
     2
     3// XXX a couple of fixes should speed this up a bit: test
    24
    35int SEDfitCatalog (Catalog *outcat, Catalog *incat, SEDtable *table) {
     
    79  unsigned short USNOred, USNOblu;
    810  float color;
    9   int *found, valid;
     11  int *found, valid, *modelRow, *reqRow;
    1012
    1113  SEDtableRow sourceValue, sourceError;
    1214  SEDfit minFit, testFit;
     15
     16  Nmodel = Nreq = 0;
     17  for (i = 0; i < table[0].Nfilter; i++) {
     18    if (table[0].mode[i] == SED_REQ) Nreq ++;
     19    if (table[0].mode[i] == SED_MODEL) Nmodel ++;
     20  }
     21  if (Nmodel < 1) {
     22    fprintf (stderr, "no model filter defined\n!");
     23    exit (2);
     24  }
     25  if (Nreq < 1) {
     26    fprintf (stderr, "no required filter defined\n!");
     27    exit (2);
     28  }
     29
     30  ALLOCATE (modelRow, int, Nmodel);
     31  for (j = i = 0; i < table[0].Nfilter; i++) {
     32    if (table[0].mode[i] == SED_MODEL) {
     33      modelRow[j] = i;
     34      j++;
     35    }
     36  }
     37  ALLOCATE (reqRow, int, Nreq);
     38  for (j = i = 0; i < table[0].Nfilter; i++) {
     39    if (table[0].mode[i] == SED_REQ) {
     40      reqRow[j] = i;
     41      j++;
     42    }
     43  }
    1344
    1445  sourceValue.mags = NULL;
     
    6495    if (Nphot < 3) continue;
    6596
     97    // XXX pre-select list of REQ entries; loop over only those?
    6698    valid = TRUE;
    67     for (j = 0; valid && (j < table[0].Nfilter); j++) {
    68       if ((table[0].mode[j] == SED_REQ) && !found[j]) valid = FALSE;
     99    for (j = 0; valid && (j < Nreq); j++) {
     100      if ((table[0].mode[reqRow[j]] == SED_REQ) && !found[reqRow[j]]) valid = FALSE;
    69101    }
    70102    if (!valid) continue;
     
    77109    // find tableRow within 0.1 mag of color
    78110    // XXX : check on the delta value
    79     start = SEDcolorBracket (table, color);
     111    start = SEDcolorBracket (table, color, 0.05);
    80112    minFit = SEDchisq (table[0].row[start], &sourceValue, &sourceError, table[0].Nfilter);
    81113    minFit.row = start;
     
    91123        minFit.row = row;
    92124      }
    93       if (fabs(table[0].row[row][0].color - color) > 0.5) done = TRUE;
     125      if (fabs(table[0].row[row][0].color - color) > 0.25) done = TRUE;
    94126      row --;
    95127    }
     
    105137        minFit.row = row;
    106138      }
    107       if (fabs(table[0].row[row][0].color - color) > 0.5) done = TRUE;
     139      if (fabs(table[0].row[row][0].color - color) > 0.25) done = TRUE;
    108140      row ++;
    109141    }
     
    145177
    146178    // we now have the min chisq row. use this to supply the other filter values....
    147     for (j = 0; valid && (j < table[0].Nfilter); j++) {
    148       if (table[0].mode[j] != SED_MODEL) continue;
     179    // XXX pre-select the SED_MODEL rows...
     180    if (Nmeas + table[0].Nfilter >= NMEAS) {
     181        NMEAS += 100 + table[0].Nfilter;
     182        REALLOCATE (outcat[0].measure, Measure, NMEAS);
     183    }
     184
     185    for (j = 0; valid && (j < Nmodel; j++) {
     186      n = modelRow[j];
    149187      outcat[0].measure[Nmeas].dR_PS       = 0.0;
    150188      outcat[0].measure[Nmeas].dD_PS       = 0.0;
    151       outcat[0].measure[Nmeas].M_PS        = MIN (table[0].row[minFit.row][0].mags[j] + minFit.Md,  NO_MAG);
     189      outcat[0].measure[Nmeas].M_PS        = MIN (table[0].row[minFit.row][0].mags[n] + minFit.Md,  NO_MAG);
    152190      outcat[0].measure[Nmeas].dM_PS       = 0.0;
    153191      outcat[0].measure[Nmeas].Mcal_PS     = 0;
    154192      outcat[0].measure[Nmeas].t           = TIMEREF;
    155193      outcat[0].measure[Nmeas].averef      = Nave;
    156       outcat[0].measure[Nmeas].source      = table[0].code[j];
     194      outcat[0].measure[Nmeas].source      = table[0].code[n];
    157195      outcat[0].measure[Nmeas].dophot      = 0;
    158196      outcat[0].measure[Nmeas].flags       = 0;
     
    167205      outcat[0].average[Nave].Nm++;
    168206      Nmeas ++;
    169       CHECK_REALLOCATE (outcat[0].measure, Measure, NMEAS, Nmeas, 100);
    170207    }
    171208
     
    180217  outcat[0].Nmeasure = Nmeas;
    181218 
     219  free (sourceValue.mags);
     220  free (sourceError.mags);
     221  free (found);
     222
    182223  SEDfitClear ();
    183224}
  • trunk/Ohana/src/addstar/src/SEDops.c

    r7696 r8002  
    3434
    3535// find the first table row within 0.1 mag of the requested color (or within 10)
    36 int SEDcolorBracket (SEDtable *table, float color) {
     36int SEDcolorBracket (SEDtable *table, float color, float delta) {
    3737
    3838  int Nlo, Nhi, N;
     
    4141  N = Nlo = 0; Nhi = table[0].Nrow;
    4242  tcolor = table[0].row[Nlo][0].color;
    43   while ((Nhi - Nlo > 10) && (fabs(tcolor-color) > 0.1)) {
     43  while ((Nhi - Nlo > 10) && (fabs(tcolor-color) > delta)) {
    4444    N = 0.5*(Nlo + Nhi);
    4545    N = MAX (N, 0);
  • trunk/Ohana/src/addstar/src/sedstar.c

    r7696 r8002  
    33int main (int argc, char **argv) {
    44
    5   char *root, *ext;
    6   int i, N, Nrefcat, status;
     5  char *root, *ext, tmp;
     6  int i, N, Nbytes, Nrefcat, status;
    77  SkyList *skylist;
    88  SkyTable *sky, *sky2mass;
     
    4242
    4343    ext = incatalog.filename + strlen(CATDIR);
    44     ALLOCATE (outcatalog.filename, char, strlen(argv[2]) + strlen(ext) + 2);
    45     sprintf (outcatalog.filename, "%s/%s", argv[2], ext);
     44    while (*ext == '/') ext++;
     45
     46    Nbytes = snprintf (&tmp, 0, "%s/%s", argv[2], ext);
     47    ALLOCATE (outcatalog.filename, char, Nbytes + 1);
     48    snprintf (outcatalog.filename, Nbytes + 1, "%s/%s", argv[2], ext);
    4649
    4750    if (!check_file_access (outcatalog.filename, TRUE, TRUE)) Shutdown ("can't create output directory");
     
    5659    unlock_catalog (&outcatalog);
    5760    free (outcatalog.filename);
     61    free_catalog (&outcatalog);
    5862
    5963    unlock_catalog (&incatalog);
     64    free_catalog (&incatalog);
    6065  }
    6166
Note: See TracChangeset for help on using the changeset viewer.