Click here to Skip to main content
11,641,971 members (57,983 online)
Click here to Skip to main content

Online Software

, 2 Jun 2014 CPOL 9.9K 106 5
Rate this:
Please Sign up or sign in to vote.
Online Sodium Hypochlorite Dilution Calculator

Online Sodium Hypochlorite Dilution Calculator

About Online software

  • Online software is easy to use and does not need installation to run
  • Your software and your code will be safe since it will not distributed to the final user
  • Your software will be easy to integrated with your site

Introduction

  • Sodium hypochlorite Solution is widely used in home care, swimming water disinfecting, poultry production plants & many more.
  • The mostly know trade name of it is Clorox.
  • Many small plants buy concentrated solution in bulk for diluting and packing.
  • This calculator is for providing online calculations of the diluting.

Using this calculator:

  • Decide what the concentration you want to produce example 4%w/w
  • Get the concentration of the stock solution you have.
  • Go to the online page for the calculation Online calculator
  • Enter your values then press calculate
  • the online calculator will use AJAX so the page will display result without reload it.
  • All the input data will be send to php script that will make the calculation.

Point of Interest:

This article discus the following technique:

  • How to build simple online software that could be run on free hosting.
  • Simple implantation of ajax
  • Testing your software on your PC

Hosting requirements:

  • Free or paid hosting account
  • No database is needed for this software
  • The hosting should support PHP.

Why PHP

  • It is the most server side script available on the webserver even on free plans
  • It is run on booth windows and unix server

Testing your code locally

To test you code locally you will need a web sever with php support.

List of some easy to use servers with php support by default.

  • Uniform Server Zero: Uniform Zero takes a fresh look at Apache, MySQL, PHP and Perl portability. It have a power full control panel
  • XAMPP: It is very common Apache based webserver with php support
  • Server2Go: Portable Apache based webserver with php support. It could run on CD
  • AppServ
  • USBWebserver
  • WampServer

List of some easy to use servers that you should add php support by additional software.

  • Small HTTP server light weight, very power full, multi functional webserver.
  • IIS: IIS is built in windows to add php support just download php for iis and run it

How this application work:

  • This application depends on a table of concentration in deferent units and the density of the sodium hypochlorite solution. It contains also required excess of sodium hydroxide for each concentration.
  • To calculate the quantity of water needed to dilute 8%w/w solution to be 4% solution as example.
  • We search in the table for the input and output chlorine weight percentage and the density.
  • If we do not found the concentration we will calculate it defending on the nearest concentration
//This function will search for a given concentration 
//$var:  value to be searched
//$field:unit of the value 
function searchit($var, $field){
    global $hypochlorite_table;  
    //array contains the data table of chlorine concentrations 
    //and density and reqiured sodium hydroxide
    global $precision;           
    //precision for each field in the $hypochlorite_table array
    $var=round($var,$precision[$field]);
    if ( is_numeric ( $var )) $var = (trim($var) == '')? 0 :$var; else $var = 0;
    for ($index = 0; $index < count($hypochlorite_table); $index++) {
        if($var == $hypochlorite_table[$index][$field]){
            return outputrow($index);
        }elseif($var < $hypochlorite_table[$index][$field]){
            if(!$index) return outputrow($index);
            $delta = ($var-$hypochlorite_table[$index-1][$field])
/($hypochlorite_table[$index][$field]-$hypochlorite_table[$index-1][$field]);
            return outputrow($index,$delta);
        }
    }    
    return false;
}


function outputfield($field,&$row,$index,$delta=0){
    global $hypochlorite_table,$precision;
    if($delta==0){
        $row[$field]= round($hypochlorite_table[$index][$field], 
                $precision[$field]);
    }else{
        $row[$field]=round(
          $hypochlorite_table[$index-1][$field] 
        + $delta*($hypochlorite_table[$index][$field]
        - $hypochlorite_table[$index-1][$field]) 
        , $precision[$field]);
    }
}


function outputrow($index,$delta=0){
    $row=array();
    outputfield(ClWV     ,$row,$index,$delta);
    outputfield(d        ,$row,$index,$delta);
    outputfield(dChange  ,$row,$index,$delta);             
    outputfield(ClWW     ,$row,$index,$delta);
    outputfield(ClDegrees,$row,$index,$delta);
    outputfield(NaOClWV  ,$row,$index,$delta);
    outputfield(NaOClWW  ,$row,$index,$delta);
    outputfield(NaOH     ,$row,$index,$delta);
    outputfield(dNone    ,$row,$index,$delta);
    return $row;
}

Hear is a part of the table

