1 | function DefaultDateValues(){ |
---|
2 | |
---|
3 | var rightnow= new Date(); |
---|
4 | |
---|
5 | //document.calendar.year.value=2000; |
---|
6 | document.calendar.year.value=rightnow.getFullYear(); |
---|
7 | //document.calendar.month.value=1; |
---|
8 | document.calendar.month.value=rightnow.getMonth()+1; |
---|
9 | //document.calendar.day.value=1; |
---|
10 | document.calendar.day.value=rightnow.getDate(); |
---|
11 | } |
---|
12 | |
---|
13 | function DefaultTimeValues(){ |
---|
14 | |
---|
15 | var rightnow= new Date(); |
---|
16 | |
---|
17 | document.calendar.hours.value=rightnow.getUTCHours(); |
---|
18 | //document.calendar.hours.value=0; |
---|
19 | document.calendar.minutes.value=rightnow.getUTCMinutes(); |
---|
20 | //document.calendar.minutes.value=0; |
---|
21 | document.calendar.seconds.value=rightnow.getUTCSeconds(); |
---|
22 | //document.calendar.seconds.value=0; |
---|
23 | } |
---|
24 | |
---|
25 | function DateValues(y,m,d){ |
---|
26 | var y; |
---|
27 | var m; |
---|
28 | var d; |
---|
29 | document.calendar.year.value=y; |
---|
30 | document.calendar.month.value=m; |
---|
31 | document.calendar.day.value=d; |
---|
32 | } |
---|
33 | |
---|
34 | function TimeValues(h,m,s){ |
---|
35 | var h; |
---|
36 | var m; |
---|
37 | var s; |
---|
38 | document.calendar.hours.value=h; |
---|
39 | document.calendar.minutes.value=m; |
---|
40 | document.calendar.seconds.value=s; |
---|
41 | } |
---|
42 | |
---|
43 | function DateAndTimeValues(year,month,day,hours,minutes,seconds){ |
---|
44 | var year,month,day,hours,minutes,seconds; |
---|
45 | DateValues(year,month,day); |
---|
46 | TimeValues(hours,minutes,seconds); |
---|
47 | } |
---|
48 | |
---|
49 | function CheckGivenYear(){ |
---|
50 | var bissextil; // bissextil year ? (0==no, 1==yes) (returned value) |
---|
51 | var val=document.calendar.year.value; |
---|
52 | |
---|
53 | while ((val!=Math.round(val))||(val<1583)) { |
---|
54 | if (val!=Math.round(val)) { |
---|
55 | val=prompt("Year must be an integer! e.g.:",Math.round(val)); |
---|
56 | } |
---|
57 | if (val<1583) { |
---|
58 | val=prompt("Sorry, Year must not be less than 1583 \n (in order to stick to the Gregorian calendar)",1583); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | document.calendar.year.value=val; |
---|
63 | |
---|
64 | // check if it is a bissextil year |
---|
65 | /* a year is bissextil if it is a multiple of 4 but not of 100, |
---|
66 | or if it is a multiple of 400 */ |
---|
67 | if ((((val%4)==0)&&((val%100)!=0))||((val%400)==0)) { |
---|
68 | bissextil=1; |
---|
69 | } |
---|
70 | else { |
---|
71 | bissextil=0; // not a bissextil year |
---|
72 | } |
---|
73 | |
---|
74 | return bissextil; |
---|
75 | } |
---|
76 | |
---|
77 | function CheckGivenMonth(){ |
---|
78 | var val=document.calendar.month.value; |
---|
79 | |
---|
80 | while((val<=0)||(val>12)||(val!=Math.round(val))) { |
---|
81 | val=prompt("Month must be an integer between 1 and 12!",Math.round(val)); |
---|
82 | } |
---|
83 | |
---|
84 | document.calendar.month.value=val; |
---|
85 | } |
---|
86 | |
---|
87 | function CheckGivenDay(year,bissextil,month){ |
---|
88 | var year; |
---|
89 | var bissextil; // bissextil year ? (0==no, 1==yes) |
---|
90 | var month; |
---|
91 | var dayval; |
---|
92 | |
---|
93 | dayval=document.calendar.day.value; |
---|
94 | |
---|
95 | if (month==1) { |
---|
96 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
97 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
98 | } |
---|
99 | } |
---|
100 | if (month==2) { |
---|
101 | if (bissextil==0){ |
---|
102 | while (((dayval<=0)||(dayval>28))||(dayval!=Math.round(dayval))){ |
---|
103 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 28)",dayval); |
---|
104 | } |
---|
105 | } |
---|
106 | else { |
---|
107 | while (((dayval<=0)||(dayval>29))||(dayval!=Math.round(dayval))){ |
---|
108 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 29)",dayval); |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | if (month==3) { |
---|
113 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
114 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
115 | } |
---|
116 | } |
---|
117 | if (month==4) { |
---|
118 | while (((dayval<=0)||(dayval>30))||(dayval!=Math.round(dayval))){ |
---|
119 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 30)",dayval); |
---|
120 | } |
---|
121 | } |
---|
122 | if (month==5) { |
---|
123 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
124 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
125 | } |
---|
126 | } |
---|
127 | if (month==6) { |
---|
128 | while (((dayval<=0)||(dayval>30))||(dayval!=Math.round(dayval))){ |
---|
129 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 30)",dayval); |
---|
130 | } |
---|
131 | } |
---|
132 | if (month==7) { |
---|
133 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
134 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
135 | } |
---|
136 | } |
---|
137 | if (month==8) { |
---|
138 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
139 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
140 | } |
---|
141 | } |
---|
142 | if (month==9) { |
---|
143 | while (((dayval<=0)||(dayval>30))||(dayval!=Math.round(dayval))){ |
---|
144 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 30)",dayval); |
---|
145 | } |
---|
146 | } |
---|
147 | if (month==10) { |
---|
148 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
149 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
150 | } |
---|
151 | } |
---|
152 | if (month==11) { |
---|
153 | while (((dayval<=0)||(dayval>30))||(dayval!=Math.round(dayval))){ |
---|
154 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 30)",dayval); |
---|
155 | } |
---|
156 | } |
---|
157 | if (month==12) { |
---|
158 | while (((dayval<=0)||(dayval>31))||(dayval!=Math.round(dayval))){ |
---|
159 | dayval=prompt("Invalid day! (must be an integer ranging from 1 to 31)",dayval); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | document.calendar.day.value=dayval; |
---|
165 | } |
---|
166 | |
---|
167 | function CheckGivenTime(){ |
---|
168 | var hours; |
---|
169 | var minutes; |
---|
170 | var seconds; |
---|
171 | |
---|
172 | // Check value of hours |
---|
173 | hours=document.calendar.hours.value; |
---|
174 | while (((hours<0)||(hours>=24))||(hours!=Math.round(hours))) { |
---|
175 | hours=prompt("Invalid Time (hh) value! (must be an integer ranging from 0 to 23)",hours); |
---|
176 | document.calendar.hours.value=hours; |
---|
177 | } |
---|
178 | |
---|
179 | // Check value of minutes |
---|
180 | minutes=document.calendar.minutes.value; |
---|
181 | while (((minutes<0)||(hours>=60))||(minutes!=Math.round(minutes))) { |
---|
182 | minutes=prompt("Invalid Time (mm) value! (must be an integer ranging from 0 to 59)",minutes); |
---|
183 | document.calendar.minutes.value=minutes; |
---|
184 | } |
---|
185 | |
---|
186 | //Check value of seconds |
---|
187 | seconds=document.calendar.seconds.value; |
---|
188 | while((seconds<0)||(seconds>=60)) { |
---|
189 | seconds=prompt("Invalid Time (ss) value! (must range from 0 to 60)",seconds); |
---|
190 | document.calendar.seconds.value=seconds; |
---|
191 | } |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | /*--------------------------------------------------------------------------*/ |
---|
196 | |
---|
197 | function CheckGivenDate(){ |
---|
198 | var bissextil; // bissextil year ? (0==no, 1==yes) |
---|
199 | |
---|
200 | bissextil=CheckGivenYear(); |
---|
201 | CheckGivenMonth(); |
---|
202 | CheckGivenDay(document.calendar.year.value,bissextil,document.calendar.month.value); |
---|
203 | CheckGivenTime(); |
---|
204 | //alert("OK"); |
---|
205 | return bissextil; |
---|
206 | } |
---|
207 | |
---|
208 | /*--------------------------------------------------------------------------*/ |
---|
209 | |
---|
210 | function Convert2Julian(){ |
---|
211 | var bissextil; // bissextil year ? (0==no, 1==yes) |
---|
212 | var year; |
---|
213 | var month; |
---|
214 | var day; |
---|
215 | var i; |
---|
216 | var hours,minutes,seconds; |
---|
217 | var ref_year=1968; |
---|
218 | var ref_jdate=2.4398565e6; // Julian date for 01/01/1968 00:00:00 |
---|
219 | var edays = new Array(0,31,59,90,120,151,181,212,243,273,304,334); |
---|
220 | // edays = number of elapsed days during previous monthes of same year |
---|
221 | var nday=0.0; // number of days |
---|
222 | |
---|
223 | // start by checking validity of given date |
---|
224 | bissextil=CheckGivenDate(); |
---|
225 | |
---|
226 | year=document.calendar.year.value; |
---|
227 | month=document.calendar.month.value; |
---|
228 | day=document.calendar.day.value; |
---|
229 | |
---|
230 | // compute number of days due to years |
---|
231 | if(year>ref_year) { |
---|
232 | for(i=ref_year;i<year;i++){ |
---|
233 | nday=nday+365.0; |
---|
234 | if ((((i%4)==0)&&((i%100)!=0))||((i%400)==0)) { // bissextil year |
---|
235 | nday++; |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | else { |
---|
240 | for(i=year;i<ref_year;i++){ |
---|
241 | nday=nday-365.0; |
---|
242 | if ((((i%4)==0)&&((i%100)!=0))||((i%400)==0)) { // bissextil year |
---|
243 | nday--; |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | // add number of days due to elapsed monthes |
---|
249 | nday=nday+edays[month-1]; |
---|
250 | //alert(nday) |
---|
251 | |
---|
252 | //add 1 if year is bissextil and month >=3 |
---|
253 | if((bissextil==1)&&(month>=3)){ |
---|
254 | nday=nday+1; |
---|
255 | } |
---|
256 | // add reference year offset and day |
---|
257 | //jdate=ref_jdate+nday+day; |
---|
258 | jdate=nday*1.0+day*1.0+ref_jdate*1.0-1.0; |
---|
259 | |
---|
260 | // add time (hours+minutes+seconds) |
---|
261 | hours=document.calendar.hours.value; |
---|
262 | minutes=document.calendar.minutes.value; |
---|
263 | seconds=document.calendar.seconds.value; |
---|
264 | jdate=jdate+hours/24.0+minutes/1440.0+seconds/86400.0; |
---|
265 | |
---|
266 | document.calendar.julian.value=jdate; |
---|
267 | } |
---|
268 | |
---|
269 | /*--------------------------------------------------------------------------*/ |
---|
270 | |
---|
271 | function Convert2Ls(){ |
---|
272 | // Convert a Julian date to corresponding "sol" and "Ls" |
---|
273 | var jdate; |
---|
274 | var sol; |
---|
275 | var ls; |
---|
276 | var martianyear; |
---|
277 | var martianmonth; |
---|
278 | |
---|
279 | var jdate_ref=2.442765667e6; // 19/12/1975 4:00:00, such that Ls=0 |
---|
280 | // jdate_ref is also the begining of Martian Year "12" |
---|
281 | var martianyear_ref=12; |
---|
282 | var earthday=86400.0; |
---|
283 | var marsday=88775.245; |
---|
284 | var marsyear=668.60; // number of sols in a martian year |
---|
285 | |
---|
286 | // Start by converting given date to Julian date |
---|
287 | Convert2Julian(); |
---|
288 | |
---|
289 | // Convert julian days to sol date |
---|
290 | jdate=document.calendar.julian.value; |
---|
291 | |
---|
292 | sol=(jdate-jdate_ref)*earthday/marsday; |
---|
293 | |
---|
294 | martianyear=martianyear_ref; |
---|
295 | // Compute Martian Year #, along with sol value |
---|
296 | // sol being computed modulo the number of sols in a martian year |
---|
297 | while (sol>=marsyear){ |
---|
298 | sol=sol-marsyear; |
---|
299 | martianyear=martianyear+1; |
---|
300 | } |
---|
301 | while (sol<0.0){ |
---|
302 | sol=sol+marsyear; |
---|
303 | martianyear=martianyear-1; |
---|
304 | } |
---|
305 | |
---|
306 | //document.dummy.dummy1.value=sol; |
---|
307 | |
---|
308 | // convert sol number to Ls |
---|
309 | ls=Sol2Ls(sol); |
---|
310 | |
---|
311 | // Knowing Ls compute martian month |
---|
312 | martianmonth=1+Math.floor(ls/30.); |
---|
313 | |
---|
314 | //Display value with a maximum of 2 decimal digits |
---|
315 | document.calendar.martianyear.value=martianyear; |
---|
316 | document.calendar.martianmonth.value=martianmonth; |
---|
317 | document.calendar.ls.value=Math.round(ls*10)/10; |
---|
318 | //document.calendar.sol.value=Math.round(sol*10)/10; |
---|
319 | document.calendar.sol.value=1+Math.floor(sol); |
---|
320 | } |
---|
321 | |
---|
322 | /*--------------------------------------------------------------------------*/ |
---|
323 | |
---|
324 | function Sol2Ls(sol) { |
---|
325 | var sol; |
---|
326 | var ls; |
---|
327 | |
---|
328 | var year_day=668.6; // number of sols in a martian year |
---|
329 | var peri_day=485.35; // perihelion date |
---|
330 | var e_ellip=0.09340; // orbital ecentricity |
---|
331 | var timeperi=1.90258341759902 // 2*Pi*(1-Ls(perihelion)/360); Ls(perihelion)=250.99 |
---|
332 | var rad2deg=180./Math.PI; |
---|
333 | |
---|
334 | var i; |
---|
335 | var zz,zanom,zdx=10; |
---|
336 | var xref,zx0,zteta; |
---|
337 | // xref: mean anomaly, zx0: eccentric anomaly, zteta: true anomaly |
---|
338 | |
---|
339 | zz=(sol-peri_day)/year_day; |
---|
340 | zanom=2.*Math.PI*(zz-Math.round(zz)); |
---|
341 | xref=Math.abs(zanom); |
---|
342 | |
---|
343 | // Solve Kepler equation zx0 - e *sin(zx0) = xref |
---|
344 | // Using Newton iterations |
---|
345 | zx0=xref+e_ellip*Math.sin(xref); |
---|
346 | do { |
---|
347 | zdx=-(zx0-e_ellip*Math.sin(zx0)-xref)/(1.-e_ellip*Math.cos(zx0)); |
---|
348 | zx0=zx0+zdx; |
---|
349 | }while (zdx>1.e-7); |
---|
350 | if (zanom<0) zx0=-zx0; |
---|
351 | |
---|
352 | // Compute true anomaly zteta, now that eccentric anomaly zx0 is known |
---|
353 | zteta=2.*Math.atan(Math.sqrt((1.+e_ellip)/(1.-e_ellip))*Math.tan(zx0/2.)); |
---|
354 | |
---|
355 | // compute Ls |
---|
356 | ls=zteta-timeperi; |
---|
357 | if(ls<0) ls=ls+2.*Math.PI; |
---|
358 | if(ls>2.*Math.PI) ls=ls-2.*Math.PI; |
---|
359 | // convert Ls into degrees |
---|
360 | ls=rad2deg*ls; |
---|
361 | |
---|
362 | return ls; |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | function PlaceValues(lon,lat){ |
---|
367 | var lon; |
---|
368 | var lat; |
---|
369 | var savlon; |
---|
370 | var savlat; |
---|
371 | var yeah; |
---|
372 | savlon=document.calendar.longitude.value; |
---|
373 | savlat=document.calendar.latitude.value; |
---|
374 | document.calendar.longitude.value=lon; |
---|
375 | document.calendar.latitude.value=lat; |
---|
376 | yeah=document.calendar.toto.value; |
---|
377 | // to be improved. lon and lat should be separated. but for the moment |
---|
378 | // only mapping capabilities exist as 2D plots which means if lon is all |
---|
379 | // lat is all and vice versa. |
---|
380 | if ( document.calendar.longitude.value == "all") { |
---|
381 | if ( document.calendar.altitude.value == "all") { |
---|
382 | alert("Not allowed! Altitude and time must be fixed in mapping mode."); |
---|
383 | document.calendar.longitude.value=savlon; |
---|
384 | document.calendar.latitude.value=savlat; |
---|
385 | document.calendar.toto.value=yeah; |
---|
386 | } |
---|
387 | if ( document.calendar.localtime.value == "all") { |
---|
388 | alert("Not allowed! Altitude and time must be fixed in mapping mode."); |
---|
389 | document.calendar.longitude.value=savlon; |
---|
390 | document.calendar.latitude.value=savlat; |
---|
391 | document.calendar.toto.value=yeah; |
---|
392 | } |
---|
393 | } |
---|
394 | } |
---|
395 | |
---|
396 | function PlaceVar(var1,var2,var3,var4){ |
---|
397 | var var1; |
---|
398 | var var2; |
---|
399 | var var3; |
---|
400 | var var4; |
---|
401 | document.calendar.var1.value=var1; |
---|
402 | document.calendar.var2.value=var2; |
---|
403 | document.calendar.var3.value=var3; |
---|
404 | document.calendar.var4.value=var4; |
---|
405 | } |
---|
406 | |
---|
407 | function DefaultSpaceTime(){ |
---|
408 | document.calendar.localtime.value = 9 |
---|
409 | document.calendar.altitude.value = 2 |
---|
410 | } |
---|
411 | |
---|
412 | // this is separated from PlaceValues because |
---|
413 | // allows easier determination through earth time |
---|
414 | // if needed (e.g. example case with rovers) |
---|
415 | function PlaceValues2(localtime){ |
---|
416 | var localtime; |
---|
417 | var savlocaltime; |
---|
418 | savlocaltime=document.calendar.localtime.value |
---|
419 | document.calendar.localtime.value=localtime; |
---|
420 | if ( document.calendar.localtime.value == "all" ) { |
---|
421 | if ( document.calendar.altitude.value == "all" ) { |
---|
422 | alert("Not allowed! Now choose either a fixed altitude or a fixed time."); |
---|
423 | //document.calendar.localtime.value=savlocaltime; |
---|
424 | } |
---|
425 | } |
---|
426 | if ( document.calendar.localtime.value == "all" ) { |
---|
427 | if ( document.calendar.longitude.value == "all" ) { |
---|
428 | alert("Not allowed! Now choose either a lander or a fixed time."); |
---|
429 | //document.calendar.localtime.value=savlocaltime; |
---|
430 | } |
---|
431 | } |
---|
432 | } |
---|
433 | function PlaceValues3(altitude){ |
---|
434 | var altitude; |
---|
435 | var savaltitude; |
---|
436 | savaltitude=document.calendar.altitude.value |
---|
437 | document.calendar.altitude.value=altitude; |
---|
438 | if ( document.calendar.altitude.value == "all" ) { |
---|
439 | if ( document.calendar.localtime.value == "all") { |
---|
440 | alert("Not allowed! Now choose either a fixed time or a fixed altitude."); |
---|
441 | //document.calendar.altitude.value=savaltitude; |
---|
442 | } |
---|
443 | } |
---|
444 | if ( document.calendar.altitude.value == "all" ) { |
---|
445 | if ( document.calendar.longitude.value == "all") { |
---|
446 | alert("Not allowed! Now choose either a lander or a fixed altitude."); |
---|
447 | //document.calendar.altitude.value=savaltitude; |
---|
448 | } |
---|
449 | } |
---|
450 | } |
---|
451 | |
---|
452 | |
---|
453 | function submit_form_beginner() { |
---|
454 | document.calendar.submit(); |
---|
455 | document.calendar.reset(); |
---|
456 | DefaultDateValues(); |
---|
457 | DefaultTimeValues(); |
---|
458 | Convert2Ls(); |
---|
459 | PlaceValues(0.,0.); |
---|
460 | DefaultSpaceTime() |
---|
461 | } |
---|
462 | |
---|