Example #1
0
        /// <summary>
        /// Constructor. </summary>
        /// <param name="crop"> StateCU_CropCharacteristics object to display </param>
        /// <param name="editable"> whether the display should be editable or not. </param>
        public StateCU_CropCharacteristics_JFrame(StateCU_DataSet dataset, StateCU_CropCharacteristics crop, bool editable) : base(dataset.getBaseName() + " - StateCU GUI - Crop Characteristics")
        {
            __currentCropIndex = -1;
            __editable         = editable;

            __dataset       = dataset;
            __cropComponent = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_CROP_CHARACTERISTICS);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateCU_CropCharacteristics> cropsVector0 = (java.util.List<StateCU_CropCharacteristics>)__cropComponent.getData();
            IList <StateCU_CropCharacteristics> cropsVector0 = (IList <StateCU_CropCharacteristics>)__cropComponent.getData();

            __cropsVector = cropsVector0;

            __blaneyComponent = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_BLANEY_CRIDDLE);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateCU_BlaneyCriddle> blaneyVector0 = (java.util.List<StateCU_BlaneyCriddle>)__blaneyComponent.getData();
            IList <StateCU_BlaneyCriddle> blaneyVector0 = (IList <StateCU_BlaneyCriddle>)__blaneyComponent.getData();

            __blaneyVector = blaneyVector0;

            string id    = crop.getID();
            int    index = StateCU_Util.IndexOf(__cropsVector, id);

            setupGUI(index);
        }
	/// <summary>
	/// Constructor. </summary>
	/// <param name="title"> Title for JFrame.  If null, an appropriate default is used. </param>
	/// <param name="dataset"> dataset containing data to display </param>
	/// <param name="station"> StateCU_ClimateStation object to display </param>
	/// <param name="editable"> whether the display should be editable or not. </param>
	public StateCU_ClimateStation_JFrame(string title, StateCU_DataSet dataset, StateCU_ClimateStation station, bool editable)
	{
		if (string.ReferenceEquals(title, null))
		{
			setTitle("StateCU Climate Stations");
		}
		else
		{
			setTitle(title);
		}
		__dataset = dataset;
		__currentStationIndex = -1;

		__stationComponent = __dataset.getComponentForComponentType(StateCU_DataSet.COMP_CLIMATE_STATIONS);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateCU_ClimateStation> stationsVector0 = (java.util.List<StateCU_ClimateStation>)__stationComponent.getData();
		IList<StateCU_ClimateStation> stationsVector0 = (IList<StateCU_ClimateStation>)__stationComponent.getData();
		__stationsVector = stationsVector0;

		string id = station.getID();
		int index = StateCU_Util.IndexOf(__stationsVector, id);

		__editable = editable;

		setupGUI(index);
	}
Example #3
0
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateCU_ClimateStation station = (StateCU_ClimateStation)_data.get(row);

            switch (col)
            {
            case __COL_ID:
                return(station.getID());

            case __COL_NAME:
                return(station.getName());

            case __COL_ELEVATION:
                return(new double?(station.getElevation()));

            case __COL_LATITUDE:
                return(new double?(station.getLatitude()));

            case __COL_REGION1:
                return(station.getRegion1());

            case __COL_REGION2:
                return(station.getRegion2());

            case __COL_ZH:
                if (StateCU_Util.isMissing(station.getZh()))
                {
                    return(null);
                }
                else
                {
                    return(new double?(station.getZh()));
                }

            case __COL_ZM:
                if (StateCU_Util.isMissing(station.getZm()))
                {
                    return(null);
                }
                else
                {
                    return(new double?(station.getZm()));
                }
            }

            return("");
        }
	/// <summary>
	/// Processes a table selection (either via a mouse press or programmatically 
	/// from selectTableIndex() by writing the old data back to the data set component
	/// and getting the next selection's data out of the data and displaying it on the form. </summary>
	/// <param name="index"> the index of the reservoir to display on the form. </param>
	private void processTableSelection(int index)
	{
		__lastStationIndex = __currentStationIndex;
		__currentStationIndex = __worksheet.getOriginalRowNumber(index);

		saveLastRecord();

		if (__worksheet.getSelectedRow() == -1)
		{
			nothingSelected();
			return;
		}

		somethingSelected();

		StateCU_ClimateStation station = __stationsVector[__currentStationIndex];

		__stationIDJTextField.setText(station.getID());
		__nameJTextField.setText(station.getName());
		StateCU_Util.checkAndSet(station.getLatitude(), __latitudeJTextField);
		StateCU_Util.checkAndSet(station.getElevation(), __elevationJTextField);
		__region1JTextField.setText(station.getRegion1());
		__region2JTextField.setText(station.getRegion2());
	}
