How do you call FORTRAN subroutines? 
Author Message
 How do you call FORTRAN subroutines?

 A friend needs to write an assembler program that will call a fortran sub-
routine to do search and replace functions.  I need to know the assembly
code to call the subroutine.  I've included the subroutine to be called
below.  Please send your replies/comments to:

post them to this group.

Thanks, Steve

 ********** FORTRAN program follows ******************

 The main program written in FORTRAN establishes three independent text buffers
referred to as SRCBUF, SEARCH, and REPLACE.  All three buffers contain valid
ASCII codes (values of 0 - 80H).  The SERBUF represents a source text buffer
which is to be searched for the presence of words (or other alphanumerical
patterns) as specified by the contents of the SEARCH buffer.  All of the
occurrences of the specified text are to be replaced by the contents of the
REPLAC buffer, which, in general, will contain text string of different
length that the one specified by SEARCH.

 The actual length of the SRCBUF is indicated by the LENSRC variable, but will
never exceed 1024 characters.  Similarly, the length of SEARCH string is
described by LENSEA, and the length of REPLAC is described by LENREP
(both LENSEA and LENREP are guaranteed never to exceed 32).  All variables
have been allocated by the FORTRAN program, and have been given the following

                SRCBUF  string, 1024 characters
                SEARCH  string, 32 characters
                REPLACE string, 32 characters
                LENSRC  signed integer, 16-bit
                LENSEA  signed integer, 16-bit
                LENREP  signed integer, 16-bit
The main program written in FORTRAN issues a call to the SUBST subroutine,
passing total of six parameters in the following order:


******* The goal is to:****************
Write a SUBST subroutine to performe a "search and replace" operation on the
text contained in SRCBUF using the contents of SEARCH as a pattern to be search
for and the contents of REPLACE as a replacement string to be substitude for
each confirmed presence of the pattern of interest.  Assume that regardless of
the lengths of SEARCH and REPLACE, the total length of the string in SRCBUF
will never exceed 1024 characters (i.e. the buffer will never overflow).

 In addition, assume that the replacements are not to be nested (i.e.  if
the REPLACE buffer incidentally contains the origially searched for text,
no further substitutions are needed).


        CHARACTER*1024  SRCBUF
        CHARACTER*1     ALPHA(61),CHAR

        data    ALPHA/'A','B','C','D','E','F',' ',
     $                'G','H','I','J','K','L',' ',
     $                'M','N','O','P','Q','R',' ',
     $                'S','T','U','V','W','X',' ',
     $                'Y','Z','a','b','c','d',' ',
     $                'e','f','g','h','i','j',' ',
     $                'k','l','m','n','o','p',' ',
     $                'q','r','s','t','u','v',' ',
     $                'w','x','y','z',' '/

        read(0,2000) SEARCH
        read(0,2000) REPLACE

        call gettim(ihr,imin,isec,i100th)
        call seed(isec*100+i100th)
        call random(RNUM)

        LENSRC=256+RNUM*768                     !Set LENSRC to a random > 256
        LENSEA=len_trim(SEARCH)                 !Find lenght of SEARCH
        LENREP=len_trim(REPLACE)                !Find lenght of REPLACE

        do 100 i=1,LENSRC
          call random(RNUM)
          SRCBUF(i:i)=CHAR                      !Fill SRCBUF with random text
100     continue



        do 200 i=1,NZONES
          IZNBEG=ifix((i-1)*ZONE)+1             !Find start of the next zone
          IZNEND=IZNBEG+ifix(ZONE)              ! ... and the end of it
          ISLACK=ifix(ZONE)-LENSEA              ! ... and the slack

          call random(RNUM)
          PATPOS=RNUM*ISLACK+IZNBEG             !Randomize SEARCH insertion
          write(0,1015) PATPOS

          do 200 j=1,LENSEA
200     continue


        do 300 j=1,NLINES
          write(0,1040) (SRCBUF((64*(j-1)+i):(64*(j-1)+i)),i=1,64)
300     continue


        do 400 j=1,NLINES
          write(0,1040) (SRCBUF((64*(j-1)+i):(64*(j-1)+i)),i=1,64)
400     continue


1000    format(1h ,//////'  Please enter the SEARCH: ',$)
1005    format(1h ,' Please enter the REPLACE: ',$)
1010    format(1h ,/'  SEARCH strings placed at: ',$)
1015    format(i4,$)
1030    format(1h ,/)
1040    format(' ----> ',64A1)
1070    format(//' ====> Original Text Buffer:')
1080    format(/' ====> Modified Text Buffer:')
2000    format(A32)


************* End of FORTRAN program *********************
| Steve Harkins, gearhead | These are my opinions | Owns a '66 Corvair AND  |
| Dallas, TX USA          | and not those of      | a 207,000 mile '76 Vega!|

| "If you don't think too good, don't think too much." - Ted Williams       |

Mon, 05 May 1997 06:05:48 GMT  
 How do you call FORTRAN subroutines?


> A friend needs to write an assembler program that will call a FORTRAN sub-
>routine to do search and replace functions.  I need to know the assembly
>code to call the subroutine.  I've included the subroutine to be called
>below.  Please send your replies/comments to:

You don't say what compiler. If Microsoft Fortran, look in the
mixed language programming manual - it is all documented in there.

Wed, 07 May 1997 09:00:35 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Help: how to call a c subroutine in a fortran program

2. Fortran subroutine interfacing with MS-C call

3. Calling IMSL Subroutines in Digital Visual Fortran

4. C call, in a Fortran subroutine, within a C main program

5. Fortran subroutine interface with MS-C call

6. Calling Fortran Functions/Subroutines From MSVC++ programs

7. calling ANSYS as a Fortran subroutine

8. call fortran subroutines from C++

9. Call FORTRAN subroutine from VC++

10. Q: Calling Fortran SUBROUTINE from C

11. HELP: call FORTRAN subroutines from C?

12. MS FORTRAN subroutines for calling/connecting the mouse


Powered by phpBB® Forum Software