Showing posts with label Awk 'n SED. Show all posts
Showing posts with label Awk 'n SED. Show all posts

Friday, December 07, 2007

Extracting Door Data from .SIM Files Using Awk

Topic: Door counts, areas & conductance losses from SIM files using Awk data extraction scripts.

Below is a simple door counting script using GNU Awk. More sophisticated data extraction routines are in progress -- thanks to all the good people at comp.lang.awk:

# DOOR_COUNT.AWK extracts the door count from the specified .SIM report using
# GNU Awk for Windows:
#
# http://gnuwin32.sourceforge.net/packages/gawk.htm
#
# Note that GAWK.EXE must exist in the shell path. Thus after installation
# using the package installer, it is recommended that copies of GAWK.EXE,
# libconv2.dll, and libintl3.dll (found in
C:\Program Files\GnuWin32\bin in
# default installations)
be placed in the %WINDIR%\system32 directory.
#
#
Save this program as DOOR_COUNT.AWK in the eQuest projects directory, e.g.
#
# C:\Program Files\eQuest [Rev]\Projects\DOOR_COUNT.AWK
#
# ...where [Rev] is the current eQuest revision.
#
# If not done so already, under the "My Computer\System Properties\Advanced"
# tab click the "Environment Variables" button and add the following system
# environment variable:
#
# Variable name: AWKPATH
# Variable value: C:\Program Files\eQuest [Rev]\Projects
#
# ...where [Rev] is the current eQuest revision. This will allow AWK to find
# the program library from any project directory

#
# CMD-line usage:
#
# gawk -f DOOR_COUNT.AWK SimFile.SIM
#
# ...where the data file SimFile.SIM must exist in the current directory.
#

/TOTAL    WINDOWS/{go=1}/^[[:digit:][:space:]]+$/\
&&go{Doors+=$3;go=0}END{print "Door Count = " Doors}

Sunday, November 11, 2007

Outdoor Air Load Estimator

Topic: A nifty Java-based outdoor air load calculator, courtesy of ArchEnergy Inc.

Consider this calculator, which includes American and Canadian weather tables, for reality checking energy recovery numbers calculated by energy modeling programs. Following is a sample output report:

********************************************************************************************

Result summary for Calculation Number: 5
Location: BURLINGTON, Vermont
Elevation: 341 ft
Operating Hours: 0:00 o'clock until 0:00 o'clock
Hours of Operation: 24
Makeup Air Flow: 183000 cfm
Thermostat Setpoints: Heating = 68 F, Cooling = 72 F

Dehumidification was set to limit the Relative Humidity to: No Dehumidification

Heating was locked out during: --
Cooling was locked out during: --

The Lockout of Heating or Cooling systems resulted in...
Insufficient Heating during: --
Insufficient Cooling during: --

The Heating Design Load is: 18891.3 kBtu/h
The Cooling Design Load is: 4754.9 kBtu/h

Calculated Monthly loads:
Month Heating Load Cooling Load
January : 7,847,593 kBtu 0 kBtu
February : 7,329,964 kBtu 0 kBtu
March : 6,296,320 kBtu 0 kBtu
April : 3,911,545 kBtu 28,900 kBtu
May : 1,574,753 kBtu 97,140 kBtu
June : 889,352 kBtu 128,736 kBtu
July : 399,761 kBtu 382,194 kBtu
August : 532,923 kBtu 221,369 kBtu
September : 1,517,449 kBtu 33,329 kBtu
October : 2,836,548 kBtu 0 kBtu
November : 4,821,821 kBtu 0 kBtu
December : 6,956,354 kBtu 0 kBtu
Total_Year : 44,914,382 kBtu 891,668 kBtu

FAN ENERGY CALCULATIONS:
Supply Exhaust
Total Static Pressure: 3.5 inW 1.0 inW
Fan Type: Forward_Curved Forward_Curved
Fan Efficiency: 63.0 % 63.0 %
Motor Class: Standard Standard
Motor Efficiency: 91.0 % 89.0 %
Motor Output Power: 159.032 HP 45.438 HP
Moter Rated Input: 130.319 kW 38.071 kW
Motor Energy Consumption: 1141594 kWh 333499 kWh
********************************************************************************************


