Path: | macro.rb |
Last Update: | Wed Jan 11 16:59:32 JST 2006 |
Authors: | Yasuhiro MORIKAWA |
Version: | $Id: macro.rb,v 1.5 2006/01/11 07:59:32 morikawa Exp $ |
Tag Name: | $Name: gt4f90io-20060117 $ |
Copyright: | Copyright (C) GFD Dennou Club, 2005. All rights reserved. |
License: | See ../COPYRIGHT |
These functions are used to generate f90 code files from Ruby code files. They are expected to help ruby code approximates f90 code for as long as possible.
[JAPANESE]
これらの関数は Ruby で記述されたファイルから F90 ファイルを生成 するための関数です. これらの関数により, できるだけ F90 コードに 近い形で Ruby のコードを記述できることが期待されます.
array_colon(num) [JA]
array_colon(num) num に正の整数を代入する. 0 ならば何も出力せず, 1 ならば (:), 2 ならば (:,:), ... と出力する.
# File macro.rb, line 199 199: def array_colon(num) 200: return unless num 201: int = num.to_i 202: return if int < 1 203: return "(:)" if int < 2 204: int -= 1 205: body = "(:" 206: int.times{ 207: body << ",:" 208: } 209: body << ")" 210: return body 211: end
foreach(string-1, first, last, string-2) [JA]
forloop(string-1, first, last, string-2) first, last には整数を代入する. string-2 を last - first 回文だけ反復して返す. その際, string-2 内で string-1 と同じ文字列を数値に置換する. 置換される数値は first から last へと 1 つづつ増加する数値である.
# File macro.rb, line 167 167: def foreach(str, *words) 168: return if words.size < 2 169: body = "#{words[words.size - 1]}" 170: words.pop 171: rbody = "" 172: repeated = nil 173: words.each{ |word| 174: rbody << "\n" if repeated 175: rbody << body.sub(/^\n/, '').gsub(/#{str}/, word.to_s).chomp 176: repeated = true 177: } 178: return rbody.chomp 179: end
forloop(string-1, first, last, string-2) [JA]
forloop(str, first, last, body) first, last には整数を代入する. body を last - first 回文だけ反復して返す. その際, body 内で str と同じ文字列を数値に置換する. 置換される数値は first から last へと 1 つづつ増加する数値である.
# File macro.rb, line 136 136: def forloop(str, first, last, body) 137: rbody = "" 138: repeated = nil 139: for i in first..last 140: rbody << "\n" if repeated 141: rbody << body.sub(/^\n/, '').gsub(/#{str}/, i.to_s).chomp 142: repeated = true 143: end 144: return rbody.chomp 145: end
ifelse(string-1, string-2, equal, [not-equal]) ifelse(string-1, string-2, equal, [string-3, string-4, equal, ... [not-equal]]) [JA]
ifelse(string-1, string-2, equal, [not-equal]) ifelse(string-1, string-2, equal, [string-3, string-4, equal, ... [not-equal]]) string-1 と string-2 が等しい場合, equal が返る. 等しくない場合には not-equal が返る. not-equal が指定されない場合には何も返らない. 後ろにさらに条件分岐を付け加えることも可能である. 3 つ目の例では, string-3 と 4 が指定されている. string-1 と 2 が異なる場合, 次に string-3 と string-4 が比較され, 等しい場合にはその後ろの equal が返る. 等しくない場合には さらに後ろの引数に制御を渡す.
# File macro.rb, line 84 84: def ifelse(*all) 85: allsize = all.size 86: entire = Array.new 87: count = -1 88: one_set = Array.new(3) 89: body = "" 90: all.each{ |item| 91: count += 1 92: if count == allsize then 93: entire << Array.new([item]) 94: break 95: end 96: one_set[count.modulo(3)] = item 97: if count.modulo(3) == 2 then 98: entire << one_set.clone 99: one_set.clear 100: next 101: end 102: } 103: entire.each{ |set| 104: if set.size == 1 then 105: body << set[0].sub(/^\n/, '').chomp 106: break 107: end 108: if set[0] == set[1] then 109: body << set[2].sub(/^\n/, '').chomp 110: break 111: end 112: } 113: return body.chomp 114: end
# File macro.rb, line 48 48: def rb2f90_emacs_readonly 49: mess = "!Local Variables:\n" 50: mess << "!mode: f90\n!buffer-read-only: t\n!End:\n" 51: return mess 52: end
# File macro.rb, line 24 24: def rb2f90_header_comment 25: mess = "! *** Caution!! ***\n!\n! This file is generated from \"\#{File.basename($0.to_s)}\" by Ruby \#{RUBY_VERSION}.\n! Please do not edit this file directly.\n!\n! [JAPANESE]\n!\n! \242\250\242\250\242\250 \303\355\260\325!!! \242\250\242\250\242\250\n!\n! \244\263\244\316\245\325\245\241\245\244\245\353\244\317 \"\#{File.basename($0.to_s)}\" \244\253\244\351 Ruby \#{RUBY_VERSION}\n! \244\313\244\350\244\303\244\306\274\253\306\260\300\270\300\256\244\265\244\354\244\277\245\325\245\241\245\244\245\353\244\307\244\271.\n! \244\263\244\316\245\325\245\241\245\244\245\353\244\362\304\276\300\334\312\324\275\270\244\267\244\336\244\273\244\363\244\350\244\246\244\252\264\352\244\244\303\327\244\267\244\336\244\271.\n!\n" 26: 27: return mess 28: end