/// <summary> /// Read plan information in and store in a list. </summary> /// <param name="filename"> filename containing plan 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 java.util.List<StateMod_Plan> readStateModFile(String filename) throws Exception public static IList <StateMod_Plan> readStateModFile(string filename) { string routine = "StateMod_Plan.readStateModFile"; string iline = null; IList <string> v = new List <string>(9); IList <StateMod_Plan> thePlans = new List <StateMod_Plan>(); int linecount = 0; StateMod_Plan aPlan = null; StreamReader @in = null; Message.printStatus(2, routine, "Reading plan file: " + filename); int size = 0; int errorCount = 0; try { @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename)); IList <string> commentsBeforeData = new List <string>(); while (!string.ReferenceEquals((iline = @in.ReadLine()), null)) { ++linecount; // check for comments if (iline.StartsWith("#>", StringComparison.Ordinal) || (iline.Trim().Length == 0)) { // Special dynamic header comments written by software and blank lines - no need to keep continue; } else if (iline.StartsWith("#", StringComparison.Ordinal)) { // Comment prior to a plan - do not trim so that input/output comparisons can be made but // do remove the initial comment character commentsBeforeData.Add(iline.Substring(1)); continue; } if (Message.isDebugOn) { Message.printDebug(50, routine, "line: " + iline); } // Break the line using whitespace, while allowing for quoted strings... v = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS); size = 0; if (v != null) { size = v.Count; } if (size < 11) { Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values. Have " + size + " expecting " + 11); ++errorCount; continue; } // Uncomment if testing... //Message.printStatus ( 2, routine, "" + v ); // Allocate new plan node and set the values aPlan = new StateMod_Plan(); aPlan.setID(v[0].Trim()); aPlan.setName(v[1].Trim()); aPlan.setCgoto(v[2].Trim()); aPlan.setSwitch(v[3].Trim()); aPlan.setIPlnTyp(v[4].Trim()); aPlan.setPeffFlag(v[5].Trim()); int peffFlag = aPlan.getPeffFlag(); aPlan.setIPrf(v[6].Trim()); aPlan.setIPfail(v[7].Trim()); aPlan.setPsto1(v[8].Trim()); aPlan.setPsource(v[9].Trim()); aPlan.setIPAcc(v[10].Trim()); // Read the efficiencies... if (peffFlag == 1) { iline = @in.ReadLine(); ++linecount; if (string.ReferenceEquals(iline, null)) { throw new IOException("Unexpected end of file after line " + linecount + " - expecting 12 efficiency values."); } v = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS); size = 0; if (v != null) { size = v.Count; } if (size != 12) { Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values. Have " + size + " expecting " + 12); ++errorCount; } else { for (int iEff = 0; iEff < 12; iEff++) { string val = v[0].Trim(); try { aPlan.setPeff(iEff, double.Parse(val)); } catch (Exception) { Message.printStatus(2, routine, "Efficiencies on line " + linecount + " value \"" + val + "\" is not a number."); ++errorCount; } } } } // Set the comments if (commentsBeforeData.Count > 0) { // Set comments that have been read previous to this line. First, attempt to discard // comments that do not below with the operational right. For now, search backward for // "EndHeader" and "--e" which indicate the end of the header. If found, discard the comments prior // to this because they are assumed to be file header comments, not comments for a specific right. // Only do this for the first right because the user may actually want to include the header // information in their file periodically to help with formatting string comment; if (thePlans.Count == 0) { for (int iComment = commentsBeforeData.Count - 1; iComment >= 0; --iComment) { comment = commentsBeforeData[iComment].ToUpper(); if ((comment.IndexOf("ENDHEADER", StringComparison.Ordinal) >= 0) || (comment.IndexOf("--E", StringComparison.Ordinal) >= 0)) { // Remove the comments above the position. while (iComment >= 0) { commentsBeforeData.RemoveAt(iComment--); } break; } } } aPlan.setCommentsBeforeData(commentsBeforeData); } // Always clear out for next right... commentsBeforeData = new List <string>(1); // Set the plan to not dirty because it was just initialized... aPlan.setDirty(false); // Add the plan to the vector of plans thePlans.Add(aPlan); } } catch (Exception e) { Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" uniquetempvar."); Message.printWarning(3, routine, e); throw e; } finally { if (@in != null) { @in.Close(); } } if (errorCount > 0) { throw new Exception("There were " + errorCount + " errors processing the data - refer to log file."); } return(thePlans); }
/// <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 ival; int index; StateMod_Plan smd = (StateMod_Plan)_data.get(row); switch (col) { case COL_ID: smd.setID((string)value); break; case COL_NAME: smd.setName((string)value); break; case COL_RIVER_NODE_ID: smd.setCgoto((string)value); break; case COL_ON_OFF: if (value is int?) { ival = ((int?)value).Value; smd.setSwitch(ival); } else if (value is string) { string onOff = (string)value; index = onOff.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(onOff.Substring(0, index))); smd.setSwitch(ival); } break; case COL_TYPE: smd.setIPlnTyp((int?)value); break; case COL_RETURN_TYPE: smd.setIPrf((int?)value); break; case COL_FAILURE_SWITCH: smd.setIPfail((int?)value); break; case COL_INITIAL_STORAGE: smd.setPsto1((double?)value); break; case COL_SOURCE_ID: smd.setPsource((string)value); break; case COL_SOURCE_ACCOUNT: smd.setIPAcc((string)value); break; case COL_EFF_FLAG: smd.setPeffFlag((int?)value); break; case COL_EFF_01: case COL_EFF_02: case COL_EFF_03: case COL_EFF_04: case COL_EFF_05: case COL_EFF_06: case COL_EFF_07: case COL_EFF_08: case COL_EFF_09: case COL_EFF_10: case COL_EFF_11: case COL_EFF_12: smd.setPeff((col - COL_EFF_01), (double?)value.Value); break; } base.setValueAt(value, row, col); }