Set system runtimes matching equipment operational schedule to establish an upper bound for energy recovery savings. Here the building is operating at 7x24, and if the rough cost for a therm of natural gas and a kilowatt hour of electricity are $1.20 and $0.10 respectively, then an upper bound on heat recovery savings is:

  • 1.20 $/therm * 44,914,382 kBTU / 100 kBTU per therm = $530,973 from gas, and
  • $0.10 $/kWH * 1,141,594 kWH = $114,160 from electricity,
  • for a total of $645,133 heating load cost with systems running 24 hours a day, seven days a week, for one year at constant volume.
This number is the maximum theoretical value of the savings, however it cannot be approached without 1) consistent internal heat gains -- heat gains sufficient to keep the exhaust airstream temperature elevated effectively above the outdoor air temperature, and 2) significant fan motor energy expenditures.

What typically happens in laboratory-type buildings is that while there may be a consistent heat recovery demand, the heat available to recover varies widely with occupancy. And likely there will be a number of hours in a 7 x 24 year-round operation when the outside air approaches to within 5° of the exhaust air, rendering energy recovery essentially ineffective.

Have not counted heat recovery from a cooling standpoint, as the number of annual hours where the outside air exceeds the exhaust air by more than 5° F in this climate most likely won't be very compelling.

So for how many hours per year does the exhaust air temperature exceed the outside air and by how much, on the average? Just check that 'Outside & Exhaust Air Loads Report' in the SIM file...if it actually existed, it might tell you...;-) All of the information is calculated and carried in the program, and presumably is output to the SIM file directly and indirectly in various places.

Am hoping to figure a way to pull a report like the above-mentioned together one of these days...if anyone has an Awk-based outside air loads report, even a rudimentary one as a starting point, I'd be much obliged.

Wednesday, November 07, 2007

eQuest SIM File Data Extraction Using Awk

Topic: Extracting discrete data values using Gawk (GNU Awk)

Following are some (one, for now) potentially useful Gawk (using GNU Awk for Win32) scripts for extracting data from an eQuest/DOE2 output SIM file :

# Save this script to a file named BEPU.AWK in the directory
# containing the simulation output files.
#
# BEPU.AWK extracts energy consumption totals from
# the specified .SIM report using GNU Awk for Windows:
#
# http://gnuwin32.sourceforge.net/packages/gawk.htm
#
# Note that GAWK.EXE must exist in the shell path. Thus after installation
# using the package installer, it is recommended that a copy of GAWK.EXE
# be placed in the %WINDIR%\system32 directory.
#
# Usage:
#
# gawk -f BEPU.AWK SimFile.SIM
#
# ...where the program file BEPU.AWK and data file SimFile.SIM must exist.
#

{if ($2 ~/BEPU/) {ipr = 1}}
{if (ipr == 1)
{if ($1 == "TOTAL") print $1" "$2" "$3" "$4
if ($2 == "PS-H") ipr = 0}}
At left is a simple Awk script to extract the energy consumption totals in kWH and therms from the specified SIM file.

Run this script from a CMD prompt in the same directory as your .SIM files; be sure to copy GAWK.EXE to %WINDIR%\System32, where %WINDIR% is usually (but not always) C:\WINDOWS.

Modified from an original script posted by Joe Huang in the BLDG-SIM archives.

Thanks Joe!

More fun with Awk and SED to come over the next few months, as time permits or workload demands.

Note that in this example, printing is turned on (ipr = 1) by flagging the desired report, and off (ipr = 0) by flagging the report following the desired report. Examine the contents of the SIM file or see this post to determine the actual report sequence -- its not the same as shown in the drop-down box in the SIM file viewer.

More Awk examples from elsewhere...

Monday, November 05, 2007

SED & eQuest SIM File Reports

