/// <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); }