introduction_to_igor_programming

更新时间:2023-07-28 06:30:23 阅读: 评论:0

Introduction to IGOR Pro Program-ming
小提琴价位IGOR Pro is a bona fide programming platform. It is software that can interpret long quences of commands, compile them (translate them into lower level binary quences that the computer can understand) and execute the programs. It has a simple development environment, complete with a ur interface and a debugger. The system is designed primarily to allow you to build programs from IGOR's large repository of built-in functions. Hence, IGOR programming proceeds with greater speed than traditional programming becau one need not write analytical or statistical al-gorithms from scratch. Many such functions are already built into IGOR.
IGOR programming focus on automating tasks, but it is not limited to automation. It is also pos-sible to write programs that do complex calculations, acquire data from instruments, and create elaborate ur interfaces.  The objective of this primer is to help you get started on the path to be-coming an IGOR programmer.
This manual will also rve as a very brief survey of IGOR’s built-in functions. It starts slowly, but the pace will quicken quite rapidly.
Before Y ou Begin
Prerequisites
This tutorial requires IGOR Pro version 5.04 or later. If you do not have version 5.04 or later, plea update to the latest IGOR Pro. In IGOR Pro 5 you can do this by choosing Updates from the IGOR Help menu.
There are some requirements to using this manual. Prior to proceeding with programming IGOR, it is esntial to take the Guided Tour of IGOR Pro (in Volume I of the IGOR Pro manual t). Y ou should be comfortable with IGOR waves, with IGOR experiments, with creating graphs and tables manually, and with running IGOR procedures written by others. If not, re-take the Guided Tour or refer to IGOR’s manual and get acquainted with IGOR before you begin programming.
We also assume that you have some experience programming at any level in any language so that basic programming concepts like functions, parameters and loops are not entirely foreign to you. Programming Esntials
IGOR programming is much easier than conventional programming becau IGOR Pro already has innumerable built-in functions that perform most tasks. For example, you need not write your own curve fitting algorithm. The CurveFit command readily does that. Hence, IGOR programming focu
s more on automating tasks, rather than implementing analys from scratch. Of cour, you are free to do that in IGOR if you so desire.
In addition, IGOR programming is easier becau it is highly interactive. Y ou can enter a function in IGOR’s procedure window and compile and execute it right away from the command line.  Companion Experiment
Much of the material prented here works on data in the IntroToIGORProgramming.pxp experi-ment file. Open it now in IGOR so that you can follow along. The waves that you need for the ex-amples are provided in the root data folder of this experiment. (From the menu choo Data and then Data Browr.)
The Structure of the Tutorial
This tutorial begins with some quick drills to get you acquainted with the the process of entering  code into the Procedure window, compiling  the code and executing the code. The most basic elements are introduced first, and the subquent examples build on the sim-pler ones. New elements are intro-duced in bold  text. The explanations are offered mainly in the text that fol-lows each example, and partly in the comments that accompany each func-tion. As you enter code, exami
ne it line by line and read the comments.
Although you can cut and paste the functions into the Procedure window, we recommend that you manually type  the functions into the Procedure win-dow or u the built-in templates (Fig-ure 1). This will help you get ud to the mechanics of IGOR programming.Fundamentals
原则英语The Procedure Window
指数函数性质In IGOR Pro, program code is entered into procedure files. Procedure files can be standalone files or they can be part of an experiment package. Each experiment includes one special, built-in pro-cedure file which you view through the Procedure Window. Y ou can u the Windows menu to open the procedure window or, better yet, u a keyboard shortcut – cmd-M (Macintosh ) or Ctrl-M (Windows ).
Open the procedure window now using  the keyboard shortcut. Now clo it using  cmd-W or Ctrl-W.
Programs entered into the built-in procedure window become part of that particular experiment. As such they are accessible from that experiment only. The built-in procedure window is a good place to experiment with programming, and that is how we will u it.
Once your program is working, you can save it as a parate, standalone procedure file that can be accesd from any experiment. Y ou should save general procedures that you want to u over and over as standalone procedure files. For now, we stay with the built-in Procedure window.
Two features are important when you are a beginning programmer. First, text entered into the Pro-cedure window is color coded as it is typed. The colors make it easy to avoid conflicts between ur-lected object names and IGOR commands and statements. If the color does not look right, you need to change the text. Second, you can inrt a generic template for any IGOR command or statement from the "template" menu on the lower left of the Procedure window. Figure 1 shows how a do-while  loop template is inrted. The templates are uful in the early stages when one Figure 1 Using the templates menu to inrt a program-ming element into the procedure window. In this ca, it is a do-while  loop.
is inclined to forget a comma, a parenthesis, or a bracket. As you can e, the templates also come with some standard comments (the text appearing in red).
The Function
The basic IGOR programming unit is the function, and, in its simplest form it has the following structu
周宣
re:
Function Function_Name()
巨蟹座幸运数字IGOR commands
End
The first line is the declaration of the function itlf, and the assignment of its name (letters, num-bers and underscore character only), which is Function_Name in this ca. It will become clear soon why the parenthes are required. After the function declaration come the commands that will be carried out when the function is called. The commands constitute the body of the func-tion. The last line is the End statement which marks the end of the function.
The function is executed whenever it is called. Y ou can call it from the command line or from an-other function. IGOR also has many built-in functions. The ones we write are ur-defined func-tions (IV Ch. 3; this is how future references to the IGOR manual t will appear).
Writing a Function
Let's start with the obligatory "Hello World" example.
Open the Procedure Window (Command-M on Mac, Ctrl-M on Windows, or from the Procedure Window menu item under the Windows menu) and type the following:
Function HelloWorld()
Print "Hello World!"
End
When you start typing, the "Compile" button becomes active. Y ou can press it to start compiling your function. Y ou can also switch to another window, an act that will trigger a compile. If you have any typographical or syntactical errors, IGOR will report them to you at this stage.
英语基础学习If the function compiles without any errors, you are ready to execute it (or call it). If the compiler discovers any errors, you can choo Edit Procedure or Quit Compile from the error dialog. Edit Procedure will take you to the position where the error was encountered in the Procedure window. Quit Compile will halt compiling and return you to IGOR Pro to perform other tasks.
Errors noted by the compiler are compile time errors. They are usually typographical or syntactical errors. Errors that are encountered when functions are executed are run time errors. Run time er-ror
s can be difficult to discover and correct and may require debugging. For example, telling IGOR to kill a wave that does not exist is a runtime error. More on this topic later.
Calling a Function
Once written, a function must be called. When a function is called, it is executed in its entirety. The function is most commonly called from the command line, from a menu, from another func-tion or from an assignment statement.
Call the function you wrote above from the Command window by typing
HelloWorld()
into the command line area of the command window and pressing the Enter or Return key on your keyboard. Y ou will e Hello world! printed in the history area of the Command window.
Let's call this function from an IGOR menu (IV Ch. 5). Type the following menu definition into the Procedure window.
Menu "Macros"
"Hello World", HelloWorld()
End
After compiling, you e "Hello World" listed as an item under the Macros menu. Choosing it yields the same result as when you called  HelloWorld from the command line.
So, now you know what the Print command does. It is a uful command in debugging run time errors.
The Return Value of A Function
Historically and generally, functions strictly calculated certain values and returned the values to the source from which they were called. This value can be a string (i.e., text), a real number, or a complex number. The function is no longer required to return a value to its caller, but if we require a value from a function, the return statement does this job.
Enter the following into the Procedure window.
Function ValueDemo()
return pi*3^2
End
Now, execute the following command in the Command window.
Print “The area of a circle with a radius of 3 units is “, ValueDemo(),”
units squared.”
冰糖葫芦怎么做As you can e, the return statement defines the value that the function returns, the area of the circle in this instance.
By default, IGOR expects functions to return a real number. Let’s demonstrate the importance of value types by making ValueDemo a string function with the /S flag and compile it again.
Function/S ValueDemo()
return pi*3^2
End
Compiling this function fails becau IGOR reports a type mismatch. IGOR expects ValueDemo to return a string value, but the return statement returns a number. Invoking one IGOR built-in func-tion solves the problem:
Function/S ValueDemo()
return num2str(pi*3^2)
End
The num2str function converts the numerical value inside the parenthes that follow it into a string. There is a no longer a type conflict, and the function compiles and executes normally. Types
must be defined and obrved for parameters as well becau computer stores and process numbers, text and complex numbers differently. And, yes, the rever function, str2num, exists.
Of cour, this is a fairly worthless function, for it is capable of evaluating the area of a circle with a fixed radius. We need to u parameters to make functions more general.
Parameters
When a function needs to operate on a particular object(wave, string or text variable, etc.), it must receive the information about the object as a parameter during the function call. The function must also contain instructions on how to treat each parameter. In other words, values, strings and waves are pasd to functions as parameters.
The three parameters types are numeric (number, real and complex), string (i.e., text), and wave. Numeric parameters are declared with the Variable declaration. String parameters are declared with the String declaration. Waves are declared with the Wave declaration. Complex parameters are declared with the /C flag; i.e., Variable/C. Let's start a few drills with parameters by changing ValueDemo function to read:
Function ValueDemo(radius)
Variable radius
return pi*radius^2
End
Now you must supply a numeric parameter when calling ValueDemo.
Execute this line in the Command window:
Print "The area of a circle with radius = 2.75 in. is",ValueDemo(2.75)," sq. in."
Now let’s try a function with both a numeric and string parameter.
Enter this in the procedure window:
Function CircleArea(radius,units)
Variable radius
String units
Print "If radius=",radius,units,", then area is ",pi*radius^2," square", units
End
Now call the function from the command line with CircleArea(8.5,"meters")and examine the output in the history area. Values for the variables need to be entered in the order in which they appear in the function declaration. String values are marked by double quotes.
宝宝痱子图片
Save the experiment file. Remember to save your files periodically. At prent, IGOR offers no backup solution. So, your only backup is to save your experiment and/or procedure files regularly. Wave Parameters and Forming Wave Names
Wave parameters derve special attention becau mishandling waves is mishandling data, and you don't want to lo any data. Although waves can be accesd directly by a function, certain situations require that they be declared like string and numerical values before they can be ud in a function. For example,

本文发布于:2023-07-28 06:30:23,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1121306.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:指数函数   学习   痱子   性质   基础   图片
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图