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