Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:58:04+00:00 2026-06-15T18:58:04+00:00

GCC version 4.6 The Problem: To find a way to feed in parameters to

  • 0

GCC version 4.6

The Problem: To find a way to feed in parameters to the executable, say a.out, from the command line – more specifically feed in an array of double precision numbers.

Attempt: Using the READ(*,*) command, which is older in the standard:
Program test.f –

PROGRAM MAIN  
     REAL(8)    :: A,B  
     READ(*,*) A,B
     PRINT*, A+B, COMMAND_ARGUMENT_COUNT()
END PROGRAM MAIN

The execution –

$ gfortran test.f
$ ./a.out 3.D0 1.D0

This did not work. On a bit of soul-searching, found that

$./a.out
3.d0,1.d0
   4.0000000000000000                0

does work, but the second line is an input prompt, and the objective of getting this done in one-line is not achieved. Also the COMMAND_ARGUMENT_COUNT() shows that the numbers fed into the input prompt don’t really count as ‘command line arguments’, unlike PERL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:58:06+00:00Added an answer on June 15, 2026 at 6:58 pm

    If you want to get the arguments fed to your program on the command line, use the (since Fortran 2003) standard intrinsic subroutine GET_COMMAND_ARGUMENT. Something like this might work

    PROGRAM MAIN  
         REAL(8)    :: A,B
         integer :: num_args, ix
         character(len=12), dimension(:), allocatable :: args
    
         num_args = command_argument_count()
         allocate(args(num_args))  ! I've omitted checking the return status of the allocation 
    
         do ix = 1, num_args
             call get_command_argument(ix,args(ix))
             ! now parse the argument as you wish
         end do
    
         PRINT*, A+B, COMMAND_ARGUMENT_COUNT()
    END PROGRAM MAIN
    

    Note:

    • The second argument to the subroutine get_command_argument is a character variable which you’ll have to parse to turn into a real (or whatever). Note also that I’ve allowed only 12 characters in each element of the args array, you may want to fiddle around with that.
    • As you’ve already figured out read isn’t used for reading command line arguments in Fortran programs.

    Since you want to read an array of real numbers, you might be better off using the approach you’ve already figured out, that is reading them from the terminal after the program has started, it’s up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem with compiling. gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2) c89 cmake version 2.8.7
I have two Executable generated with different gcc version One is using gcc 3.4.2
I'm trying to find a way to debug core files sent to me from
I am running g++(gcc version 3.4.4) on cygwin. I can't get this small snippet
Redhat 5.5 gcc version 4.1.2 I have a directory call lib, and in that
When I'm trying to compile this code with gcc version 4.6.3 on linux with
I have written two short tests and compiled both with g++ -S (gcc version
When I compile C code in recent version of gcc, I am getting the
when I get a compiler error (in my case gcc) in Emacs (version 23
I am using xcode 4, Compiler version LLVM GCC 4.2. I have been trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.