Topic: Extracting individual reports from SIM files using SED

See this post for another SED vs. Awk comparative editorial. Following is my own take, after fiddling around with SED for a few hours in an attempt accomplish discrete value data extraction.

Next time: Discrete value data extraction using Awk!

SED = Sledgehammer

SED seems most useful for gross editing tasks -- i.e. global search-and-replacements or chunking out reports from the SIM file. SED is essentially batch application of regular expressions.

Lacking basic programming constructs, there are fundamental functionality limitations. But for the tasks it is capable performing, SED accomplishes them exceedingly well.

Awk = Sawzall

With built-in programming language constructs, Awk seems to be more suited for 'refined' tasks like discrete value data extraction, doing arithmetic on arrays and columns, or creating custom reports.

They both seem to be the right tool, just for different tasks. Following are some potentially useful SED examples (using GNU SED for Win32):

SED /HW-BOILER/!d SimFile.SIMOutputs from SimFile.SIM all lines with HW-BOILER
SED /PS-E/,/PS-F/!d SimFile.SIM
Outputs the PS-E report contained in SimFile.SIM
@ECHO OFF
SET SIMRPT=Energy Cost Summary
SET SIMBGN=BEPS
SET SIMEND=BEPU
SED.EXE --version >NUL
IF %ERRORLEVEL% GTR 0 GOTO USAGE
IF EXIST %1.SIM GOTO NEXT
GOTO USAGE

:NEXT
SED /%SIMBGN%/,/%SIMEND%/!d %1.SIM >%TEMP%\~SED.TMP
IF /I "%2" EQU "/A" GOTO APPEND
SED /%SIMEND%/d %TEMP%\~SED.TMP
GOTO :EOF
:APPEND
SED /%SIMEND%/d %TEMP%\~SED.TMP >>%0.RPT
GOTO :EOF

:USAGE
ECHO.
ECHO The %SIMBGN%.CMD script extracts the "%SIMRPT%" section from
ECHO the specified .SIM report using GNU SED for Windows:
ECHO.
ECHO http://gnuwin32.sourceforge.net/packages/sed.htm
ECHO.
ECHO Note that SED.EXE must exist in the shell path. Thus after installation
ECHO using the package installer, it is recommended that a copy of SED.EXE
ECHO be placed in the %WINDIR%\system32 directory.
ECHO.
ECHO Usage:
ECHO.
ECHO %SIMBGN% SimFile [/A]
ECHO.
ECHO ...where SimFile is specified without the .SIM extension and must exist.
ECHO If the optional /A parameter is supplied, the output will be appended to
ECHO a file named %SIMBGN%.RPT so that a 'FOR' command may collect
ECHO all %SIMBGN% reports into a single file for further processing.
ECHO.
ECHO Example:
ECHO.
ECHO FOR %%i in (*.SIM) DO %SIMBGN% "%%~ni" /A
ECHO.
ECHO CAUTION!!! The %SIMBGN%.RPT file must be deleted manually
ECHO to be refreshed, else updates will simply be appended to it.
ECHO.
ECHO Released to public domain under General Public Licence (GPL)
ECHO http://www.gnu.org/licenses/gpl.html
ECHO Copyright 2007 by Brandon Nichols, PE
ECHO.

The command script at left extracts the BEPS report from the specified .SIM file and echoes it to the screen by default.

Copy the code, paste it to a blank Notepad window. Save the file as 'BEPS.CMD' (be sure to change the drop-down in the Notepad file-save dialog from '*.txt' to 'All Files') to the eQuest reports directory, or to a designated script directory in the command path.

Assure that GNU SED.EXE may also be found in the command path -- see the installation tip under 'USAGE' in the script.

Type 'BEPS SimFile' at the CMD prompt, where SimFile is specified WITHOUT the .SIM extension.

Now for some real fun type 'BEPS' at the CMD prompt and hit return, then copy/paste the 'FOR' example displayed on the 'Usage' screen to the CMD prompt and hit return. Written to disk will be each BEPS report from all simulations in a directory into a text file named BEPS.RPT for output or further processing.

