IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 22, 2020, 11:00:22 AM (6 years ago)
Author:
eugene
Message:

add -copy option to coords; add mjdtolst; add option to control major tick spacing; add -copy option to header; add usage info to avperiodomatch

File:
1 edited

Legend:

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

    r40376 r41379  
    2323  char *long_str = get_variable ("LONGITUDE");
    2424  if (!long_str) {
    25     gprint (GP_ERR, "please define $LONGITUDE\n");
     25    gprint (GP_ERR, "please define $LONGITUDE (decimal hours, west positive)\n");
    2626    FREE (OutputName);
    2727    return FALSE;
    2828  }
    2929  double longitude = atof (long_str);
    30   if (VERBOSE) gprint (GP_ERR, "using longitude of %f\n", longitude);
     30  if (VERBOSE) gprint (GP_ERR, "using longitude of %f (decimal hours, west positive)\n", longitude);
    3131  free (long_str);
    3232
     
    8787  gprint (GP_ERR, "  (JD) may be a number or a vector.\n");
    8888  gprint (GP_ERR, "  if (JD) is a vector, (output) must be supplied and is used as the name of the output vector \n");
     89  gprint (GP_ERR, "  $LONGITUDE must be set (decimal hours, west positive)\n");
    8990  return (FALSE);
    9091}
     92
     93# define MJD_OFFSET 2400000.5
     94
     95int mjdtolst (int argc, char **argv) {
     96
     97  int N;
     98  Vector *mjdvec, *outvec;
     99
     100  int VERBOSE = FALSE;
     101  VERBOSE = FALSE;
     102  if ((N = get_argument (argc, argv, "-v"))) {
     103    VERBOSE = TRUE;
     104    remove_argument (N, &argc, argv);
     105  }
     106
     107  char *OutputName = NULL;
     108  if ((N = get_argument (argc, argv, "-output"))) {
     109    remove_argument (N, &argc, argv);
     110    OutputName = strcreate (argv[N]);
     111    remove_argument (N, &argc, argv);
     112  }
     113  if (argc != 2) goto syntax;
     114
     115  char *long_str = get_variable ("LONGITUDE");
     116  if (!long_str) {
     117    gprint (GP_ERR, "please define $LONGITUDE (decimal hours, west positive)\n");
     118    FREE (OutputName);
     119    return FALSE;
     120  }
     121  double longitude = atof (long_str);
     122  if (VERBOSE) gprint (GP_ERR, "using longitude of %f (decimal hours, west positive)\n", longitude);
     123  free (long_str);
     124
     125  if (ISNUM(argv[1][0])) {
     126
     127    char *endptr;
     128    double mjd = strtod (argv[1], &endptr);
     129    if (endptr == argv[1]) {
     130      gprint (GP_ERR, "error interpretting %s as a number\n", argv[1]);
     131      FREE (OutputName);
     132      return FALSE;
     133    }
     134
     135    double lst = ohana_lst (mjd + MJD_OFFSET, longitude);
     136
     137    if (OutputName) {
     138      set_variable (OutputName, lst);
     139      FREE (OutputName);
     140      return (TRUE);
     141    }
     142   
     143    gprint (GP_ERR, "lst: %f\n", lst);
     144    return (TRUE);
     145  }
     146
     147  if (!OutputName) {
     148    gprint (GP_ERR, " if (MJD) is a vector, -output must be supplied\n");
     149    return FALSE;
     150  }
     151
     152  if ((mjdvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) {
     153    FREE (OutputName);
     154    return FALSE;
     155  }
     156
     157  if (mjdvec->type != OPIHI_FLT) {
     158    gprint (GP_ERR, " (MJD) must be of type FLOAT\n");
     159    FREE (OutputName);
     160    return FALSE;
     161  }
     162
     163  if ((outvec = SelectVector (OutputName, ANYVECTOR, TRUE)) == NULL) {
     164    FREE (OutputName);
     165    return FALSE;
     166  }
     167
     168  ResetVector (outvec, OPIHI_FLT, mjdvec[0].Nelements);
     169
     170  for (int i = 0; i < mjdvec[0].Nelements; i++) {
     171    double lst = ohana_lst (mjdvec->elements.Flt[i] + MJD_OFFSET, longitude);
     172    outvec->elements.Flt[i] = lst;
     173  }
     174  FREE (OutputName);
     175  return TRUE;
     176
     177 syntax:
     178  gprint (GP_ERR, "USAGE: mjdtolst (MJD) [-output name]\n");
     179  gprint (GP_ERR, "  (MJD) may be a number or a vector.\n");
     180  gprint (GP_ERR, "  if (MJD) is a vector, (output) must be supplied and is used as the name of the output vector \n");
     181  gprint (GP_ERR, "  $LONGITUDE must be set (decimal hours, west positive)\n");
     182  return (FALSE);
     183}
Note: See TracChangeset for help on using the changeset viewer.