<?php

require_once './connection.php';

if (!isset($_POST['user_id']) == "") {
    $user_id = $_POST['user_id'];
//    echo '$user_id ' . $user_id;
    $result_data = array();

//    $result = [];

    function metersToFeet($meters) {
        $feet = $meters * 3.28084; // Convert meters to feet
        return $feet;
    }

    $query = 'SELECT MAX(id) as id FROM `tbl_flow_meter_data` WHERE flag=1 and user_id=' . $user_id . ' GROUP BY flow_meter_id ORDER by id asc';
//    echo '$$query ' . $query . ' ';
    mysqli_set_charset($con, 'utf8');
    $result = mysqli_query($con, $query);
    if (mysqli_num_rows($result) > 0) {
        $i = 1;
        while ($row = mysqli_fetch_assoc($result)) {

            $meter_name = "";
            $address = "";
            $water_level = 0;
            $Q_Flow = 0;
            $Velocity = 0;
            $cusec = 0;
            $created_date = "";

            $id = $row["id"];
//            echo '<br>$id ' . $id;
//            print_r($result);

            $query1 = 'SELECT tfmd.*,DATE_FORMAT(tfmd.created_date,"%d-%m-%Y %H:%i:%s") AS created_date_new,DATE_FORMAT(tfmd.created_date,"%Y-%m-%d") AS days_date,tfm.meter_name,tfm.canal_type,tfm.address,tfm.canal_height,tfm.side_slop,tfm.channel_slop,tfm.m_r_coefficient,tfm.canal_bottom_width,tfm.canal_top_width,tfm.latitude,tfm.longitude FROM `tbl_flow_meter_data` as tfmd LEFT join tbl_flow_meter as tfm on tfm.id=tfmd.flow_meter_id WHERE tfmd.id=' . $id . ' and tfmd.flag=1 ORDER by tfmd.id DESC LIMIT 0,1';
//            echo '$query1 ' . $query1;
            mysqli_set_charset($con, 'utf8');
            $result1 = mysqli_query($con, $query1);
            if (mysqli_num_rows($result1) > 0) {
                while ($row1 = mysqli_fetch_assoc($result1)) {
                    $now = time(); // or your date as well
                    $your_date = strtotime($row1["days_date"]);
                    $datediff = $now - $your_date;

                    $Days = round($datediff / (60 * 60 * 24));
                    $check_on_off = $row1["canal_height"] - $row1["water_level"];

                    if ($Days > 2) {
                        
                    } else {
                        if ($row1["water_level"] >= 0.20) {   //1 days
                            $bottom_width = $row1["canal_bottom_width"];
                            $side_slop = $row1["side_slop"];
                            $channel_slop = $row1["channel_slop"];
                            $m_r_coefficient = $row1["m_r_coefficient"];
                            $canal_top_width = $row1["canal_top_width"];
                            $water_level = $row1["water_level"];

                            if ($row1["canal_type"] == "Canal") {
                                $a1 = $water_level * $bottom_width;
                                $flow_level_squre = $water_level * $water_level;
                                $a2 = $side_slop * $flow_level_squre;
                                $Area = $a1 + $a2;

                                $z12 = $water_level * $side_slop;
                                $z3 = $bottom_width + $z12;
                                $Area = $z3 * $water_level;

                                $pw0 = $bottom_width;
                                $pw1 = 2 * $water_level;
                                $pw_side_slop = $side_slop * $side_slop;

                                $pw2 = 1 + $pw_side_slop;

                                $pw2_squre = number_format(sqrt($pw2), 4);
//                                                                                            
                                $pw1_squre = number_format($pw1 * $pw2_squre, 4);
//                                                                                            
                                $wetted_perimeter = $pw0 + $pw1_squre;

                                $hydraulic_radius = $Area / $wetted_perimeter;
                                $R = number_format($hydraulic_radius, 3);
//                                      
                                $S = $channel_slop; // slope
                                $V = (1 / $m_r_coefficient) * pow($R, 2 / 3) * sqrt($S);
                                $Q = $Area * $V;

                                $Q_Flow = number_format($Q, 4);
////                                                                                            
                                $Velocity = number_format($V, 2);

                                $Cusec_1_unit = 35.3147;
                                $liter_1_unit = 1000;

                                $meters = $water_level; // Example value in meters
                                $feet = metersToFeet($meters);

                                $water_level_check = $feet;

                                $cusec = 0;

                                $location_id = $row1["flow_meter_id"];
//                                                                                print_r($result);

                                $query21 = 'SELECT * FROM `tbl_canal_measure_data` WHERE location=' . $location_id . ' and flag=1 ORDER by id DESC LIMIT 0,1';
//                                                                                echo '$query1 ' . $query1;
                                mysqli_set_charset($con, 'utf8');
                                $result21 = mysqli_query($con, $query21);
                                if (mysqli_num_rows($result21) > 0) {
                                    while ($row21 = mysqli_fetch_assoc($result21)) {

                                        if ($water_level_check >= 0.15 && $water_level_check <= 0.25) {
                                            $cusec = $row21["0_1"];
                                        } else if ($water_level_check >= 0.25 && $water_level_check <= 0.35) {
                                            $cusec = $row21["0_2"];
                                        } else if ($water_level_check >= 0.35 && $water_level_check <= 0.45) {
                                            $cusec = $row21["0_3"];
                                        } else if ($water_level_check >= 0.45 && $water_level_check <= 0.55) {
                                            $cusec = $row21["0_4"];
                                        } else if ($water_level_check >= 0.55 && $water_level_check <= 0.65) {
                                            $cusec = $row21["0_5"];
                                        } else if ($water_level_check >= 0.65 && $water_level_check <= 0.75) {
                                            $cusec = $row21["0_6"];
                                        } else if ($water_level_check >= 0.75 && $water_level_check <= 0.85) {
                                            $cusec = $row21["0_7"];
                                        } else if ($water_level_check >= 0.85 && $water_level_check <= 0.95) {
                                            $cusec = $row21["0_8"];
                                        } else if ($water_level_check >= 0.95 && $water_level_check <= 1.05) {
                                            $cusec = $row21["0_9"];
                                        } else if ($water_level_check >= 1.05 && $water_level_check <= 1.15) {
                                            $cusec = $row21["1_0"];
                                        } else if ($water_level_check >= 1.15 && $water_level_check <= 1.25) {
                                            $cusec = $row21["1_1"];
                                        } else if ($water_level_check >= 1.25 && $water_level_check <= 1.35) {
                                            $cusec = $row21["1_2"];
                                        } else if ($water_level_check > 1.35 && $water_level_check <= 1.45) {
                                            $cusec = $row21["1_3"] + 3;
                                        } else if ($water_level_check > 1.45 && $water_level_check <= 1.55) {
                                            $cusec = $row21["1_4"] + 3;
                                        } else if ($water_level_check > 1.55 && $water_level_check <= 1.65) {
                                            $cusec = $row21["1_5"] + 3;
                                        } else if ($water_level_check > 1.65 && $water_level_check <= 1.75) {
                                            $cusec = $row21["1_6"] + 3;
                                        } else if ($water_level_check > 1.75 && $water_level_check <= 1.85) {
                                            $cusec = $row21["1_7"] + 3;
                                        } else if ($water_level_check > 1.85 && $water_level_check <= 1.95) {
                                            $cusec = $row21["1_8"] + 3;
                                        } else if ($water_level_check > 1.95 && $water_level_check <= 2.05) {
                                            $cusec = $row21["1_9"] + 3;
                                        } else if ($water_level_check > 2.05 && $water_level_check <= 2.15) {
                                            $cusec = $row21["2_0"] + 3;
                                        } else if ($water_level_check > 2.15 && $water_level_check <= 2.25) {
                                            $cusec = $row21["2_1"] + 3;
                                        } else if ($water_level_check > 2.25 && $water_level_check <= 2.35) {
                                            $cusec = $row21["2_2"] + 3;
                                        } else if ($water_level_check > 2.35 && $water_level_check <= 2.45) {
                                            $cusec = $row21["2_3"] + 3;
                                        } else if ($water_level_check > 2.45 && $water_level_check <= 2.55) {
                                            $cusec = $row21["2_4"] + 3;
                                        } else if ($water_level_check > 2.55 && $water_level_check <= 2.65) {
                                            $cusec = $row21["2_5"] + 3;
                                        } else if ($water_level_check > 2.65 && $water_level_check <= 2.75) {
                                            $cusec = $row21["2_6"] + 3;
                                        } else if ($water_level_check > 2.75 && $water_level_check <= 2.85) {
                                            $cusec = $row21["2_7"] + 3;
                                        } else if ($water_level_check > 2.85 && $water_level_check <= 2.95) {
                                            $cusec = $row21["2_8"] + 3;
                                        } else if ($water_level_check > 2.95 && $water_level_check <= 3.05) {
                                            $cusec = $row21["2_9"] + 3;
                                        } else if ($water_level_check > 3.05 && $water_level_check <= 3.15) {
                                            $cusec = $row21["3_0"] + 3;
                                        } else if ($water_level_check > 3.15 && $water_level_check <= 3.25) {
                                            $cusec = $row21["3_1"] + 3;
                                        } else if ($water_level_check > 3.25 && $water_level_check <= 3.35) {
                                            $cusec = $row21["3_2"] + 3;
                                        } else if ($water_level_check > 3.35 && $water_level_check <= 3.45) {
                                            $cusec = $row21["3_3"] + 3;
                                        } else if ($water_level_check > 3.45 && $water_level_check <= 3.55) {
                                            $cusec = $row21["3_4"] + 3;
                                        } else if ($water_level_check > 3.55 && $water_level_check <= 3.65) {
                                            $cusec = $row21["3_5"] + 3;
                                        } else if ($water_level_check > 3.65 && $water_level_check <= 3.75) {
                                            $cusec = $row21["3_6"] + 3;
                                        } else if ($water_level_check > 3.75 && $water_level_check <= 3.85) {
                                            $cusec = $row21["3_7"] + 3;
                                        } else if ($water_level_check > 3.85 && $water_level_check <= 3.95) {
                                            $cusec = $row21["3_8"] + 3;
                                        } else if ($water_level_check > 3.95 && $water_level_check <= 4.05) {
                                            $cusec = $row21["3_9"] + 3;
                                        } else if ($water_level_check > 4.05 && $water_level_check <= 4.15) {
                                            $cusec = $row21["4_0"] + 3;
                                        } else if ($water_level_check > 4.15 && $water_level_check <= 4.25) {
                                            $cusec = $row21["4_1"] + 3;
                                        } else if ($water_level_check > 4.25 && $water_level_check <= 4.35) {
                                            $cusec = $row21["4_2"] + 3;
                                        } else if ($water_level_check > 4.35 && $water_level_check <= 4.45) {
                                            $cusec = $row21["4_3"] + 3;
                                        } else if ($water_level_check > 4.45 && $water_level_check <= 4.55) {
                                            $cusec = $row21["4_4"] + 3;
                                        } else if ($water_level_check > 4.55 && $water_level_check <= 4.65) {
                                            $cusec = $row21["4_5"] + 3;
                                        } else if ($water_level_check > 4.65 && $water_level_check <= 4.75) {
                                            $cusec = $row21["4_6"] + 3;
                                        } else if ($water_level_check > 4.72 && $water_level_check <= 4.85) {
                                            $cusec = $row21["4_7"] + 3;
                                        } else if ($water_level_check > 4.82 && $water_level_check <= 4.95) {
                                            $cusec = $row21["4_8"] + 3;
                                        } else if ($water_level_check > 4.92 && $water_level_check <= 5.05) {
                                            $cusec = $row21["4_9"] + 3;
                                        } else if ($water_level_check > 5.02 && $water_level_check <= 5.15) {
                                            $cusec = $row21["5_0"] + 3;
                                        } else if ($water_level_check > 5.15 && $water_level_check <= 5.25) {
                                            $cusec = $row21["5_1"] + 3;
                                        } else if ($water_level_check > 5.25 && $water_level_check <= 5.35) {
                                            $cusec = $row21["5_2"] + 3;
                                        } else if ($water_level_check > 5.35 && $water_level_check <= 5.45) {
                                            $cusec = $row21["5_3"] + 3;
                                        } else if ($water_level_check > 5.45 && $water_level_check <= 5.55) {
                                            $cusec = $row21["5_4"] + 3;
                                        } else if ($water_level_check > 5.55 && $water_level_check <= 5.65) {
                                            $cusec = $row21["5_5"] + 3;
                                        } else if ($water_level_check > 5.65 && $water_level_check <= 5.75) {
                                            $cusec = $row21["5_6"] + 3;
                                        } else if ($water_level_check > 5.75 && $water_level_check <= 5.85) {
                                            $cusec = $row21["5_7"] + 3;
                                        } else if ($water_level_check > 5.85 && $water_level_check <= 5.95) {
                                            $cusec = $row21["5_8"] + 3;
                                        } else if ($water_level_check > 5.95 && $water_level_check <= 6.05) {
                                            $cusec = $row21["5_9"] + 3;
                                        } else if ($water_level_check > 6.05 && $water_level_check <= 6.15) {
                                            $cusec = $row21["6_0"] + 3;
                                        } else if ($water_level_check > 6.15 && $water_level_check <= 6.25) {
                                            $cusec = $row21["6_1"] + 3;
                                        } else if ($water_level_check > 6.25 && $water_level_check <= 6.35) {
                                            $cusec = $row21["6_2"] + 3;
                                        } else if ($water_level_check > 6.35 && $water_level_check <= 6.45) {
                                            $cusec = $row21["6_3"] + 3;
                                        } else if ($water_level_check > 6.45 && $water_level_check <= 6.55) {
                                            $cusec = $row21["6_4"] + 3;
                                        } else if ($water_level_check > 6.55 && $water_level_check <= 6.65) {
                                            $cusec = $row21["6_5"] + 3;
                                        } else if ($water_level_check > 6.65 && $water_level_check <= 6.75) {
                                            $cusec = $row21["6_6"] + 3;
                                        } else if ($water_level_check > 6.75) {
                                            $cusec = $row21["6_7"] + 3;
                                        }
                                    }
                                } else {
//                                echo '<br>$Q_Flow '.$Q_Flow;
                                    $cusec = number_format($Q_Flow * $Cusec_1_unit, 2);
//                                echo '<br>$cusec '.$cusec;
                                }
                                $water_level = $row1["water_level"];
                            } else if ($row1["canal_type"] == "Dam") {
                                $location_id = $row1["flow_meter_id"];
//                                                                                print_r($result);

                                $meters = $water_level; // Example value in meters
//                                                                                                        echo '$meters ' . $meters;
                                $feet = metersToFeet($meters);
                                // echo "<br>$meters meters is equal to " . $feet . " feet.";
//// Output the result
                                // echo "<br>$meters meters is equal to " . number_format($feet, 2) . " feet.";
                                $water_level_check = $feet;
//                                                                                                        echo '<br>$water_level_check ' . $water_level_check;

                                $query21 = 'SELECT * FROM `tbl_canal_kakarapar_mesure` WHERE location_id=' . $location_id . ' and flag=1 ORDER by id asc LIMIT 0,1';
//                                                                                                        echo '<br>$query21 ' . $query21;
                                mysqli_set_charset($con, 'utf8');
                                $result21 = mysqli_query($con, $query21);
                                if (mysqli_num_rows($result21) > 0) {
                                    while ($row21 = mysqli_fetch_assoc($result21)) {


                                        if ($water_level_check <= 159.95) {
                                            $cusec = 0;
                                        } else if ($water_level_check > 159.95 && $water_level_check <= 160.05) {
                                            $cusec = $row21["160_0"];
                                        } else if ($water_level_check > 160.05 && $water_level_check <= 160.15) {
                                            $cusec = $row21["160_10"];
                                        } else if ($water_level_check > 160.15 && $water_level_check <= 160.25) {
                                            $cusec = $row21["160_20"];
                                        } else if ($water_level_check > 160.25 && $water_level_check <= 160.35) {
                                            $cusec = $row21["160_30"];
                                        } else if ($water_level_check > 160.35 && $water_level_check <= 160.45) {
                                            $cusec = $row21["160_40"];
                                        } else if ($water_level_check > 160.45 && $water_level_check <= 160.55) {
                                            $cusec = $row21["160_50"];
                                        } else if ($water_level_check > 160.55 && $water_level_check <= 160.65) {
                                            $cusec = $row21["160_60"];
                                        } else if ($water_level_check > 160.65 && $water_level_check <= 160.75) {
                                            $cusec = $row21["160_70"];
                                        } else if ($water_level_check > 160.75 && $water_level_check <= 160.85) {
                                            $cusec = $row21["160_80"];
                                        } else if ($water_level_check > 160.85 && $water_level_check <= 160.95) {
                                            $cusec = $row21["160_90"];
                                        } else if ($water_level_check > 160.95 && $water_level_check <= 161.05) {
                                            $cusec = $row21["161_0"];
                                        } else if ($water_level_check > 161.05 && $water_level_check <= 161.15) {
                                            $cusec = $row21["161_10"];
                                        } else if ($water_level_check > 161.15 && $water_level_check <= 161.25) {
                                            $cusec = $row21["161_20"];
                                        } else if ($water_level_check > 161.25 && $water_level_check <= 161.35) {
                                            $cusec = $row21["161_30"];
                                        } else if ($water_level_check > 161.35 && $water_level_check <= 161.45) {
                                            $cusec = $row21["161_40"] + 3;
                                        } else if ($water_level_check > 161.45 && $water_level_check <= 161.55) {
                                            $cusec = $row21["161_50"] + 3;
                                        } else if ($water_level_check > 161.55 && $water_level_check <= 161.65) {
                                            $cusec = $row21["161_60"] + 3;
                                        } else if ($water_level_check > 161.65 && $water_level_check <= 161.75) {
                                            $cusec = $row21["161_70"] + 3;
                                        } else if ($water_level_check > 161.75 && $water_level_check <= 161.85) {
                                            $cusec = $row21["161_80"] + 3;
                                        } else if ($water_level_check > 161.85 && $water_level_check <= 161.95) {
                                            $cusec = $row21["161_90"] + 3;
                                        } else if ($water_level_check > 161.95 && $water_level_check <= 162.05) {
                                            $cusec = $row21["162_0"] + 3;
                                        } else if ($water_level_check > 162.05 && $water_level_check <= 162.15) {
                                            $cusec = $row21["162_10"] + 3;
                                        } else if ($water_level_check > 162.15 && $water_level_check <= 162.25) {
                                            $cusec = $row21["162_20"] + 3;
                                        } else if ($water_level_check > 162.25 && $water_level_check <= 162.35) {
                                            $cusec = $row21["162_30"] + 3;
                                        } else if ($water_level_check > 162.35 && $water_level_check <= 162.45) {
                                            $cusec = $row21["162_40"] + 3;
                                        } else if ($water_level_check > 162.45 && $water_level_check <= 162.55) {
                                            $cusec = $row21["162_50"] + 3;
                                        } else if ($water_level_check > 162.55 && $water_level_check <= 162.65) {
                                            $cusec = $row21["162_60"] + 3;
                                        } else if ($water_level_check > 162.65 && $water_level_check <= 162.75) {
                                            $cusec = $row21["162_70"] + 3;
                                        } else if ($water_level_check > 162.75 && $water_level_check <= 162.85) {
                                            $cusec = $row21["162_80"] + 3;
                                        } else if ($water_level_check > 162.85 && $water_level_check <= 162.95) {
                                            $cusec = $row21["162_90"] + 3;
                                        } else if ($water_level_check > 162.95 && $water_level_check <= 163.05) {
                                            $cusec = $row21["163_0"] + 3;
                                        } else if ($water_level_check > 163.05 && $water_level_check <= 163.15) {
                                            $cusec = $row21["163_10"] + 3;
                                        } else if ($water_level_check > 163.15 && $water_level_check <= 163.25) {
                                            $cusec = $row21["163_20"] + 3;
                                        } else if ($water_level_check > 163.25 && $water_level_check <= 163.35) {
                                            $cusec = $row21["163_30"] + 3;
                                        } else if ($water_level_check > 163.35 && $water_level_check <= 163.45) {
                                            $cusec = $row21["163_40"] + 3;
                                        } else if ($water_level_check > 163.45 && $water_level_check <= 163.55) {
                                            $cusec = $row21["163_50"] + 3;
                                        } else if ($water_level_check > 163.55 && $water_level_check <= 163.65) {
                                            $cusec = $row21["163_60"] + 3;
                                        } else if ($water_level_check > 163.65 && $water_level_check <= 163.75) {
                                            $cusec = $row21["163_70"] + 3;
                                        } else if ($water_level_check > 163.75 && $water_level_check <= 163.85) {
                                            $cusec = $row21["163_80"] + 3;
                                        } else if ($water_level_check > 163.85 && $water_level_check <= 163.95) {
                                            $cusec = $row21["163_90"] + 3;
                                        } else if ($water_level_check > 163.95 && $water_level_check <= 164.05) {
                                            $cusec = $row21["164_0"] + 3;
                                        } else if ($water_level_check > 164.05 && $water_level_check <= 164.15) {
                                            $cusec = $row21["164_10"] + 3;
                                        } else if ($water_level_check > 164.15 && $water_level_check <= 164.25) {
                                            $cusec = $row21["164_20"] + 3;
                                        } else if ($water_level_check > 164.25 && $water_level_check <= 164.35) {
                                            $cusec = $row21["164_30"] + 3;
                                        } else if ($water_level_check > 164.35 && $water_level_check <= 164.45) {
                                            $cusec = $row21["164_40"] + 3;
                                        } else if ($water_level_check > 164.45 && $water_level_check <= 164.55) {
                                            $cusec = $row21["164_50"] + 3;
                                        } else if ($water_level_check > 164.55 && $water_level_check <= 164.65) {
                                            $cusec = $row21["164_60"] + 3;
                                        } else if ($water_level_check > 164.65 && $water_level_check <= 164.75) {
                                            $cusec = $row21["164_70"] + 3;
                                        } else if ($water_level_check > 164.75 && $water_level_check <= 164.85) {
                                            $cusec = $row21["164_80"] + 3;
                                        } else if ($water_level_check > 164.85 && $water_level_check <= 164.95) {
                                            $cusec = $row21["164_90"] + 3;
                                        } else if ($water_level_check > 164.95 && $water_level_check <= 165.05) {
                                            $cusec = $row21["165_0"] + 3;
                                        } else if ($water_level_check > 165.05 && $water_level_check <= 165.15) {
                                            $cusec = $row21["165_10"] + 3;
                                        } else if ($water_level_check > 165.15 && $water_level_check <= 165.25) {
                                            $cusec = $row21["165_20"] + 3;
                                        } else if ($water_level_check > 165.25 && $water_level_check <= 165.35) {
                                            $cusec = $row21["165_30"] + 3;
                                        } else if ($water_level_check > 165.35 && $water_level_check <= 165.45) {
                                            $cusec = $row21["165_40"] + 3;
                                        } else if ($water_level_check > 165.45 && $water_level_check <= 165.55) {
                                            $cusec = $row21["165_50"] + 3;
                                        } else if ($water_level_check > 165.55 && $water_level_check <= 165.65) {
                                            $cusec = $row21["165_60"] + 3;
                                        } else if ($water_level_check > 165.65 && $water_level_check <= 165.75) {
                                            $cusec = $row21["165_70"] + 3;
                                        } else if ($water_level_check > 165.75 && $water_level_check <= 165.85) {
                                            $cusec = $row21["165_80"] + 3;
                                        } else if ($water_level_check > 165.85 && $water_level_check <= 165.95) {
                                            $cusec = $row21["165_90"] + 3;
                                        } else if ($water_level_check > 165.95 && $water_level_check <= 166.05) {
                                            $cusec = $row21["166_0"] + 3;
                                        } else if ($water_level_check > 166.05 && $water_level_check <= 166.15) {
                                            $cusec = $row21["166_10"] + 3;
                                        } else if ($water_level_check > 166.15 && $water_level_check <= 166.25) {
                                            $cusec = $row21["166_20"] + 3;
                                        } else if ($water_level_check > 166.25 && $water_level_check <= 166.35) {
                                            $cusec = $row21["166_30"] + 3;
                                        } else if ($water_level_check > 166.35 && $water_level_check <= 166.45) {
                                            $cusec = $row21["166_40"] + 3;
                                        } else if ($water_level_check > 166.45 && $water_level_check <= 166.55) {
                                            $cusec = $row21["166_50"] + 3;
                                        } else if ($water_level_check > 166.55 && $water_level_check <= 166.65) {
                                            $cusec = $row21["166_60"] + 3;
                                        } else if ($water_level_check > 166.65 && $water_level_check <= 166.75) {
                                            $cusec = $row21["166_70"] + 3;
                                        } else if ($water_level_check > 166.75 && $water_level_check <= 166.85) {
                                            $cusec = $row21["166_80"] + 3;
                                        } else if ($water_level_check > 166.85 && $water_level_check <= 166.95) {
                                            $cusec = $row21["166_90"] + 3;
                                        } else if ($water_level_check > 166.95 && $water_level_check <= 167.05) {
                                            $cusec = $row21["167_0"] + 3;
                                        } else if ($water_level_check > 167.05 && $water_level_check <= 167.15) {
                                            $cusec = $row21["167_10"] + 3;
                                        } else if ($water_level_check > 167.15 && $water_level_check <= 167.25) {
                                            $cusec = $row21["167_20"] + 3;
                                        } else if ($water_level_check > 167.25 && $water_level_check <= 167.35) {
                                            $cusec = $row21["167_30"] + 3;
                                        } else if ($water_level_check > 167.35 && $water_level_check <= 167.45) {
                                            $cusec = $row21["167_40"] + 3;
                                        } else if ($water_level_check > 167.45 && $water_level_check <= 167.55) {
                                            $cusec = $row21["167_50"] + 3;
                                        } else if ($water_level_check > 167.55 && $water_level_check <= 167.65) {
                                            $cusec = $row21["167_60"] + 3;
                                        } else if ($water_level_check > 167.65 && $water_level_check <= 167.75) {
                                            $cusec = $row21["167_70"] + 3;
                                        } else if ($water_level_check > 167.75 && $water_level_check <= 167.85) {
                                            $cusec = $row21["167_80"] + 3;
                                        } else if ($water_level_check > 167.85 && $water_level_check <= 167.95) {
                                            $cusec = $row21["167_90"] + 3;
                                        } else if ($water_level_check > 167.95 && $water_level_check <= 168.05) {
                                            $cusec = $row21["168_0"] + 3;
                                        } else if ($water_level_check > 168.05 && $water_level_check <= 168.15) {
                                            $cusec = $row21["168_10"] + 3;
                                        } else if ($water_level_check > 168.15 && $water_level_check <= 168.25) {
                                            $cusec = $row21["168_20"] + 3;
                                        } else if ($water_level_check > 168.25 && $water_level_check <= 168.35) {
                                            $cusec = $row21["168_30"] + 3;
                                        } else if ($water_level_check > 168.35 && $water_level_check <= 168.45) {
                                            $cusec = $row21["168_40"] + 3;
                                        } else if ($water_level_check > 168.45 && $water_level_check <= 168.55) {
                                            $cusec = $row21["168_50"] + 3;
                                        } else if ($water_level_check > 168.55 && $water_level_check <= 168.65) {
                                            $cusec = $row21["168_60"] + 3;
                                        } else if ($water_level_check > 168.65 && $water_level_check <= 168.75) {
                                            $cusec = $row21["168_70"] + 3;
                                        } else if ($water_level_check > 168.75 && $water_level_check <= 168.85) {
                                            $cusec = $row21["168_80"] + 3;
                                        } else if ($water_level_check > 168.85 && $water_level_check <= 169.95) {
                                            $cusec = $row21["168_90"] + 3;
                                        } else if ($water_level_check > 169.95 && $water_level_check <= 169.05) {
                                            $cusec = $row21["169_0"] + 3;
                                        } else if ($water_level_check > 169.05 && $water_level_check <= 169.15) {
                                            $cusec = $row21["169_10"] + 3;
                                        } else if ($water_level_check > 169.15 && $water_level_check <= 169.25) {
                                            $cusec = $row21["169_20"] + 3;
                                        } else if ($water_level_check > 169.25 && $water_level_check <= 169.35) {
                                            $cusec = $row21["169_30"] + 3;
                                        } else if ($water_level_check > 169.35 && $water_level_check <= 169.45) {
                                            $cusec = $row21["169_40"] + 3;
                                        } else if ($water_level_check > 169.45 && $water_level_check <= 169.55) {
                                            $cusec = $row21["169_50"] + 3;
                                        } else if ($water_level_check > 169.55 && $water_level_check <= 169.65) {
                                            $cusec = $row21["169_60"] + 3;
                                        } else if ($water_level_check > 169.65 && $water_level_check <= 169.75) {
                                            $cusec = $row21["169_70"] + 3;
                                        } else if ($water_level_check > 169.75 && $water_level_check <= 169.85) {
                                            $cusec = $row21["169_80"] + 3;
                                        } else if ($water_level_check > 169.85 && $water_level_check <= 169.95) {
                                            $cusec = $row21["169_90"] + 3;
                                        } else if ($water_level_check > 169.95 && $water_level_check <= 170.05) {
                                            $cusec = $row21["170_0"] + 3;
                                        } else if ($water_level_check > 170.05 && $water_level_check <= 170.15) {
                                            $cusec = $row21["170_10"] + 3;
                                        } else if ($water_level_check > 170.15 && $water_level_check <= 170.25) {
                                            $cusec = $row21["170_20"] + 3;
                                        } else if ($water_level_check > 170.25 && $water_level_check <= 170.35) {
                                            $cusec = $row21["170_30"] + 3;
                                        } else if ($water_level_check > 170.35 && $water_level_check <= 170.45) {
                                            $cusec = $row21["170_40"] + 3;
                                        } else if ($water_level_check > 170.45 && $water_level_check <= 170.55) {
                                            $cusec = $row21["170_50"] + 3;
                                        } else if ($water_level_check > 170.55 && $water_level_check <= 170.65) {
                                            $cusec = $row21["170_60"] + 3;
                                        } else if ($water_level_check > 170.65 && $water_level_check <= 170.75) {
                                            $cusec = $row21["170_70"] + 3;
                                        } else if ($water_level_check > 170.75 && $water_level_check <= 170.85) {
                                            $cusec = $row21["170_80"] + 3;
                                        } else if ($water_level_check > 170.85 && $water_level_check <= 170.95) {
                                            $cusec = $row21["170_90"] + 3;
                                        } else if ($water_level_check > 170.95 && $water_level_check <= 171.05) {
                                            $cusec = $row21["171_0"] + 3;
                                        } else if ($water_level_check > 171.05 && $water_level_check <= 171.15) {
                                            $cusec = $row21["171_10"] + 3;
                                        } else if ($water_level_check > 171.15 && $water_level_check <= 171.25) {
                                            $cusec = $row21["171_20"] + 3;
                                        } else if ($water_level_check > 171.25 && $water_level_check <= 171.35) {
                                            $cusec = $row21["171_30"] + 3;
                                        } else if ($water_level_check > 171.35 && $water_level_check <= 171.45) {
                                            $cusec = $row21["171_40"] + 3;
                                        } else if ($water_level_check > 171.45 && $water_level_check <= 171.55) {
                                            $cusec = $row21["171_50"] + 3;
                                        } else if ($water_level_check > 171.55 && $water_level_check <= 171.65) {
                                            $cusec = $row21["171_60"] + 3;
                                        } else if ($water_level_check > 171.65 && $water_level_check <= 171.75) {
                                            $cusec = $row21["171_70"] + 3;
                                        } else if ($water_level_check > 171.75 && $water_level_check <= 171.85) {
                                            $cusec = $row21["171_80"] + 3;
                                        } else if ($water_level_check > 171.85 && $water_level_check <= 171.95) {
                                            $cusec = $row21["171_90"] + 3;
                                        } else if ($water_level_check > 171.95 && $water_level_check <= 172.05) {
                                            $cusec = $row21["172_0"] + 3;
                                        } else if ($water_level_check > 172.05 && $water_level_check <= 172.15) {
                                            $cusec = $row21["172_10"] + 3;
                                        } else if ($water_level_check > 172.15 && $water_level_check <= 172.25) {
                                            $cusec = $row21["172_20"] + 3;
                                        } else if ($water_level_check > 172.25 && $water_level_check <= 172.35) {
                                            $cusec = $row21["172_30"] + 3;
                                        } else if ($water_level_check > 172.35 && $water_level_check <= 172.45) {
                                            $cusec = $row21["172_40"] + 3;
                                        } else if ($water_level_check > 172.45 && $water_level_check <= 172.55) {
                                            $cusec = $row21["172_50"] + 3;
                                        } else if ($water_level_check > 172.55 && $water_level_check <= 172.65) {
                                            $cusec = $row21["172_60"] + 3;
                                        } else if ($water_level_check > 172.65 && $water_level_check <= 172.75) {
                                            $cusec = $row21["172_70"] + 3;
                                        } else if ($water_level_check > 172.75 && $water_level_check <= 172.85) {
                                            $cusec = $row21["172_80"] + 3;
                                        } else if ($water_level_check > 172.85 && $water_level_check <= 172.95) {
                                            $cusec = $row21["172_90"] + 3;
                                        } else if ($water_level_check > 172.95 && $water_level_check <= 173.05) {
                                            $cusec = $row21["173_0"] + 3;
                                        } else if ($water_level_check > 173.05 && $water_level_check <= 173.15) {
                                            $cusec = $row21["173_10"] + 3;
                                        } else if ($water_level_check > 173.15 && $water_level_check <= 173.25) {
                                            $cusec = $row21["173_20"] + 3;
                                        } else if ($water_level_check > 173.25 && $water_level_check <= 173.35) {
                                            $cusec = $row21["173_30"] + 3;
                                        } else if ($water_level_check > 173.35 && $water_level_check <= 173.45) {
                                            $cusec = $row21["173_40"] + 3;
                                        } else if ($water_level_check > 173.45 && $water_level_check <= 173.55) {
                                            $cusec = $row21["173_50"] + 3;
                                        } else if ($water_level_check > 173.55 && $water_level_check <= 173.65) {
                                            $cusec = $row21["173_60"] + 3;
                                        } else if ($water_level_check > 173.65 && $water_level_check <= 173.75) {
                                            $cusec = $row21["173_70"] + 3;
                                        } else if ($water_level_check > 173.75 && $water_level_check <= 173.85) {
                                            $cusec = $row21["173_80"] + 3;
                                        } else if ($water_level_check > 173.85 && $water_level_check <= 173.95) {
                                            $cusec = $row21["173_90"] + 3;
                                        } else if ($water_level_check > 173.95 && $water_level_check <= 174.05) {
                                            $cusec = $row21["174_0"] + 3;
                                        } else if ($water_level_check > 174.05 && $water_level_check <= 174.15) {
                                            $cusec = $row21["174_10"] + 3;
                                        } else if ($water_level_check > 174.15 && $water_level_check <= 174.25) {
                                            $cusec = $row21["174_20"] + 3;
                                        } else if ($water_level_check > 174.25 && $water_level_check <= 174.35) {
                                            $cusec = $row21["174_30"] + 3;
                                        } else if ($water_level_check > 174.35 && $water_level_check <= 174.45) {
                                            $cusec = $row21["174_40"] + 3;
                                        } else if ($water_level_check > 174.45 && $water_level_check <= 174.55) {
                                            $cusec = $row21["174_50"] + 3;
                                        } else if ($water_level_check > 174.55 && $water_level_check <= 174.65) {
                                            $cusec = $row21["174_60"] + 3;
                                        } else if ($water_level_check > 174.65 && $water_level_check <= 174.75) {
                                            $cusec = $row21["174_70"] + 3;
                                        } else if ($water_level_check > 174.75 && $water_level_check <= 174.85) {
                                            $cusec = $row21["174_80"] + 3;
                                        } else if ($water_level_check > 174.85 && $water_level_check <= 174.95) {
                                            $cusec = $row21["174_90"] + 3;
                                        } else if ($water_level_check > 174.95 && $water_level_check <= 175.05) {
                                            $cusec = $row21["175_0"] + 3;
                                        } else if ($water_level_check > 175.05 && $water_level_check <= 175.15) {
                                            $cusec = $row21["175_10"] + 3;
                                        } else if ($water_level_check > 175.15 && $water_level_check <= 175.25) {
                                            $cusec = $row21["175_20"] + 3;
                                        } else if ($water_level_check > 175.25 && $water_level_check <= 175.35) {
                                            $cusec = $row21["175_30"] + 3;
                                        } else if ($water_level_check > 175.35 && $water_level_check <= 175.45) {
                                            $cusec = $row21["175_40"] + 3;
                                        } else if ($water_level_check > 175.45 && $water_level_check <= 175.55) {
                                            $cusec = $row21["175_50"] + 3;
                                        } else if ($water_level_check > 175.55 && $water_level_check <= 175.65) {
                                            $cusec = $row21["175_60"] + 3;
                                        } else if ($water_level_check > 175.65 && $water_level_check <= 175.75) {
                                            $cusec = $row21["175_70"] + 3;
                                        } else if ($water_level_check > 175.75 && $water_level_check <= 175.85) {
                                            $cusec = $row21["175_80"] + 3;
                                        } else if ($water_level_check > 175.85 && $water_level_check <= 175.95) {
                                            $cusec = $row21["175_90"] + 3;
                                        } else if ($water_level_check > 175.95 && $water_level_check <= 176.05) {
                                            $cusec = $row21["176_0"] + 3;
                                        } else if ($water_level_check > 176.05 && $water_level_check <= 176.15) {
                                            $cusec = $row21["176_10"] + 3;
                                        } else if ($water_level_check > 176.15 && $water_level_check <= 176.25) {
                                            $cusec = $row21["176_20"] + 3;
                                        } else if ($water_level_check > 176.25 && $water_level_check <= 176.35) {
                                            $cusec = $row21["176_30"] + 3;
                                        } else if ($water_level_check > 176.35 && $water_level_check <= 176.45) {
                                            $cusec = $row21["176_40"] + 3;
                                        } else if ($water_level_check > 176.45 && $water_level_check <= 176.55) {
                                            $cusec = $row21["176_50"] + 3;
                                        } else if ($water_level_check > 176.55 && $water_level_check <= 176.65) {
                                            $cusec = $row21["176_60"] + 3;
                                        } else if ($water_level_check > 176.65 && $water_level_check <= 176.75) {
                                            $cusec = $row21["176_70"] + 3;
                                        } else if ($water_level_check > 176.75 && $water_level_check <= 176.85) {
                                            $cusec = $row21["176_80"] + 3;
                                        } else if ($water_level_check > 176.85 && $water_level_check <= 176.95) {
                                            $cusec = $row21["176_90"] + 3;
                                        } else if ($water_level_check > 176.95 && $water_level_check <= 177.05) {
                                            $cusec = $row21["177_0"] + 3;
                                        } else if ($water_level_check > 177.05 && $water_level_check <= 177.15) {
                                            $cusec = $row21["177_10"] + 3;
                                        } else if ($water_level_check > 177.15 && $water_level_check <= 177.25) {
                                            $cusec = $row21["177_20"] + 3;
                                        } else if ($water_level_check > 177.25 && $water_level_check <= 177.35) {
                                            $cusec = $row21["177_30"] + 3;
                                        } else if ($water_level_check > 177.35 && $water_level_check <= 177.45) {
                                            $cusec = $row21["177_40"] + 3;
                                        } else if ($water_level_check > 177.45 && $water_level_check <= 177.55) {
                                            $cusec = $row21["177_50"] + 3;
                                        } else if ($water_level_check > 177.55 && $water_level_check <= 177.65) {
                                            $cusec = $row21["177_60"] + 3;
                                        } else if ($water_level_check > 177.65 && $water_level_check <= 177.75) {
                                            $cusec = $row21["177_70"] + 3;
                                        } else if ($water_level_check > 177.75 && $water_level_check <= 177.85) {
                                            $cusec = $row21["177_80"] + 3;
                                        } else if ($water_level_check > 177.85 && $water_level_check <= 177.95) {
                                            $cusec = $row21["177_90"] + 3;
                                        } else if ($water_level_check > 177.95 && $water_level_check <= 178.05) {
                                            $cusec = $row21["178_0"] + 3;
                                        } else if ($water_level_check > 178.05 && $water_level_check <= 178.15) {
                                            $cusec = $row21["178_10"] + 3;
                                        } else if ($water_level_check > 178.15 && $water_level_check <= 178.25) {
                                            $cusec = $row21["178_20"] + 3;
                                        } else if ($water_level_check > 178.25 && $water_level_check <= 178.35) {
                                            $cusec = $row21["178_30"] + 3;
                                        } else if ($water_level_check > 178.35 && $water_level_check <= 178.45) {
                                            $cusec = $row21["178_40"] + 3;
                                        } else if ($water_level_check > 178.45 && $water_level_check <= 178.55) {
                                            $cusec = $row21["178_50"] + 3;
                                        } else if ($water_level_check > 178.55 && $water_level_check <= 178.65) {
                                            $cusec = $row21["178_60"] + 3;
                                        } else if ($water_level_check > 178.65 && $water_level_check <= 178.75) {
                                            $cusec = $row21["178_70"] + 3;
                                        } else if ($water_level_check > 178.75 && $water_level_check <= 178.85) {
                                            $cusec = $row21["178_80"] + 3;
                                        } else if ($water_level_check > 178.85 && $water_level_check <= 179.95) {
                                            $cusec = $row21["178_90"] + 3;
                                        } else if ($water_level_check > 179.95 && $water_level_check <= 179.05) {
                                            $cusec = $row21["179_0"] + 3;
                                        } else if ($water_level_check > 179.05 && $water_level_check <= 179.15) {
                                            $cusec = $row21["179_10"] + 3;
                                        } else if ($water_level_check > 179.15 && $water_level_check <= 179.25) {
                                            $cusec = $row21["179_20"] + 3;
                                        } else if ($water_level_check > 179.25 && $water_level_check <= 179.35) {
                                            $cusec = $row21["179_30"] + 3;
                                        } else if ($water_level_check > 179.35 && $water_level_check <= 179.45) {
                                            $cusec = $row21["179_40"] + 3;
                                        } else if ($water_level_check > 179.45 && $water_level_check <= 179.55) {
                                            $cusec = $row21["179_50"] + 3;
                                        } else if ($water_level_check > 179.55 && $water_level_check <= 179.65) {
                                            $cusec = $row21["179_60"] + 3;
                                        } else if ($water_level_check > 179.65 && $water_level_check <= 179.75) {
                                            $cusec = $row21["179_70"] + 3;
                                        } else if ($water_level_check > 179.75 && $water_level_check <= 179.85) {
                                            $cusec = $row21["179_80"] + 3;
                                        } else if ($water_level_check > 179.85 && $water_level_check <= 179.95) {
                                            $cusec = $row21["179_90"] + 3;
                                        } else if ($water_level_check > 179.95 && $water_level_check <= 180.05) {
                                            $cusec = $row21["180_0"] + 3;
                                        } else if ($water_level_check > 180.05 && $water_level_check <= 180.15) {
                                            $cusec = $row21["180_10"] + 3;
                                        } else if ($water_level_check > 180.15 && $water_level_check <= 180.25) {
                                            $cusec = $row21["180_20"] + 3;
                                        } else if ($water_level_check > 180.25 && $water_level_check <= 180.35) {
                                            $cusec = $row21["180_30"] + 3;
                                        } else if ($water_level_check > 180.35 && $water_level_check <= 180.45) {
                                            $cusec = $row21["180_40"] + 3;
                                        } else if ($water_level_check > 180.45 && $water_level_check <= 180.55) {
                                            $cusec = $row21["180_50"] + 3;
                                        } else if ($water_level_check > 180.55 && $water_level_check <= 180.65) {
                                            $cusec = $row21["180_60"] + 3;
                                        } else if ($water_level_check > 180.65 && $water_level_check <= 180.75) {
                                            $cusec = $row21["180_70"] + 3;
                                        } else if ($water_level_check > 180.75 && $water_level_check <= 180.85) {
                                            $cusec = $row21["180_80"] + 3;
                                        } else if ($water_level_check > 180.85 && $water_level_check <= 180.95) {
                                            $cusec = $row21["180_90"] + 3;
                                        } else if ($water_level_check > 180.95 && $water_level_check <= 181.05) {
                                            $cusec = $row21["181_0"] + 3;
                                        } else if ($water_level_check > 181.05 && $water_level_check <= 181.15) {
                                            $cusec = $row21["181_10"] + 3;
                                        } else if ($water_level_check > 181.15 && $water_level_check <= 181.25) {
                                            $cusec = $row21["181_20"] + 3;
                                        } else if ($water_level_check > 181.25 && $water_level_check <= 181.35) {
                                            $cusec = $row21["181_30"] + 3;
                                        } else if ($water_level_check > 181.35 && $water_level_check <= 181.45) {
                                            $cusec = $row21["181_40"] + 3;
                                        } else if ($water_level_check > 181.45 && $water_level_check <= 181.55) {
                                            $cusec = $row21["181_50"] + 3;
                                        } else if ($water_level_check > 181.55 && $water_level_check <= 181.65) {
                                            $cusec = $row21["181_60"] + 3;
                                        } else if ($water_level_check > 181.65 && $water_level_check <= 181.75) {
                                            $cusec = $row21["181_70"] + 3;
                                        } else if ($water_level_check > 181.75 && $water_level_check <= 181.85) {
                                            $cusec = $row21["181_80"] + 3;
                                        } else if ($water_level_check > 181.85 && $water_level_check <= 181.95) {
                                            $cusec = $row21["181_90"] + 3;
                                        } else if ($water_level_check > 181.95 && $water_level_check <= 182.05) {
                                            $cusec = $row21["182_0"] + 3;
                                        } else if ($water_level_check > 182.05 && $water_level_check <= 182.15) {
                                            $cusec = $row21["182_10"] + 3;
                                        } else if ($water_level_check > 182.15 && $water_level_check <= 182.25) {
                                            $cusec = $row21["182_20"] + 3;
                                        } else if ($water_level_check > 182.25 && $water_level_check <= 182.35) {
                                            $cusec = $row21["182_30"] + 3;
                                        } else if ($water_level_check > 182.35 && $water_level_check <= 182.45) {
                                            $cusec = $row21["182_40"] + 3;
                                        } else if ($water_level_check > 182.45 && $water_level_check <= 182.55) {
                                            $cusec = $row21["182_50"] + 3;
                                        } else if ($water_level_check > 182.55 && $water_level_check <= 182.65) {
                                            $cusec = $row21["182_60"] + 3;
                                        } else if ($water_level_check > 182.65 && $water_level_check <= 182.75) {
                                            $cusec = $row21["182_70"] + 3;
                                        } else if ($water_level_check > 182.75 && $water_level_check <= 182.85) {
                                            $cusec = $row21["182_80"] + 3;
                                        } else if ($water_level_check > 182.85 && $water_level_check <= 182.95) {
                                            $cusec = $row21["182_90"] + 3;
                                        } else if ($water_level_check > 182.95 && $water_level_check <= 183.05) {
                                            $cusec = $row21["183_0"] + 3;
                                        } else if ($water_level_check > 183.05 && $water_level_check <= 183.15) {
                                            $cusec = $row21["183_10"] + 3;
                                        } else if ($water_level_check > 183.15 && $water_level_check <= 183.25) {
                                            $cusec = $row21["183_20"] + 3;
                                        } else if ($water_level_check > 183.25 && $water_level_check <= 183.35) {
                                            $cusec = $row21["183_30"] + 3;
                                        } else if ($water_level_check > 183.35 && $water_level_check <= 183.45) {
                                            $cusec = $row21["183_40"] + 3;
                                        } else if ($water_level_check > 183.45 && $water_level_check <= 183.55) {
                                            $cusec = $row21["183_50"] + 3;
                                        } else if ($water_level_check > 183.55 && $water_level_check <= 183.65) {
                                            $cusec = $row21["183_60"] + 3;
                                        } else if ($water_level_check > 183.65 && $water_level_check <= 183.75) {
                                            $cusec = $row21["183_70"] + 3;
                                        } else if ($water_level_check > 183.75 && $water_level_check <= 183.85) {
                                            $cusec = $row21["183_80"] + 3;
                                        } else if ($water_level_check > 183.85 && $water_level_check <= 183.95) {
                                            $cusec = $row21["183_90"] + 3;
                                        } else if ($water_level_check > 183.95 && $water_level_check <= 184.05) {
                                            $cusec = $row21["184_0"] + 3;
                                        } else if ($water_level_check > 184.05 && $water_level_check <= 184.15) {
                                            $cusec = $row21["184_10"] + 3;
                                        } else if ($water_level_check > 184.15 && $water_level_check <= 184.25) {
                                            $cusec = $row21["184_20"] + 3;
                                        } else if ($water_level_check > 184.25 && $water_level_check <= 184.35) {
                                            $cusec = $row21["184_30"] + 3;
                                        } else if ($water_level_check > 184.35 && $water_level_check <= 184.45) {
                                            $cusec = $row21["184_40"] + 3;
                                        } else if ($water_level_check > 184.45 && $water_level_check <= 184.55) {
                                            $cusec = $row21["184_50"] + 3;
                                        } else if ($water_level_check > 184.55 && $water_level_check <= 184.65) {
                                            $cusec = $row21["184_60"] + 3;
                                        } else if ($water_level_check > 184.65 && $water_level_check <= 184.75) {
                                            $cusec = $row21["184_70"] + 3;
                                        } else if ($water_level_check > 184.75 && $water_level_check <= 184.85) {
                                            $cusec = $row21["184_80"] + 3;
                                        } else if ($water_level_check > 184.85 && $water_level_check <= 184.95) {
                                            $cusec = $row21["184_90"] + 3;
                                        } else if ($water_level_check > 184.95 && $water_level_check <= 185.05) {
                                            $cusec = $row21["185_0"] + 3;
                                        } else if ($water_level_check > 185.05 && $water_level_check <= 185.15) {
                                            $cusec = $row21["185_10"] + 3;
                                        } else if ($water_level_check > 185.15 && $water_level_check <= 185.25) {
                                            $cusec = $row21["185_20"] + 3;
                                        } else if ($water_level_check > 185.25 && $water_level_check <= 185.35) {
                                            $cusec = $row21["185_30"] + 3;
                                        } else if ($water_level_check > 185.35 && $water_level_check <= 185.45) {
                                            $cusec = $row21["185_40"] + 3;
                                        } else if ($water_level_check > 185.45 && $water_level_check <= 185.55) {
                                            $cusec = $row21["185_50"] + 3;
                                        } else if ($water_level_check > 185.55 && $water_level_check <= 185.65) {
                                            $cusec = $row21["185_60"] + 3;
                                        } else if ($water_level_check > 185.65 && $water_level_check <= 185.75) {
                                            $cusec = $row21["185_70"] + 3;
                                        } else if ($water_level_check > 185.75 && $water_level_check <= 185.85) {
                                            $cusec = $row21["185_80"] + 3;
                                        } else if ($water_level_check > 185.85 && $water_level_check <= 185.95) {
                                            $cusec = $row21["185_90"] + 3;
                                        } else if ($water_level_check > 185.95 && $water_level_check <= 186.05) {
                                            $cusec = $row21["186_0"] + 3;
                                        } else if ($water_level_check > 186.05 && $water_level_check <= 186.15) {
                                            $cusec = $row21["186_10"] + 3;
                                        } else if ($water_level_check > 186.15 && $water_level_check <= 186.25) {
                                            $cusec = $row21["186_20"] + 3;
                                        } else if ($water_level_check > 186.25 && $water_level_check <= 186.35) {
                                            $cusec = $row21["186_30"] + 3;
                                        } else if ($water_level_check > 186.35 && $water_level_check <= 186.45) {
                                            $cusec = $row21["186_40"] + 3;
                                        } else if ($water_level_check > 186.45 && $water_level_check <= 186.55) {
                                            $cusec = $row21["186_50"] + 3;
                                        } else if ($water_level_check > 186.55 && $water_level_check <= 186.65) {
                                            $cusec = $row21["186_60"] + 3;
                                        } else if ($water_level_check > 186.65 && $water_level_check <= 186.75) {
                                            $cusec = $row21["186_70"] + 3;
                                        } else if ($water_level_check > 186.75 && $water_level_check <= 186.85) {
                                            $cusec = $row21["186_80"] + 3;
                                        } else if ($water_level_check > 186.85 && $water_level_check <= 186.95) {
                                            $cusec = $row21["186_90"] + 3;
                                        } else if ($water_level_check > 186.95 && $water_level_check <= 187.05) {
                                            $cusec = $row21["187_0"] + 3;
                                        } else if ($water_level_check > 187.05 && $water_level_check <= 187.15) {
                                            $cusec = $row21["187_10"] + 3;
                                        } else if ($water_level_check > 187.15 && $water_level_check <= 187.25) {
                                            $cusec = $row21["187_20"] + 3;
                                        } else if ($water_level_check > 187.25 && $water_level_check <= 187.35) {
                                            $cusec = $row21["187_30"] + 3;
                                        } else if ($water_level_check > 187.35 && $water_level_check <= 187.45) {
                                            $cusec = $row21["187_40"] + 3;
                                        } else if ($water_level_check > 187.45 && $water_level_check <= 187.55) {
                                            $cusec = $row21["187_50"] + 3;
                                        } else if ($water_level_check > 187.55 && $water_level_check <= 187.65) {
                                            $cusec = $row21["187_60"] + 3;
                                        } else if ($water_level_check > 187.65 && $water_level_check <= 187.75) {
                                            $cusec = $row21["187_70"] + 3;
                                        } else if ($water_level_check > 187.75 && $water_level_check <= 187.85) {
                                            $cusec = $row21["187_80"] + 3;
                                        } else if ($water_level_check > 187.85 && $water_level_check <= 187.95) {
                                            $cusec = $row21["187_90"] + 3;
                                        } else if ($water_level_check > 187.95 && $water_level_check <= 188.05) {
                                            $cusec = $row21["188_0"] + 3;
                                        } else if ($water_level_check > 188.05 && $water_level_check <= 188.15) {
                                            $cusec = $row21["188_10"] + 3;
                                        } else if ($water_level_check > 188.15 && $water_level_check <= 188.25) {
                                            $cusec = $row21["188_20"] + 3;
                                        } else if ($water_level_check > 188.25 && $water_level_check <= 188.35) {
                                            $cusec = $row21["188_30"] + 3;
                                        } else if ($water_level_check > 188.35 && $water_level_check <= 188.45) {
                                            $cusec = $row21["188_40"] + 3;
                                        } else if ($water_level_check > 188.45 && $water_level_check <= 188.55) {
                                            $cusec = $row21["188_50"] + 3;
                                        } else if ($water_level_check > 188.55 && $water_level_check <= 188.65) {
                                            $cusec = $row21["188_60"] + 3;
                                        } else if ($water_level_check > 188.65 && $water_level_check <= 188.75) {
                                            $cusec = $row21["188_70"] + 3;
                                        } else if ($water_level_check > 188.75 && $water_level_check <= 188.85) {
                                            $cusec = $row21["188_80"] + 3;
                                        } else if ($water_level_check > 188.85 && $water_level_check <= 189.95) {
                                            $cusec = $row21["188_90"] + 3;
                                        } else if ($water_level_check > 189.95 && $water_level_check <= 189.05) {
                                            $cusec = $row21["189_0"] + 3;
                                        } else if ($water_level_check > 189.05 && $water_level_check <= 189.15) {
                                            $cusec = $row21["189_10"] + 3;
                                        } else if ($water_level_check > 189.15 && $water_level_check <= 189.25) {
                                            $cusec = $row21["189_20"] + 3;
                                        } else if ($water_level_check > 189.25 && $water_level_check <= 189.35) {
                                            $cusec = $row21["189_30"] + 3;
                                        } else if ($water_level_check > 189.35 && $water_level_check <= 189.45) {
                                            $cusec = $row21["189_40"] + 3;
                                        } else if ($water_level_check > 189.45 && $water_level_check <= 189.55) {
                                            $cusec = $row21["189_50"] + 3;
                                        } else if ($water_level_check > 189.55 && $water_level_check <= 189.65) {
                                            $cusec = $row21["189_60"] + 3;
                                        } else if ($water_level_check > 189.65 && $water_level_check <= 189.75) {
                                            $cusec = $row21["189_70"] + 3;
                                        } else if ($water_level_check > 189.75 && $water_level_check <= 189.85) {
                                            $cusec = $row21["189_80"] + 3;
                                        } else if ($water_level_check > 189.85 && $water_level_check <= 189.95) {
                                            $cusec = $row21["189_90"] + 3;
                                        } else if ($water_level_check > 189.95 && $water_level_check <= 190.05) {
                                            $cusec = $row21["190_0"] + 3;
                                        } else if ($water_level_check > 190.05) {
                                            $cusec = $row21["190_10"] + 3;
                                        }
                                    }

                                    if ($cusec != 0) {
                                        $Q_Flow = number_format($cusec * 0.0283168, 2);
                                        $Velocity = 0;
                                    } else {
                                        $Q_Flow = 0;
                                        $Velocity = 0;
                                    }
                                } else {
                                    $cusec = number_format($Q_Flow * $Cusec_1_unit, 2);
                                }

                                $water_level = number_format($feet, 2) . " Foot";
                            }



                            $meter_name = $row1["meter_name"];
                            $address = $row1["address"];
                            $water_level = $water_level;
//                            $Q_Flow = $Q_Flow;
//                            $Velocity = $Velocity;
//                            $cusec = $cusec;

                            $created_date = $row1["created_date_new"];

                            $index["id"] = $row["id"];
                            $index["flow_meter_id"] = $row1["flow_meter_id"];
                            $index["user_id"] = $user_id;
                            $index["meter_name"] = $meter_name;
                            $index["Canal_Type"] = $row1["canal_type"];
                            $index["address"] = $address;
                            $index["water_level"] = $water_level;
                            $index["Q_Flow"] = $Q_Flow;
                            $index["Velocity"] = $Velocity;
                            $index["cusec"] = $cusec;
                            $index["latitude"] = $row1["latitude"];
                            $index["longitude"] = $row1["longitude"];
                            $index["created_date"] = $created_date;

                            array_push($result_data, $index);
                        }
                    }
                }
            }
        }
    }

    echo json_encode($result_data);
} else {
    echo 'Username is Null';
}
?>