To create your own report extractor, simply change the three 'SET' values at the top of the file and save it under a new name.

For instance changing values of SIMRPT to Summary of Utility Rates,
SIMBGN to BEPU, and SIMEND to PS-H creates a BEPU extractor.


When creating a new report extractor, examine the contents of the SIM file or see this post to determine the actual report order -- its not the same as shown in the drop-down box in the SIM file viewer.

Perhaps not immediately obvious, but a 'System Report Extractor' for a report within the SIM file 'system repeat block' will extract each instance of the report for all systems! For example, copy the script above to Notepad and change the values of SIMRPT to 'System Utility Energy Use', SIMBGN to 'SS-H', and SIMEND to 'SS-I' and save to SS-H.CMD (be sure to change the drop-down in the Notepad file-save dialog from '*.txt' to 'All Files') in same directory where the SIM files are located. Thus created is an SS-H extractor that extracts all System Utility Energy Use reports for every system from the specified SIM file!.

Type 'SS-H SimFile' (without the .SIM extension) at the command line to test the output. Note that SimFile must exist in the same directory as the script and GNU SED.EXE must be in the command search path. If the above conditions have been met and your syntax is correct, then all SS-H reports will be echoed sequentially to the screen.

Now type just 'SS-H' at the command line and hit return. Then copy/paste the 'FOR' example from the usage screen to the command line and hit return. Congratulations, you have just created the text file SS-H.RPT, containing each System Utility Energy Use report for every system from all SIM files in the current directory!

eQuest SIM File Reports

Topic: A listing of the reports in the order found in the DOE2 .SIM output file


LV-M
DOE-2.2 Units Conversion Table
LV-N
Building Coordinate Geometry
LV-A
General Project Parameters

LV-B
Summary of Spaces

LV-C
Details of Space

LV-D
Details of Exterior Surfaces

LV-E
Details of Underground Surfaces

LV-F
Details of Interior Surfaces

LV-G
Details of Schedules

LV-H
Details of Windows

LV-I
Details of Constructions

LV-J
Details of Building Shades

LS-A
Space Peak Loads Summary

LS-B
Space Peak Loads Components
LS-C
Building Peak Load Components

LS-D
Building Monthly Loads Summary

LS-E
Space Monthly Load Components

LS-F
Building Monthly Load Components

LS-K
Space Input Fuels Summary

LS-K
Building Input Fuels Summary

LS-L
Management and Solar Summary

SV-A
System Design Parameters

SS-D
Building HVAC Load Summary

SS-E
Building HVAC Load Hours

SS-M
Building HVAC Fan Elec Energy

SS-A
System Loads Summary
Begin system repeat
SS-B
System Load Summary Zones
block
SS-C
System Load Hours
|
SS-H
System Utility Energy Use
|
SS-I
Sensible/Latent Summary
|
SS-J
Peak Heating and Cooling
|
SS-K
Space Temperature Summary
This group of
SS-R
Zone Performance Summary
reports is repeated
SS-L
Fan Electric Energy Use
once for each system
SS-N
Relative Humidity Summary
|
SS-P
Heating Performance Summary
|
SS-P
Cooling Performance Summary
|
SS-G
Zone Loads Summary
|
SS-F
Zone Demand Summary
End system repeat
SS-O
Space Temperature Summary
block
PV-A
Plant Design Parameters

PS-A
Plant Energy Utilization

PS-B
Utility and Fuel Use Summary

PS-C
Equipment Loads and Energy Use

PS-D
Circulation Loop Loads

PS-E
Energy End-Use Summary for all Electric Meters

PS-E
Energy End-Use Summary for all Fuel Meters

PS-F
Energy End-Use Summary for Meters

BEPS
Building Energy Performance

BEPU
Building Utility Performance

PS-H
Loads and Energy Usage for Plant

HOURLY REPORT
Hourly Report for Energy End-Usage

EV-A
Life-Cycle Costing Parameters

