command line arguments - How to convert character to integer in fortran? -
how manipulate command line argument? example
te.f90 program print_ integer :: character(len = 32) :: arg = 1 call get_command_argument(i, arg) if ( len_trim(arg) == 0) exit write(*,*) trim(arg) write(*,*) trim(arg)**2 = + 1 end end program print_ te.sh #!/bin/bash (( x = 1; x <=3; x++ )) ./te $x done i pass $x arg has type character, want manipulate arg number, when execute ./te.sh, got error promotion operands of binary numeric operator '**' @ (1) character(1)/integer(4).
what do?
you'll need convert string (arg) integer.
program print_ integer :: i, iarg character(len = 32) :: arg = 1 call get_command_argument(i, arg) if ( len_trim(arg) == 0) exit write(*,*) trim(arg) read(arg,"(i)") iarg write(*,*) iarg**2 = + 1 end end program print_
Comments
Post a Comment