Find the answer to your Linux question:
Results 1 to 3 of 3
Hi all... I'm programming in Fortran 77 and i call a external program which receive 3 arguments. This arguments are variables of the fortran code. How can i pass this ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    1

    Variables as arguments in Fortran 77

    Hi all...
    I'm programming in Fortran 77 and i call a external program which receive 3 arguments. This arguments are variables of the fortran code. How can i pass this variables as arguments of the external program (or script), using the 'call system()' subroutine?


    Thanks all...

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Usually you have to dynamically build the command line with all the arguments and store that to a buffer which is passed in turn to the system() call. There are C language calls that will allow you to pass the argument list as a variable length argument list (execl) or an array of arguments (execv), but I don't know if you can call them from Fortran or not.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    In keeping with a Fortran style, you can write to a Fortran character variable, and pass that to system:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate composed string to call system, Fortran.
    
    echo
    set +o nounset
    LC_ALL=C ; LANG=C ; export LC_ALL LANG
    echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
    echo "(Versions displayed with local utility \"version\")"
    version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) gfortran
    set -o nounset
    echo
    
    FILE=${1-t.f}
    
    echo " Data file $FILE:"
    cat $FILE
    
    echo
    echo " Results:"
    gfortran -Wall -ffree-form $FILE
    ./a.out
    
    exit 0
    Producing:
    Code:
    % ./s1
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0 
    GNU bash 3.2.39
    gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
    
     Data file t.f:
    program main
    
    integer mark
    character*12 first, second
    character*50 command
    
    ! As a literal string.
    
    call system("echo 'Hello, world.'")
    
    ! As a string composed with a format to an "internal file".
    
    first = " Hello, "
    second = "world, and: "
    mark = 99
    write(command,'(a," ",a, " ",a," ",i2," ",a)') "echo '",first,second,mark,"'"
    print*, "command ", command
    
    call system(command)
    
    end
    
     Results:
    Hello, world.
     command echo '  Hello,      world, and:  99 '             
      Hello,      world, and:  99
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...