home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / spredsht / prof2d.arc / TUTORIAL.PR2 < prev   
Encoding:
Text File  |  1990-01-03  |  11.6 KB  |  377 lines

  1. : Prof2d, The 2D Scientific Spreadsheet                IBM-PC Version
  2. : by Gertjan L. Ouwerling, Electrical Materials Lab, Delft University
  3. : -------------------------------------------------------------------
  4. : Execute this tutorial by typing:  prof2d tutorial.pr2 <enter>
  5. :
  6. : NOTE: some steps may be slow without a co-processor!
  7. :       Graphical pictures are terminated by giving <enter>
  8. : -------------------------------------------------------------------
  9. :
  10. : In this tutorial the following subjects are treated:
  11. :
  12. : 1. Prof2d on the IBM-PC (and its video adaptor card)
  13. : 2. Prof2d data structures (variables and data types)
  14. : 3. Internal generation of data and making graphs
  15. : 4. Reading and writing data from and to file
  16. : 5. Escaping to the operating system (on the PC MS-DOS)
  17. : 6. Integration of 2D data to find a volume
  18. : 7. Data manipulation (reduction, partial removal, transformations)
  19. : 8. List of interesting but not demonstrated commands
  20. :
  21. :
  22. :
  23. pause
  24. : -------------------------------------------------------------------
  25. :
  26. : 1. Prof2d on the IBM-PC (and its video adaptor card)
  27. :
  28. : Prof2d runs on (among many computers) IBM-PCs or true compatibles with 
  29. : Hercules, CGA, EGA, VGA or AT&T 6300 (Olivetti) graphics adaptors. It 
  30. : automatically senses which adaptor is present, but sometimes makes a mistake.
  31. :
  32. : The command  adapt  is used to ask which card is sensed and to set another
  33. : one if this is wrong. If the wrong card is sensed, edit tutorial.pr2 and 
  34. : remove one of the five comment colons (: means comment in Prof2d) below:
  35.  
  36. : adapt Hercules
  37. : adapt Olivetti/AT&T
  38. : adapt CGA
  39. : adapt EGA
  40. : adapt VGA
  41.  
  42. : we will now ask Prof2d what adaptor card it is currently sensing:
  43.  
  44. adapt ?
  45. pause
  46. : 2. Prof2d data structures (variables and data types)
  47. :
  48. : Basic data structures of Prof2d are:
  49. :
  50. : - integer and real variables (scalar)
  51. : - horizontal 1D arrays of data (rows)
  52. : - vertical   1D arrays of data (columns)
  53. : -            2D arrays of data (fields)
  54. :
  55. : Most data structures must be declared before using with the commands
  56. : var, row, column and field.
  57. :
  58. : However, some variables and rows and columns are present by 
  59. : default and need not be declared. Most notable examples are:
  60. :
  61. : -> integer variable nx, active number of elements in rows 
  62. : -> integer variable ny, active number of elements in columns 
  63. : -> row    xcount, counts from 0 to nx-1 
  64. : -> column ycount, counts from 0 to ny-1 
  65. :
  66. :
  67. pause
  68. :
  69. : We will now declare some data structures to be used further. Later
  70. : on we will declare some more (this is always possible).
  71.  
  72.  
  73. var int nx1 ny1 $
  74. row x1 $
  75. column y1 $
  76. field gauss $
  77.  
  78. : Declarations end in $ to indicate the end of the argument list.
  79. : Currently, the maximum field dimension is 64x64 elements (IBM-PC).
  80.  
  81. pause
  82. :
  83. : 3. Internal generation of data and making graphs
  84. :
  85. : Prof2d accepts either commands (such as adapt or field) or 
  86. : mathematical expressions containing variables, data types and constants.
  87. : If an = sign is present, assignment is made. Otherwise the result is
  88. : printed. Some much used constants are present by default, for example
  89.  
  90. pi
  91.  
  92. : The default row and column xcount and ycount may be used for 
  93. : data generation. A 2D gaussian (normal distribution) is synthesized
  94. : by using the default row xcount and column ycount:
  95.  
  96. nx = 21
  97. x1 = -2.0 + 4.0*xcount/(nx-1)
  98. ny = 21
  99. y1 = -2.5 + 5.0*ycount/(ny-1)
  100. : This may take a while!
  101. gauss = exp(-(x1*x1+y1*y1))
  102.  
  103. pause
  104.  
  105. : The  cview  command may be used to make a contour plot on the screen
  106. : of the data. The default number of contours is 10, and they run between
  107. : 10% and 90% of the interval that the viewed field spans.
  108. :
  109. : The number of contours can be specified by the (default) integer variable
  110. : ncont. We will do only 5 contours (to save computation time on PCs without
  111. : a mathematical coprocessor).
  112. :
  113. : After completion, give <enter> to leave the picture.
  114.  
  115. ncont = 5
  116.  
  117. pause
  118. cview x1 y1 gauss 
  119.  
  120. : Some Prof2d variables choose the region of the contour plot:
  121. :
  122. : nxs (starting x mesh line)   if nxs >= nxe, the whole row is used
  123. : nxe (ending   x mesh line)
  124. : nys (starting y mesh line)   if nys >= nye, the whole column is used
  125. : nye (ending   y mesh line)
  126. : Naturally, the contour plot also depends on the row and column used!
  127. : A small demonstration is given by perturbing x1 and y1 and 
  128. : selecting part of the field region to be plotted.
  129.  
  130.  
  131. row x2 $ column y2 $
  132. x2 = sqrt(x1+2.0)
  133. y2 = 0.05*sgn(y1)*(y1*y1)
  134.  
  135. nxs=8
  136. nxe=16
  137.  
  138. : remember to finish the cview with <enter>
  139.  
  140. pause
  141. cview x2 y2 gauss
  142.  
  143. : the default full region contour plotting is restored:
  144.  
  145. nxs=nxe
  146.  
  147. : other possibilities of cview are:
  148. :
  149. : - use default row xmesh and default column ymesh to select mesh lines
  150. :   to be shown in the picture (with the assign command)
  151. :
  152. : - use command  setcont  to select contour values to be used by hand
  153. :
  154. : Please read the cview, assign and setcont manual pages to find out
  155. : more about this (with the help command).
  156. :
  157.  
  158. pause
  159.  
  160. : 1D Cross Sections through a field with view.
  161. : -------------------------------------------
  162. :
  163. : The  view  command makes 1D cross-sections through a 2D data field
  164. : along either a selected row or a selected column. By default, up to 
  165. : 10 lines are selected for cross-sectioning in one graph.
  166. :
  167. : The default row xplot and column yplot can be used to assign cross-
  168. : section lines to be used. Here we use assign to view the first 8
  169. : horizontal cross sections.
  170. :
  171. : View commands are also ended by <enter>.
  172.  
  173. assign yplot 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 $
  174. pause
  175. view x1 gauss
  176.  
  177. : In fact, the Prof2d view command was directly derived from the Profile 
  178. : view command (Profile is the 1D scientific spreadsheet and optimizer,
  179. : also available in the Public Domain). The use of the (again present by
  180. : default) scaling variables xls, xrs, yus and yls is explained in the
  181. : view manual page and in the Profile tutorial.
  182.  
  183. pause
  184. :
  185. : Now, using the expression evaluation capabilities of Prof2d, we will
  186. : produce a so called 'Schmoo' plot of our Gaussian field.
  187. : The built-in function pos(x) returns 1 if x > 0, otherwise it returns 0.
  188. : A formula is defined and remembered with the  define  command.
  189.  
  190. field s t $
  191. var real c1 c2 c3 c4 c5 $
  192.  
  193. define schmoo=pos(t-c1)+pos(t-c2)+pos(t-c3)+pos(t-c4)+pos(t-c5)
  194.  
  195. c1=0.1
  196. c2=0.3
  197. c3=0.5
  198. c4=0.7
  199. c5=0.9
  200.  
  201. t=gauss
  202. s=schmoo
  203.  
  204. : the plot is produced by evaluating the very simple expression 's'
  205.  
  206. pause
  207. s
  208. pause
  209.  
  210. :
  211. : 4. Reading and writing data from and to file
  212. :
  213. : Of course, often you will use Prof2d to view or transform externally
  214. : generated or measured data.
  215. :
  216. : Prof2d has two formats in which it can read and write data:
  217. :
  218. : 1. The list   format (commands get  & put)   
  219. : 2. The matrix format (commands mget & mput)
  220. :
  221. : In the list format, you can read or write more than 1 field at the time:
  222. :
  223. :   x(i) y(j) z1(i,j) z2(i,j) z3(i,j) ..... (one line from a file)
  224. :    
  225. : In the matrix format, only one field can be filed, optionally together
  226. : with a row and column. Give <help formats> for more detailed information.
  227. :
  228. : We will now put a file in list format and then read back its contents 
  229. : into different rows, columns and fields.
  230.  
  231. pause
  232.  
  233. : reduce number of lines a little ...
  234. nx=5
  235. ny=4
  236.  
  237. put tutor.dat x1 y1 gauss s $
  238.  
  239. get tutor.dat x2 y2 s t $
  240.  
  241. pause
  242.  
  243. : 5. Escaping to the operating system (on the PC MS-DOS)
  244. :
  245. : Many operating system commands (such as dir and del, etc) can be typed
  246. : to the Prof2d prompt ("pr2d> ", only shown interactively). They are
  247. : executed if a command.com file can be loaded by the system.
  248. :
  249. : If Prof2d doesn't recognize a command (e.g. because it is not a standard
  250. : MS-DOS command or one of the DOS commands that is also a Prof2d command),
  251. : you can use the 'shell escape' sign %
  252. :
  253. : An example (typing the data file tutor.dat):
  254. :
  255. pause
  256. % type tutor.dat
  257. pause
  258.  
  259. : Now look at the directory and delete our data file tutor.dat:
  260.  
  261. dir
  262. del tutor.dat
  263.  
  264. pause
  265.  
  266. : Run your application program (e.g. in development) from Prof2d 
  267. : and use the Prof2d history mechanism to rapidly see your results:
  268. :
  269. : % myprog mydata.in           : execute the external program MYPROG
  270. : get myprog.out x y z $       : read output from MYPROG
  271. : cview x y z                  : look at output
  272. : % edit mydata.in             : change input for myprog with your editor
  273. : % myprog mydata.in           : re-run the external program MYPROG
  274. : !get                         : repeat the last line starting with 'get'
  275. : !cvi                         : repeat the last line starting with 'cvi'
  276. : .... etc
  277.  
  278. pause
  279.  
  280. : 6. Integration of a field to find the volume below a surface.
  281. :
  282. : Prof2d offers a facility for numerical integration. This command uses
  283. : a 2D trapezium derived by integration of the bilinear approximation
  284. : of the 2D function on each mesh rectangle.
  285. :
  286. : The gaussian is integrated over the entire region. This should yield
  287. : a volume of Pi (apart from discretisation error and error due to the
  288. : finite integration area).
  289.  
  290. : Reset number of lines from get/put demonstration
  291. nx=21
  292. ny=21
  293.  
  294. : Real variable to contain the volume and integration by command inte2d
  295. var real volume $
  296. inte volume x1 y1 gauss
  297.  
  298. : Print result and compare with Pi
  299. volume
  300. volume/pi
  301.  
  302. pause
  303.  
  304. : 7. Data manipulation (reduction, partial removal, transformations)
  305. :
  306. : One of the applications of the Prof2d (and also the Profile) package
  307. : is the manipulation of data to bring it in another form, e.g. conversion
  308. : of the output from one program to the input of the next program.
  309. :
  310. : Prof2d offers several possibilities for data manipulation:
  311. :
  312. : - expression evaluation to compute and create new data; use of the pos(),
  313. :   neg() and pls() functions to select only part of a data field to be used;
  314. : - getting data in list format and putting it in matrix format, or vice versa;
  315. : - reduction of the number of data elements in the x- and/or the y-direction
  316. :   with the commands redx and redy;
  317. : - partial removal of data with the commands remx and remy;
  318. : - mirroring a data field (with a row or column) in the x- or y-axis 
  319. :   with the command mirror;
  320. : - transposing a data field (and optionally interchanging a row with a 
  321. :   column) with the command transpose.
  322. :
  323. :
  324. : Not everything can be demonstrated here. One small example:
  325. :
  326. pause
  327. :
  328. : The middle horizontal section of the gaussian is removed and
  329. : the result is looked at:
  330.  
  331. var int nstart nend $
  332. nstart = ny/2 -1
  333. nend   = ny/2 +2
  334. remy nstart nend
  335.  
  336. pause
  337. cview x1 y1 gauss
  338.  
  339. : Gauss is transposed together with x1 and y1  and re-cviewed
  340. : Note that x1 and y1 are interchanged (x1 has become a column, y1 a row)
  341.  
  342. show rows
  343.  
  344. transpose x1 y1 gauss
  345.  
  346. show columns
  347.  
  348. pause
  349. cview y1 x1 gauss
  350.  
  351. : ------------------------------------------------------------------
  352. :
  353. : This completes the Prof2d tutorial introduction.
  354. :
  355. : Many things were not treated. Some omissions are the cplot and plot
  356. : commands to create contour and cross section plots with an HP7550A or
  357. : HP7475 pen plotter, and the bget and bput commands to read and create
  358. : data files in binary format.
  359. :
  360. :
  361. : Please continue playing a little with Prof2d and use
  362. :
  363. : - help <command> for help on a specific command
  364. : - help help      for a list of all help pages
  365. : - show           for a list of variables and data structures in use
  366. : - history or h   for a list of recently given commands (to be repeated)
  367. :
  368. : Note that Prof2d runs on UNIX and VAX/VMS computers as well. Give
  369. : help public  to read Copyright information and find the address to
  370. : apply for a licence agreement to obtain the source code (in C).
  371. :
  372. : Give <quit enter> to leave Prof2d.
  373. :
  374.