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

In summary: You can call system() many times, just be sure to give the files different names. In my case I used a random name generator as i was looping over this procedure many times.It's not a good idea to call gnuplot once for each line you want to plot. Instead, prepare a single data file which contains all the lines, and call gnuplot once to plot them all at once. For this, use the multiplot feature of gnuplot. set terminal png set output "graf.png" set multiplot plot
  • #1
kevin86
20
0
Anyone know the codes to draw polygons in fortran. Actually a few points work too.
 
Technology news on Phys.org
  • #2
u can render in fortran?
 
  • #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
 
  • #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 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.
 
  • #5
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:
  • #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).
 
  • #7
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.
 
  • #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,
Tim
 
  • #9
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...
 

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

1. What is Fortran?

Fortran (short for Formula Translation) is a programming language commonly used for scientific and engineering applications. It was developed in the 1950s and is still widely used today.

2. How do I draw polygons using Fortran?

To draw polygons using Fortran, you will need to use a graphics library such as OpenGL or DirectX. These libraries provide functions and procedures for drawing geometric shapes, including polygons.

3. Can Fortran handle complex polygons?

Yes, Fortran can handle complex polygons with the help of graphics libraries. These libraries have functions for creating and manipulating complex shapes, such as polygons with holes or self-intersecting polygons.

4. Is it difficult to draw polygons using Fortran?

It can be challenging to draw polygons using Fortran, especially for beginners. However, with the help of graphics libraries and proper understanding of the language, it is possible to create complex and visually appealing polygons.

5. Are there any resources available for learning how to draw polygons using Fortran?

Yes, there are many resources available for learning how to draw polygons using Fortran. Online tutorials, books, and forums are great places to start. You can also refer to the documentation of the graphics library you are using for specific instructions on drawing polygons.

Similar threads

  • Programming and Computer Science
Replies
2
Views
927
  • Programming and Computer Science
Replies
8
Views
1K
Replies
13
Views
3K
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
Back
Top