Archive site for Autodesk Ecotect Analysis educational resources, notes and tutorials



Script example 03

FormatDataTable.scr

This script demonstrates the process of performing a thermal analysis and then extracting the data for a specific zone into a tab-delimited textual table. This table can then be copy/pasted directly into a spreadsheet or any other text-based formating application.

When calculating hourly gains for a day using the calc.thermal.gains command, the results are stored each hour for each component of the heat gains to the zone, where the index into the get.results.array data is shown in the following table. In this case the HVAC load is ignored (hence the indexes 1,6) and we sum up the total gains ourselves.

DATA TYPE INDEX
Total HVAC Load 0
Conduction Gain 1
Sol-Air Gains 2
Direct Solar Gains 3
Ventilation Gains 4
Internal Gains 5
Inter-Zonal Gains 6
Table 1 - Gain Indexes in Results Array

Of some interest may be the use of the "%s%12.0f" format in the printf command. This simply includes the delimiter as a string value without caring how big/small it is, but then immediately follows it with a floating value formated number 12 spaces in size and with 0 decimal places. Combined with the "%s%12s" format in the table header, this keeps all the columns neatly aligned.

Script Contents (Lang: lua)

--[[---------------------------------------------
-- TABULATE HOURLY GAINS IN CURRENT ZONE:
-- This script calculates hourly heat gains 
-- for the current zone in the current model
-- and displays the hourly totals.
--]]---------------------------------------------

-- Specify a start day of the year (1-365).
startDay = 219;

-- Run calculation for set number of days.
stopDay = startDay + 14

-- If you separate values in your text 
-- table with a TAB character, you can 
-- simply copy/paste it into spreadsheet.
delimiter = "\t";

-- Get index and name of current zone.
currentZone = get("model.currentzone")
currentZoneName = get("zone.name", currentZone)

-- Allocate an array of arrays 
-- for the table of gain data.
zoneData = {}
for hr = 0, 23 do
    zoneData[hr] = {}
end

-- Print out a title for the table.
-- ---------------------------------------------
modelfile = get("model.file")
printf("Model: %s, Zone: %s", modelfile, currentZoneName);
printf("Hourly Gains From %d to %d.", startDay, stopDay);
printf("\n")

-- Output table title.
printf("%4s%s%4s%s%12s%s%12s%s%12s%s%12s%s%12s%s%12s%s%12s",
  "Day", delimiter,
  "Hour", delimiter,
  "Conduction", delimiter,
  "SolAir", delimiter,
  "DirectSolar", delimiter,
  "Ventilation", delimiter,
  "Internal", delimiter,
  "InterZonal", delimiter,
  "OVERALL"
  )

-- Cycle through each day of the year.
-- ---------------------------------------------
for day = startDay,stopDay do

  -- Set required date.
  set("dayoftheyear", day);

  -- Calculate hourly gains for specific zone.
  cmd("calc.thermal.gains", currentZone);

  -- Cycle through hours.
  for hr = 0, 23 do

    -- Initilise each hour.
    total = 0

    -- store and sum up all 6 types 
    -- of space gain in that hour.
    for i = 1, 6 do 
      zoneData[hr][i] = get("results.array", i, hr);
      total = total + zoneData[hr][i]
    end

    -- Add total at end of array.
    zoneData[hr][0] = total;

  end

  -- Cycle through hours.
  for hr = 0, 23 do

    -- Add day and hour columns.
    line = format("%03d%s%02d", day, delimiter, hr) 

    -- Add column for each gain type.
    for i = 1, 6 do 
      line = line .. format("%s%12.0f", 
        delimiter, zoneData[hr][i]
        )
    end 

    -- Add column for total.
    line = line .. format("%s%12.0f", 
      delimiter, zoneData[hr][0]
      )

    -- Output the row.
    print(line)

  end

end

HOW WOULD YOU RATE THIS SCRIPT ?

No votes yet


Navigation

User login

Translate Site To: