[comp.os.vms] Language question conclusion

STEINBERGER@KL.SRI.COM (Richard Steinberger) (05/26/87)

Several people responded to my query about using Fortran (or another HLL)
to make a runtime decision on who to appropriatly use an array of a specified
data type.  Specifically I wanted to have a subroutine receive an array and
its data type.  The subroutine would then correctly write the array data to
a file (or otherwise use it).  I didn't want to copy the array data to a 
local array, use common statements, and, as some people found out, 
equivalencing a passed array to local arrays doesn't work.  The pseudo-code
below represents what I consider the best Fortran approach, although it was
pointed out that C allows run-time casting of data types.

    Call sub1(array,array_type)            !Main or calling program
    integer, real or whatever array(size)  !original storage allocation
    .
    .
    end

    subroutine sub1(array,array_type)  !"intermediate subroutine"
    integer array(*)                   !any type is OK here
    call sub2(array,array,array,array,...,array_type)
    return
    end

    subroutine sub2(b_array,i2_array,i4_array,r4_array,....,array_type)
    byte b_array(*)
    integer*2 i2_array(*)
    integer*4 i4_array(*)
    .
    .
    if(array_type .eq. 'byte')then
      use b_array
    elseif (array_type .eq. 'i2')then
      use i2_array
    .
    .
    .
    endif
    return
    end

Note that no copying was necessary, only arrays (and not structures) were
necessary, and only one intermediate routine was necessary.
Thanks to everyone for their suggestions.

-Ric Steinberger
steinberger@kl.sri.com

-------