ION Script source code:




<!-- Copyright (c) 1997-2002, Research Systems, Inc.  All rights reserved
     Unauthorized reproduction prohibited. -->

<ION_SCRIPT>
<ION_HEADER>
  <TITLE>ION Script Image Example</TITLE>

  <VARIABLES>
    <VARIABLE_DECL NAME="IMAGE_W" VALUE="1200" TYPE="INT" PERSIST="TRUE"/>
    <VARIABLE_DECL NAME="IMAGE_H" VALUE="1200" TYPE="INT" PERSIST="TRUE"/>

    <VARIABLE_DECL NAME="REGION_W" VALUE="320" TYPE="INT" PERSIST="TRUE"/>
    <VARIABLE_DECL NAME="REGION_H" VALUE="256" TYPE="INT" PERSIST="TRUE"/>

    <VARIABLE_DECL NAME="CENTER_X" VALUE="600" TYPE="INT" PERSIST="TRUE"/>
    <VARIABLE_DECL NAME="CENTER_Y" VALUE="600" TYPE="INT" PERSIST="TRUE"/>

    <VARIABLE_DECL NAME="SCALE_MIN" VALUE="0" TYPE="INT" PERSIST="TRUE"/>
    <VARIABLE_DECL NAME="SCALE_MAX" VALUE="255" TYPE="INT" PERSIST="TRUE"/>
    <VARIABLE_DECL NAME="SCALE_TOP" VALUE="255" TYPE="INT" PERSIST="TRUE"/>
  </VARIABLES>

  <EVENTS>
    <EVENT_DECL NAME="SCALE_COLORS" ACTION="ion://ex1_scale.ion"/>
    <EVENT_DECL NAME="CENTER_IMAGE" ACTION="ion://ex1_main.ion"/>
    <EVENT_DECL NAME="SHOW_DATA" ACTION="ion://ex1_data.ion"/>
  </EVENTS>
</ION_HEADER>

<ION_BODY>

  <FONT SIZE=+2>ION Script Image Example</FONT>
  <BR><BR>

  <!-- If the mouse was pressed, recompute the cetner -->
  <ION_IF EXPR="$Mouse.x NE 0.0">
    <ION_EVALUATE EXPR="$CENTER_X = $CENTER_X + ($Mouse.x - $REGION_W/2)"/>
    <ION_EVALUATE EXPR="$CENTER_Y = $CENTER_Y - ($Mouse.y - $REGION_H/2)"/>
  </ION_IF>

  <!-- Make sure we haven't reached the edge of the image -->
  <ION_IF EXPR="($CENTER_X + $REGION_W/2) GT ($IMAGE_W - 1)">
    <ION_EVALUATE EXPR="$CENTER_X = ($IMAGE_W - 1) - $REGION_W/2"/>
    <FONT COLOR="#0000CC">
    <BR>Right edge of image reached, view center has been adjusted
    </FONT>
  <ION_ELSEIF EXPR="($CENTER_X - $REGION_W/2) LT 0"/>
    <ION_EVALUATE EXPR="$CENTER_X = $REGION_W/2"/>
    <FONT COLOR="#0000CC">
    <BR>Left edge of image reached, view center has been adjusted
    </FONT>
  </ION_IF>

  <ION_IF EXPR="($CENTER_Y + $REGION_H/2) GT ($IMAGE_H - 1)">
    <ION_EVALUATE EXPR="$CENTER_Y = ($IMAGE_H - 1) - $REGION_H/2"/>
    <FONT COLOR="#0000CC">
    <BR>Top edge of image reached, view center has been adjusted
    </FONT>
  <ION_ELSEIF EXPR="($CENTER_Y - $REGION_H/2) LT 0"/>
    <ION_EVALUATE EXPR="$CENTER_Y = $REGION_H/2"/>
    <FONT COLOR="#0000CC">
    <BR>Bottom edge of image reached, view center has been adjusted
    </FONT>
  </ION_IF>
  <!-- end image center ------------------------------------ --> 

  <ION_IMAGE EVENT="CENTER_IMAGE" WIDTH="$REGION_W" HEIGHT="$REGION_H" TYPE="DIRECT">
    <IDL>
      ; Read in the original image:
      image = read_png( filepath(sub=['products','ion', 'ion_script','examples', 'data'], 'landsat.png'), r, g, b)

      ; Calculate the x subscripts:
      xstart = $CENTER_X - $REGION_W/2
      xend = $CENTER_X + $REGION_W/2 - 1

      ; Calculate the y subscripts:
      ystart = $CENTER_Y - $REGION_H/2
      yend = $CENTER_Y + $REGION_H/2 - 1

      ; Create the region to be displayed:
      region = image[xstart:xend, ystart:yend]

      ; Scale the region:
      scale_region = bytscl(region, MIN=$SCALE_MIN, MAX=$SCALE_MAX, TOP=$SCALE_TOP)

      ; Load the display color table:
      tvlct, r, g, b

      ; Display the region:
      tv, scale_region
    </IDL>
  </ION_IMAGE>
  <BR>
  <B>Image Size:</B> (<ION_VARIABLE NAME="$IMAGE_W"/>, 
                      <ION_VARIABLE NAME="$IMAGE_H"/>)
  <BR>
  <B>Region Size:</B> (<ION_VARIABLE NAME="$REGION_W"/>, 
                       <ION_VARIABLE NAME="$REGION_H"/>)
  <BR>
  <B>Region Center:</B> (<ION_VARIABLE NAME="$CENTER_X"/>, 
                         <ION_VARIABLE NAME="$CENTER_Y"/>)

  <!-- Include the user input form -->
  <ION_INCLUDE SRC="ion://ex1_form.ion"/>

  <ION_LINK EVENT="SHOW_DATA">View Image Data</ION_LINK>

</ION_BODY>
</ION_SCRIPT>