Exemplo n.º 1
0
        public static CrdFile Read(Stream stream)
        {
            CrdFile file = new CrdFile();

            if (file.Comments == null)
            {
                file.Comments = new List <string>();
            }

            using (StreamReader reader = new StreamReader(stream))
            {
                string line;
                //第一行
                //PPP_021430_143MATE                                               24-JAN-13 09:21
                line            = reader.ReadLine();
                file.Label      = line.Substring(0, 65).Trim();
                file.DateString = line.Substring(65).Trim();

                //第二行
                //--------------------------------------------------------------------------------
                line = reader.ReadLine();

                //第3行
                //LOCAL GEODETIC DATUM: IGS00             EPOCH: 2002-05-23 11:57:30
                line = reader.ReadLine();
                if (line.Contains("DATUM"))
                {
                    file.Datum = line.Substring(line.IndexOf(":") + 1, 15).Trim();
                }
                if (line.Contains("EPOCH"))
                {
                    file.Epoch = new Time(DateTime.Parse(line.Substring(line.IndexOf("EPOCH") + 6)));
                }

                while ((line = reader.ReadLine()) != null)
                {
                    //正式记录
                    if (line.StartsWith("NUM"))
                    {
                        file.Items = new List <CrdItem>();
                        line       = reader.ReadLine();//空了一行。
                        while (line != null)
                        {
                            line = line.Trim();
                            if (line == "")
                            {
                                line = reader.ReadLine();
                                continue;
                            }

                            CrdItem coord = CrdItem.ParseLine(line);
                            file.Items.Add(coord);

                            line = reader.ReadLine();
                            if (line == "")
                            {
                                break;            //跳出
                            }
                        }

                        //末尾有些东西
                        while ((line = reader.ReadLine()) != null)
                        {
                            file.Comments.Add(line);
                        }
                    }
                }
                return(file);
            }
        }