/// <summary> /// Writes a list of StateMod_ReservoirAreaCap 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"> new comments to add at the top of the file. </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_ReservoirAreaCap> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirAreaCap> data, IList <string> newComments) { string routine = "StateMod_ReservoirAreaCap.writeListFile"; int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ReservoirID"); fields.Add("Content"); fields.Add("Area"); fields.Add("Seepage"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_Util.COMP_RESERVOIR_AREA_CAP; string s = null; for (int i = 0; i < fieldCount; i++) { s = (string)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_ReservoirAreaCap area = null; string[] line = new string[fieldCount]; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); 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 reservoir content/area/seepage data as a delimited list file."); newComments2.Insert(2, "See also the associated station, account, precipitation station,"); newComments2.Insert(3, "evaporation station, and collection files."); newComments2.Insert(4, ""); @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 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++) { area = (StateMod_ReservoirAreaCap)data[i]; line[0] = StringUtil.formatString(area.getCgoto(), formats[0]).Trim(); line[1] = StringUtil.formatString(area.getConten(), formats[1]).Trim(); line[2] = StringUtil.formatString(area.getSurarea(), formats[2]).Trim(); line[3] = StringUtil.formatString(area.getSeepage(), formats[3]).Trim(); buffer = new StringBuilder(); for (j = 0; j < fieldCount; j++) { if (j > 0) { buffer.Append(delimiter); } if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1) { line[j] = "\"" + line[j] + "\""; } buffer.Append(line[j]); } @out.println(buffer.ToString()); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_ReservoirAccount 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"> new comments to add to the top of the file. </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 data, java.util.List newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, System.Collections.IList data, System.Collections.IList newComments) { string routine = "StateMod_ReservoirAccount.writeListFile"; int size = 0; if (data != null) { size = data.Count; } System.Collections.IList fields = new List <object>(); fields.Add("ReservoirID"); fields.Add("OwnerID"); fields.Add("OwnerAccount"); fields.Add("MaxStorage"); fields.Add("InitialStorage"); fields.Add("ProrateEvap"); fields.Add("OwnershipTie"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_RESERVOIR_STATION_ACCOUNTS; string s = null; for (int i = 0; i < fieldCount; i++) { s = (string)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; StateMod_ReservoirAccount acct = null; System.Collections.IList commentIndicators = new List <object>(1); commentIndicators.Add("#"); System.Collections.IList ignoredCommentIndicators = new List <object>(1); ignoredCommentIndicators.Add("#>"); string[] line = new string[fieldCount]; StringBuilder buffer = new StringBuilder(); PrintWriter @out = null; 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. System.Collections.IList newComments2 = null; if (newComments == null) { newComments2 = new List <object>(); } else { newComments2 = new List <object>(newComments); } newComments2.Insert(0, ""); newComments2.Insert(1, "StateMod reservoir station accounts as a delimited list file."); newComments2.Insert(2, "See also the associated station, precipitation station, evaporation station,"); newComments2.Insert(3, "content/area/seepage, and collection files."); newComments2.Insert(4, ""); @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++) { acct = (StateMod_ReservoirAccount)data[i]; line[0] = StringUtil.formatString(acct.getCgoto(), formats[0]).Trim(); line[1] = StringUtil.formatString(acct.getID(), formats[1]).Trim(); line[2] = StringUtil.formatString(acct.getName(), formats[2]).Trim(); line[3] = StringUtil.formatString(acct.getOwnmax(), formats[3]).Trim(); line[4] = StringUtil.formatString(acct.getCurown(), formats[4]).Trim(); line[5] = StringUtil.formatString(acct.getPcteva(), formats[5]).Trim(); line[6] = StringUtil.formatString(acct.getN2own(), 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()); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_RiverNetworkNode 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"> new comments to add to the file 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_RiverNetworkNode> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_RiverNetworkNode> data, IList <string> newComments) { string routine = "StateMod_RiverNetworkNode.writeListFile"; int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("Name"); fields.Add("DownstreamID"); fields.Add("Comment"); fields.Add("GWMaxRecharge"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_RIVER_NETWORK; 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_RiverNetworkNode rnn = null; string[] line = new string[fieldCount]; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); 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 river network as a delimited list file."); newComments2.Insert(2, "See also the generalized network file."); newComments2.Insert(3, ""); @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 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++) { rnn = (StateMod_RiverNetworkNode)data[i]; line[0] = StringUtil.formatString(rnn.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(rnn.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(rnn.getCstadn(), formats[2]).Trim(); line[3] = StringUtil.formatString(rnn.getComment(), formats[3]).Trim(); line[4] = StringUtil.formatString(rnn.getGwmaxr(), formats[4]).Trim(); buffer = new StringBuilder(); for (j = 0; j < fieldCount; j++) { if (j > 0) { buffer.Append(delimiter); } if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1) { line[j] = "\"" + line[j] + "\""; } buffer.Append(line[j]); } @out.println(buffer.ToString()); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_StreamGage 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"> list of comments to add at the top of the file. </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_StreamGage> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_StreamGage> 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("NodeID"); fields.Add("DailyID"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_STREAMGAGE_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_StreamGage gage = 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 stream gage 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++) { if (i > 0) { buffer.Append(delimiter); } buffer.Append("\"" + names[i] + "\""); } @out.println(buffer.ToString()); for (int i = 0; i < size; i++) { gage = (StateMod_StreamGage)data[i]; line[0] = StringUtil.formatString(gage.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(gage.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(gage.getCgoto(), formats[2]).Trim(); line[3] = StringUtil.formatString(gage.getCrunidy(), formats[3]).Trim(); buffer = new StringBuilder(); for (j = 0; j < fieldCount; j++) { if (j > 0) { buffer.Append(delimiter); } if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1) { line[j] = "\"" + line[j] + "\""; } buffer.Append(line[j]); } @out.println(buffer.ToString()); } } catch (Exception e) { throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_ReturnFlow 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"> new comments to add to the header (e.g., command file, 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<StateMod_ReturnFlow> data, int componentType, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReturnFlow> data, int componentType, IList <string> newComments) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("RiverNodeID"); if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES) { fields.Add("DepletionPercent"); } else { fields.Add("ReturnPercent"); } fields.Add("DelayTableID"); fields.Add("Comment"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = componentType; 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_ReturnFlow rf = 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. 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, ""); if (componentType == StateMod_DataSet.COMP_DIVERSION_STATION_DELAY_TABLES) { newComments2.Insert(1, "StateMod diversion delay (return) file."); newComments2.Insert(2, "See also the associated diversion station file."); } else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES) { newComments2.Insert(1, "StateMod well depletion file."); newComments2.Insert(2, "See also the associated well station and return files."); } else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DELAY_TABLES) { newComments2.Insert(1, "StateMod well delay (return) file."); newComments2.Insert(2, "See also the associated well station and depletion files."); } newComments2.Insert(3, ""); @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++) { rf = data[i]; line[0] = StringUtil.formatString(rf.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(rf.getCrtnid(), formats[1]).Trim(); line[2] = StringUtil.formatString(rf.getPcttot(), formats[2]).Trim(); line[3] = StringUtil.formatString(rf.getIrtndl(), formats[3]).Trim(); line[4] = StringUtil.formatString(rf.getComment(), formats[4]).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 StateMod_DelayTable 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"> the list of new comments to write to the header, or null if none. </param> /// <param name="comp"> the component type being written (to distinguish between daily and monthly delay tables), /// either StateMod_DataSet.COMP_DELAY_TABLES_DAILY or StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY. </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_DelayTable> data, java.util.List<String> newComments, int comp) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_DelayTable> data, IList <string> newComments, int comp) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("DelayTableID"); fields.Add("Date"); fields.Add("ReturnAmount"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; string s = null; for (int i = 0; i < fieldCount; i++) { s = (string)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; int k = 0; int num = 0; PrintWriter @out = null; StateMod_DelayTable delay = null; IList <string> commentIndicators = new List <string>(1); commentIndicators.Add("#"); IList <string> ignoredCommentIndicators = new List <string>(1); ignoredCommentIndicators.Add("#>"); string[] line = new string[fieldCount]; string id = null; 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, ""); if (comp == StateMod_DataSet.COMP_DELAY_TABLES_DAILY) { newComments2.Insert(1, "StateMod delay tables (daily) as a delimited list file."); } else { newComments2.Insert(1, "StateMod delay tables (monthly) as a delimited list file."); } newComments2.Insert(2, ""); @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(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++) { delay = (StateMod_DelayTable)data[i]; id = delay.getID(); num = delay.getNdly(); for (j = 0; j < num; j++) { line[0] = StringUtil.formatString(id, formats[0]).Trim(); line[1] = StringUtil.formatString((j + 1), formats[1]).Trim(); line[2] = StringUtil.formatString(delay.getRet_val(j), formats[2]).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()); } } @out.flush(); @out.close(); @out = null; } catch (Exception e) { // TODO SAM 2009-01-11 Log it? throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_Plan_WellAugmentation 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"> new comments to add to the header (e.g., command file, 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<StateMod_Plan_WellAugmentation> data, int componentType, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_Plan_WellAugmentation> data, int componentType, IList <string> newComments) { int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("PlanID"); fields.Add("WellRightID"); fields.Add("WellStructureID"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = componentType; 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_Plan_WellAugmentation wellAug = 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. 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, "StateMod well augmentation plan data file."); newComments2.Insert(2, "See also the associated plan station file."); newComments2.Insert(3, ""); @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++) { wellAug = data[i]; line[0] = StringUtil.formatString(wellAug.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(wellAug.getCistatW(), formats[1]).Trim(); line[2] = StringUtil.formatString(wellAug.getCistatS(), formats[2]).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()); } @out.flush(); @out.close(); } finally { if (@out != null) { @out.flush(); @out.close(); } } }
/// <summary> /// Writes a list of StateMod_ReservoirRight 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"> comments to write to the top of the file. </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_ReservoirRight> data, java.util.List<String> newComments) throws Exception public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirRight> data, IList <string> newComments) { string routine = "StateMod_ReservoirRight.writeListFile"; int size = 0; if (data != null) { size = data.Count; } IList <string> fields = new List <string>(); fields.Add("ID"); fields.Add("Name"); fields.Add("StructureID"); fields.Add("AdministrationNumber"); fields.Add("DecreedAmount"); fields.Add("OnOff"); fields.Add("AccountDistribution"); fields.Add("Type"); fields.Add("FillType"); fields.Add("OopRight"); int fieldCount = fields.Count; string[] names = new string[fieldCount]; string[] formats = new string[fieldCount]; int comp = StateMod_DataSet.COMP_RESERVOIR_RIGHTS; 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; StateMod_ReservoirRight right = 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(); PrintWriter @out = null; 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 reservoir rights 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++) { if (i > 0) { buffer.Append(delimiter); } buffer.Append("\"" + names[i] + "\""); } @out.println(buffer.ToString()); for (int i = 0; i < size; i++) { right = (StateMod_ReservoirRight)data[i]; line[0] = StringUtil.formatString(right.getID(), formats[0]).Trim(); line[1] = StringUtil.formatString(right.getName(), formats[1]).Trim(); line[2] = StringUtil.formatString(right.getCgoto(), formats[2]).Trim(); line[3] = StringUtil.formatString(right.getRtem(), formats[3]).Trim(); line[4] = StringUtil.formatString(right.getDcrres(), formats[4]).Trim(); line[5] = StringUtil.formatString(right.getSwitch(), formats[5]).Trim(); line[6] = StringUtil.formatString(right.getIresco(), formats[6]).Trim(); line[7] = StringUtil.formatString(right.getItyrstr(), formats[7]).Trim(); line[8] = StringUtil.formatString(right.getN2fill(), formats[8]).Trim(); line[9] = StringUtil.formatString(right.getCopid(), formats[9]).Trim(); buffer = new StringBuilder(); for (j = 0; j < fieldCount; j++) { if (j > 0) { buffer.Append(delimiter); } if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1) { line[j] = "\"" + line[j] + "\""; } buffer.Append(line[j]); } @out.println(buffer.ToString()); } } catch (Exception e) { Message.printWarning(3, routine, e); throw e; } finally { if (@out != null) { @out.flush(); @out.close(); } } }