Example #5
0
        /// <summary>
        /// Writes a list of StateCU_BlaneyCriddle objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the Vector of objects to write. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_BlaneyCriddle> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_BlaneyCriddle> data, IList <string> outputComments)
        {
            string routine = "StateCU_BlaneyCriddle.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("Name");
            fields.Add("CurveType");
            fields.Add("DayPercent");
            fields.Add("Coefficient");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_BLANEY_CRIDDLE;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                   j             = 0;
            int                   k             = 0;
            PrintWriter           @out          = null;
            StateCU_BlaneyCriddle bc            = null;
            IList <string>        commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            string        flag   = null;
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU Blaney-Criddle crop coefficients as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    bc   = (StateCU_BlaneyCriddle)data[i];
                    flag = bc.getFlag();
                    if (flag.Equals("Percent", StringComparison.OrdinalIgnoreCase))
                    {
                        for (j = 0; j < 21; j++)
                        {
                            line[0] = StringUtil.formatString(bc.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString(bc.getFlag(), formats[1]).Trim();
                            line[2] = StringUtil.formatString(bc.getNckca(j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(bc.getCkca(j), formats[3]).Trim();

                            buffer = new StringBuilder();
                            for (k = 0; k < fieldCount; k++)
                            {
                                if (k > 0)
                                {
                                    buffer.Append(delimiter);
                                }
                                if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                                {
                                    line[k] = "\"" + line[k] + "\"";
                                }
                                buffer.Append(line[k]);
                            }
                            @out.println(buffer.ToString());
                        }
                    }
                    else
                    {
                        for (j = 0; j < 25; j++)
                        {
                            line[0] = StringUtil.formatString(bc.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString(bc.getFlag(), formats[1]).Trim();
                            line[2] = StringUtil.formatString(bc.getNckcp(j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(bc.getCkcp(j), formats[3]).Trim();

                            buffer = new StringBuilder();
                            for (k = 0; k < fieldCount; k++)
                            {
                                if (k > 0)
                                {
                                    buffer.Append(delimiter);
                                }
                                if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                                {
                                    line[k] = "\"" + line[k] + "\"";
                                }
                                buffer.Append(line[k]);
                            }
                            @out.println(buffer.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
                @out = null;
            }
        }
Example #6
0
        /// <summary>
        /// Write a list of StateCU_BlaneyCriddle to an opened file. </summary>
        /// <param name="data_Vector"> A Vector of StateCU_BlaneyCriddle to write. </param>
        /// <param name="out"> output PrintWriter. </param>
        /// <param name="props"> Properties to control the output.  Currently only the
        /// optional Precision property can be set, indicating how many digits after the
        /// decimal should be printed (default is 3). </param>
        /// <exception cref="IOException"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void writeVector(java.util.List<StateCU_BlaneyCriddle> data_Vector, java.io.PrintWriter out, RTi.Util.IO.PropList props) throws java.io.IOException
        private static void writeVector(IList <StateCU_BlaneyCriddle> data_Vector, PrintWriter @out, PropList props)
        {
            int    i, j;
            string cmnt = "#>";
            // Missing data are handled by formatting all as strings (blank if necessary).
            bool version10 = false;     // Indicate if old Version 10 format is written

            if (props == null)
            {
                props = new PropList("StateCU_BlaneyCriddle");
            }
            string Precision = props.getValue("Precision");
            string Version   = props.getValue("Version");

            if (!string.ReferenceEquals(Version, null) && Version.Equals("10"))
            {
                // Version 10 is an older version.
                version10 = true;
            }

            int Precision_int = 3;

            if ((!string.ReferenceEquals(Precision, null)) && StringUtil.isInteger(Precision))
            {
                Precision_int = StringUtil.atoi(Precision);
            }

            @out.println(cmnt);
            @out.println(cmnt + "  StateCU Blaney-Criddle Crop Coefficient (KBC) File");
            @out.println(cmnt);
            @out.println(cmnt + "  Record 1 format (a80)");
            @out.println(cmnt);
            @out.println(cmnt + "  Title     remark:  Title");
            @out.println(cmnt);
            @out.println(cmnt + "  Record 2 format (free format)");
            @out.println(cmnt);
            @out.println(cmnt + "  NumCurves     nc:  Number of crop coefficient curves");
            @out.println(cmnt);
            @out.println(cmnt + "  Record 3 format (free format)");
            @out.println(cmnt);
            @out.println(cmnt + "  ID            id:  Crop number (not used by StateCU)");
            @out.println(cmnt + "  CropName   cropn:  Crop name (e.g., ALFALFA)");
            @out.println(cmnt + "  CurveType   flag:  Growth curve type");
            @out.println(cmnt + "                     Day = perennial; specify 25 values");
            @out.println(cmnt + "                           for start, middle, end of month");
            @out.println(cmnt + "                     Percent = annual; specify 21 values");
            @out.println(cmnt + "                           for 0, 5, ..., 100% of season");
            @out.println(cmnt);
            if (!version10)
            {
                // Include newer format information...
                @out.println(cmnt + "  BCMethod    ktsw:  Blaney-Criddle Method");
                @out.println(cmnt + "                     0 = SCS Modified Blaney-Criddle");
                @out.println(cmnt + "                     1 = Original Blaney-Criddle");
                @out.println(cmnt + "                     2 = Modifed Blaney-Criddle w/ Elev. Adj.");
                @out.println(cmnt + "                     3 = Original Blaney-Criddle w/ Elev. Adj.");
                @out.println(cmnt + "                     4 = Pochop");
                @out.println(cmnt);
            }
            @out.println(cmnt + "  Record 4 format (free format)");
            @out.println(cmnt);
            @out.println(cmnt + "Position     nckca:  Percent (0 to 100) of growing season for annual crop");
            @out.println(cmnt + "             nckcp:  Day of year (1 to 366) for perennial crop");
            @out.println(cmnt + "Coeff         ckca:  Crop coefficient for annual crop");
            @out.println(cmnt + "         OR   ckcp:  Crop coefficient for perennial crop");
            @out.println(cmnt);
            @out.println(cmnt + "Title...");
            @out.println(cmnt + "NumCurves");
            @out.println(cmnt + "ID CropName CurveType");
            @out.println(cmnt + "Position Coeff");
            @out.println(cmnt + "----------------------------");
            @out.println(cmnt + "EndHeader");
            @out.println("Crop Coefficient Curves for Blaney-Criddle");

            int num = 0;

            if (data_Vector != null)
            {
                num = data_Vector.Count;
            }
            @out.println(num);
            StateCU_BlaneyCriddle kbc = null;

            int[]    nckca        = null;
            int[]    nckcp        = null;
            double[] ckca         = null;
            double[] ckcp         = null;
            int      size         = 0;
            string   value_format = "%9." + Precision_int + "f";

            for (i = 0; i < num; i++)
            {
                kbc = (StateCU_BlaneyCriddle)data_Vector[i];
                if (kbc == null)
                {
                    continue;
                }

                // Just get all the data.  Null arrays are used as a check
                // below to know what data to output...
                nckca = kbc.getNckca();
                nckcp = kbc.getNckcp();
                ckca  = kbc.getCkca();
                ckcp  = kbc.getCkcp();

                // Do not truncate the name to 20 characters if version 10 because
                // doing so may result in arbitrary cut of the current crop names and
                // result in different output from old anyhow.
                string name = kbc.getName();
                // Since free format, the ID must always have something.  If
                // we don't know, put -999...
                string id = "" + (i + 1);         // Default to sequential number
                if (version10)
                {
                    // Previously used -999
                    id = "-999";
                }
                if (!StateCU_Util.isMissing(kbc.getID()))
                {
                    // Changes elsewhere impact this so also use -999 unless it is a number
                    if (StringUtil.isInteger(kbc.getID()))
                    {
                        id = "" + kbc.getID();
                    }
                    else
                    {
                        id = "-999";
                    }
                    // Can't use the crop name because StateCU expects a number (?)
                    //id = kbc.getID();
                }
                // Output based on the version because file comparisons may be done when verifying files.
                if (version10)
                {
                    // No ktsw...
                    @out.println(id + " " + name + " " + kbc.getFlag());
                }
                else
                {
                    // With ktsw, but OK if blank.
                    @out.println(id + " " + name + " " + kbc.getFlag() + " " + kbc.getKtsw());
                }

                if (nckca != null)
                {
                    size = nckca.Length;
                }
                else
                {
                    size = nckcp.Length;
                }
                for (j = 0; j < size; j++)
                {
                    if (nckca != null)
                    {
                        // Print annual curve (Percent)...
                        @out.println(StringUtil.formatString(nckca[j], "%-3d") + StringUtil.formatString(ckca[j], value_format));
                    }
                    else
                    {
                        // Print perennial curve (Day)...
                        @out.println(StringUtil.formatString((int)nckcp[j], "%-3d") + StringUtil.formatString(ckcp[j], value_format));
                    }
                }
            }
        }
        /// <summary>
        /// Writes a list of StateCU_ClimateStation objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current </param>
        /// header (true) or to create a new file with a new header<param name="data"> the Vector of objects to write. </param>
        /// <param name="outputComments"> Comments to add to the header, usually the command file and database information. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_ClimateStation> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_ClimateStation> data, IList <string> outputComments)
        {
            int size = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("Latitude");
            fields.Add("Elevation");
            fields.Add("Region1");
            fields.Add("Region2");
            fields.Add("HeightHumidity");
            fields.Add("HeightWind");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_CLIMATE_STATIONS;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                    j             = 0;
            PrintWriter            @out          = null;
            StateCU_ClimateStation cli           = null;
            IList <string>         commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU climate stations as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    buffer.Append("\"" + names[i] + "\"");
                    if (i < (fieldCount - 1))
                    {
                        buffer.Append(delimiter);
                    }
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    cli = data[i];

                    line[0] = StringUtil.formatString(cli.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(cli.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(cli.getLatitude(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(cli.getElevation(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(cli.getRegion1(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(cli.getRegion2(), formats[5]).Trim();
                    line[6] = StringUtil.formatString(cli.getZh(), formats[6]).Trim();
                    line[7] = StringUtil.formatString(cli.getZm(), formats[7]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                        if (j < (fieldCount - 1))
                        {
                            buffer.Append(delimiter);
                        }
                    }

                    @out.println(buffer.ToString());
                }
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
        /// <summary>
        /// Write a list of StateCU_ClimateStation to an opened file. </summary>
        /// <param name="dataList"> A list of StateCU_ClimateStation to write. </param>
        /// <param name="out"> output PrintWriter. </param>
        /// <exception cref="IOException"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void writeStateCUFile(java.util.List<StateCU_ClimateStation> dataList, java.io.PrintWriter out) throws java.io.IOException
        private static void writeStateCUFile(IList <StateCU_ClimateStation> dataList, PrintWriter @out)
        {
            int    i;
            string iline;
            string cmnt = "#>";
            // Missing data handled by formatting all as strings...
            string         format = "%-12.12s%6.6s%9.9s  %-20.20s%-8.8s  %-24.24s%8.8s%8.8s";
            IList <object> v      = new List <object>(8); // Reuse for all output lines.

            @out.println(cmnt);
            @out.println(cmnt + "  StateCU Climate Stations File");
            @out.println(cmnt);
            @out.println(cmnt + "  Record format (a12,f6.2,f9.2,2x,a20,a8,2x,a24,8.2f,2.2f)");
            @out.println(cmnt);
            @out.println(cmnt + "  StationID:  Station identifier (e.g., 3951)");
            @out.println(cmnt + "        Lat:  Latitude (decimal degrees)");
            @out.println(cmnt + "       Elev:  Elevation (feet)");
            @out.println(cmnt + "    Region1:  Region1 (e.g., County)");
            @out.println(cmnt + "    Region2:  Region2 (e.g., Hydrologic Unit Code, HUC)");
            @out.println(cmnt + "StationName:  Station name");
            @out.println(cmnt + "     zHumid:  Height of humidity and temperature measurements (feet, daily analysis only)");
            @out.println(cmnt + "      zWind:  Height of wind speed measurement (feet, daily analysis only)");
            @out.println(cmnt);
            @out.println(cmnt + " StationID  Lat   Elev            Region1      Region2        StationName         zHumid  zWind");
            @out.println(cmnt + "---------eb----eb-------exxb------------------eb------exxb----------------------eb------eb------e");
            @out.println(cmnt + "EndHeader");

            int num = 0;

            if (dataList != null)
            {
                num = dataList.Count;
            }
            StateCU_ClimateStation sta = null;

            for (i = 0; i < num; i++)
            {
                sta = dataList[i];
                if (sta == null)
                {
                    continue;
                }

                v.Clear();
                v.Add(sta._id);
                // Latitude...
                if (StateCU_Util.isMissing(sta.__latitude))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__latitude, "%6.2f"));
                }
                // Elevation...
                if (StateCU_Util.isMissing(sta.__elevation))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__elevation, "%9.2f"));
                }
                v.Add(sta.__region1);
                v.Add(sta.__region2);
                v.Add(sta._name);
                // zh...
                if (StateCU_Util.isMissing(sta.__zh))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__zh, "%8.2f"));
                }
                // zm...
                if (StateCU_Util.isMissing(sta.__zm))
                {
                    v.Add("");
                }
                else
                {
                    v.Add(StringUtil.formatString(sta.__zm, "%8.2f"));
                }

                iline = StringUtil.formatString(v, format);
                @out.println(iline);
            }
        }
        /// <summary>
        /// From AbstractTableMode.  Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            if (__singleLocation)
            {
                switch (col)
                {
                case 1:
                case 2:
                    StateCU_Location location = (StateCU_Location)_data.get(row);
                    switch (col)
                    {
                    case 1:
                        return(location.getID());

                    case 2:
                        return(location.getName());
                    }

                case 3:
                    return(new double?(__delays.getDelayTablePercent(row)));

                case 4:
                    return(__delays.getDelayTableID(row));

                case 5:
                    return(__parentLocation.getClimateStationID(row));

                case 6:
                    int index = StateCU_Util.IndexOf(__stations, __parentLocation.getClimateStationID(row));
                    if (index == -1)
                    {
                        return("N/A");
                    }
                    return(((StateCU_ClimateStation)__stations[row]).getName());

                case 7:
                    return(new double?(__parentLocation.getPrecipitationStationWeight(row)));

                case 8:
                    return(new double?(__parentLocation.getTemperatureStationWeight(row)));

                case 9:
                case 10:
                case 11:
                case 12:
                case 13:
                    StateMod_DiversionRight right = (StateMod_DiversionRight)__rights[row];
                    switch (col)
                    {
                    case 9:
                        return(right.getID());

                    case 10:
                        return(right.getName());

                    case 11:
                        return(Convert.ToDouble(right.getIrtem()));

                    case 12:
                        return(new double?(right.getDcrdiv()));

                    case 13:
                        return(new int?(right.getSwitch()));
                    }

                default:
                    return("");
                }
            }
            else
            {
                StateCU_Location location = (StateCU_Location)_data.get(row);
                switch (col)
                {
                case __COL_ID:
                    return(location.getID());

                case __COL_NAME:
                    return(location.getName());

                case __COL_ELEVATION:
                    return(new double?(location.getElevation()));

                case __COL_LATITUDE:
                    return(new double?(location.getLatitude()));

                case __COL_REGION1:
                    return(location.getRegion1());

                case __COL_REGION2:
                    return(location.getRegion2());

                case __COL_NUM_STA:
                    return(new int?(location.getNumClimateStations()));

                case __COL_AWC:
                    return(new double?(location.getAwc()));
                }
            }
            return("");
        }
Example #10
0
        /// <summary>
        /// Processes a table selection (either via a mouse press or programmatically
        /// from selectTableIndex() by writing the old data back to the data set component
        /// and getting the next selection's data out of the data and displaying it
        /// on the form. </summary>
        /// <param name="index"> the index of the reservoir to display on the form. </param>
        private void processTableSelection(int index)
        {
            __lastCropIndex    = __currentCropIndex;
            __currentCropIndex = __worksheet.getOriginalRowNumber(index);

            saveLastRecord();

            if (__worksheet.getSelectedRow() == -1)
            {
                nothingSelected();
                return;
            }

            somethingSelected();

            StateCU_CropCharacteristics crop = (StateCU_CropCharacteristics)__cropsVector[__currentCropIndex];

            __cropIDJTextField.setText(crop.getID());
            __nameJTextField.setText(crop.getName());
            StateCU_Util.checkAndSet(crop.getGdate1(), __plantMonthJTextField);
            StateCU_Util.checkAndSet(crop.getGdate2(), __plantDayJTextField);
            StateCU_Util.checkAndSet(crop.getGdate3(), __harvestMonthJTextField);
            StateCU_Util.checkAndSet(crop.getGdate4(), __harvestDayJTextField);
            StateCU_Util.checkAndSet(crop.getGdate5(), __daysToCoverJTextField);
            StateCU_Util.checkAndSet(crop.getGdates(), __seasonLengthJTextField);
            StateCU_Util.checkAndSet(crop.getTmois1(), __earliestValueJTextField);
            StateCU_Util.checkAndSet(crop.getTmois2(), __latestValueJTextField);
            StateCU_Util.checkAndSet(crop.getFrx(), __maxRootFeetJTextField);
            StateCU_Util.checkAndSet(crop.getApd(), __maxAppDepthJTextField);
            StateCU_Util.checkAndSet(crop.getCut2(), __firstDaysBetweenJTextField);
            StateCU_Util.checkAndSet(crop.getCut3(), __secondDaysBetweenJTextField);

            int flag = crop.getTflg1();

            if (flag == -999)
            {
                flag = 3;
            }
            __earliestFlagComboBox.select(flag);

            flag = crop.getTflg2();
            if (flag == -999)
            {
                flag = 3;
            }
            __latestFlagComboBox.select(flag);

            int bcindex = StateCU_Util.indexOfName(__blaneyVector, crop.getID());
            StateCU_BlaneyCriddle bc = null;

            if (bcindex != -1)
            {
                bc = (StateCU_BlaneyCriddle)__blaneyVector[bcindex];
                if (bc.getFlag().Equals("Percent", StringComparison.OrdinalIgnoreCase))
                {
                    __coeffWorksheet.setColumnName(3, "PERCENT");
                }
                else
                {
                    __coeffWorksheet.setColumnName(3, "DAY");
                }
            }
            __blaneyModel.setBlaneyCriddle(bc);
        }
Example #11
0
        /// <summary>
        /// Writes a list of StateCU_PenmanMonteith objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the file.
        /// Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_PenmanMonteith> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_PenmanMonteith> data, IList <string> outputComments)
        {
            string routine = "StateCU_PenmanMonteith.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("Name");
            fields.Add("GrowthStage");
            fields.Add("Percent");
            fields.Add("Coefficient");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_PENMAN_MONTEITH;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int            j             = 0;
            int            k             = 0;
            PrintWriter    @out          = null;
            IList <string> commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU Penman-Monteith crop coefficients as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());
                StateCU_PenmanMonteith kpm;
                for (int i = 0; i < size; i++)
                {
                    kpm = data[i];
                    int ngs   = kpm.getNGrowthStages();
                    int ncpgs = StateCU_PenmanMonteith.getNCoefficientsPerGrowthStage();
                    for (int igs = 0; igs < ngs; igs++)
                    {
                        for (j = 0; j < ncpgs; j++)
                        {
                            line[0] = StringUtil.formatString(kpm.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString((igs + 1), formats[1]).Trim();
                            line[2] = StringUtil.formatString(kpm.getKcday(igs, j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(kpm.getKcb(igs, j), formats[3]).Trim();

                            buffer = new StringBuilder();
                            for (k = 0; k < fieldCount; k++)
                            {
                                if (k > 0)
                                {
                                    buffer.Append(delimiter);
                                }
                                if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                                {
                                    line[k] = "\"" + line[k] + "\"";
                                }
                                buffer.Append(line[k]);
                            }
                            @out.println(buffer.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
                @out = null;
            }
        }
        /// <summary>
        /// Writes a list of StateCU_DelayTableAssignment objects to a list file.  A
        /// header is printed to the top of the file, containing the commands used to
        /// generate the file.  Any strings in the body of the file that contain the field
        /// delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the Vector of objects to write. </param>
        /// <param name="newComments"> comments to add to the top of the file (e.g., command file and HydroBase version). </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_DelayTableAssignment> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_DelayTableAssignment> data, IList <string> newComments)
        {
            string routine = "StateCU_DelayTableAssignment.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("DelayTableID");
            fields.Add("Percent");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_DELAY_TABLE_ASSIGNMENT_MONTHLY;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int         j    = 0;
            int         k    = 0;
            int         num  = 0;
            PrintWriter @out = null;
            StateCU_DelayTableAssignment dly = null;
            IList <string> commentString     = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            string        id     = null;
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU location delay table assignment information as a delimited list file.");
                newComments2.Insert(2, "See also the associated CU location file.");
                newComments2.Insert(3, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    dly = (StateCU_DelayTableAssignment)data[i];

                    num = dly.getNumDelayTables();
                    id  = dly.getID();

                    for (j = 0; j < num; j++)
                    {
                        line[0] = StringUtil.formatString(id, formats[0]).Trim();
                        line[1] = StringUtil.formatString(dly.getDelayTableID(j), formats[1]).Trim();
                        line[2] = StringUtil.formatString(dly.getDelayTablePercent(j), formats[2]).Trim();

                        buffer = new StringBuilder();
                        for (k = 0; k < fieldCount; k++)
                        {
                            if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                            {
                                line[k] = "\"" + line[k] + "\"";
                            }
                            if (k > 0)
                            {
                                buffer.Append(delimiter);
                            }
                            buffer.Append(line[k]);
                        }

                        @out.println(buffer.ToString());
                    }
                }
                @out.flush();
                @out.close();
                @out = null;
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }