/// <summary> /// Read diversion information in and store in a java vector. /// The new diversions are added to the end of the previously stored diversions. </summary> /// <param name="filename"> filename containing diversion 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_Diversion> readStateModFile(String filename) throws Exception public static IList <StateMod_Diversion> readStateModFile(string filename) { string routine = "StateMod_Diversion.readStateModFile"; string iline = null; IList <object> v = new List <object>(9); IList <StateMod_Diversion> theDiversions = new List <StateMod_Diversion>(); int i; int linecount = 0; string s = null; int[] format_0 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING }; int[] format_0w = new int[] { 12, 24, 12, 8, 8, 8, 8, 1, 12 }; int[] format_1 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER }; int[] format_1w = new int[] { 12, 24, 12, 8, 8, 8, 8, 8, 8 }; int[] format_2 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER }; int[] format_2w = new int[] { 36, 12, 8, 8 }; StateMod_Diversion aDiversion = null; StateMod_ReturnFlow aReturnNode = null; StreamReader @in = null; Message.printStatus(1, routine, "Reading diversion file: " + filename); try { @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename)); while (!string.ReferenceEquals((iline = @in.ReadLine()), null)) { ++linecount; // check for comments if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0) { continue; } // allocate new diversion node aDiversion = new StateMod_Diversion(); // line 1 if (Message.isDebugOn) { Message.printDebug(50, routine, "line 1: " + iline); } StringUtil.fixedRead(iline, format_0, format_0w, v); aDiversion.setID(((string)v[0]).Trim()); aDiversion.setName(((string)v[1]).Trim()); aDiversion.setCgoto(((string)v[2]).Trim()); aDiversion.setSwitch((int?)v[3]); aDiversion.setDivcap((double?)v[4]); aDiversion.setIreptype(((int?)v[6])); aDiversion.setCdividy(((string)v[8]).Trim()); // line 2 iline = @in.ReadLine(); ++linecount; if (Message.isDebugOn) { Message.printDebug(50, routine, "line 2: " + iline); } StringUtil.fixedRead(iline, format_1, format_1w, v); aDiversion.setUsername(((string)v[1]).Trim()); aDiversion.setIdvcom(((int?)v[3])); int nrtn = ((int?)v[4]).Value; aDiversion.setDivefc(((double?)v[5])); aDiversion.setArea(((double?)v[6])); aDiversion.setIrturn(((int?)v[7])); aDiversion.setDemsrc(((int?)v[8])); // get the efficiency information if (aDiversion.getDivefc() < 0) { // Negative value indicates monthly efficiencies will follow... iline = @in.ReadLine(); ++linecount; // Free format... char[] seps = { ' ', '\t', '\n', '\r', '\f' }; string[] split = iline.Split(seps); if (split != null && split.Length == 12) { for (i = 0; i < 12; i++) { aDiversion.setDiveff(i, split[0]); } } } else { // Annual efficiency so set monthly efficiencies to the annual... aDiversion.setDiveff(0, aDiversion.getDivefc()); aDiversion.setDiveff(1, aDiversion.getDivefc()); aDiversion.setDiveff(2, aDiversion.getDivefc()); aDiversion.setDiveff(3, aDiversion.getDivefc()); aDiversion.setDiveff(4, aDiversion.getDivefc()); aDiversion.setDiveff(5, aDiversion.getDivefc()); aDiversion.setDiveff(6, aDiversion.getDivefc()); aDiversion.setDiveff(7, aDiversion.getDivefc()); aDiversion.setDiveff(8, aDiversion.getDivefc()); aDiversion.setDiveff(9, aDiversion.getDivefc()); aDiversion.setDiveff(10, aDiversion.getDivefc()); aDiversion.setDiveff(11, aDiversion.getDivefc()); } // get the return information for (i = 0; i < nrtn; i++) { iline = @in.ReadLine(); ++linecount; StringUtil.fixedRead(iline, format_2, format_2w, v); aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_DIVERSION_STATIONS); s = ((string)v[1]).Trim(); if (s.Length <= 0) { aReturnNode.setCrtnid(((string)v[0]).Trim()); Message.printWarning(3, routine, "Return node for structure \"" + aDiversion.getID() + "\" is blank. "); } else { aReturnNode.setCrtnid(s); } aReturnNode.setPcttot(((double?)v[2])); aReturnNode.setIrtndl(((int?)v[3])); aDiversion.addReturnFlow(aReturnNode); } // Set the diversion to not dirty because it was just initialized... aDiversion.setDirty(false); // add the diversion to the vector of diversions theDiversions.Add(aDiversion); } } catch (Exception e) { Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\""); Message.printWarning(3, routine, e); throw e; } finally { if (@in != null) { @in.Close(); } } return(theDiversions); }
/// <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_Diversion smd = (StateMod_Diversion)_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_CAPACITY: smd.setDivcap((double?)value); break; case COL_REPLACE_RES_OPTION: if (value is int?) { ival = ((int?)value).Value; smd.setIreptype(ival); } else if (value is string) { string ireptyp = (string)value; index = ireptyp.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(ireptyp.Substring(0, index))); smd.setIreptype(ival); } break; case COL_DAILY_ID: smd.setCdividy((string)value); break; case COL_USER_NAME: smd.setUsername((string)value); break; case COL_DEMAND_TYPE: if (value is int?) { ival = ((int?)value).Value; smd.setIdvcom(ival); } else if (value is string) { string idvcom = (string)value; index = idvcom.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(idvcom.Substring(0, index))); smd.setIdvcom(ival); } break; case COL_EFF_ANNUAL: smd.setDivefc((double?)value); break; case COL_AREA: smd.setArea((double?)value); break; case COL_USE_TYPE: if (value is int?) { ival = ((int?)value).Value; smd.setIrturn(ival); } else if (value is string) { string irturn = (string)value; index = irturn.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(irturn.Substring(0, index))); smd.setIrturn(ival); } break; case COL_DEMAND_SOURCE: if (value is int?) { ival = ((int?)value).Value; smd.setDemsrc(ival); } else if (value is string) { string demsrc = (string)value; index = demsrc.IndexOf(" -", StringComparison.Ordinal); ival = (Convert.ToInt32(demsrc.Substring(0, index))); smd.setDemsrc(ival); } break; case COL_EFF_01: smd.setDiveff(0, (double?)value); break; case COL_EFF_02: smd.setDiveff(1, (double?)value); break; case COL_EFF_03: smd.setDiveff(2, (double?)value); break; case COL_EFF_04: smd.setDiveff(3, (double?)value); break; case COL_EFF_05: smd.setDiveff(4, (double?)value); break; case COL_EFF_06: smd.setDiveff(5, (double?)value); break; case COL_EFF_07: smd.setDiveff(6, (double?)value); break; case COL_EFF_08: smd.setDiveff(7, (double?)value); break; case COL_EFF_09: smd.setDiveff(8, (double?)value); break; case COL_EFF_10: smd.setDiveff(9, (double?)value); break; case COL_EFF_11: smd.setDiveff(10, (double?)value); break; case COL_EFF_12: smd.setDiveff(11, (double?)value); break; } base.setValueAt(value, row, col); }