Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Draw polygons using fortran

  1. Aug 31, 2006 #1
    Anyone know the codes to draw polygons in fortran. Actually a few points work too.
  2. jcsd
  3. Aug 31, 2006 #2
    u can render in fortran?
  4. Aug 31, 2006 #3
    i am thinking of just a few points should do it, not lines necessary, just the code to setup a coordinate system is good enough, the codes for display and print etc etc
  5. Aug 31, 2006 #4
    yeah, as far as I know, you can't do that. Its possible you that there's a c library you could use from a fortran program, but thats the only way i can think of doing it. I haven't done that enough times (used c libraries with fortran codes) to really be able to help more than that.
  6. Aug 31, 2006 #5


    User Avatar
    Homework Helper

    Before the days of graphic interfaces, us old Fortran programmers would print graphs on line printers. We would create a coordinate system based on the points of a printer, 10 characters per inch horizontal, 6 lines per inch vertical. Horizontal was limited to 120 or 132 characters, but vertical was unlimited (OK, limited to one box of paper). Then using a matrix to represent the paper, we would fill in the "dots", and then print it out. To save memory, a single horizontal vector could be used, and what ever functions involved were used to cacluate the "dots" for that rows worth of vertical displacement.

    I would assume that modern day Fortran programs with access to graphics mode on monitors would have a draw line function, as they did back in the days of plotters.
    Last edited: Sep 1, 2006
  7. Aug 31, 2006 #6
    last I knew(3 years ago) fortran didn't have rendering capabilities...like franz said you had to port to C(or just dump a data file into C or excel or matlab).
  8. Aug 31, 2006 #7

    I know you can mix languages through libraries, so I believe that hypothetically you can use C libraries called from fortran to do any rendering you like, but I've never heard of anyone using that capability actually for rendering. Usually some sort of data dump (HDF is common) is used, that is then rendered using something else. The only time I've ever even called C routines in fortran was using code that I didn't even write, so I'm really not familiar with it, any limitations or problems that might arise.
  9. Sep 1, 2006 #8
    I think franznietzsche is on the right track: dump your data and either use a canned graphics package, or use C/C++ if you want to reinvent the wheel.

    OpenGL if you're a wheel-reinventing glutton for punishment.

    I avoid going as low-level as OpenGL by using VTK. You can use VTK via C++, or Python if you prefer a more civilized approach to life.

    Fortran is one tool. Trying to solve every problem using just one tool is a trap.

    "Graphics mode on monitors"? That's when the going was good! Now you have multiple levels of hardware and software between you and the monitor.

    Good luck,
  10. Sep 1, 2006 #9


    User Avatar
    Homework Helper

    You could dump out a text file of numbers and then use a spreadsheet program to import and plot the numbers.

    The last graphics monitors I'm aware of were used in arcade games. These could only draw straight lines, and were called vector monitors. In Battlezone, you drove in a tank and all objects were 3-d wire frames.

    Unlike plotters, some of the graphic monitors had the ability to draw arcs, but I don't remember the interface. Plotters were really slow at drawing curves, since you had to break them up into a series of small lines.

    Most, if not all, older computers (mainframes) with plotters included a Fortran callable library for using the plotters. The choiced for languages in those days was assembly (with various levels of macro capability), Cobol, Fortran, and later, RPG (report generator, an associative language similar to the punched card / line printer processors that you programmed via a matrix board and wires).

    I would assume that Microsoft's Fortran can do some Windows graphics, either directly or through a C library interface.
    Last edited: Sep 1, 2006
  11. Sep 24, 2006 #10
    You could download the fortranposix (I think that is the name) library for fortan and it would be connected to gnuplot for graphing. Or you could do like I do:

    Write a short script that runs your fortran which makes a data dump, then calls gnuplot to produce pdfs of your results (could be set for screen just as well).
  12. Nov 6, 2007 #11

    I've been trying to figure our how to call gnuplot from inside my Fortran77 program to save manually opening the dump file and choosing all the plotting parameters each time i want to view the program output. Any idea if / how I can do this?!

    novice Ross
  13. Nov 22, 2007 #12
    gnuplot call from fortran

    I just came across the same problem in plotting data produced by my FNCK0 in MINUIT (old f77 program but still very very useful).
    I solved it by using :

    command = "gnuplot gnucomm"
    call system(command)

    the (previously declared) string 'command' is executed by the shell.
    Gnucomm is the file with the plot command (or anything else) to be executed by GNUPLOT
    in my case that file is written within Fortran since my output file may change its name following my input parameters:

    OPEN (UNIT=8, FILE= "gnucomm", STATUS= 'UNKNOWN')
    WRITE(8,*) "plot '"//TRIM(FILEout)//"','"//TRIM(FILEout)//"'
    & us 1:3 w l ,'"//TRIM(FILEout)//"' us 1:4 w i"
    CLOSE (UNIT=8)

    This worked nice on my MacBook with gfortran
    gfortran -v
    Using built-in specs.
    Target: i386-apple-darwin8.10.1
    Configured with: ../gcc-4.3-20070810/configure --enable-threads=posix --enable-languages=fortran
    Thread model: posix
    gcc version 4.3.0 20070810 (experimental)
  14. Nov 22, 2007 #13
    Or I guess if you want to get fancy you could try dumping a text file full of SVG. But feeding through a spreadsheet program (or gnuplot as Ulderico suggests) would probably be simpler...
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook