-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_tephi.js
162 lines (127 loc) · 4.05 KB
/
get_tephi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var form_bckup = $("<div>");
function get_tephi(lat,lon){
var url = "http://ready.arl.noaa.gov"
var place_path = "/ready2-bin/main.pl?Lat=" + lat + "&Lon=" + lon
var form;
//Get forecast type form
$.ajax({
type: "GET",
url: url + place_path,
success: function(data){
form = data;
},
async: false
});
//Choose tephigram forecast
var new_path = $($("option",form)[10]).val();
//Get cycle form
$.ajax({
type: "GET",
url: url + new_path,
success: function(data){
form = data;
},
async: false
});
//Choose the newest cycle available
var form_data = $("form", form).serialize();
var form_action = $("form", form).attr("action");
//Get date and captcha form and display it to the user
$.ajax({
type: "POST",
url: url + form_action,
data: form_data,
success: function(data){
form = data;
},
async: false
});
$("#content").html($("form",form));
//Fix relative links
$("form").find("img").attr("src", "http://ready.arl.noaa.gov" + $("form").find("img").attr("src"));
$("form").attr("action", "http://ready.arl.noaa.gov" + $("form").attr("action"));
$("form").submit(form_callback);
//---------------------------------------------------------//
//----------------- Function Definitions ------------------//
//---------------------------------------------------------//
function form_callback(e) {
//Prevent the form from submiting
e.preventDefault();
form_bckup.html("");
form_bckup.append($(this).clone());
form_data = $(this).serialize();
new_path = this.action;
$.ajax({
type: "POST",
url: new_path,
data: form_data,
success: function(data){
form = data;
get_tephi_data(form);
},
async: false
});
}
function get_tephi_data(form_data){
$("#content").html("");
var tephi_path = $($("img",form)[4]).attr("src");
var text_path = $($("a",form)[10]).attr("href");
//Get tephi's text
$.ajax({
type: "GET",
url: url + text_path,
success: function(data){
lines = data.split("\n");
var grad = calc_gradient(lines);
$("<table>", {id: "text1", class: "tephi-text"}).appendTo("#content");
for(var i = 5; i < 23; ++i){
var row = $("<tr>").appendTo("#text1");
var text = lines[i].split(':');
row.append("<td>"+text[0]);
row.append("<td>"+text[1]);
}
$("<table>", {id: "text2", class: "tephi-text"}).appendTo("#content");
for(var i = 24; i < lines.length - 2; ++i){
if(i == 26 || i == 27){
continue;
}
var row = $("<tr>").appendTo("#text2");
var text = lines[i].split(/[ ,]+/)
//row.append("<td>"+text[0]);
row.append("<td>"+text[1]);
row.append("<td>"+text[2]);
row.append("<td>"+text[3]);
if(i == 24 || i == 24){
row.append("<td>"+text[4] + " " + text[5]);
row.append("<td>"+text[7] + " " + text[8]);
row.append("<td>"+text[8] + " " + text[9]);
continue;
}
row.append("<td>"+text[4]);
row.append("<td>"+text[5]);
row.append("<td>"+text[6]);
}
//Append Gradient
$($("table#text2 tr")[0].children[3]).after("<td>T GRAD</td>");
$($("table#text2 tr")[1].children[3]).after("<td>C/100M</td>");
$($("table#text2 tr")[2].children[3]).after("<td>---</td>");
for(var i = 3; i < grad.length; ++i){
$($("table#text2 tr")[i].children[3]).after("<td>" + grad[i-3].toFixed(2) +"</td>");
}
},
async: true
});
$("<a>", {href: "#", id: "zoom", rel: url + tephi_path}).appendTo("#content");
$("<img>", {
id: 'tephi',
src: url + tephi_path,
}).appendTo("#zoom")
//Display form
$(form_bckup.children()).prependTo("#content").submit(form_callback);
$($("form").children()[15]).children().children().css("display", "none");
$($($("form").children()[15]).children().children()[0]).css("display", "block");
$($($($("form").children()[15]).children().children()[0]).children()[0]).text("Tephigram Time");
$($("table")[1]).css("display", "none");
$($("select")[0]).change(function(){$("form").submit();});
}
}