Changeset 4805 for trunk/Ohana/src/opihi
- Timestamp:
- Aug 16, 2005, 6:41:16 PM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 4 edited
-
include/convert.h (modified) (2 diffs)
-
include/dvo1.h (modified) (1 diff)
-
lib.data/Makefile (modified) (1 diff)
-
lib.data/convert.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/include/convert.h
r4602 r4805 4 4 # define CONVERT_H 5 5 6 /*** values for time formats */ 7 enum {TIME_NONE, TIME_JD, TIME_MJD, TIME_DATE, TIME_DAYS, TIME_HOURS, TIME_MINUTES, TIME_SECONDS}; 8 9 /*** conversion functions ***/ 6 /*** time/coord conversion functions not supplied by libohana ***/ 10 7 time_t TimeRef PROTO((double time, time_t TimeReference, int TimeFormat)); 11 8 double TimeValue PROTO((time_t time, time_t TimeReference, int TimeFormat)); 12 int chk_time PROTO((char *line)); 13 time_t date_to_sec PROTO((char *date)); 14 int dms_to_ddd PROTO((double *Value, char *string)); 15 time_t jd_to_sec PROTO((double jd)); 16 time_t mjd_to_sec PROTO((double mjd)); 17 char *sec_to_date PROTO((time_t second)); 18 double sec_to_jd PROTO((time_t second)); 19 double sec_to_mjd PROTO((time_t second)); 20 int str_to_dtime PROTO((char *line, double *second)); 21 int str_to_radec PROTO((double *ra, double *dec, char *str1, char *str2)); 22 int str_to_time PROTO((char *line, time_t *second)); 9 23 10 int hh_hms PROTO((double hh, int *hr, int *mn, double *sc)); 24 11 int dd_dms PROTO((double dd, int *dg, int *mn, double *sc)); … … 33 20 char *meade_dec_to_str PROTO((double deg)); 34 21 int hstgsc_hms_to_deg PROTO((double *h0, double *h1, double *d0, double *d1, char *string)); 22 char *strptime PROTO((const char *s, const char *format, struct tm *tm)); 35 23 36 24 # endif -
trunk/Ohana/src/opihi/include/dvo1.h
r4689 r4805 23 23 } RegionFile; 24 24 25 /* aregion, region_list, match_image, LoadImages */ 26 RegionFile *find_regions PROTO((double Ra, double Dec, double radius, int *Nregions)); 27 GSCRegion *get_regions PROTO((Image *image, int *Nregions)); 28 void aregion PROTO((GSCRegion *region, FILE *f, double ra, double dec, char *path)); 29 RegionFile *region_list PROTO((char *filename, int *Nregions)); 30 int match_image PROTO((Image *image, int Nimage, unsigned int T, short int S)); 31 Image *LoadImages PROTO((int *Nimage)); 32 void image_subset PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, Graphdata *graph, int RegionSelect, unsigned long int tzero, double trange, int TimeSelect)); 33 void sort_images PROTO((Image *image, int N)); 34 void sortave PROTO((Average *ave, int N)); 35 void cprecess PROTO((Average *average, int Naverage, double in_epoch, double out_epoch)); 36 void compare PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec, Vector *dvec, Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius)); 37 38 /*** photometry functions ***/ 39 double *ExtractByDMag PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param)); 40 double *ExtractDMag PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist)); 41 double *ExtractMagnitudes PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *n)); 42 double *ExtractMeasures PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param)); 25 /*** dvo prototypes ***/ 26 int DetermineTypeCode PROTO((Average *average, Measure *measure, int code)); 27 double DetermineTypefrac PROTO((Average *average, Measure *measure, PhotCode *code)); 28 double ExtractAverages PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int param)); 29 double *ExtractByDMag PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param)); 30 double *ExtractDMag PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist)); 31 double *ExtractMagnitudes PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *n)); 32 double *ExtractMeasures PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param)); 43 33 double *ExtractMeasuresByDMag PROTO((PhotCode **code, int *mode, int use_first, Average *average, SecFilt *secfilt, Measure *measure, int *nlist, int param)); 44 34 double *ExtractMeasuresDMag PROTO((PhotCode **code, int *mode, Average *average, SecFilt *secfilt, Measure *measure, int *nlist)); 35 void FreeImageSelection PROTO(()); 36 void FreeImageSelection PROTO(()); 37 int GetAverageParam PROTO((char *parname)); 38 void GetAverageParamHelp PROTO(()); 39 int GetMagMode PROTO((char *string)); 40 double GetMeasure PROTO((int param, Average *average, Measure *measure, double mag)); 41 int GetMeasureParam PROTO((char *parname)); 42 int GetMeasureTypeCode PROTO((Measure *measure)); 43 int GetPhotcodeInfo PROTO((char *string, PhotCode **Code, int *Mode)); 44 int GetRegionSelection PROTO(()); 45 int GetSelectionParam PROTO(()); 46 int GetTimeSelection PROTO((time_t *tz, time_t *te)); 47 void InitDVO PROTO(()); 48 int InitPhotcodes PROTO(()); 49 Image *LoadImages PROTO((int *Nimage)); 50 Image *MatchImage PROTO((unsigned int time, short int source)); 45 51 Image *MatchImage PROTO((unsigned int time, short int source)); 46 52 Coords *MatchMosaic PROTO((unsigned int time, short int source)); 47 int DetermineTypeCode PROTO((Average *average, Measure *measure, int code)); 48 double DetermineTypefrac PROTO((Average *average, Measure *measure, PhotCode *code)); 49 double ExtractAverages PROTO((PhotCode *code, int mode, Average *average, SecFilt *secfilt, Measure *measure, int param)); 50 void FreeImageSelection PROTO(()); 51 int GetAverageParam PROTO((char *parname)); 52 void GetAverageParamHelp PROTO(()); 53 int GetMagMode PROTO((char *string)); 54 double GetMeasure PROTO((int param, Average *average, Measure *measure, double mag)); 55 int GetMeasureParam PROTO((char *parname)); 56 int GetMeasureTypeCode PROTO((Measure *measure)); 57 int GetPhotcodeInfo PROTO((char *string, PhotCode **Code, int *Mode)); 58 int GetSelectionParam PROTO(()); 59 int InitPhotcodes PROTO(()); 60 int Quality PROTO((Measure *measure, int IsDophot)); 53 int Quality PROTO((Measure *measure, int IsDophot)); 61 54 int SelectMags PROTO((int Nphot, int Tphot, int Ns, Average *average, Measure *measure, SecFilt *secfilt, int UL)); 62 int SetImageSelection PROTO((int mode)); 63 int SetPhotSelections PROTO((int *argc, char **argv, int Nparams)); 64 int SetSelectionParam PROTO((int param)); 65 int TestAverage PROTO((PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure)); 66 int TestPhotSelections PROTO((PhotCode **code, int *mode, int param)); 55 RegionFile *SelectRegions PROTO((char *RegionName, char *RegionList, int *nregions)); 56 int SetImageSelection PROTO((int mode)); 57 int SetPhotSelections PROTO((int *argc, char **argv, int Nparams)); 58 int SetRegionSelection PROTO((int *argc, char **argv, char **RegionName, char **RegionList)); 59 int SetSelectionParam PROTO((int param)); 60 int TestAverage PROTO((PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure)); 61 int TestPhotSelections PROTO((PhotCode **code, int *mode, int param)); 62 void aregion PROTO((GSCRegion *region, FILE *f, double ra, double dec, char *path)); 63 void compare PROTO((Catalog *catlog1, Catalog *catlog2, Vector *rvec, Vector *dvec, Vector *mvec, Vector *drvec, Vector *ddvec, Vector *dmvec, double radius)); 64 void cprecess PROTO((Average *average, int Naverage, double in_epoch, double out_epoch)); 65 RegionFile *find_regions PROTO((double Ra, double Dec, double radius, int *Nregions)); 66 GSCRegion *get_regions PROTO((Image *image, int *Nregions)); 67 void image_subset PROTO((Image *image, int Nimage, int **Subset, int *Nsubset, Graphdata *graph, int RegionSelect, unsigned long int tzero, double trange, int TimeSelect)); 68 int match_image PROTO((Image *image, int Nimage, unsigned int T, short int S)); 69 int match_image_subset PROTO((Image *image, int *subset, int Nsubset, unsigned int T, short int S)); 67 70 void print_value PROTO((FILE *f, double value, short int ival)); 68 69 RegionFile *SelectRegions PROTO((char *RegionName, char *RegionList, int *nregions)); 70 71 void InitDVO (); 72 73 void FreeImageSelection (); 74 Image *MatchImage (unsigned int time, short int source); 75 int GetRegionSelection (); 76 int SetRegionSelection (int *argc, char **argv, char **RegionName, char **RegionList); 77 void sort_image_subset (Image *image, int *subset, int N); 78 int match_image_subset (Image *image, int *subset, int Nsubset, unsigned int T, short int S); 79 int GetTimeSelection (time_t *tz, time_t *te); 71 RegionFile *region_list PROTO((char *filename, int *Nregions)); 72 void sort_image_subset PROTO((Image *image, int *subset, int N)); 73 void sort_images PROTO((Image *image, int N)); 74 void sortave PROTO((Average *ave, int N)); 80 75 81 76 # endif -
trunk/Ohana/src/opihi/lib.data/Makefile
r4747 r4805 21 21 # general numerical functions (libdata) ##################### 22 22 srcs = \ 23 $(SDIR)/convert.$(ARCH).o \24 23 $(SDIR)/sort.$(ARCH).o \ 25 24 $(SDIR)/fft.$(ARCH).o \ -
trunk/Ohana/src/opihi/lib.data/convert.c
r4697 r4805 3 3 # include <time.h> 4 4 5 char *strptime(const char *s, const char *format, struct tm *tm); 6 7 5 /** additional time / coordinate conversions not supplied by libohana **/ 6 8 7 int hh_hms (double hh, int *hr, int *mn, double *sc) { 9 8 … … 111 110 } 112 111 113 /***** convert [-]00:00:00 to 0.0000 ****/114 int dms_to_ddd (double *Value, char *string) {115 116 int valid, neg, status;117 double tmp, value;118 char *p1, *p2, *px;119 120 valid = FALSE;121 neg = FALSE;122 stripwhite (string);123 p1 = string;124 px = string + strlen(string);125 126 if (string[0] == '-') {127 valid = TRUE;128 neg = TRUE;129 p1 = &string[1];130 }131 if (string[0] == '+') {132 valid = TRUE;133 neg = FALSE;134 p1 = &string[1];135 }136 if (isdigit(string[0])) {137 valid = TRUE;138 p1 = &string[0];139 }140 if (!valid) { return (FALSE); }141 142 status = 1;143 tmp = strtod (p1, &p2);144 if (p2 == p1) return (FALSE); /* entry not a number: +fred */145 value = tmp;146 if (p2 == px) goto escape; /* entry only number: +1.0 */147 p1 = p2 + 1;148 149 tmp = strtod (p1, &p2);150 if (p2 == p1) goto escape; /* entry not a number: +1:fred */151 status = 2;152 value += tmp / 60.0;153 if (p2 == px) goto escape; /* entry only number: +1:1 */154 p1 = p2 + 1;155 156 tmp = strtod (p1, &p2);157 if (p2 == p1) goto escape; /* entry not a number: +1:1:fred */158 value += tmp / 3600.0;159 160 escape:161 if (neg) {162 value *= -1;163 }164 *Value = value;165 166 return (status);167 }168 169 112 /***** convert 00:00:00 or 00:00 to 0 - 86400 ****/ 170 113 int hms_to_sec (char *string, time_t *second) { … … 211 154 if (*p) return (FALSE); 212 155 *second = time.tm_wday*86400 + time.tm_hour*3600 + time.tm_min*60 + time.tm_sec; 213 return (TRUE);214 }215 216 /**********/217 int str_to_radec (double *ra, double *dec, char *str1, char *str2) {218 219 double Ra, Dec;220 221 *ra = *dec = 0;222 switch (dms_to_ddd (&Ra, str1)) {223 case 0:224 fprintf (stderr, "syntax error in RA\n");225 return (FALSE);226 case 1:227 break;228 case 2:229 Ra = Ra * 15;230 break;231 }232 switch (dms_to_ddd (&Dec, str2)) {233 case 0:234 fprintf (stderr, "syntax error in DEC\n");235 return (FALSE);236 case 1:237 case 2:238 break;239 }240 *ra = Ra;241 *dec = Dec;242 156 return (TRUE); 243 157 } … … 302 216 } 303 217 304 /**********/305 int chk_time (char *line) {306 307 char *p1, *p2;308 double tmp;309 int mode;310 311 p1 = line;312 tmp = strtod (p1, &p2);313 mode = TIME_DATE;314 if (p2 == p1 + strlen (p1) - 1) {315 if (*p2 == 'j') {316 mode = TIME_JD;317 }318 if (*p2 == 'J') {319 mode = TIME_MJD;320 }321 if (*p2 == 'd') {322 mode = TIME_DAYS;323 }324 if (*p2 == 'h') {325 mode = TIME_HOURS;326 }327 if (*p2 == 'm') {328 mode = TIME_MINUTES;329 }330 if (*p2 == 's') {331 mode = TIME_SECONDS;332 }333 }334 return (mode);335 }336 337 /**********/338 int str_to_time (char *line, time_t *second) {339 340 char *tmpline;341 struct tm *gmt;342 struct timeval now;343 double jd;344 time_t tsec;345 346 if (!strcasecmp (line, "NOW")) {347 gettimeofday (&now, (struct timezone *) NULL);348 *second = now.tv_sec;349 return (TRUE);350 }351 352 if (!strncasecmp (line, "TODAY", 5)) {353 gettimeofday (&now, (struct timezone *) NULL);354 if (line[5]) { /* line has extra data (ie, hh:mm:ss) */355 tsec = now.tv_sec;356 ALLOCATE (tmpline, char, 64);357 gmt = gmtime (&tsec);358 sprintf (tmpline, "%04d/%02d/%02d,%s",359 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, &line[6]);360 *second = date_to_sec (tmpline);361 free (tmpline);362 return (TRUE);363 } else {364 *second = 86400 * ((int)(now.tv_sec / 86400));365 return (TRUE);366 }367 }368 369 switch (chk_time (line)) {370 case 0:371 return (FALSE);372 case TIME_JD:373 jd = strtod (line, 0);374 *second = jd_to_sec (jd);375 return (TRUE);376 case TIME_MJD:377 jd = strtod (line, 0);378 *second = mjd_to_sec (jd);379 return (TRUE);380 case TIME_DATE:381 *second = date_to_sec (line);382 return (TRUE);383 case TIME_DAYS:384 *second = strtod (line, 0) * 86400.0;385 return (TRUE);386 case TIME_HOURS:387 *second = strtod (line, 0) * 3600.0;388 return (TRUE);389 case TIME_MINUTES:390 *second = strtod (line, 0) * 60.0;391 return (TRUE);392 case TIME_SECONDS:393 *second = strtod (line, 0);394 return (TRUE);395 }396 return (FALSE);397 }398 399 400 /**********/401 int str_to_dtime (char *line, double *second) {402 403 switch (chk_time (line)) {404 case 0:405 case TIME_JD:406 case TIME_MJD:407 case TIME_DATE:408 return (FALSE);409 case TIME_DAYS:410 *second = strtod (line, 0) * 86400.0;411 return (TRUE);412 case TIME_HOURS:413 *second = strtod (line, 0) * 3600.0;414 return (TRUE);415 case TIME_MINUTES:416 *second = strtod (line, 0) * 60.0;417 return (TRUE);418 case TIME_SECONDS:419 *second = strtod (line, 0);420 return (TRUE);421 }422 return (FALSE);423 }424 425 /**********/426 double sec_to_jd (time_t second) {427 428 double jd;429 430 jd = second/86400.0 + 2440587.5;431 return (jd);432 }433 434 /**********/435 time_t jd_to_sec (double jd) {436 437 time_t second;438 439 second = (jd - 2440587.5)*86400;440 return (second);441 }442 443 /**********/444 double sec_to_mjd (time_t second) {445 446 double mjd;447 448 mjd = second/86400.0 + 40587.0;449 return (mjd);450 }451 452 /**********/453 time_t mjd_to_sec (double mjd) {454 455 time_t second;456 457 second = (mjd - 40587.0)*86400;458 return (second);459 }460 461 /**********/462 char *sec_to_date (time_t second) {463 464 struct tm *gmt;465 char *line;466 467 ALLOCATE (line, char, 64);468 gmt = gmtime (&second);469 sprintf (line, "%04d/%02d/%02d,%02d:%02d:%02d",470 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday,471 gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);472 return (line);473 474 }475 476 /***** date in format yyyy/mm/dd,hh:mm:ss *****/477 time_t date_to_sec (char *date) {478 479 time_t second;480 double tmp, jd;481 struct tm now;482 char *p1, *p2, *px;483 484 p1 = date;485 px = date + strlen(date);486 bzero (&now, sizeof(now));487 488 tmp = strtod (p1, &p2);489 if (p2 == p1) goto escape;490 now.tm_year = tmp;491 if (now.tm_year > 1000) now.tm_year -= 1900;492 if (now.tm_year < 50) now.tm_year += 100;493 if (p2 == px) goto escape;494 p1 = p2 + 1;495 496 tmp = strtod (p1, &p2);497 if (p2 == p1) goto escape;498 now.tm_mon = tmp - 1; /* mon runs from 0 - 11 */499 if (p2 == px) goto escape;500 p1 = p2 + 1;501 502 tmp = strtod (p1, &p2);503 if (p2 == p1) goto escape;504 now.tm_mday = tmp;505 if (p2 == px) goto escape;506 p1 = p2 + 1;507 508 tmp = strtod (p1, &p2);509 if (p2 == p1) goto escape;510 p1 = p2 + 1;511 now.tm_hour = tmp;512 if (p2 == px) goto escape;513 514 tmp = strtod (p1, &p2);515 if (p2 == p1) goto escape;516 now.tm_min = tmp;517 if (p2 == px) goto escape;518 p1 = p2 + 1;519 520 tmp = strtod (p1, &p2);521 if (p2 == p1) goto escape;522 now.tm_sec = tmp;523 if (p2 == px) goto escape;524 p1 = p2 + 1;525 526 escape:527 jd = now.tm_mday - 32075 + (int)(1461*(1900 + now.tm_year + 4800 + (int)(((now.tm_mon+1)-14)/12))/4)528 + (int)(367*((now.tm_mon+1) - 2 - (int)(((now.tm_mon+1) - 14)/12)*12)/12)529 - (int)(3*(int)((1900 + now.tm_year + 4900 + (int)(((now.tm_mon+1) - 14)/12))/100)/4) - 0.5;530 531 second = (jd - 2440587.5)*86400 + 3600.0*now.tm_hour + now.tm_min*60.0 + now.tm_sec;532 533 return (second);534 }535 536 218 /* convert UNIX time to a value referenced to the TimeReference in the given unit */ 537 219 double TimeValue (time_t time, time_t TimeReference, int TimeFormat) { … … 599 281 600 282 /* times may be in forms as: 601 20040200450s (N seconds since 1970.0) 602 2440900.232j (julian date) 603 99/02/23,03:22:18 (date string) 604 (separators may be anything except space, +, -) 605 99:02:15:12:23:30 606 99:02:15:12h23m30s 607 */ 283 * 20040200450s (N seconds since 1970.0) 284 * 2440900.232j (julian date) 285 * 99/02/23,03:22:18 (date string) 286 * (separators may be anything except space, +, -) 287 * 99:02:15:12:23:30 288 * 99:02:15:12h23m30s 289 */ 290
Note:
See TracChangeset
for help on using the changeset viewer.
