forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Issue with use of CMNARGS@

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Thu Jun 01, 2006 9:37 am    Post subject: Issue with use of CMNARGS@ Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7925
Location: Salford, UK

PostPosted: Thu Jun 01, 2006 10:20 am    Post subject: Issue with use of CMNARGS@ Reply with quote

Mark

I looks like the function is simply not working!

Back to top
View user's profile Send private message AIM Address
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Thu Jun 01, 2006 12:16 pm    Post subject: Issue with use of CMNARGS@ Reply with quote

An alternative would be to use the F200x routine:

INTEGER FUNCTION COMMAND_ARGUMENT_COUNT()

Which does work as expected.

Back to top
View user's profile Send private message
brucebowler
Guest





PostPosted: Thu Jun 01, 2006 12:48 pm    Post subject: Issue with use of CMNARGS@ Reply with quote

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: 7925
Location: Salford, UK

PostPosted: Thu Jun 01, 2006 3:20 pm    Post subject: Issue with use of CMNARGS@ Reply with quote

Bruce

You are right this does fix the problem.
Back to top
View user's profile Send private message AIM Address
Anonymous
Guest





PostPosted: Fri Jun 02, 2006 2:32 am    Post subject: Issue with use of CMNARGS@ Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group