home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / spredsht / profile.arc / TUTORIAL.PRO < prev   
Text File  |  1990-01-03  |  12KB  |  394 lines

  1. : Profile, The 1D Scientific Spreadsheet               IBM-PC Version
  2. : by Gertjan L. Ouwerling, Electrical Materials Lab, Delft University
  3. : -------------------------------------------------------------------
  4. : Execute this tutorial by typing:  prof tutorial.pro <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. Profile on the IBM-PC (and its video adaptor card)
  13. : 2. Profile 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, differentiation and curve-fit
  18. : 7. Data manipulation and use of auxiliary files
  19. : 8. List of interesting but not demonstrated commands
  20. :
  21. :
  22. :
  23. pause
  24. : -------------------------------------------------------------------
  25. :
  26. : 1. Profile on the IBM-PC (and its video adaptor card)
  27. :
  28. : Profile 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.pro and 
  34. : remove one of the five comment colons (: means comment in Profile) 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 Profile what adaptor card it is currently sensing:
  43.  
  44. adapt ?
  45. pause
  46. : 2. Profile data structures (variables and data types)
  47. :
  48. : Basic data structures of Profile are integer and real variables (scalar)
  49. : and 1D columns of real data (called 'data types'). Most data structures
  50. : must be declared before using with the commands  var  and  type. 
  51. :
  52. : However, some variables and 'data types' (columns) are present by 
  53. : default and need not be declared. Most notable examples are:
  54. :
  55. : -> integer variable ndata, contains current number of data lines
  56. : -> data type count, counts from 0 to ndata-1 (unless changed)
  57. :
  58. : We will now declare some data structures to be used further. Later
  59. : on we will declare some more (this is always possible).
  60.  
  61. var int  naxis1 naxis2   $
  62. var real ysum   yinte    $
  63. type xaxis1 y1 y2 $
  64.  
  65. : Declarations end in $ to indicate the end of the argument list
  66.  
  67. pause
  68. :
  69. : 3. Internal generation of data and making graphs
  70. :
  71. : Profile accepts either commands (such as adapt or type) or 
  72. : mathematical expressions containing variables, data types and constants.
  73. : If an = sign is present, assignment is made. Otherwise the result is
  74. : printed. Some much used constants are present by default, for example
  75.  
  76. pi
  77.  
  78. : The default data type count may be used for data generation:
  79.  
  80. ndata=40
  81. xaxis1=count/(ndata-1)*2*pi
  82. y1=sin(xaxis1)
  83. naxis1=ndata
  84.  
  85. : The view command is used to look at data. Give  <enter> to leave!
  86.  
  87. pause
  88. view xaxis1 y1 $
  89.  
  90. : Columns of data are listed using the  print  command.
  91. : Part of the lines are optionally selected by ending in: | [start] [end] 
  92.  
  93. pause
  94. print xaxis1 y1 | 12 24 
  95.  
  96. : Some more data is generated and a graph is made with both y1 and y2
  97.  
  98. y2=cos(2*xaxis1)
  99.  
  100. pause
  101. view xaxis1 y1 y2 $
  102.  
  103. : The view command has more possibilities: a right xaxis may also be 
  104. : used and scaling values can be forced using the default variables:
  105. :
  106. : xls  - X Left  Scale
  107. : xrs  - X Right Scale
  108. : yls  - Y Lower Scale       (left  y axis)
  109. : yus  - Y Upper Scale       (left  y axis)
  110. : ryls - Right Y Lower Scale (right y axis)
  111. : ryus - Right Y Upper Scale (right y axis)
  112. :
  113. : Autoscaling is restored if  xls >= xrs,  etcetera.
  114.  
  115. xls  = -1.0
  116. xrs  =  8.0
  117. yus  =  1.2
  118. yls  = -1.2
  119. ryus =  2.0
  120. ryls = -2.0
  121.  
  122. pause
  123. view xaxis1 y1 | y2 $
  124.  
  125. : Restore the autoscaling by (re)setting scaling variables to zero
  126.  
  127. xls  = 0
  128. xrs  = 0
  129. yus  = 0
  130. yls  = 0
  131. ryus = 0
  132. ryls = 0
  133.  
  134. : Log plots can be made by taking the logarithm of the data
  135. : ---------
  136.  
  137. type log_y1 log_y2 $
  138.  
  139. : Argument of log() may not become zero!
  140.  
  141. log_y1 = log(abs(y1)+0.001)
  142. log_y2 = log(abs(y2)+0.001)
  143.  
  144. pause
  145. view xaxis1 log_y1 log_y2 $
  146.  
  147. :
  148. : 4. Reading and writing data from and to file
  149. :
  150. : Data can be written to and read from file with the commands  put & get.
  151. :
  152. : -> put [filename] [data type names] $
  153. : -> get [filename] [data type names] $
  154. :
  155. : Data has to be present in the form of legible columns of numbers. A one
  156. : line heading containing the names of the columns is allowed (and made by
  157. : the put command).
  158. :
  159. : If the get command is given without arguments, it automatically uses and
  160. : necessarily declares the appropriate columns ('data types').
  161. : The view command also shows these 'last read' types automatically. A fast
  162. : "get 'n see" sequence thus becomes:
  163. :
  164. : get file.dat $
  165. : view $              (or also print $  and even put [filename] $)
  166. :
  167. : This will be illustrated by putting a file, and getting and viewing it.
  168.  
  169. pause
  170.  
  171. put tutor.dat xaxis1 y1 y2 $
  172. get tutor.dat $
  173.  
  174. pause
  175.  
  176. : show last read data types
  177. view $
  178.  
  179. : It is remarked (but not demonstrated) that the commands
  180. :
  181. : startmark [begin of reading marker text]
  182. : endmark   [end   of reading marker text]
  183. :
  184. : are available to select only part of a file for reading.
  185. : Later on, try typing  help startmark  for some explanation.
  186.  
  187. pause
  188.  
  189. : 5. Escaping to the operating system (on the PC MS-DOS)
  190. :
  191. : Many operating system commands (such as dir and del, etc) can be typed
  192. : to the Profile prompt ("prof> ", only shown interactively). They are
  193. : executed if a command.com file can be loaded by the system.
  194. :
  195. : If Profile doesn't recognize a command (e.g. because it is not a standard
  196. : MS-DOS command or one of the DOS commands that is also a Profile command
  197. : such as type and print), you can use the 'shell escape' sign %
  198. :
  199. : An example:
  200. :
  201. pause
  202. % type tutor.dat
  203.  
  204. : Now look at the directory and delete our data file tutor.dat:
  205.  
  206. dir
  207. del tutor.dat
  208.  
  209. pause
  210.  
  211. : Run your application program (e.g. in development) from Profile 
  212. : and use the Profile history mechanism to rapidly see your results:
  213. :
  214. : % myprog mydata.in           : execute the external program MYPROG
  215. : get myprog.out $             : read output (file with header)
  216. : view $                       : look at output
  217. : % edit mydata.in             : change input for myprog with your editor
  218. : % myprog mydata.in           : re-run the external program MYPROG
  219. : !get                         : repeat the last line starting with 'get'
  220. : !vi                          : repeat the last line starting with 'vi'
  221. : .... etc
  222.  
  223. pause
  224.  
  225. : 6. Integration, differentiation and curve-fit
  226. :
  227. : Profile offers facilities for numerical data processing. With an example
  228. : integration, differentiation and curve-fit are demonstrated. 
  229. :
  230. : Using a synthetic x-axis, a Gaussian curve is formed. This is integrated
  231. : to give the shape of the error function erf(x). The integral value on a
  232. : sufficiently large interval should equal sqrt(pi). This is verified.
  233.  
  234. type x2 gauss errorf $
  235. ndata = 100
  236. : reset the count default data type
  237. recount
  238. x2 = 6*((count/(ndata-1))-0.5)
  239. gauss = exp(-x2*x2)
  240. : integrate gaussian function to find error function
  241. inte gauss x2 errorf
  242.  
  243. : Take a look at the results up till now
  244.  
  245. xls = -3.5
  246. xrs =  3.5
  247. pause
  248. view x2 gauss errorf $
  249.  
  250. : Check integral value by assigment of data type errorf to a real variable,
  251. : and divide by the expected value to see the relative error:
  252.  
  253. var real gaussarea $
  254. gaussarea = errorf
  255. gaussarea
  256. gaussarea / sqrt(pi)
  257.  
  258. pause
  259.  
  260. : Curve-fit.
  261. :
  262. : The Profile command  fit  makes a polynomial (recursive) fit to available
  263. : data. This is done by minimizing the sum of squared differences between 
  264. : measured and fit data. The data type  weight  (present by default) may be 
  265. : used to assign different weights to error sum components. By default, 
  266. : weight=1 for all elements. The default integer variable  npoly  may be 
  267. : used to limit the order of the polynomial. 
  268. :
  269. : A polynomial of 6th order is fit to the computed gaussian. A list is 
  270. : printed of the variance (a measure of the fit accuracy) and the ratio
  271. : between subsequent variances. Note that for the even gaussian function,
  272. : addition of odd polynomial orders does not improve the fit!
  273.  
  274. npoly=6
  275. type fitgauss $
  276.  
  277. pause
  278. fit gauss x2 fitgauss
  279.  
  280. : The fit command does not end in '$' because the number of 
  281. : arguments is known in advance. Let's take a look at the results:
  282.  
  283. pause
  284. view x2 gauss fitgauss $
  285.  
  286. : A better fit can be obtained by setting npoly=12 (the highest allowed). 
  287. : Maybe you can try this your self at the end of this tutorial.
  288. :
  289. : Note that the fit command supplies the first and second derivatives
  290. : of the fitted polynomial in the default data types tmp1 and tmp2. 
  291. : The same method of differentiation can be invoked by using the 
  292. : diff  command like:
  293. :
  294. : -> diff fit gauss x2 dgaussdx
  295. :
  296. : Here we will demonstrate differentiation by simple differencing
  297. : (subtraction of values). This is useful only if your data is very 
  298. : smooth. The differentiation of errorf (integrated from gauss)
  299. : should return our gaussian function:
  300.  
  301. type derf_dx2 $
  302. diff num errorf x2 derf_dx2 
  303. compare derf_dx2 gauss
  304.  
  305. pause
  306. : The compare command shows only a small difference. Look at the graphs:
  307.  
  308. pause
  309. view x2 gauss derf_dx2 $
  310.  
  311. : 7. Data manipulation and use of auxiliary files
  312. :
  313. : Finally, we will show some small Profile 'tricks' to bring data in
  314. : a desired form. With some creativity, many things can be arranged
  315. : using:
  316. :
  317. : - the pos(), pls() and neg() functions to select parts of a data type
  318. :   this is demonstrated in example2.pro
  319. : - the assign and extract commands to access individual data elements
  320. : - the map command to interpolate data from one x-axis to another
  321. : - the reduce and remove commands to throw away data lines
  322. : - the insert command to add new (zeroed) data lines
  323. : - the sort command to sort all lines according to one data type
  324. : - intermediate files to temporarily store data
  325. :
  326. : Not everything can be demonstrated here. One small example:
  327. :
  328. pause
  329. :
  330. : The gaussian will be put in front of the error function to form one
  331. : long data column. The x2 x-axis is also duplicated.
  332. : First save the gaussian in a temporary file.
  333.  
  334. put gauss.tmp x2 gauss $
  335.  
  336. : Create the prolonged x-axis by copy and addition.
  337.  
  338. var real xmin xmin2 xmax $
  339.  
  340. extract x2 1     xmin 
  341. extract x2 2     xmin2
  342. extract x2 ndata xmax
  343.  
  344. x2 = x2 + (xmax-xmin) + (xmin2-xmin) 
  345.  
  346. pause
  347.  
  348. : Insert enough lines to contain the first x-axis and the gauss.
  349. : Put the error function 'on top'.
  350. : Read the gauss and put it in front of the error function.
  351.  
  352. insert 1 ndata
  353. gauss = errorf
  354. get gauss.tmp x2 gauss $
  355. del gauss.tmp
  356. ndata = ndata*2
  357.  
  358. : look at the result!
  359.  
  360. pause
  361.  
  362. : disable forced x-axis scaling
  363. xls=0
  364. xrs=0
  365. view x2 gauss $
  366.  
  367. : ------------------------------------------------------------------
  368. :
  369. : This completes the Profile tutorial introduction.
  370. :
  371. : Many things were not treated. The most important omission is the 
  372. : Profile command  levmar  that does non-linear parameter extraction
  373. : by the Levenberg-Marquardt method on parametrized data models.
  374. :
  375. : Example1.pro gives a demonstration of the levmar command.
  376. :
  377. : Please continue playing a little with Profile and use
  378. :
  379. : - help <command> for help on a specific command
  380. : - help help      for a list of all help pages
  381. : - show           for a list of variables and data types in use
  382. : - history or h   for a list of recently given commands (to be repeated)
  383. :
  384. : Note that Profile runs on UNIX and VAX/VMS computers as well. Give
  385. : help public  to read Copyright information and find the address to
  386. : apply for a licence agreement to obtain the source code (in C).
  387. :
  388. : Give <quit enter> to leave Profile.
  389. :
  390.