示例#1
0
        // End ReadFileProperties

        public static void WriteFileProperties(SALSAFileProperties FileProps, StreamWriter sw)
        {
            sw.WriteLine(String.Format("FileProperties\tLocalVectorDimension:{0}", FileProps.LocalVectorDimension));
            sw.WriteLine(String.Format("FileProperties\tClusterStartIndex:{0}", FileProps.ClusterStartIndex));
            sw.WriteLine(String.Format("FileProperties\tOriginalPointStartIndex:{0}", FileProps.OriginalPointStartIndex));
            sw.WriteLine(String.Format("FileProperties\tLocalPointStartIndex:{0}", FileProps.LocalPointStartIndex));
            sw.WriteLine(String.Format("FileProperties\tFileGenerationType:{0}", FileProps.FileGenerationType));
            sw.WriteLine(String.Format("FileProperties\tFamilyName1:{0}", FileProps.FamilyName1));
            sw.WriteLine(String.Format("FileProperties\tFamilyName2:{0}", FileProps.FamilyName2));
            sw.WriteLine(String.Format("FileProperties\tGroupName:{0}", FileProps.GroupName));
            sw.WriteLine(String.Format("FileProperties\tClusterName:{0}", FileProps.ClusterName));
            sw.WriteLine(String.Format("FileProperties\tNumberOriginalPoints:{0}", FileProps.NumberOriginalPoints));
            sw.WriteLine(String.Format("FileProperties\tNumberPointsinFile:{0}", FileProps.NumberPointsinFile));
            sw.WriteLine(String.Format("FileProperties\tRotationParameters:{0}", FileProps.RotationParameters));
            sw.WriteLine(String.Format("FileProperties\tNumberRotationParameters:{0}",
                                       FileProps.NumberRotationParameters));

            string FileComments = FileProps.Comment;

            if (FileComments != "")
            {
                string[] split = FileComments.Split(new[] { '\n' });
                for (int runthroughcomments = 0; runthroughcomments < split.Length; runthroughcomments++)
                {
                    if (split[runthroughcomments] != "")
                    {
                        sw.WriteLine(String.Format("FileProperties\tComment:{0}", split[runthroughcomments]));
                    }
                }
            }
            return;
        }
