Subroutine read_commandline

  1 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2 : !
  3 : ! Read data needed to run the VOM
  4 : !   Parameter optimisation algorithm based on a paper by Duan et al.
  5 : !   (1993, J. Opt. Theory and Appl., 76, 501--521).
  6 : !
  7 : !
  8 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9 : !
 10 : ! Currently only includes the reading of command line arguments
 11 : ! Needs to contain all subroutines that read data in the future
 12 : !
 13 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 14 : !
 15 : ! Copyright (C) 2008 Stan Schymanski
 16 : !
 17 : !   This program is free software: you can redistribute it and/or modify
 18 : !   it under the terms of the GNU General Public License as published by
 19 : !   the Free Software Foundation, either version 3 of the License, or
 20 : !   (at your option) any later version.
 21 : !
 22 : !   This program is distributed in the hope that it will be useful,
 23 : !   but WITHOUT ANY WARRANTY; without even the implied warranty of
 24 : !   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 25 : !   GNU General Public License for more details.
 26 : !
 27 : !   You should have received a copy of the GNU General Public License
 28 : !   along with this program. If not, see .
 29 : !
 30 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 31 : 
 32 : 
 33 : 
 34 : subroutine read_commandline(outputpath_tmp, inputpath_tmp, change_in, change_out )
 35 :       use vom_vegwat_mod
 36 :       implicit none
 37 : 
 38 :      CHARACTER*100, INTENT(out)                    :: outputpath_tmp ! Temporary outputpath 
 39 :      CHARACTER*100, INTENT(out)                    :: inputpath_tmp  ! Temporary inputpath
 40 :      LOGICAL, INTENT(out)                          :: change_in      ! Change input true/false
 41 :      LOGICAL, INTENT(out)                          :: change_out     ! Change output true/false
 42 : 
 43 :      CHARACTER(len=100), DIMENSION(:), ALLOCATABLE :: args           ! array for arguments
 44 :      INTEGER                                       :: ix             ! Counter
 45 :      INTEGER                                       :: num_args       ! Number of arguments
 46 : 
 47 : 
 48 :      !count arguments
 49 :      num_args = command_argument_count()
 50 : 
 51 :      !create array to save arguments
 52 :      allocate(args(num_args))  
 53 : 
 54 :      do ix = 1, num_args
 55 :          !loop over arguments and save them
 56 :          call get_command_argument(ix,args(ix))
 57 :      end do
 58 : 
 59 :      change_in  = .FALSE.
 60 :      change_out = .FALSE.
 61 : 
 62 :      !loop over saved arguments and check flags
 63 :      do ix = 1, num_args
 64 : 
 65 :         !check inputpath
 66 :         if(args(ix) .eq. "-i") then
 67 :            inputpath_tmp = args(ix+1)
 68 :            change_in = .True.
 69 :         end if
 70 : 
 71 :         !check outputpath
 72 :         if(args(ix) .eq. "-o") then
 73 :            outputpath_tmp = args(ix+1)
 74 :            change_out = .True.
 75 :         end if
 76 : 
 77 :         !check namelist and read again if needed
 78 :         if(args(ix) .eq. "-n") then
 79 :            sfile_namelist = args(ix+1)
 80 :            write(*,*) "Changed vom_namelist:", sfile_namelist
 81 :         end if
 82 : 
 83 :      end do
 84 : 
 85 : 
 86 : 
 87 : 
 88 : 
 89 : end subroutine read_commandline