-
Notifications
You must be signed in to change notification settings - Fork 1
/
functionForSoil.php
212 lines (156 loc) · 5.64 KB
/
functionForSoil.php
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
// Judge the content type of the line
function judgeContentType($line, $flg) {
if (strpos($line, "*") === 0) {
if (strpos(strtolower($line), "soils") === 1) {
$flg[0] = "soils";
} else {
$flg[0] = "site";
}
$flg[1] = "";
$flg[2] = "data";
} else if (strpos($line, "@") === 0) {
$flg[1] = strtolower(trim(substr($line, 1)));
$flg[2] = "";
} else if (strpos($line, "!") === 0) {
$flg[2] = "comment";
} else if (trim($line) !== "") {
$flg[2] = "data";
} else if ($flg[2] !== "blank") {
$flg[1] = "";
$flg[2] = "blank";
} else {
$flg[0] = "";
$flg[1] = "";
$flg[2] = "blank";
}
return $flg;
}
// split one line content into array
function getSpliterResult($flg, $line, $ret) {
//Read SOILS Info
if ($flg[0] == "soils" && $flg[2] == "data") {
$line = str_ireplace("*soils:", "", $line);
$ret["address"] = str_ireplace("*soils :", "", $line);
// read Site Info
} else if ($flg[0] == "site") {
// header info
if ($flg[1] == "" && $flg[2] == "data") {
// Create the sub array for the new soil
$tmp = createSoilSubArray();
// Get the info from line and save them into array
sscanf($line, "%*1s%10s %11s %5s %5f %50[^\^]", $tmp["pedon"], $tmp["slsour"], $tmp["sltx"], $tmp["sldp"], $tmp["sldesc"]);
$ret["site"] = addArray($ret["site"], $tmp, "");
} // Site info
else if (strpos($flg[1], "site ") === 0 && $flg[2] == "data") {
// Get the current sub array
$cnt = count($ret["site"]);
$tmp = $ret["site"][$cnt];
// Get the info from line and save them into array
sscanf($line, " %11s %11s %8f %8f %50[^\^]", $tmp["ssite"], $tmp["scount"], $tmp["slat"], $tmp["slong"], $tmp["tacon"]);
$ret["site"][$cnt] = $tmp;
} // soil info
else if (strpos($flg[1], "scom ") === 0 && $flg[2] == "data") {
// Get the current sub array
$cnt = count($ret["site"]);
$tmp = $ret["site"][$cnt];
// Get the info from line and save them into array
sscanf($line, " %5s %5f %5f %5f %5f %5f %5f %5s %5s %5s", $tmp["scom"], $tmp["salb"], $tmp["u"], $tmp["swcon"], $tmp["cn2"], $tmp["slnf"], $tmp["slpf"], $tmp["smhb"], $tmp["smpx"], $tmp["smke"]);
$ret["site"][$cnt] = $tmp;
} // layer1 info
else if (strpos($flg[1], "slb slmh") === 0 && $flg[2] == "data") {
// Get the current element's index in the array
$cnt = count($ret["site"]);
// Get the info from line and save them into array
sscanf($line, " %5f %5s %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f", $tmp["zlyr"], $tmp["mh"], $tmp["ll"], $tmp["dul"], $tmp["sat"], $tmp["shf"], $tmp["swcn"], $tmp["bd"], $tmp["oc"], $tmp["clay"], $tmp["silt"], $tmp["stones"], $tmp["totn"], $tmp["ph"], $tmp["phkcl"], $tmp["cec"], $tmp["sadc"]);
$ret["site"][$cnt]["layer1"] = addArray($ret["site"][$cnt]["layer1"], $tmp, "");
} // layer2 info
else if (strpos($flg[1], "slb slpx ") === 0 && $flg[2] == "data") {
// Get the current element's index in the array
$cnt = count($ret["site"]);
// Get the info from line and save them into array
sscanf($line, " %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f %5f", $tmp["zzlyr"], $tmp["extp"], $tmp["totp"], $tmp["orgp"], $tmp["caco"], $tmp["extal"], $tmp["extfe"], $tmp["extmn"], $tmp["totbas"], $tmp["pterma"], $tmp["ptermb"], $tmp["exk"], $tmp["exmg"], $tmp["exna"], $tmp["exts"], $tmp["slec"], $tmp["slca"]);
$ret["site"][$cnt]["layer2"] = addArray($ret["site"][$cnt]["layer2"], $tmp, "");
} else {
}
} else {
}
return $ret;
}
// Add the input value into the array where the position is located by id
function addArray($arr, $value, $id) {
// if id is not pointed out, then add into the end of array
if ($id == "") {
if (isset($arr)) {
$arr[count($arr)+1] = $value;
} else {
$arr[1] = $value;
}
// if id is pointed out, then add into the located position
} else {
$arr[$id] = $value;
}
return $arr;
}
// create exp data array
function createSoilArray() {
$ret["address"] = "";
$ret["site"] = array();
return $ret;
}
// create exp data array
function createSoilSubArray() {
$ret["pedon"] = "";
$ret["slsour"] = "";
$ret["sltx"] = "";
$ret["sldp"] = "";
$ret["sldesc"] = "";
$ret["ssite"] = "";
$ret["scount"] = "";
$ret["slat"] = "";
$ret["slong"] = "";
$ret["tacon"] = "";
$ret["scom"] = "";
$ret["salb"] = "";
$ret["u"] = "";
$ret["swcon"] = "";
$ret["cn2"] = "";
$ret["slnf"] = "";
$ret["slpf"] = "";
$ret["smhb"] = "";
$ret["smpx"] = "";
$ret["smke"] = "";
$ret["layer1"] = array();
$ret["layer2"] = array();
return $ret;
}
function checkInvalidValue($value) {
if ($value == "" || $value == "-99" || $value == -99) {
return true;
} else {
return false;
}
}
function printSoilArray($arr) {
echo "[soils]......[" . $arr["address"] . "]<br/>";
$site = $arr["site"];
for ($i = 1; $i <=count($site) ;$i++) {
echo "############## Site" . $i . " ##############<br/>";
$subKeys = array_keys($site[$i]);
foreach ($subKeys as $subKey) {
if (gettype($site[$i][$subKey]) == "array") {
for ($j = 1; $j<= count($site[$i][$subKey]); $j++) {
$subArr = $site[$i][$subKey][$j];
$subKeys2 = array_keys($subArr);
echo "************* layer" . $j . " *************<br/>";
foreach ($subKeys2 as $subKey2) {
echo "[" . $subKey . "]-->[".$subKey2."]......[" . $subArr[$subKey2] . "]<br />";
}
}
} else {
echo "[". $subKey . "]......[" . $site[$i][$subKey] ."]<br />";
}
}
}
}
?>