ES-AAnnual Costs and Savings

ES-BLife-Cycle Non-Energy Costs

ES-CLife-Cycle Investment Savings

ES-DEnergy Cost Summary
ES-ESummary of Utility Rates
ES-FBlock Charges and Ratchets

Monday, October 29, 2007

MultiEdit & Regular Expressions

Topic: Using the MultiEdit text editor and regular expressions to clean up DOE2 .inp files generated by the eQuest wizard.

MultiEdit

There are a number of adequate text editors out there -- many of them are free. My favorite text editor is not free, but IMHO MultiEdit stands a professional cut above the freeware pack. A partial list of features that makes it particularly suitable to working with DOE2 files is as follows:



  • Multiple tabbed windows, allowing rapid file switching
  • Remembered windows, from the last time the program was open
  • Multiple sessions. Most useful if you wear additional hats like 'CAD Guru' or 'Systems Integrator' -- each named session recalls a group of files in exactly the same window state as when last worked upon.
  • Split windows, permitting two different parts of the same file to be edited
  • Line numbers and a handy 'go to line number' function
  • Scrolling side-by-side on-screen file comparisons, highlighting the location and nature of differences between files
  • An undo buffer that will take you back to the beginning of an editing session, even after a massively botched search and replacement.
  • Backup files saved in a common directory on the local hard drive, off-network. This has saved many hours of rework more than once in my brief career so far with eQuest.
  • ...more features to be listed as time permits
  • And last but not least, search and replacements using 'regular expressions'
Regular Expression Examples

Regular expressions enable powerful search and replacements in a single operation that would otherwise require many operations using 'literal' search and replace strings. The syntax is necessarily cryptic for utilitarian compactness; however comprehensive free learning resources are just a google away, such as this tutorial site
.
Expect a bit of a learning curve, but once you've accomplished a search and replacement in a single line that would've taken a dozen or more literal iterations, there's no going back.

Further, regular expression syntax is applicable to scripting utilities such as Perl and SED, meaning that once your approach to search and replacements has become standardized, it can be batched and run without ever opening the input files -- when I get to this point with .inp and .sim files I'll be sure to post some examples.

First and foremost, make backup files religiously when working with eQuest in general, and in particular do not fail to do so before tackling a relatively risky editing task such as this -- it's always easier (and better for your social life) to restart from the last waypoint than to rebuild a disaster.

Schedules

REMINDER: Make sure you change the type of "Regular Expression" from Perl to Unix on the "Search and Replace" Option tab.

