/// <summary>
            /// Writes a Pac1 file. [Useable by scripts and interface components alike.]
            /// </summary>
            /// <param name="filename">The location of the final saved file...</param>
            /// <param name="Direct_Data">Array of Completed Direct Sound Simulations Required</param>
            /// <param name="IS_Data">Array of Completed Image Source Simulations. Enter null if opted out.</param>
            /// <param name="Receiver">Array of Completed Ray-Tracing Simulation Receivers. Enter null if opted out.</param>
            public static void Write_Pac1(string filename, ref Direct_Sound[] Direct_Data, ref ImageSourceData[] IS_Data, ref Environment.Receiver_Bank[] Receiver)
            {
                if (Direct_Data == null && IS_Data == null && IS_Data == null && Receiver != null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no simulated data to save.");
                    return;
                }

                Pachyderm_Acoustic.UI.PachydermAc_PlugIn plugin = Pachyderm_Acoustic.UI.PachydermAc_PlugIn.Instance;

                //use StreamWriter to write to csv files
                System.IO.StreamWriter sw = System.IO.File.CreateText(filename);

                //1. Date & Time
                sw.WriteLine("Current Date and Time");
                sw.WriteLine(System.DateTime.Now.ToString());

                //2. Plugin Version... if less than 1.1, assume only 1 source.
                sw.WriteLine("Plugin Version");
                sw.WriteLine(plugin.Version);

                //3. Cut off Time (seconds) and SampleRate
                sw.WriteLine("Cut off Time");
                sw.WriteLine((double)Receiver[0].CO_Time);//CO_TIME.Value);
                sw.WriteLine("Sample Rate");
                sw.WriteLine(Receiver[0].SampleRate);

                //4.0 Source Count(int)
                Rhino.Geometry.Point3d[] SRC;
                plugin.SourceOrigin(out SRC);
                sw.WriteLine("Source Count");
                sw.WriteLine(SRC.Length);

                //4 Source Location x,y,z (double)
                sw.WriteLine("Source Location : x y z");
                for (int i = 0; i < SRC.Length; i++)
                {
                    sw.WriteLine(Helper_Functions.ConvertToCSVString(SRC[i].X, SRC[i].Y, SRC[i].Z));
                }

                //5. No of Receivers
                sw.WriteLine("Number of Receivers");
                sw.WriteLine(Receiver[0].Rec_List.Length);

                //6. Write the coordinates of each receiver point
                //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                for (int q = 0; q < Receiver[0].Rec_List.Length; q++)
                {
                    string origin_and_rhoC = Helper_Functions.ConvertToCSVString(
                        Receiver[0].Rec_List[q].H_Origin.x,
                        Receiver[0].Rec_List[q].H_Origin.y,
                        Receiver[0].Rec_List[q].H_Origin.z,
                        Receiver[0].Rec_List[q].Rho_C);
                    sw.WriteLine(origin_and_rhoC);
                }

                for (int s = 0; s < SRC.Length; s++)
                {
                    if (Direct_Data != null)
                    {
                        //7. Write Direct Sound Data
                        Direct_Data[s].Write_Data(ref sw);
                    }

                    if (IS_Data[0] != null)
                    {
                        //8. Write Image Source Sound Data
                        IS_Data[s].Write_Data(ref sw);
                    }

                    if (Receiver != null)
                    {
                        //9. Write Ray Traced Sound Data
                        Receiver[s].Write_Data(ref sw);
                    }
                }
                sw.Write("End");
                sw.Close();
            }
            /// <summary>
            /// Writes pachyderm mapping file.
            /// </summary>
            /// <param name="filename">The location the new file is to be written to.</param>
            /// <param name="Rec_List">The list of receivers to be written.</param>
            public static void Write_pachm(string filename, ref Mapping.PachMapReceiver[] Rec_List)
            {
                // use Streamwriter to write to csv files
                System.IO.StreamWriter sw = System.IO.File.CreateText(filename);
                //1. Write calculation type. (string)
                sw.WriteLine("Calculation Tyle:");
                sw.WriteLine(Rec_List[0].Data_Type());
                Boolean Directional = Rec_List[0].Data_Type() == "Type;Map_Data";

                //2. Write the number of samples in each histogram. (int)
                sw.WriteLine("Number of samples in each histogram:");
                sw.WriteLine((UInt32)Rec_List[0].SampleCT);
                //3. Write the sample rate. (int)
                sw.WriteLine("Sample Rate:");
                sw.WriteLine((UInt32)Rec_List[0].SampleRate);
                //4. Write the number of Receivers (int)
                int Rec_Ct = Rec_List[0].Rec_List.Length;

                sw.WriteLine("Number of Receivers:");
                sw.WriteLine((UInt32)Rec_Ct);
                //4.5 Announce the Version
                sw.WriteLine("Version");
                sw.WriteLine(UI.PachydermAc_PlugIn.Instance.Version);
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                sw.WriteLine("Mesh Information:");
                //6. Announce Mesh Vertices (string)
                sw.WriteLine("Mesh Vertices:");
                //Write the number of vertices (int) (int)
                sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Vertices.Count);

                for (int i = 0; i < Rec_List[0].Map_Mesh.Vertices.Count; i++)
                {
                    //Write Vertex: (double) (double) (double)

                    /*sw.WriteLine(Rec_List[0].Map_Mesh.Vertices[i].X);
                     * sw.WriteLine(Rec_List[0].Map_Mesh.Vertices[i].Y);
                     * sw.WriteLine(Rec_List[0].Map_Mesh.Vertices[i].Z); */
                    string meshvertice = Helper_Functions.ConvertToCSVString(
                        Rec_List[0].Map_Mesh.Vertices[i].X,
                        Rec_List[0].Map_Mesh.Vertices[i].Y,
                        Rec_List[0].Map_Mesh.Vertices[i].Z);
                    sw.WriteLine(meshvertice);
                }
                //7. Announce Mesh Faces (string)
                sw.WriteLine("Mesh Faces:");
                // Write the number of faces
                sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Faces.Count);

                for (int i = 0; i < Rec_List[0].Map_Mesh.Faces.Count; i++)
                {
                    // Write mesh vertex indices: (int) (int) (int) (int)

                    /*sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Faces[i][0]);
                    *  sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Faces[i][1]);
                    *  sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Faces[i][2]);
                    *  sw.WriteLine((UInt32)Rec_List[0].Map_Mesh.Faces[i][3]);*/
                    string meshfaces = Helper_Functions.ConvertToCSVString(
                        (UInt32)Rec_List[0].Map_Mesh.Faces[i][0],
                        (UInt32)Rec_List[0].Map_Mesh.Faces[i][1],
                        (UInt32)Rec_List[0].Map_Mesh.Faces[i][2],
                        (UInt32)Rec_List[0].Map_Mesh.Faces[i][3]);
                    sw.WriteLine(meshfaces);
                }
                //7.5: Announce the number of sources.
                //sw.WriteLine("Sources");
                sw.WriteLine("Number of Receivers:");
                sw.WriteLine(Rec_List.Length);
                //7.5a: Announce the Type of Source
                sw.WriteLine("Source Coordinate, Type, and delaytime in ms:");
                for (int i = 0; i < Rec_List.Length; i++)
                {
                    /*
                     * sw.WriteLine(Rec_List[i].Src.X);
                     * sw.WriteLine(Rec_List[i].Src.Y);
                     * sw.WriteLine(Rec_List[i].Src.Z);
                     * //////////////////////*/
                    sw.WriteLine(Helper_Functions.ConvertToCSVString(Rec_List[i].Src.X, Rec_List[i].Src.Y, Rec_List[i].Src.Z));
                    sw.WriteLine(Rec_List[i].SrcType);
                    sw.WriteLine(Rec_List[i].delay_ms);//v.2.0.0.1
                }

                //8. Announce that the following data pertains to the receiver histograms (string)
                sw.WriteLine("Receiver Hit Data:");
                //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                sw.WriteLine("True: data is linked to vertices; False:data is linked to faces;");
                sw.WriteLine(Rec_List[0].Rec_Vertex);
                // this part need to be rewritten for readability//
                for (int s = 0; s < Rec_List.Length; s++)
                {
                    for (int i = 0; i < Rec_Ct; i++)
                    {
                        //Write Receiver Index (int), direct sound arrival time,Impedance of Air
                        sw.WriteLine("Receiver Index, Direct Sound Arrival Time, Air Impedance:");
                        sw.WriteLine(Helper_Functions.ConvertToCSVString((UInt32)i, (Rec_List[s].Rec_List[i] as Mapping.PachMapReceiver.Map_Receiver).Direct_Time, Rec_List[0].Rec_List[i].Rho_C));

                        sw.WriteLine("Octave band; energy histogram of each receiver:");
                        for (int Octave = 0; Octave < 8; Octave++)
                        {
                            double[] Hist = Rec_List[s].Rec_List[i].GetEnergyHistogram(Octave);
                            //directional or not directional
                            string temp = (UInt32)Octave + ",";
                            for (int e = 0; e < Rec_List[s].SampleCT; e++)
                            {
                                //foreach should be here
                                foreach (double histe in Hist)
                                {
                                    if (Directional)
                                    {
                                        //Write octave band (int); each directional value in the histogram (double) (double) (double), and each energy value in the histogram (double)
                                        Hare.Geometry.Vector DirPos = Rec_List[s].Directions_Pos(Octave, e, i);
                                        Hare.Geometry.Vector DirNeg = Rec_List[s].Directions_Neg(Octave, e, i);
                                        temp += Helper_Functions.ConvertToCSVString(
                                            DirPos.x, DirPos.y, DirPos.z,
                                            DirNeg.x, DirNeg.y, DirNeg.z);
                                        temp += ",";
                                        temp += Hist[e];
                                        temp += ",";

                                        /*sw.Write(Helper_Functions.ConvertToCSVString((UInt32)Octave, (Hist[e])));
                                         * sw.WriteLine(Helper_Functions.ConvertToCSVString(
                                         *  DirPos.x, DirPos.y, DirPos.z,
                                         *  DirNeg.x, DirNeg.y, DirNeg.z));*/
                                    }
                                    else
                                    {
                                        //Write Octave (int) & each energy value in the histogram (double)...
                                        //sw.WriteLine(Helper_Functions.ConvertToCSVString((UInt32)Octave, (Hist[e])));
                                        {
                                            temp += Hist[e];
                                            temp += ",";
                                        }
                                    }
                                }
                            }
                            sw.WriteLine(temp);
                        }
                        sw.WriteLine("End_Receiver_Hits");
                    }
                }
                sw.WriteLine("End_of_File");
                sw.Close();
            }