/// <summary>
        /// Inserts the specified value into the table at the given position. </summary>
        /// <param name="value"> the object to store in the table cell. </param>
        /// <param name="row"> the row of the cell in which to place the object. </param>
        /// <param name="col"> the column of the cell in which to place the object. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            int dataPos = lookupVectorPositionForRow(row);

            StateCU_PenmanMonteith pm = (StateCU_PenmanMonteith)_data.get(dataPos);

            // Row position in the data object...
            int num = row - __cropFirstRows[dataPos];
            // Which growth stage (0+ index)
            int igs = num / StateCU_PenmanMonteith.getNCoefficientsPerGrowthStage();
            // Which value in the growth stage
            int ipos = num - igs * StateCU_PenmanMonteith.getNCoefficientsPerGrowthStage();

            switch (col)
            {
            case __COL_CROP_NAME:
                pm.setName((string)value);
                break;

            case __COL_GROWTH_STAGE:
                /* TODO SAM 2010-03-31 Not editable...
                 * int gsval = ((Integer)value).intValue();
                 * pm.setKtsw( gsval );
                 */
                break;

            case __COL_PERCENT:
                double percent = ((double?)value).Value;
                pm.setCurvePosition(igs, ipos, percent);
                break;

            case __COL_COEFF:
                double coeff = ((double?)value).Value;
                pm.setCurveValue(igs, ipos, coeff);
                break;
            }

            base.setValueAt(value, row, col);
        }
Example #2
0
        /// <summary>
        /// Read the StateCU KPM file and return as a list of StateCU_PenmanMonteith. </summary>
        /// <param name="filename"> filename containing KPM records. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateCU_PenmanMonteith> readStateCUFile(String filename) throws java.io.IOException
        public static IList <StateCU_PenmanMonteith> readStateCUFile(string filename)
        {
            string rtn   = "StateCU_PenmanMonteith.readStateCUFile";
            string iline = null;
            StateCU_PenmanMonteith         kpm     = null;
            IList <StateCU_PenmanMonteith> kpmList = new List <StateCU_PenmanMonteith>(25);
            StreamReader @in     = null;
            int          lineNum = 0;

            Message.printStatus(1, rtn, "Reading StateCU KPM file: " + filename);
            try
            {
                // The following throws an IOException if the file cannot be opened...
                @in = new StreamReader(filename);
                int    nc    = -1;
                string title = null;         // The title is currently read but not stored since it is never really used for anything.
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++lineNum;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }
                    if (string.ReferenceEquals(title, null))
                    {
                        title = iline;
                    }
                    else if (nc < 0)
                    {
                        // Assume that the line contains the number of crops
                        nc = int.Parse(iline.Trim());
                        break;
                    }
                }

                // Now loop through the number of curves...

                // TODO SAM 2010-03-30 Evaluate if needed
                //String id;
                string         cropn;
                IList <string> tokens;
                int            j = 0;
                // Read the number of curves (crops)
                for (int i = 0; i < nc; i++)
                {
                    // Read a free format line...
                    iline = @in.ReadLine();
                    ++lineNum;

                    tokens = StringUtil.breakStringList(iline.Trim(), " \t", StringUtil.DELIM_SKIP_BLANKS);
                    // TODO SAM 2007-02-18 Evaluate if needed
                    //id = tokens.elementAt(0);
                    cropn = tokens[1];

                    // Allocate new StateCU_PenmanMonteith instance...

                    int ngs = getNGrowthStagesFromCropName(cropn);
                    kpm = new StateCU_PenmanMonteith(ngs);
                    // Number of coefficients per growth stage...
                    int ncpgs = StateCU_PenmanMonteith.getNCoefficientsPerGrowthStage();
                    kpm.setName(cropn);
                    // TODO SAM 2005-05-22 Ignore the old ID and use the crop name - this facilitates
                    // sorting and other standard StateCU_Data features.
                    //kbc.setID ( id );
                    kpm.setID(cropn);

                    // Read the coefficients...
                    for (int igs = 0; igs < ngs; igs++)
                    {
                        for (j = 0; j < ncpgs; j++)
                        {
                            iline = @in.ReadLine();
                            ++lineNum;
                            tokens = StringUtil.breakStringList(iline.Trim(), " \t", StringUtil.DELIM_SKIP_BLANKS);
                            kpm.setCurvePosition(igs, j, double.Parse(tokens[0]));
                            kpm.setCurveValue(igs, j, double.Parse(tokens[1]));
                        }
                    }

                    // add the StateCU_PenmanMonteith to the list...
                    kpmList.Add(kpm);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, rtn, "Error reading file (" + e + ").");
                Message.printWarning(3, rtn, e);
                throw new IOException("Error reading file \"" + filename + "\" near line " + lineNum);
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(kpmList);
        }