Presentation is loading. Please wait.

Presentation is loading. Please wait.

Frank Milthorpe 27 May 2011 Suite of Emme Macros to Enable Flexible Specification of Multiple Data Sources.

Similar presentations

Presentation on theme: "Frank Milthorpe 27 May 2011 Suite of Emme Macros to Enable Flexible Specification of Multiple Data Sources."— Presentation transcript:

1 Frank Milthorpe 27 May 2011 Suite of Emme Macros to Enable Flexible Specification of Multiple Data Sources

2 Outline 1.Goals 2.Text registers within Emme 3.Implementation Approach 4.Conclusions 5.Listing of macros

3 Goals Flexible definition of input data Easy to distinguish differences between model runs Implemented within Emme macros

4 Overview of Desired Specification Run 1 Standard Inputs except Employment_A Run 2 Standard Inputs except Population_B Employment_C

5 Text Registers t1.. t9 are text registers available t9 is global t1.. t8 local registers –can ’ t return arguments Can ’ t “ load-up ” registers with filenames from a lower macro

6 Implementation Approach Create a LIFO (last in first out) text file Write to text file with label and filename Read the text file in appropriate macro to retrieve and return filename via t9 Also allows an audit trail

7 Example Data File Created start_default === 27-Apr :23 zonal_data M:\STM_Core\Inputs\ZonalMtx\ emp_data M:\STM_Core\Inputs\Employment\2009_Oct\ pop_adjust_file m:\stm_gma\lu_adjust\pop_adjust_default.mtx emp_adjust_file m:\stm_gma\lu_adjust\emp_adjust_default.mtx timeskim_busonly_macro tskimfac carskim_data M:\STM_Core\Inputs\Calibration_data\Dec_09\ end_default === pop_adjust_file M:\Myproject\PopFac_2011.mtx carskim_data M:\Myproject\carskim_matrices\

8 Reading Data ~/... Start of macro read_emp.mac %ms02%... ~# ~t2=%t1%read_emp.rep ~

9 Conclusions Macro suite designed and implemented to meet requirements Can be a filename or a directory Can be adapted for other purposes (eg specify assignment parameters) Text file provides an audit log of specifications

10 Core Macros delete_data_source_stackDelete the data_source_stack file create_data_source_stackCreate data_source_stack file write_data_sourceWrite an item to a data_source_stack file get_data_source_itemFind a return value for data item strip_leading_blanks Trim the leading spaces from a text string

11 delete_data_source_stack.mac ~:start ~/... Start of macro delete_data_source_stack.mac... ~# ~

12 create_data_source_stack.mac ~:start ~/... Start of macro create_data_source_stack.mac... ~# ~

13 write_data_source.mac Example macro call write_data_source %1% %2% %1% - source_name %2% - directory (or other item) eg ~stripped ~+;~t2=%t2.-1%;~$continue_stripping ~# ~:stripped ~# Write to output file ~+;~>>%t1%;~"%t2%;~>

14 get_data_source_item.mac (1) ~$>start Emme/2 macro "get_data_source_item.mac" Macro to obtain answer (normally directory) for a data item written to the data_source file. This is the last entry written. N.B. If macro used the first entry this may not be the entry that is needed. For example if the model was rerun with different defaults and the stack was not deleted, it would return the first (and wrong original entry). Example macro call ~

15 get_data_source_item.mac (2) ~:start ~/... Start of macro get_data_source_item.mac %t0%... ~# ~t1=stmaudit\data_source_stack.dat ~# ~# --- Find length of macro argument %1% store in %x% ~t2=%1% ~# ~x=-1 ~:continue_counting ~x+1 ~t3=%t2.1% ~+;~?t3= ;~$>counted ~+;~t2=%t2.-1%;~$continue_counting ~# ~:counted ~# ~# length of argument %1% is %x% ~#

16 get_data_source_item.mac (3) ~# --- Find line in file with source_name ~# ~# t8 - line of data read in ~# t7 - line of data with a match ~# t3 - substring of t8 for trial match to source_name %1% ~# r1 - count of entries found (set to zero initially) ~# ~r1=0 ~# ~:process_line ~+;~?e;~$>end_of_file ~+;~t3=%%t8.%x%% ~+;~?t3=%1%;~t7=%t8% ~+;~?t3=%1%;~r1+1 ~$process_line ~# ~:end_of_file ~#

