View previous topic :: View next topic |
Author |
Message |
mhudson
Joined: 05 Jan 2006 Posts: 18
|
Posted: Thu Jun 01, 2006 9:37 am Post subject: Issue with use of CMNARGS@ |
|
|
Hi, I've got some command line parameters to parse. I would usually just run along the characters in the string to find where the spaces are between the arguments and then extract them in that way, but I thought I'd use the CMNARGS@ function instead, as this seems like it ought to do what I need. However, it does not get the number of arguments correct. I may just be using the function incorrectly.
My mini program is:
program cmdlineprog
implicit none
! program to test cmnargs@ function from Salford library
character(len=255) :: cmdline
integer :: numargs
integer :: cmnargs@
external :: cmnargs@
! get command line string
call command_line(cmdline)
! find out how many command line arguments we've got
numargs=cmnargs@(cmdline)
! write this to screen
write(*,*) 'We have: ',numargs,' command line arguments'
end
When I run the program with, say, cmdlineprog hello, the "hello" is correctly assigned to cmdline, but numargs ends up with a number far larger than 1.
Am I using the function in the wrong way?
Mark. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7942 Location: Salford, UK
|
Posted: Thu Jun 01, 2006 10:20 am Post subject: Issue with use of CMNARGS@ |
|
|
Mark
I looks like the function is simply not working!
|
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Thu Jun 01, 2006 12:16 pm Post subject: Issue with use of CMNARGS@ |
|
|
An alternative would be to use the F200x routine:
INTEGER FUNCTION COMMAND_ARGUMENT_COUNT()
Which does work as expected.
|
|
Back to top |
|
|
brucebowler Guest
|
Posted: Thu Jun 01, 2006 12:48 pm Post subject: Issue with use of CMNARGS@ |
|
|
I haven't tried your program with these changes, but have run into similar things in the past. cmnargs@ returns an integer (kind=2). The default integer is (kind=3). Try declaring numargs and cmnargs@ is (kind=2) or the more old fashioned integer*2 and see if that solves the problem. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7942 Location: Salford, UK
|
Posted: Thu Jun 01, 2006 3:20 pm Post subject: Issue with use of CMNARGS@ |
|
|
Bruce
You are right this does fix the problem. |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Fri Jun 02, 2006 2:32 am Post subject: Issue with use of CMNARGS@ |
|
|
Ah!
Thank you to all of the respondents. The help file does indeed say that the function is kind=2. My apologies for not having noticed this myself! But I am also grateful for being pointed to the COMMAND_ARGUMENT_COUNT function, which I had also missed in my reading of the help file.
Thanks again,
Mark. |
|
Back to top |
|
|
|