2015年4月26日日曜日

パソコンのお掃除

 2~3日前に、使っているノートパソコンのファンがうるさいことに気付きました。

 重たいソフトウェアを起動しているわけでもないのに、ファンの回転音が鳴りっぱなしで、CPUの辺りが熱くなっていました。

 これはいかん、ということで、すぐに中を開けてファンを取り外してみました。案の定、中からスポンジみたいに固まった綿埃が出てきました。綿埃を取り除くと、以前のように静かな状態に戻りました。

 おそらく、そのまま放置していたら、熱のダメージでパソコンの寿命が縮んでいたでしょう。使っているパソコンがクラッシュするのは、想像するだけでも怖いです。

 たまに掃除するだけでいいものは、つい掃除を忘れて、いつの間にか汚くなっていたりするものです。そして、気付かないうちに、ものをダメにしてしまうというのは、よくあるパターンです。

 ものを長持ちさせるためにも、ときどきは、普段掃除していない所にも目を向けよう、とつくづく思いました。



・・・とは言っておきながら、掃除を忘れているところが多々あるんだろうなぁ。

2015年4月19日日曜日

ピーターの法則

 ピーターの法則というのを最近知りました。ピーターの法則とは、組織の構成員についての法則です。

 ある役職で優秀な結果を出した人は昇進するでしょう。その人が次の役職でも結果を出したら、さらに昇進するでしょう。これが繰り返されると、その人は結果を出せなくなるまで昇進することになります。最終的には、すべての役職は、その役職で結果を出すことが出来ない人に埋め尽くされることになります。これがピーターの法則です。

 あなたが今の役職にいるのは、まだ結果を出せていないからです。もっとがんばりましょう。

 あなたの上司がその役職にいるのは、まだその役職の仕事を十分にこなせていないからです。上司が少しくらいダメでも大目に見てあげましょう。

 ピーターの法則は、極端ではありますが、面白い考え方だと思います。

 まぁ現実では、結果を出していない人が出世したり、評価されるべき人が評価されていなかったりするものですが。

参考:wikipedia

2015年4月12日日曜日

Excelでマップ描画

 Excel VBAでマップ画像を作成するマクロを作ってみました。等高線の描画もできます。ちょっと長いですが、ソースコードを以下に載せます。標準モジュールにコピーすれば使えるはずです。

 sample_data関数で適当なデータを作ります。draw関数でマップを作って描画します。趣味なのでコメントとかは少ないですが、ソースコードを見れば、内容は分かると思います。

 Excelでビットマップを描画しているところがポイントです。しかも、Windows APIを使わずに文字列を描画しています。本当はPNG保存にしたかったんですが、難しい点があったので、ペイントを起動する関数だけ用意しました。

 元々はSiウェハ上の測定データからマップを作るマクロなんですが、いろいろと応用できると思います。

 興味ある方は、ご自由にご利用ください。


2016/2/21 ソースコードを新しくしました。


Option Explicit

Public Const PI = 3.1415926535

'---------- 画像関連パラメータ ----------
Private Const IMAGE_SIZE As Long = 256
Private Const MARGIN_SIZE As Long = 16

Private Const MAP_IMAGE As String = "MAP_IMAGE"
'----------------------------------------

'データ座標の範囲
Private Const DATA_SCALE As Double = 200

'等高線の分割数
Private Const NUM_CONTOUR_LEVELS As Integer = 8

'フォントのビットマップデータ
Private fnt() As Byte

'---------- カラーマップ関連パラメータ ----------
Private Const COLOR_MAP_TYPE_GRAY As Integer = 1
Private Const COLOR_MAP_TYPE_JET1 As Integer = 2
Private Const COLOR_MAP_TYPE_JET2 As Integer = 3
Private Const COLOR_MAP_TYPE_HSV As Integer = 4

Private color_map_type As Integer
Private color_min As Double
Private color_max As Double
'------------------------------------------------

'---------- 補間関連パラメータ ----------
Private Const INTERPOLATION_TYPE_LINEAR As Integer = 1
Private Const INTERPOLATION_TYPE_GAUSS As Integer = 2

Private interpolation_type As Integer
Private range As Double
Private sigma As Double
'----------------------------------------



Private Sub test_bitmap()
    Dim i As Long
    Dim j As Long
    Dim width As Long
    Dim height As Long
    Dim pos As Long
    Dim data() As Byte
    Dim filename As String
 
    '------------------------------
    'データの作成
    width = 256
    height = 128
    ReDim data(width * height * 3 - 1) As Byte
 
    For i = 0 To height - 1
        For j = 0 To width - 1
            pos = (width * i + j) * 3
            data(pos + 0) = CByte(255)              'Blue
            data(pos + 1) = CByte(255 / height * i) 'Green
            data(pos + 2) = CByte(255 / width * j)  'Red
        Next j
    Next i
 
    drawString data, width, height, "Hello", 30, 60
    '------------------------------
 
    filename = ThisWorkbook.Path + "\test.bmp"
 
    'ファイルに書き出す
    writeBitmap filename, data, width, height
End Sub

Private Sub test_color_map()
    Dim i As Long
    Dim r As Byte
    Dim g As Byte
    Dim b As Byte
 
    For i = 0 To 31
        hsv2rgb CByte(255 * i / 32), r, g, b
        'jet2rgb1 CByte(255 * i / 32), r, g, b
        'jet2rgb2 CByte(255 * i / 32), r, g, b
     
        '適当な位置に表示
        Sheet1.Cells(1 + i, 10) = i
        Sheet1.Cells(1 + i, 11) = r
        Sheet1.Cells(1 + i, 12) = g
        Sheet1.Cells(1 + i, 13) = b
    Next i
End Sub

Private Sub test_weight()
    Dim i As Long
    Dim w As Double
 
    range = Sheet1.Cells(9, 3).value
    sigma = Sheet1.Cells(10, 3).value
 
    For i = 0 To 63
        If i < range Then
            w = CDbl(1) - i / range
            'w = Exp(-i * i / sigma / sigma)
        Else
            w = 0
        End If
     
        '適当な位置に表示
        Sheet1.Cells(1 + i, 10) = i
        Sheet1.Cells(1 + i, 11) = w
    Next i
End Sub

'テストデータの作成
Public Sub sample_data()
    Dim i As Long
    Dim N As Long
    Dim x As Double
    Dim y As Double
    Dim data As Double

    Sheet1.Cells.Delete
 
    Sheet1.Cells(1, 1) = "title"
    Sheet1.Cells(1, 3) = "sample"
 
    Sheet1.Cells(2, 1) = "show"
    Sheet1.Cells(2, 2) = "map"
    Sheet1.Cells(2, 3).Validation.Delete
    Sheet1.Cells(2, 3) = "ON"
    Sheet1.Cells(2, 3).Validation.Add Type:=xlValidateList, Formula1:="ON,off"
 
    Sheet1.Cells(3, 2) = "contour"
    Sheet1.Cells(3, 3).Validation.Delete
    Sheet1.Cells(3, 3).Validation.Add Type:=xlValidateList, Formula1:="ON,off"
    Sheet1.Cells(3, 3) = "ON"
 
    Sheet1.Cells(4, 2) = "data point"
    Sheet1.Cells(4, 3).Validation.Delete
    Sheet1.Cells(4, 3).Validation.Add Type:=xlValidateList, Formula1:="ON,off"
    Sheet1.Cells(4, 3) = "ON"
 
    Sheet1.Cells(5, 1) = "color"
    Sheet1.Cells(5, 2) = "type"
    Sheet1.Cells(5, 3) = "jet2"
    Sheet1.Cells(5, 3).Validation.Delete
    Sheet1.Cells(5, 3).Validation.Add Type:=xlValidateList, Formula1:="gray,jet1,jet2,hsv"
    Sheet1.Cells(6, 2) = "min"
    Sheet1.Cells(6, 3) = "=MIN(c13:c256)"
    Sheet1.Cells(6, 3).NumberFormatLocal = "0.00_ "
    Sheet1.Cells(7, 2) = "max"
    Sheet1.Cells(7, 3) = "=Max(c13:c256)"
    Sheet1.Cells(7, 3).NumberFormatLocal = "0.00_ "
 
    Sheet1.Cells(8, 1) = "interpolation"
    Sheet1.Cells(8, 2) = "type"
    Sheet1.Cells(8, 3) = "linear"
    Sheet1.Cells(8, 3).Validation.Delete
    Sheet1.Cells(8, 3).Validation.Add Type:=xlValidateList, Formula1:="linear,gauss"
    Sheet1.Cells(9, 2) = "range"
    Sheet1.Cells(9, 3) = 50
    Sheet1.Cells(10, 2) = "sigma"
    Sheet1.Cells(10, 3) = 16
 
    Sheet1.Cells(12, 1) = "x"
    Sheet1.Cells(12, 2) = "y"
    Sheet1.Cells(12, 3) = "data"
 
    N = 64
 
    For i = 0 To N - 1
        x = DATA_SCALE / 2 * i / N * Math.Cos(6 * PI * i / N)
        y = DATA_SCALE / 2 * i / N * Math.Sin(6 * PI * i / N)
        data = Exp((-x ^ 2 - y ^ 2) / (2 * 50 * 50))
     
        Sheet1.Cells(i + 13, 1) = x
        Sheet1.Cells(i + 13, 2) = y
        Sheet1.Cells(i + 13, 3) = data
    Next i