示例#2
0
        // End ArrayInitializer

        // Write label-cluster results into a file
        public static void WriteDataPointFile(string CoreOutputFileName, bool write2Das3D, string OutputStyles,
                                              SALSAFileProperties FileProperties, SALSADataPointProperties[] DataPoints,
                                              int NumberofDataPoints)
        {
            var DothisOutputStyle = new bool[5];

            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                DothisOutputStyle[StyleIndex] = false;
                if (OutputStyles.Contains("all"))
                {
                    DothisOutputStyle[StyleIndex] = true;
                }
            }
            if (OutputStyles.Contains("colon"))
            {
                DothisOutputStyle[0] = true;
            }
            if (OutputStyles.Contains("family1"))
            {
                DothisOutputStyle[1] = true;
            }
            if (OutputStyles.Contains("family2"))
            {
                DothisOutputStyle[2] = true;
            }
            if (OutputStyles.Contains("cluster"))
            {
                DothisOutputStyle[3] = true;
            }
            if (OutputStyles.Contains("group"))
            {
                DothisOutputStyle[4] = true;
            }

            bool setgroup     = false;
            bool OutputValues = false;

            SALSADataPointProperties FirstOne = DataPoints[0];

            if (FirstOne.family1 < 0)
            {
                DothisOutputStyle[1] = false;
            }
            if (FirstOne.family2 < 0)
            {
                DothisOutputStyle[2] = false;
            }
            if (FirstOne.cluster < 0)
            {
                DothisOutputStyle[3] = false;
            }
            if (FirstOne.group < 0)
            {
                DothisOutputStyle[4] = false;
            }
            if ((FirstOne.family1 < 0) && (FirstOne.family2 < 0) && (FirstOne.cluster < 0) && (FirstOne.group < 0))
            {
                DothisOutputStyle[4] = true;
                setgroup             = true;
            }
            if (FirstOne.valuesset)
            {
                OutputValues = true;
            }
            int LocalVectorDimension = FileProperties.LocalVectorDimension;
            int LocalPointIncrement  = FileProperties.LocalPointStartIndex;

            int numberoffiles = 0;

            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                if (DothisOutputStyle[StyleIndex])
                {
                    ++numberoffiles;
                }
            }
            if (numberoffiles == 0)
            {
                SALSAUtility.SALSAError("No files output for core name " + CoreOutputFileName);
                return;
            }
            if (numberoffiles > 1)
            {
                if (OutputStyles.Contains("SameFileName"))
                {
                    Exception e =
                        SALSAUtility.SALSAError("Attempt to generate multiple outputs to same file " +
                                                CoreOutputFileName);
                    throw (e);
                }
            }
            for (int StyleIndex = 0; StyleIndex < 5; StyleIndex++)
            {
                if (!DothisOutputStyle[StyleIndex])
                {
                    continue;
                }
                string OutputFileName = "";
                if (!OutputStyles.Contains("SameFileName"))
                {
                    if (StyleIndex == 0)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Colon.txt");
                    }
                    if (StyleIndex == 1)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Family1.txt");
                    }
                    if (StyleIndex == 2)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Family2.txt");
                    }
                    if (StyleIndex == 3)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Cluster.txt");
                    }
                    if (StyleIndex == 4)
                    {
                        OutputFileName = CoreOutputFileName.Replace(".txt", "Group.txt");
                    }
                }
                else
                {
                    OutputFileName = CoreOutputFileName;
                }

                try
                {
                    StreamWriter sw = null;
                    if (!string.IsNullOrEmpty(OutputFileName))
                    {
                        sw = new StreamWriter(OutputFileName, false, Encoding.UTF8);
                    }
                    if (sw != null)
                    {
                        if (StyleIndex == 0)
                        {
                            WriteFileProperties(FileProperties, sw); // Write Header of a Colon File
                        }
                        for (int GlobalDataPoint = 0; GlobalDataPoint < NumberofDataPoints; GlobalDataPoint++)
                        {
                            SALSADataPointProperties ThesePointProperties = DataPoints[GlobalDataPoint];
                            if ((LocalVectorDimension == 2) && write2Das3D && OutputValues)
                            {
                                ThesePointProperties.z    = 0.0;
                                ThesePointProperties.zerr = 0.0;
                            }
                            if (StyleIndex == 0)
                            {
                                string OutputLine = "";
                                AppendDataPointProperties(ThesePointProperties, ref OutputLine);
                                sw.WriteLine(OutputLine);
                                continue;
                            }
                            int IntegerIndex = 0;
                            if (StyleIndex == 1)
                            {
                                IntegerIndex = ThesePointProperties.family1;
                            }
                            if (StyleIndex == 2)
                            {
                                IntegerIndex = ThesePointProperties.family2;
                            }
                            if (StyleIndex == 3)
                            {
                                IntegerIndex = ThesePointProperties.cluster;
                            }
                            if (StyleIndex == 4)
                            {
                                IntegerIndex = ThesePointProperties.group;
                                if (setgroup)
                                {
                                    IntegerIndex = 1;
                                }
                            }
                            string Coordinates = "";
                            if (OutputValues)
                            {
                                Coordinates = ThesePointProperties.x.ToString("E4") + "\t" +
                                              ThesePointProperties.y.ToString("E4") + "\t";
                                if ((LocalVectorDimension == 3) || write2Das3D)
                                {
                                    Coordinates += ThesePointProperties.z.ToString("E4") + "\t";
                                }
                            }
                            sw.WriteLine(
                                String.Format((GlobalDataPoint + LocalPointIncrement).ToString() + "\t" + Coordinates +
                                              IntegerIndex.ToString()));
                        }

                        sw.Flush();
                        sw.Close();
                    }
                }
                catch
                {
                    Exception e = SALSAUtility.SALSAError(" Failed to Write Properties File " + CoreOutputFileName);
                    throw (e);
                }
            } // End Loop over File Types
            return;
        }
示例#3
0
        // End WriteDataPointFile


        public static void ReadFileProperties(SALSAFileProperties FileProps, string InputLine)
        {
            InputLine = InputLine.Trim(new[] { ' ', '\t' });
            string[] colonsplit = InputLine.Split(new[] { ':' }, 2);
            if (colonsplit.Length < 2)
            {
                Console.WriteLine("No deliminator in Line " + InputLine);
                return;
            }
            colonsplit[0] = colonsplit[0].Trim();
            colonsplit[1] = colonsplit[1].Trim();
            if (colonsplit[0].Equals("LocalVectorDimension"))
            {
                FileProps.LocalVectorDimension = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("ClusterStartIndex"))
            {
                FileProps.ClusterStartIndex = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("OriginalPointStartIndex"))
            {
                FileProps.OriginalPointStartIndex = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("LocalPointStartIndex"))
            {
                FileProps.LocalPointStartIndex = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("FileGenerationType"))
            {
                FileProps.FileGenerationType = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("FamilyName1"))
            {
                FileProps.FamilyName1 = colonsplit[1];
            }
            if (colonsplit[0].Equals("FamilyName2"))
            {
                FileProps.FamilyName2 = colonsplit[1];
            }
            if (colonsplit[0].Equals("GroupName"))
            {
                FileProps.GroupName = colonsplit[1];
            }
            if (colonsplit[0].Equals("ClusterName"))
            {
                FileProps.ClusterName = colonsplit[1];
            }
            if (colonsplit[0].Equals("NumberOriginalPoints"))
            {
                FileProps.NumberOriginalPoints = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("NumberPointsinFile"))
            {
                FileProps.NumberPointsinFile = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("RotationParameters"))
            {
                FileProps.RotationParameters = colonsplit[1];
            }
            if (colonsplit[0].Equals("NumberRotationParameters"))
            {
                FileProps.NumberRotationParameters = Convert.ToInt32(colonsplit[1]);
            }
            if (colonsplit[0].Equals("Comment"))
            {
                if (FileProps.Comment != "")
                {
                    FileProps.Comment += "\n";
                }
                FileProps.Comment += colonsplit[1];
            }
            return;
        }
