/// <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]; } StateMod_InstreamFlow isf = (StateMod_InstreamFlow)_data.get(row); switch (col) { case COL_ID: return(isf.getID()); case COL_NAME: return(isf.getName()); case COL_DAILY_ID: return(isf.getCifridy()); case COL_DOWN_NODE: return(isf.getIfrrdn()); case COL_DEMAND_TYPE: return(new int?(isf.getIifcom())); default: return(""); } }
/// <summary> /// Sets the value at the specified position to the specified value. </summary> /// <param name="value"> the value to set the cell to. </param> /// <param name="row"> the row of the cell for which to set the value. </param> /// <param name="col"> the col of the cell for which to set the value. </param> public virtual void setValueAt(object value, int row, int col) { if (_sortOrder != null) { row = _sortOrder[row]; } StateMod_InstreamFlow isf = (StateMod_InstreamFlow)_data.get(row); switch (col) { case COL_ID: isf.setID((string)value); break; case COL_NAME: isf.setName((string)value); break; case COL_DAILY_ID: isf.setCifridy((string)value); break; case COL_DOWN_NODE: isf.setIfrrdn((string)value); break; case COL_DEMAND_TYPE: isf.setIifcom(((int?)value).Value); break; } base.setValueAt(value, row, col); }
/// <summary> /// Compares this object to another StateMod_InstreamFlow object. </summary> /// <param name="data"> the object to compare against. </param> /// <returns> 0 if they are the same, 1 if this object is greater than the other object, or -1 if it is less. </returns> public virtual int CompareTo(StateMod_Data data) { int res = base.CompareTo(data); if (res != 0) { return(res); } StateMod_InstreamFlow i = (StateMod_InstreamFlow)data; res = _cifridy.CompareTo(i._cifridy); if (res != 0) { return(res); } res = _ifrrdn.CompareTo(i._ifrrdn); if (res != 0) { return(res); } if (_iifcom < i._iifcom) { return(-1); } else if (_iifcom > i._iifcom) { return(1); } return(0); }
/// <summary> /// Performs data checks on instream flow station data. </summary> /// <param name="props"> A property list for specific properties /// on checking this data. </param> /// <param name="data_vector"> Vector of data to check. </param> private void checkInstreamFlowStationData(PropList props, System.Collections.IList data_vector) { // Create elements for the checks and check file string[] header = StateMod_InstreamFlow.getDataHeader(); System.Collections.IList data = new List <object>(); string title = "Instream Flow Station"; // Perform the general validation using the Data Table Model StateMod_Data_TableModel tm = new StateMod_InstreamFlow_Data_TableModel(data_vector, false); System.Collections.IList @checked = performDataValidation(tm, title); //String [] columnHeader = getDataTableModelColumnHeader( tm ); string[] columnHeader = getColumnHeader(tm); // Do specific checks int size = 0; if (data_vector != null) { size = data_vector.Count; } data = doSpecificDataChecks(data_vector, props); // Add the data and checks to the check file. // Provides basic header information for this data check table string info = "The following " + title + " (" + data.Count + " out of " + size + ") have no ....."; // Create data models for Check file CheckFile_DataModel dm = new CheckFile_DataModel(data, header, title, info, data.Count, size); CheckFile_DataModel gen_dm = new CheckFile_DataModel(@checked, columnHeader, title + " Missing or Invalid Data", "", __gen_problems, size); __check_file.addData(dm, gen_dm); }
/// <summary> /// Called when the Apply button is pressed. This commits any changes to the data /// objects. /// </summary> protected internal override void apply() { StateMod_InstreamFlow isf = null; int size = _data.Count; for (int i = 0; i < size; i++) { isf = (StateMod_InstreamFlow)_data[i]; isf.createBackup(); } }
/// <summary> /// Called when the cancel button is pressed. This discards any changes made to /// the data objects. /// </summary> protected internal override void cancel() { StateMod_InstreamFlow isf = null; int size = _data.Count; for (int i = 0; i < size; i++) { isf = (StateMod_InstreamFlow)_data[i]; isf.restoreOriginal(); } }
/// <summary> /// Cancels any changes made to this object within a GUI since createBackup() /// was called and sets _original to null. /// </summary> public override void restoreOriginal() { StateMod_InstreamFlow i = (StateMod_InstreamFlow)_original; base.restoreOriginal(); _cifridy = i._cifridy; _ifrrdn = i._ifrrdn; _iifcom = i._iifcom; _original = null; _isClone = false; }
/// <summary> /// Constructor. </summary> /// <param name="dataset"> the dataset in which the data is contained. </param> /// <param name="insf"> the InstreamFlow right to display. </param> /// <param name="editable"> whether the gui data is editable or not </param> public StateMod_InstreamFlow_Right_JFrame(StateMod_DataSet dataset, StateMod_InstreamFlow insf, bool editable) { StateMod_GUIUtil.setTitle(this, dataset, insf.getName() + " - Instream Flow Water Rights", null); JGUIUtil.setIcon(this, JGUIUtil.getIconImage()); __currentInstreamFlow = insf; __dataset = dataset; __editable = editable; setupGUI(); }
/// <summary> /// Clones the data object. </summary> /// <returns> a cloned object. </returns> public override object clone() { StateMod_InstreamFlow i = (StateMod_InstreamFlow)base.clone(); i._isClone = true; // The following are not cloned because there is no need to. // The cloned values are only used for comparing between the // values that can be changed in a single GUI. The following // lists' data have their changes committed in other GUIs. i._rights = _rights; return(i); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void saveComponent(RTi.Util.IO.DataSetComponent comp, String oldFilename,String newFilename, java.util.List<String> comments) throws Exception private void saveComponent(DataSetComponent comp, string oldFilename, string newFilename, IList <string> comments) { bool daily = false; int type = comp.getComponentType(); object data = comp.getData(); string name = null; switch (type) { //////////////////////////////////////////////////////// // StateMod_* classes case StateMod_DataSet.COMP_CONTROL: StateMod_DataSet.writeStateModControlFile(__dataset, oldFilename, newFilename, comments); name = "Control"; break; case StateMod_DataSet.COMP_DELAY_TABLES_DAILY: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DelayTable> delayTablesDaily = (java.util.List<StateMod_DelayTable>)data; IList <StateMod_DelayTable> delayTablesDaily = (IList <StateMod_DelayTable>)data; StateMod_DelayTable.writeStateModFile(oldFilename, newFilename, delayTablesDaily, comments, __dataset.getInterv(), -1); name = "Delay Tables Daily"; break; case StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DelayTable> delayTablesMonthly = (java.util.List<StateMod_DelayTable>)data; IList <StateMod_DelayTable> delayTablesMonthly = (IList <StateMod_DelayTable>)data; StateMod_DelayTable.writeStateModFile(oldFilename, newFilename, delayTablesMonthly, comments, __dataset.getInterv(), -1); name = "Delay Tables Monthly"; break; case StateMod_DataSet.COMP_DIVERSION_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Diversion> diversionStations = (java.util.List<StateMod_Diversion>)data; IList <StateMod_Diversion> diversionStations = (IList <StateMod_Diversion>)data; StateMod_Diversion.writeStateModFile(oldFilename, newFilename, diversionStations, comments, daily); name = "Diversion"; break; case StateMod_DataSet.COMP_DIVERSION_RIGHTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_DiversionRight> diversionRights = (java.util.List<StateMod_DiversionRight>)data; IList <StateMod_DiversionRight> diversionRights = (IList <StateMod_DiversionRight>)data; StateMod_DiversionRight.writeStateModFile(oldFilename, newFilename, diversionRights, comments, daily); name = "Diversion Rights"; break; case StateMod_DataSet.COMP_INSTREAM_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_InstreamFlow> instreamFlow = (java.util.List<StateMod_InstreamFlow>)data; IList <StateMod_InstreamFlow> instreamFlow = (IList <StateMod_InstreamFlow>)data; StateMod_InstreamFlow.writeStateModFile(oldFilename, newFilename, instreamFlow, comments, daily); name = "Instream"; break; case StateMod_DataSet.COMP_INSTREAM_RIGHTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_InstreamFlowRight> instreamFlowRights = (java.util.List<StateMod_InstreamFlowRight>)data; IList <StateMod_InstreamFlowRight> instreamFlowRights = (IList <StateMod_InstreamFlowRight>)data; StateMod_InstreamFlowRight.writeStateModFile(oldFilename, newFilename, instreamFlowRights, comments); name = "Instream Rights"; break; case StateMod_DataSet.COMP_OPERATION_RIGHTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_OperationalRight> operationalRights = (java.util.List<StateMod_OperationalRight>)data; IList <StateMod_OperationalRight> operationalRights = (IList <StateMod_OperationalRight>)data; // 2 is the file version (introduced for StateMod version 12 change) StateMod_OperationalRight.writeStateModFile(oldFilename, newFilename, 2, operationalRights, comments, __dataset); name = "Operational Rights"; break; case StateMod_DataSet.COMP_PLANS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Plan> planStations = (java.util.List<StateMod_Plan>)data; IList <StateMod_Plan> planStations = (IList <StateMod_Plan>)data; StateMod_Plan.writeStateModFile(oldFilename, newFilename, planStations, comments); name = "Plan"; break; case StateMod_DataSet.COMP_RESERVOIR_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Reservoir> reservoirStations = (java.util.List<StateMod_Reservoir>)data; IList <StateMod_Reservoir> reservoirStations = (IList <StateMod_Reservoir>)data; StateMod_Reservoir.writeStateModFile(oldFilename, newFilename, reservoirStations, comments, daily); name = "Reservoir"; break; case StateMod_DataSet.COMP_RESERVOIR_RIGHTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReservoirRight> reservoirRights = (java.util.List<StateMod_ReservoirRight>)data; IList <StateMod_ReservoirRight> reservoirRights = (IList <StateMod_ReservoirRight>)data; StateMod_ReservoirRight.writeStateModFile(oldFilename, newFilename, reservoirRights, comments); name = "Reservoir Rights"; break; case StateMod_DataSet.COMP_RESPONSE: StateMod_DataSet.writeStateModFile(__dataset, oldFilename, newFilename, comments); name = "Response"; break; case StateMod_DataSet.COMP_RIVER_NETWORK: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_RiverNetworkNode> riverNodes = (java.util.List<StateMod_RiverNetworkNode>)data; IList <StateMod_RiverNetworkNode> riverNodes = (IList <StateMod_RiverNetworkNode>)data; StateMod_RiverNetworkNode.writeStateModFile(oldFilename, newFilename, riverNodes, comments, true); name = "River Network"; break; case StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamEstimate> streamEstimateStations = (java.util.List<StateMod_StreamEstimate>)data; IList <StateMod_StreamEstimate> streamEstimateStations = (IList <StateMod_StreamEstimate>)data; StateMod_StreamEstimate.writeStateModFile(oldFilename, newFilename, streamEstimateStations, comments, daily); name = "Stream Estimate"; break; case StateMod_DataSet.COMP_STREAMESTIMATE_COEFFICIENTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamEstimate_Coefficients> streamEstimateCoefficients = (java.util.List<StateMod_StreamEstimate_Coefficients>)data; IList <StateMod_StreamEstimate_Coefficients> streamEstimateCoefficients = (IList <StateMod_StreamEstimate_Coefficients>)data; StateMod_StreamEstimate_Coefficients.writeStateModFile(oldFilename, newFilename, streamEstimateCoefficients, comments); name = "Stream Estimate Coefficients"; break; case StateMod_DataSet.COMP_STREAMGAGE_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_StreamGage> streamGageStations = (java.util.List<StateMod_StreamGage>)data; IList <StateMod_StreamGage> streamGageStations = (IList <StateMod_StreamGage>)data; StateMod_StreamGage.writeStateModFile(oldFilename, newFilename, streamGageStations, comments, daily); name = "Streamgage Stations"; break; case StateMod_DataSet.COMP_WELL_STATIONS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Well> wellStations = (java.util.List<StateMod_Well>)data; IList <StateMod_Well> wellStations = (IList <StateMod_Well>)data; StateMod_Well.writeStateModFile(oldFilename, newFilename, wellStations, comments); name = "Well"; break; case StateMod_DataSet.COMP_WELL_RIGHTS: //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_WellRight> wellRights = (java.util.List<StateMod_WellRight>)data; IList <StateMod_WellRight> wellRights = (IList <StateMod_WellRight>)data; StateMod_WellRight.writeStateModFile(oldFilename, newFilename, wellRights, comments, (PropList)null); name = "Well Rights"; break; ////////////////////////////////////////////////////// // StateMod Time Series case StateMod_DataSet.COMP_CONSUMPTIVE_WATER_REQUIREMENT_TS_DAILY: case StateMod_DataSet.COMP_CONSUMPTIVE_WATER_REQUIREMENT_TS_MONTHLY: case StateMod_DataSet.COMP_DEMAND_TS_DAILY: case StateMod_DataSet.COMP_DEMAND_TS_AVERAGE_MONTHLY: case StateMod_DataSet.COMP_DEMAND_TS_MONTHLY: case StateMod_DataSet.COMP_DEMAND_TS_OVERRIDE_MONTHLY: case StateMod_DataSet.COMP_DIVERSION_TS_DAILY: case StateMod_DataSet.COMP_DIVERSION_TS_MONTHLY: case StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY: case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_AVERAGE_MONTHLY: case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_DAILY: case StateMod_DataSet.COMP_INSTREAM_DEMAND_TS_MONTHLY: case StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY: case StateMod_DataSet.COMP_RESERVOIR_CONTENT_TS_DAILY: case StateMod_DataSet.COMP_RESERVOIR_CONTENT_TS_MONTHLY: case StateMod_DataSet.COMP_RESERVOIR_TARGET_TS_DAILY: case StateMod_DataSet.COMP_RESERVOIR_TARGET_TS_MONTHLY: case StateMod_DataSet.COMP_STREAMESTIMATE_NATURAL_FLOW_TS_DAILY: case StateMod_DataSet.COMP_STREAMESTIMATE_NATURAL_FLOW_TS_MONTHLY: case StateMod_DataSet.COMP_STREAMGAGE_NATURAL_FLOW_TS_DAILY: case StateMod_DataSet.COMP_STREAMGAGE_NATURAL_FLOW_TS_MONTHLY: case StateMod_DataSet.COMP_STREAMGAGE_HISTORICAL_TS_DAILY: case StateMod_DataSet.COMP_STREAMGAGE_HISTORICAL_TS_MONTHLY: case StateMod_DataSet.COMP_WELL_DEMAND_TS_DAILY: case StateMod_DataSet.COMP_WELL_DEMAND_TS_MONTHLY: case StateMod_DataSet.COMP_WELL_PUMPING_TS_DAILY: case StateMod_DataSet.COMP_WELL_PUMPING_TS_MONTHLY: double missing = -999.0; YearType yearType = null; if (__dataset.getCyrl() == YearType.CALENDAR) { yearType = YearType.CALENDAR; } else if (__dataset.getCyrl() == YearType.WATER) { yearType = YearType.WATER; } else if (__dataset.getCyrl() == YearType.NOV_TO_OCT) { yearType = YearType.NOV_TO_OCT; } int precision = 2; // Do the following to avoid warnings IList <TS> tslist = null; if (data != null) { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<RTi.TS.TS> tslist0 = (java.util.List<RTi.TS.TS>)data; IList <TS> tslist0 = (IList <TS>)data; if (tslist0.Count > 0) { TS ts = tslist0[0]; missing = ts.getMissing(); } tslist = tslist0; } StateMod_TS.writeTimeSeriesList(oldFilename, newFilename, comments, tslist, null, null, yearType, missing, precision); name = "TS (" + type + ")"; break; default: name = "(something: " + type + ")"; break; } comp.setDirty(false); Message.printStatus(1, "", "Component '" + name + "' written"); }
/// <summary> /// Read instream flow information in and store in a list. The new instream /// flows are added to the end of the previously stored instream flows. </summary> /// <param name="filename"> Name of file to read. </param> /// <exception cref="Exception"> if there is an error reading the file. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static java.util.List<StateMod_InstreamFlow> readStateModFile(String filename) throws Exception public static IList <StateMod_InstreamFlow> readStateModFile(string filename) { string routine = "StateMod_InstreamFlow.readStateModFile"; string iline, s; IList <StateMod_InstreamFlow> theIns = new List <StateMod_InstreamFlow>(); IList <object> v = new List <object>(9); int[] format_0 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING }; int[] format_0w = new int[] { 12, 24, 12, 8, 1, 12, 1, 12, 8 }; if (Message.isDebugOn) { Message.printDebug(10, routine, "Reading file: " + filename); } StreamReader @in = null; try { @in = new StreamReader(filename); StateMod_InstreamFlow anIns; while (!string.ReferenceEquals((iline = @in.ReadLine()), null)) { // check for comments if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0) { continue; } // allocate new instream flow node anIns = new StateMod_InstreamFlow(); // line 1 if (Message.isDebugOn) { Message.printDebug(50, routine, "line 1: " + iline); } StringUtil.fixedRead(iline, format_0, format_0w, v); if (Message.isDebugOn) { Message.printDebug(50, routine, "Fixed read returned " + v.Count + " elements"); } s = StringUtil.unpad((string)v[0], " ", StringUtil.PAD_FRONT_BACK); anIns.setID(s); s = StringUtil.unpad((string)v[1], " ", StringUtil.PAD_FRONT_BACK); anIns.setName(s); s = StringUtil.unpad((string)v[2], " ", StringUtil.PAD_FRONT_BACK); anIns.setCgoto(s); anIns.setSwitch((int?)v[3]); s = StringUtil.unpad((string)v[5], " ", StringUtil.PAD_FRONT_BACK); if (Message.isDebugOn) { Message.printDebug(50, routine, "Ifrrdn: " + s); } anIns.setIfrrdn(s); // daily id s = StringUtil.unpad((string)v[7], " ", StringUtil.PAD_FRONT_BACK); anIns.setCifridy(s); // Data type(read as string and convert to integer)... s = StringUtil.unpad((string)v[8], " ", StringUtil.PAD_FRONT_BACK); anIns.setIifcom(s); // add the instream flow to the vector of instream flows theIns.Add(anIns); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@in != null) { @in.Close(); } } return(theIns); }
/// <summary> /// Writes a list of StateMod_InstreamFlow 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> /// <param name="newComments"> additional comments to write to the header. </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<StateMod_InstreamFlow> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_InstreamFlow> data, IList <string> newComments) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("Name"); fields.Add("UpstreamRiverNodeID"); fields.Add("OnOff"); fields.Add("DownstreamRiverNodeID"); fields.Add("DailyID"); fields.Add("DemandType"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_INSTREAM_STATIONS; string s = null; for (int i = 0; i < fieldCount; i++) { s = fields[i]; names[i] = StateMod_Util.lookupPropValue(comp, "FieldName", s); formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s); } string oldFile = null; if (update) { oldFile = IOUtil.getPathUsingWorkingDir(filename); } int j = 0; PrintWriter @out = null; StateMod_InstreamFlow flo = null; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); string[] line = new string[fieldCount]; StringBuilder buffer = new StringBuilder(); try { // Add some basic comments at the top of the file. 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, "StateMod instream flow stations as a delimited list file."); newComments2.Insert(2, ""); @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 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++) { flo = (StateMod_InstreamFlow)data[i]; line[0] = StringUtil.formatString(flo.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(flo.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(flo.getCgoto(), formats[2]).Trim(); line[3] = StringUtil.formatString(flo.getSwitch(), formats[3]).Trim(); line[4] = StringUtil.formatString(flo.getIfrrdn(), formats[4]).Trim(); line[5] = StringUtil.formatString(flo.getCifridy(), formats[5]).Trim(); line[6] = StringUtil.formatString(flo.getIifcom(), formats[6]).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 the instream flow objects to the StateMod file. </summary> /// <param name="infile"> input file(original file read from, can be null). </param> /// <param name="outfile"> output file(to create or update, can be same as input). </param> /// <param name="theInsf"> list of StateMod_InstreamFlow instances. </param> /// <param name="newcomments"> Comments to add at the top of the file. </param> /// <param name="useDailyData"> Indicates whether daily and extended data(cifridy, iifcom)should be used. </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 writeStateModFile(String infile, String outfile, java.util.List<StateMod_InstreamFlow> theInsf, java.util.List<String> newcomments, boolean useDailyData) throws Exception public static void writeStateModFile(string infile, string outfile, IList <StateMod_InstreamFlow> theInsf, IList <string> newcomments, bool useDailyData) { string routine = "StateMod_InstreamFlow.writeStateModFile"; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); PrintWriter @out = null; Message.printStatus(2, routine, "Writing instream flows to file \"" + outfile + "\" using \"" + infile + "\" header..."); // Process the header from the old file... try { @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newcomments, commentIndicators, ignoredCommentIndicators, 0); int i; string iline; string cmnt = "#>"; IList <object> v = new List <object>(7); StateMod_InstreamFlow insf = null; string format_0 = "%-12.12s%-24.24s%-12.12s%8d %-12.12s %-12.12s%8d"; string format_1 = "%-12.12s%-24.24s%-12.12s%8d %-12.12s"; @out.println(cmnt); @out.println(cmnt + " ******************************************************* "); @out.println(cmnt + " StateMod Instream Flow Station File"); @out.println(cmnt); @out.println(cmnt + " Card format: (a12,a24,a12,i8,1x,a12,1x,a12,i8)"); @out.println(cmnt); @out.println(cmnt + " ID cifrid: Instream Flow ID"); @out.println(cmnt + " Name cfrnam: Instream Flow Name"); @out.println(cmnt + " Riv ID cgoto: Upstream river ID where instream flow is located"); @out.println(cmnt + " On/Off ifrrsw: Switch; 0=off, 1=on"); @out.println(cmnt + " Downstream ifrrdn: Downstream river ID where instream flow is located"); @out.println(cmnt + " (blank indicates downstream=upstream)"); @out.println(cmnt + " DailyID cifridy: Daily instream flow ID (see StateMod doc)"); @out.println(cmnt + " DemandType iifcom: Demand type switch (see StateMod doc)"); @out.println(cmnt); @out.println(cmnt + " ID Name Riv ID On/Off Downstream DailyID DemandType"); @out.println(cmnt + "---------eb----------------------eb----------eb------e-b----------exb----------eb------e"); @out.println(cmnt + "EndHeader"); @out.println(cmnt); int num = 0; if (theInsf != null) { num = theInsf.Count; } for (i = 0; i < num; i++) { insf = theInsf[i]; if (insf == null) { continue; } v.Clear(); v.Add(insf.getID()); v.Add(insf.getName()); v.Add(insf.getCgoto()); v.Add(new int?(insf.getSwitch())); v.Add(insf.getIfrrdn()); if (useDailyData) { v.Add(insf.getCifridy()); v.Add(new int?(insf.getIifcom())); iline = StringUtil.formatString(v, format_0); } else { iline = StringUtil.formatString(v, format_1); } @out.println(iline); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }