IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39223


Ignore:
Timestamp:
Dec 3, 2015, 4:13:55 PM (11 years ago)
Author:
eugene
Message:

add fitpm_irls, fitplx_irls

Location:
branches/eam_branches/ipp-20151113/Ohana/src/opihi
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20151113/Ohana/src/opihi/cmd.astro

  • branches/eam_branches/ipp-20151113/Ohana/src/opihi/cmd.astro/Makefile

    r39194 r39223  
    3535$(SRC)/fitplx.$(ARCH).o    \
    3636$(SRC)/fitpm.$(ARCH).o     \
     37$(SRC)/fitpm_irls.$(ARCH).o  \
     38$(SRC)/fitplx_irls.$(ARCH).o  \
    3739$(SRC)/fixwrap.$(ARCH).o           \
    3840$(SRC)/fixcols.$(ARCH).o           \
  • branches/eam_branches/ipp-20151113/Ohana/src/opihi/cmd.astro/fitpm_irls.c

    r39086 r39223  
    231231  sigma_ols = 0.0;
    232232  for (i = 0; i < Npts; i++) {
    233     rx[i] = X[i] - (T[i] * B[0][0] + B[1][0]);
    234     ry[i] = Y[i] - (T[i] * B[2][0] + B[3][0]);
     233    rx[i] = X[i] - (T[i] * B[1][0] + B[0][0]);
     234    ry[i] = Y[i] - (T[i] * B[3][0] + B[2][0]);
    235235    //    u[i] = r[i] /
    236236    sigma_ols += SQ(rx[i]) + SQ(ry[i]);
     
    280280    sigma_hat = 0.0;
    281281    for (i = 0; i < Npts; i++) {
    282       rx[i] = X[i] - (T[i] * B[0][0] + B[1][0]);
    283       ry[i] = Y[i] - (T[i] * B[2][0] + B[3][0]);
     282      rx[i] = X[i] - (T[i] * B[1][0] + B[0][0]);
     283      ry[i] = Y[i] - (T[i] * B[3][0] + B[2][0]);
    284284      u[i] = sqrt(SQ(rx[i] / dX[i]) + SQ(ry[i] / dY[i]));
    285285    }
  • branches/eam_branches/ipp-20151113/Ohana/src/opihi/cmd.astro/init.c

    r39194 r39223  
    2020int fitplx                  PROTO((int, char **));
    2121int fitpm                   PROTO((int, char **));
     22int fitpm_irls              PROTO((int, char **));
     23int fitplx_irls             PROTO((int, char **));
    2224int fixwrap                 PROTO((int, char **));
    2325int fiximage                PROTO((int, char **));
     
    8789  {1, "fitplx",      fitplx,       "fit proper motion and parallax"},
    8890  {1, "fitpm",       fitpm,        "fit proper motion only"},
     91  {1, "fitpm_irls",  fitpm_irls,   "fit proper motion only using irls method"},
     92  {1, "fitplx_irls", fitplx_irls,  "fit proper motion and parallax using irls method"},
    8993  {1, "fixwrap",     fixwrap,      "fix megacam over-wrapped pixels"},
    9094  {1, "fiximage",    fiximage,     "fix pixels in an image by interpolation"},
  • branches/eam_branches/ipp-20151113/Ohana/src/opihi/cmd.data/read_vectors.c

    r38989 r39223  
    4141  time_t TimeReference;
    4242  int i, j, Nskip, Narg, IsCSV, VERBOSE;
    43   int Nbytes, Nstart, NELEM, Nelem, nread;
     43  int Nbytes, NELEM, nread;
    4444  char *colstr, *c0, *c1, *extname;
    4545  char varname[1024];  // used as a buffer for the names of string fields
     
    188188  }
    189189 
     190  // we allocate one extra byte into which we never read so there will always be a NULL terminating the string
    190191  ALLOCATE (buffer, char, 0x10001);
    191192  bzero (buffer, 0x10001);
    192 
    193   /*
    194   for (i = 0; i < Nskip; i++) {
    195     if (scan_line_maxlen (f, buffer, 0x10000) == EOF) {
    196       gprint (GP_ERR, "problem reading file %s\n", filename);
    197       read_vectors_cleanup();
    198       return FALSE;
    199     }
    200   }
    201   */
    202193
    203194  int Nline_read = 0; // track number of lines read so far (use to skip lines as well)
     
    209200  // we treat \n\r pair as a single EOL char to handle mac files:
    210201
    211   Nstart = 0; // location of the last valid byte in the buffer (start filling here)
    212   Nelem = 0; // number of valid rows read (vector elements)
    213   while (TRUE) {
     202  int Nstart = 0; // location of the last valid byte in the buffer (start filling here)
     203  int Nelem = 0; // number of valid rows read (vector elements)
     204  int EndOfFile = FALSE;
     205  while (!EndOfFile) {
    214206    Nbytes = 0x10000 - Nstart;
    215     bzero (&buffer[Nstart], Nbytes);
     207    // we have allocated one extra byte into which we never read so there will always be a NULL terminating the string
     208    bzero (&buffer[Nstart], Nbytes + 1);
    216209    nread = fread (&buffer[Nstart], 1, Nbytes, f);
    217210    if (ferror (f)) {
     
    219212      break;
    220213    }
    221     if (nread == 0) break; // end of the file
    222     // nbytes = nread + Nstart;
     214    // we still need to parse the rest of the buffer, but there might not be an EOL on the last line
     215    if (nread == 0) {
     216      EndOfFile = TRUE;
     217    }
    223218   
    224219    int bufferStatus = TRUE;
     
    227222      c1 = strchr (c0, '\n'); // find the end of this current line (also valid for a Mac: \r\n)
    228223      if (!c1) {
    229         c1 = strchr (c0, '\r'); // try \r for non-UNIX files
    230       }
    231       if (c1 == (char *) NULL) {
     224        c1 = strchr (c0, '\r'); // try \r for Windows files
     225      }
     226      if (!c1) {
    232227        Nstart = strlen (c0);
    233         memmove (buffer, c0, Nstart);
    234         bufferStatus = FALSE;
    235         continue;
     228        if (EndOfFile) {
     229          // if we have reached EOF, we need to do one last pass in case there is a line without a return
     230          c1 = c0 + Nstart;
     231          bufferStatus = FALSE;
     232        } else {
     233          // if we have not reached EOF, we need to shift the buffer to the start of this line and read more data
     234          memmove (buffer, c0, Nstart);
     235          bufferStatus = FALSE;
     236          continue;
     237        }
    236238      }
    237239      *c1 = 0; // mark the end of the line
    238240      Nline_read ++;
    239241
    240       if (Nline_read <= Nskip) { c0 = c1 + 1; continue; }
    241 
    242       if (*c0 == '#') { c0 = c1 + 1; continue; }
    243       if (*c0 == '!') { c0 = c1 + 1; continue; }
     242      // skip to the next line (but if EOF, do not overrun buffer)
     243      if (Nline_read <= Nskip) { if (!EndOfFile) { c0 = c1 + 1; } continue; }
     244      if (*c0 == '#')          { if (!EndOfFile) { c0 = c1 + 1; } continue; }
     245      if (*c0 == '!')          { if (!EndOfFile) { c0 = c1 + 1; } continue; }
    244246
    245247      // parse the vectors in this line.  this code is a bit inefficient: each column
     
    319321        }
    320322      }
    321       c0 = c1 + 1;
     323      if (!EndOfFile) {
     324        c0 = c1 + 1;
     325      }
    322326    }
    323327  }
Note: See TracChangeset for help on using the changeset viewer.