IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 6, 2013, 3:30:44 PM (13 years ago)
Author:
eugene
Message:

option to specify output format for fits table columns; add dbinsert; pass db info on command line; option to make a guess for vgauss; option to rename a spline; option to get results files for remote clients; some improvments to gstar (sorting, optional fields)

Location:
trunk/Ohana/src/opihi
Files:
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi

  • trunk/Ohana/src/opihi/cmd.data

  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r34584 r35109  
    4242$(SRC)/dbconnect.$(ARCH).o      \
    4343$(SRC)/dbselect.$(ARCH).o       \
     44$(SRC)/dbinsert.$(ARCH).o       \
    4445$(SRC)/erase.$(ARCH).o          \
    4546$(SRC)/extract.$(ARCH).o        \
  • trunk/Ohana/src/opihi/cmd.data/dbconnect.c

    r34584 r35109  
    88int dbconnect (int argc, char **argv) {
    99 
     10  int N;
    1011  char query[256];
    11   char password[1024];
    1212  MYSQL_RES *result;
     13
     14  char *password = NULL;
     15  if ((N = get_argument (argc, argv, "-p"))) {
     16    remove_argument (N, &argc, argv);
     17    password = strcreate (argv[N]);
     18    remove_argument (N, &argc, argv);
     19  }
    1320
    1421  if (argc != 4) {
     
    1724  }
    1825
    19   fprintf (stdout, "Enter password: ");
    20   scan_line (stdin, password);
     26  if (!password) {
     27      ALLOCATE (password, char, 1024);
     28      fprintf (stdout, "Enter password: ");
     29      scan_line (stdin, password);
    2130
    2231# if (0)
    23   int i;
    24   char c;
     32      int i;
     33      char c;
    2534
    26   initscr();
    27   noecho();
    28   i = 0;
    29   while (((c = getch()) != EOF) && (c != '\n')) {
    30     password[i] = c;
    31     i++;
     35      initscr();
     36      noecho();
     37      i = 0;
     38      while (((c = getch()) != EOF) && (c != '\n')) {
     39          password[i] = c;
     40          i++;
     41      }
     42      password[i] = 0;
     43# endif
    3244  }
    33   password[i] = 0;
    34 # endif
    3545
    3646  // XXX do I need to call mysql_library_init()?
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r34584 r35109  
    2424int dbconnect        PROTO((int, char **));
    2525int dbselect         PROTO((int, char **));
     26int dbinsert         PROTO((int, char **));
    2627int delete           PROTO((int, char **));
    2728int densify          PROTO((int, char **));
     
    170171  {1, "dbconnect",    dbconnect,        "setup mysql db connection"},
    171172  {1, "dbselect",     dbselect,         "extract vectors from mysql database table"},
     173  {1, "dbinsert",     dbinsert,         "sql insert command"},
    172174  {1, "delete",       delete,           "delete vectors or images"},
    173175  {1, "densify",      densify,          "create an image histogram from a set of vectors"},
  • trunk/Ohana/src/opihi/cmd.data/spline.c

    r34584 r35109  
    22
    33int spline_list (int argc, char **argv);
     4int spline_help (int argc, char **argv);
    45int spline_create (int argc, char **argv);
    56int spline_apply (int argc, char **argv);
     
    78int spline_save (int argc, char **argv);
    89int spline_delete (int argc, char **argv);
     10int spline_rename (int argc, char **argv);
    911int spline_getspline (int argc, char **argv);
    1012
    1113static Command spline_commands[] = {
     14  {1, "help",       spline_help,       "list spline help info"},
    1215  {1, "list",       spline_list,       "list splines"},
    1316  {1, "create",     spline_create,     "create a spline"},
     
    1619  {1, "save",       spline_save,       "read a spline from a FITS file"},
    1720  {1, "delete",     spline_delete,     "delete a spline"},
     21  {1, "rename",     spline_rename,     "rename a spline"},
    1822};
     23
     24int spline_help (int argc, char **argv) {
     25
     26  gprint (GP_ERR, "USAGE: spline (command)\n");
     27  gprint (GP_ERR, "    spline help                                  : this listing\n");
     28  gprint (GP_ERR, "    spline list                                  : list splines\n");
     29  gprint (GP_ERR, "    spline create (spline) (Xknots) (Yknots)     : create a spline\n");
     30  gprint (GP_ERR, "    spline apply  (spline) (Xpts) (Ypts)         : apply a spline to Xpts to get Ypts\n");
     31  gprint (GP_ERR, "    spline delete (spline)                       : delete named spline\n");
     32  gprint (GP_ERR, "    spline rename (spline) (new)                 : change spline name to new name\n");
     33  gprint (GP_ERR, "    spline load   (spline) (filename)            : load a spline from a FITS file\n");
     34  gprint (GP_ERR, "    spline save   (spline) (filename) [-append]  : save a spline in FITS format\n");
     35
     36  return FALSE;
     37}
    1938
    2039int spline_command (int argc, char **argv) {
     
    2342
    2443  if (argc < 2) {
    25     gprint (GP_ERR, "USAGE: spline (command)\n");
    26     gprint (GP_ERR, "    spline list                                    : list splines\n");
    27     gprint (GP_ERR, "    spline create   (spline)                       : create a spline\n");
    28     gprint (GP_ERR, "    spline delete   (spline)                       : delete a spline\n");
     44    spline_help(0,NULL);
    2945    return (FALSE);
    3046  }
  • trunk/Ohana/src/opihi/cmd.data/spline_commands.c

    r34584 r35109  
    126126}
    127127
     128int spline_rename (int argc, char **argv) {
     129
     130  Spline *spline;
     131
     132  if (argc != 3) {
     133    gprint (GP_ERR, "USAGE: spline rename (spline) (newname)\n");
     134    return FALSE;
     135  }
     136
     137  spline = FindSpline (argv[1]);
     138  if (spline == NULL) {
     139    gprint (GP_ERR, "spline %s not found\n", argv[1]);
     140    return FALSE;
     141  }
     142
     143  free (spline->name);
     144  spline->name = strcreate (argv[2]);
     145  return TRUE;
     146}
     147
    128148/*
    129149int spline_listspline (int argc, char **argv) {
  • trunk/Ohana/src/opihi/cmd.data/subset.c

    r34461 r35109  
    3535  }
    3636  if ((tvec = SelectVector (out, OLDVECTOR, TRUE)) == NULL) goto error;
    37   /* check size of ivec, tvec: must match */
     37  if (ivec->Nelements != tvec->Nelements) {
     38    /* check size of ivec, tvec: must match */
     39    gprint (GP_ERR, "logical expression has different length from input vector\n");
     40    goto error;
     41  }
    3842
    3943  // ovec matches ivec in type
  • trunk/Ohana/src/opihi/cmd.data/vgauss.c

    r29938 r35109  
    3131  }
    3232
     33//   Guess = FALSE;
     34//   if ((N = get_argument (argc, argv, "-guess"))) {
     35//     Guess = TRUE;
     36//     remove_argument (N, &argc, argv);
     37//   }
     38
    3339  if (argc != 5) {
    3440    gprint (GP_ERR, "USAGE: vgauss <x> <y> <dy> (out)\n");
     41    gprint (GP_ERR, "  <dy> may be the words 'con[stant]' or 'poi[sson]', in which case the error is constructed'\n");
    3542    gprint (GP_ERR, " uses guesses: C0 (mean), C1 (sigma), C2 (norm), C3 (sky)\n");
    3643    return (FALSE);
     
    3946  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    4047  if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    41   if ((svec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    4248  if ((ovec = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);
     49
     50  int Nsvec = strlen(argv[3]);
     51
     52  if ((Nsvec >= 3) && (!strncasecmp ("poisson", argv[3], Nsvec) || !strncasecmp ("constant", argv[3], Nsvec))) {
     53    svec = SelectVector ("vgauss_err", ANYVECTOR, TRUE);
     54    if (svec == NULL) return (FALSE);
     55    MatchVector (svec, xvec, OPIHI_FLT);
     56    v1 = svec[0].elements.Flt;
     57    v2 = yvec[0].elements.Flt;
     58    if (!strncasecmp ("poisson", argv[3], Nsvec)) {
     59      for (i = 0; i < svec[0].Nelements; i++) {
     60        v1[i] = (isfinite(v2[i]) && (v2[i] > 0)) ? sqrt(v2[i]) : 1.0;
     61      }
     62    } else {
     63      for (i = 0; i < svec[0].Nelements; i++) {
     64        v1[i] = 1.0;
     65      }
     66    }
     67  } else {
     68    if ((svec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     69  }
    4370
    4471  CastVector (xvec, OPIHI_FLT);
     
    4673  CastVector (svec, OPIHI_FLT);
    4774  // XXX Cast is failing.
    48    
    4975
    5076  Npts = xvec[0].Nelements;
     
    5884  GET_VAR (par[3], "C3");
    5985  Npar = 4;
     86
    6087
    6188  // mrqmin takes the inverse variance (do not generate NANs)
  • trunk/Ohana/src/opihi/cmd.data/vstats.c

    r33963 r35109  
    123123
    124124    ALLOCATE (Nval, int, Nbin + 2);
    125     bzero (Nval, Nbin*sizeof(int));
     125    bzero (Nval, (Nbin + 2)*sizeof(int));
    126126    var = 0;
    127127    if (vec[0].type == OPIHI_FLT) {
  • trunk/Ohana/src/opihi/cmd.data/write_vectors.c

    r34584 r35109  
    1010  Vector **vec;
    1111
     12  if ((N = get_argument (argc, argv, "-h"))) goto usage;
     13  if ((N = get_argument (argc, argv, "--h"))) goto usage;
     14  if ((N = get_argument (argc, argv, "-help"))) goto usage;
     15  if ((N = get_argument (argc, argv, "--help"))) goto usage;
     16
    1217  /* look for format option */
    1318  format = (char *) NULL;
     
    1722    remove_argument (N, &argc, argv);
    1823  }
     24  if ((N = get_argument (argc, argv, "-format"))) {
     25    if (format) {
     26      gprint (GP_ERR, "ERROR: do not mix -f and -format\n");
     27      free (format);
     28      return (FALSE);
     29    }
     30    remove_argument (N, &argc, argv);
     31    format = strcreate (argv[N]);
     32    remove_argument (N, &argc, argv);
     33  }
    1934
    2035  /* option generate a FITS output table */
    2136  FITS = NULL;
    2237  if ((N = get_argument (argc, argv, "-fits"))) {
    23     if (format) {
    24       gprint (GP_ERR, "ERROR: do not mix -fits and -format\n");
    25       free (format);
    26       return (FALSE);
    27     }
    2838    remove_argument (N, &argc, argv);
    2939    FITS = strcreate (argv[N]);
     
    6171
    6272  if (argc < 3) {
    63     gprint (GP_ERR, "USAGE: write [-append] [-f \"format\"] file vector vector ...\n");
     73    gprint (GP_ERR, "USAGE: write [options] file vector vector ...\n");
     74    gprint (GP_ERR, "OPTIONS: [-header] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n");
    6475    return (FALSE);
    6576  }
     
    222233  return (TRUE);
    223234
     235 usage:
     236    gprint (GP_ERR, "USAGE: write [options] file vector vector ...\n");
     237    gprint (GP_ERR, "OPTIONS: [-header] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n\n");
     238
     239    gprint (GP_ERR, "OPTIONS: \n");
     240    gprint (GP_ERR, "  -header : add a descriptive header line to ascii or csv output\n");
     241    gprint (GP_ERR, "  -append : write to the end of the existing file\n");
     242    gprint (GP_ERR, "  -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n");
     243    gprint (GP_ERR, "  -csv : write a comma-separated values file (eg, to read in excel)\n");
     244    gprint (GP_ERR, "  -f \"format\" : provide formatting codes for output:\n");
     245    gprint (GP_ERR, "    ascii / csv : format consists of c-style format codes in form %NN.Md\n");
     246    gprint (GP_ERR, ",     the following codes are allowed\n");
     247    gprint (GP_ERR, "        %e -- double, %f -- float\n");
     248    gprint (GP_ERR, "        %d -- int, %c -- char, %x -- hex int\n");
     249    gprint (GP_ERR, "    FITS : format consists of the following FITS binary table format codes:\n");
     250    gprint (GP_ERR, "      B : 1 byte int\n");   
     251    gprint (GP_ERR, "      I : 2 byte int\n");   
     252    gprint (GP_ERR, "      J : 4 byte int\n");   
     253    gprint (GP_ERR, "      K : 8 byte int\n");   
     254    gprint (GP_ERR, "      D : 4 byte float\n");   
     255    gprint (GP_ERR, "      F : 1 byte float\n");   
     256    gprint (GP_ERR, "   -h : this help listing\n");
     257    gprint (GP_ERR, "   --h : this help listing\n");
     258    gprint (GP_ERR, "   -help : this help listing\n");
     259    gprint (GP_ERR, "   --help : this help listing\n");
     260    return FALSE;
    224261}
    225262
Note: See TracChangeset for help on using the changeset viewer.