UnitConverter.st
author Claus Gittinger <cg@exept.de>
Sun, 18 Apr 2010 16:11:29 +0200
changeset 2444 6c4c6addc97a
parent 2443 e64a7f2f3fb4
child 2547 283c931ce260
permissions -rw-r--r--
changed: #initializeConversions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
884
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     1
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     2
 COPYRIGHT (c) 1996 eXept Software AG
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     3
              All Rights Reserved
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     4
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     5
 This software is furnished under a license and may be used
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     6
 only in accordance with the terms of that license and with the
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     9
 other person.  No title to or ownership of the software is
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    10
 hereby transferred.
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    11
"
981
5bbc2823967e ounce thanks to christian
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
5bbc2823967e ounce thanks to christian
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
    13
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Object subclass:#UnitConverter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    16
	classVariableNames:'Conversions Scaling Aliases Constants'
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Magnitude-General'
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!UnitConverter class methodsFor:'documentation'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
884
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    23
copyright
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    24
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    25
 COPYRIGHT (c) 1996 eXept Software AG
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    26
              All Rights Reserved
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    27
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    28
 This software is furnished under a license and may be used
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    29
 only in accordance with the terms of that license and with the
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    31
 be provided or otherwise made available to, or used by, any
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    32
 other person.  No title to or ownership of the software is
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    33
 hereby transferred.
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    34
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    35
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    36
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    37
!
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    38
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    In order to collect various unit conversions into one central
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    manageable (and especially: browsable) place, all previously
564
9d5d54a11553 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 556
diff changeset
    43
    spread knowledge about metric (and other) conversions has been
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    brought into this class.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    This class is purely functional, abstract and has no instances;
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    all queries are via class protocol.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    Choosing the Magnitudes category as its home is arbitrary.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    50
    The supported units are setup in the classes initialize method;
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    51
    supported are:
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    52
        meter - inch - feet - foot - yard
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    53
        meter2 - acre - 'german-ar' 'german-hektar' are
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    54
        liter - gallon - barrel - floz
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    55
        celsius - fahrenheit
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    56
    and many others.
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    57
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    58
    The converter does a recursive search for a conversion;
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    59
    thus, if there is a conversion from #inch to #millimeter and another 
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    60
    from #millimeter to #kilometer, conversion from #inch to #kilometer
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    61
    is found automatically.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    62
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    63
    No Warranty:
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    64
        The numbers and conversion factors were obtained from the Unix
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    65
        units command. Please check before using it - there might be
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    66
        typos or wrong conversions in the setup code.
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    67
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    68
1323
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    69
    Notice:
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    70
        This class is *much* older than the younger and more object oriented
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    71
        Measurements package. Other than solving similar problems, these two packages
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    72
        are not related.
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    73
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    74
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    [author:]
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    76
        Claus Gittinger
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    see also:
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    79
        examples
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    80
        /usr/share/lib/unittab (if present on your system)
