Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!rex!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.fortran Subject: Keyword and optional argments (was Fortran vs C) Message-ID: Date: 30 Nov 90 04:06:37 GMT References: <1990Nov24.002836.19739@ariel.unm.edu> <1270009@hpcllmv.HP.COM> <771@sarnoff.sarnoff.com> <11977@milton.u.washington.edu> Sender: news@skipper.dfrf.nasa.gov Organization: NASA Dryden, Edwards, Cal. Lines: 64 In-reply-to: whit@milton.u.washington.edu's message of 30 Nov 90 02:21:55 GMT On 30 Nov 90 02:21:55 GMT, whit@milton.u.washington.edu (John Whitmore) said: John> Finally, a topic I can really get behind! Most languages have John> some constructs that allow optional arguments: John> OPEN(UNIT= the_unit, FILE='FileName',FORM='UNFORMATTED) John> is a Fortran example. Yet, this sort of 'keyword=value' calling John> sequence is not supported for user subroutines. The language implementors John> needed it; SO DO THE USERS. John> CALL READ_THE_FILE( file='FileName', John> & format='Bruce''s third generation data set', John> & into= data_array(5) ) I 100% agree. And I note that this is incorporated in Fortran 90 modules, one of my favorite Fortran 90 features. The statement above is a perfectly legal Fortran 90 statement (well, except that you'd probably be using free source form, which does continuation lines differently). The subroutine interface might be something like. module file_stuff use precision contains subroutine read_the_file(file,format,some_other_argument,into) character, intent(in) :: file*(*) character, intent(in), optional :: format*(*) integer, intent(in), optional :: some_other_argument real(r_kind), intent(out) :: into ........ end subroutine read_the_file end module file_stuff where for no relevant reason, except that I like it, I've also choosen to illustrate the usage of the KIND parameter. The r_kind parameter above might be defined in module precision integer, parameter :: r_kind = selected_real_kind(12,30) ...... end module precision Selected_real_kind is a Fortran 90 intrinsic that gives the "kind" of the smallest (loosely speaking) real type with precision of at least 12 decimal digits and range of at least 10**-30 to 10**+30. Thus the into variable is double precision (to use old style Fortran terms) on my Sun or other 32-bit systems, but single precision on the Cybers or Crays; no source code changes required. I think I've got all the above correct, though I'm still a bit short on compilers to test my Fortran 90 code on. (Waiting anxiously for you Keith. Either a Sun3 or Sparc version will do fine. :-)) -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.64.6]