コード例 #1
0
        public void LoadModel(string modelFile, string svFile)
        {
            _Models = null;

            if (string.IsNullOrEmpty(modelFile))
            {
                throw new GeoMagExceptionFileNotFound("Error coefficient file name not specified");
            }

            _Models = ModelReader.Read(modelFile, svFile);
        }
コード例 #2
0
        public void SaveResults(string fileName, bool loadAfterSave = false)
        {
            if (ResultsOfCalculation == null)
            {
                throw new GeoMagExceptionModelNotLoaded("Error: No calculation results to save");
            }

            if (ModelReader.IsFileLocked(fileName))
            {
                throw new GeoMagExceptionOpenError(string.Format("Error: The file '{0}' is locked by another user or application",
                                                                 Path.GetFileName(fileName)));
            }

            if (File.Exists(fileName))
            {
                try
                {
                    File.Delete(fileName);
                }
                catch (Exception e)
                {
                    throw new GeoMagExceptionOpenError(string.Format("Error: The file '{0}' could not be deleted: {1}",
                                                                     System.IO.Path.GetFileName(fileName), e.ToString()));
                }
            }

            Int32 lineCount = 0;

            //Int32 lineNumColIdx = -1;

            var tabStrRight = new StringBuilder();

            //Build header



            tabStrRight.AppendFormat("{0}:\t{1}{2}", "Model".PadLeft(15, ' '), Path.GetFileNameWithoutExtension(_Models.Name).ToUpper(), Environment.NewLine);
            lineCount++;

            tabStrRight.AppendFormat("{0}:\t{1}{2}", "latitude".PadLeft(15, ' '), _CalculationOptions.Latitude.ToString("F7"), Environment.NewLine);
            lineCount++;

            tabStrRight.AppendFormat("{0}:\t{1}{2}", "longitude".PadLeft(15, ' '), _CalculationOptions.Longitude.ToString("F7"), Environment.NewLine);
            lineCount++;

            var elevation = _CalculationOptions.GetElevation;

            tabStrRight.AppendFormat("{0}:\t{1}\t{2}{3}", string.Format("{0}", elevation[0]).PadLeft(15, ' '), Convert.ToDouble(elevation[1]).ToString("F4"), elevation[2], Environment.NewLine);
            lineCount++;

            tabStrRight.AppendFormat("{0}", Environment.NewLine);
            lineCount++;

            const Int32 padlen = 25;

            const string rowFormat = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}{8}";

            //Build Column Header

            tabStrRight.AppendFormat(rowFormat,
                                     "Date".PadRight(padlen, ' '), "Declination (+E/W)".PadRight(padlen, ' '), "Inclination (+D/-U)".PadRight(padlen, ' '),
                                     "Horizontal Intensity".PadRight(padlen, ' '), "North Comp (+N/-S)".PadRight(padlen, ' '), "East Comp (+E/-W)".PadRight(padlen, ' '),
                                     "Vertical Comp (+D/-U)".PadRight(padlen, ' '), "Total Field".PadRight(padlen, ' '), Environment.NewLine);
            lineCount++;

            tabStrRight.AppendFormat(rowFormat,
                                     "".PadRight(padlen, ' '), "deg".PadRight(padlen, ' '), "deg".PadRight(padlen, ' '),
                                     "nT".PadRight(padlen, ' '), "nT".PadRight(padlen, ' '), "nT".PadRight(padlen, ' '),
                                     "nT".PadRight(padlen, ' '), "nT".PadRight(padlen, ' '), Environment.NewLine);
            lineCount++;

            tabStrRight.AppendFormat("{0}", Environment.NewLine);
            lineCount++;

            //Build result rows

            foreach (var result in ResultsOfCalculation)
            {
                //Date
                tabStrRight.AppendFormat(rowFormat,
                                         result.Date.ToString("MM/dd/yyyy").PadRight(padlen, ' '), result.Declination.Value.ToString("F3").PadRight(padlen, ' '),
                                         result.Inclination.Value.ToString("F3").PadRight(padlen, ' '), result.HorizontalIntensity.Value.ToString("F2").PadRight(padlen, ' '),
                                         result.NorthComp.Value.ToString("F2").PadRight(padlen, ' '), result.EastComp.Value.ToString("F2").PadRight(padlen, ' '),
                                         result.VerticalComp.Value.ToString("F2").PadRight(padlen, ' '), result.TotalField.Value.ToString("F2").PadRight(padlen, ' '),
                                         Environment.NewLine);

                lineCount++;
            }

            tabStrRight.AppendFormat(rowFormat,
                                     "Change Per year".PadRight(padlen, ' '), ResultsOfCalculation.First().Declination.ChangePerYear.ToString("F3").PadRight(padlen, ' '),
                                     ResultsOfCalculation.First().Inclination.ChangePerYear.ToString("F3").PadRight(padlen, ' '), ResultsOfCalculation.First().HorizontalIntensity.ChangePerYear.ToString("F2").PadRight(padlen, ' '),
                                     ResultsOfCalculation.First().NorthComp.ChangePerYear.ToString("F2").PadRight(padlen, ' '), ResultsOfCalculation.First().EastComp.ChangePerYear.ToString("F2").PadRight(padlen, ' '),
                                     ResultsOfCalculation.First().VerticalComp.ChangePerYear.ToString("F2").PadRight(padlen, ' '), ResultsOfCalculation.First().TotalField.ChangePerYear.ToString("F2").PadRight(padlen, ' '),
                                     Environment.NewLine);

            // Write the stream contents to a text fle
            using (StreamWriter outFile = File.AppendText(fileName))
            {
                outFile.Write(tabStrRight.ToString());
            }
        }