#! /usr/bin/gawk -f # Last edited on 2019-04-04 07:54:16 by jstolfi @include "gawklib/fill_molar_mass_table_elems.gawk" @include "gawklib/fill_water_solubility_table_CaCl2.gawk" @include "gawklib/fill_water_solubility_table_CaSO4.gawk" @include "gawklib/fill_water_solubility_table_CuCl2.gawk" @include "gawklib/fill_water_solubility_table_CuSO4.gawk" @include "gawklib/compute_g_w_hydrated.gawk" BEGIN \ { # Computations for the preparation of copper(II) chloride CuCl2 # from copper(II) sulfate CuSO4 and calcium chloride CaCl2. # ---------------------------------------------------------------------- abort = -1; # Molar mass table (grams per mol): split("", g_m); # Indexed by chem formula. fill_molar_mass_table(); # Water solubility table (grams of substance that can be dissolved in 100 g H2O): split("", g_w); # Indexed by chem formula and temperature (C). fill_water_solubility_table_CaCl2(); fill_water_solubility_table_CuCl2(); fill_water_solubility_table_CuSO4(); fill_water_solubility_table_CaSO4(); # Ethanol solubility table (grams of substance that can be dissolved in 100 ml ethanol): split("", g_e); # Indexed by chem formula and temperature (C). fill_ethanol_solubility_table_CaCl2(); # General parameters: g_CuCl2 = 50; # Grams of anhydrous CuCl2 to make. Ts = 20; # Min temperature of reagent solutions. Tf = 20; # Min temperature of filtration. Td = 120; # Min temperature of drying. ex_CuSO4 = 0.05; # Fractional excess of CuSO4. # Compute the plan steps: m_CuCl2 = g_CuCl2/g_m["CuCl2"]; # Moles of CuCl2 to make. m_CuCl2Wt2 = m_CuCl2; # Moles of CuCl2(H2O)2 to make. g_CuCl2Wt2 = m_CuCl2Wt2*g_m["CuCl2(H2O)2"]; # Grams of CuCl2(H2O)2 to make. # Use the right amount of anhydrous CaCl2: m_CaCl2 = m_CuCl2; # Moles of anhydrous CaCl2 to use. g_CaCl2 = m_CaCl2*g_m["CaCl2"]; # Grams of anhydrous CaCl2 to use. # Use a bit excess CuSO4: m_CuSO4 = (1 + ex_CuSO4)*m_CuCl2; # Moles of anhydrous CuSO4 to use. g_CuSO4 = m_CuSO4*g_m["CuSO4"]; # Grams of anhydrous CuSO4 to use. m_CuSO4Wt5 = m_CuSO4; # Moles of CuSO4(H2O)5 to use. g_CuSO4Wt5 = m_CuSO4Wt5*g_m["CuSO4(H2O)5"]; # Grams of CuSO4(H2O)5 to use. # Use enough water to dissolve each reagent at temperature {Ts}: v_w_CaCl2 = 100*g_CaCl2/g_w["CaCl2",Ts]; # Water (ml) for CaCl2 soln. g_w_CaCl2 = v_w_CaCl2; # Water (g) for CaCl2 soln. v_w_CuSO4 = 100*g_CuSO4/g_w["CuSO4",Ts]; # Water (ml) for anhydr CuSO4 soln. g_w_CuSO4 = v_w_CuSO4; # Water (g) for anhydr CuSO4 soln. v_w_CuSO4Wt5 = 100*g_CuSO4Wt5/g_w["CuSO4(H2O)5",Ts]; # Water (ml) for CuSO4(H2O)5 soln. g_w_CuSO4Wt5 = v_w_CuSO4Wt5; # Water (g) for CuSO4(H2O)5 soln. # Compute weight of resulting CaSO4(H2O)2: m_CaSO4Wt2 = m_CaCl2; # Moles of CaSO4(H2O)2 in precp+filtrate. g_CaSO4Wt2 = m_CaSO4Wt2*g_m["CaSO4(H2O)2"]; # Grams of CaSO4(H2O)2 in precp+filtrate. # Compute how much H2O will be in final solution: # It is approx the H2O in the two reagent solns minus that locked in solid CaSO4. v_w_filtr = v_w_CaCl2 + v_w_CuSO4 - 2*m_CaSO4Wt2*g_m["H2O"]; # Water (ml) in filtrate. g_w_filtr = v_w_filtr; # Water (g) in filtrate. # Compute excss of CuSO4 in filtrate: m_ex_CuSO4 = ex_CuSO4*m_CuCl2; # Moles of excess anhydrous CuSO4 g_ex_CuSO4 = m_ex_CuSO4*g_m["CuSO4"]; # Grams of excess anhydrous CuSO4. m_ex_CuSO4Wt5 = m_ex_CuSO4; # Moles of excess CuSO4(H2O)5. g_ex_CuSO4Wt5 = m_ex_CuSO4Wt5*g_m["CuSO4(H2O)5"]; # Grams of excess CuSO4(H2O)5. m_ex_CuSO4Wt1 = m_ex_CuSO4; # Moles of excess CuSO4(H2O)5. g_ex_CuSO4Wt1 = m_ex_CuSO4Wt1*g_m["CuSO4(H2O)1"]; # Grams of excess CuSO4(H2O)1. # Compute how much water is needed to dissolve all CuCl2 at temp {Tf}: v_w_CuCl2 = 100*g_CuCl2/g_w["CuCl2",Tf]; # Water (ml) needed for anhydr CuCl2 soln. g_w_CuCl2 = v_w_CuCl2; # Water (g) needed for anhydr CuCl2 soln. # Purificatin with anhydrous ethanol: # Ignore the water of crystallization: # Assume solubility is 50 g per 100 ml at temp {Tf}: d_Et = 0.789; # Density of ethanol (g/l). v_e_CuCl2 = 100*g_CuCl2/g_e["CuCl2",Tf]; g_e_CuCl2 = v_e_CuCl2*d_Et; # Print the recipe: printf "------------------------------------------------------------\n"; printf "RECIPE\n"; printf "\n"; printf "Copper sulfate saturated solution:\n"; printf " %5.1f g of CuSO4(H2O)5 ", g_CuSO4Wt5; printf "= %5.1f g of CuSO4 (anhydrous)\n", g_CuSO4; printf " %5.1f ml of water\n", v_w_CuSO4Wt5; printf " %5.1f g total weight of solution\n", g_w_CuSO4Wt5 + g_CuSO4Wt5; printf " decantation temp = %3.0f C\n", Ts; printf "\n"; printf "Calcium chloride saturated solution:\n"; printf " %5.1f g of CaCl2 (anhydrous)\n", g_CaCl2; printf " %5.1f ml of water\n", v_w_CaCl2; printf " %5.1f g total weight of solution\n", g_w_CaCl2 + g_CaCl2; printf " decantation temp = %3.0f C\n", Ts; printf "\n"; printf "Reaction result:\n"; printf " reaction temp = %3.0f C\n", Ts; printf " %5.1f g total weight of reaction products\n", g_CaSO4Wt2 + g_w_filtr + g_CuCl2 + g_ex_CuSO4; printf "\n"; printf "Filtration 1:\n"; printf " %5.1f g precipitate of CaSO4(H2O)2\n", g_CaSO4Wt2; printf "\n"; printf " %5.1f g of dissolved CuCl2 (anhydrous)\n", g_CuCl2; printf " %5.1f g of dissolved CuSO4 (anhydrous)\n", g_ex_CuSO4; printf " %5.1f ml of water in filtrate\n", v_w_filtr; printf " %5.1f g total weight of filtrate\n", g_w_filtr + g_CuCl2 + g_ex_CuSO4; printf " filtration 1 temp = %3.0f C\n", Tf; printf "\n"; # Assumes that the CuSO4 will still be in solution after evap step 1 # but the CaSO4 will be mostly precipitated before or during the evaporarion. printf "Concentrated solution after evaporation 1:\n"; printf " %5.1f ml of water\n", v_w_CuCl2; printf " %5.1f g of dissolved CuCl2 (anhydrous)\n", g_CuCl2; printf " %5.1f g of dissolved CuSO4 (anhydrous)\n", g_ex_CuSO4; printf " %5.1f g total weight in concentrated solution\n", g_CuCl2 + g_ex_CuSO4 + g_w_CuCl2; printf " filtration 2 temp = %3.0f C\n", Tf; printf "\n"; printf "Residue after filtration 2 and evaporation 2:\n"; printf " %5.1f g of CuCl2 (anhydrous)\n", g_CuCl2; printf " %5.1f g of CuSO4(H2O)1\n", g_ex_CuSO4Wt1; printf " %5.1f g total weight of residue\n", g_CuCl2 + g_ex_CuSO4Wt1; printf " drying temp = %3.0f C\n", Td; printf "\n"; printf "Purification:\n"; printf " %5.1f ml of ethanol needed to dissolve the CuCl2\n", v_e_CuCl2; printf " %5.1f g of ethanol needed to dissolve the CuCl2\n", g_e_CuCl2; printf " %5.1f g total weight of solution\n", g_e_CuCl2 + g_CuCl2; printf " extraction temp = %3.0f C\n", Tf; printf "------------------------------------------------------------\n" } function fill_molar_mass_table() \ { # Fills the necessary entries of the {g_m} globa table: fill_molar_mass_table_elems(); g_m["H2O"] = 2*g_m["H"] + g_m["O"]; pmm("H2O"); g_m["SO4"] = g_m["S"] + 4*g_m["O"]; pmm("SO4"); g_m["CaCl2"] = g_m["Ca"] + 2*g_m["Cl"]; pmm("CaCl2"); g_m["CaSO4"] = g_m["Ca"] + g_m["SO4"]; pmm("CaSO4"); g_m["CaSO4(H2O)2"] = g_m["CaSO4"] + 2*g_m["H2O"]; pmm("CaSO4(H2O)2"); g_m["CuCl2"] = g_m["Cu"] + 2*g_m["Cl"]; pmm("CuCl2"); g_m["CuCl2(H2O)2"] = g_m["CuCl2"] + 2*g_m["H2O"]; pmm("CuCl2(H2O)2"); g_m["CuSO4"] = g_m["Cu"] + g_m["SO4"]; pmm("CuSO4"); g_m["CuSO4(H2O)1"] = g_m["CuSO4"] + g_m["H2O"]; pmm("CuSO4(H2O)1"); g_m["CuSO4(H2O)5"] = g_m["CuSO4"] + 5*g_m["H2O"]; pmm("CuSO4(H2O)5"); # g_m[""] = ; # g_m["CaCl2"] = 110.98; # g_m["CaCl2.2H2O"] = 147.0; # g_m["CuSO4(H2O)5"] = 249.685; } function pmm(fm) \ { # Prints to {stderr} the molar mass of formula {fm}, # as stored in the global array {g_m}. printf "%-20s molar mass = %8.3f\n", fm, g_m[fm] > "/dev/stderr"; } function pws(fm,T) \ { # Prints to {stderr} the grams of formula {fm} that can be # dissoved in 100 ml of water at temp {T}, # as stored in the global array {g_w}. printf "%-20s sol in H2O = %6.1f g/dl at %4.0f C\n", \ fm, g_w[fm,T], T > "/dev/stderr"; } function fill_ethanol_solubility_table_CaCl2() \ { # Fills the necessary entries of the {g_e} global table: g_e["CaCl2", 0] = 18.3; g_e["CaCl2", 20] = 25.8; g_e["CaCl2", 40] = 35.3; g_e["CaCl2", 70] = 56.2; g_e["CuCl2", 0] = 42.3; g_e["CuCl2", 20] = 50.0; g_e["CuCl2", 40] = 58.3; g_e["CuCl2", 60] = 70.8; # [WP] has g_e["CuCl2",15] = 53.0. Maybe it was 25 C instead. # g_e["", ] = ; } function prog_error(msg) \ { printf "** PROG ERROR:%s\n", msg > "/dev/stderr"; abort = 1; exit(abort); }