コード例 #1
0
ファイル: Equation.cs プロジェクト: tcooc/ChemtoolsCs
        //returns an equivalent formula that takes into account all
        //formulas and coefficients
        //i.e. [O2,2H2] results in H4O2
        private static Formula CountMolecules(Formula[] formulas, int[] coeff)
        {
            Formula f = new Formula();

            for (int i = 0; i < formulas.Length; i++)
            {
                //creates new equivalent formula without coefficient
                Formula f2 = new Formula(formulas[i]);
                //merges the formula into f
                f.MergeFormula(f2.Factor(coeff[i]));
            }
            return(f);
        }
コード例 #2
0
        //gets a Formula starting from next
        //hydrates arent handled
        private Formula GetFormula()
        {
            Formula formula = new Formula();

            while (BoundCheck)
            {
                //end inner formula, return this
                if (chars[next] == ')')
                {
                    Next();
                    return(formula);
                }
                //start inner formula
                else if (chars[next] == '(')
                {
                    Next();
                    //gets formula
                    Formula f1 = GetFormula();
                    //gets the number after the closing parens
                    //i.e. get 7 from (CO2)7
                    if (f1 == null)
                    {
                        return(null);
                    }
                    int n = GetNumber();
                    //adds it to the main formula
                    formula.MergeFormula(f1.Factor(n));
                }
                //start symbol
                else if (char.IsUpper(chars[next]))
                {
                    Element e = GetSymbol();
                    if (e == null)
                    {
                        continue;
                    }
                    int n = GetNumber();
                    formula.Add(new NElements(n, e));
                    //error or end of data
                }
                else
                {
                    return(null);
                }
            }
            return(formula);
        }
コード例 #3
0
ファイル: Equation.cs プロジェクト: tcooc/ChemtoolsCs
 //returns an equivalent formula that takes into account all
 //formulas and coefficients
 //i.e. [O2,2H2] results in H4O2
 private static Formula CountMolecules(Formula[] formulas, int[] coeff)
 {
     Formula f = new Formula();
     for(int i = 0; i < formulas.Length; i++) {
         //creates new equivalent formula without coefficient
         Formula f2 = new Formula(formulas[i]);
         //merges the formula into f
         f.MergeFormula(f2.Factor(coeff[i]));
     }
     return f;
 }