Changeset 41379 for trunk/Ohana/src/opihi/cmd.astro/jdtolst.c
- Timestamp:
- Jun 22, 2020, 11:00:22 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.astro/jdtolst.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.astro/jdtolst.c
r40376 r41379 23 23 char *long_str = get_variable ("LONGITUDE"); 24 24 if (!long_str) { 25 gprint (GP_ERR, "please define $LONGITUDE \n");25 gprint (GP_ERR, "please define $LONGITUDE (decimal hours, west positive)\n"); 26 26 FREE (OutputName); 27 27 return FALSE; 28 28 } 29 29 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); 31 31 free (long_str); 32 32 … … 87 87 gprint (GP_ERR, " (JD) may be a number or a vector.\n"); 88 88 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"); 89 90 return (FALSE); 90 91 } 92 93 # define MJD_OFFSET 2400000.5 94 95 int 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.