Following are MultiEdit search and replace strings using regular expressions applicable to DOE2 schedules; be sure to uncheck the radio button entitled 'Search All Windows' (refer to screenshot below) until you're sure you know what you're doing.


  • System Fan Schedules: Replace all auto-generated system fan schedules with a single fan schedule named 'EMS Fan Sch'
    • Search String: (")S.* Fan Sch
    • Replace String: \0EMS Fan Sch
  • System Cooling Schedules: Replace all auto-generated system cooling schedules with a single cooling schedule named 'EMS Cool Sch'
    • Search String: (")S.* Cool Sch
    • Replace String: \0EMS Cool Sch
  • System Heating Schedules: Replace all auto-generated system heating schedules with a single heating schedule named 'EMS Heat Sch'
    • Search String: (")S.* Heat Sch
    • Replace String: \0EMS Heat Sch
  • Infiltration Schedules: Replace all auto-generated perimeter infiltration schedules with a single infiltration schedule named 'EMS P-Inf Sch'
    • Search String: (")Z.* P-Inf Sch
    • Replace String: \0EMS P-Inf Sch
  • Infiltration Schedules: Replace all auto-generated core infiltration schedules with a single infiltration schedule named 'EMS C-Inf Sch'
    • Search String: (")Z.* C-Inf Sch
    • Replace String: \0EMS C-Inf Sch
  • Building Occupancy Schedules: Replace all auto-generated building occupancy schedules with a single building occupancy schedule named 'EMS Occup Sch'
    • Search String: (")E.* Bldg Occup Sch
    • Replace String: \0EMS Occup Sch
  • Building Office Equipment Schedules: Replace all auto-generated office equipment schedules with a single office equipment schedule named 'EMS OffEq Sch'
    • Search String: (")E.* Bldg OffEq Sch
    • Replace String: \0EMS OffEq Sch
  • Building Inside Lighting Schedules: Replace all auto-generated inside lighting schedules with a single inside lighting schedule named 'EMS InsLt Sch'
    • Search String: (")E.* Bldg InsLt Sch
    • Replace String: \0EMS InsLt Sch
  • Building Cooking Schedules: Replace all auto-generated cooking schedules with a single cooking schedule named 'EMS Cook Sch'
    • Search String: (")E.* Bldg Cook Sch
    • Replace String: \0EMS Cook Sch
  • Exterior Lighting Schedules (same as literal): Replace the string 'Ext Lighting Sch' with the string 'EMS Ext Lighting Sch'
    • Search String: "Ext Lighting Sch
    • Replace String: "EMS Ext Lighting Sch
  • Domestic Hot Water Schedules (same as literal): Replace the string 'DHW Eqp NRes Sch' with the string 'EMS DHW Eqp NRes Sch'
    • Search String: "DHW Eqp NRes Sch
    • Replace String: "EMS DHW Eqp NRes Sch
It should go without saying that the schedules named by the replacement strings need to exist in the .inp file -- see this post for an outline procedure to copy schedules from one project to another. Be aware that the search and replacements described above should be done only after swapping-out the .inp file's daily, weekly and annual schedule sections.

Envelope

Following are MultiEdit search and replace strings using regular expressions applicable to DOE2 envelope components; be sure to uncheck the radio button entitled 'Search All Windows' (refer to screenshot below) until you're sure you know what you're doing.



  • Exterior Walls: Replace all auto-generated exterior wall constructions with a single construction named 'Exterior Wall Construction'
    • Search String: = "E.{1,4} EWall Construction"
    • Replace String: = "Exterior Wall Construction"
  • Roofs: Replace all auto-generated roof constructions with a single construction named 'Exterior Roof Construction'
    • Search String: = "E.{1,4} Roof Construction"
    • Replace String: = "Exterior Roof Construction"
  • Windows: Replace auto-generated 'Window Type #1 GT' glass types in all shells with a single glass type named 'Exterior Glass Type #1'
    • Search String: = "E.{1,4} Window Type \#1 GT"
    • Replace String: = "Exterior Glass Type \#1"
  • Window Frames & Spacers: Eliminate frames and install insulated spacers on all 'Exterior Glass Type' permutations
    • Search String: ("Exterior Glass Type \#.*$).*FRAME-WIDTH =.*$
    • Replace String: \0$ SPACER-TYPE = INSULATED
Systems, Loops & Equipment

The following MultiEdit search and replace strings using regular expressions are applicable to DOE2 systems, loops and equipment; be sure to uncheck the radio button entitled 'Search All Windows' (refer to screenshot below) until you're sure you know what you're doing.



  • Hot Water Loop: Replace assignments to the HW-LOOP keyword with 'Hot Water Loop'; note leading space to prevent matching the DHW-LOOP keyword.
    • Search String: ( HW-LOOP *= ).*$
    • Replace String: \0"Hot Water Loop"


A very handy tool for learning regular expressions is RegExBuddy, available from the author's site for a nominal fee. MultiEdit also includes some regular expression help built into the search and replace dialog box; click the left-arrows to the right of the search and replace fields when the regular expression radio button is selected:




(click on the image to see a larger version)

Next time...regular expression fun with SED and SIM files!

Note: a reasonable set of extensions for the MultiEdit 'Add Files Wizard' is as follows:
AWK SED INP TXT DOC PD2 BDL PRD SIM CSV PDH DAT CMD DAT
Process Loads:
This is the link for the process loads Btu/(People x Hr) for different kind of building