private IGSLine CreateGSLineFromCommaSeparatedString(String inCourse, esriDirectionUnits inDirectionUnits,
            esriDirectionType inDirectionType)
        {
            string[] sCourse = inCourse.Split(',');
              int iUpperBnd = sCourse.GetUpperBound(0);
              double dToMeterUnitConversion = m_dScaleFactor;
              if (m_dScaleFactor == -1)
              {//if the scale factor wasn't found in the file for some reason
            Utilities UTILS = new Utilities();
            dToMeterUnitConversion = UTILS.ToMeterUnitConversion();
              }
              if (iUpperBnd <= 4) { return null; }
              IGSLine pLine = new GSLineClass();
              string sLineCat = "";
              string sLineUserType = "";
              string sAccCat = "";
              string sFromPt = (string)sCourse.GetValue(0);//from point
              //string sTemplate = (string)sCourse.GetValue(1);//line template
              string sDirection = (string)sCourse.GetValue(1);//direction
              string sDistance = (string)sCourse.GetValue(2);//distance
              string sRadius = (string)sCourse.GetValue(3);//radius
              string sChord = (string)sCourse.GetValue(4);//chord
              string sToPt = (string)sCourse.GetValue(5);//to point
              if (iUpperBnd >= 6)
            sLineCat = (string)sCourse.GetValue(6); //line category
              if (iUpperBnd >= 7)
            sLineUserType = (string)sCourse.GetValue(7); //line user type
              if (iUpperBnd >= 8)
            sAccCat = (string)sCourse.GetValue(8); //accuracy category

              int iFromPt = -1; //from point
              int iToPt = -1; //to point
              int iLineCat = -1;//line category
              int iLineUserType = -1;//line user type
              int iAccCat = -1;//accuracy
              double dDistance = -123456789;//distance
              double dChord = -123456789;//chord
              double dRadius = -123456789;//radius

              try
              {
            iFromPt = Convert.ToInt32(sFromPt); //from point
            iToPt = Convert.ToInt32(sToPt); //to point
            if (sLineCat.Trim().Length > 0)
              iLineCat = Convert.ToInt32(sLineCat); //line category
            if (sLineUserType.Trim().Length > 0)
              iLineUserType = Convert.ToInt32(sLineUserType); //line user type
            if (sAccCat.Trim().Length > 0)
              iAccCat = Convert.ToInt32(sAccCat); //accuracy
            if (sDistance.Trim().Length > 0)
              dDistance = Convert.ToDouble(sDistance); //distance
            if (sChord.Trim().Length > 0)
              dChord = Convert.ToDouble(sChord); //chord
            if (sRadius.Trim().Length > 0)
              dRadius = Convert.ToDouble(sRadius); //radius
              }
              catch
              {
            return null;
              }
              double dBear = DirectionString_2_NorthAzimuth(sDirection, inDirectionType, inDirectionUnits);
              pLine.Bearing = dBear;
              if (dDistance != -123456789)
            pLine.Distance = dDistance * dToMeterUnitConversion;
              if (dChord != -123456789)
            pLine.Distance = dChord * dToMeterUnitConversion;
              if (dRadius != -123456789)
            pLine.Radius = dRadius * dToMeterUnitConversion;
              pLine.FromPoint = iFromPt;
              pLine.ToPoint = iToPt;
              if (iAccCat > -1)
            pLine.Accuracy = iAccCat;
              if (iLineUserType > -1)
            pLine.LineType = iLineUserType;
              if (iLineCat > -1)
            pLine.Category = (esriCadastralLineCategory)iLineCat;
              return pLine;
        }
        private IGSLine CreateGSLine(String inCourse, esriDirectionUnits inDirectionUnits,
            esriDirectionType inDirectionType, ISegment EntryTangent,
            out ISegment ExitTangent, out ICircularArc outCircularArc)
        {
            //
              string[] sCourse = inCourse.Split(' ');
              Utilities UTILS = new Utilities();
              double dToMeterUnitConversion = UTILS.ToMeterUnitConversion();
              // ISegment ExitTangent = null;
              string item = (string)sCourse.GetValue(0);
              if (item.ToLower() == "dd")
              {//Direction distance -- straight line course
            IGSLine pLine = new GSLineClass();
            double dBear = DirectionString_2_NorthAzimuth((string)sCourse.GetValue(1), inDirectionType, inDirectionUnits);
            pLine.Bearing = dBear;
            pLine.Distance = Convert.ToDouble(sCourse.GetValue(2)) * dToMeterUnitConversion;
            pLine.FromPoint = m_count;
            m_count += 1;
            pLine.ToPoint = m_count;
            //Now define the tangent exit segment
            //in case it's needed for the next course (TC tangent curve, or Angle deflection)
            double dPolar = DirectionString_2_PolarRadians((string)sCourse.GetValue(1),
                inDirectionType, inDirectionUnits);
            IPoint pFromPt = new PointClass();
            pFromPt.PutCoords(1000, 1000);
            IConstructPoint2 pToPt = new PointClass();
            pToPt.ConstructAngleDistance(pFromPt, dPolar, 100);
            ILine ExitTangentLine = new LineClass();
            ExitTangentLine.PutCoords(pFromPt, (IPoint)pToPt);
            ExitTangent = (ISegment)ExitTangentLine;
            outCircularArc = null;
            Marshal.ReleaseComObject(pFromPt);
            Marshal.ReleaseComObject(pToPt);
            return pLine;
              }
              if (item.ToLower() == "ad")
              {//Angle deflection distance
            IGSLine pLine = new GSLineClass();
            double dDeflAngle = Angle_2_Radians((string)sCourse.GetValue(1), inDirectionUnits);
            //now need to take the previous tangent segment, reverse its orientation and
            //add +ve clockwise to get the bearing
            ILine calcLine = (ILine)EntryTangent;
            double dBear = PolarRAD_2_SouthAzimuthRAD(calcLine.Angle) + dDeflAngle;
            pLine.Bearing = dBear;
            pLine.Distance = Convert.ToDouble(sCourse.GetValue(2)) * dToMeterUnitConversion;
            pLine.FromPoint = m_count;
            m_count += 1;
            pLine.ToPoint = m_count;
            //Now define the tangent exit segment
            //in case it's needed for the next course (TC tangent curve, or Angle deflection)
            IPoint pFromPt = new PointClass();
            pFromPt.PutCoords(1000, 1000);
            IConstructPoint2 pToPt = new PointClass();
            double dPolar = NorthAzimuthRAD_2_PolarRAD(dBear);
            pToPt.ConstructAngleDistance(pFromPt, dPolar, 100);
            ILine ExitTangentLine = new LineClass();
            ExitTangentLine.PutCoords(pFromPt, (IPoint)pToPt);
            ExitTangent = (ISegment)ExitTangentLine;
            outCircularArc = null;
            Marshal.ReleaseComObject(pFromPt);
            Marshal.ReleaseComObject(pToPt);

            return pLine;
              }
              else if ((item.ToLower() == "nc") || (item.ToLower() == "tc"))
              {
            double dChordlength;
            double dChordBearing;
            ICircularArc pArc = ConstructCurveFromString(inCourse, EntryTangent,
                inDirectionType, inDirectionUnits, out dChordlength, out dChordBearing);
            try
            {
              IGSLine pLine = new GSLineClass();
              pLine.Bearing = PolarRAD_2_NorthAzimuthRAD(dChordBearing);
              pLine.Radius = pArc.Radius * dToMeterUnitConversion;//convert to meters
              if (pArc.IsCounterClockwise) { pLine.Radius = pLine.Radius * -1; }
              pLine.Distance = dChordlength * dToMeterUnitConversion; //convert to meters
              pLine.FromPoint = m_count;
              m_count += 1;
              pLine.ToPoint = m_count;
              ILine pTangentLine = new LineClass();
              pArc.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 100, pTangentLine);
              //pass the exit tangent back out for use as next entry tangent
              ExitTangent = (ISegment)pTangentLine;
              outCircularArc = pArc;
              return pLine;
            }
            catch { }
              }
              outCircularArc = null;
              ExitTangent = null;
              return null;
        }