17 get_data_source_item.mac (4) ~# Was the source_name found? ~+;~?r1>0;~$>found ~# ~:not_found ~/ did not find %1% in get_data_source_item ~t9=Error %1% Not found in get_data_source_item ~$>end ~# ~:found ~# --- Extract the item label (probably directory) ~# remove first %x% chars ~+;~t2=%%t7.-%x%% ~# ~# remove leading blanks ~# result is returned in %t9% ~ ~/... End of macro get_data_source_item.mac %1% %t9%...

18 Strip_leading_blanks.mac ~:start ~# Does this macro have an argument passed to it? ~x=%0% ~+;~?x>0;~$>valid_argument ~# No argument - nothing to strip ~t9=%t0% ~# ~$>end ~:valid_argument ~# remove leading blanks if they exist ~t2=%t0% ~:continue_stripping ~t3=%t2.1% ~+;~?!t3= ;~$>stripped ~+;~t2=%t2.-1%;~$continue_stripping ~:stripped ~t9=%t2% ~:end ~# returned value t9 is:%t9% ~#... End of macro stip_leading_blank.mac %t9%...

19 Implementation Macros set_default_data_sourcesWrite the default data sources to data_source_stack file read_empMacro to read employment matrices (similar macros exist to read other data files)

20 set_default_data_sources.mac ~/... Start of macro set_default_data_sources.mac... ~# ~# Make sure directory where data_source_stack.dat resides exists ~

21 read_emp.mac ~:start ~/... Start of macro read_emp.mac %ms02%... ~# ~t2=%t1%read_emp.rep ~

22 General Utility Macros ifexist_deleteDelete a file if it exists get_date_timeObtain and return the date and time make_directoryCreate a DOS directory stm_logWrite to logbook and a DOS file waitWait a specified number of seconds

23 ifexist_delete.mac ~:Start ~# ~!if exist %1% del %1% ~

24 get_date_time.mac (1) ~:start ~# --- Get date string ~# Obtain current day - Global parameter p=2008 ~p=2008 ~x=%p% ~# Obtain current month - Global parameter p=2007 ~p=2007 ~y=%p% ~# Obtain current year - Global parameter p=2006 ~# Depending of status of switch 25 ~# This value may only be a 2-digit year. ~p=2006 ~z=%p% ~+;~?z<2000;~z+2000 ~# --- Obtain month character label ~+;~?y=1;~t2=Jan ~+;~?y=2;~t2=Feb..... ~# Consolidated Date String dd-mmm-yyyy ~# If d is less than 10 need a 0 to pad the field ~t1=%x% ~+;~?x<10;~t1=0%x% ~t4=%t1%-%t2%-%z%

25 get_date_time.mac (2) ~# --- Get date string ~# Obtain current hour - Global parameter p=2009 ~p=2009 ~x=%p% ~# Obtain current minute - Global parameter p=2010 ~p=2010 ~y=%p% ~# Obtain current second - Global parameter p=2011 ~p=2011 ~z=%p% ~# Consolidated Time String hh:mm ~# If hour or min is less than 10 need a 0 to pad the field ~t1=%x% ~+;~?x<10;~t1=0%x% ~t2=%y% ~+;~?y<10;~t2=0%y% ~t5=%t1%:%t2% ~t9=%t4% %t5% ~# ~# t9 (Date Time) is %t9%~#

26 make_directory.mac ~:start ~/... Start of macro Make_directory.mac %1%... ~# ~!IF not exist %1% MKDIR %1% ~# ~/... End of macro Make_directory.mac %1%...

27 stm_log.mac Example macro call stm_log %t0% %t0% - text to write to log file / logbook ~:start ~/... Start of macro stm_log.mac %t0%... ~# ~t1=stm_log.rep ~# ~# Write to output file ~+;~>>%t1%;~"%t0%;~> ~# ~# Write to logbook (with a max of 60 characters) c=%t0.60% ~# ~/... End of macro stm_log.mac %t0%...

28 wait.mac ~:Start ~# current cpu time since creation of database in 1/10 secs ~p=2005 ~x=%p% ~# current sec (1/10) since database creation %x% ~# ~# Add %1% * 10 to current 1/10 second to get new target ~r1=%1% ~r1*10 ~r1+%x% ~z=%r1% ~# ~# New target is %z% ~:Repeat ~# current cpu time since creation of database in 1/10 secs ~p=2005 ~x=%p% ~?x<%z% ~$Repeat ~#

Download ppt "Frank Milthorpe 27 May 2011 Suite of Emme Macros to Enable Flexible Specification of Multiple Data Sources."

Similar presentations

Ads by Google