/// <summary>
        /// Read in EarLab .metadata parameter file and store appropriate values to local variables
        /// </summary>
        private void ReadMetaDataFile(string fileName)
        {
            DataSet xmlDataSet = ReaderWriterXMLMetadata.Read(fileName);

            if (xmlDataSet != null)
            {
                this.minimumSample = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MinValue"];
                this.maximumSample = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MaxValue"];
                this.sampleRate    = (double)xmlDataSet.Tables["Parameters"].Rows[0]["SampleRate_Hz"];
                this.xStart        = (double)xmlDataSet.Tables["Parameters"].Rows[0]["LagMin_uS"];
                this.xEnd          = (double)xmlDataSet.Tables["Parameters"].Rows[0]["LagMax_uS"];

                this.xDimension = (long)xmlDataSet.Tables["Dimension"].Select("Name = 'Lag'")[0]["Value"];
                this.yDimension = (long)xmlDataSet.Tables["Dimension"].Select("Name = 'Frequency'")[0]["Value"];
                this.zDimension = (long)xmlDataSet.Tables["Dimension"].Select("Name = 'Time'")[0]["Value"];
            }
            else
            {
                throw new Exception("XMLMetadataReaderWriter.Read(fileName): Incorrect EarLab .metadata file format.");
            }

            this.yStart = this.zStart = 0;
            this.yEnd   = yDimension - 1;
            this.zEnd   = zDimension - 1;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read in EarLab .metadata parameter file and store appropriate values to local variables
        /// </summary>
        private void ReadMetaDataFile(string fileName)
        {
            DataSet xmlDataSet = ReaderWriterXMLMetadata.Read(fileName);

            if (xmlDataSet != null)
            {
                this.minimumSample = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MinValue"];
                this.maximumSample = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MaxValue"];
                this.sampleRate    = (double)xmlDataSet.Tables["Parameters"].Rows[0]["SampleRate_Hz"];
                this.timeDimension = (long)xmlDataSet.Tables["Dimension"].Select("Name = 'Time'")[0]["Value"];
                this.freqDimension = (long)xmlDataSet.Tables["Dimension"].Select("Name = 'Frequency'")[0]["Value"];

                long fileLength;
                try
                {
                    fileLength = new FileInfo(fileName.Replace(".metadata", ".binary")).Length;
                }
                catch
                {
                    throw new Exception("ReaderWriterFrequencyTime.ReadMetaDataFile(): EarLab Data (.binary) file not found.");
                }

                if (this.timeDimension * this.freqDimension * FLOAT_BYTES != fileLength)
                {
                    throw new Exception("ReaderWriterFrequencyTime.ReadMetaDataFile(): Incorrect EarLab Metadata (.metadata) file vs Data (.binary) file.");
                }
            }
            else
            {
                throw new Exception("XMLMetadataReaderWriter.Read(fileName): Incorrect EarLab .metadata file format.");
            }
        }
Exemplo n.º 3
0
        public static EarLabBinaryFileType GetBinaryFileType(string fileName)
        {
            DataSet xmlDataSet = ReaderWriterXMLMetadata.Read(fileName);

            if (xmlDataSet == null)
            {
                return(EarLabBinaryFileType.Unknown);
            }

            if (xmlDataSet.Tables["Parameters"].Rows[0]["FileType"].ToString() == "Time")
            {
                return(EarLabBinaryFileType.Time);
            }
            if (xmlDataSet.Tables["Parameters"].Rows[0]["FileType"].ToString() == "FrequencyTime")
            {
                return(EarLabBinaryFileType.FrequencyTime);
            }
            else
            {
                return(EarLabBinaryFileType.LagFrequencyTime);
            }
        }
Exemplo n.º 4
0
        private string ReadMetaDataFile(string fileName)
        {
            DataSet xmlDataSet;

            try
            {
                xmlDataSet = ReaderWriterXMLMetadata.Read(fileName);
            }
            catch (Exception e)
            {
                return(e.Message.ToString());
            }

            if (xmlDataSet != null)
            {
                // store the min/max values
                this.minimumValue = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MinimumValue"];
                this.maximumValue = (double)xmlDataSet.Tables["Parameters"].Rows[0]["MaximumValue"];
                this.unitsString  = (string)xmlDataSet.Tables["Parameters"].Rows[0]["Units"];

                // read in the dimensions, store them, and sort them so that they are ordered
                this.dimensionsArray = new Dimension[xmlDataSet.Tables["Dimension"].Rows.Count];
                int[] indexArray = new int[this.dimensionsArray.Length];
                for (int i = 0; i < this.dimensionsArray.Length; i++)
                {
                    this.dimensionsArray[i].Name  = (string)xmlDataSet.Tables["Dimension"].Rows[i]["Name"];
                    this.dimensionsArray[i].Size  = (long)xmlDataSet.Tables["Dimension"].Rows[i]["Size"];
                    this.dimensionsArray[i].Index = int.Parse(xmlDataSet.Tables["Dimension"].Rows[i]["Index"].ToString());
                    DataRow axisRow = xmlDataSet.Tables["Dimension"].Rows[i].GetChildRows("Dimension_Axis")[0];
                    if (axisRow.GetChildRows("Axis_Auto").Length > 0)
                    {
                        DataRow autoRow = axisRow.GetChildRows("Axis_Auto")[0];
                        this.dimensionsArray[i].Start = (double)autoRow["StartValue"];
                        this.dimensionsArray[i].End   = (double)autoRow["EndValue"];
                    }
                    else
                    {
                        DataRow[] arrayRows   = axisRow.GetChildRows("Axis_Array")[0].GetChildRows("Array_Element");
                        int[]     index2Array = new int[arrayRows.Length];
                        this.dimensionsArray[i].ElementArray = new double[arrayRows.Length];
                        for (int j = 0; j < arrayRows.Length; j++)
                        {
                            index2Array[j] = (int)arrayRows[j]["Index"];
                            this.dimensionsArray[i].ElementArray[j] = (double)arrayRows[j]["Value"];
                        }
                        Array.Sort(index2Array, this.dimensionsArray[i].ElementArray);

                        this.dimensionsArray[i].Start = 0;
                        this.dimensionsArray[i].End   = (double)(arrayRows.Length - 1);
                    }
                    indexArray[i] = this.dimensionsArray[i].Index;
                }
                Array.Sort(indexArray, this.dimensionsArray);

                // check to make sure that the dimensions in the metadata line up with binary file length
                long fileLength;
                try
                {
                    fileLength = new FileInfo(fileName.Replace(".metadata", ".binary")).Length;
                }
                catch
                {
                    return("EarLab Data file could not be opened or read successfully.");
                }
                long tempLength = 1;
                foreach (Dimension dimension in this.dimensionsArray)
                {
                    tempLength *= dimension.Size;
                }
                tempLength *= FLOAT_BYTES;
                if (tempLength != fileLength)
                {
                    return("Incorrect EarLab Metadata dimension values vs EarLab Data file length.");
                }

                return("0");
            }
            else
            {
                return("Incorrect EarLab Metadata file format.  Please verify file contents.");
            }
        }