
The ECN No Name Newsletter is no longer being published. This is an archived issue.
[previous article] [next article]The Sun workstations have a package called CGI (Computer Graphics Interface) that runs under suntools and is designed to work with C and FORTRAN. The SunCGI Reference Manual provides excellent documentation for the C library interfaces, but has only an appendix to explain the corresponding FORTRAN routines. The following is a commented example of a FORTRAN program with the more interesting variables explained. This program will read two points from the mouse and draw a rectangle based on these values. A complete listing of the FORTRAN procedures is listed in Appendix G of the SunCGI Reference Manual.
c program will read two points from the mouse
c and draw a rectangle out on the screen using
c CGI and FORTRAN routines.
c
c compile this using f77 file.f -lcgi77
c -lcgi -lsuntool -lsunwindow -lpixrect -lm
program test
parameter(ibignum=256)
include '/usr/include/f77/cgidefs77.h'
c parameters to cfopenvws
integer name
character screenname *(ibignum)
integer screenlen
character windowname* (ibignum)
integer windowlen
integer windowfd
integer retained
integer dd
integer cmapsize
character cmapname* (ibignum)
integer cmaplen
integer flags
character ptr* (ibignum)
integer noargs
c the returned xy values from reading the mouse
real xbot
real ybot
real xtop
real ytop
c other miscellaneous variables
integer xdummy(1), ydummy(1)
character*4 cstrg
ixt=1
iyt=1
c open cgi
c --initializes the event queue but NOT the
c input devices. No other CGI functions can
c be called if this is not called first
call cfopencgi()
c open a pixwin
c --initializes a view surface. Later references
c to this surface are made through the use of
c the identifier returned in "name."
c "dd" specifies the view surface type;
c here set to monochrome display.
dd = BWPIXWINDO
call cfopenvws(name, screenname,
$screenlen, windowname, windowlen,
$windowfd, retained, dd, cmapsize,
$cmapname, cmaplen, flags, ptr, noargs)
c go read the mouse
c --initialize the logical input device
c device class: specifies desired type of input value
c 0 specifies IC_LOCATOR which returns the
c xy position of the cursor when the trigger is
c fired (ie, the mouse button is pushed)
c device number: number of the device within
c device class
c 1 specifies printer's fist mouse pointer
c ivals: initial measure of the device
c ixt and iyt are initial x and y locations
call cfinitlid(0,1,ixt,iyt,xdummy,ydummy,
$1,ival,0,cstrg, isegid,ipickid)
c --link triggers with the specific input devices
c trigger number: 2 is the left mouse button
c trigger number: 3 is the middle mouse button
c device class: as above...0=IC_LOCATOR
c device number: as above...1=printer's fist cursor
call cfassoc(2,0,1)
call cfassoc(3,0,1)
c --initiate track (or echo) for a specific device
c
c device class: 0 = IC_LOCATOR
c device number: 1 = printer's fist cursor
c echotype: 1 = specify to display as printer's fist
c exlow,eylow,exup,eyup: specifies track
c region...not used.
c device tracks in all areas of the view surface
c x,y: initial value locations. ixy and iyt
c xlist,ylist: unknown arrays passed but not used.
c n: how many to read out of array.
c passed but not used.
c val: used to initialize tracking.
c choice: a type of redundant specification
c of IC_LOCATOR
call cftrackon(0,1,1,0,0,0,0,ixt,iyt,
$xdummy,ydummy,1,val,0,cstrg,isegid,
$ipickid)
c --request input from input device
c device class: same as above...0 = IC_LOCATOR
c device number: same...1 = printer's fist
c timeout: number of seconds it will wait for input
c valid: nonzero on successful request
call cfreqinp(0,1,60000000,ivalid,
$itrigger,ixt,iyt, xdummy,ydummy,
$1,val,0,cstrg,isegid,ipickid)
xbot = ixt/100.
ybot = iyt/100.
call cfreqinp(0,1,60000000,ivalid,
$itrigger,ixt,iyt, xdummy,ydummy,
$1,val,0,cstrg,isegid,ipickid)
xtop = ixt/100.
ytop = iyt/100.
c --define vdc_extent
call cfvdcext(-500,-500,500,500)
print *, int(xbot), int(ybot), int(xtop),
$int(ytop)
c print out our rectangle and take time to look at it
call cfrectangle(int(xbot),int(ybot),
$int(xtop),int(ytop))
call sleep(2)
c cleanup
c cfdissoc: disassociates triggers from their devices
c cfrelidev: releases all associations between a device
c and its triggers and cleans up the event queue for
c that device
c cfclosevws: closes the view surface
c cfclosecgi: closes the cgi routines and returns the
c screen to the state it was in before cfopencgi
c was called
call cfdissoc(2,0,1)
call cfdissoc(3,0,1)
call cfrelidev(0,1)
call cfclosevws(name)
call cfclosecgi()
end
CGI must first be started using cfopencgi(). CGI uses the concept of view surfaces which must be opened before they are activated. The routine cfopenvws() handles this. To get input, the input device must be initialized and associated with a trigger. This is done by calling initialize_lid and the associate functions which turn on an input device and associate it with a specific trigger.
The vdc_extent is the virtual device coordinate extent and the call to the function will define the limits of the VDC space. The range of coordinates must be between +/- 32767 and it defaults to 0 to 32767 in both the x and y directions. If a coordinate falls outside the VDC space, it will be clipped (ie, ignored). Simulations of zooming in or panning out can be obtained by changing this range and redrawing an image within the program. Tracking (cftrackon()) determines how the measure of an input device is displayed on the view surface.
It is hoped that this example will give an idea of how the FORTRAN routines parallel the C routines. Once this program is understood, it becomes easier to extend the C documentation to the FORTRAN descriptions.