示例#4
0
        public static bool ReadDataPointFile(string MDSClusterFileName, ref int FileType,
                                             SALSAFileProperties FileProperties,
                                             ref SALSADataPointProperties[] DataPoints, ref int NumberofPoints)
        {
            // FileType = 0 simple integers and positions:  PointNumber x y z LABEL or Group Number (LABEL if file name contains label)
            // FileType = 1 Just integers -- Point Number and Group Number: PointNumber  Group Number
            // File Type = 2 Integer and Label: Point LABEL (LABEL if file name contains label)
            // File Type = 3 Pure colon style -- with  positions
            // File Type = 4 Pure Colon Style -- no    positions
            // File Type = 5 Pure Colon Style --    Labels
            // File Type = 6 Hybrid Style --     with positions
            // File Type = 7 Hybrid Style --     no positions
            // File Type = 8 Hybrid Style --     Labels


            bool   positionsset   = false;
            bool   colonsinput    = false;
            bool   NonColonsInput = false;
            bool   labelfile      = false;
            string LowerFileName  = MDSClusterFileName.ToLower();

            if (LowerFileName.Contains("label"))
            {
                labelfile = true;
            }

            NumberofPoints = 0;

            try
            {
                // Check if file exists
                if (!File.Exists(MDSClusterFileName))
                {
                    Exception e = SALSAUtility.SALSAError("File " + MDSClusterFileName + " does not exists");
                    throw (e);
                }

                // Create a new stream to read from a file
                using (StreamReader sr = File.OpenText(MDSClusterFileName))
                {
                    // Read contents of a file
                    String inputLineStr;
                    int    newlabelnumber = -1;
                    int    LocalStart     = FileProperties.LocalPointStartIndex;
                    int    OriginalStart  = FileProperties.OriginalPointStartIndex;
                    while ((inputLineStr = sr.ReadLine()) != null)
                    {
                        if (inputLineStr.Length < 2)
                        {
                            continue; //replace empty line
                        }

                        inputLineStr = inputLineStr.Trim(new[] { ' ', '\t' });
                        try
                        {
                            // Parse each record string
                            inputLineStr = inputLineStr.Replace("\t\t", "\t");

                            if (inputLineStr.Contains("FileProperties"))
                            {
                                // Not a Data Point
                                string EndofInput = inputLineStr.Replace("FileProperties", "");
                                ReadFileProperties(FileProperties, EndofInput);
                                colonsinput   = true;
                                LocalStart    = FileProperties.LocalPointStartIndex;
                                OriginalStart = FileProperties.OriginalPointStartIndex;
                            }
                            else
                            {
                                // Must be a Data Point
                                ArrayInitializer(ref DataPoints, SALSAUtility.NumberOriginalPoints,
                                                 FileProperties.NumberPointsinFile);
                                DataPoints[NumberofPoints] = new SALSADataPointProperties();
                                bool incrementcount  = false;
                                int  PointDataStarts = inputLineStr.IndexOf("PointProperties");
                                if (PointDataStarts >= 0)
                                {
                                    // Some Colon Information
                                    string EndofInput = inputLineStr.Substring(PointDataStarts);
                                    EndofInput = EndofInput.Replace("PointProperties", "");
                                    ReadDataPointProperties(DataPoints[NumberofPoints], EndofInput);
                                    colonsinput = true;
                                    if (DataPoints[NumberofPoints].valuesset)
                                    {
                                        positionsset = true;
                                    }
                                    incrementcount = true;
                                    DataPoints[NumberofPoints].LocalPointNumber = NumberofPoints +
                                                                                  FileProperties.LocalPointStartIndex;
                                } //  End Processing Colon Point Information

                                if (PointDataStarts < 0)
                                {
                                    // traditional bare line
                                    PointDataStarts = inputLineStr.Length;
                                }
                                if (PointDataStarts > 0)
                                {
                                    // Process number information
                                    string StartofString = inputLineStr.Substring(0, PointDataStarts);
                                    StartofString = StartofString.Trim(new[] { ' ', '\t' });

                                    if (StartofString.Length > 0)
                                    {
                                        // You come here only for traditional bare line of x,y,z coordinates.

                                        string[] split = StartofString.Split(new[] { ' ', '\t' },
                                                                             StringSplitOptions.RemoveEmptyEntries);

                                        if ((split.Length != 5) && (split.Length != 2) && (split.Length != 4))
                                        {
                                            Exception e =
                                                SALSAUtility.SALSAError(" Bad Line " + split.Length.ToString() + " "
                                                                        + NumberofPoints.ToString() + " " + inputLineStr);
                                            throw (e);
                                        }
                                        newlabelnumber = Convert.ToInt32(split[0]);

                                        if ((NumberofPoints + LocalStart) != newlabelnumber)
                                        {
                                            Exception e =
                                                SALSAUtility.SALSAError("Unexpected Label Number " + newlabelnumber +
                                                                        " Expected "
                                                                        + NumberofPoints.ToString() + " + " +
                                                                        LocalStart.ToString());
                                            throw (e);
                                        }
                                        if (DataPoints[NumberofPoints].LocalPointNumber >= 0)
                                        {
                                            if ((DataPoints[NumberofPoints].LocalPointNumber - LocalStart) !=
                                                NumberofPoints)
                                            {
                                                Exception e =
                                                    SALSAUtility.SALSAError("Unexpected Local Number " +
                                                                            DataPoints[NumberofPoints].LocalPointNumber +
                                                                            " Expected "
                                                                            + NumberofPoints.ToString() + " + " +
                                                                            LocalStart.ToString());
                                                throw (e);
                                            }
                                        }
                                        DataPoints[NumberofPoints].LocalPointNumber = NumberofPoints;
                                        if (DataPoints[NumberofPoints].OriginalPointNumber >= 0)
                                        {
                                            if ((DataPoints[NumberofPoints].OriginalPointNumber - OriginalStart) < 0)
                                            {
                                                Exception e =
                                                    SALSAUtility.SALSAError("Unexpected Original Number " +
                                                                            DataPoints[NumberofPoints].
                                                                            OriginalPointNumber + " Local Point "
                                                                            + NumberofPoints.ToString() +
                                                                            " Original Increment " +
                                                                            OriginalStart.ToString());
                                                throw (e);
                                            }
                                            DataPoints[NumberofPoints].OriginalPointNumber -= OriginalStart;
                                        }
                                        else
                                        {
                                            DataPoints[NumberofPoints].OriginalPointNumber = newlabelnumber;
                                        }

                                        if (labelfile)
                                        {
                                            DataPoints[NumberofPoints].pointlabel = split[split.Length - 1];
                                        }
                                        else
                                        {
                                            DataPoints[NumberofPoints].group = Convert.ToInt32(split[split.Length - 1]);
                                        }

                                        if (split.Length >= 4)
                                        {
                                            DataPoints[NumberofPoints].valuesset = true;
                                            DataPoints[NumberofPoints].x         = Convert.ToDouble(split[1]);
                                            DataPoints[NumberofPoints].y         = Convert.ToDouble(split[2]);
                                            positionsset = true;
                                        }
                                        if (split.Length == 5)
                                        {
                                            DataPoints[NumberofPoints].z = Convert.ToDouble(split[3]);
                                        }
                                        incrementcount = true;
                                        NonColonsInput = true;
                                    } // End Processing non colon Point information
                                }
                                if (incrementcount)
                                {
                                    ++NumberofPoints;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            SALSAUtility.SALSAError("Failed to load data array " + inputLineStr + " "
                                                    + " " + NumberofPoints.ToString() + " " + newlabelnumber.ToString() +
                                                    " " + e);
                            throw (e);
                        }
                    }

                    FileType = 1;
                    if (positionsset)
                    {
                        FileType = 0;
                    }
                    if (labelfile)
                    {
                        FileType = 2;
                    }
                    if (colonsinput)
                    {
                        if (NonColonsInput)
                        {
                            FileType += 6;
                        }
                        else
                        {
                            FileType += 3;
                        }
                    }
                    if (FileProperties.NumberOriginalPoints == 0)
                    {
                        FileProperties.NumberOriginalPoints = NumberofPoints;
                    }

                    if (FileProperties.NumberPointsinFile == 0)
                    {
                        FileProperties.NumberPointsinFile = NumberofPoints;
                    }

                    if (FileProperties.NumberPointsinFile != NumberofPoints)
                    {
                        Exception e =
                            SALSAUtility.SALSAError("Unexpected Number of Points in File " + NumberofPoints.ToString() +
                                                    " Read but Expected "
                                                    + FileProperties.NumberPointsinFile.ToString());
                        throw (e);
                    }
                    sr.Close();
                }
            }
            catch (Exception e)
            {
                SALSAUtility.SALSAError("Failed to read data from " + MDSClusterFileName + " " + e);
                throw (e);
            }
            return(true);
        }