End Sub

'マップ描画マクロ本体
Public Sub draw()
    Dim i As Long
    Dim str As String
 
    Dim N As Long
    Dim xPos() As Double
    Dim yPos() As Double
    Dim data() As Double
 
    Dim mapData() As Double     '補間後データ
    Dim weight() As Double      '重みデータ
    Dim imgData() As Byte       '画像データ
 
    '--------------------------------------------------
    'データの取得
    getParameter
 
    Sheet1.Cells(12, 3).Select
    If Sheet1.Cells(13, 3) = "" Then Exit Sub
    N = Selection.End(xlDown).Row - 12
 
    ReDim xPos(N - 1) As Double
    ReDim yPos(N - 1) As Double
    ReDim data(N - 1) As Double
 
    For i = 0 To N - 1
        xPos(i) = Sheet1.Cells(i + 13, 1).value
        yPos(i) = Sheet1.Cells(i + 13, 2).value
        data(i) = Sheet1.Cells(i + 13, 3).value
    Next i
 
    ReDim mapData(IMAGE_SIZE * IMAGE_SIZE - 1) As Double
    ReDim weight(IMAGE_SIZE * IMAGE_SIZE - 1) As Double
    ReDim imgData(IMAGE_SIZE * IMAGE_SIZE * 3 - 1) As Byte
 
    '--------------------------------------------------
    'データの補間
    gridding mapData, weight, xPos, yPos, data, N
 
    '--------------------------------------------------
    '画像の作成
    For i = 0 To IMAGE_SIZE * IMAGE_SIZE * 3 - 1
        imgData(i) = CByte(255)
    Next i
 
    str = Sheet1.Cells(1, 3).Text
    drawString imgData, IMAGE_SIZE, IMAGE_SIZE, str, 0, IMAGE_SIZE - 16
 
    If Sheet1.Cells(2, 3) = "ON" Then
        drawMap imgData, mapData
        drawColorScale imgData
     
        str = Sheet1.Cells(6, 3).Text
        drawString imgData, IMAGE_SIZE, IMAGE_SIZE, str, IMAGE_SIZE / 4 - 8 * Len(str), 0
     
        str = Sheet1.Cells(7, 3).Text
        drawString imgData, IMAGE_SIZE, IMAGE_SIZE, str, IMAGE_SIZE * 3 / 4, 0
    End If
 
    If Sheet1.Cells(3, 3) = "ON" Then
        drawContour imgData, mapData
    End If
 
    If Sheet1.Cells(4, 3) = "ON" Then
        drawDataPoints imgData, xPos, yPos, N
    End If
 
    drawEdge imgData
 
    ChDir ThisWorkbook.Path
    writeBitmap "map.bmp", imgData, IMAGE_SIZE, IMAGE_SIZE
 
    '--------------------------------------------------
    '重み画像の保存
    For i = 0 To IMAGE_SIZE * IMAGE_SIZE * 3 - 1
        imgData(i) = CByte(255)
    Next i
 
    drawString imgData, IMAGE_SIZE, IMAGE_SIZE, "weight", 0, IMAGE_SIZE - 16
 
    drawWeight imgData, weight
    drawColorScale imgData
    drawDataPoints imgData, xPos, yPos, N
    drawEdge imgData
 
    writeBitmap "weight.bmp", imgData, IMAGE_SIZE, IMAGE_SIZE
 
    '--------------------------------------------------
 
    '画像の貼り付け
    Dim shp As Shape
 
    For Each shp In Sheet1.Shapes
        If shp.Name = MAP_IMAGE Then shp.Delete
    Next
 
    Set shp = Sheet1.Shapes.AddPicture("map.bmp", False, True, 250, 50, IMAGE_SIZE, IMAGE_SIZE)
    shp.Name = MAP_IMAGE
End Sub

'パラメータの取得
Private Sub getParameter()
    Select Case Sheet1.Cells(5, 3)
        Case "gray"
            color_map_type = COLOR_MAP_TYPE_GRAY
        Case "jet1"
            color_map_type = COLOR_MAP_TYPE_JET1
        Case "jet2"
            color_map_type = COLOR_MAP_TYPE_JET2
        Case "hsv"
            color_map_type = COLOR_MAP_TYPE_HSV
    End Select
         
    color_min = Sheet1.Cells(6, 3).value
    color_max = Sheet1.Cells(7, 3).value
 
    Select Case Sheet1.Cells(8, 3)
        Case "linear"
            interpolation_type = INTERPOLATION_TYPE_LINEAR
        Case "gauss"
            interpolation_type = INTERPOLATION_TYPE_GAUSS
    End Select
 
    range = Sheet1.Cells(9, 3).value
    sigma = Sheet1.Cells(10, 3).value
End Sub

'マップの描画
Private Sub drawMap(ByRef imgData() As Byte, mapData() As Double)
    Dim i As Long
    Dim j As Long
    Dim pos As Long
    Dim temp As Long
    Dim r As Byte
    Dim g As Byte
    Dim b As Byte
 
    For i = MARGIN_SIZE To IMAGE_SIZE - MARGIN_SIZE - 1
        '円形の領域だけ描画
        temp = Sqr((IMAGE_SIZE / 2 - MARGIN_SIZE) ^ 2 - (IMAGE_SIZE / 2 - i) ^ 2)
     
        For j = IMAGE_SIZE / 2 - temp To IMAGE_SIZE / 2 + temp
            pos = i * IMAGE_SIZE + j
            getColor mapData(pos), color_min, color_max, r, g, b
            imgData(pos * 3 + 0) = b
            imgData(pos * 3 + 1) = g
            imgData(pos * 3 + 2) = r
        Next j
    Next i
End Sub

'重みマップの描画
Private Sub drawWeight(ByRef imgData() As Byte, weight() As Double)
    Dim i As Long
    Dim j As Long
    Dim min As Double
    Dim max As Double
    Dim pos As Long
    Dim temp As Long
    Dim r As Byte
    Dim g As Byte
    Dim b As Byte

    min = weight(0)
    max = weight(0)

    For i = 0 To IMAGE_SIZE * IMAGE_SIZE - 1
        If max < weight(i) Then
            max = weight(i)
        End If
     
        If weight(i) < min Then
            min = weight(i)
        End If
    Next i

    For i = MARGIN_SIZE To IMAGE_SIZE - MARGIN_SIZE - 1
        '円形の領域だけ描画
        temp = Sqr((IMAGE_SIZE / 2 - MARGIN_SIZE) ^ 2 - (IMAGE_SIZE / 2 - i) ^ 2)
     
        For j = IMAGE_SIZE / 2 - temp To IMAGE_SIZE / 2 + temp
            pos = i * IMAGE_SIZE + j
            getColor weight(pos), min, max, r, g, b
            imgData(pos * 3 + 0) = b
            imgData(pos * 3 + 1) = g
            imgData(pos * 3 + 2) = r
        Next j
    Next i
End Sub

'カラースケールを描画
Private Sub drawColorScale(ByRef imgData() As Byte)
    Dim i As Long
    Dim j As Long
    Dim pos As Long
    Dim r As Byte
    Dim g As Byte
    Dim b As Byte

    For i = MARGIN_SIZE / 4 To MARGIN_SIZE * 3 / 4 - 1
        For j = IMAGE_SIZE / 4 To IMAGE_SIZE * 3 / 4 - 1
            pos = i * IMAGE_SIZE + j
            getColor CDbl(j - IMAGE_SIZE / 4), 0, IMAGE_SIZE / 2 - 1, r, g, b
            imgData(pos * 3 + 0) = b
            imgData(pos * 3 + 1) = g
            imgData(pos * 3 + 2) = r
        Next j
    Next i
End Sub

'等高線を描画
'隣のピクセルとの間に等高線があるかをチェックして、あれば黒く塗りつぶす
Private Sub drawContour(ByRef imgData() As Byte, mapData() As Double)
    Dim i As Long
    Dim ix As Long
    Dim iy As Long
    Dim pos As Long
    Dim temp As Long
    Dim level() As Double
 
    ReDim level(NUM_CONTOUR_LEVELS + 1) As Double
 
    For i = 0 To NUM_CONTOUR_LEVELS
        level(i) = color_min + (color_max - color_min) * i / NUM_CONTOUR_LEVELS
    Next i
 
    For iy = MARGIN_SIZE To IMAGE_SIZE - MARGIN_SIZE - 1
        temp = Sqr((IMAGE_SIZE / 2 - MARGIN_SIZE) ^ 2 - (IMAGE_SIZE / 2 - iy) ^ 2)
     
        For ix = IMAGE_SIZE / 2 - temp To IMAGE_SIZE / 2 + temp
            pos = iy * IMAGE_SIZE + ix
         
            For i = 1 To NUM_CONTOUR_LEVELS - 1
                '隣(右と下)のピクセルをチェック
                If (mapData(pos) - level(i)) * (mapData(pos + 1) - level(i)) < 0 _
                    Or (mapData(pos) - level(i)) * (mapData(pos + IMAGE_SIZE) - level(i)) < 0 Then
                    imgData(pos * 3 + 0) = CByte(0)
                    imgData(pos * 3 + 1) = CByte(0)
                    imgData(pos * 3 + 2) = CByte(0)
                End If
            Next i
        Next ix
    Next iy
