Download (right-click and "save as")

#
# @author:       Phoenix Integration
# @description:  Converts array of measurements in meters to measures in feet.
#

variable: inputs     double[] input
variable: outputs    double[] output
variable: withUnits  string[] output

# ------------------------------------------
script: language="java"

void run()
{
   //Implement run sharing
   wrapper.getRunShare().lock();
   convertIN(PHXRowFieldFile.GENERATE);
   convertOUT(PHXRowFieldFile.PARSE);
}

void convertIN(int mode)
{
   //Editors note: RowFieldFile pulls the correct directory
   //from wrapper.getDirectory() or wrapper.getRunShare().getDirectory()

   PHXRowFieldFile file = new PHXRowFieldFile(wrapper, mode);
   file.setTemplateFile("convert.in.template");
   file.setFileToGenerateOrParse("convert.in");

   // Read in a 4x4 2D array
   int[] size = {4, 4};
   inputs.resize( size );
   file.transferArray(inputs, 1, 4, 1, 4, 2);

   //Actually generate a file if we are told to
   if ( mode == PHXRowFieldFile.GENERATE )
      file.generate();
}

void convertOUT(int mode)
{
   PHXRowFieldFile file = new PHXRowFieldFile(wrapper, mode);
   file.setFileToGenerateOrParse("convert.out");

   // Make the outputs array 2D
   int[] size = {1, 1};
   outputs.resize( size );

   // Transfer array as being resizable, having no Fortran formatting,
   // and being 2D.
   file.transferArray(outputs, 1, -1, 1, -1, true, null, 2);

   // Create an array that is the outputs, with each element having the
   // units "ft." appended.
   withUnits.resize( outputs.getDimensions() );
   for ( int i = 0; i < outputs.getLength(0); i++ )
      for ( int j = 0; j < outputs.getLength(1); j++ )
      {
         int[] index = { i, j };
         String fullValue = outputs.getValue( index ) + " ft." ;
         withUnits.setValue( index, fullValue );
      }

   // Actually generate a file if we are told to
   if ( mode == PHXRowFieldFile.GENERATE )
      file.generate();
}

try
{
   convertIN(PHXRowFieldFile.READ_TEMPLATE);
   convertOUT(PHXRowFieldFile.READ_TEMPLATE);
}
catch( Exception e )
{
}