Changeset 19681
- Timestamp:
- Sep 23, 2008, 10:05:34 AM (18 years ago)
- Location:
- trunk/Ohana/src/skycalc
- Files:
-
- 4 added
- 12 edited
-
Makefile (modified) (2 diffs)
-
README (added)
-
doc/Thorstensen.txt (added)
-
doc/skycalc.c (added)
-
include/skycalc.h (modified) (1 diff)
-
include/skycalc_internal.h (modified) (2 diffs)
-
src/astro.c (modified) (7 diffs)
-
src/dusktime.c (modified) (3 diffs)
-
src/geometry.c (modified) (7 diffs)
-
src/moon.c (modified) (18 diffs)
-
src/moondata.c (modified) (3 diffs)
-
src/skylib.c (modified) (1 diff)
-
src/sun.c (modified) (12 diffs)
-
src/sundata.c (modified) (3 diffs)
-
src/sunmoon.c (added)
-
src/time.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/skycalc/Makefile
r12842 r19681 1 default: skycalc1 default: install 2 2 help: 3 @echo "make options: (default)"3 @echo "make options: install libskycalc all programs clean dist" 4 4 5 5 include ../../Makefile.System … … 13 13 14 14 # programs may add their own internal requirements here 15 FULL_CFLAGS = $(BASE_CFLAGS) 15 FULL_CFLAGS = $(BASE_CFLAGS) -fPIC 16 16 FULL_CPPFLAGS = $(BASE_CPPFLAGS) 17 FULL_LDFLAGS = $(BASE_LDFLAGS) 17 FULL_LDFLAGS = $(BASE_LDFLAGS) -lskycalc -lohana 18 18 19 skycalc: $(DESTLIB)/libskycalc.a20 19 install: $(DESTINC)/skycalc.h $(DESTLIB)/libskycalc.a 20 libskycalc: $(DESTLIB)/libskycalc.a $(DESTLIB)/libskycalc.$(DLLTYPE) 21 21 22 all: moondata dusktime sundata 22 all: libskycalc dusktime moondata sundata 23 programs: all 23 24 24 OBJ = $(SRC)/time.$(ARCH).o $(SRC)/geometry.$(ARCH).o \ 25 $(SRC)/astro.$(ARCH).o $(SRC)/sun.$(ARCH).o \ 26 $(SRC)/moon.$(ARCH).o 25 INCS = $(DESTINC)/skycalc.h 27 26 28 $(OBJ): $(INC)/skycalc.h$(INC)/skycalc_internal.h27 MYINCS = $(INCS) $(INC)/skycalc_internal.h 29 28 30 $(LIB)/libskycalc.$(ARCH).a: $(OBJ) 31 @if [ ! -d $(LIB) ]; then mkdir -p $(LIB); fi 32 rm -f $(LIB)/libskycalc.$(ARCH).a 33 ar rcv $(LIB)/libskycalc.$(ARCH).a $(OBJ) 34 $(RANLIB) $(LIB)/libskycalc.$(ARCH).a 29 OBJS = \ 30 $(SRC)/time.$(ARCH).o \ 31 $(SRC)/geometry.$(ARCH).o \ 32 $(SRC)/astro.$(ARCH).o \ 33 $(SRC)/sun.$(ARCH).o \ 34 $(SRC)/moon.$(ARCH).o 35 35 36 $(DESTLIB)/libskycalc.a: $(LIB)/libskycalc.$(ARCH).a 37 @if [ ! -d $(DESTLIB) ]; then mkdir -p $(DESTLIB); fi 38 rm -f $(DESTLIB)/libskycalc.a 39 cp $(LIB)/libskycalc.$(ARCH).a $(DESTLIB)/libskycalc.a 36 $(OBJS): $(MYINCS) 40 37 41 $(DESTINC)/skycalc.h: $(INC)/skycalc.h 42 @if [ ! -d $(DESTINC) ]; then mkdir -p $(DESTINC); fi 43 rm -f $(DESTINC)/skycalc.h 44 cp $(INC)/skycalc.h $(DESTINC)/ 38 $(LIB)/libskycalc.$(ARCH).a: $(OBJS) 39 $(LIB)/libskycalc.$(ARCH).$(DLLTYPE): $(OBJS) 45 40 46 test: 47 $(CC) $(CCFLAGS) -g -o skylib $(SRC)/skylib.c -lskycalc -lm 41 $(DESTLIB)/libskycalc.a: $(LIB)/libskycalc.$(ARCH).a 42 $(DESTLIB)/libskycalc.$(DLLTYPE): $(LIB)/libskycalc.$(ARCH).$(DLLTYPE) 48 43 49 dusktime: skycalc 50 @if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi 51 @if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi 52 $(CC) $(CCFLAGS) -g -o $(BIN)/dusktime.$(ARCH) $(SRC)/dusktime.c -lskycalc -lm -lohana 53 cp $(BIN)/dusktime.$(ARCH) $(DESTBIN)/dusktime 44 dusktime : $(BIN)/dusktime.$(ARCH) 45 moondata : $(BIN)/moondata.$(ARCH) 46 sundata : $(BIN)/sundata.$(ARCH) 47 sunmoon : $(BIN)/sunmoon.$(ARCH) 54 48 55 moondata: skycalc 56 @if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi 57 @if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi 58 $(CC) $(CCFLAGS) -g -o $(BIN)/moondata.$(ARCH) $(SRC)/moondata.c -lskycalc -lm -lohana 59 cp $(BIN)/moondata.$(ARCH) $(DESTBIN)/moondata 49 DUSKTIME = $(SRC)/dusktime.$(ARCH).o 50 MOONDATA = $(SRC)/moondata.$(ARCH).o 51 SUNDATA = $(SRC)/sundata.$(ARCH).o 52 SUNMOON = $(SRC)/sunmoon.$(ARCH).o 60 53 61 sundata: skycalc 62 @if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi 63 @if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi 64 $(CC) $(CCFLAGS) -g -o $(BIN)/sundata.$(ARCH) $(SRC)/sundata.c -lskycalc -lm -lohana 65 cp $(BIN)/sundata.$(ARCH) $(DESTBIN)/sundata 54 $(DUSKTIME) : $(MYINCS) 55 $(MOONDATA) : $(MYINCS) 56 $(SUNDATA) : $(MYINCS) 57 $(SUNMOON) : $(MYINCS) 66 58 67 clean: 68 rm -f `find . -name "*.o"` 69 rm -f `find . -name "*.a"` 70 rm -f `find . -name "*~"` 71 rm -f `find . -name "#*"` 59 $(BIN)/dusktime.$(ARCH) : $(DUSKTIME) 60 $(BIN)/moondata.$(ARCH) : $(MOONDATA) 61 $(BIN)/sundata.$(ARCH) : $(SUNDATA) 62 $(BIN)/sunmoon.$(ARCH) : $(SUNMOON) 72 63 73 .SUFFIXES: .$(ARCH).o 64 INSTALL = dusktime moondata sundata sunmoon 74 65 75 .c.$(ARCH).o: 76 $(CC) $(CFLAGS) -c $< 66 # dependancy rules for binary code ######################### 67 $(INSTALL): % : $(BIN)/%.$(ARCH) 77 68 69 %.clean : 70 rm -f $(BIN)/$*.$(ARCH) 71 72 %.install: 73 make $(DESTBIN)/$* 74 75 install: 76 for i in $(INSTALL); do make $$i.install || exit; done -
trunk/Ohana/src/skycalc/include/skycalc.h
r2496 r19681 1 2 /* This is the header file for the Ohana version of 'libskycalc'. This library is based on the 3 * code provided to the community by John Thorstensen. See the discussion in the README file 4 * and in the file doc/Thorstensen.txt 5 */ 1 6 2 7 /* header for skycalc library function calls */ -
trunk/Ohana/src/skycalc/include/skycalc_internal.h
r3263 r19681 1 /* header for use by the skycalc library files and stand-alone programs, not needed for external calls */ 1 2 2 /* header for use by the skycalc library files, not needed for external calls */3 4 # include <skycalc.h>5 3 # include <stdio.h> 6 4 # include <math.h> 7 # include <ctype.h> 8 # include <stdarg.h> 9 # include <string.h> 5 # include <stdlib.h> 10 6 # include <time.h> 11 12 /* a couple of the system-dependent magic numbers are defined here */ 13 14 #define SYS_CLOCK_OK 1 /* 1 means ANSI-standard time libraries do work, 15 2 means they don't. This is used by compiler switches in file 5 and 16 the main program. */ 17 18 #define LOG_FILES_OK 1 /* 1 means that log files are enabled. 19 Any other value means they're not. */ 20 21 #define MAX_OBJECTS 500 22 #define MINSHORT -32767 /* min, max short integers and double precision */ 23 #define MAXSHORT 32767 24 #define MAXDOUBLE 1.0e38 25 #define MINDOUBLE -1.0e38 26 #define BUFSIZE 150 7 # include <skycalc.h> 27 8 28 9 /* some (not all) physical, mathematical, and astronomical constants … … 44 25 #define PLANET_TOL 3. /* flag if nearer than 3 degrees 45 26 to a major planet ... */ 46 #define KZEN 0.172 /* zenith extinction, mag, for use47 in lunar sky brightness calculations. */48 #define FIRSTJD 2415387. /* 1901 Jan 1 -- calendrical limit */49 #define LASTJD 2488070. /* 2099 Dec 31 */50 27 51 /* MAGIC NUMBERS which might depend on how accurately double- 52 precision floating point is handled on your machine ... */ 28 # define dCOS(A) ((double) cos ((double)RAD_DEG*A)) 29 # define dSIN(A) ((double) sin ((double)RAD_DEG*A)) 53 30 54 #define EARTH_DIFF 0.05 /* used in numerical 55 differentiation to find earth velocity -- this value gives 56 about 8 digits of numerical accuracy on the VAX, but is 57 about 3 orders of magnitude larger than the value where roundoff 58 errors become apparent. */ 31 /** prototypes of private functions used by the library **/ 59 32 60 #define MIDN_TOL 0.00001 /* this is no longer 61 used -- it was formerly 62 how close (in days) a julian date has to be to midnight 63 before a warning flag is printed for the reader. VAX 64 double precision renders a Julian date considerably 65 more accurately than this. The day and date are now based 66 on the same rounding of the julian date, so they should 67 always agree. */ 33 /* in time.c */ 34 int SC_get_sys_date (struct SC_date_time *date); 35 double SC_date_to_jd (struct SC_date_time date); 36 void SC_jd_to_date (double jdin, struct SC_date_time *date); 37 double SC_lst (double jd, double longit); 38 double SC_adj_time (double x); 68 39 69 /** prototypes **/ 70 int get_sys_date (struct SC_date_time *date); 71 double date_to_jd (struct SC_date_time date); 72 void jd_to_date (double jdin, struct SC_date_time *date); 73 double lst (double jd, double longit); 74 double adj_time (double x); 75 void xyz_cel (double x, double y, double z, double *r, double *d); 76 double atan_circ (double x, double y); 77 double altit (double dec, double ha, double lat, double *az); 78 double ha_alt (double dec, double lat, double alt); 79 void min_max_alt (double lat, double dec, double *min, double *max); 80 double circulo (double x); 81 void precrot (double rorig, double dorig, double orig_epoch, double final_epoch, double *rf, double *df); 82 void geocent (double geolong, double geolat, double height, double *x_geo, double *y_geo, double *z_geo); 83 void eclrot(double jd, double *x, double *y, double *z); 84 double etcorr (double jd); 85 void set_zenith (struct SC_date_time date, double lat, double longit, double epoch, double *ra, double *dec); 86 void lpsun (double jd, double *ra, double *dec); 87 double jd_sun_alt (double alt, double jdguess, double lat, double longit); 88 void accumoon (double jd, double geolat, double lst, double elevsea, 89 double *geora, double *geodec, double *geodist, 90 double *topora, double *topodec, double *topodist); 91 double jd_moon_alt (double alt, double jdguess, double lat, double longit, double elevsea); 40 /* in geometry.c */ 41 void SC_xyz_cel (double x, double y, double z, double *r, double *d); 42 double SC_atan_circ (double x, double y); 43 double SC_altit (double dec, double ha, double lat, double *az); 44 double SC_ha_alt (double dec, double lat, double alt); 45 void SC_min_max_alt (double lat, double dec, double *min, double *max); 46 double SC_circulo (double x); 92 47 93 double sunset_tonight (struct SC_date_time date, double lat, double longit, double elev); 94 double sunrise_tonight (struct SC_date_time date, double lat, double longit, double elev); 48 /* in astro.c */ 49 void SC_precrot (double rorig, double dorig, double orig_epoch, double final_epoch, double *rf, double *df); 50 void SC_geocent (double geolong, double geolat, double height, double *x_geo, double *y_geo, double *z_geo); 51 void SC_eclrot(double jd, double *x, double *y, double *z); 52 double SC_etcorr (double jd); 53 void SC_set_zenith (struct SC_date_time date, double lat, double longit, double epoch, double *ra, double *dec); 95 54 96 int dms_to_ddd (double *Value, char *string); 97 int str_to_radec (double *ra, double *dec, char *str1, char *str2); 98 int chk_time (char *line); 99 double sec_to_jd (time_t second); 100 time_t jd_to_sec (double jd); 101 char *sec_to_date (time_t second); 102 time_t date_to_sec (char *date); 103 int str_to_time (char *line, time_t *second); 104 int str_to_dtime (char *line, double *second); 55 /* in sun.c */ 56 void SC_lpsun (double jd, double *ra, double *dec); 57 double SC_jd_sun_alt (double alt, double jdguess, double lat, double longit); 58 double SC_sunset_tonight (struct SC_date_time date, double lat, double longit, double elev); 59 double SC_sunrise_tonight (struct SC_date_time date, double lat, double longit, double elev); 60 61 /* in moon.c */ 62 void SC_lpmoon(double jd, double lat, double sid, double* ra, double* dec, double* dist); 63 void SC_accumoon (double jd, double geolat, double lst, double elevsea, double *geora, double *geodec, double *geodist, double *topora, double *topodec, double *topodist); 64 double SC_jd_moon_alt (double alt, double jdguess, double lat, double longit, double elevsea); 65 double SC_moonset_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev); 66 double SC_moonrise_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev); 67 68 // are these defined in here or in libohana? 69 // int dms_to_ddd (double *Value, char *string); 70 // int str_to_radec (double *ra, double *dec, char *str1, char *str2); 71 // int chk_time (char *line); 72 // double sec_to_jd (time_t second); 73 // time_t jd_to_sec (double jd); 74 // char *sec_to_date (time_t second); 75 // time_t date_to_sec (char *date); 76 // int str_to_time (char *line, time_t *second); 77 // int str_to_dtime (char *line, double *second); -
trunk/Ohana/src/skycalc/src/astro.c
r2496 r19681 9 9 system. Angles in degrees, epochs in years */ 10 10 11 void precrot (double rorig, double dorig, double orig_epoch, double final_epoch, double *rf, double *df) {11 void SC_precrot (double rorig, double dorig, double orig_epoch, double final_epoch, double *rf, double *df) { 12 12 13 13 double ti, tf, zeta, z, theta; /* all as per Taff */ … … 72 72 /* convert back to spherical polar coords */ 73 73 74 xyz_cel(fin_x, fin_y, fin_z, rf, df);74 SC_xyz_cel(fin_x, fin_y, fin_z, rf, df); 75 75 76 76 } … … 83 83 p. K11 */ 84 84 85 void geocent (double geolong, double geolat, double height, double *x_geo, double *y_geo, double *z_geo) {85 void SC_geocent (double geolong, double geolat, double height, double *x_geo, double *y_geo, double *z_geo) { 86 86 87 87 double denom, C_geo, S_geo; … … 103 103 /* rotates ecliptic rectangular coords x, y, z to 104 104 equatorial (all assumed of date.) */ 105 void eclrot(double jd, double *x, double *y, double *z) {105 void SC_eclrot(double jd, double *x, double *y, double *z) { 106 106 107 107 double incl; … … 139 139 usually rather smaller. */ 140 140 141 double etcorr (double jd) {141 double SC_etcorr (double jd) { 142 142 143 143 double jd1900 = 2415019.5; … … 173 173 174 174 /* sets RA and DEC at zenith as defined by given time and date */ 175 void set_zenith (struct SC_date_time date, double lat, double longit, double epoch, double *ra, double *dec)175 void SC_set_zenith (struct SC_date_time date, double lat, double longit, double epoch, double *ra, double *dec) 176 176 { 177 177 double jd, current_epoch; 178 178 179 jd = date_to_jd (date);179 jd = SC_date_to_jd (date); 180 180 181 181 if (jd < 0.) return; /* nonexistent time. */ 182 182 183 *ra = lst (jd, longit);183 *ra = SC_lst (jd, longit); 184 184 185 185 *dec = lat; … … 187 187 current_epoch = 2000. + (jd - J2000) / 365.25; 188 188 189 precrot (*ra,*dec,current_epoch,epoch,ra,dec);189 SC_precrot (*ra,*dec,current_epoch,epoch,ra,dec); 190 190 191 191 } -
trunk/Ohana/src/skycalc/src/dusktime.c
r3263 r19681 1 # include <stdio.h>2 # include <math.h>3 1 # include <skycalc_internal.h> 2 # include <ohana.h> 4 3 # define VERBOSE 0 5 4 6 void set_site (double *longit, double *lat, double *elevsea, double *elev) { 5 // XXX is this set for MKO?? 6 void SC_set_site (double *longit, double *lat, double *elevsea, double *elev) { 7 7 8 8 *longit = 10.36478; /* W longitude in decimal hours */ … … 26 26 } 27 27 28 if (! str_to_time (argv[1], &tzero)) {28 if (!ohana_str_to_time (argv[1], &tzero)) { 29 29 fprintf (stderr, "syntax error\n"); 30 30 exit (1); … … 40 40 if (VERBOSE) fprintf (stderr, "%4d/%02d/%02d %02d:%02d:%02f\n", date.y, date.mo, date.d, date.h, date.mn, date.s); 41 41 42 set_site (&longit, &lat, &elevsea, &elev);42 SC_set_site (&longit, &lat, &elevsea, &elev); 43 43 44 jdnow = date_to_jd (date);45 jdset = sunset_tonight (date, lat, longit, elev);46 jdrise = sunrise_tonight (date, lat, longit, elev);44 jdnow = SC_date_to_jd (date); 45 jdset = SC_sunset_tonight (date, lat, longit, elev); 46 jdrise = SC_sunrise_tonight (date, lat, longit, elev); 47 47 48 48 -
trunk/Ohana/src/skycalc/src/geometry.c
r2496 r19681 2 2 3 3 /* converts a coordinate triplet back to a standard ra and dec */ 4 void xyz_cel (double x, double y, double z, double *r, double *d) {4 void SC_xyz_cel (double x, double y, double z, double *r, double *d) { 5 5 6 6 /* converts a coordinate triplet back to a standard ra and dec */ … … 48 48 } 49 49 50 /* returns radian angle 0 to 2pi for coords x, y -- get that quadrant right !! */ 51 double atan_circ (double x, double y) { 50 /* returns radian angle 0 to 2pi for coords x, y -- get that quadrant nright !! */ 51 /* XXX : reimplements atan2() */ 52 double SC_atan_circ (double x, double y) { 52 53 53 54 double theta; … … 66 67 /* returns altitude(degr) for dec, ha, lat (decimal degr, hr, degr); 67 68 also computes and returns azimuth through pointer argument. */ 68 double altit (double dec, double ha, double lat, double *az) {69 double SC_altit (double dec, double ha, double lat, double *az) { 69 70 70 71 double x,y,z; … … 76 77 y = sin(dec)*cos(lat) - cos(dec)*cos(ha)*sin(lat); /* due N comp. */ 77 78 z = -1. * cos(dec)*sin(ha); /* due east comp. */ 78 *az = atan_circ(y,z) * DEG_IN_RADIAN;79 *az = SC_atan_circ(y,z) * DEG_IN_RADIAN; 79 80 return(x); 80 81 } … … 83 84 If object is never at this altitude, signals with special 84 85 return values 1000 (always higher) and -1000 (always lower). */ 85 double ha_alt (double dec, double lat, double alt) {86 double SC_ha_alt (double dec, double lat, double alt) { 86 87 87 88 double x,coalt,min,max; 88 89 89 min_max_alt(lat,dec,&min,&max);90 SC_min_max_alt(lat,dec,&min,&max); 90 91 if(alt < min) 91 92 return(1000.); /* flag value - always higher than asked */ … … 104 105 105 106 /* computes minimum and maximum altitude for a given dec and latitude. */ 106 void min_max_alt (double lat, double dec, double *min, double *max) {107 void SC_min_max_alt (double lat, double dec, double *min, double *max) { 107 108 108 109 double x; … … 124 125 125 126 /* force domain to be 0 - 360 degrees */ 126 double circulo (double x) {127 double SC_circulo (double x) { 127 128 128 129 /* fails for negative angles! */ -
trunk/Ohana/src/skycalc/src/moon.c
r2496 r19681 1 1 # include <skycalc_internal.h> 2 2 3 void lpmoon(double jd, double lat, double sid,3 void SC_lpmoon(double jd, double lat, double sid, 4 4 double* ra, double* dec, double* dist) { 5 5 … … 68 68 n = z / topo_dist; 69 69 70 alpha = atan_circ(l,m);70 alpha = SC_atan_circ(l,m); 71 71 delta = asin(n); 72 72 … … 83 83 pub. Willman-Bell. Includes all the terms given there. */ 84 84 85 void accumoon (jd,geolat,lst,elevsea,geora,geodec,geodist,topora,topodec,topodist)85 void SC_accumoon (jd,geolat,lst,elevsea,geora,geodec,geodist,topora,topodec,topodist) 86 86 double jd,geolat,lst,elevsea; 87 87 double *geora,*geodec,*geodist,*topora,*topodec,*topodist; … … 93 93 double x_geo, y_geo, z_geo; /* geocentric position of *observer* */ 94 94 95 jd = jd + etcorr(jd)/SEC_IN_DAY; /* approximate correction to ephemeris time */95 jd = jd + SC_etcorr(jd)/SEC_IN_DAY; /* approximate correction to ephemeris time */ 96 96 T = (jd - 2415020.) / 36525.; /* this based around 1900 ... */ 97 97 Tsq = T * T; … … 111 111 + 0.0000022*Tcb; 112 112 113 Lpr = circulo(Lpr);114 Mpr = circulo(Mpr);115 M = circulo(M);116 D = circulo(D);117 F = circulo(F);118 Om = circulo(Om);113 Lpr = SC_circulo(Lpr); 114 Mpr = SC_circulo(Mpr); 115 M = SC_circulo(M); 116 D = SC_circulo(D); 117 F = SC_circulo(F); 118 Om = SC_circulo(Om); 119 119 120 120 … … 292 292 m = sin(lambda) * cos(beta); 293 293 n = sin(beta); 294 eclrot(jd,&l,&m,&n);294 SC_eclrot(jd,&l,&m,&n); 295 295 296 296 dist = 1/sin((pie)/DEG_IN_RADIAN); … … 299 299 z = n * dist; 300 300 301 *geora = atan_circ(l,m) * HRS_IN_RADIAN;301 *geora = SC_atan_circ(l,m) * HRS_IN_RADIAN; 302 302 *geodec = asin(n) * DEG_IN_RADIAN; 303 303 *geodist = dist; 304 304 305 geocent (lst, geolat, elevsea, &x_geo, &y_geo, &z_geo);305 SC_geocent (lst, geolat, elevsea, &x_geo, &y_geo, &z_geo); 306 306 307 307 x = x - x_geo; /* topocentric correction using elliptical earth fig. */ … … 315 315 n = z / (*topodist); 316 316 317 *topora = atan_circ(l,m) * HRS_IN_RADIAN;317 *topora = SC_atan_circ(l,m) * HRS_IN_RADIAN; 318 318 *topodec = asin(n) * DEG_IN_RADIAN; 319 319 … … 326 326 you can replace calls to 'accumoon' with 'lpmoon' and remove 327 327 the 'elevsea' argument. */ 328 double jd_moon_alt (double alt, double jdguess, double lat, double longit, double elevsea) {328 double SC_jd_moon_alt (double alt, double jdguess, double lat, double longit, double elevsea) { 329 329 330 330 double jdout; … … 335 335 /* first guess */ 336 336 337 sid= lst(jdguess,longit);338 accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist,337 sid=SC_lst(jdguess,longit); 338 SC_accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist, 339 339 &ra,&dec,&dist); 340 ha = lst(jdguess,longit) - ra;341 alt2 = altit(dec,ha,lat,&az);340 ha = SC_lst(jdguess,longit) - ra; 341 alt2 = SC_altit(dec,ha,lat,&az); 342 342 jdguess = jdguess + del; 343 sid = lst(jdguess,longit);344 accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist,343 sid = SC_lst(jdguess,longit); 344 SC_accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist, 345 345 &ra,&dec,&dist); 346 alt3 = altit(dec,(sid - ra),lat,&az);346 alt3 = SC_altit(dec,(sid - ra),lat,&az); 347 347 err = alt3 - alt; 348 348 deriv = (alt3 - alt2) / del; 349 349 while((fabs(err) > 0.1) && (i < 10)) { 350 350 jdguess = jdguess - err/deriv; 351 sid= lst(jdguess,longit);352 accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist,351 sid=SC_lst(jdguess,longit); 352 SC_accumoon(jdguess,lat,sid,elevsea,&geora,&geodec,&geodist, 353 353 &ra,&dec,&dist); 354 alt3 = altit(dec,(sid - ra),lat,&az);354 alt3 = SC_altit(dec,(sid - ra),lat,&az); 355 355 err = alt3 - alt; 356 356 i++; … … 362 362 363 363 /* Given site position, return Moonset for closest midnight */ 364 double moonset_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev) {364 double SC_moonset_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev) { 365 365 366 366 double jd, jdmid, stmid; … … 376 376 377 377 /* find offset in hours from longit to greenwich */ 378 jd = date_to_jd (date); /* true jd now */379 lst0 = lst (jd, 0.0); /* lst at long = 0 */380 lst1 = lst (jd, longit); /* local lst now */378 jd = SC_date_to_jd (date); /* true jd now */ 379 lst0 = SC_lst (jd, 0.0); /* lst at long = 0 */ 380 lst1 = SC_lst (jd, longit); /* local lst now */ 381 381 dt = lst0 - lst1; 382 382 if (dt < 0) dt += 24; … … 389 389 390 390 /* find jd for local midnight, select the *closest* midnight */ 391 jdmid = date_to_jd (date_midnight) - dt / 24.0;391 jdmid = SC_date_to_jd (date_midnight) - dt / 24.0; 392 392 djd = jd - jdmid; 393 393 if (djd < -0.5) jdmid -= 1.0; 394 394 if (djd > 0.5) jdmid += 1.0; 395 stmid = lst (jdmid,longit);396 397 accumoon (jdmid,lat,stmid,elevsea,&geora,&geodec,&geodist,&ramoon,&decmoon,&distmoon);398 399 min_max_alt (lat,decmoon,&min_alt,&max_alt); /* rough check -- occurs? */395 stmid = SC_lst (jdmid,longit); 396 397 SC_accumoon (jdmid,lat,stmid,elevsea,&geora,&geodec,&geodist,&ramoon,&decmoon,&distmoon); 398 399 SC_min_max_alt (lat,decmoon,&min_alt,&max_alt); /* rough check -- occurs? */ 400 400 if (max_alt < -(0.83+horiz)) return (-1); 401 401 if (min_alt > -(0.83+horiz)) return (-1); … … 403 403 /* compute moonrise and set if they're likely to occur */ 404 404 405 hamoonset = ha_alt(decmoon,lat,-(0.83+horiz)); /* rough approx. */406 407 tmoonset = adj_time(ramoon+hamoonset-stmid);405 hamoonset = SC_ha_alt(decmoon,lat,-(0.83+horiz)); /* rough approx. */ 406 407 tmoonset = SC_adj_time(ramoon+hamoonset-stmid); 408 408 jdmoonset = jdmid + tmoonset / 24.; 409 jdmoonset = jd_moon_alt(-(0.83+horiz),jdmoonset,lat,longit,elevsea);409 jdmoonset = SC_jd_moon_alt(-(0.83+horiz),jdmoonset,lat,longit,elevsea); 410 410 411 411 return (jdmoonset); … … 414 414 415 415 /* Given site position, return Moonrise for closest midnight */ 416 double moonrise_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev) {416 double SC_moonrise_tonight (struct SC_date_time date, double lat, double longit, double elevsea, double elev) { 417 417 418 418 double jd, jdmid, stmid; … … 428 428 429 429 /* find offset in hours from longit to greenwich */ 430 jd = date_to_jd (date); /* true jd now */431 lst0 = lst (jd, 0.0); /* lst at long = 0 */432 lst1 = lst (jd, longit); /* local lst now */430 jd = SC_date_to_jd (date); /* true jd now */ 431 lst0 = SC_lst (jd, 0.0); /* lst at long = 0 */ 432 lst1 = SC_lst (jd, longit); /* local lst now */ 433 433 dt = lst0 - lst1; 434 434 if (dt < 0) dt += 24; … … 441 441 442 442 /* find jd for local midnight, select the *closest* midnight */ 443 jdmid = date_to_jd (date_midnight) - dt / 24.0;443 jdmid = SC_date_to_jd (date_midnight) - dt / 24.0; 444 444 djd = jd - jdmid; 445 445 if (djd < -0.5) jdmid -= 1.0; 446 446 if (djd > 0.5) jdmid += 1.0; 447 stmid = lst (jdmid,longit);448 449 accumoon (jdmid,lat,stmid,elevsea,&geora,&geodec,&geodist,&ramoon,&decmoon,&distmoon);450 451 min_max_alt (lat,decmoon,&min_alt,&max_alt); /* rough check -- occurs? */447 stmid = SC_lst (jdmid,longit); 448 449 SC_accumoon (jdmid,lat,stmid,elevsea,&geora,&geodec,&geodist,&ramoon,&decmoon,&distmoon); 450 451 SC_min_max_alt (lat,decmoon,&min_alt,&max_alt); /* rough check -- occurs? */ 452 452 if (max_alt < -(0.83+horiz)) return (-1); 453 453 if (min_alt > -(0.83+horiz)) return (-1); … … 455 455 /* compute moonrise and set if they're likely to occur */ 456 456 457 hamoonset = ha_alt(decmoon,lat,-(0.83+horiz)); /* rough approx. */458 459 tmoonrise = adj_time(ramoon-hamoonset-stmid);457 hamoonset = SC_ha_alt(decmoon,lat,-(0.83+horiz)); /* rough approx. */ 458 459 tmoonrise = SC_adj_time(ramoon-hamoonset-stmid); 460 460 jdmoonrise = jdmid + tmoonrise / 24.; 461 jdmoonrise = jd_moon_alt(-(0.83+horiz),jdmoonrise,lat,longit,elevsea);461 jdmoonrise = SC_jd_moon_alt(-(0.83+horiz),jdmoonrise,lat,longit,elevsea); 462 462 463 463 return (jdmoonrise); -
trunk/Ohana/src/skycalc/src/moondata.c
r3263 r19681 1 # include <stdio.h>2 # include <math.h>3 1 # include <skycalc_internal.h> 2 # include <ohana.h> 3 # define VERBOSE 0 4 4 5 # define DEG_RAD 57.295779513082322 6 # define RAD_DEG 0.017453292519943 7 8 double atof(); 9 10 void set_site (double *longit, double *lat, double *elevsea, double *elev) { 5 void SC_set_site (double *longit, double *lat, double *elevsea, double *elev) { 11 6 12 7 *longit = 10.36478; /* W longitude in decimal hours */ … … 36 31 DECo = atof (argv[3]); 37 32 38 if (! str_to_time (argv[1], &tzero)) {33 if (!ohana_str_to_time (argv[1], &tzero)) { 39 34 fprintf (stderr, "syntax error\n"); 40 35 exit (1); … … 52 47 */ 53 48 54 set_site (&longit, &lat, &elevsea, &elev);55 jdnow = date_to_jd (date);49 SC_set_site (&longit, &lat, &elevsea, &elev); 50 jdnow = SC_date_to_jd (date); 56 51 /* Calcualte local sidereal time */ 57 sid = lst(jdnow, longit);58 lpsun (jdnow, &Rsun, &Dsun);52 sid = SC_lst(jdnow, longit); 53 SC_lpsun (jdnow, &Rsun, &Dsun); 59 54 60 accumoon(jdnow,lat,sid,elevsea,&geora,&geodec,&geodist,&ra,&dec,&dist);55 SC_accumoon(jdnow,lat,sid,elevsea,&geora,&geodec,&geodist,&ra,&dec,&dist); 61 56 62 57 /* fprintf (stdout, "moon @ %f %f\n", 15*ra, dec); */ -
trunk/Ohana/src/skycalc/src/skylib.c
r2496 r19681 20 20 double jd; 21 21 22 set_site (&longit, &lat, &elevsea, &elev);23 get_sys_date (&date);22 SC_set_site (&longit, &lat, &elevsea, &elev); 23 SC_get_sys_date (&date); 24 24 25 jd = sunset_tonight (date, lat, longit, elev);25 jd = SC_sunset_tonight (date, lat, longit, elev); 26 26 fprintf (stderr, "Sunset (%5.0f m horizon): %f\n", elev, jd); 27 jd_to_date (jd, &tmpdate);27 SC_jd_to_date (jd, &tmpdate); 28 28 fprintf (stderr, "%4d/%02d/%02d %02d:%02d:%02f\n", tmpdate.y, tmpdate.mo, tmpdate.d, tmpdate.h, tmpdate.mn, tmpdate.s); 29 29 30 jd = sunrise_tonight (date, lat, longit, elev);30 jd = SC_sunrise_tonight (date, lat, longit, elev); 31 31 fprintf (stderr, "Sunrise (%5.0f m horizon): %f\n", elev, jd); 32 jd_to_date (jd, &tmpdate);32 SC_jd_to_date (jd, &tmpdate); 33 33 fprintf (stderr, "%4d/%02d/%02d %02d:%02d:%02f\n", tmpdate.y, tmpdate.mo, tmpdate.d, tmpdate.h, tmpdate.mn, tmpdate.s); 34 34 35 35 36 jd = moonset_tonight (date, lat, longit, elevsea, elev);36 jd = SC_moonset_tonight (date, lat, longit, elevsea, elev); 37 37 fprintf (stderr, "Moonset (%5.0f m horizon): %f\n", elev, jd); 38 jd_to_date (jd, &tmpdate);38 SC_jd_to_date (jd, &tmpdate); 39 39 fprintf (stderr, "%4d/%02d/%02d %02d:%02d:%02f\n", tmpdate.y, tmpdate.mo, tmpdate.d, tmpdate.h, tmpdate.mn, tmpdate.s); 40 40 41 jd = moonrise_tonight (date, lat, longit, elevsea, elev);41 jd = SC_moonrise_tonight (date, lat, longit, elevsea, elev); 42 42 fprintf (stderr, "Moonrise (%5.0f m horizon): %f\n", elev, jd); 43 jd_to_date (jd, &tmpdate);43 SC_jd_to_date (jd, &tmpdate); 44 44 fprintf (stderr, "%4d/%02d/%02d %02d:%02d:%02f\n", tmpdate.y, tmpdate.mo, tmpdate.d, tmpdate.h, tmpdate.mn, tmpdate.s); 45 45 -
trunk/Ohana/src/skycalc/src/sun.c
r2496 r19681 3 3 /* Low precision formulae for the sun, from Almanac p. C24 (1990) */ 4 4 /* ra and dec are returned as decimal hours and decimal degrees. */ 5 void lpsun (double jd, double *ra, double *dec) {5 void SC_lpsun (double jd, double *ra, double *dec) { 6 6 7 7 double n, L, g, lambda,epsilon,alpha,delta,x,y,z; … … 17 17 z = sin(epsilon)*sin(lambda); 18 18 19 *ra = ( atan_circ(x,y))*HRS_IN_RADIAN;19 *ra = (SC_atan_circ(x,y))*HRS_IN_RADIAN; 20 20 *dec = (asin(z))*DEG_IN_RADIAN; 21 21 } … … 24 24 altitude, given jdguess as a starting point. Uses 25 25 low-precision sun, which is plenty good enough. */ 26 double jd_sun_alt (double alt, double jdguess, double lat, double longit) {26 double SC_jd_sun_alt (double alt, double jdguess, double lat, double longit) { 27 27 28 28 double jdout; … … 33 33 /* first guess */ 34 34 35 lpsun (jdguess, &ra, &dec);36 ha = lst (jdguess,longit) - ra;37 alt2 = altit (dec,ha,lat,&az);35 SC_lpsun (jdguess, &ra, &dec); 36 ha = SC_lst (jdguess,longit) - ra; 37 alt2 = SC_altit (dec,ha,lat,&az); 38 38 jdguess = jdguess + del; 39 lpsun (jdguess,&ra,&dec);40 alt3 = altit(dec,(lst(jdguess,longit) - ra),lat,&az);39 SC_lpsun (jdguess,&ra,&dec); 40 alt3 = SC_altit(dec,(SC_lst(jdguess,longit) - ra),lat,&az); 41 41 err = alt3 - alt; 42 42 deriv = (alt3 - alt2) / del; 43 43 while((fabs(err) > 0.1) && (i < 10)) { 44 44 jdguess = jdguess - err/deriv; 45 lpsun(jdguess,&ra,&dec);46 alt3 = altit(dec,(lst(jdguess,longit) - ra),lat,&az);45 SC_lpsun(jdguess,&ra,&dec); 46 alt3 = SC_altit(dec,(SC_lst(jdguess,longit) - ra),lat,&az); 47 47 err = alt3 - alt; 48 48 i++; … … 56 56 /* Given site position, prints Sun info for the given night. 57 57 /* dates are all in UT now */ 58 double sunset_tonight (struct SC_date_time date, double lat, double longit, double elev) {58 double SC_sunset_tonight (struct SC_date_time date, double lat, double longit, double elev) { 59 59 60 60 double jd, jdmid0, jdmid, stmid; … … 68 68 69 69 /* find offset in hours from longit to greenwich */ 70 jd = date_to_jd (date); /* true jd now */71 lst0 = lst (jd, 0.0); /* lst at long = 0 */72 lst1 = lst (jd, longit); /* local lst now */70 jd = SC_date_to_jd (date); /* true jd now */ 71 lst0 = SC_lst (jd, 0.0); /* lst at long = 0 */ 72 lst1 = SC_lst (jd, longit); /* local lst now */ 73 73 dt = lst0 - lst1; 74 74 if (dt < 0) dt += 24; … … 81 81 82 82 /* find jd for local midnight, select the *closest* midnight */ 83 jdmid0 = date_to_jd (date_midnight);83 jdmid0 = SC_date_to_jd (date_midnight); 84 84 jdmid = jdmid0 + dt / 24.0; 85 85 djd = jd - jdmid; 86 86 if (djd < -0.5) jdmid -= 1.0; 87 87 if (djd > 0.5) jdmid += 1.0; 88 stmid = lst (jdmid,longit);88 stmid = SC_lst (jdmid,longit); 89 89 90 90 /* sunset / sunrise hour angle */ 91 lpsun (jdmid, &rasun, &decsun);92 hasunset = ha_alt (decsun, lat, -(0.83+horiz));91 SC_lpsun (jdmid, &rasun, &decsun); 92 hasunset = SC_ha_alt (decsun, lat, -(0.83+horiz)); 93 93 if(hasunset > 900.) { /* flag for never sets */ 94 94 return (-1); … … 99 99 100 100 /* find sunset time */ 101 jdsunset = jdmid + adj_time(rasun+hasunset-stmid)/24.;102 jdsunset = jd_sun_alt (-(0.83+horiz),jdsunset,lat,longit);101 jdsunset = jdmid + SC_adj_time(rasun+hasunset-stmid)/24.; 102 jdsunset = SC_jd_sun_alt (-(0.83+horiz),jdsunset,lat,longit); 103 103 104 104 return (jdsunset); … … 108 108 /* Given site position, prints Sun info for the given night. 109 109 /* dates are all in UT now */ 110 double sunrise_tonight (struct SC_date_time date, double lat, double longit, double elev) {110 double SC_sunrise_tonight (struct SC_date_time date, double lat, double longit, double elev) { 111 111 112 112 double jd, jdmid, stmid; … … 120 120 121 121 /* find offset in hours from longit to greenwich */ 122 jd = date_to_jd (date); /* true jd now */123 lst0 = lst (jd, 0.0); /* lst at long = 0 */124 lst1 = lst (jd, longit); /* local lst now */122 jd = SC_date_to_jd (date); /* true jd now */ 123 lst0 = SC_lst (jd, 0.0); /* lst at long = 0 */ 124 lst1 = SC_lst (jd, longit); /* local lst now */ 125 125 dt = lst0 - lst1; 126 126 if (dt < 0) dt += 24; … … 133 133 134 134 /* find jd for local midnight, select the *closest* midnight */ 135 jdmid = date_to_jd (date_midnight) - dt / 24.0;135 jdmid = SC_date_to_jd (date_midnight) - dt / 24.0; 136 136 djd = jd - jdmid; 137 137 if (djd < -0.5) jdmid -= 1.0; 138 138 if (djd > 0.5) jdmid += 1.0; 139 stmid = lst (jdmid,longit);139 stmid = SC_lst (jdmid,longit); 140 140 141 141 /* sunset / sunrise hour angle */ 142 lpsun (jdmid, &rasun, &decsun);143 hasunset = ha_alt (decsun, lat, -(0.83+horiz));142 SC_lpsun (jdmid, &rasun, &decsun); 143 hasunset = SC_ha_alt (decsun, lat, -(0.83+horiz)); 144 144 if(hasunset > 900.) { /* flag for never sets */ 145 145 return (-1); … … 151 151 152 152 /* find sunrise time */ 153 jdsunrise = jdmid + adj_time(rasun-hasunset-stmid)/24.;154 jdsunrise = jd_sun_alt(-(0.83+horiz),jdsunrise,lat,longit);153 jdsunrise = jdmid + SC_adj_time(rasun-hasunset-stmid)/24.; 154 jdsunrise = SC_jd_sun_alt(-(0.83+horiz),jdsunrise,lat,longit); 155 155 156 156 return (jdsunrise); -
trunk/Ohana/src/skycalc/src/sundata.c
r3263 r19681 1 # include <stdio.h>2 # include <math.h>3 1 # include <skycalc_internal.h> 2 # include <ohana.h> 4 3 5 # define DEG_RAD 57.295779513082322 6 # define RAD_DEG 0.017453292519943 7 # define dCOS(A) ((double) cos ((double)RAD_DEG*A)) 8 # define dSIN(A) ((double) sin ((double)RAD_DEG*A)) 9 10 double atof(); 11 12 void set_site (double *longit, double *lat, double *elevsea, double *elev) { 4 void SC_set_site (double *longit, double *lat, double *elevsea, double *elev) { 13 5 14 6 *longit = 10.36478; /* W longitude in decimal hours */ … … 38 30 DECo = atof (argv[3]); 39 31 40 if (! str_to_time (argv[1], &tzero)) {32 if (!ohana_str_to_time (argv[1], &tzero)) { 41 33 fprintf (stderr, "syntax error\n"); 42 34 exit (1); … … 54 46 */ 55 47 56 set_site (&longit, &lat, &elevsea, &elev);57 jdnow = date_to_jd (date);48 SC_set_site (&longit, &lat, &elevsea, &elev); 49 jdnow = SC_date_to_jd (date); 58 50 59 /* Calcu alte local sidereal time */60 sid = lst(jdnow, longit);61 lpsun (jdnow, &Rsun, &Dsun);51 /* Calculate local sidereal time */ 52 sid = SC_lst(jdnow, longit); 53 SC_lpsun (jdnow, &Rsun, &Dsun); 62 54 63 55 /* dot product of unit vectors of (RAo,DECo) & (Rsun,Dsun) */ -
trunk/Ohana/src/skycalc/src/time.c
r2496 r19681 2 2 3 3 /* fill date structure with current date & time (UT) */ 4 int get_sys_date (struct SC_date_time *date) {4 int SC_get_sys_date (struct SC_date_time *date) { 5 5 6 6 time_t t; … … 25 25 26 26 /* convert a UT date to JD ( 1900 -- 2100?) */ 27 double date_to_jd (struct SC_date_time date) {27 double SC_date_to_jd (struct SC_date_time date) { 28 28 29 short yr1=0, mo1=1; 30 long jdzpt = 1720982, jdint, inter; 31 double jd,jdfrac; 29 short yr1=0; 30 short mo1=1; 31 long jdzpt = 1720982; 32 long jdint, inter; 33 double jd, jdfrac; 32 34 33 35 if ((date.y <= 1900) | (date.y >= 2100)) return (0.0); … … 53 55 54 56 /* convert JD to a UT date & time */ 55 void jd_to_date (double jdin, struct SC_date_time *date) { 57 /* XXX can we drop this and use the unix time functions? */ 58 void SC_jd_to_date (double jdin, struct SC_date_time *date) { 56 59 57 60 #define IGREG 2299161 … … 104 107 p.359, 1982. On workstations, accuracy (numerical only!) 105 108 is about a millisecond in the 1990s. */ 106 double lst (double jd, double longit) {109 double SC_lst (double jd, double longit) { 107 110 108 111 double t, ut, jdmid, jdint, jdfrac, sid_g, sid; … … 132 135 133 136 /* force time domain to be -12h and 12h */ 134 double adj_time (double x) {137 double SC_adj_time (double x) { 135 138 136 139 /* ridiculously inefficient - use modulo and fractions.. */
Note:
See TracChangeset
for help on using the changeset viewer.
