#!/usr/bin/env ruby # -*- f90 -*- # vi: set sw=4 ts=8: require("lib-rb2f90-macro") require("optparse") # # "sysdeparg-****.f90" Generator with Ruby. # opt = OptionParser.new opt.on('--argtype=VAL') {|v| $argtype = v} opt.parse!(ARGV) $argtype = "NOSTD" unless $argtype print <<"__EndOfFortran90Code__" !-- #{rb2f90_header_comment}! !++ ! !== SysdepArg - 環境依存性ルーチン (コマンドライン取得) ! ! Authors:: Eizi TOYODA, Yasuhiro MORIKAWA ! Version:: $Id: sysdeparg.rb2f90,v 1.2 2009-03-22 02:17:32 morikawa Exp $ ! Tag Name:: $Name: gtool5-20090704 $ ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved. ! License:: See COPYRIGHT[link:../../COPYRIGHT] ! ! Fortran 95 以前の大抵の処理系では IARGC, GETARG というサービスサブルーチンが ! 用意されている (これらは Fortran90/95 の規格には含まれていない). ! Fortran 2003 規格には COMMAND_ARGUMENT_COUNT, GET_COMMAND_ARGUMENT ! というサブルーチンが規定されている. ! これを使えない処理系では適宜対処が必要である。 ! 日立コンパイラでは上記サービスサブルーチンの挙動が違うので注意。 ! __EndOfFortran90Code__ print <<"__EndOfFortran90Code__" integer function SysdepArgCount() result(result) ! ! この手続きは, コマンドライン引数の数を返します. ! F95 以前の処理系では Fortran90/95 規格外の IARGC() ! 関数により実装され, F2003 に対応する処理系では ! COMMAND_ARGUMENT_COUNT 関数によって実装されます. ! ! Get the number of commandline arguments. ! In F95, it is implemented by nonstandard built-in ! function IARGC(). ! In F2003, it is implemented by standard built-in ! function COMMAND_ARGUMENT_COUNT(). ! implicit none ! ! Selected by Makefile using Ruby ! #{ifelse($argtype, "HITACHI", %Q{ interface integer function iargc() end function iargc end interface result = iargc() - 1 }, $argtype, "F2003STD", %Q{ result = command_argument_count() }, %Q{ interface integer function iargc() end function iargc end interface result = iargc() })} end function SysdepArgCount __EndOfFortran90Code__ print <<"__EndOfFortran90Code__" subroutine SysdepArgGet(idx_given, result) ! ! この手続きはコマンドライン引数のうち、*index* (*idx_given*) ! 番目の値を *value* (*result*) に返します。 ! ! *index* が引数の数よりも大きい場合、*value* には空文字 ! が返ります。*index* が負の場合には、後方からの順番になります。 ! すなわち、-1 ならば最後の引数が返ります。 ! ! ほとんどの処理系では Fortran90/95 規格外の GETARGC() ! 関数により実装されます。 ! ! gets the *index*th (*idx_given*th) commandline argument ! to *value* (*result*). ! ! If *index* is more than the number of arguments, ! *value* will be filled with blank. ! If *index* is negative, *index*th argument in reverse ! is return to *value*. In other words, if *index* = -1, ! the last argument is returned. ! ! Most typically, it is implemented by nonstandard built-in ! subroutine GETARG(). ! implicit none integer, intent(in):: idx_given character(len = *), intent(out):: result integer:: idx integer:: argc interface integer function SysdepArgCount() end function SysdepArgCount end interface continue argc = SysdepArgCount() if (idx_given < 0) then idx = argc + 1 + idx_given else idx = idx_given endif if (idx > argc) then result = "" else ! ! Selected by Makefile using Ruby ! #{ifelse($argtype, "HITACHI", %Q{ call getarg(idx + 1, result) }, $argtype, "F2003STD", %Q{ call get_command_argument(idx, result) }, %Q{ call getarg(idx, result) })} endif end subroutine SysdepArgGet __EndOfFortran90Code__ print <<"__EndOfFooter__" !-- ! vi:set readonly sw=4 ts=8: ! #{rb2f90_emacs_readonly}! !++ __EndOfFooter__