source: trunk/UTIL/PYTHON/mcd/proto/martian_time.js @ 797

Last change on this file since 797 was 761, checked in by aslmd, 12 years ago

UTIL PYTHON : a more definitive version of what could make a new and simple MCD web interface. added a lot of capabilities: variable setting, beginner mode, wind vector, fixed or not local time, etc etc etc. some modifications were made to the python MCD interface too (this makes the basis for the web interface).

File size: 12.3 KB
Line 
1function DefaultDateValues(){
2
3var rightnow= new Date();
4
5//document.calendar.year.value=2000;
6document.calendar.year.value=rightnow.getFullYear();
7//document.calendar.month.value=1;
8document.calendar.month.value=rightnow.getMonth()+1;
9//document.calendar.day.value=1;
10document.calendar.day.value=rightnow.getDate();
11}
12
13function DefaultTimeValues(){
14
15var rightnow= new Date();
16
17document.calendar.hours.value=rightnow.getUTCHours();
18//document.calendar.hours.value=0;
19document.calendar.minutes.value=rightnow.getUTCMinutes();
20//document.calendar.minutes.value=0;
21document.calendar.seconds.value=rightnow.getUTCSeconds();
22//document.calendar.seconds.value=0;
23}
24
25function DateValues(y,m,d){
26var y;
27var m;
28var d;
29document.calendar.year.value=y;
30document.calendar.month.value=m;
31document.calendar.day.value=d;
32}
33
34function TimeValues(h,m,s){
35var h;
36var m;
37var s;
38document.calendar.hours.value=h;
39document.calendar.minutes.value=m;
40document.calendar.seconds.value=s;
41}
42
43function DateAndTimeValues(year,month,day,hours,minutes,seconds){
44var year,month,day,hours,minutes,seconds;
45DateValues(year,month,day);
46TimeValues(hours,minutes,seconds);
47}
48
49function CheckGivenYear(){
50var bissextil; // bissextil year ? (0==no, 1==yes) (returned value)
51var val=document.calendar.year.value;
52
53while ((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
62document.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,
66or if it is a multiple of 400 */
67if ((((val%4)==0)&&((val%100)!=0))||((val%400)==0)) {
68  bissextil=1;
69}
70else {
71  bissextil=0; // not a bissextil year
72}
73
74return bissextil;
75}
76
77function CheckGivenMonth(){
78var val=document.calendar.month.value;
79
80while((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
84document.calendar.month.value=val;
85}
86
87function CheckGivenDay(year,bissextil,month){
88var year;
89var bissextil; // bissextil year ? (0==no, 1==yes)
90var month;
91var dayval;
92
93dayval=document.calendar.day.value;
94
95if (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}
100if (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}
112if (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}
117if (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}
122if (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}
127if (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}
132if (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}
137if (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}
142if (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}
147if (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}
152if (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}
157if (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
164document.calendar.day.value=dayval;
165}
166
167function CheckGivenTime(){
168var hours;
169var minutes;
170var seconds;
171
172// Check value of hours
173hours=document.calendar.hours.value;
174while (((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
180minutes=document.calendar.minutes.value;
181while (((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
187seconds=document.calendar.seconds.value;
188while((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
197function CheckGivenDate(){
198var bissextil; // bissextil year ? (0==no, 1==yes)
199
200bissextil=CheckGivenYear();
201CheckGivenMonth();
202CheckGivenDay(document.calendar.year.value,bissextil,document.calendar.month.value);
203CheckGivenTime();
204//alert("OK");
205return bissextil;
206}
207
208/*--------------------------------------------------------------------------*/
209
210function Convert2Julian(){
211var bissextil; // bissextil year ? (0==no, 1==yes)
212var year;
213var month;
214var day;
215var i;
216var hours,minutes,seconds;
217var ref_year=1968;
218var ref_jdate=2.4398565e6; // Julian date for 01/01/1968 00:00:00
219var 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
221var nday=0.0; // number of days
222
223// start by checking validity of given date
224bissextil=CheckGivenDate();
225
226year=document.calendar.year.value;
227month=document.calendar.month.value;
228day=document.calendar.day.value;
229
230// compute number of days due to years
231if(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}
239else {
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
249nday=nday+edays[month-1];
250//alert(nday)
251
252//add 1 if year is bissextil and month >=3
253if((bissextil==1)&&(month>=3)){
254  nday=nday+1;
255}
256// add reference year offset and day
257//jdate=ref_jdate+nday+day;
258jdate=nday*1.0+day*1.0+ref_jdate*1.0-1.0;
259
260// add time (hours+minutes+seconds)
261hours=document.calendar.hours.value;
262minutes=document.calendar.minutes.value;
263seconds=document.calendar.seconds.value;
264jdate=jdate+hours/24.0+minutes/1440.0+seconds/86400.0;
265
266document.calendar.julian.value=jdate;
267}
268
269/*--------------------------------------------------------------------------*/
270
271function Convert2Ls(){
272// Convert a Julian date to corresponding "sol" and "Ls"
273var jdate;
274var sol;
275var ls;
276var martianyear;
277var martianmonth;
278
279var 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"
281var martianyear_ref=12;
282var earthday=86400.0;
283var marsday=88775.245;
284var marsyear=668.60; // number of sols in a martian year
285
286// Start by converting given date to Julian date
287Convert2Julian();
288
289// Convert julian days to sol date
290jdate=document.calendar.julian.value;
291
292sol=(jdate-jdate_ref)*earthday/marsday;
293
294martianyear=martianyear_ref;
295// Compute Martian Year #, along with sol value
296// sol being computed modulo the number of sols in a martian year
297while (sol>=marsyear){
298  sol=sol-marsyear;
299  martianyear=martianyear+1;
300}
301while (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
309ls=Sol2Ls(sol);
310
311// Knowing Ls compute martian month
312martianmonth=1+Math.floor(ls/30.);
313
314//Display value with a maximum of 2 decimal digits
315document.calendar.martianyear.value=martianyear;
316document.calendar.martianmonth.value=martianmonth;
317document.calendar.ls.value=Math.round(ls*10)/10;
318//document.calendar.sol.value=Math.round(sol*10)/10;
319document.calendar.sol.value=1+Math.floor(sol);
320}
321
322/*--------------------------------------------------------------------------*/
323
324function Sol2Ls(sol) {
325var sol;
326var ls;
327
328var year_day=668.6; // number of sols in a martian year
329var peri_day=485.35; // perihelion date
330var e_ellip=0.09340; // orbital ecentricity
331var timeperi=1.90258341759902 // 2*Pi*(1-Ls(perihelion)/360); Ls(perihelion)=250.99
332var rad2deg=180./Math.PI;
333
334var i;
335var zz,zanom,zdx=10;
336var xref,zx0,zteta;
337// xref: mean anomaly, zx0: eccentric anomaly, zteta: true anomaly
338
339zz=(sol-peri_day)/year_day;
340zanom=2.*Math.PI*(zz-Math.round(zz));
341xref=Math.abs(zanom);
342
343// Solve Kepler equation zx0 - e *sin(zx0) = xref
344// Using Newton iterations
345zx0=xref+e_ellip*Math.sin(xref);
346do {
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);
350if (zanom<0) zx0=-zx0;
351
352// Compute true anomaly zteta, now that eccentric anomaly zx0 is known
353zteta=2.*Math.atan(Math.sqrt((1.+e_ellip)/(1.-e_ellip))*Math.tan(zx0/2.));
354
355// compute Ls
356ls=zteta-timeperi;
357if(ls<0) ls=ls+2.*Math.PI;
358if(ls>2.*Math.PI) ls=ls-2.*Math.PI;
359// convert Ls into degrees
360ls=rad2deg*ls;
361
362return ls;
363}
364
365
366function PlaceValues(lon,lat){
367var lon;
368var lat;
369var savlon;
370var savlat;
371var yeah;
372savlon=document.calendar.longitude.value;
373savlat=document.calendar.latitude.value;
374document.calendar.longitude.value=lon;
375document.calendar.latitude.value=lat;
376yeah=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.
380if ( 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
396function PlaceVar(var1,var2,var3,var4){
397var var1;
398var var2;
399var var3;
400var var4;
401document.calendar.var1.value=var1;
402document.calendar.var2.value=var2;
403document.calendar.var3.value=var3;
404document.calendar.var4.value=var4;
405}
406
407function DefaultSpaceTime(){
408document.calendar.localtime.value = 9
409document.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)
415function PlaceValues2(localtime){
416var localtime;
417var savlocaltime;
418savlocaltime=document.calendar.localtime.value
419document.calendar.localtime.value=localtime;
420if ( 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}
426if ( 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}
433function PlaceValues3(altitude){
434var altitude;
435var savaltitude;
436savaltitude=document.calendar.altitude.value
437document.calendar.altitude.value=altitude;
438if ( 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}
444if ( 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
Note: See TracBrowser for help on using the repository browser.