Index: /branches/eam_branches/ipp-20230313/Ohana/src/tools/src/mpcorb_predict.c
===================================================================
--- /branches/eam_branches/ipp-20230313/Ohana/src/tools/src/mpcorb_predict.c	(revision 42676)
+++ /branches/eam_branches/ipp-20230313/Ohana/src/tools/src/mpcorb_predict.c	(revision 42677)
@@ -51,5 +51,5 @@
 PlanetDatum mpcorb_predict (Planets *planet, double mjdObs, int FullCalc);
 
-Planets *mpcorb_read_text (char *filename, int *nplanets);
+Planets *mpcorb_read_text (char *filename, int *nplanets, int noHeader);
 Planets *mpcorb_read_fits (char *filename, int *nplanets);
 void     mpcorb_save_fits (char *filename, Planets *planets, int Nplanets);
@@ -73,4 +73,7 @@
 
 int main (int argc, char **argv) {
+
+  if (get_argument (argc, argv, "-h")) goto usage;
+  if (get_argument (argc, argv, "--help")) goto usage;
 
   // XXX test
@@ -84,5 +87,5 @@
     // load the planets
     int Nplanets = 0;
-    Planets *planets = mpcorb_read_text (filename, &Nplanets);
+    Planets *planets = mpcorb_read_text (filename, &Nplanets, FALSE);
     for (int i = 0; i < 10; i++) {
       // if it is in the region, use the more accurate calculation
@@ -92,6 +95,5 @@
   }
 
-  if ((argc != 9) && (argc != 10)) goto usage;
-
+  if (argc < 2) goto usage;
   if (!strcasecmp (argv[1], "trange")) mpcorb_trange (argc, argv);
   if (!strcasecmp (argv[1], "moment")) mpcorb_moment (argc, argv);
@@ -99,9 +101,16 @@
 usage:
   fprintf (stderr, "USAGE: %s trange (MPCORB.DAT) (Tmin) (Tmax) (Rmin) (Rmax) (Dmin) (Dmax) (range.fits)\n", argv[0]);
-  fprintf (stderr, "USAGE: %s moment (range.fits) (Tobs) (Rmin) (Rmax) (Dmin) (Dmax) (output)\n", argv[0]);
+  fprintf (stderr, "USAGE: %s moment (range.fits) (Tobs) (Rmin) (Rmax) (Dmin) (Dmax) (output)\n\n", argv[0]);
 
   fprintf (stderr, " trange : generate a table of asteroid orbital elements which fall within the region at Tmin or Tmax (in MJD)\n");
-  fprintf (stderr, " moment : generate a table of asteroid positions which fall within the region at Tobs (in MJD)\n");
-
+  fprintf (stderr, " moment : generate a table of asteroid positions which fall within the region at Tobs (in MJD)\n\n");
+
+  fprintf (stderr, " Tmin, Tmax, Tobs are in MJD; Rmin, Rmax, Dmin, Dmax are in decimal degrees\n");
+  fprintf (stderr, " Orbital predictions are valid for the PS1 site\n");
+
+  fprintf (stderr, " trange options:\n");
+  fprintf (stderr, " -no-header (for files other than MPCORB.DAT)\n");
+  fprintf (stderr, " -min-obs (Nobs) : minimum number of observations to keep object\n");
+  fprintf (stderr, " -min-opp (Nopp) : minimum number of oppositions to keep object\n");
   exit (2);
 }
@@ -110,5 +119,25 @@
 void mpcorb_trange (int argc, char **argv) {
 
-  if (argc != 10) Shutdown ("USAGE: %s trange (MPCORB.DAT) (Tmin) (Tmax) (Rmin) (Rmax) (Dmin) (Dmax) (range.fits)\n", argv[0]);
+  int N;
+  
+  int noHeader = FALSE;
+  if ((N = get_argument (argc, argv, "-no-header"))) {
+    remove_argument (N, &argc, argv);
+    noHeader = TRUE;
+  }
+  int MIN_OBS = 0;
+  if ((N = get_argument (argc, argv, "-min-obs"))) {
+    remove_argument (N, &argc, argv);
+    MIN_OBS = atoi(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  int MIN_OPP = 0;
+  if ((N = get_argument (argc, argv, "-min-opp"))) {
+    remove_argument (N, &argc, argv);
+    MIN_OPP = atoi(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 10) Shutdown ("USAGE: %s trange (MPCORB.DAT) (Tmin) (Tmax) (Rmin) (Rmax) (Dmin) (Dmax) (range.fits) [-no-header] [-min-obs] [-min-opp]\n", argv[0]);
 
   char  *filename = argv[2];
@@ -122,5 +151,5 @@
 
   int Nplanets = 0;
-  Planets *planets = mpcorb_read_text (filename, &Nplanets);
+  Planets *planets = mpcorb_read_text (filename, &Nplanets, noHeader);
   if (VERBOSE) fprintf (stderr, "loaded %d planets\n", Nplanets);
 
@@ -133,6 +162,7 @@
     if (i % 1000 == 0) fprintf (stderr, ".");
 
-    // XXX make these quality cuts user options
-    if (SKIP_BAD && ((planets[i].Nobs < 20) || (planets[i].Nopp < 2))) continue;
+    // skip poor-quality observations
+    if (planets[i].Nobs < MIN_OBS) continue;
+    if (planets[i].Nopp < MIN_OPP) continue;
 
     // is the object in the region for the start of the period?
@@ -804,5 +834,5 @@
 
 // read the full MPCORB file, storing desired information in Planets structure
-Planets *mpcorb_read_text (char *filename, int *nplanets) {
+Planets *mpcorb_read_text (char *filename, int *nplanets, int noHeader) {
 
   ALLOCATE_PTR (buffer, char, NBYTE);
@@ -838,6 +868,8 @@
 
       Nline ++;
-      if ((Nline > 43) && (q - p > 5)) {
+      int doParse = (noHeader || (Nline > 43));
+      if (doParse && (q - p > 5)) {
 	mpcorb_parseline (p, &planets[Nplanets], Nbyte - offset);
+	if ((Nplanets < 10) && DEBUG) fprintf (stderr, "object: %s", planets[Nplanets].ID);
 	Nplanets ++;
 	CHECK_REALLOCATE (planets, Planets, NPLANETS, Nplanets, 10000);
