home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4345 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  3.6 KB

  1. Path: sparky!uunet!usc!sol.ctr.columbia.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!cf-cm!news
  2. From: spxsjm@thor.cf.ac.uk (Mr S J Morris 92)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Data initialization: FORTRAN program called as SUBROUTINE
  5. Message-ID: <24952.9211181008@thor.cf.ac.uk>
  6. Date: 18 Nov 92 10:08:20 GMT
  7. References: <1992Nov18.025912.13187@netcom.com>
  8. Sender: news@cm.cf.ac.uk (Network News System)
  9. Organization: University of Wales College at Cardiff
  10. Lines: 75
  11. X-Mailer: Cardiff Computing Maths PP Mail Open News Gateway
  12.  
  13. In article <1992Nov18.025912.13187@netcom.com> jchauvin@netcom.com (John H. Chauvin) writes:
  14. |
  15. |I am currently working on a mix language program in which a C program 
  16. |calls a large FORTRAN program ( 15,000 lines , 100+ SUBROUTINES, 
  17. |and extensive use of COMMON blocks). I have converted the main routine 
  18. |from the FORTRAN into a SUBROUTINE and am calling the routine from 
  19. |the C code. I pass file information from the C program to the FORTRAN 
  20. |program using C data structures to FORTRAN common blocks. The 
  21. |general program flow is: C calls FORTRAN , waits, FORTRAN updates C, 
  22. |FORTRAN returns to C, C calls FORTRAN ,etc.. The C and FORTRAN 
  23. |routines are linked into one large binary program. All FORTRAN variables 
  24. |required SAVE status. The main advantage to the above approach is the 
  25. |ease to which I can exchange data between the C (graphics front end) and 
  26. |the FORTRAN (number crunchier).
  27. |
  28. |Everything works great until I try and call the FORTRAN a second time. 
  29. |The variables and COMMON blocks still retain values from the first call. 
  30. |(Not surprisingly) How can I reinitialize all the COMMON blocks and 
  31. |variables to the state that existed at the beginning of the first call?  
  32. |Normally the FORTRAN would be executed as a stand alone program 
  33. |from the command line , loaded into memory and the variables initialized 
  34. |each time it is used. This is the behavior I want to achieve with each call to 
  35. |the FORTRAN. Initializing all the variables myself is out of the questions 
  36. |because of the size of the code and the fact that all the variables have 
  37. |been SAVEd. Is there a way to do this?  Any help or suggestions would be 
  38. |GREATLY appreciated.
  39. |
  40. |
  41. |Thanks
  42. |
  43. |jchauvin@netcom.com
  44. |
  45. |-------------------------- Configuration Information -------------------------------------
  46. |Workstation:           Silicon Graphics Crimson Elan with 64 mb RAM
  47. |Operating System      IRIX 4.0.5A (AT&T UNIX with Berkeley extensions)
  48. |Development Options.....v4.1
  49. |FORTRAN & C Compilers    v3.10
  50. |--------------------------------------------------------------------------------------------------
  51. |-- 
  52. |John H. Chauvin jchauvin@netcom.COM
  53. |Netcom - Online Communication Services San Jose, CA
  54.  
  55. One way you could do this would be to store the initial values in a
  56. file, which could then be read at the beginning of each iteration of the
  57. Fortran program. A flag passed from the C program could tell the Fortran
  58. program whether it ought to initialise the variables itself or look for
  59. them in the file, hence:
  60.  
  61. -----------------------C program-----------------------
  62. C First iteration
  63.          flag=0
  64.          call [Fortran program]     {pardon my C!}
  65.  
  66. -----------------------Fortran program-----------------
  67.  
  68.          if (flag.eq.0) then
  69. C Initialise variables
  70.                 .
  71.                 .
  72.                 .
  73.          write (7) .....
  74.          else
  75.          read (7) .....
  76.          endif
  77.  
  78. ---------------------C program-------------------------
  79. C Subsequent iterations
  80.          flag=1
  81.          call [Fortran prohram]
  82.  
  83. and so on...
  84.  
  85.  
  86. Steve Morris,
  87. Department of Physics, University of Wales College Cardiff.
  88.