1323
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
    81
        Measurement Unit
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
examples
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    ever wanted to know, how many floz's are there in a european
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    Coce bottle ?
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    89
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    90
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    91
            (UnitConverter convert:1 from:#liter to:#floz)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    92
                                                                [exEnd]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    93
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    94
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    95
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    96
            (UnitConverter convert:43.5 from:#oz to:#gram)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
    97
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    98
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    or, how many square-meters an acre is:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   100
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   101
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   102
            (UnitConverter convert:1 from:#acre to:#'meter^2')
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   103
                                                                [exEnd]
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   105
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   106
    or europeans might want to know, what those
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   107
    fahrenheit numbers mean in an US weather report ;-):
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   108
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   109
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   110
            (UnitConverter convert:80 from:#fahrenheit to:#celsius)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   111
                asFixedPoint:1)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   112
                                                                [exEnd]
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   113
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   114
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   115
    how fast do I drive ? :-)
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   116
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   117
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   118
                UnitConverter convert:200 from:#'km/hr' to:#'mile/hr')
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   119
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   120
    how fast does Chris drive ? :-)
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   121
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   122
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   123
                UnitConverter convert:65 from:#'mile/hr' to:#'km/hr')
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   124
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   125
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   126
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   127
    calories or joule ?
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   128
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   129
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   130
                UnitConverter convert:0.18 from:#'kilocalorie' to:#'kilojoule')
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   131
                                                                [exEnd]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   132
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   133
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   134
                UnitConverter convert:2000 from:#'kilocalorie' to:#'kilojoule')
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   135
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   136
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   137
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   138
    distances:
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   139
        
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   140
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   141
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   142
            UnitConverter convert:1 from:#'lightsecond' to:#'kilometer') 
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   143
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   144
    thats the same:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   145
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   146
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   147
            UnitConverter convert:1 from:#'lightspeed*s' to:#'kilometer') 
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   148
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   149
    a days travel ...
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   150
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   151
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   152
            UnitConverter convert:1 from:#'lightspeed*dy' to:#'kilometer') 
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   153
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   154
    a year travel ...
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   155
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   156
        Transcript showCR:(
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   157
            UnitConverter convert:1 from:#'lightyear' to:#'kilometer') 
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   158
                                                                [exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   159
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   160
    wonna race on the autobahn ?
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   161
                                                                [exBegin]
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   162
        Transcript showCR:(
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   163
            UnitConverter convert:200 from:#'km/h' to:#'mph') 
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   164
                                                                [exEnd]
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   165
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   166
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    real estate buyers might want to know, how many acres
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    a german ar is:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   169
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   170
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   171
            (UnitConverter convert:1 from:#'german-ar' to:#acre)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   172
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   173
    - or how many square-feet are there in your living room:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   174
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   175
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   176
            (UnitConverter convert:100 from:#'meter^2' to:#'foot^2')   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   177
                                                                [exEnd]
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   178
    - or how about:
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   179
                                                                [exBegin]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   180
        Transcript showCR:
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   181
            (UnitConverter convert:3600 from:#'ft*ft' to:#'m*,')   
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   182
                                                                [exEnd]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   183
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   184
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   185
    how many tea spoons are there in a cubic meter ?
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   186
    (roughly, since a teaspoon is not a standard unit)
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   187
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   188
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   189
            (UnitConverter convert:1 from:#'meter^3' to:#teaspoon)
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   190
                                                                [exEnd]
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   191
    how wide is a US page in inches:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   192
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   193
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   194
            (UnitConverter convert:1 from:#'letterW' to:#inch)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   195
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   196
    - in millimeter:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   197
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   198
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   199
            (UnitConverter convert:1 from:#'letterW' to:#mm)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   200
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   201
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   202
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   203
    the height of a US page in inches:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   204
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   205
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   206
            (UnitConverter convert:1 from:#'letterH' to:#inch)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   207
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   208
    - in millimeter:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   209
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   210
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   211
            (UnitConverter convert:1 from:#'letterH' to:#mm)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   212
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   213
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   214
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   215
    the same for european A4 standard page:
982
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   216
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   217
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   218
            (UnitConverter convert:1 from:#'a4H' to:#mm)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   219
                                                                [exEnd]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   220
                                                                [exBegin]
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   221
        Transcript showCR:
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   222
            (UnitConverter convert:1 from:#'a4H' to:#inch)   
fa890fb509d5 initialize example changed
penk
parents: 981
diff changeset
   223
                                                                [exEnd]
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   224
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   225
    the mass of a proton:
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   226
                                                                [exBegin]
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   227
        Transcript showCR:
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   228
            (UnitConverter convert:1 from:#'proton' to:#eV)    
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   229
                                                                [exEnd]
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   230
    the energy of a single proton in the LHC (as of 2010)
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   231
                                                                [exBegin]
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   232
        Transcript showCR:
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   233
            (UnitConverter convert:7 from:#'TeV' to:#joule)   
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   234
                                                                [exEnd]
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
!UnitConverter class methodsFor:'initialization'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   240
initializeConversions
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    "initialize common conversions"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   243
    self initializeScaleFactors.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   244
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    Conversions := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    Aliases := IdentityDictionary new.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   247
    Constants := IdentityDictionary new.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   249
    "/ ---------- velocity -------------
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   250
556
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   251
    Constants at:#lightspeed   put:#(2.997925E8   #'m/s').
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   252
    Constants at:#soundspeed   put:#(343          #'m/s').  "/ 20degC - AIR
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   253
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   254
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    "/ -------------- length -------------
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    Aliases at:#km       put:#kilometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    Aliases at:#m        put:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    Aliases at:#dm       put:#decimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    Aliases at:#cm       put:#centimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    Aliases at:#mm       put:#millimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    Aliases at:#micron   put:#micrometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    Aliases at:#nm       put:#nanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    Aliases at:#angstrom put:#decinanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    "/ US
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    self addConversion:12       from:#foot to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
    self addConversion:3        from:#yard to:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    self addConversion:5280     from:#mile to:#foot.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   270
    self addConversion:0.001    from:#inch to:#mil.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   272
    Aliases at:#feet  put:#foot.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   273
    Aliases at:#ft    put:#foot.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   274
    Aliases at:#yd    put:#yard.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   275
    Aliases at:#mi    put:#mile.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   276
    Aliases at:#mph   put:#'mile/hr'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    "/ inch to millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
    self addConversion:(25.4/1000) from:#inch to:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   281
    "/ nautic
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   282
    self addConversion:1852        from:#'nautical-mile' to:#meter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   283
556
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   284
    Aliases at:#lightsecond put:#'lightspeed*s'.
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   285
    Aliases at:#lightyear   put:#'lightspeed*yr'.
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   286
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   287
    self addConversion:((Constants at:#lightspeed) at:1) from:#'lightspeed*s' to:#'meter'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   288
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   289
    "/ ---------- time -------------
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   290
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   291
    self addConversion:60           from:#min to:#s.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   292
    self addConversion:60           from:#hr  to:#min.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   293
    self addConversion:24           from:#dy  to:#hr.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   294
    self addConversion:365.24219879 from:#yr  to:#dy.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   295
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   296
    Aliases at:#h   put:#'hr'.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   297
    Aliases at:#d   put:#'dy'.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   298
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   299
    "/ ---------- printing -------------
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   300
    self initializePrintValues.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   301
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   302
    "/ ---------------- area -------------------
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   303
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   304
    "/ US
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   305
    self addConversion:4840        from:#acre  to:#'yard^2'.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   306
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   307
    self addConversion:100         from:#are      to:#'meter^2'.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   308
    self addConversion:100         from:#hectare  to:#are.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   309
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   310
    "/ german area - add your countries, and return to me ...
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   311
    Aliases at:#'german-ar'      put:#are.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   312
    Aliases at:#'german-hektar'  put:#hectare.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   313
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   314
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   315
    "/ ---------------- liquid ---------------- 
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   316
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   317
    self addConversion:231      from:#gallon to:#'inch^3'.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   318
    self addConversion:(1/4)    from:#quart to:#gallon.  "/ well - at least here,
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   319
                                                         "/ thats also 1/4th of a good wine ;-)
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   320
    self addConversion:(1/2)    from:#pint to:#quart.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   321
    self addConversion:(1/16)   from:#floz to:#pint.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   322
    self addConversion:(1/8)    from:#fldr to:#floz.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   323
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   324
    self addConversion:42       from:#barrel to:#gallon.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   325
    self addConversion:35.23907 from:#bushel to:#liter.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   326
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   327
    Aliases at:#cc    put:#'cm^3'.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   328
    Aliases at:#liter put:#kilocc.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   329
    Aliases at:#ml    put:#milliliter.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   330
    Aliases at:#gal   put:#gallon.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   331
    Aliases at:#qt    put:#quart.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   332
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   333
    "/ well, a pint of beer is not always:
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   334
    self addConversion:277.420 from:#'british-gallon'  to:#'inch^3'.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   335
    self addConversion:(1/4)   from:#'british-quart'   to:#'british-gallon'.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   336
    self addConversion:(1/2)   from:#'british-pint'    to:#'british-quart'.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   337
    self addConversion:(1/16)  from:#'british-floz'    to:#'british-pint'.
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   338
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   339
    "/ ---------------- mass ---------------- 
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   340
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   341
    self addConversion:28.35     from:#ounce to:#gram.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   342
    self addConversion:453.59237 from:#lb    to:#gram.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   343
    self addConversion:205       from:#carat to:#milligram.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   344
2444
6c4c6addc97a changed: #initializeConversions
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   345
    self addConversion:0.938272013 from:#proton to:#GeV.
6c4c6addc97a changed: #initializeConversions
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   346
    self addConversion:0.510998910 from:#electron to:#MeV.
6c4c6addc97a changed: #initializeConversions
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   347
    self addConversion:0.939565346 from:#neutron to:#GeV.
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   348
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   349
    Aliases at:#oz put:#ounce.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   350
    Aliases at:#lbs put:#lb.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   351
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   352
    Aliases at:#gm put:#gram.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   353
    Aliases at:#kg put:#kilogram.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   354
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   355
    "/ ---------------- energy ---------------- 
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   356
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   357
    Aliases at:#cal     put:#calorie.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   358
    Aliases at:#nt      put:#newton.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   359
    Aliases at:#joule   put:#'nt*m'.
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   360
    Aliases at:#J       put:#'joule'.
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   361
    Aliases at:#N       put:#'newton'.
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   362
    Aliases at:#eV      put:#'electronvolt'.
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   363
    Aliases at:#MeV     put:#'megaeV'.
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   364
    Aliases at:#GeV     put:#'gigaeV'.
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   365
    Aliases at:#TeV     put:#'teraeV'.
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   366
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   367
    Aliases at:#watt    put:#'J/s'.
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   368
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   369
    self addConversion:4.1868 from:#calorie  to:#joule.
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   370
    self addConversion:1.60217653E-19 from:#electronvolt  to:#joule.
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   371
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   372
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   373
    "/ ---------------- cooking ---------------- 
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   374
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   375
    self addConversion:4      from:#tablespoon   to:#fldr.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   376
    self addConversion:(4/3)  from:#teaspoon     to:#fldr.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   377
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   378
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   379
    "/ ---------------- temperature ---------------- 
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   380
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   381
    self addConversion:[:d | d * 1.8 + 32] from:#celsius    to:#fahrenheit.
2443
e64a7f2f3fb4 changed:
Claus Gittinger <cg@exept.de>
parents: 2320
diff changeset
   382
    self addConversion:[:f | (f - 32) / 1.8] from:#fahrenheit to:#celsius.
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   383
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   384
    "
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   385
     Conversions := nil.
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   386
     UnitConverter initializeConversions
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   387
    "
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   388
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   389
    "Created: / 22.7.1997 / 13:56:40 / cg"
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   390
    "Modified: / 10.10.2001 / 14:39:04 / cg"
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   391
!
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   392
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   393
initializePrintValues
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
    "/ inch to (roughly) a typesetter point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
    self addConversion:(1/72)      from:#point to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    "/ point to twips; 20 twips (as in Rich-Text-Format) make a point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
    self addConversion:(1/20)      from:#twip  to:#point.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   400
    "/ US paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   401
    self addConversion:11          from:#'letter-page-height' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   402
    self addConversion:8.5         from:#'letter-page-width'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   403
    self addConversion:8.5         from:#'letter-landscape-page-height'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   404
    self addConversion:11          from:#'letter-landscape-page-width' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   405
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   406
    self addConversion:14          from:#'legal-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   407
    self addConversion:8.5         from:#'legal-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   408
    self addConversion:8.5         from:#'legal-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   409
    self addConversion:14          from:#'legal-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   410
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   411
    self addConversion:11          from:#'ledger-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   412
    self addConversion:17          from:#'ledger-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   413
    self addConversion:17          from:#'ledger-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   414
    self addConversion:11          from:#'ledger-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   415
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   416
    "/ European paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   417
    self addConversion:840         from:#'a1-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   418
    self addConversion:592         from:#'a1-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   419
    self addConversion:592         from:#'a1-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   420
    self addConversion:840         from:#'a1-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   421
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   422
    self addConversion:592         from:#'a2-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   423
    self addConversion:420         from:#'a2-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   424
    self addConversion:420         from:#'a2-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   425
    self addConversion:592         from:#'a2-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   426
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   427
    self addConversion:420         from:#'a3-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   428
    self addConversion:296         from:#'a3-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   429
    self addConversion:296         from:#'a3-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   430
    self addConversion:420         from:#'a3-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   431
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   432
    self addConversion:296         from:#'a4-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   433
    self addConversion:210         from:#'a4-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   434
    self addConversion:210         from:#'a4-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   435
    self addConversion:296         from:#'a4-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   436
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   437
    self addConversion:210         from:#'a5-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   438
    self addConversion:148         from:#'a5-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   439
    self addConversion:148         from:#'a5-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   440
    self addConversion:210         from:#'a5-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   441
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   442
    self addConversion:148         from:#'a6-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   443
    self addConversion:105         from:#'a6-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   444
    self addConversion:105         from:#'a6-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   445
    self addConversion:148         from:#'a6-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   446
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   447
    self addConversion:257         from:#'b5-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   448
    self addConversion:182         from:#'b5-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   449
    self addConversion:182         from:#'b5-landscape-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   450
    self addConversion:257         from:#'b5-landscape-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   451
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   452
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   453
    Aliases at:#letterW    put:#'letter-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   454
    Aliases at:#letterH    put:#'letter-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   455
    Aliases at:#legalW     put:#'legal-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   456
    Aliases at:#legalH     put:#'legal-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   457
    Aliases at:#ledgerW    put:#'ledger-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   458
    Aliases at:#ledgerH    put:#'ledger-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   459
    Aliases at:#a1W        put:#'a1-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   460
    Aliases at:#a1H        put:#'a1-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   461
    Aliases at:#a2W        put:#'a2-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   462
    Aliases at:#a2H        put:#'a2-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   463
    Aliases at:#a3W        put:#'a3-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   464
    Aliases at:#a3H        put:#'a3-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   465
    Aliases at:#a4W        put:#'a4-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   466
    Aliases at:#a4H        put:#'a4-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   467
    Aliases at:#a5W        put:#'a5-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   468
    Aliases at:#a5H        put:#'a5-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   469
    Aliases at:#a6W        put:#'a6-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   470
    Aliases at:#a6H        put:#'a6-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   471
    Aliases at:#b5W        put:#'b5-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   472
    Aliases at:#b5H        put:#'b5-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   473
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   474
    Aliases at:#letterlW   put:#'letter-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   475
    Aliases at:#letterlH   put:#'letter-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   476
    Aliases at:#legallW    put:#'legal-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   477
    Aliases at:#legallH    put:#'legal-landscape-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   478
    Aliases at:#ledgerlW   put:#'ledger-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   479
    Aliases at:#ledgerlH   put:#'ledger-landscape-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   480
    Aliases at:#a1lW       put:#'a1-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   481
    Aliases at:#a1lH       put:#'a1-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   482
    Aliases at:#a2lW       put:#'a2-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   483
    Aliases at:#a2lH       put:#'a2-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   484
    Aliases at:#a3lW       put:#'a3-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   485
    Aliases at:#a3lH       put:#'a3-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   486
    Aliases at:#a4lW       put:#'a4-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   487
    Aliases at:#a4lH       put:#'a4-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   488
    Aliases at:#a5lW       put:#'a5-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   489
    Aliases at:#a5lH       put:#'a5-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   490
    Aliases at:#a6lW       put:#'a6-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   491
    Aliases at:#a6lH       put:#'a6-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   492
    Aliases at:#b5lW       put:#'b5-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   493
    Aliases at:#b5lH       put:#'b5-landscape-page-height'.
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   494
!
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   496
initializeScaleFactors
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   497
    Scaling := IdentityDictionary new.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
1285
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   499
    Scaling at:#yotta put:1000000000000000000000000.    "/ 10^24
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   500
    Scaling at:#zetta put:1000000000000000000000.       "/ 10^21
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   501
    Scaling at:#exa   put:1000000000000000000.          "/ 10^18
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   502
    Scaling at:#peta  put:1000000000000000.             "/ 10^15
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   503
    Scaling at:#tera  put:1000000000000.                "/ 10^12
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   504
    Scaling at:#giga  put:1000000000.                   "/ 10^9
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   505
    Scaling at:#mega  put:1000000.                      "/ 10^6
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   506
    Scaling at:#myria put:10000.
1285
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   507
    Scaling at:#kilo  put:1000.                         "/ 10^3
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   508
    Scaling at:#hecto put:100.                          "/ 10^2
0b70d88e4a74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1161
diff changeset
   509
    Scaling at:#deca  put:10.                           "/ 10^1
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   510
    Scaling at:#deka  put:10.                           "/ 10^1
1323
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   511
    Scaling at:#deci  put:(1/10).                       "/ 10^-1
1135
9a343ebe206b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1132
diff changeset
   512
    Scaling at:#centi put:(1/100).
1323
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   513
    Scaling at:#milli put:(1/1000).                     "/ 10^-3
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   514
    Scaling at:#micro put:(1/1000000).                  "/ 10^-6
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   515
    Scaling at:#nano  put:(1/1000000000).               "/ 10^-9
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   516
    Scaling at:#pico  put:(1/1000000000000).            "/ 10^-12
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   517
    Scaling at:#femto put:(1/1000000000000000).         "/ 10^-15
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   518
    Scaling at:#atto  put:(1/1000000000000000000).      "/ 10^-18
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   519
    Scaling at:#zepto put:(1/1000000000000000000000).   "/ 10^-21
e5eb14af1cfa comments
Claus Gittinger <cg@exept.de>
parents: 1298
diff changeset
   520
    Scaling at:#yocto put:(1/1000000000000000000000000)."/ 10^-24
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   521
! !
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   522
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   523
!UnitConverter class methodsFor:'accessing'!
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   524
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   525
scalings
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   526
    "return the set of known scaling prefixes"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   527
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   528
    ^ Scaling keys
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   529
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   530
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   531
     UnitConverter scalings
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   532
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   533
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   534
    "Created: 6.8.1997 / 16:53:19 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   535
    "Modified: 6.8.1997 / 16:58:11 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   536
!
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   537
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   538
units
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   539
    "return the set of known units"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   540
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   541
    |setOfUnits|
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   542
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   543
    setOfUnits := IdentitySet new.
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   544
    Conversions keysAndValuesDo:[:srcUnit :conversionInfo |
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   545
	setOfUnits add:srcUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   546
	conversionInfo keysDo:[:targetUnit |
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   547
	    setOfUnits add:targetUnit
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   548
	]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   549
    ].
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   550
    ^ setOfUnits
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   551
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   552
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   553
     UnitConverter units
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   554
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   556
    "Created: 6.8.1997 / 16:57:08 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   557
    "Modified: 6.8.1997 / 16:57:47 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
!UnitConverter class methodsFor:'conversions'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
convert:howMany from:sourceUnit to:destUnit
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
    "given a value in sourceUnit (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
     to destUnit (symbolic); return nil, if the conversion is
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
     unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   567
    |u conversions alias rslt sU dU const val unit 
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   568
     i suNumerator suDenominator duNumerator duDenominator uN uD
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   569
     sF1 sF2 dF1 dF2
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   570
     s d|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   572
"/ Transcript showCR:('try ' , sourceUnit , '->' , destUnit).
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   573
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   574
    Conversions isNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   575
        self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   576
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   577
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    "/ somehow, recursion must end ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    sourceUnit == destUnit ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   580
        ^ howMany
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   583
    sourceUnit isSymbol ifFalse:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   584
        s := sourceUnit withoutSeparators.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   585
        sU := s asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   586
        sU notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   587
            ^ self convert:howMany from:sU to:destUnit
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   588
        ].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   589
        (s startsWith:$() ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   590
            (s endsWith:$)) ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   591
                s := s copyFrom:2 to:(s size - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   592
                ^ self convert:howMany from:s to:destUnit
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   593
            ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   594
        ].
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   595
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   596
    destUnit isSymbol ifFalse:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   597
        d := destUnit withoutSeparators.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   598
        dU := d asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   599
        dU notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   600
            ^ self convert:howMany from:sourceUnit to:dU
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   601
        ].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   602
        (d startsWith:$() ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   603
            (d endsWith:$)) ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   604
                d := d copyFrom:2 to:(d size - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   605
                ^ self convert:howMany from:sourceUnit to:d
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   606
            ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   607
        ].
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   608
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   609
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
    "/ first, get rid of scalers ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
    u := self unscaled:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
    u notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   614
        ^ self convert:(howMany*(u value)) from:(u key) to:destUnit
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
    u := self unscaled:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
    u notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   619
        ^ self convert:(howMany/(u value)) from:sourceUnit to:(u key)
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
    "/ and of aliases ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
    alias := Aliases at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
    alias notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   626
        ^ self convert:howMany from:alias to:destUnit
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
    alias := Aliases at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
    alias notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   630
        ^ self convert:howMany from:sourceUnit to:alias
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   633
    "/ any constants ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   634
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   635
    (Constants includesKey:sourceUnit) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   636
        const := Constants at:sourceUnit.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   637
        val := const at:1.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   638
        unit := const at:2.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   639
        ^ self convert:(howMany*val) from:unit to:destUnit
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   640
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   641
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   642
    "/ compounds (^ , / or *) are very naively parsed
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   643
    "/ need a full expression parser (tree) for full power.
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   644
    "/ I leave that as an excercise to you ...
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   645
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   646
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
    "/ working with squares or cubics ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   649
    ((sourceUnit endsWith:'^2') and:[destUnit endsWith:'^2']) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   650
        sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   651
        dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   652
        (sU notNil and:[dU notNil]) ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   653
            ^ (self convert:(howMany sqrt) from:sU to:dU) squared
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   654
        ].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   655
        ^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
    ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   657
    ((sourceUnit endsWith:'^3') and:[destUnit endsWith:'^3']) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   658
        sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   659
        dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   660
        (sU notNil and:[dU notNil]) ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   661
            ^ (self convert:(howMany raisedTo:(1/3)) from:sU to:dU) raisedTo:3
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   662
        ].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   663
        ^ self noConversionFrom:sourceUnit to:destUnit.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   664
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   665
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   666
    "/ working with fractions ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   667
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   668
    ((sourceUnit includes:$/) and:[destUnit includes:$/]) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   669
        "/ look for a constant conversion factor
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   670
        i := sourceUnit indexOf:$/.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   671
        suNumerator := sourceUnit copyTo:(i - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   672
        suDenominator := sourceUnit copyFrom:(i + 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   673
        i := destUnit indexOf:$/.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   674
        duNumerator := destUnit copyTo:(i - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   675
        duDenominator := destUnit copyFrom:(i + 1).
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   676
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   677
        uN := self convert:howMany from:suNumerator to:duNumerator.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   678
        uN notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   679
            uD := self convert:1 from:suDenominator to:duDenominator.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   680
            uD notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   681
                ^ uN / uD
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   682
            ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   683
        ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   684
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   685
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   686
    "/ working with products ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   687
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   688
    ((sourceUnit includes:$*) and:[destUnit includes:$*]) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   689
        i := sourceUnit indexOf:$*.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   690
        sF1 := sourceUnit copyTo:(i - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   691
        sF2 := sourceUnit copyFrom:(i + 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   692
        i := destUnit indexOf:$*.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   693
        dF1 := destUnit copyTo:(i - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   694
        dF2 := destUnit copyFrom:(i + 1).
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   695
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   696
        u := self convert:howMany from:sF1 to:dF1.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   697
        u notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   698
            u := self convert:u from:sF2 to:dF2.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   699
            u notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   700
                ^ u
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   701
            ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   702
        ].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
    "/ the real work comes here ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
    "/ is there a direct conversion in the dataBase ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
    rslt := self convertDirect:howMany from:sourceUnit to:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
    rslt notNil ifTrue:[^ rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
    "/ try inverse conversion ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
    rslt := self convertDirect:1 from:destUnit to:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
    rslt notNil ifTrue:[ ^ howMany / rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   717
    "/ here's the deep recursion ...
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
    "/ try indirect conversion from source
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
    conversions := Conversions at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
    conversions notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   724
        conversions keysAndValuesDo:[:intermediateUnit :factor1 |
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   725
            |factor2|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   727
            factor2 := self convert:factor1 from:intermediateUnit to:destUnit.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   728
            factor2 notNil ifTrue:[^ factor2 * howMany].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   729
        ].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
    "/ try indirect conversion from dest
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
    conversions := Conversions at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
    conversions notNil ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   736
        conversions keysAndValuesDo:[:intermediateUnit :factor1 |
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   737
            |factor2|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   739
            factor2 := self convert:(factor1) from:intermediateUnit to:sourceUnit.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   740
            factor2 notNil ifTrue:[^ howMany / factor2].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   741
        ].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   744
    "/ if working with a product, try each component
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   745
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   746
    (sourceUnit includes:$*) ifTrue:[
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   747
        i := sourceUnit indexOf:$*.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   748
        sF1 := sourceUnit copyTo:(i - 1).
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   749
        sF2 := sourceUnit copyFrom:(i + 1).
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   750
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   751
        "/ see what we have ...
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   752
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   753
        self units do:[:aUnit |
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   754
            |pref iUnit factor2 rslt|
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   755
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   756
            pref := sF1 , '*'.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   757
            (aUnit startsWith:pref) ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   758
                "/ ok; want a/b -> x
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   759
                "/ found a/c -> any
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   760
                "/ what about c->b ?
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   761
1031
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   762
                iUnit := aUnit copyFrom:pref size + 1.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   763
                factor2 := self convert:1 from:sF2 to:iUnit.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   764
                factor2 notNil ifTrue:[
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   765
                    "/ good ...
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   766
                    rslt := self convert:(factor2 * howMany)
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   767
                                    from:aUnit to:destUnit.
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   768
                    rslt notNil ifTrue:[^ rslt].
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   769
                ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   770
            ]
956850b2b7ef *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 983
diff changeset
   771
        ].
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   772
    ].
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   773
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   774
    ^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
    "direct - how many meters are there in two inches:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
     UnitConverter convert:2 from:#inch to:#meter     
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   778
     UnitConverter convert:37 from:#degrees to:#fahrenheit     
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
     reverse - how many inches are there in one meter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
     UnitConverter convert:1 from:#meter to:#inch   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
     with alias:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
     UnitConverter convert:1 from:#inch to:#m    
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
     UnitConverter convert:1 from:#inch to:#mm          
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
     UnitConverter convert:1 from:#inch to:#millimeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
     UnitConverter convert:1 from:#inch to:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
     UnitConverter convert:1 from:#mm to:#km  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
     UnitConverter convert:1 from:#km to:#foot   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
     indirect:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
     UnitConverter convert:1 from:#mm   to:#twip  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
     UnitConverter convert:1 from:#inch to:#twip  
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   794
     UnitConverter convert:1 from:'letterH' to:#point  
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   795
     UnitConverter convert:1 from:'letterlH' to:#point  
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   796
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   797
     UnitConverter convert:5 from:#barrel to:#liter  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   798
     UnitConverter convert:10 from:#kilogram to:#carat  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   799
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   800
     UnitConverter convert:1 from:#liter to:#floz  
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
    "Created: 31.5.1996 / 16:23:38 / cg"
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   804
    "Modified: 6.8.1997 / 18:10:22 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
1292
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   807
fileSizeFromString:fileSizeString
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   808
    "given a fileSize string (i.e. a number followed by optional Kb, Mb or Gb as required.
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   809
     Provided here since this is so common..."
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   810
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   811
    |numericValue s scaleChar scale|
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   812
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   813
    fileSizeString isEmpty ifTrue:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   814
        ^ 0
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   815
    ].
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   816
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   817
    scale := 1.
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   818
    s := fileSizeString readStream.
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   819
    numericValue := Number readFrom:s onError:[0].
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   820
    s skipSeparators.
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   821
    s atEnd ifFalse:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   822
        scaleChar := s next asLowercase.
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   823
        scaleChar = $k ifTrue:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   824
            scale := 1024
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   825
        ] ifFalse:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   826
            scaleChar = $m ifTrue:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   827
                scale := 1024 * 1024
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   828
            ] ifFalse:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   829
                scaleChar = $g ifTrue:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   830
                    scale := 1024 * 1024 * 1024
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   831
                ] ifFalse:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   832
                    scaleChar = $t ifTrue:[
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   833
                        scale := 1024 * 1024 * 1024 * 1024
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   834
                    ]
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   835
                ]
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   836
            ]
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   837
        ].
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   838
    ].
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   839
    ^ (numericValue*scale) asInteger
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   840
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   841
    "
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   842
     self fileSizeFromString:'1234'          
1295
d2eddb82f12b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   843
     self fileSizeFromString:'10 k'            
d2eddb82f12b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   844
     self fileSizeFromString:'0.6 k'            
d2eddb82f12b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   845
     self fileSizeFromString:'1.8 M'            
d2eddb82f12b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   846
     self fileSizeFromString:'0.5 G'            
d2eddb82f12b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   847
     self fileSizeFromString:'0.5 T'            
1292
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   848
    "
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   849
!
cf61a7dfeca6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1285
diff changeset
   850
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   851
fileSizeStringFor:nBytes
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   852
    "return a useful string for a size-in-bytes; 
1294
07b05530726f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1293
diff changeset
   853
     Scales by K (*1024), M (*1024*1024) or G (*1024*1024*1024) or even T
07b05530726f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1293
diff changeset
   854
     as required and useful.
1143
ad4a5f867538 comment
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   855
     Provided here since this is so common..."
ad4a5f867538 comment
Claus Gittinger <cg@exept.de>
parents: 1135
diff changeset
   856
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   857
    |unitString n|
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   858
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   859
    nBytes < (1000 * 1024 * 1024 * 1024) ifTrue:[
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   860
        nBytes < (1000 * 1024 * 1024) ifTrue:[
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   861
            nBytes < (1000 * 1024) ifTrue:[
1457
6831feb0bd08 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1346
diff changeset
   862
                nBytes < 1000 ifTrue:[
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   863
                    n := nBytes.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   864
                    unitString := '   '.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   865
                ] ifFalse:[
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   866
                    n := (nBytes / 1024) asFixedPoint:1.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   867
                    unitString := ' K'
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   868
                ]
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   869
            ] ifFalse:[
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   870
                n := (nBytes / (1024 * 1024)) asFixedPoint:1.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   871
                unitString := ' M'
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   872
            ].
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   873
        ] ifFalse:[
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   874
            n := (nBytes / 1024 / (1024 * 1024)) asFixedPoint:1.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   875
            unitString := ' G'
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   876
        ]
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   877
    ] ifFalse:[
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   878
        n := (nBytes / (1024 * 1024) / (1024 * 1024)) asFixedPoint:1.
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   879
        unitString := ' T'
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   880
    ].
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   881
1346
ed26d90d4ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1323
diff changeset
   882
"/    n truncated = n ifTrue:[
ed26d90d4ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1323
diff changeset
   883
"/        n := n truncated
ed26d90d4ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1323
diff changeset
   884
"/    ].
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   885
    ^ n printString , unitString.
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   886
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   887
    "
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   888
     self fileSizeStringFor:10          
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   889
     self fileSizeStringFor:100            
1298
7e831af30f44 return integer if possible for fileSize conversions
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   890
     self fileSizeStringFor:1000            
7e831af30f44 return integer if possible for fileSize conversions
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   891
     self fileSizeStringFor:8192            
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   892
     self fileSizeStringFor:10000          
1298
7e831af30f44 return integer if possible for fileSize conversions
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   893
     self fileSizeStringFor:100000          
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   894
     self fileSizeStringFor:1000000        
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   895
     self fileSizeStringFor:10000000       
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   896
     self fileSizeStringFor:100000000      
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   897
     self fileSizeStringFor:1000000000      
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   898
     self fileSizeStringFor:10000000000      
1293
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   899
     self fileSizeStringFor:100000000000      
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   900
     self fileSizeStringFor:1000000000000      
4504cf3db7d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1292
diff changeset
   901
     self fileSizeStringFor:10000000000000      
1132
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   902
    "
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   903
!
2f0305cb691b fileSizeString added (Kb/Mb/Gb)
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
   904
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
inchToMillimeter:inches
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   906
    "convert inches to mm. Made this an extra method, since its so common."
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
    ^ inches * 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   910
    "Created: 31.5.1996 / 13:37:31 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   911
    "Modified: 31.5.1996 / 18:08:14 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   912
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   914
millimeterToInch:mm
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   915
    "convert mm to inches. Made this an extra method, since its so common."
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   916
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   917
    ^ mm / 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   919
    "Created: 31.5.1996 / 13:37:48 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   920
    "Modified: 31.5.1996 / 18:08:20 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   921
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   923
!UnitConverter class methodsFor:'missing conversion'!
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   924
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   925
noConversionFrom:sourceUnit to:destUnit
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   926
    Transcript showCR:'no conversion ' , sourceUnit printString , ' -> ' , destUnit printString.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   927
    ^ nil
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   928
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   929
    "Created: 29.3.1997 / 17:56:03 / cg"
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   930
! !
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   931
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   932
!UnitConverter class methodsFor:'private'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   933
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   934
addConversion:factor from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
    "add a conversion"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
    |conversion|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   939
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
    conversion isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   941
	conversion := IdentityDictionary new.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   942
	Conversions at:sourceMetric put:conversion
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
    conversion at:destMetric put:factor.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
    ^ conversion
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
    "Created: 31.5.1996 / 13:51:25 / cg"
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   948
    "Modified: 29.3.1997 / 17:19:31 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
convertDirect:howMany from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
    "given a value in sourceMetric (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
     to destMetric (symbolic); 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
     Only direct conversions are tried; return nil, if the conversion is unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
    |conversion factor|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   958
    Conversions isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   959
	self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   960
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   961
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
    conversion isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   964
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   965
    factor := conversion at:destMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   966
    factor isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   967
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   968
    factor isNumber ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   969
	^ howMany * factor
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   970
    ].
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   971
    ^ factor value:howMany
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
     UnitConverter convertDirect:1 from:#inch to:#meter 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
     UnitConverter convertDirect:1 from:#inch to:#millimeter 
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   976
     UnitConverter convertDirect:1 from:#degrees to:#fahrenheit 
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   978
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   979
    "Created: 31.5.1996 / 13:54:33 / cg"
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   980
    "Modified: 22.7.1997 / 13:57:52 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   981
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   982
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
unscaled:what
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
    "given a unit, return the base and a factor as assoc,
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
     or nil if not found"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   987
    Conversions isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   988
	self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   989
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   990
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
    Scaling keysAndValuesDo:[:name :factor |
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   992
	|rest|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   994
	(what startsWith:name) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   995
	    rest := what copyFrom:(name size+1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   996
	    rest := rest asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   997
	    rest notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   998
		^ rest -> factor.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   999
	    ]        
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1000
	].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1002
    ^ nil
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1003
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1004
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
     UnitConverter unscaled:#millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
     UnitConverter unscaled:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1007
     UnitConverter unscaled:#kilometer   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1008
     UnitConverter unscaled:#fuzzymeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1009
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1010
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
  1011
    "Modified: 22.7.1997 / 13:57:46 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1012
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1013
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1014
!UnitConverter class methodsFor:'documentation'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1015
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
version
2444
6c4c6addc97a changed: #initializeConversions
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
  1017
    ^ '$Header: /cvs/stx/stx/libbasic2/UnitConverter.st,v 1.38 2010-04-18 14:11:29 cg Exp $'
2320
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
  1018
!
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
  1019
c7f52f534977 changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
  1020
version_CVS
2444
6c4c6addc97a changed: #initializeConversions
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
  1021
    ^ '$Header: /cvs/stx/stx/libbasic2/UnitConverter.st,v 1.38 2010-04-18 14:11:29 cg Exp $'
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
! !