Drawing Polygons in Fortran: How to Use Code to Create Geometric Shapes

  • Context: Fortran 
  • Thread starter Thread starter kevin86
  • Start date Start date
  • Tags Tags
    Fortran Polygons
Click For Summary

Discussion Overview

The discussion revolves around the methods and challenges of drawing polygons and rendering graphics using Fortran. Participants explore various approaches, including using external libraries, data dumping, and integrating with other programming languages for graphical output.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Some participants inquire about the specific codes needed to draw polygons in Fortran, suggesting that even a few points might suffice for basic representation.
  • There is a suggestion that Fortran lacks native rendering capabilities, and using C libraries may be necessary for graphical functions.
  • Historical perspectives are shared on how older Fortran programmers used line printers to create graphical representations based on a coordinate system.
  • Some participants propose using data dumps to external programs like gnuplot or spreadsheets for plotting, rather than relying solely on Fortran for graphics.
  • One participant mentions the possibility of using the fortranposix library to connect Fortran with gnuplot for graphing purposes.
  • A specific method is described for calling gnuplot from within a Fortran77 program to automate plotting without manual intervention.
  • There is a discussion about the limitations of older graphics technology and how modern Fortran might interface with graphics libraries.

Areas of Agreement / Disagreement

Participants express a range of views on the capabilities of Fortran regarding graphics, with some agreeing that external libraries or data dumps are necessary, while others share differing experiences and methods. No consensus is reached on a single approach or solution.

Contextual Notes

Limitations include the dependency on external libraries for rendering, the historical context of graphical capabilities in Fortran, and unresolved technical details regarding the integration of Fortran with other programming languages.

Who May Find This Useful

Individuals interested in programming with Fortran, particularly those looking to implement graphical representations or integrate Fortran with other languages for data visualization.

kevin86
Messages
20
Reaction score
0
Anyone know the codes to draw polygons in fortran. Actually a few points work too.
 
Technology news on Phys.org
u can render in fortran?
 
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
 
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 that's 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.
 
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 calculate 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:
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).
 
Jeff Reid said:
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, may 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 invovled were used to calculate 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.

Interesting.

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.
 
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,
Tim
 
You could dump out a text file of numbers and then use a spreadsheet program to import and plot the numbers.

"Graphics mode on monitors"? That's when the going was good!
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:
  • #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).
 
  • #11
Junglepeanut,

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
 
  • #12
gnuplot call from fortran

ross26 said:
Junglepeanut,

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

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:

FILEout='Out_'//TRIM(FILEDAT)//'_'//TRIM(ADJUSTL(CTEMP))
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)
 
  • #13
Jeff Reid said:
You could dump out a text file of numbers and then use a spreadsheet program to import and plot the numbers.

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...
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 17 ·
Replies
17
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K