Cl %W/V Cl% Chlorometric
Degrees
°Cl
NaOCl %W/V NaOCl% Required
excess of
NaOH
%W/W
Specific Gravity
change when adding
1% NaOH
Specific Gravity
With required
excess of NaOH
Specific Gravity
Without NaOH
0.0% 0.0% 0.0 0.0% 0.0% 0.25% 0.012 1.001 0.998
2.5% 2.4% 8.0 2.6% 2.5% 0.36% 0.044 1.041 1.025
5.0% 4.6% 16.0 5.2% 4.9% 0.47% 0.028 1.076 1.063
5.5% 5.1% 17.6 5.8% 5.3% 0.49% 0.027 1.083 1.070
6.0% 5.5% 19.2 6.3% 5.8% 0.51% 0.024 1.089 1.077
6.5% 5.9% 20.8 6.8% 6.2% 0.53% 0.023 1.096 1.084
7.0% 6.3% 22.4 7.3% 6.7% 0.55% 0.022 1.103 1.091
7.5% 6.8% 24.0 7.9% 7.1% 0.57% 0.019 1.109 1.098
8.0% 7.2% 25.6 8.4% 7.5% 0.59% 0.019 1.116 1.105

Storing table data in array:

  • There are 3 data fields and other fields are calculated fields.
  • I store the data fields in array
     $hypochlorite_table =array(
    array(00.0, 1.001, 0.012),
    array(01.0, 1.020, 0.064),
    array(01.5, 1.027, 0.053),
    array(02.0, 1.034, 0.050),
    array(02.1, 1.035, 0.049),
    array(02.5, 1.041, 0.044),
    array(02.6, 1.043, 0.041),
    ........
    </pre lang="php"> 
  • I define fields constants
    $fields=array(
    0=>'ClWV',       //Cl(%w/v): weight of chlorine in 100 ml of the solution
    1=>'d',          //Specific Gravity of Sodium Hypochlorite solution that 
                     //contains default required excess of Sodium Hydroxide
    2=>'dChange',    //Specific Gravity change when adding 1% NaOH
    3=>'ClWW',       //Cl%= ClWV /d
    4=>'ClDegrees',  //&deg;Cl Chlorometric Degrees = = 3.2 * ClWV
    5=>'NaOClWV',    //NaOCl% w/v: weight of Sodium Hypochlorite in 100 ml of the solution 
    6=>'NaOClWW',    //NaOCl%: weight of Sodium Hypochlorite in 100 g of the solution  
    7=>'NaOH',       //NaOH%: Default required excess of Sodium Hydroxide for 
                     //this concentration of hypochlorite=0.25+ClWW*0.75/16
    8=>'dNone'       //Specific gravity of Sodium Hypochlorite solution that 
                     //does not contain any excess of Sodium Hydroxide    
    );
    
    foreach ($fields as $key => $value) define($value,$key);
    
  • Them I store the calculated fields in the array for easy searching.
  • I wrote a html page that will be the interface of the application

Using AJAX to call php data

Once the user fill the form and press calculate button if will call AjaxRefresh function.

This function will do the follwing

  • Store all form data in string
  • Create XMLHttpRequest object
  • Create function that will handle the AJAX response
  • Open XMLHttpRequest object and send the data
function AjaxRefresh(){

var q = 'ajax.php'  + '?id='        + 
'&CIn='         + CIn.value         + 
'&COut='        + COut.value        + 
'&dIn='         + dIn.value         + 
'&lang='        + lang.value        + 
'&NaOHIn='      + NaOHIn.value      + 
'&QOut='        + QOut.value        + 
'&UnitIn='      + UnitIn.value      + 
'&UnitInAr='    + UnitInAr.value    + 
'&UnitOut='     + UnitOut.value     + 
'&UnitOutAr='   + UnitOutAr.value   +
'&UnitQOut='    + UnitQOut.value    +
'&UnitQOutAr='  + UnitQOutAr.value  ;

var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState===4 && xmlhttp.status===200)
    var pairs = xmlhttp.responseText.split('&');
    for(i=0;i<pairs.length;i++){
       var pair = pairs[i].split('=');
       var element = document.getElementById(pair[0]);
        if(element===null){
        }else{ 
            try{element.innerHTML = pair[1].trim();}catch(e){};
            try{element.value = pair[1].trim();}catch(e){};
        };
    };
};
xmlhttp.open("GET",q,true);
xmlhttp.send();
}

The php script will send the html elements ids with there new values

Follow me

on facebook

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

NewPast
Lebanon Lebanon
Mini Software Developer, VBA Macro Writer & Web developer
VB, ASP.Net, php & MySQL
------------------------------------------
Look at your eyes:
There is a developer behind every piece of code!

Eyes are too complex what about them!

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 4 Pin
CatchExAs20-May-14 12:29
professionalCatchExAs20-May-14 12:29 
AnswerRe: My vote of 4 Pin
NewPast20-Jun-14 3:04
groupNewPast20-Jun-14 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 2 Jun 2014
Article Copyright 2014 by NewPast
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid