Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!hao!ames!ucbcad!ucbvax!SDAG.CS.UMD.EDU!ogud From: ogud@SDAG.CS.UMD.EDU (Olafur Gudmundsson) Newsgroups: comp.os.vms Subject: Re: Language question Message-ID: <8705221905.AA01082@sdag.cs.umd.edu> Date: Fri, 22-May-87 15:05:36 EDT Article-I.D.: sdag.8705221905.AA01082 Posted: Fri May 22 15:05:36 1987 Date-Received: Sat, 23-May-87 18:49:37 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 41 >I have a question concerning a problem that Fortran does not handle well. >I would like to write a subroutine that gets as arguments the following: > > (1) An array > (2) The type of array (byte, integer*2, integer*4, real*4, etc.) > >In the subroutine I want to write to a file (or otherwise manipulate) data >from the passed array. Fortran has an obvious problem with data typing. > The simple solution to your problem is to use equivalence statements this way there is no overhead because of copying. The only overhead is that you will have to use IF statments to pick the right data to work with Example : subroutine foo( arr, typ) int arr( *) , typ real r4( 1) integer*2 i2(1) byte c1(1) eqivalence (arr(1), r4(1) , i2(1) , c1(1)) c and in the subroutine you do if( typ.eq. INT) then else if( typ .eq. REA4) then ... endif and so on ---------------------------------------------------------------------------- Spelling mistakes make life more colorful ____________________________________________________________________________ Olafur Gudmundsson Dept. of Computer Science University of Maryland ARPA: ogud@sdag.cs.umd.edu UUCP: {...}!seismo!mimsy!sdag!ogud Tel: (301)-454-6153 (w) UPS: College Park MD. 20742 ATT: (301)-595-4154 (h)