IDL Exercise 4
The purpose of this exercise is familiarization with function and procedure calls using positional and keyword parameters. This will be done by constructing script files that make use of IDL built in procedures and functions.
  1.  We will use the PLOT procedure to demonstrate some of the basic elements of procedure calls. Open idlde and type copy the following line into your edit window. Save these lines in a file called plot1.pro.  Then type @plot1 in the IDL command line window. You should see a graph like that shown below. The color of your background and plotlines may be different depending on how your color environment is set up. Don't worry about that right now.
  2. x=FINDGEN(1001)/20-25
    y=(x-10)*(x+10)*sin(x)
    plot,x,y


    The above exercise used the function FINDGEN to generate a vector x of values and then used operators and the SIN function to compute a vector of y values. You can use the methods of exercise 3 to investigate the contents of these vectors. You then used the plot procedure to create and display a graph of these vectors. Note that a function puts the parameters inside parentheses and a procedure puts them after the name, separated by commas.

  3. We will now enhance the plot by adding a title at the top and axis titles below and on the left. This is done by using keyword parameters. Modify your file so it reads as shown below. The added part is shown in red. Then run the program again using @prog1.
  4. x=FINDGEN(1001)/20-25
    y=(x-10)*(x+10)*sin(x)
    plot,x,y,TITLE='My First Plot',$
        XTITLE='x',YTITLE='y=f(x)'

    The graph should now have titles, as shown below. The parameters TITLE, XTITLE and YTITLE called keywords. In this example they are given string values. The strings are then used as the titles. You can experiment with changing the strings to get different titles.
    PLOT is a procedure that has many parameters. You can read about them by using IDL online help. Select Help from the menu bar, then select the index tab, then type Plot Procedure in the search field to select the PLOT help. Read about some of the keyword parameters that are available. We will use some additional keywords to cause the plot to draw a dotted grid.

  5. Modify your program so it reads as follows. Again, the changes are shown in red. Save and run prog1

    x=FINDGEN(1001)/20-25
    1. y=(x-10)*(x+10)*sin(x)
      plot,x,y,TITLE='My First Plot',$
          XTITLE='x',YTITLE='y=f(x)'
      ,$
          XTICKLEN=1,YTICKLEN=1,$
          XGRIDSTYLE=1,YGRIDSTYLE=1


    The graph should now look like the picture below. Note that our new keyword parameters caused the plot procedure to draw the gridlines. Read the help documentation to see what the parameter values mean. Try other parameter values in these keywords.