/// <summary> /// Initialize data members. </summary> /// <param name="initialize_defaults"> If true, initialize data to reasonable defaults /// (e.g., zero dead storage) - this is suitable for defaults in the StateMod GUI. /// If false, don't initialize data - this is suitable for filling in StateDMI. </param> private void initialize(bool initialize_defaults) { _smdata_type = StateMod_DataSet.COMP_RESERVOIR_STATIONS; _owners = new List <StateMod_ReservoirAccount>(); _climate_Vector = new List <StateMod_ReservoirClimate>(); _areacapvals = new List <StateMod_ReservoirAreaCap>(); _rights = new List <StateMod_ReservoirRight>(); _content_MonthTS = null; _content_DayTS = null; _mintarget_MonthTS = null; _maxtarget_MonthTS = null; _mintarget_DayTS = null; _maxtarget_DayTS = null; //_georecord = null; if (initialize_defaults) { _cresdy = "0"; // Use monthly TS for daily _switch = 1; // In base class _rdate = -1; _volmin = 0; _volmax = 0; _flomax = 99999.0; // As per old SMGUI new reservoir _deadst = 0; } else { _cresdy = ""; _rdate = StateMod_Util.MISSING_INT; _volmin = StateMod_Util.MISSING_DOUBLE; _volmax = StateMod_Util.MISSING_DOUBLE; _flomax = StateMod_Util.MISSING_DOUBLE; _deadst = StateMod_Util.MISSING_DOUBLE; } }
/// <summary> /// Copy constructor. </summary> /// <param name="deep_copy"> If true, make a deep copy including secondary vectors of data. /// Currently only false is recognized, in which primitive data are copied. This is /// suitable to allow the StateMod_Diversion_JFrame class to know when changes have /// been made to data on the main screen. </param> public StateMod_Diversion(StateMod_Diversion div, bool deep_copy) : this() { // Base class... // TODO // Local data members... _cdividy = div._cdividy; _divcap = div._divcap; _username = div._username; _idvcom = div._idvcom; _divefc = div._divefc; for (int i = 0; i < 12; i++) { _diveff[i] = div._diveff[i]; } _area = div._area; _irturn = div._irturn; _rivret = div._rivret; _rights = div._rights; _demsrc = div._demsrc; _ireptype = div._ireptype; // For time series, the references are pointed to the original but data are not copied. _demand_MonthTS = div._demand_MonthTS; _demand_override_MonthTS = div._demand_override_MonthTS; _demand_average_MonthTS = div._demand_average_MonthTS; _demand_DayTS = div._demand_DayTS; _diversion_MonthTS = div._diversion_MonthTS; _diversion_DayTS = div._diversion_DayTS; _cwr_MonthTS = div._cwr_MonthTS; _cwr_DayTS = div._cwr_DayTS; //_ipy_YearTS = div._ipy_YearTS; _awc = div._awc; //_georecord = div._georecord; }
/// <summary> /// Connect the historical daily TS pointer to the appropriate TS in the Vector. /// A connection is made if the node identifier matches the time series location. </summary> /// <param name="tslist"> Vector of DayTS. </param> private void connectHistoricalDayTS(IList <DayTS> tslist) { if (tslist == null) { return; } DayTS ts; _historical_DayTS = null; int size = tslist.Count; for (int i = 0; i < size; i++) { ts = tslist[i]; if (ts == null) { continue; } if (_id.Equals(ts.getLocation(), StringComparison.OrdinalIgnoreCase)) { // Set this because the original file does not have... ts.setDescription(getName()); _historical_DayTS = ts; break; } } }
/// <summary> /// Connect daily demand time series to the instream flow. /// The daily id "cifridy" must match the time series. /// The time series description is set to the station name. /// </summary> public virtual void connectDemandDayTS(IList <DayTS> tslist) { if (tslist == null) { return; } _demand_DayTS = null; int numTS = tslist.Count; DayTS ts; for (int i = 0; i < numTS; i++) { ts = tslist[i]; if (ts == null) { continue; } if (_cifridy.Equals(ts.getLocation(), StringComparison.OrdinalIgnoreCase)) { _demand_DayTS = ts; ts.setDescription(getName()); break; } } }
/// <summary> /// Initialize data. Sets the smdata_type to _dataset.COMP_DIVERSION_STATIONS. </summary> /// <param name="initialize_defaults"> If true, assign data to reasonable defaults. /// If false, all data are set to missing. </param> private void initialize(bool initialize_defaults) { _smdata_type = StateMod_DataSet.COMP_DIVERSION_STATIONS; if (initialize_defaults) { _divefc = -60.0; // Ray Bennett, Ray Alvarado, 2003-10-07 progress mtg. _diveff = new double[12]; for (int i = 0; i < 12; i++) { _diveff[i] = 60.0; // See above } _username = ""; _cdividy = "0"; // Use the average monthly TS for daily TS _divcap = 0; _idvcom = 1; _area = 0; _irturn = 1; _demsrc = DEMSRC_UNKNOWN; _ireptype = -1; // Provide depletion replacement } else { _divefc = StateMod_Util.MISSING_DOUBLE; _diveff = new double[12]; for (int i = 0; i < 12; i++) { _diveff[i] = StateMod_Util.MISSING_DOUBLE; } _username = StateMod_Util.MISSING_STRING; _cdividy = StateMod_Util.MISSING_STRING; _divcap = StateMod_Util.MISSING_INT; _idvcom = StateMod_Util.MISSING_INT; _area = StateMod_Util.MISSING_DOUBLE; _irturn = StateMod_Util.MISSING_INT; _demsrc = StateMod_Util.MISSING_INT; _ireptype = StateMod_Util.MISSING_INT; } _rivret = new List <StateMod_ReturnFlow>(); _rights = new List <StateMod_DiversionRight>(); _diversion_MonthTS = null; _diversion_DayTS = null; _demand_MonthTS = null; _demand_override_MonthTS = null; _demand_average_MonthTS = null; _demand_DayTS = null; //_ipy_YearTS = null; _cwr_MonthTS = null; _cwr_DayTS = null; //_georecord = null; }
/// <summary> /// Set default values for all arguments </summary> /// <param name="initialize_defaults"> If true, initialize data to reasonable values. If /// false, initialize to missing values. </param> private void initialize(bool initialize_defaults) { _smdata_type = StateMod_DataSet.COMP_WELL_STATIONS; _rivret = new List <StateMod_ReturnFlow>(10); _depl = new List <StateMod_ReturnFlow>(10); _pumping_MonthTS = null; _pumping_DayTS = null; _demand_MonthTS = null; _demand_DayTS = null; //_ipy_YearTS = null; _cwr_MonthTS = null; _cwr_DayTS = null; _rights = new List <StateMod_WellRight>(); //_georecord = null; if (initialize_defaults) { _cdividyw = "0"; // Estimate average daily from monthly data. _idvcow2 = "N/A"; _diveff = new double[12]; for (int i = 0; i < 12; i++) { _diveff[i] = 60.0; } _divcapw = 0; _idvcomw = 1; _divefcw = -60.0; // Indicate to use monthly efficiencies _areaw = 0.0; _irturnw = 0; _demsrcw = 1; _primary = 0; } else { _cdividyw = ""; _idvcow2 = ""; _diveff = new double[12]; for (int i = 0; i < 12; i++) { _diveff[i] = StateMod_Util.MISSING_DOUBLE; } _divcapw = StateMod_Util.MISSING_DOUBLE; _idvcomw = StateMod_Util.MISSING_INT; _divefcw = StateMod_Util.MISSING_DOUBLE; _areaw = StateMod_Util.MISSING_DOUBLE; _irturnw = StateMod_Util.MISSING_INT; _demsrcw = StateMod_Util.MISSING_INT; _primary = StateMod_Util.MISSING_INT; } }
/// <summary> /// Initialize data. </summary> /// <param name="initialize_defaults"> If true, the time series are set to null and other /// information is empty strings - this is suitable for the StateMod GUI. If false, /// the data are set to missing - this is suitable for StateDMI where data will be filled. </param> private void initialize(bool initialize_defaults) { _smdata_type = StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS; _cgoto = ""; _baseflow_MonthTS = null; _baseflow_DayTS = null; _related_smdata_type = StateMod_DataSet.COMP_UNKNOWN; if (initialize_defaults) { // Reasonable defaults... _crunidy = "0"; // Estimate average daily from monthly data. } else { // Missing... _crunidy = ""; } //_georecord = null; }
/// <summary> /// Initialize data. </summary> /// <param name="initialize_defaults"> If true, the time series are set to null and other /// information to empty strings or other reasonable defaults - this is suitable /// for the StateMod GUI when creating new instances. If false, the /// data values are set to missing - this is suitable for use with StateDMI, where /// data will be filled with commands. </param> private void initialize(bool initialize_defaults) { _smdata_type = StateMod_DataSet.COMP_STREAMGAGE_STATIONS; _cgoto = ""; _historical_MonthTS = null; _historical_DayTS = null; _baseflow_MonthTS = null; _baseflow_DayTS = null; if (initialize_defaults) { // Set to reasonable defaults... _crunidy = "0"; // Use monthly data } else { // Initialize to missing _crunidy = ""; } _georecord = null; }
/// <summary> /// Initialize data. </summary> /// <param name="initializeDefaults"> If true, then data values are initialized to /// reasonable defaults - this is suitable for adding a new instance in the /// StateMod GUI. If false, data values are initialized to missing - this is /// suitable for a new instance in StateDMI. </param> private void initialize(bool initializeDefaults) { _smdata_type = StateMod_DataSet.COMP_INSTREAM_STATIONS; _ifrrdn = ""; if (initializeDefaults) { _cifridy = "0"; // Estimate average daily data from monthly _iifcom = 2; // Default to annual } else { _cifridy = ""; _iifcom = StateMod_Util.MISSING_INT; } _rights = new List <StateMod_InstreamFlowRight>(); _demand_DayTS = null; _demand_MonthTS = null; _demand_average_MonthTS = null; //_georecord = null; }
//implements Cloneable, Comparable /// <summary> /// Read return information in and store in a list. </summary> /// <param name="filename"> filename for data file to read </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 RTi.TS.DayTS readStateModFile(String filename) throws Exception public static DayTS readStateModFile(string filename) { string routine = "StateMod_DownstreamCall.readStateModFile"; string iline = null; IList <string> vData = new List <object>(4); int linecount = 0; StreamReader @in = null; Message.printStatus(2, routine, "Reading downstream call file: " + filename); int size = 0; int errorCount = 0; int year, month, day; double adminNumber; DateTime date = new DateTime(DateTime.PRECISION_DAY); DayTS ts = null; try { @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename)); bool headerRead = false; 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; } if (Message.isDebugOn) { Message.printDebug(50, routine, "line: " + iline); } if (!headerRead) { // Read the header line and create the time series. // This code copied from StateMod_TS.readTimeSeriesList() string format = "i5x1i4x5i5x1i4s5s5"; IList <object> v = StringUtil.fixedRead(iline, format); int m1 = ((int?)v[0]).Value; int y1 = ((int?)v[1]).Value; int m2 = ((int?)v[2]).Value; int y2 = ((int?)v[3]).Value; DateTime date1Header; date1Header = new DateTime(DateTime.PRECISION_DAY); date1Header.setYear(y1); date1Header.setMonth(m1); date1Header.setDay(1); DateTime date2Header; date2Header = new DateTime(DateTime.PRECISION_DAY); date2Header.setYear(y2); date2Header.setMonth(m2); date2Header.setDay(TimeUtil.numDaysInMonth(m2, y2)); string units = ((string)v[4]).Trim(); string yeartypes = ((string)v[5]).Trim(); // TODO SAM 2011-01-02 Year type is not used since year month and day are all calendar /* * int yeartype = StateMod_DataSet.SM_CYR; * // Year type is used in one place to initialize the year when * // transferring data. However, it is assumed that m1 is always correct for the year type. * if ( yeartypes.equalsIgnoreCase("WYR") ) { * yeartype = StateMod_DataSet.SM_WYR; * } * else if ( yeartypes.equalsIgnoreCase("IYR") ) { * yeartype = StateMod_DataSet.SM_IYR; * } */ // year that are specified are used to set the period. if (Message.isDebugOn) { Message.printDebug(1, routine, "Parsed m1=" + m1 + " y1=" + y1 + " m2=" + m2 + " y2=" + y2 + " units=\"" + units + "\" yeartype=\"" + yeartypes + "\""); } // Now create the time series string tsidentString = "OprType23..DownstreamCall.Day"; ts = (DayTS)TSUtil.newTimeSeries(tsidentString, true); ts.setDate1(date1Header); ts.setDate1Original(date1Header); ts.setDate2(date2Header); ts.setDate2Original(date2Header); ts.setDataUnits(units); ts.setDataUnitsOriginal(units); ts.allocateDataSpace(); } else { // A time series data line // Break the line using whitespace, while allowing for quoted strings... try { vData = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS); size = 0; if (vData != null) { size = vData.Count; } if (size < 3) { Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values. Have " + size + " expecting 3"); ++errorCount; continue; } // Uncomment if testing... //Message.printStatus ( 2, routine, "" + v ); // Allocate new plan node and set the values year = int.Parse(vData[0].Trim()); month = int.Parse(vData[1].Trim()); day = int.Parse(vData[2].Trim()); adminNumber = double.Parse(vData[3].Trim()); date.setYear(year); date.setMonth(month); date.setDay(day); ts.setDataValue(date, adminNumber); } catch (Exception e2) { Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" (" + e2 + ") - skipping line."); Message.printWarning(3, routine, e2); } } // Set the data to not dirty because it was just initialized... ts.setDirty(false); } } 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 the single time series. return(ts); }
/// <summary> /// Set the daily historical TS pointer. </summary> /// <param name="ts"> Daily historical TS. </param> public virtual void setHistoricalDayTS(DayTS ts) { _historical_DayTS = ts; }
/// <summary> /// Set the daily baseflow TS. </summary> /// <param name="ts"> daily baseflow TS. </param> public virtual void setBaseflowDayTS(DayTS ts) { _baseflow_DayTS = ts; }
/// <summary> /// Sets daily demand ts /// </summary> public virtual void setDemandDayTS(DayTS demand_DayTS) { _demand_DayTS = demand_DayTS; }
/// <summary> /// Responds to action performed events. </summary> /// <param name="e"> the ActionEvent that happened. </param> public virtual void actionPerformed(ActionEvent e) { string routine = "StateMod_DelayTable_JFrame" + ".actionPerformed"; if (Message.isDebugOn) { Message.printDebug(1, routine, "In actionPerformed: " + e.getActionCommand()); } string action = e.getActionCommand(); if (action.Equals(__BUTTON_HELP)) { // REVISIT HELP (JTS - 2003-06-09) } else if (action.Equals(__BUTTON_CLOSE)) { closeWindow(); } else if (action.Equals(__BUTTON_APPLY)) { saveDelayTable(); int size = __delaysVector.Count; StateMod_DelayTable dt = null; bool changed = false; for (int i = 0; i < size; i++) { dt = (StateMod_DelayTable)__delaysVector[i]; if (!changed && dt.changed()) { changed = true; } dt.createBackup(); } if (changed) { __dataset.setDirty(__componentType, true); } } else if (action.Equals(__BUTTON_CANCEL)) { __worksheetR.deselectAll(); int size = __delaysVector.Count; StateMod_DelayTable dt = null; bool changed = false; for (int i = 0; i < size; i++) { dt = (StateMod_DelayTable)__delaysVector[i]; if (!changed && dt.changed()) { changed = true; } dt.restoreOriginal(); } if (__dataset_wm != null) { __dataset_wm.closeWindow(__window_type); } else { JGUIUtil.close(this); } } else if (action.Equals(__BUTTON_ADD_RETURN)) { int row = __worksheetR.getSelectedRow(); int total_num_rows = __worksheetR.getRowCount() - 1; if (row == -1) { row = total_num_rows; } if (row != -1) { if (row == total_num_rows) { int x = new ResponseJDialog(this, "Insert row", "Do you wish to add a new row above " + "the last row?\n" + "uniquetempvar.response(); if (x == ResponseJDialog.CANCEL) { return; } else if (x == ResponseJDialog.NO) { row += 1; } } __worksheetR.insertRowAt(new double?(0), row); __worksheetR.scrollToRow(row); __worksheetR.selectRow(row); } else { __worksheetR.addRow(new double?(0)); __worksheetR.scrollToRow(0); __worksheetR.selectRow(0); } __deleteReturn.setEnabled(true); } else if (action.Equals(__BUTTON_DELETE_RETURN)) { int row = __worksheetR.getSelectedRow(); if (row != -1) { int x = (new ResponseJDialog(this, "Delete Return", "Delete return?", ResponseJDialog.YES | ResponseJDialog.NO)).response(); if (x == ResponseJDialog.NO) { return; } //StateMod_DelayTable dt = (StateMod_DelayTable) //__worksheetL.getRowData( //__worksheetL.getSelectedRow()); __worksheetR.deleteRow(row); __deleteReturn.setEnabled(false); } else { Message.printWarning(1, routine, "Must select desired right to delete."); } } else if (e.getSource() == __findNextDelay) { searchLeftWorksheet(__worksheetL.getSelectedRow() + 1); } else if (e.getSource() == __searchID) { searchLeftWorksheet(); } else { if (__worksheetL.getSelectedRow() == -1) { new ResponseJDialog(this, "You must first select a delay from the list.", ResponseJDialog.OK); return; } else if (e.getSource() == __graphDelayJButton) { try { __worksheetR.deselectAll(); int index = __worksheetL.getSelectedRow(); if (index == -1) { return; } StateMod_DelayTable currentDelay = ((StateMod_DelayTable) __delaysVector[index]); int j; DateTime date; TSIdent tsident = new TSIdent(); tsident.setLocation(currentDelay.getID()); tsident.setSource("StateMod"); if (__monthly_data) { tsident.setInterval("Month"); } else { tsident.setInterval("Day"); } tsident.setType("Delay"); DateTime date1 = null; DateTime date2 = null; int interval_base; if (__monthly_data) { date1 = new DateTime(DateTime.PRECISION_MONTH); date2 = new DateTime(DateTime.PRECISION_MONTH); interval_base = TimeInterval.MONTH; } else { date1 = new DateTime(DateTime.PRECISION_DAY); date2 = new DateTime(DateTime.PRECISION_DAY); interval_base = TimeInterval.DAY; } date1.setMonth(1); date1.setYear(1); date2.setMonth(1); date2.setYear(1); date2.addInterval(interval_base, (currentDelay.getNdly() - 1)); TS ts = null; if (__monthly_data) { ts = new MonthTS(); } else { ts = new DayTS(); } ts.setDate1(date1); ts.setDate2(date2); ts.setIdentifier(tsident); if (__monthly_data) { ts.setDescription(ts.getLocation() + " Monthly Delay Table"); } else { ts.setDescription(ts.getLocation() + " Daily Delay Table"); } ts.setDataType("Delay"); ts.setDataUnits(currentDelay.getUnits()); ts.allocateDataSpace(); double max = 0.0; for (date = new DateTime(date1), j = 0; date.lessThanOrEqualTo(date2); date.addInterval(interval_base, 1), j++) { ts.setDataValue(date, currentDelay.getRet_val(j)); if (currentDelay.getRet_val(j) > max) { max = currentDelay.getRet_val(j); } } IList<TS> tslist = new List<TS>(); tslist.Add(ts); PropList graphProps = new PropList("TSView"); // If dealing with small values, use a high // of precision... if (max < 1.0) { graphProps.set("YAxisPrecision","6"); graphProps.set("OutputPrecision","6"); } else { graphProps.set("YAxisPrecision","3"); graphProps.set("OutputPrecision","3"); } graphProps.set("InitialView", "Graph"); graphProps.set("TotalWidth", "600"); graphProps.set("TotalHeight", "400"); if (__monthly_data) { graphProps.set("Title", ts.getLocation() + " Monthly Delay Table"); } else { graphProps.set("Title", ts.getLocation() + " Daily Delay Table"); } graphProps.set("DisplayFont", "Courier"); graphProps.set("DisplaySize", "11"); graphProps.set("PrintFont", "Courier"); graphProps.set("PrintSize", "7"); graphProps.set("PageLength", "100"); new TSViewJFrame(tslist, graphProps); } catch (Exception) { Message.printWarning(1, routine, "Unable to graph delay. "); } } } }