/// <summary>
        /// Check the Name and Alias properties of the given Raster Function Variable to see
        /// if they contain a reference to a field and get the value of the corresponding field if needed.
        /// </summary>
        /// <param name="rasterFunctionVar">The Raster Function Variable to check.</param>
        /// <param name="pRow">The row corresponding to the function raster dataset.</param>
        /// <returns></returns>
        private object FindPropertyInRow(IRasterFunctionVariable rasterFunctionVar, IRow pRow)
        {
            string       varName  = "";
            IStringArray varNames = new StrArrayClass();

            varName = rasterFunctionVar.Name;
            // If the name of  the variable contains '@Field'
            if (varName.Contains("@Field."))
            {
                varNames.Add(varName); // Add it to the list of names.
            }
            // Check the aliases of the variable
            for (int i = 0; i < rasterFunctionVar.Aliases.Count; ++i)
            {
                // Check the list of aliases for the '@Field' string
                varName = rasterFunctionVar.Aliases.get_Element(i);
                if (varName.Contains("@Field."))
                {
                    varNames.Add(varName); // and add any that are found to the list of names.
                }
            }

            // Use the list of names and find the value by looking up the appropriate field.
            for (int i = 0; i < varNames.Count; ++i)
            {
                // Get the variable name containing the field string
                varName = varNames.get_Element(i);
                // Replace the '@Field' with nothing to get just the name of the field.
                string  fieldName = varName.Replace("@Field.", "");
                IFields rowFields = pRow.Fields;
                // Look up the index of the field name in the row.
                int fieldIndex = rowFields.FindField(fieldName);
                // If it is a valid index and the field type is string, return the value.
                if (fieldIndex != -1 &&
                    ((rowFields.get_Field(fieldIndex)).Type == esriFieldType.esriFieldTypeString))
                {
                    return(pRow.get_Value(fieldIndex));
                }
            }
            // If no value has been returned yet, return null.
            return(null);
        }
 /// <summary>
 /// Sets band properties on a given dataset including stats, band names and wavelengths.
 /// </summary>
 /// <param name="dataset">The dataset to set properties on.</param>
 /// <param name="dimParser">Dimap parser to read properties from.</param>
 private void SetBandProperties(IDataset dataset, DiMapParser dimParser)
 {
     try
     {
         // Set band band props.
         IRasterKeyProperties rasterKeyProps = (IRasterKeyProperties)dataset;
         IRasterBandCollection rasterBandColl = (IRasterBandCollection)dataset;
         int imageNumBands = ((IFunctionRasterDataset)dataset).RasterInfo.BandCount;
         int dinNumBands = dimParser.NumBands;
         int[] bandIndexes = new int[dinNumBands];
         IStringArray bandNames = new StrArrayClass();
         for (int i = 0; i < dinNumBands; ++i)
         {
             // Get band index for the first band.
             bandIndexes[i] = Convert.ToInt16(dimParser.GetBandIndex(i));
             // Validate band index.
             if (bandIndexes[i] > 0 && bandIndexes[i] <= imageNumBands)
             {
                 // Get Band Name for the index.
                 bandNames.Add(dimParser.GetBandDesc(bandIndexes[i]));
                 // Get Band stats for the index.
                 IRasterStatistics bandStats = new RasterStatisticsClass();
                 bandStats.Minimum = Convert.ToDouble(dimParser.GetBandStatMin(bandIndexes[i]));
                 bandStats.Maximum = Convert.ToDouble(dimParser.GetBandStatMax(bandIndexes[i]));
                 bandStats.Mean = Convert.ToDouble(dimParser.GetBandStatMean(bandIndexes[i]));
                 bandStats.StandardDeviation = Convert.ToDouble(dimParser.GetBandStatStdDev(bandIndexes[i]));
                 // Set stats on the dataset.
                 ((IRasterBandEdit2)rasterBandColl.Item(bandIndexes[i] - 1)).AlterStatistics(bandStats);
                 // Set Band Name and wavelengths according to the name.
                 rasterKeyProps.SetBandProperty("BandName", (bandIndexes[i] - 1), bandNames.get_Element(i));
                 SetBandWavelengths(dataset, (bandIndexes[i] - 1));
                 // Refresh dataset so changes are saved.
                 ((IRasterDataset3)dataset).Refresh();
             }
         }
     }
     catch (Exception exc)
     {
         string error = exc.Message;
     }
 }
        /// <summary>
        /// Check the Name and Alias properties of the given Raster Function Variable to see
        /// if they contain a reference to a field and get the value of the corresponding field if needed.
        /// </summary>
        /// <param name="rasterFunctionVar">The Raster Function Variable to check.</param>
        /// <param name="pRow">The row corresponding to the function raster dataset.</param>
        /// <returns></returns>
        private object FindPropertyInRow(IRasterFunctionVariable rasterFunctionVar, IRow pRow)
        {
            string varName = "";
            IStringArray varNames = new StrArrayClass();
            varName = rasterFunctionVar.Name;
            // If the name of  the variable contains '@Field'
            if (varName.Contains("@Field."))
                varNames.Add(varName); // Add it to the list of names.
            // Check the aliases of the variable
            for (int i = 0; i < rasterFunctionVar.Aliases.Count; ++i)
            {
                // Check the list of aliases for the '@Field' string
                varName = rasterFunctionVar.Aliases.get_Element(i);
                if (varName.Contains("@Field."))
                    varNames.Add(varName); // and add any that are found to the list of names.
            }

            // Use the list of names and find the value by looking up the appropriate field.
            for (int i = 0; i < varNames.Count; ++i)
            {
                // Get the variable name containing the field string
                varName = varNames.get_Element(i);
                // Replace the '@Field' with nothing to get just the name of the field.
                string fieldName = varName.Replace("@Field.", "");
                IFields rowFields = pRow.Fields;
                // Look up the index of the field name in the row.
                int fieldIndex = rowFields.FindField(fieldName);
                // If it is a valid index and the field type is string, return the value.
                if (fieldIndex != -1 &&
                   ((rowFields.get_Field(fieldIndex)).Type == esriFieldType.esriFieldTypeString))
                    return pRow.get_Value(fieldIndex);
            }
            // If no value has been returned yet, return null.
            return null;
        }