From:	SMTP%"carl@gergo.tamu.edu" 13-JAN-1995 10:46:21.98
To:	EVERHART
CC:	
Subj:	Re: AXP FORTRAN argument list (variable)

From: carl@gergo.tamu.edu (Carl Perkins)
X-Newsgroups: comp.os.vms
Subject: Re: AXP FORTRAN argument list (variable)
Date: 13 Jan 1995 05:29 CST
Organization: Geochemical and Environmental Research Group - TAMU
Lines: 109
Distribution: world
Message-ID: <13JAN199505292627@gergo.tamu.edu>
NNTP-Posting-Host: gergo.tamu.edu
News-Software: VAX/VMS VNEWS 1.41    
To: Info-VAX@Mvb.Saic.Com
X-Gateway-Source-Info: USENET

system@bolam5.lamel.bo.cnr.it (Maurizio Impronta) writes...
}Maybe there is some misunderstanding in my question.
}I have appreciated greatly the IARGCOUNT and IARGPTR routines, but
}actually I have on VAX hundreds of routines with code like (simplified):
}	PROGRAM MAIN
}	....
}	CALL SUB(a1,,c1)
}	...
}	SUBROUTINE SUB(a,b,c,d)		! **really DUMMY** arguments
}	INTEGER LSTARG			! my MACRO routine
}	IF (LSTARG(2).GT.0) THEN	! returns address of 2nd arg i.e.
}		b2=b			! if 2nd argument is passed
}	ELSE
}		b2=b_default		! default value if NOT passed
}	ENDIF
}	....
}LSTARG(nvar) is my VAX MACRO integer function which:
}1_ goes backward in the call chain to read SUB argument list
}2_ returns the address of nvar-th argument if passed by the calling
}   procedure (MAIN i.e.), or
}3_ returns 0 if nvar-th argument is defaulted (i.e. 'b' or 'd')
} 
}Maurizio Impronta

Why exactly did you ever bother with that MACRO routine?  It is not needed!

Instead, in a couple of places I have used things like what follows.
From a routine that does this:

       subroutine cp_open(in_lun,in_filename_struct,in_def_ext_struct,in_new
     &                    ,in_unformatted,in_readonly,in_prompt_struct)
       ...
c Use:
c     call cp_open(lun,[filename],[default_extender],[new],[unformatted],
c    &             [readonly],[prompt])
c
c Defaults on input and applied to open statement:
c            lun = <none>
c       filename = name of image being run
c        def_ext = 'dat'
c            new = .false.
c    unformatted = .false.
c       readonly = .false.
c         prompt = 'Enter filename: '
       ...
       character*10 def_ext
       ...
       logical in_new, in_unformatted, in_readonly
       logical new, unformatted, readonly ,retryflag, bad_filename_flag
       ...
       structure /descriptor/
         integer*2 len
         byte ctype
     &       ,sclass
         integer*4 address
       end structure !descriptor
       ...
       record /descriptor/ in_filename_struct
     &                    ,in_def_ext_struct
     &                    ,in_prompt_struct

Which is uses the sort of thing you were trying to do with your MACRO routine.

How I did the same thing, no macro needed:

The non-character variables are done like this (example for new, via the
parameter in_new):

       if (%loc(in_new) .eq. 0) then
         new=.false.
       else
         new=in_new
       end if

The character variables need a subroutine to rebuild them properly if passed,
but other than that are essentially the same (example for def_ext via the
parameter in_def_ext_struct):

       if (%loc(in_def_ext_struct) .eq. 0) then !it was omitted, set up default
         def_ext='dat'
       else !it was present
         call cp_rebuild_char(in_def_ext_struct,def_ext)
       end if

And the cp_rebuild_char() routine is:
       subroutine cp_rebuild_char(var,outvar)
c
c Function to rebuild a character variable from a descriptor.
c The argument in the function reference should be a record describing the
c descriptor (word-length, 2 bytes-type&class, longword-address).
c
c This is, as you can see, exceedingly easy to do.
c
       character*(*) var,outvar

       outvar=var

       return
       end

Then the subroutine goes on to use new and def_ext with either the default
data (if omitted from the argument list in the calling of the routine)
or the data passed.

I would be surprised if this method did not also work with DEC FORTRAN on an
AXP, presumably using 64 bits for the address part of the descriptor structure
instead of only 32 if/when needed.

--- Carl Perkins
