Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract storage elevations #32

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions tools/steady.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ type RSFlow struct {

// Storage Area Elevation Data Pair.
type StoAreaElevation struct {
SorageArea string `json:"storage_area"`
Elevation float64 `json:"elevation"`
StorageArea string `json:"storage_area"`
Elevation float64 `json:"elevation"`
}

// Get Number of Profiles.
Expand Down Expand Up @@ -126,6 +126,37 @@ func parseSteadyBCHeader(line string) (reach string, profNum int, err error) {
}
}

//Get Storage Area information and add to the appropriate profile if not empty
func getStorageArea(sc *bufio.Scanner, sd *SteadyData) error {
line := sc.Text()
roe := rightofEquals(line)

nameAndProfile := strings.Split(roe, ",")
name := strings.TrimSpace(nameAndProfile[0])
numProfiles, innerErr := strconv.Atoi(strings.TrimSpace(nameAndProfile[1]))
if innerErr != nil {
return innerErr
}

values, innerErr := parseSeriesTextBlock(sc, numProfiles, 80, 8)
if innerErr != nil {
return innerErr
}

for i, textVal := range values {
if len(textVal) > 0 {
floatVal, err := parseFloat(textVal, 64)
if err != nil {
return err
}
newStorage := StoAreaElevation{name, floatVal}
sd.Profiles[i].StorageAreaElevations = append(sd.Profiles[i].StorageAreaElevations, newStorage)
}
}

return nil
}

// Get Boundary Condition's data.
// Advances the given scanner.
// Returns only when new RAS element is encountered
Expand Down Expand Up @@ -245,6 +276,16 @@ func getSteadyData(fd *ForcingData, fs filestore.FileStore, flowFilePath string)
}
case "Boundary for River Rch & Prof#":
skipScan, err = getReachBCs(sc, &sd)
if err != nil {
return err
}

case "Storage Area Elev":
err := getStorageArea(sc, &sd)
if err != nil {
return err
}

}

// if a new RAS element is encountered during the functions call, scanning again will skip that element, therefore skip scan
Expand Down
37 changes: 28 additions & 9 deletions tools/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,43 @@ func numberofLines(nValues int, colWidth int, valueWidth int) int {

// Get series from HEC-RAS Text block that contains series e.g. Flow Hydrograph
func seriesFromTextBlock(sc *bufio.Scanner, nValues int, colWidth int, valueWidth int) ([]float64, error) {
series := []float64{}
series := make([]float64, nValues)

textValues, err := parseSeriesTextBlock(sc, nValues, colWidth, valueWidth)
if err != nil {
return series, err
}
for i, val := range textValues {
floatVal, err := parseFloat(val, 64)
if err != nil {
return series, errors.Wrap(err, 0)
}
series[i] = floatVal
}

return series, nil
}

// Returns a series of strings (rather than floats)
// Can check for empty entries rather than set to 0
func parseSeriesTextBlock(sc *bufio.Scanner, nValues int, colWidth int, valueWidth int) ([]string, error) {
series := make([]string, nValues)
i := 0
out:
for sc.Scan() {
line := sc.Text()
for s := 0; s < colWidth; {
for s := 0; s < colWidth; s += valueWidth {
if len(line) > s {
val, err := parseFloat(strings.TrimSpace(line[s:s+valueWidth]), 64)
if err != nil {
return series, errors.Wrap(err, 0)
}
series = append(series, val)
if len(series) == nValues {
val := strings.TrimSpace(line[s : s+valueWidth])

series[i] = val
i++
if i == nValues {
break out
}
} else {
break
}
s += valueWidth
}
}
return series, nil
Expand Down