Re: XForms: Date: Thu, 30 Nov 2000 14:19:51 -0800

From: Danny G. Holstein (danny@holstein.tritonetd.com)
Date: Fri Dec 01 2000 - 10:41:15 EST

  • Next message: Jan Menzel: "XForms: strange behavior with popups"

    # To subscribers of the xforms list from "Danny G. Holstein" <danny@holstein.tritonetd.com> :

    On 01-Dec-00 Steve Lamont wrote:
    ># To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
    >
    >> I have some very old (but useful) FORTRAN code (mid 60's)! I've been
    >> working with it on two fronts : 1) f2c-ing the fortran code, and 2)
    >> developing front-ends using xforms. I've been successful on both
    >> fronts, independently, but I can't merge the two (2-mains I believe). I
    >> read Bob's comment suggesting the use of a "c" wrapper, but I don't have
    >> a clue what a wrapper is. Can someone help me.
    >
    > There are several ways of going about the task, depending upon what
    > your needs are.
    >
    > If all you need to do is basically call the FORTRAN program from a C
    > program, this might be pretty easy. Just change your FORTRAN main to
    > a subroutine or function, link the two in the standard manner, and
    > call it from the C program.
    >
    I've used this approach and it works well, I recommend against F2C since much
    of the transparency of the FORTRAN code disappears, especially when working with
    COMPLEX arithmatic. When will c incorporate COMPLEX as an intrinsic? (and I
    know I can define that data type myself, I think a division should look like
    cnum/cdenom, not cdiv(cnum, cdenum))

    Another approach is to use file I/O and "system()" calls. Write your c wrapper
    to generate a namelist or flat input file and call the FORTRAN code to process
    it. You can have the c wrapper code read the output files and plot it as well.
    With this approach, you don't need to delve into the FORTRAN source code.

    A neat trick I figured out is you can have a single character variable define
    a complete file with carriage returns and format definitions, let me illustrate:

    char *file_tail1 = "\n\
     $nlinp\n\
     $end\n\
     \n\
     $nlout\n\
     loout(1, 0) = %s,\n\
     inout(1, 5) = 1,\n\
     reout(1, 6) = %.4f,\n\
     reout(1, 7) = %.2f,\n\
     $end\n";
     
    I've used this approach with input files of hundreds of lines and you can print
    with:

    if (fl_get_button(fd_control->output_match) == PUSHED) {
      fprintf(out_file, file_tail1,
              ".true.",
              atof(fl_get_input(fd_control->gamma)),
              atof(fl_get_input(fd_control->angle)));}

    It works beautifully!

       ...Dan
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Fri Dec 01 2000 - 10:50:24 EST