Sender: Leavy (☆ ☆ ☆), letter area: fortran
Title: Visual Fortran Advanced Programming Technology
Sending station: Nanjing University Small Lily Station (Fri Jul 9 21:44:36 2004)
Visual Fortran Advanced Programming Technology
Microsof has launched a 32-bit Fortran Power Station 1.0 to the Fortran Power Station to sell it to DEC. DEC immediately launched DVF5.0 (Digital Visual Fortran 5.0), its work environment is exactly the same, and recent DEC has launched DVF6.0 (Digital Visual Fortran 6.0, its working environment is exactly the same.
Fortran's programming technology under DOS believes that I have thought that everyone is familiar. There are also many books on Fortran90, so they will not be described here. The following mainly describe the method of Fortran graphics programming with the latest DVF5.0.
1 DVF overview
2 QuickWin Application
3 Win32 Application
4 OpenGL
1 DVF overview
1. 1 installation
1) In the installation option, pay attention to the selection / Samples, which includes the rich example of DVF.
2) To copy / msdn subdirectory, here is included here. Help.
3) You can download the upgrade online.
1.2 language
1) Writing format
● Not listed, it is free to write.
● Comment is in any place! 'Start.
● Continue in the tail plus '&'.
2) Dynamic array
●
Advantages: The dimension of the dynamic array can be changed as needed during the program execution. How much memory can be dynamically assigned to the array in the program; if the array is no longer used, it can release the array , Use the internal storage of the array to use it to the system. This saves memory and improves memory usage efficiency. Dynamic population main program and subroutine.
● Statement:
? Property description statement
Allocatable
? Assign statement
Allocate (array 1 (shape description), array name 2 (shape description), ... [stat = variable name])
? Release statement
DEAALLOCATE (Dynamic Arrow Name 1, Dynamic Arrow Name 2, ... [stat = Variable Name])
● Example 1
Real (8), allocatable :: x (:), y (:), z (:)
Integer (4) :: Node
Read (*, *) Node
Allocate (x (1: node), y (1: node), z (1: node))
Do I = 1, Node
X (i) = 1.0
Y (i) = 1.0
Z (i) = i
End DO
Do I = 1, Node
Write (*, *) x (i), y (i), z (i)
End DO
Deallocate (X, Y, Z)
End
3) module
● Advantages: The module is a program unit that is independently written outside the main program unit. There is no executable statement in the module program unit, in addition to the explanation statement, up to the module process. The main role is for other program citations, ie, data sharing and copy of the module process. Contains all the features of Common and Include.
● Statement:
A module writing
Module module name
Type Description Part
[Contains]
[Module Process 1]
...
[Module Process N]
End module [Module Name]
B module reference
USE module 1, module 2, ..., module N
● Example 2:
! Module *********************************************************
Module MyDataInteger Node, NEL
End Module MyData
**************************************************
! Main program ***********************************************
Use mydata
Node = 100
Nel = 90
Write (*, *) "in main program:"
Write (*, *) "node =", Node
Write (*, *) "nel =", NEL
Call subsprogram ()
End
**************************************************
Subprint ************************************
Subroutine subprogram ()
Use mydata
Write (*, *) "in subsprogram:"
Write (*, *) "node =", Node
Write (*, *) "nel =", NEL
End subroutine
**************************************************
1.2 development environment
1) Establish a new file, new project
● "File" → "new" → "files"
file type:
a fixed format
B free format
● "File" → "new" → "projects"
project type:
A Win32 Console Application:
Command line-based program (character interface).
B Standard Graphics Application:
Single window single task drawing application, easy to learn.
C Quick Win Application
Multi-window single task drawing applications, easy to learn.
D Win32 Application
Multi-window multi-tasking applications, fixed program structure, complex difficult to learn.
2) Establish a resource file
● "INSERT" → "resource"
Resource file type:
a acceleration key
b dialog
C image
D menu
2 Quick Win Application
2.1 drawing
1) Example 3
Subroutine Plot_ju ()
USE DFLIB
Type (xycoord) POS
Open (8, file = 'user', title = 'rectangle ")
I = setbkcolor (3)
Call Clearscreen ($ GCLEARSCREEN)
I = setColorrgb (#fffff)
I = Rectangle ($ GFillInterior, 100, 100, 300, 300)
End
2) Notes:
● The DFLIB library must be included.
● The child window opens with the Open (window number, file = 'user').
● The plot program written by QuickWin cannot be referenced by Win32 Application.
2.2 menu
1) Edit menu
2) Application of menu
Example 4
Logical (4) function initialSettings ()
USE DFLIB
Logical (4) Result
External Plot_Type
Result = appendmenuqq (1, $ menuenabled, 'draw (& P)' C, Plot_Type)
INITIALSETTINGS = .true.
End function initialSettings2.3 dialog
1) Edit dialog
2) Application of dialog
Example 5
SUBROUTINE PLOT_TYPE (L)
Use dialogm
Implicit None
INCLUDE 'Resource.fd'
Logical Ret, L
TYPE (DIALOG) DLG
External Plot
Ret = dlginit (IDD_PLOT_TYPE, DLG)
RET = DLGSET (DLG, IDC_PLOT_S1, 'Graphics Type:')
RET = DLGSET (DLG, IDC_PLOT_L1, 2, DLG_NUMITEMS)
RET = DLGSET (DLG, IDC_PLOT_L1, 'Rectangle' C, 1)
RET = DLGSET (DLG, IDC_PLOT_L1, 'Circle' C, 2)
Ret = DLGSETSUB (DLG, IDOK, PLOT)
Ret = DLGMODAL (DLG)
Call Dlguninit (DLG)
Return
End subroutine
Subroutine Plot (DLG, Control_Name, CallbackType)
USE DFLOGM
INCLUDE 'Resource.fd'
TYPE (DIALOG) DLG
Integer Control_name, CallbackType, Local_CallbackType
Integer Value
Logical Ret
Local_CallbackType = CallbackType
Ret = DLGGET (DLG, IDC_Plot_L1, Value, 1)
SELECT CASE (Value)
Case (1)
Call plot_ju ()
Case (2)
Call plot_yuan ()
Case Default
End SELECT
Call Dlgexit (DLG)
End subroutine
3 Win32 Application
3.1 concept
1) Window
It is the basic operating unit of the Windows application, which is an interface environment interacting between the application and the user. It is also the basic unit of the system management application.
2) Event driver
The Windows program is designed to generate a driver running processing function around the event or message.
3) News
The Windows application exchanges information exchanged and receiving a unified format message with other applications and Windows systems.
4) Objects and handles
The Windows system identifies different instances of different objects and similar objects via handle.
3.2 Program Structure
1) WinMain function
● The WinMain function is an entry function of the application, which is functional to complete a series of definitions and initialization work and generate a message loop.
● Example 6
2) Window function
● Define the response of the application's different messages received, which is a collection of messaging branch control statements.
● Example 7
3.3 menu
Example 8
3.4 dialog
Example 9
Integer * 4 Function File_Input (Hwnd, Message, WParam, LPARAM)
Dec $ IF defined (_x86_)
! Dec $ attributes stdcall, alias: '_file_input @ 16' :: file_input
! Dec $ ELSE
! Dec $ attributes stdcall, alias: 'file_input' :: file_input
! Dec $ ENDIF
Use dfwina
Use mydata
Integer * 4 HWND, Message, WPARAM, LPARAM, H
Logical Bret
Character * 30 str
SELECT CASE (MESSAGE) CASE (WM_INITDIALOG)
Str = 'dialog instance'
H = getdlgitem (hwnd, 1201)
I = sendMessage (h, cb_addstring, 0, loc (str (1:10))))
Return
Case (WM_COMMAND)
SELECT CASE (Loword (WPARAM))
Case (IDCANCEL)
I = enddialog (hwnd, 1)
FILE_INPUT = True
Return
Case (IDOK)
I = enddialog (hwnd, 1)
FILE_INPUT = True
Return
End SELECT
End SELECT
FILE_INPUT = FALSE
Return
End
3.5 GDI drawing
Example 10
SUBROUTINE PLOT (HDC)
Use dfwina
Use mydata
Use dfwin
Integer HDC, HFONT
Logical Bret
ID_PLOT = 1
IF (Plot_Type == 1) THEN
Bret = SELECTOBJECT (HDC, HPEN (1))
Bret = ARC (HDC, 300, 200, 700, 600, 300, 200, 300, 200)
Bret = setTextColor (HDC, RGB (0,0,0))
Bret = setbkcolor (HDC, RGB (255, 255, 255)))
H = 65
LINE_W = 50
Call font (h, line_w, hfont)
Bret = SELECTOBJECT (HDC, HFONT)
Bret = Textout (HDC, 320, 400, 'GDI drawing example 1', 12)
Bret = deleteObject (HFONT)
Else
Bret = SELECTOBJECT (HDC, HPEN (2))
Bret = ARC (HDC, 300, 200, 700, 600, 300, 200, 300, 200)
Bret = setTextColor (HDC, RGB (255, 100, 0))
Bret = setbkcolor (HDC, RGB (255, 255, 255)))
H = 65
LINE_W = 50
Call font (h, line_w, hfont)
Bret = SELECTOBJECT (HDC, HFONT)
Bret = Textout (HDC, 320, 400, 'GDI drawing example 2', 12)
Bret = deleteObject (HFONT)
END IF
End subroutine
Subroutine Font (h, line_w, hfont)
Use dfwina
Integer HFont
HFONT = CreateFont (h, 0, 0, 0, line_w, 0, 0, 0, ANSI_Charset, &)
OUT_DEFAULT_PRECIS, Clip_Default_Precis, Default_quality, &
Default_pitchiff_dontcare, "large word")
End
Subroutine Pen ()
Use dfwina
Use mydata
HPEN (1) = Createpen (ps_solid, 7, rgb (255, 0))
HPEN (2) = Createpen (PS_SOLOD, 7, RGB (0,255,0))
End
3.6 Unresolved issues
● Use of toolbars.
4 three-dimensional computer graphics library OpenGL
4.1 Overview
1) Quick Win, GDI, OpenGL Comparison
Quick Win GDI OpenGL Type Flat Plane 3D
Speed slowly
Simple and complicated
2) Pay attention
● QuickWin Application and Win32 Application can draw with OpenGL.
● To connect OpenGL32.lib Glu32.lib Glaux.lib.
3) Basic steps to write OpenGL programs
Modeling → Set Perspective → Set Light → Draw Scene → Screen Window
4.2 OpenGL implementation
● Basic geometric elements.
Example 11
..............................
..............................
INTEGER RET
Call readdata ()
Call FauxinitdisplayMode (iOR (iOR (aux_single, aux_index), aux_depth))
Call FauxinitPosition (0,0,700,700)
Ret = FauxinitWindow ("Surface" C)
Call myinit ()
Call Fauxreshapefunc (Loc (Myreshape))
Call Fauxmainloop (Loc (Display))
end
************************************************************ **********************************
Subroutine Myreshape (W, H)! Recall the model, view conversion, projection transformation
Dec $ IF defined (_x86_)
! DEC $ attributes stdcall, alias: '_myreshape @ 8' :: Myreshape
! Dec $ ELSE
! DEC $ attributes stdcall, alias: 'Myreshape' :: Myreshape
! Dec $ ENDIF
Use dfopngl
Use mydata
Integer (4) W, H
Call FglviewPort (0, 0, W, H)
Call fglmatrixmode (GL_PROJECTION)
Call fglloadIndIndity ()
Callfgluperspective (BIAO_APH 10., Dble (W) / Dble (H), BIAO_S- BIAO_R * 1.01, BIAO
_S BIAO_R)
Call Fglmatrixmode (GL_MODELVIEW)
Call fglloadIndIndity ()
Call FGLTranslatef (x_eye, y_eye, z_eye)
End subroutine
************************************************************ *****************************
Subroutine myinit ()! Shaltern
Dec $ IF defined (_x86_)
! Dec $ attributes stdcall, alias: '_myinit @ 0' :: Myinit
! Dec $ ELSE
! Dec $ attributes stdcall, alias: 'Myinit' :: Myinit
! Dec $ ENDIF
Use dfopngl
Use mydata
A = 252. / 255.
B = 22. / 255.
C = 16. / 255.
Call FauxSetoneColor (30, A, B, C)
.......................
Call FauxsetoneColor (59, A, B, C)
Call FglclearIndex (Real (29))
Call Fglshademodel (GL_SMOOTH)
Call fgldepthfunc (gl_lequal) Call Fglenable (GL_DEPTH_TEST)
Call FGLDISABLE (GL_DITHER)
End subroutine
************************************************************ ***********************************
SUBROUTINE DISPLAY ()
Dec $ IF defined (_x86_)
! Dec $ attributes stdcall, alias: '_display @ 0' :: Display
! Dec $ ELSE
! Dec $ Attributes Stdcall, Alias: 'Display' :: DISPLAY
! Dec $ ENDIF
Use dfopngl
Use mydata
External DrawMyObjects
Call Fglclear (GL_COLOR_BUFFER_bit)! Clear buffers in the view area
Call Fglclear (GL_DEPTH_BUFFER_BIT)
Call Fglrotatef (-55, 1.0, 0.0, 0.0)
Call Fglrotatef (-45, 0.0, 0.0, 1.0)
Call DrawmyObjects ()
Call fough ()
End subroutine
************************************************************ **********************************
Subroutine DrawmyObjects ()
Use dfopngl
Use mydata
Do I = 1, Node
Call Fglbegin (GL_POLYGON)
Call Fglindexi (59- (Z_Node (1, I) 400) / 30.-2)
Call Fglvertex3f (X_Node (1, I), Y_Node (1, I), Z_Node (1, I))
Call Fglindexi (59- (Z_Node (2, I) 400) / 30.-2)
Call Fglvertex3f (X_Node (2, I), Y_Node (2, I), Z_Node (2, I))
Call Fglindexi (59- (Z_Node (3, I) 400) / 30.-2)
Call Fglvertex3f (X_Node (3, I), Y_Node (3, I), Z_Node (3, I))
Call Fglindexi (59- (z_Node (4, I) 400) / 30.-2)
Call Fglvertex3f (X_Node (4, I), Y_Node (4, I), Z_Node (4, I))
Call fough ()
End DO
End subroutine
● Material, light processing.
Example 12
.........................
.........................
Real (4) :: ambient (4)
Real (4) :: Diffuse (4)
Real (4) :: Position (4)
Real (4) :: Mat_Ambient1 (4)
REAL (4) :: Mat_Diffuse1 (4)
Real (4) :: Spot_Dir (3)
Data ambient / 0.0, 0.0, 0.0, 1.0 /
Data Diffuse / 1.0,1.0,1.0,1.0 /
Data position / -30., 30.0, 30., 1.0 /
Data Mat_Ambient1 / 0.0, 0.5, 1.0, 1.0 /
Data mat_diffuse1/0.0, 0.5, 1.0, 1.0 /
Data Spot_Dir / 1.0, -1.0, -1.0 /
Call Fglenable (GL_Depth_test)
Call FGLDepthfunc (GL_SS)
Call Fgllightfv (GL_Light0, GL_AMBIENT, LOC (Ambient) Call FgllightFv (GL_LIGHT0, GL_DIFFUSE, LOC (DIFFUSE))
Call Fgllightfv (GL_Light0, GL_Position, LOC (Position))
Call Fgllightf (GL_Light0, GL_Spot_cutoff, Aphadd)
Call Fgllightf (GL_LIGHT0, GL_SPOT_DIRECTION, LOC (Spot_Dir))
Call Fglenable (GL_Lighting)
Call Fglenable (GL_LIGHT0)
Call Fglmaterialfv (GL_FRONT, GL_AMBIENT, LOC (MAT_AMBIENT1))
Call Fglmaterialfv (GL_FRONT, GL_DIFFUSE, LOC (MAT_DIFFUSE1))
.......................... ...
.......................
● Mixed, dried away.
● Texture.
........................................
........................................
Call Fglteximage2D (GL_Texture_2D, 0, 3, 4, 4, &
0, GL_RGB, GL_UNSIGNED_BYTE, LOC (CHE))
Call Fgltexparameterf (GL_Texture_2D, GL_Texture_Wrap_s, GL_Repeat)
Call Fgltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
Call Fgltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
Call Fgltexparameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
Call Fgltexenvf (GL_TEYTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
Call Fglenable (GL_TEXTURE_2D)
.............................. .. ..
.............................. .. ..
Call FgltexcoRoR2F (0.0, 0.0); Call Fglvertex2f (-2.0, -1.0)
Call FgltexcoRD2F (0.0, 2.); Call Fglvertex2f (-2.0, 1.0)
Call FgltexcoRD2F (2., 2.); Call Fglvertex2f (0.0, 1.0)
Call fgltexcoord2f (2., 0.0); Call Fglvertex2f (0.0, -1.0)
.............................. .. ..
................................
● Select and feedback.
4.3 Unresolved issues
● Graphical printing.
● Write Chinese characters.
- http://www.cnvf.com/fortran/communion/com_dvf_graphic.htm
-
※ Source:. Nanjing University small lily station bbs.nju.edu.cn. [From: 172.16.66.171]