<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="None">
  <name>Modular Programming</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2004/06/14 14:51:30 GMT-5</md:created>
  <md:revised>2004/07/16 14:57:00.694 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>lizzardg@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mshiralkar05">
      <md:firstname>Malan</md:firstname>
      
      <md:surname>Shiralkar</md:surname>
      <md:email>mshiralkar05@hotmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="harika">
      <md:firstname>Harika</md:firstname>
      
      <md:surname>Basana</md:surname>
      <md:email>ilsai@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  

  <md:abstract/>
</metadata>

  <content>
    <para id="intro">
      The power of LabVIEW lies in the hierarchical nature of the
      VI. After you create a VI, you can use it on the block diagram
      of another VI. There is no limit on the number of layers in the
      hierarchy. Using modular programming helps you manage changes
      and debug the block diagram quickly.  
    </para>
    <para id="intro2">
      A VI within another VI is called a subVI. A subVI corresponds to
      a subroutine in text-based programming languages. When you
      double-click a subVI, a front panel and block diagram appear,
      rather than a dialog box in which you can configure options. The
      front panel includes controls and indicators that might look
      familiar. The block diagram includes wires, front panel icons,
      functions, possibly subVIs, and other LabVIEW objects that also
      might look familiar.
    </para>

    <para id="intro3">
      The upper right corner of the front panel and block diagram
      displays the icon for the VI. This icon is the same as the icon
      that appears when you place the VI on the block diagram.
    </para>
    
    <section>
      <name>Icon and Connector Pane</name>
      <para id="p1">
	<media id="m1" type="image/png" src="vi_icon.png"/> After you build a
	front panel and block diagram, build the icon and the
	connector pane so you can use the VI as a subVI. Every VI
	displays an icon, such as the one shown in <cnxn target="m1"/>, in the upper right corner of the front panel
	and block diagram windows. An icon is a graphical
	representation of a VI. It can contain text, images, or a
	combination of both. If you use a VI as a subVI, the icon
	identifies the subVI on the block diagram of the VI. You can
	double-click the icon to customize or edit it.
      </para>

      <para id="p2">
	<media id="m2" type="image/png" src="conpane.png"/> 
	You also need to build a connector pane, shown in <cnxn target="m2"/>, to use the VI as a subVI. The connector pane is
	a set of terminals that correspond to the controls and
	indicators of that VI, similar to the parameter list of a
	function call in text-based programming languages. The
	connector pane defines the inputs and outputs you can wire to
	the VI so you can use it as a subVI. A connector pane receives
	data at its input terminals and passes the data to the block
	diagram code through the front panel controls and receives the
	results at its output terminals from the front panel
	indicators.
      </para>

      <para id="p3">
	As you create VIs, you might find that you perform a certain
	operation frequently. Consider using subVIs or loops to
	perform that operation repetitively. For example, the block
	diagram in <cnxn target="fig1"/> contains two identical
	operations.
	<figure id="fig1">
	  <media type="image/bmp" src="SubVIEx1.png"/>
	</figure>
      </para>

      <para id="p4">
	You can create a subVI that performs that operation and call
	the subVI twice. The example in <cnxn target="fig2"/> calls
	the <code>Temperature</code> VI as a subVI twice on its block
	diagram and functions the same as the previous block
	diagram.You also can reuse the subVI in other VIs. Refer to
	<cnxn document="m12212">Repetition and Loops</cnxn> for more
	information about using loops to combine common operations.
	<figure id="fig2">
	  <media type="image/bmp" src="SubVIEx2.png"/> 
	</figure>
      </para>

      <para id="p5">
	Refer to the <cite>LabVIEW Basics II: Development Course
	  Manual</cite> for more information about application
	development.  The following pseudo-code and block diagrams
	demonstrate the analogy between subVIs and subroutines.
	
	<table id="danny">
	  <tgroup cols="2">
	    <thead> 
	      <row>
		<entry> Function Code </entry>
		<entry> Calling Program Code</entry>
	      </row>
	    </thead>
	    
	    <tbody> 
	      <row>
		<entrytbl cols="1" rowsep="0">
		  <tbody>
		    <row>
		      <entry>
			<code type="block">
			  main
			  {
			  average (point1, point2,
			  pointavg)
			  }
			</code>
		      </entry>
		    </row>
		  </tbody>
		</entrytbl>
		<entrytbl cols="1" rowsep="0">
		  <tbody>
		    <row>
		      <entry>
			<code type="block">
			  function average (in1,
			  in2, out)
			  {
			  out = (in1 + in2)/2.0;
			  }
			</code>
		      </entry>
		    </row>
		  </tbody>
		</entrytbl>
	      </row>      
	      
	      <row>
		<entry>SubVI Block Diagram </entry>
		<entry> CallingVI Block Diagram </entry>
	      </row>
	      
	      <row>
		<entry align="center"> 
		  <media type="image/png" src="2ptavg.png"/> </entry> 
		<entry align="center"> 
		  <media type="image/png" src="subvicall.png"/> </entry>
	      </row>
	    </tbody>
	    
	  </tgroup>
	</table>
	
      </para>
      
    </section>
  </content>
  
</document>
