Created At: 2026-06-14T16:15:31Z
Completed At: 2026-06-14T16:15:31Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 3878
Total Bytes: 161401
Showing lines 1 to 100
The following code has been modified to include a line number before every line, in the format: <line_number>: <original_line>. Please note that any changes targeting the original code should remove the line number, colon, and leading space.
1: <?php
2: session_start();
3: // ======================================================
4: // =================== BACKEND PHP & DB ==================
5: // ======================================================
6: 
7: // Set headers & error reporting
8: error_reporting(E_ALL);
9: ini_set('display_errors', 0); // Sembunyikan detail error dari user demi keamanan
10: 
11: // Fungsi mem-parsing file CSV IPCC-style dengan column-mapping cerdas & fallback
12: function parse_ipcc_csv($file_path, $start_year = null, $end_year = null) {
13:     $data = [];
14:     if (!file_exists($file_path)) return $data;
15:     if (($handle = fopen($file_path, "r")) !== FALSE) {
16:         $header = fgetcsv($handle, 1000, ",");
17:         if ($header !== FALSE) {
18:             $header = array_map('trim', $header);
19:             
20:             $yearIdx = FALSE;
21:             $ssp126Idx = FALSE;
22:             $ssp245Idx = FALSE;
23:             $ssp370Idx = FALSE;
24:             $ssp585Idx = FALSE;
25: 
26:             foreach ($header as $idx => $colName) {
27:                 $colLower = strtolower($colName);
28:                 if ($colLower === 'year' || $colLower === 'tahun') $yearIdx = $idx;
29:                 else if ($colLower === 'ssp126' || $colLower === 'ssp1-2.6' || $colLower === 'ssp1') $ssp126Idx = $idx;
30:                 else if ($colLower === 'ssp245' || $colLower === 'ssp2-4.5' || $colLower === 'ssp2') $ssp245Idx = $idx;
31:                 else if ($colLower === 'ssp370' || $colLower === 'ssp3-7.0' || $colLower === 'ssp3') $ssp370Idx = $idx;
32:           
<truncated 2132 bytes>
!== false || stripos($variable_sanitized, 'hujan') !== false) {
68:         $base = 2300; // default baseline (curah hujan)
69:     } else if (stripos($variable_sanitized, 'kelembaban') !== false || stripos($variable_sanitized, 'humidity') !== false) {
70:         $base = 82.0;
71:     } else if (stripos($variable_sanitized, 'kecepatan') !== false || stripos($variable_sanitized, 'angin') !== false || stripos($variable_sanitized, 'wind') !== false) {
72:         $base = 2.4;
73:     } else if (stripos($variable_sanitized, 'radiasi') !== false || stripos($variable_sanitized, 'matahari') !== false || stripos($variable_sanitized, 'solar') !== false) {
74:         $base = 178.0;
75:     }
76: 
77:     // 1. historical_timeseries.csv (1980 - 2020)
78:     $hist_path = "{$dir}/historical_timeseries.csv";
79:     if (!file_exists($hist_path)) {
80:         $handle = fopen($hist_path, "w");
81:         if ($handle !== FALSE) {
82:             fputcsv($handle, ['year', 'ssp126', 'ssp245', 'ssp370', 'ssp585']);
83:             for ($y = 1980; $y <= 2020; $y++) {
84:                 $idx = $y - 1980;
85:                 $val = $base + sin($y * 0.5) * ($base > 1000 ? 120 : 0.2) + cos($y) * ($base > 1000 ? 50 : 0.1);
86:                 fputcsv($handle, [$y, round($val, 2), round($val, 2), round($val, 2), round($val, 2)]);
87:             }
88:             fclose($handle);
89:         }
90:     }
91: 
92:     // 2. areal_averaged_ensmean.csv (2021 - 2100)
93:     $mean_path = "{$dir}/areal_averaged_ensmean.csv";
94:     if (!file_exists($mean_path)) {
95:         $handle = fopen($mean_path, "w");
96:         if ($handle !== FALSE) {
97:             fputcsv($handle, ['year', 'ssp126', 'ssp245', 'ssp370', 'ssp585']);
98:             for ($y = 2021; $y <= 2100; $y++) {
99:                 $idx = $y - 2021;
100:                 if ($base > 1000) {
The above content does NOT show the entire file contents. If you need to view any lines of the file which were not shown to complete your task, call this tool again to view those lines.