End Sub

'データ点の描画
Private Sub drawDataPoints(ByRef imgData() As Byte, xPos() As Double, yPos() As Double, N As Long)
    Dim i As Long
    Dim j As Long
    Dim ix As Long
    Dim iy As Long
    Dim pos(4) As Long
    Dim ratio As Double

    ratio = (IMAGE_SIZE - 2 * MARGIN_SIZE) / DATA_SCALE
 
    For i = 0 To N - 1
        If Math.Abs(xPos(i)) < DATA_SCALE / 2 And Math.Abs(yPos(i)) < DATA_SCALE / 2 Then
            ix = xPos(i) * ratio + IMAGE_SIZE / 2
            iy = yPos(i) * ratio + IMAGE_SIZE / 2
         
            If 0 <= ix And ix < IMAGE_SIZE And 0 <= iy And iy < IMAGE_SIZE Then
                pos(0) = iy * IMAGE_SIZE + ix
                pos(1) = pos(0) - 1
                pos(2) = pos(0) + IMAGE_SIZE
                pos(3) = pos(0) + 1
                pos(4) = pos(0) - IMAGE_SIZE
             
                For j = 0 To 4
                    imgData(pos(j) * 3 + 0) = CByte(0)
                    imgData(pos(j) * 3 + 1) = CByte(0)
                    imgData(pos(j) * 3 + 2) = CByte(0)
                Next j
            End If
        End If
    Next i
End Sub

'輪郭の描画
Private Sub drawEdge(ByRef imgData() As Byte)
    Dim i As Long
    Dim j As Long
    Dim ix As Long
    Dim iy As Long
    Dim pos(3) As Long
 
    For i = 0 To IMAGE_SIZE
        iy = (IMAGE_SIZE / 2 - MARGIN_SIZE) * Math.Sin(PI * i / 2 / IMAGE_SIZE)
        ix = (IMAGE_SIZE / 2 - MARGIN_SIZE) * Math.Cos(PI * i / 2 / IMAGE_SIZE)
     
        pos(0) = (IMAGE_SIZE / 2 + iy) * IMAGE_SIZE + IMAGE_SIZE / 2 + ix
        pos(1) = (IMAGE_SIZE / 2 + ix) * IMAGE_SIZE + IMAGE_SIZE / 2 - iy
        pos(2) = (IMAGE_SIZE / 2 - iy) * IMAGE_SIZE + IMAGE_SIZE / 2 - ix
        pos(3) = (IMAGE_SIZE / 2 - ix) * IMAGE_SIZE + IMAGE_SIZE / 2 + iy
     
        For j = 0 To 3
            imgData(pos(j) * 3 + 0) = CByte(0)
            imgData(pos(j) * 3 + 1) = CByte(0)
            imgData(pos(j) * 3 + 2) = CByte(0)
        Next j
    Next i
End Sub

'2次元のグリッディング
Private Sub gridding(ByRef mapData() As Double, ByRef weight() As Double, xPos() As Double, yPos() As Double, data() As Double, N As Long)
    Dim i As Long
    Dim ix As Long
    Dim iy As Long
    Dim pos As Long
 
    Dim left As Long
    Dim top As Long
    Dim right As Long
    Dim bottom As Long
 
    Dim range2 As Double
    Dim sigma2 As Double
    Dim ratio As Double
    Dim x2 As Double
    Dim y2 As Double
    Dim r2 As Double
    Dim w As Double
 
    'メモリの初期化
    For i = 0 To IMAGE_SIZE * IMAGE_SIZE - 1
        mapData(i) = 0
        weight(i) = 0
    Next i
 
    range2 = range ^ 2
    sigma2 = 2 * sigma ^ 2
    ratio = (IMAGE_SIZE - 2 * MARGIN_SIZE) / DATA_SCALE
 
    'グリッディング
    For i = 0 To N - 1
        'ループ領域を計算
        bottom = (yPos(i) - range) * ratio + IMAGE_SIZE / 2
        top = (yPos(i) + range) * ratio + IMAGE_SIZE / 2
        left = (xPos(i) - range) * ratio + IMAGE_SIZE / 2
        right = (xPos(i) + range) * ratio + IMAGE_SIZE / 2
     
        'ループ領域を確認
        If bottom < 0 Then bottom = 0
        If IMAGE_SIZE - 1 < bottom Then bottom = IMAGE_SIZE - 1
        If top < 0 Then top = 0
        If IMAGE_SIZE - 1 < top Then top = IMAGE_SIZE - 1
        If left < 0 Then left = 0
        If IMAGE_SIZE - 1 < left Then left = IMAGE_SIZE - 1
        If right < 0 Then right = 0
        If IMAGE_SIZE - 1 < right Then right = IMAGE_SIZE - 1
     
        '重みつき平均の計算
        For iy = bottom To top
            y2 = ((iy - IMAGE_SIZE / 2) / ratio - yPos(i)) ^ 2
         
            For ix = left To right
                x2 = ((ix - IMAGE_SIZE / 2) / ratio - xPos(i)) ^ 2
                r2 = x2 + y2

                If r2 < range2 Then
                    If interpolation_type = INTERPOLATION_TYPE_LINEAR Then
                        w = CDbl(1) - Sqr(r2) / range
                    ElseIf interpolation_type = INTERPOLATION_TYPE_GAUSS Then
                        w = Exp(-r2 / sigma2)
                    End If
             
                    pos = iy * IMAGE_SIZE + ix
                    mapData(pos) = mapData(pos) + w * data(i)
                    weight(pos) = weight(pos) + w
                End If
            Next ix
        Next iy
    Next i
 
    '重みで規格化
    For i = 0 To IMAGE_SIZE * IMAGE_SIZE - 1
        If 0.000001 < weight(i) Then
            mapData(i) = mapData(i) / weight(i)
        Else
            mapData(i) = 0
        End If
    Next i
End Sub

'文字の描画
'x,y : 描画する文字の左下の座標(ビットマップと同じ座標系)
Private Sub drawString(ByRef imgData() As Byte, width As Long, height As Long, str As String, x As Long, y As Long)
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim key As Long
    Dim pos As Long
    Dim temp As Byte
 
    createFont
 
    For i = 0 To Len(str) - 1
        key = Asc(Mid(str, i + 1, 1))
     
        For j = 0 To 15
            temp = fnt((key - 32) * 16 + j)
         
            For k = 0 To 7
                If temp Mod 2 = 1 And 0 <= x + 8 * i + k And x + 8 * i + k < width And 0 <= y + j And y + j < height Then
                    pos = ((y + j) * width + (x + 8 * i + k)) * 3
             
                    imgData(pos + 0) = CByte(0)
                    imgData(pos + 1) = CByte(0)
                    imgData(pos + 2) = CByte(0)
                End If
             
                temp = temp \ 2
            Next k
        Next j
    Next i
End Sub

