IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31667


Ignore:
Timestamp:
Jun 22, 2011, 12:40:23 AM (15 years ago)
Author:
eugene
Message:

merge from trunk: various details, see eam/ipp-20110505

Location:
trunk/Ohana/src/opihi
Files:
17 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.astro/czplot.c

    r20936 r31667  
    33int czplot (int argc, char **argv) {
    44 
    5   int i, kapa;
     5  int i, kapa, Npts, status;
    66  double min, range, Rmin, Rmax;
    77  opihi_flt *out, *r, *d, *x, *y;
     
    1818  min = atof(argv[4]);
    1919  range = atof(argv[5]) - min;
    20   Rmin = graphmode.coords.crval1 - 180.0;
    21   Rmax = graphmode.coords.crval1 + 180.0;
     20  Rmin = graphmode.coords.crval1 - 182.0;
     21  Rmax = graphmode.coords.crval1 + 182.0;
    2222
    2323  /* find vectors */
     
    4646  x   = Xvec.elements.Flt;
    4747  y   = Yvec.elements.Flt;
    48   for (i = 0; i < Zvec.Nelements; i++, r++, d++, x++, y++) {
     48  out = Zvec.elements.Flt;
     49
     50  Npts = 0;
     51  for (i = 0; i < xvec[0].Nelements; i++, r++, d++) {
    4952    *r = ohana_normalize_angle (*r);
    50     RD_to_XY (x, y, *r, *d, &graphmode.coords);
     53    while (*r < Rmin) *r += 360.0;
     54    while (*r > Rmax) *r -= 360.0;
     55
     56    status = RD_to_XY (x, y, *r, *d, &graphmode.coords);
     57    if (!status) continue;
     58
     59    if (zvec->type == OPIHI_FLT) {
     60      opihi_flt *in  = zvec[0].elements.Flt;
     61      *out = MIN (1.0, MAX (0.01, (in[i] - min) / range));
     62    } else {
     63      opihi_int *in  = zvec[0].elements.Int;
     64      *out = MIN (1.0, MAX (0.01, (in[i] - min) / range));
     65    }
     66    x++;
     67    y++;
     68    out++;
     69    Npts++;
    5170  }
    52 
    53   out = Zvec.elements.Flt;
    54   if (zvec->type == OPIHI_FLT) {
    55     opihi_flt *in  = zvec[0].elements.Flt;
    56     for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
    57       *out = MIN (1.0, MAX (0.01, (*in - min) / range));
    58     }
    59   } else {
    60     opihi_int *in  = zvec[0].elements.Int;
    61     for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
    62       *out = MIN (1.0, MAX (0.01, (*in - min) / range));
    63     }
    64   }
     71  Xvec.Nelements = Npts;
     72  Yvec.Nelements = Npts;
     73  Zvec.Nelements = Npts;
    6574
    6675  graphmode.style = 2;
  • trunk/Ohana/src/opihi/cmd.basic/cd.c

    r27435 r31667  
    2424    }
    2525    if (VERBOSE) gprint (GP_LOG, "cwd: %s\n", cwd);
    26     ohana_memregister (cwd);
    27     free (cwd);
     26    real_free (cwd);
    2827    return (TRUE);
    2928  }
     
    6261      free (var);
    6362  }
    64   ohana_memregister (cwd);
    65   free (cwd);
     63  real_free (cwd);
    6664  return (TRUE);
    6765 
  • trunk/Ohana/src/opihi/cmd.basic/list.c

    r27587 r31667  
    223223    /* get the next line (from correct place) */
    224224    if (ThisList == 0) {
    225       input = readline (prompt);
     225      input = opihi_readline (prompt);
    226226    } else {
    227227      input = get_next_listentry (ThisList);
     
    236236      input = strcreate ("end");
    237237    }
    238     if (ThisList == 0) ohana_memregister (input);
    239238
    240239    stripwhite (input);
  • trunk/Ohana/src/opihi/cmd.basic/run_for.c

    r27798 r31667  
    4848    /* get the next line (from correct place) */
    4949    if (ThisList == 0)
    50       input = readline (prompt);
     50      input = opihi_readline (prompt);
    5151    else
    5252      input = get_next_listentry (ThisList);
     
    6767      }
    6868    }
    69     if (ThisList == 0) ohana_memregister (input);
    7069
    7170    /* test for new macro (or other list, in the future?) */
  • trunk/Ohana/src/opihi/cmd.basic/run_if.c

    r23583 r31667  
    6666    /* get the next line (from correct place) */
    6767    if (ThisList == 0) {
    68       input = readline (prompt);
     68      input = opihi_readline (prompt);
    6969    } else {
    7070      input = get_next_listentry (ThisList);
     
    7979      input = strcreate ("end");
    8080    }
    81     if (ThisList == 0) ohana_memregister (input);
    8281
    8382    stripwhite (input);
  • trunk/Ohana/src/opihi/cmd.basic/run_while.c

    r27491 r31667  
    2525    /* get the next line (from correct place) */
    2626    if (ThisList == 0)
    27       input = readline (prompt);
     27      input = opihi_readline (prompt);
    2828    else
    2929      input = get_next_listentry (ThisList);
     
    4444      }
    4545    }
    46     if (ThisList == 0) ohana_memregister (input);
    4746
    4847    /* test for new macro (or other list, in the future?) */
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r31450 r31667  
    137137int zap              PROTO((int, char **));
    138138int zplot            PROTO((int, char **));
     139int zcplot            PROTO((int, char **));
    139140
    140141static Command cmds[] = { 
     
    284285  {1, "zap",          zap,              "assign values to pixel regions"},
    285286  {1, "zplot",        zplot,            "plot x y with size scaled by z"},
     287  {1, "zcplot",       zcplot,           "plot x y with color scaled by z"},
    286288};
    287289
  • trunk/Ohana/src/opihi/cmd.data/read_vectors.c

    r29938 r31667  
    22
    33FILE *f = (FILE *) NULL;
    4 char filename[256];
     4char filename[2048];
    55
    66int datafile (int argc, char **argv) {
     
    2323int read_vectors (int argc, char **argv) {
    2424 
    25   int i, j, Nskip, Nvec, *col, done, status;
     25  int i, j, Nskip, Nvec, *col, done, status, IsCSV;
    2626  int Nbytes, nbytes, Nstart, NELEM, N, nread;
    2727  char *colstr, *c0, *c1, *buffer, *extname;
     
    4747  }
    4848
     49  IsCSV = FALSE;
     50  if ((N = get_argument (argc, argv, "-csv"))) {
     51    remove_argument (N, &argc, argv);
     52    IsCSV = TRUE;
     53  }
     54
    4955  if ((argc < 3) || !(argc % 2)) {
    5056    gprint (GP_ERR, "USAGE: read name N name N ...\n");
     
    5864  }
    5965  fseeko (f, 0LL, SEEK_SET);
     66
     67//  if (IsCSV) {
     68//    status = read_vectors_csv (argc, argv, Nskip, f);
     69//    return status;
     70//  }
    6071
    6172  Nvec = (argc - 1) / 2;
     
    7384    colstr = argv[2*i+2];
    7485    for (j = 0; j < strlen (colstr); j++) {
    75       if (!isdigit(colstr[j])) {
    76         gprint (GP_ERR, "USAGE: read name N name N ...\n");
    77         free (vec);
    78         free (col);
    79         return (FALSE);   
    80       }
    81     }
    82     col[i] = atof (colstr);
     86      if (isdigit(colstr[j])) {
     87        col[i] = atof (colstr);
     88        continue;
     89      }
     90      // allow 'excel' columns names of the form A-Z, AA-AZ, BA-BZ, .. ZA-ZZ
     91      if (strlen(colstr) >= 3) goto bad_colname;
     92      if (colstr[0] < 'A') goto bad_colname;
     93      if (colstr[0] > 'Z') goto bad_colname;
     94      if (colstr[1] && colstr[1] < 'A') goto bad_colname;
     95      if (colstr[1] && colstr[1] > 'Z') goto bad_colname;
     96
     97      col[i] = colstr[0] - 'A' + 1;
     98      if (colstr[1]) {
     99        col[i] *= 26;
     100        col[i] += colstr[1] - 'A' + 1;
     101      }
     102      continue;
     103
     104    bad_colname:
     105      gprint (GP_ERR, "USAGE: read name N name N ...\n");
     106      free (vec);
     107      free (col);
     108      return (FALSE);   
     109    }
    83110  }
    84111
     
    94121    scan_line (f, buffer);
    95122  }
     123
     124  int Nfield = 0;
     125  int Nline = 0;
    96126
    97127  Nstart = 0;
     
    122152      if ((*c0 != '#') && (*c0 != '!')) {
    123153        for (i = 0; (i < Nvec) && status; i++) {
    124           status = dparse (&value, col[i], c0);
     154          if (IsCSV) {
     155            status = dparse_csv (&value, col[i], c0);
     156          } else {
     157            status = dparse (&value, col[i], c0);
     158          }
    125159          vec[i][0].elements.Flt[N] = value;
     160          if (status) {
     161              Nfield ++;
     162          }
    126163          if (!status) vec[i][0].elements.Flt[N] = NAN;
    127164        }
    128165        if (status) N++;
    129166      }
     167      Nline ++;
     168      if (c1) {
     169          // fprintf (stderr, "line %d, chars %ld, fields %d\n", Nline, (c1 - c0), Nfield);
     170      }
     171      Nfield = 0;
    130172      c0 = c1 + 1;
    131173      if (N == NELEM) {
     
    341383  return (TRUE);
    342384}
     385
     386# if (0)
     387int read_vectors_csv (int argc, char **argv, int Nskip, FILE *f) {
     388 
     389  int i, j, Nvec, *col, done, status;
     390  int Nbytes, nbytes, Nstart, NELEM, N, nread;
     391  char *colstr, *c0, *c1, *buffer, *extname;
     392  double value;
     393  Vector **vec;
     394
     395  Nvec = (argc - 1) / 2;
     396  ALLOCATE (vec, Vector *, Nvec);
     397  ALLOCATE (col, int, Nvec);
     398
     399  for (i = 0; i < Nvec; i++) {
     400    if ((vec[i] = SelectVector (argv[2*i + 1], ANYVECTOR, TRUE)) == NULL) {
     401      gprint (GP_ERR, "USAGE: read name N name N ...\n");
     402      free (vec);
     403      free (col);
     404      return (FALSE);   
     405    }
     406    // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors...
     407    colstr = argv[2*i+2];
     408    for (j = 0; j < strlen (colstr); j++) {
     409      if (!isdigit(colstr[j])) {
     410        gprint (GP_ERR, "USAGE: read name N name N ...\n");
     411        free (vec);
     412        free (col);
     413        return (FALSE);   
     414      }
     415    }
     416    col[i] = atof (colstr);
     417  }
     418
     419  // currently, all read vectors are forced to be type FLT
     420  NELEM = 1000;
     421  for (i = 0; i < Nvec; i++) {
     422    ResetVector (vec[i], OPIHI_FLT, NELEM);
     423  }
     424 
     425  ALLOCATE (buffer, char, 0x10001);
     426  bzero (buffer, 0x10001);
     427  for (i = 0; i < Nskip; i++) {
     428    scan_line (f, buffer);
     429  }
     430
     431  Nstart = 0;
     432  N = 0;
     433  done = FALSE;
     434  while (!done) {
     435    Nbytes = 0x10000 - Nstart;
     436    bzero (&buffer[Nstart], Nbytes);
     437    nread = fread (&buffer[Nstart], 1, Nbytes, f);
     438    if (ferror (f)) {
     439      perror ("error reading data file");
     440      break;
     441    }
     442    if (nread == 0) break;
     443    nbytes = nread + Nstart;
     444   
     445    status = TRUE;
     446    c0 = buffer;
     447    while (status) {
     448      c1 = strchr (c0, '\n');
     449      if (c1 == (char *) NULL) {
     450        Nstart = strlen (c0);
     451        memmove (buffer, c0, Nstart);
     452        status = FALSE;
     453      } else {
     454        *c1 = 0;
     455      }     
     456      if ((*c0 != '#') && (*c0 != '!')) {
     457        for (i = 0; (i < Nvec) && status; i++) {
     458          status = dparse_csv (&value, col[i], c0);
     459          vec[i][0].elements.Flt[N] = value;
     460          if (!status) vec[i][0].elements.Flt[N] = NAN;
     461        }
     462        if (status) N++;
     463      }
     464      c0 = c1 + 1;
     465      if (N == NELEM) {
     466        NELEM += 1000;
     467        for (i = 0; i < Nvec; i++) {
     468          REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM);
     469        }
     470      }
     471       
     472    }
     473  }
     474  for (i = 0; i < Nvec; i++) {
     475    REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (N,1));
     476    vec[i][0].Nelements = N;
     477  }
     478 
     479  free (vec);
     480  free (col);
     481  free (buffer);
     482  return (TRUE);
     483
     484}
     485
     486# endif
  • trunk/Ohana/src/opihi/cmd.data/tvcolors.c

    r25757 r31667  
    55  int N, kapa;
    66  char *name;
    7   KapaImageData data;
     7  // KapaImageData data;
    88
    99  name = NULL;
     
    1313    remove_argument (N, &argc, argv);
    1414  }
    15   if (!GetImage (&data, &kapa, name)) return (FALSE);
     15  if (!GetGraph (NULL, &kapa, name)) return (FALSE);
    1616  FREE (name);
    1717
  • trunk/Ohana/src/opihi/cmd.data/zplot.c

    r20936 r31667  
    5858}
    5959
     60int zcplot (int argc, char **argv) {
     61 
     62  int i, kapa;
     63  opihi_flt *out;
     64  double min, range;
     65  Graphdata graphmode;
     66  Vector *xvec, *yvec, *zvec, Zvec;
    6067
     68  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
     69
     70  if (argc != 6) {
     71    gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
     72    return (FALSE);
     73  }
     74
     75  min = atof(argv[4]);
     76  range = atof(argv[5]) - min;
     77
     78  /* find vectors */
     79  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     80  if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     81  if ((zvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     82  if (xvec[0].Nelements != yvec[0].Nelements) {
     83    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[2]);
     84    return (FALSE);
     85  }
     86  if (xvec[0].Nelements != zvec[0].Nelements) {
     87    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
     88    return (FALSE);
     89  }
     90  SetVector (&Zvec, OPIHI_FLT, zvec[0].Nelements);
     91  out = Zvec.elements.Flt;
     92 
     93  if (zvec[0].type == OPIHI_FLT) {
     94    opihi_flt *in = zvec[0].elements.Flt;
     95    for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
     96      *out = MIN (1.0, MAX (0.01, (*in - min) / range));
     97    }
     98  } else {
     99    opihi_int *in = zvec[0].elements.Int;
     100    for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
     101      *out = MIN (1.0, MAX (0.01, (*in - min) / range));
     102    }
     103  }
     104
     105  /* point size determined by Zvec */
     106  graphmode.style = 2; /* plot points */
     107  graphmode.color = -1; /* point color determined by Zvec */
     108  graphmode.etype = 0; /* no errorbars */
     109  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode);
     110
     111  free (Zvec.elements.Ptr);
     112
     113  return (TRUE);
     114
     115}
     116
     117
  • trunk/Ohana/src/opihi/dvo/gstar.c

    r30612 r31667  
    155155    if (dec1 < DEC[i]) found = TRUE;
    156156   
    157     r = SQ(Dec - DEC[i]) + SQ(Ra - RA[i]);
     157    r = SQ(Dec - DEC[i]) + SQ((Ra - RA[i])*cos(Dec*RAD_DEG));
    158158    if (r < Radius2) {
    159159      k = N1[i];
  • trunk/Ohana/src/opihi/include/pantasks.h

    r27435 r31667  
    108108  int Nfailure;
    109109  int Ntimeout;
     110  int Nskipexec;
    110111
    111112  double dtimeAve_alljobs, dtimeMin_alljobs, dtimeMax_alljobs;
     
    216217int DeleteJob (Job *job);
    217218void FreeJob (Job *job);
     219char *JobStateToString (JobStat state);
    218220
    219221float CheckJobs (void);
  • trunk/Ohana/src/opihi/include/shell.h

    r31635 r31667  
    163163char         *strip_version             PROTO((char *input));
    164164
     165// wrap readline in ohana mem functions:
     166char         *opihi_readline            PROTO((char *prompt));
     167
    165168/* gprint functions */
    166169void          gprintInit                PROTO((void));
  • trunk/Ohana/src/opihi/lib.shell/CommandOps.c

    r16888 r31667  
    106106
    107107
     108/* we need a strcreate function that does NOT use the ohana memory management
     109 * system to interact with some external libraries (which themselves free the memory)
     110 */
     111char *strcreate_sans_ohana (char *string) {
     112
     113  char *line;
     114
     115  if (string == (char *) NULL) return ((char *) NULL);
     116 
     117  line = malloc (MAX (1, strlen(string)) + 1);
     118  line = strcpy (line, string);
     119
     120  return (line);
     121}
     122
    108123/* generate a command completion list for readline */
    109124/**** these probably do not interact well with OHANA memory!!! ****/
     
    122137  for (i++; i < Ncommands; i++) {
    123138    if (!len)
    124       return (strcreate(commands[i].name));
     139
     140
     141      return (strcreate_sans_ohana(commands[i].name));
    125142    if (!strncmp (commands[i].name, text, len)) {
    126       return (strcreate(commands[i].name));
     143      return (strcreate_sans_ohana(commands[i].name));
    127144    }
    128145  }
  • trunk/Ohana/src/opihi/lib.shell/macro_create.c

    r16444 r31667  
    6868
    6969    /* get the next line (from correct place) */
    70     if (ThisList == 0)
    71       input = readline (prompt);
    72     else
     70    if (ThisList == 0) {
     71      input = opihi_readline (prompt);
     72    } else {
    7373      input = get_next_listentry (ThisList);
     74    }
    7475
    7576    if ((ThisList == 0) && (input == (char *) NULL)) {
     
    7778      continue;
    7879    }
    79     if (ThisList == 0) ohana_memregister (input);
    8080
    8181    if ((ThisList > 0) && (input == (char *) NULL)) {
  • trunk/Ohana/src/opihi/lib.shell/opihi.c

    r16473 r31667  
    1919    if (Nbad == 10) exit (20);
    2020
    21     line = readline (prompt);
     21    line = opihi_readline (prompt);
    2222
    2323    if (line == NULL) {
     
    3636
    3737    Nbad = 0;
    38     ohana_memregister (line);
    3938
    4039    stripwhite (line);
  • trunk/Ohana/src/opihi/lib.shell/string.c

    r15878 r31667  
    276276}
    277277
     278char *opihi_readline (char *prompt) {
     279
     280# ifdef OHANA_MEMORY
     281    char *raw = readline (prompt);
     282    char *line = strcreate (raw);
     283    real_free (raw);
     284    return line;
     285# else
     286    char *line = readline (prompt);
     287    return line;
     288# endif
     289}
     290
    278291/* replace all instances of \A with A in line */
    279292void interpolate_slash (char *line) {
Note: See TracChangeset for help on using the changeset viewer.