1 | % (c) 2009-2013 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(units_alias, [ | |
6 | unit_alias/2, | |
7 | init_user_defined_alias/0 | |
8 | ]). | |
9 | ||
10 | :- use_module(probsrc(pragmas)). | |
11 | :- use_module(probsrc(error_manager)). | |
12 | ||
13 | :- use_module(unit_parser). | |
14 | ||
15 | :- use_module(probsrc(module_information)). | |
16 | :- module_info(group,plugin_units). | |
17 | :- module_info(description,'Units Plugin: Short aliases for commonly used units.'). | |
18 | ||
19 | init_user_defined_alias :- | |
20 | findall(alias(AliasName,Definition), | |
21 | global_pragma(unit_alias,[AliasName|Definition]), | |
22 | List), | |
23 | init_user_defined_alias2(List). | |
24 | ||
25 | init_user_defined_alias2([]). | |
26 | init_user_defined_alias2([alias(AliasName,Definition)|T]) :- | |
27 | unit_args_to_list(Definition,List), | |
28 | ((\+ unit_alias(AliasName,List2), List2 \= List) -> add_error(incorrect_unit_definition, 'Unit Alias used twice: ', AliasName) ; true), | |
29 | assert(unit_alias(AliasName,List)), | |
30 | init_user_defined_alias2(T). | |
31 | ||
32 | :- dynamic unit_alias/2. | |
33 | ||
34 | % lengths | |
35 | unit_alias(mm, [[-3,m,1]]). | |
36 | unit_alias(cm, [[-2,m,1]]). | |
37 | unit_alias(dm, [[-1,m,1]]). | |
38 | unit_alias(m, [[0,m,1]]). | |
39 | unit_alias(km, [[3,m,1]]). | |
40 | ||
41 | % railway-specific units | |
42 | unit_alias(hm, [[0,hm,1]]). % half-meter | |
43 | ||
44 | % volume | |
45 | unit_alias(l, [[-3,m,3]]). | |
46 | ||
47 | % time | |
48 | unit_alias(s, [[0,s,1]]). | |
49 | unit_alias(mins, [[0,mins,1]]). | |
50 | unit_alias(h, [[0,h,1]]). | |
51 | unit_alias(d, [[0,d,1]]). | |
52 | ||
53 | % speed | |
54 | unit_alias(mps, [[0,m,1],[0,s,-1]]). | |
55 | unit_alias(kmh, [[3,m,1],[0,h,-1]]). | |
56 | ||
57 | % temperature | |
58 | unit_alias(degC, [[0,degC,1]]). | |
59 | unit_alias('K', [[0,'K',1]]). |