Private Sub getColor(data As Double, min As Double, max As Double, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
    Dim temp As Double
 
    temp = data
    If temp < min Then temp = min
    If max < temp Then temp = max
 
    temp = 255# * (temp - min) / (max - min)
 
    If color_map_type = COLOR_MAP_TYPE_GRAY Then
        b = CByte(temp)
        g = CByte(temp)
        r = CByte(temp)
    ElseIf color_map_type = COLOR_MAP_TYPE_JET1 Then
        jet2rgb1 CByte(temp), r, g, b
    ElseIf color_map_type = COLOR_MAP_TYPE_JET2 Then
        jet2rgb2 CByte(temp), r, g, b
    ElseIf color_map_type = COLOR_MAP_TYPE_HSV Then
        hsv2rgb CByte(temp), r, g, b
    End If
End Sub

Private Sub hsv2rgb(value As Byte, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
    Dim temp As Double
 
    temp = value / 255#
 
    If temp < 1 / 6 Then
        r = CByte(255)
        g = CByte(255 * (6 * temp))
        b = CByte(0)
    ElseIf temp < 2 / 6 Then
        r = CByte(255 * (2 - 6 * temp))
        g = CByte(255)
        b = CByte(0)
    ElseIf temp < 3 / 6 Then
        r = CByte(0)
        g = CByte(255)
        b = CByte(255 * (6 * temp - 2))
    ElseIf temp < 4 / 6 Then
        r = CByte(0)
        g = CByte(255 * (4 - 6 * temp))
        b = CByte(255)
    ElseIf temp < 5 / 6 Then
        r = CByte(255 * (6 * temp - 4))
        g = CByte(0)
        b = CByte(255)
    Else
        r = CByte(255)
        g = CByte(0)
        b = CByte(255 * (6 - 6 * temp))
    End If
End Sub

Private Sub jet2rgb1(value As Byte, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
    Dim temp As Double
 
    temp = value / 255#
 
    If temp < 1 / 8 Then
        r = CByte(0)
        g = CByte(0)
        b = CByte(255 * (4 * temp + 0.5))
    ElseIf temp < 3 / 8 Then
        r = CByte(0)
        g = CByte(255 * (4 * temp - 0.5))
        b = CByte(255)
    ElseIf temp < 5 / 8 Then
        r = CByte(255 * (4 * temp - 1.5))
        g = CByte(255)
        b = CByte(255 * (2.5 - 4 * temp))
    ElseIf temp < 7 / 8 Then
        r = CByte(255)
        g = CByte(255 * (3.5 - 4 * temp))
        b = CByte(0)
    Else
        r = CByte(255 * (4.5 - 4 * temp))
        g = CByte(0)
        b = CByte(0)
    End If
End Sub

Private Sub jet2rgb2(value As Byte, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
    If value < 256 / 3 Then
        r = CByte(0)
        g = CByte(255 * Math.Sin(PI * value / 255))
        b = CByte(255 * Math.Sin(PI * value / 255 + PI / 3))
    ElseIf value < 512 / 3 Then
        r = CByte(255 * Math.Sin(PI * value / 255 - PI / 3))
        g = CByte(255 * Math.Sin(PI * value / 255))
        b = CByte(255 * Math.Sin(PI * value / 255 + PI / 3))
    Else
        r = CByte(255 * Math.Sin(PI * value / 255 - PI / 3))
        g = CByte(255 * Math.Sin(PI * value / 255))
        b = CByte(0)
    End If
End Sub

'ペイントを呼び出す
Public Sub shell_paint()
    Dim id As Long
    id = Shell("mspaint.exe map.bmp", vbNormalFocus)
End Sub

'Bitmapを描画 (24bitフルカラーのみ対応)
Private Sub writeBitmap(filename As String, imgData() As Byte, width As Long, height As Long)
 
    'バイナリファイルに書き込む
    Open filename For Binary As 1
        Put 1, , "BM"
        Put 1, , CLng(3) * width * height + 54
        Put 1, , CInt(0)
        Put 1, , CInt(0)
        Put 1, , CLng(54)
     
        Put 1, , CLng(40)
        Put 1, , CLng(width)
        Put 1, , CLng(height)
        Put 1, , CInt(1)
        Put 1, , CInt(24)
        Put 1, , CLng(0)
        Put 1, , CLng(3) * width * height
        Put 1, , CLng(0)
        Put 1, , CLng(0)
        Put 1, , CLng(0)
        Put 1, , CLng(0)
     
        '画像データ
        Put 1, , imgData
    Close 1
End Sub

'フォントのビットマップデータ
Private Sub createFont()
    ReDim fnt(16 * 96 - 1) As Byte

    fnt(0) = 0: fnt(1) = 0: fnt(2) = 0: fnt(3) = 0: fnt(4) = 0: fnt(5) = 0: fnt(6) = 0: fnt(7) = 0: fnt(8) = 0: fnt(9) = 0: fnt(10) = 0: fnt(11) = 0: fnt(12) = 0: fnt(13) = 0: fnt(14) = 0: fnt(15) = 0
    fnt(16) = 0: fnt(17) = 0: fnt(18) = 24: fnt(19) = 24: fnt(20) = 0: fnt(21) = 0: fnt(22) = 8: fnt(23) = 8: fnt(24) = 8: fnt(25) = 8: fnt(26) = 8: fnt(27) = 8: fnt(28) = 8: fnt(29) = 8: fnt(30) = 8: fnt(31) = 0
    fnt(32) = 0: fnt(33) = 0: fnt(34) = 0: fnt(35) = 0: fnt(36) = 0: fnt(37) = 0: fnt(38) = 0: fnt(39) = 0: fnt(40) = 0: fnt(41) = 0: fnt(42) = 0: fnt(43) = 0: fnt(44) = 0: fnt(45) = 18: fnt(46) = 36: fnt(47) = 108
    fnt(48) = 0: fnt(49) = 18: fnt(50) = 18: fnt(51) = 18: fnt(52) = 18: fnt(53) = 63: fnt(54) = 18: fnt(55) = 18: fnt(56) = 18: fnt(57) = 18: fnt(58) = 127: fnt(59) = 36: fnt(60) = 36: fnt(61) = 36: fnt(62) = 36: fnt(63) = 0
    fnt(64) = 0: fnt(65) = 8: fnt(66) = 28: fnt(67) = 42: fnt(68) = 73: fnt(69) = 73: fnt(70) = 72: fnt(71) = 40: fnt(72) = 24: fnt(73) = 12: fnt(74) = 10: fnt(75) = 73: fnt(76) = 73: fnt(77) = 42: fnt(78) = 28: fnt(79) = 8
    fnt(80) = 0: fnt(81) = 0: fnt(82) = 49: fnt(83) = 73: fnt(84) = 74: fnt(85) = 74: fnt(86) = 52: fnt(87) = 4: fnt(88) = 8: fnt(89) = 16: fnt(90) = 22: fnt(91) = 41: fnt(92) = 41: fnt(93) = 73: fnt(94) = 70: fnt(95) = 0
    fnt(96) = 0: fnt(97) = 0: fnt(98) = 70: fnt(99) = 41: fnt(100) = 17: fnt(101) = 17: fnt(102) = 41: fnt(103) = 42: fnt(104) = 4: fnt(105) = 12: fnt(106) = 18: fnt(107) = 18: fnt(108) = 18: fnt(109) = 18: fnt(110) = 12: fnt(111) = 0
    fnt(112) = 0: fnt(113) = 0: fnt(114) = 0: fnt(115) = 0: fnt(116) = 0: fnt(117) = 0: fnt(118) = 0: fnt(119) = 0: fnt(120) = 0: fnt(121) = 0: fnt(122) = 0: fnt(123) = 0: fnt(124) = 4: fnt(125) = 8: fnt(126) = 12: fnt(127) = 12
    fnt(128) = 0: fnt(129) = 32: fnt(130) = 16: fnt(131) = 8: fnt(132) = 8: fnt(133) = 4: fnt(134) = 4: fnt(135) = 4: fnt(136) = 4: fnt(137) = 4: fnt(138) = 4: fnt(139) = 4: fnt(140) = 8: fnt(141) = 8: fnt(142) = 16: fnt(143) = 64
    fnt(144) = 0: fnt(145) = 2: fnt(146) = 4: fnt(147) = 8: fnt(148) = 8: fnt(149) = 16: fnt(150) = 16: fnt(151) = 16: fnt(152) = 16: fnt(153) = 16: fnt(154) = 16: fnt(155) = 16: fnt(156) = 8: fnt(157) = 8: fnt(158) = 4: fnt(159) = 4
    fnt(160) = 0: fnt(161) = 0: fnt(162) = 0: fnt(163) = 0: fnt(164) = 8: fnt(165) = 73: fnt(166) = 42: fnt(167) = 28: fnt(168) = 8: fnt(169) = 28: fnt(170) = 42: fnt(171) = 73: fnt(172) = 8: fnt(173) = 0: fnt(174) = 0: fnt(175) = 0
    fnt(176) = 0: fnt(177) = 0: fnt(178) = 0: fnt(179) = 0: fnt(180) = 0: fnt(181) = 8: fnt(182) = 8: fnt(183) = 8: fnt(184) = 127: fnt(185) = 8: fnt(186) = 8: fnt(187) = 8: fnt(188) = 0: fnt(189) = 0: fnt(190) = 0: fnt(191) = 0
    fnt(192) = 0: fnt(193) = 4: fnt(194) = 8: fnt(195) = 12: fnt(196) = 12: fnt(197) = 0: fnt(198) = 0: fnt(199) = 0: fnt(200) = 0: fnt(201) = 0: fnt(202) = 0: fnt(203) = 0: fnt(204) = 0: fnt(205) = 0: fnt(206) = 0: fnt(207) = 0
    fnt(208) = 0: fnt(209) = 0: fnt(210) = 0: fnt(211) = 0: fnt(212) = 0: fnt(213) = 0: fnt(214) = 0: fnt(215) = 0: fnt(216) = 62: fnt(217) = 0: fnt(218) = 0: fnt(219) = 0: fnt(220) = 0: fnt(221) = 0: fnt(222) = 0: fnt(223) = 0
    fnt(224) = 0: fnt(225) = 0: fnt(226) = 12: fnt(227) = 12: fnt(228) = 0: fnt(229) = 0: fnt(230) = 0: fnt(231) = 0: fnt(232) = 0: fnt(233) = 0: fnt(234) = 0: fnt(235) = 0: fnt(236) = 0: fnt(237) = 0: fnt(238) = 0: fnt(239) = 0
    fnt(240) = 0: fnt(241) = 0: fnt(242) = 1: fnt(243) = 1: fnt(244) = 2: fnt(245) = 2: fnt(246) = 4: fnt(247) = 4: fnt(248) = 8: fnt(249) = 16: fnt(250) = 16: fnt(251) = 32: fnt(252) = 32: fnt(253) = 64: fnt(254) = 64: fnt(255) = 0
    fnt(256) = 0: fnt(257) = 0: fnt(258) = 12: fnt(259) = 18: fnt(260) = 33: fnt(261) = 33: fnt(262) = 33: fnt(263) = 33: fnt(264) = 33: fnt(265) = 33: fnt(266) = 33: fnt(267) = 33: fnt(268) = 33: fnt(269) = 18: fnt(270) = 12: fnt(271) = 0
    fnt(272) = 0: fnt(273) = 0: fnt(274) = 8: fnt(275) = 8: fnt(276) = 8: fnt(277) = 8: fnt(278) = 8: fnt(279) = 8: fnt(280) = 8: fnt(281) = 8: fnt(282) = 8: fnt(283) = 8: fnt(284) = 8: fnt(285) = 14: fnt(286) = 8: fnt(287) = 0
    fnt(288) = 0: fnt(289) = 0: fnt(290) = 63: fnt(291) = 1: fnt(292) = 2: fnt(293) = 4: fnt(294) = 4: fnt(295) = 8: fnt(296) = 16: fnt(297) = 16: fnt(298) = 32: fnt(299) = 33: fnt(300) = 33: fnt(301) = 18: fnt(302) = 12: fnt(303) = 0
    fnt(304) = 0: fnt(305) = 0: fnt(306) = 12: fnt(307) = 18: fnt(308) = 33: fnt(309) = 33: fnt(310) = 32: fnt(311) = 16: fnt(312) = 12: fnt(313) = 16: fnt(314) = 32: fnt(315) = 33: fnt(316) = 33: fnt(317) = 18: fnt(318) = 12: fnt(319) = 0
    fnt(320) = 0: fnt(321) = 0: fnt(322) = 16: fnt(323) = 16: fnt(324) = 16: fnt(325) = 63: fnt(326) = 17: fnt(327) = 18: fnt(328) = 18: fnt(329) = 20: fnt(330) = 20: fnt(331) = 24: fnt(332) = 24: fnt(333) = 16: fnt(334) = 16: fnt(335) = 0
    fnt(336) = 0: fnt(337) = 0: fnt(338) = 12: fnt(339) = 18: fnt(340) = 33: fnt(341) = 32: fnt(342) = 32: fnt(343) = 32: fnt(344) = 33: fnt(345) = 19: fnt(346) = 13: fnt(347) = 1: fnt(348) = 1: fnt(349) = 1: fnt(350) = 63: fnt(351) = 0
    fnt(352) = 0: fnt(353) = 0: fnt(354) = 12: fnt(355) = 18: fnt(356) = 33: fnt(357) = 33: fnt(358) = 33: fnt(359) = 33: fnt(360) = 19: fnt(361) = 13: fnt(362) = 1: fnt(363) = 33: fnt(364) = 33: fnt(365) = 18: fnt(366) = 12: fnt(367) = 0
    fnt(368) = 0: fnt(369) = 0: fnt(370) = 4: fnt(371) = 4: fnt(372) = 4: fnt(373) = 4: fnt(374) = 8: fnt(375) = 8: fnt(376) = 8: fnt(377) = 16: fnt(378) = 16: fnt(379) = 16: fnt(380) = 32: fnt(381) = 32: fnt(382) = 63: fnt(383) = 0
    fnt(384) = 0: fnt(385) = 0: fnt(386) = 12: fnt(387) = 18: fnt(388) = 33: fnt(389) = 33: fnt(390) = 33: fnt(391) = 18: fnt(392) = 12: fnt(393) = 18: fnt(394) = 33: fnt(395) = 33: fnt(396) = 33: fnt(397) = 18: fnt(398) = 12: fnt(399) = 0
    fnt(400) = 0: fnt(401) = 0: fnt(402) = 12: fnt(403) = 18: fnt(404) = 33: fnt(405) = 33: fnt(406) = 32: fnt(407) = 44: fnt(408) = 50: fnt(409) = 33: fnt(410) = 33: fnt(411) = 33: fnt(412) = 33: fnt(413) = 18: fnt(414) = 12: fnt(415) = 0
    fnt(416) = 0: fnt(417) = 0: fnt(418) = 0: fnt(419) = 12: fnt(420) = 12: fnt(421) = 0: fnt(422) = 0: fnt(423) = 0: fnt(424) = 0: fnt(425) = 12: fnt(426) = 12: fnt(427) = 0: fnt(428) = 0: fnt(429) = 0: fnt(430) = 0: fnt(431) = 0
    fnt(432) = 0: fnt(433) = 4: fnt(434) = 8: fnt(435) = 12: fnt(436) = 12: fnt(437) = 0: fnt(438) = 0: fnt(439) = 0: fnt(440) = 0: fnt(441) = 12: fnt(442) = 12: fnt(443) = 0: fnt(444) = 0: fnt(445) = 0: fnt(446) = 0: fnt(447) = 0
    fnt(448) = 0: fnt(449) = 0: fnt(450) = 0: fnt(451) = 32: fnt(452) = 16: fnt(453) = 8: fnt(454) = 4: fnt(455) = 2: fnt(456) = 1: fnt(457) = 2: fnt(458) = 4: fnt(459) = 8: fnt(460) = 16: fnt(461) = 32: fnt(462) = 0: fnt(463) = 0
    fnt(464) = 0: fnt(465) = 0: fnt(466) = 0: fnt(467) = 0: fnt(468) = 0: fnt(469) = 0: fnt(470) = 62: fnt(471) = 0: fnt(472) = 0: fnt(473) = 0: fnt(474) = 62: fnt(475) = 0: fnt(476) = 0: fnt(477) = 0: fnt(478) = 0: fnt(479) = 0
    fnt(480) = 0: fnt(481) = 0: fnt(482) = 0: fnt(483) = 1: fnt(484) = 2: fnt(485) = 4: fnt(486) = 8: fnt(487) = 16: fnt(488) = 32: fnt(489) = 16: fnt(490) = 8: fnt(491) = 4: fnt(492) = 2: fnt(493) = 1: fnt(494) = 0: fnt(495) = 0
    fnt(496) = 0: fnt(497) = 0: fnt(498) = 12: fnt(499) = 12: fnt(500) = 0: fnt(501) = 0: fnt(502) = 4: fnt(503) = 4: fnt(504) = 8: fnt(505) = 16: fnt(506) = 32: fnt(507) = 33: fnt(508) = 33: fnt(509) = 18: fnt(510) = 12: fnt(511) = 0
    fnt(512) = 0: fnt(513) = 0: fnt(514) = 60: fnt(515) = 66: fnt(516) = 1: fnt(517) = 57: fnt(518) = 85: fnt(519) = 85: fnt(520) = 85: fnt(521) = 85: fnt(522) = 85: fnt(523) = 89: fnt(524) = 65: fnt(525) = 34: fnt(526) = 28: fnt(527) = 0
    fnt(528) = 0: fnt(529) = 0: fnt(530) = 65: fnt(531) = 65: fnt(532) = 65: fnt(533) = 62: fnt(534) = 34: fnt(535) = 34: fnt(536) = 34: fnt(537) = 20: fnt(538) = 20: fnt(539) = 20: fnt(540) = 20: fnt(541) = 8: fnt(542) = 8: fnt(543) = 0
    fnt(544) = 0: fnt(545) = 0: fnt(546) = 31: fnt(547) = 33: fnt(548) = 65: fnt(549) = 65: fnt(550) = 65: fnt(551) = 33: fnt(552) = 31: fnt(553) = 33: fnt(554) = 65: fnt(555) = 65: fnt(556) = 65: fnt(557) = 33: fnt(558) = 31: fnt(559) = 0
    fnt(560) = 0: fnt(561) = 0: fnt(562) = 28: fnt(563) = 34: fnt(564) = 65: fnt(565) = 65: fnt(566) = 1: fnt(567) = 1: fnt(568) = 1: fnt(569) = 1: fnt(570) = 1: fnt(571) = 65: fnt(572) = 65: fnt(573) = 34: fnt(574) = 28: fnt(575) = 0
    fnt(576) = 0: fnt(577) = 0: fnt(578) = 31: fnt(579) = 33: fnt(580) = 65: fnt(581) = 65: fnt(582) = 65: fnt(583) = 65: fnt(584) = 65: fnt(585) = 65: fnt(586) = 65: fnt(587) = 65: fnt(588) = 65: fnt(589) = 33: fnt(590) = 31: fnt(591) = 0
    fnt(592) = 0: fnt(593) = 0: fnt(594) = 127: fnt(595) = 1: fnt(596) = 1: fnt(597) = 1: fnt(598) = 1: fnt(599) = 1: fnt(600) = 63: fnt(601) = 1: fnt(602) = 1: fnt(603) = 1: fnt(604) = 1: fnt(605) = 1: fnt(606) = 127: fnt(607) = 0
    fnt(608) = 0: fnt(609) = 0: fnt(610) = 1: fnt(611) = 1: fnt(612) = 1: fnt(613) = 1: fnt(614) = 1: fnt(615) = 1: fnt(616) = 63: fnt(617) = 1: fnt(618) = 1: fnt(619) = 1: fnt(620) = 1: fnt(621) = 1: fnt(622) = 127: fnt(623) = 0
    fnt(624) = 0: fnt(625) = 0: fnt(626) = 92: fnt(627) = 98: fnt(628) = 65: fnt(629) = 65: fnt(630) = 65: fnt(631) = 113: fnt(632) = 1: fnt(633) = 1: fnt(634) = 1: fnt(635) = 65: fnt(636) = 65: fnt(637) = 34: fnt(638) = 28: fnt(639) = 0
    fnt(640) = 0: fnt(641) = 0: fnt(642) = 65: fnt(643) = 65: fnt(644) = 65: fnt(645) = 65: fnt(646) = 65: fnt(647) = 65: fnt(648) = 127: fnt(649) = 65: fnt(650) = 65: fnt(651) = 65: fnt(652) = 65: fnt(653) = 65: fnt(654) = 65: fnt(655) = 0
    fnt(656) = 0: fnt(657) = 0: fnt(658) = 28: fnt(659) = 8: fnt(660) = 8: fnt(661) = 8: fnt(662) = 8: fnt(663) = 8: fnt(664) = 8: fnt(665) = 8: fnt(666) = 8: fnt(667) = 8: fnt(668) = 8: fnt(669) = 8: fnt(670) = 28: fnt(671) = 0
    fnt(672) = 0: fnt(673) = 0: fnt(674) = 12: fnt(675) = 18: fnt(676) = 33: fnt(677) = 33: fnt(678) = 32: fnt(679) = 32: fnt(680) = 32: fnt(681) = 32: fnt(682) = 32: fnt(683) = 32: fnt(684) = 32: fnt(685) = 32: fnt(686) = 32: fnt(687) = 0
    fnt(688) = 0: fnt(689) = 0: fnt(690) = 65: fnt(691) = 65: fnt(692) = 33: fnt(693) = 17: fnt(694) = 17: fnt(695) = 11: fnt(696) = 5: fnt(697) = 9: fnt(698) = 9: fnt(699) = 17: fnt(700) = 33: fnt(701) = 33: fnt(702) = 65: fnt(703) = 0
    fnt(704) = 0: fnt(705) = 0: fnt(706) = 127: fnt(707) = 1: fnt(708) = 1: fnt(709) = 1: fnt(710) = 1: fnt(711) = 1: fnt(712) = 1: fnt(713) = 1: fnt(714) = 1: fnt(715) = 1: fnt(716) = 1: fnt(717) = 1: fnt(718) = 1: fnt(719) = 0
    fnt(720) = 0: fnt(721) = 0: fnt(722) = 73: fnt(723) = 73: fnt(724) = 73: fnt(725) = 85: fnt(726) = 85: fnt(727) = 85: fnt(728) = 85: fnt(729) = 99: fnt(730) = 99: fnt(731) = 99: fnt(732) = 99: fnt(733) = 65: fnt(734) = 65: fnt(735) = 0
    fnt(736) = 0: fnt(737) = 0: fnt(738) = 65: fnt(739) = 97: fnt(740) = 97: fnt(741) = 81: fnt(742) = 81: fnt(743) = 73: fnt(744) = 73: fnt(745) = 69: fnt(746) = 69: fnt(747) = 67: fnt(748) = 67: fnt(749) = 65: fnt(750) = 65: fnt(751) = 0
    fnt(752) = 0: fnt(753) = 0: fnt(754) = 28: fnt(755) = 34: fnt(756) = 65: fnt(757) = 65: fnt(758) = 65: fnt(759) = 65: fnt(760) = 65: fnt(761) = 65: fnt(762) = 65: fnt(763) = 65: fnt(764) = 65: fnt(765) = 34: fnt(766) = 28: fnt(767) = 0
    fnt(768) = 0: fnt(769) = 0: fnt(770) = 1: fnt(771) = 1: fnt(772) = 1: fnt(773) = 1: fnt(774) = 1: fnt(775) = 1: fnt(776) = 31: fnt(777) = 33: fnt(778) = 65: fnt(779) = 65: fnt(780) = 65: fnt(781) = 33: fnt(782) = 31: fnt(783) = 0
    fnt(784) = 0: fnt(785) = 0: fnt(786) = 92: fnt(787) = 34: fnt(788) = 81: fnt(789) = 73: fnt(790) = 65: fnt(791) = 65: fnt(792) = 65: fnt(793) = 65: fnt(794) = 65: fnt(795) = 65: fnt(796) = 65: fnt(797) = 34: fnt(798) = 28: fnt(799) = 0
    fnt(800) = 0: fnt(801) = 0: fnt(802) = 65: fnt(803) = 65: fnt(804) = 33: fnt(805) = 33: fnt(806) = 17: fnt(807) = 17: fnt(808) = 31: fnt(809) = 33: fnt(810) = 65: fnt(811) = 65: fnt(812) = 65: fnt(813) = 33: fnt(814) = 31: fnt(815) = 0
    fnt(816) = 0: fnt(817) = 0: fnt(818) = 28: fnt(819) = 34: fnt(820) = 65: fnt(821) = 65: fnt(822) = 64: fnt(823) = 32: fnt(824) = 24: fnt(825) = 6: fnt(826) = 1: fnt(827) = 65: fnt(828) = 65: fnt(829) = 34: fnt(830) = 28: fnt(831) = 0
    fnt(832) = 0: fnt(833) = 0: fnt(834) = 8: fnt(835) = 8: fnt(836) = 8: fnt(837) = 8: fnt(838) = 8: fnt(839) = 8: fnt(840) = 8: fnt(841) = 8: fnt(842) = 8: fnt(843) = 8: fnt(844) = 8: fnt(845) = 8: fnt(846) = 127: fnt(847) = 0
    fnt(848) = 0: fnt(849) = 0: fnt(850) = 28: fnt(851) = 34: fnt(852) = 65: fnt(853) = 65: fnt(854) = 65: fnt(855) = 65: fnt(856) = 65: fnt(857) = 65: fnt(858) = 65: fnt(859) = 65: fnt(860) = 65: fnt(861) = 65: fnt(862) = 65: fnt(863) = 0
    fnt(864) = 0: fnt(865) = 0: fnt(866) = 8: fnt(867) = 8: fnt(868) = 8: fnt(869) = 20: fnt(870) = 20: fnt(871) = 20: fnt(872) = 34: fnt(873) = 34: fnt(874) = 34: fnt(875) = 34: fnt(876) = 65: fnt(877) = 65: fnt(878) = 65: fnt(879) = 0
    fnt(880) = 0: fnt(881) = 0: fnt(882) = 34: fnt(883) = 34: fnt(884) = 34: fnt(885) = 34: fnt(886) = 34: fnt(887) = 85: fnt(888) = 85: fnt(889) = 85: fnt(890) = 85: fnt(891) = 73: fnt(892) = 73: fnt(893) = 73: fnt(894) = 73: fnt(895) = 0
    fnt(896) = 0: fnt(897) = 0: fnt(898) = 65: fnt(899) = 65: fnt(900) = 34: fnt(901) = 34: fnt(902) = 20: fnt(903) = 20: fnt(904) = 8: fnt(905) = 20: fnt(906) = 20: fnt(907) = 34: fnt(908) = 34: fnt(909) = 65: fnt(910) = 65: fnt(911) = 0
    fnt(912) = 0: fnt(913) = 0: fnt(914) = 8: fnt(915) = 8: fnt(916) = 8: fnt(917) = 8: fnt(918) = 8: fnt(919) = 8: fnt(920) = 8: fnt(921) = 20: fnt(922) = 20: fnt(923) = 34: fnt(924) = 34: fnt(925) = 65: fnt(926) = 65: fnt(927) = 0
    fnt(928) = 0: fnt(929) = 0: fnt(930) = 127: fnt(931) = 1: fnt(932) = 2: fnt(933) = 2: fnt(934) = 4: fnt(935) = 4: fnt(936) = 8: fnt(937) = 16: fnt(938) = 16: fnt(939) = 32: fnt(940) = 32: fnt(941) = 64: fnt(942) = 127: fnt(943) = 0
    fnt(944) = 0: fnt(945) = 62: fnt(946) = 2: fnt(947) = 2: fnt(948) = 2: fnt(949) = 2: fnt(950) = 2: fnt(951) = 2: fnt(952) = 2: fnt(953) = 2: fnt(954) = 2: fnt(955) = 2: fnt(956) = 2: fnt(957) = 2: fnt(958) = 2: fnt(959) = 62
    fnt(960) = 0: fnt(961) = 0: fnt(962) = 8: fnt(963) = 8: fnt(964) = 8: fnt(965) = 62: fnt(966) = 8: fnt(967) = 8: fnt(968) = 62: fnt(969) = 20: fnt(970) = 20: fnt(971) = 34: fnt(972) = 34: fnt(973) = 65: fnt(974) = 65: fnt(975) = 0
    fnt(976) = 0: fnt(977) = 62: fnt(978) = 32: fnt(979) = 32: fnt(980) = 32: fnt(981) = 32: fnt(982) = 32: fnt(983) = 32: fnt(984) = 32: fnt(985) = 32: fnt(986) = 32: fnt(987) = 32: fnt(988) = 32: fnt(989) = 32: fnt(990) = 32: fnt(991) = 62
    fnt(992) = 0: fnt(993) = 0: fnt(994) = 0: fnt(995) = 0: fnt(996) = 0: fnt(997) = 0: fnt(998) = 0: fnt(999) = 0: fnt(1000) = 0: fnt(1001) = 0: fnt(1002) = 0: fnt(1003) = 0: fnt(1004) = 0: fnt(1005) = 34: fnt(1006) = 20: fnt(1007) = 8
    fnt(1008) = 255: fnt(1009) = 0: fnt(1010) = 0: fnt(1011) = 0: fnt(1012) = 0: fnt(1013) = 0: fnt(1014) = 0: fnt(1015) = 0: fnt(1016) = 0: fnt(1017) = 0: fnt(1018) = 0: fnt(1019) = 0: fnt(1020) = 0: fnt(1021) = 0: fnt(1022) = 0: fnt(1023) = 0
    fnt(1024) = 0: fnt(1025) = 0: fnt(1026) = 0: fnt(1027) = 0: fnt(1028) = 0: fnt(1029) = 0: fnt(1030) = 0: fnt(1031) = 0: fnt(1032) = 0: fnt(1033) = 0: fnt(1034) = 0: fnt(1035) = 0: fnt(1036) = 0: fnt(1037) = 16: fnt(1038) = 8: fnt(1039) = 4
    fnt(1040) = 0: fnt(1041) = 0: fnt(1042) = 110: fnt(1043) = 49: fnt(1044) = 33: fnt(1045) = 34: fnt(1046) = 60: fnt(1047) = 32: fnt(1048) = 33: fnt(1049) = 30: fnt(1050) = 0: fnt(1051) = 0: fnt(1052) = 0: fnt(1053) = 0: fnt(1054) = 0: fnt(1055) = 0
    fnt(1056) = 0: fnt(1057) = 0: fnt(1058) = 29: fnt(1059) = 35: fnt(1060) = 65: fnt(1061) = 65: fnt(1062) = 65: fnt(1063) = 65: fnt(1064) = 35: fnt(1065) = 29: fnt(1066) = 1: fnt(1067) = 1: fnt(1068) = 1: fnt(1069) = 1: fnt(1070) = 1: fnt(1071) = 0
    fnt(1072) = 0: fnt(1073) = 0: fnt(1074) = 60: fnt(1075) = 66: fnt(1076) = 1: fnt(1077) = 1: fnt(1078) = 1: fnt(1079) = 1: fnt(1080) = 66: fnt(1081) = 60: fnt(1082) = 0: fnt(1083) = 0: fnt(1084) = 0: fnt(1085) = 0: fnt(1086) = 0: fnt(1087) = 0
    fnt(1088) = 0: fnt(1089) = 0: fnt(1090) = 92: fnt(1091) = 98: fnt(1092) = 65: fnt(1093) = 65: fnt(1094) = 65: fnt(1095) = 65: fnt(1096) = 98: fnt(1097) = 92: fnt(1098) = 64: fnt(1099) = 64: fnt(1100) = 64: fnt(1101) = 64: fnt(1102) = 64: fnt(1103) = 0
    fnt(1104) = 0: fnt(1105) = 0: fnt(1106) = 60: fnt(1107) = 66: fnt(1108) = 1: fnt(1109) = 1: fnt(1110) = 127: fnt(1111) = 65: fnt(1112) = 34: fnt(1113) = 28: fnt(1114) = 0: fnt(1115) = 0: fnt(1116) = 0: fnt(1117) = 0: fnt(1118) = 0: fnt(1119) = 0
    fnt(1120) = 0: fnt(1121) = 0: fnt(1122) = 4: fnt(1123) = 4: fnt(1124) = 4: fnt(1125) = 4: fnt(1126) = 4: fnt(1127) = 4: fnt(1128) = 4: fnt(1129) = 31: fnt(1130) = 4: fnt(1131) = 4: fnt(1132) = 4: fnt(1133) = 4: fnt(1134) = 24: fnt(1135) = 0
    fnt(1136) = 0: fnt(1137) = 62: fnt(1138) = 65: fnt(1139) = 65: fnt(1140) = 62: fnt(1141) = 2: fnt(1142) = 28: fnt(1143) = 34: fnt(1144) = 34: fnt(1145) = 92: fnt(1146) = 0: fnt(1147) = 0: fnt(1148) = 0: fnt(1149) = 0: fnt(1150) = 0: fnt(1151) = 0
    fnt(1152) = 0: fnt(1153) = 0: fnt(1154) = 65: fnt(1155) = 65: fnt(1156) = 65: fnt(1157) = 65: fnt(1158) = 65: fnt(1159) = 65: fnt(1160) = 35: fnt(1161) = 29: fnt(1162) = 1: fnt(1163) = 1: fnt(1164) = 1: fnt(1165) = 1: fnt(1166) = 1: fnt(1167) = 0
    fnt(1168) = 0: fnt(1169) = 0: fnt(1170) = 8: fnt(1171) = 8: fnt(1172) = 8: fnt(1173) = 8: fnt(1174) = 8: fnt(1175) = 8: fnt(1176) = 8: fnt(1177) = 8: fnt(1178) = 0: fnt(1179) = 0: fnt(1180) = 8: fnt(1181) = 8: fnt(1182) = 0: fnt(1183) = 0
    fnt(1184) = 0: fnt(1185) = 6: fnt(1186) = 8: fnt(1187) = 8: fnt(1188) = 8: fnt(1189) = 8: fnt(1190) = 8: fnt(1191) = 8: fnt(1192) = 8: fnt(1193) = 8: fnt(1194) = 0: fnt(1195) = 0: fnt(1196) = 8: fnt(1197) = 8: fnt(1198) = 0: fnt(1199) = 0
    fnt(1200) = 0: fnt(1201) = 0: fnt(1202) = 65: fnt(1203) = 33: fnt(1204) = 17: fnt(1205) = 11: fnt(1206) = 5: fnt(1207) = 9: fnt(1208) = 17: fnt(1209) = 33: fnt(1210) = 1: fnt(1211) = 1: fnt(1212) = 1: fnt(1213) = 1: fnt(1214) = 1: fnt(1215) = 0
    fnt(1216) = 0: fnt(1217) = 0: fnt(1218) = 8: fnt(1219) = 8: fnt(1220) = 8: fnt(1221) = 8: fnt(1222) = 8: fnt(1223) = 8: fnt(1224) = 8: fnt(1225) = 8: fnt(1226) = 8: fnt(1227) = 8: fnt(1228) = 8: fnt(1229) = 8: fnt(1230) = 8: fnt(1231) = 0
    fnt(1232) = 0: fnt(1233) = 0: fnt(1234) = 73: fnt(1235) = 73: fnt(1236) = 73: fnt(1237) = 73: fnt(1238) = 73: fnt(1239) = 73: fnt(1240) = 75: fnt(1241) = 53: fnt(1242) = 0: fnt(1243) = 0: fnt(1244) = 0: fnt(1245) = 0: fnt(1246) = 0: fnt(1247) = 0
    fnt(1248) = 0: fnt(1249) = 0: fnt(1250) = 65: fnt(1251) = 65: fnt(1252) = 65: fnt(1253) = 65: fnt(1254) = 65: fnt(1255) = 65: fnt(1256) = 35: fnt(1257) = 29: fnt(1258) = 0: fnt(1259) = 0: fnt(1260) = 0: fnt(1261) = 0: fnt(1262) = 0: fnt(1263) = 0
    fnt(1264) = 0: fnt(1265) = 0: fnt(1266) = 28: fnt(1267) = 34: fnt(1268) = 65: fnt(1269) = 65: fnt(1270) = 65: fnt(1271) = 65: fnt(1272) = 34: fnt(1273) = 28: fnt(1274) = 0: fnt(1275) = 0: fnt(1276) = 0: fnt(1277) = 0: fnt(1278) = 0: fnt(1279) = 0
    fnt(1280) = 0: fnt(1281) = 1: fnt(1282) = 1: fnt(1283) = 29: fnt(1284) = 35: fnt(1285) = 65: fnt(1286) = 65: fnt(1287) = 65: fnt(1288) = 35: fnt(1289) = 29: fnt(1290) = 0: fnt(1291) = 0: fnt(1292) = 0: fnt(1293) = 0: fnt(1294) = 0: fnt(1295) = 0
    fnt(1296) = 0: fnt(1297) = 64: fnt(1298) = 64: fnt(1299) = 92: fnt(1300) = 98: fnt(1301) = 65: fnt(1302) = 65: fnt(1303) = 65: fnt(1304) = 98: fnt(1305) = 92: fnt(1306) = 0: fnt(1307) = 0: fnt(1308) = 0: fnt(1309) = 0: fnt(1310) = 0: fnt(1311) = 0
    fnt(1312) = 0: fnt(1313) = 0: fnt(1314) = 4: fnt(1315) = 4: fnt(1316) = 4: fnt(1317) = 4: fnt(1318) = 4: fnt(1319) = 4: fnt(1320) = 12: fnt(1321) = 116: fnt(1322) = 0: fnt(1323) = 0: fnt(1324) = 0: fnt(1325) = 0: fnt(1326) = 0: fnt(1327) = 0
    fnt(1328) = 0: fnt(1329) = 0: fnt(1330) = 62: fnt(1331) = 65: fnt(1332) = 64: fnt(1333) = 56: fnt(1334) = 6: fnt(1335) = 1: fnt(1336) = 65: fnt(1337) = 62: fnt(1338) = 0: fnt(1339) = 0: fnt(1340) = 0: fnt(1341) = 0: fnt(1342) = 0: fnt(1343) = 0
    fnt(1344) = 0: fnt(1345) = 0: fnt(1346) = 24: fnt(1347) = 4: fnt(1348) = 4: fnt(1349) = 4: fnt(1350) = 4: fnt(1351) = 4: fnt(1352) = 4: fnt(1353) = 31: fnt(1354) = 4: fnt(1355) = 4: fnt(1356) = 4: fnt(1357) = 4: fnt(1358) = 0: fnt(1359) = 0
    fnt(1360) = 0: fnt(1361) = 0: fnt(1362) = 92: fnt(1363) = 98: fnt(1364) = 65: fnt(1365) = 65: fnt(1366) = 65: fnt(1367) = 65: fnt(1368) = 65: fnt(1369) = 65: fnt(1370) = 0: fnt(1371) = 0: fnt(1372) = 0: fnt(1373) = 0: fnt(1374) = 0: fnt(1375) = 0
    fnt(1376) = 0: fnt(1377) = 0: fnt(1378) = 8: fnt(1379) = 8: fnt(1380) = 20: fnt(1381) = 20: fnt(1382) = 34: fnt(1383) = 34: fnt(1384) = 65: fnt(1385) = 65: fnt(1386) = 0: fnt(1387) = 0: fnt(1388) = 0: fnt(1389) = 0: fnt(1390) = 0: fnt(1391) = 0
    fnt(1392) = 0: fnt(1393) = 0: fnt(1394) = 34: fnt(1395) = 34: fnt(1396) = 34: fnt(1397) = 85: fnt(1398) = 85: fnt(1399) = 73: fnt(1400) = 73: fnt(1401) = 73: fnt(1402) = 0: fnt(1403) = 0: fnt(1404) = 0: fnt(1405) = 0: fnt(1406) = 0: fnt(1407) = 0
    fnt(1408) = 0: fnt(1409) = 0: fnt(1410) = 65: fnt(1411) = 34: fnt(1412) = 20: fnt(1413) = 8: fnt(1414) = 8: fnt(1415) = 20: fnt(1416) = 34: fnt(1417) = 65: fnt(1418) = 0: fnt(1419) = 0: fnt(1420) = 0: fnt(1421) = 0: fnt(1422) = 0: fnt(1423) = 0
    fnt(1424) = 0: fnt(1425) = 3: fnt(1426) = 4: fnt(1427) = 8: fnt(1428) = 20: fnt(1429) = 20: fnt(1430) = 34: fnt(1431) = 34: fnt(1432) = 65: fnt(1433) = 65: fnt(1434) = 0: fnt(1435) = 0: fnt(1436) = 0: fnt(1437) = 0: fnt(1438) = 0: fnt(1439) = 0
    fnt(1440) = 0: fnt(1441) = 0: fnt(1442) = 127: fnt(1443) = 1: fnt(1444) = 2: fnt(1445) = 4: fnt(1446) = 8: fnt(1447) = 16: fnt(1448) = 32: fnt(1449) = 127: fnt(1450) = 0: fnt(1451) = 0: fnt(1452) = 0: fnt(1453) = 0: fnt(1454) = 0: fnt(1455) = 0
    fnt(1456) = 0: fnt(1457) = 56: fnt(1458) = 8: fnt(1459) = 8: fnt(1460) = 8: fnt(1461) = 8: fnt(1462) = 8: fnt(1463) = 8: fnt(1464) = 4: fnt(1465) = 8: fnt(1466) = 8: fnt(1467) = 8: fnt(1468) = 8: fnt(1469) = 8: fnt(1470) = 8: fnt(1471) = 56
    fnt(1472) = 8: fnt(1473) = 8: fnt(1474) = 8: fnt(1475) = 8: fnt(1476) = 8: fnt(1477) = 8: fnt(1478) = 8: fnt(1479) = 8: fnt(1480) = 8: fnt(1481) = 8: fnt(1482) = 8: fnt(1483) = 8: fnt(1484) = 8: fnt(1485) = 8: fnt(1486) = 8: fnt(1487) = 8
    fnt(1488) = 0: fnt(1489) = 14: fnt(1490) = 8: fnt(1491) = 8: fnt(1492) = 8: fnt(1493) = 8: fnt(1494) = 8: fnt(1495) = 8: fnt(1496) = 16: fnt(1497) = 8: fnt(1498) = 8: fnt(1499) = 8: fnt(1500) = 8: fnt(1501) = 8: fnt(1502) = 8: fnt(1503) = 14
    fnt(1504) = 0: fnt(1505) = 0: fnt(1506) = 0: fnt(1507) = 0: fnt(1508) = 0: fnt(1509) = 0: fnt(1510) = 0: fnt(1511) = 0: fnt(1512) = 0: fnt(1513) = 0: fnt(1514) = 0: fnt(1515) = 0: fnt(1516) = 0: fnt(1517) = 0: fnt(1518) = 25: fnt(1519) = 38
    fnt(1520) = 0: fnt(1521) = 0: fnt(1522) = 0: fnt(1523) = 0: fnt(1524) = 0: fnt(1525) = 0: fnt(1526) = 0: fnt(1527) = 0: fnt(1528) = 0: fnt(1529) = 0: fnt(1530) = 0: fnt(1531) = 0: fnt(1532) = 0: fnt(1533) = 0: fnt(1534) = 0: fnt(1535) = 0

End Sub

パーキンソンの法則

 社会学に「パーキンソンの法則」というのがあります。「公務員は、お互いに仕事を作り出してしまうから、人数が増え続ける」というものです。無駄な手続きが増えて、仕事量が増えて、人員が必要になる、というのはありそうな話です。

 パーキンソンの法則は、公務員に限らず、一般の組織にも当てはまると思います。組織のヒトを遊ばせるわけにはいかないから、不必要かもしれない適当な仕事を与えておく。いつか使うかもしれないという理由で、使えそうなモノを集めると、それを管理する仕事が発生する。そんなこんなが続くと、仕事が増えて、人員が必要になり、組織は肥大化していきます。

 より一般的なパーキンソンの法則は、「ある資源への需要は可能な限り増大する」というものです。

 パソコンのメモリは、あればあるだけ使われます。データが多ければ検索に時間がかかって不便だとは知りつつも、築かれるのはいつも無駄なデータの山です。こういう場合、管理リストを作ろうとしても、リストの更新を忘れたりして、たいていうまくいきません。

 世の中には、増えるのは簡単で、減らすのは難しいことが色々あります。「明日から君の仕事はなくなるよ」なんて、なかなか言えないものです。ですが、増大する一方では、複雑化するだけです。パーキンソンの法則を意識して、無駄な仕事を増やさないように心がけたいものです。


参考:wikipedia

2015年4月4日土曜日

多数決と数の暴力

 多数決は民主的に集団の意思を決定する方法です。政治の世界だけでなく、ビジネスや学校などでも多数決で意思決定をすることは多いと思います。

 ところで、集団における賢さは正規分布をしているでしょう。つまり、極端に賢い人間や、極端に愚かな人間は少なく、大多数はそれなりに賢く、それなりに愚かな人間です。

 ということは、極端に賢い人間が考えた賢い意見というのは少数派です。少数派の意見は、多数決により否定される可能性があります。残念ながら、大多数の人間が賢い意見を理解するとは限りません。(これは、いわゆる民主主義の弊害というやつです。)

 賢い意見が採用されないなら、その意見を提案した人はどう思うでしょうか?
私は極端に賢い少数派ではありませんが、それでも、一生懸命考えて、いい意見を提案したのに、採用されなかったら、落ち込みます。打ちひしがれます。
多数決は、賢い意見を提案した人の心を傷つける可能性があると思います。まさに数の暴力です。

 こういった数の暴力で、賢い人間の心が傷つけられ、加えて集団が賢い意見を採用しないというのでは、何もいいことがありません。数の暴力による失敗を起こさないために、少数派の意見でもそれを正当に評価できるよう、私達、個々人が、賢くならなければいけないのだと思います。


・・・なんてことを、ふと思いました。


参考:wikipedia 多数決