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 

Odd GET_COMMAND_ARGUMENT behavior

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



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Sun Nov 09, 2014 4:55 am    Post subject: Odd GET_COMMAND_ARGUMENT behavior Reply with quote

I needed access to more than just the program name.

I first call CMPROGNM@ to get the executable name.

I then executed the following sequence, but it didn't pick up the second command line argument

if(cmnargs@() .ge. 1) then
! --- we have a copmmand line argument. Assume it is the COALCNFG.DAT pathname
call get_command_argument(1,CONFIG,l,istat)
print *,"L,istat=",l,istat
print *,"New coalcnfg.dat file is: ",trim(CONFIG)
endif

This yields a length of zero (L=0) and a status (ISTAT = 1 [error])

However, if I add the same call, but attempt to pick up the command name first, this call yields the L=0 and ISTAT=1, but the second yields L=20 (proper length), ISTAT=0 (success), and properly returns the second command line argument.
if(cmnargs@() .ge. 1) then
! --- we have a copmmand line argument. Assume it is the COALCNFG.DAT pathname
call get_command_argument(0,CONFIG,l,istat)
print *,"L,istat=",l,istat
call get_command_argument(1,CONFIG,l,istat)
print *,"L,istat=",l,istat
print *,"New coalcnfg.dat file is: ",trim(CONFIG)
endif

This makes no sense to me, but there has to be a reason!
Bill
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sun Nov 09, 2014 7:10 am    Post subject: Reply with quote

What does Get_Command return ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sun Nov 09, 2014 10:05 am    Post subject: Reply with quote

I do not have the source code for the FTN95 library to hand so I don't have a direct answer.

There is a mix of old (FTN77) and new (Fortran 2003) routines here. So maybe this is the cause. Command_argument_count is the 2003 routine to use with get_command_argument.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sun Nov 09, 2014 12:49 pm    Post subject: Reply with quote

There are some idiosyncracies in the command line argument routines, probably as Paul says because this particular wheel has been reinvented several times. In Fortran 77 the routines are extensions, and in a later version of Fortran they are standard-defined routines.

In one program of mine, I tested for whether the program was being launched from the Start menu (or clicking on its icon on the desktop) vs by clicking on a filename and the program being launched from its association, by counting the command line arguments:

Code:
      INVOKED = CMNARGS@()


Then, if INVOKED told me that there was something on the command line other than the program name, I went looking for the filename with the following inelegant loop:

Code:
       IF (INVOKED .GE. 1) THEN
           FILEN  = CMNAM()
           FILENM = FILEN(2:257)
           DO 10 I=1,256
           IF (FILENM(I:I) .EQ. '"') FILENM(I:I)=' '
 10        CONTINUE
           ENDIF


For reasons that escape me now, I had to throw away the first character returned by CMNAM, and rid what was left of double quote marks!

On reflection I probably used a routine that made life harder than it needed to be to get the first argument from the command line after the program name. This program is SDI not MDI so only needs to capture the first filename.

Eddie
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Sep 26, 2015 3:30 pm    Post subject: Reply with quote

Can anyone modify this demo to work? That damn thing with command line arguments harassed me for a long time so i stopped using it. But started today and the same story - demo does not work, the larger code sometimes does work sometimes doesn't. May be new Fortran function will give better stability
Code:

include <clearwin.ins>
integer cmnargs@

n_ofArguments_inCommand_line = cmnargs@()
print*, 'n_argComm_line=', n_ofArguments_inCommand_line
end


Last edited by DanRRight on Sat Sep 26, 2015 5:02 pm; edited 2 times in total
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Sep 26, 2015 3:40 pm    Post subject: Reply with quote

Because, Dan, you aren't printing out the number you got from the function!

Not:

Code:
   n_ofArguments_inCommand_line = cmnargs@()
   print*, 'n_argComm_line=', n_argComm_line
   end


But

Code:
   n_ofArguments_inCommand_line = cmnargs@()
   print*, 'n_argComm_line=', n_ofArguments_inCommand_line
   end


Eddie
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Sep 26, 2015 3:43 pm    Post subject: Reply with quote

I know, that was quick typo, sorry, i changed that almost immediately while you were typing, but change did not cam through due to server error. Changed again. It still does not work. Does it work in your case?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Sat Sep 26, 2015 6:23 pm    Post subject: Reply with quote

From the FTN95 help file :

Quote:
When calling CMNARGS@ you must declare it as INTEGER(KIND=2).
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Sep 26, 2015 6:26 pm    Post subject: Reply with quote

Thanks mecej4. Damid, is this Integer*2 again?
Why the hell this was designed as integer*2?
Integer*2 must be pesticided out of this compiler's library
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Sep 26, 2015 6:46 pm    Post subject: Reply with quote

If you don't like the INTEGER*2 version, there's always the more futureproof COMMAND_ARGUMENT_COUNT

There's a whole section in FTN95.CHM on command lines.

I see that in the F2003 intrinsic

GET_COMMAND_ARGUMENT(NUMBER, VALUE, LENGTH, STATUS)

that VALUE is optional. Perhaps there's an expert out there who will explain to me what the point is of:

CALL GET_COMMAND_ARGUMENT(1)

(i.e. opting not to provide a variable for VALUE) or from experience what happens if NUMBER is greater than the value returned by COMMAND_ARGUMENT_COUNT


Eddie
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sun Sep 27, 2015 10:35 am    Post subject: Reply with quote

How anyone will like how this functionality was done if you use integer*2 only for this purpose and never again? Of course there is no reason for that and so you do not expect such counteruntuitive requirement. Result is an error. And hell knows why the FTN95-specific function also has to be in declarations, can't developers declare them themselves?

I wrote many times here my request to kill integer*2 out of library, I lost disproportional amount if time debugging that making errors every time I try to use such functions again. Every single time I am on the hook with integer*2, I always think that adding such functions will take a minute or two but in reality lose a day and even ask help here. I even found one old program where I tried many times and gave up.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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