private void write_halign() { del = b2 - b1; if (del < 0) { del = 0.0 - del; } if (del > 360) { del = del - 360; } //string strTemp = ""; string strModelName = (modnam.Length > 8)? modnam.Substring(0, 8) : modnam; string strLabelStr = (stglbl.Length > 4) ? stglbl.Substring(0, 4) : stglbl; CHalignFilData FilDataObj = new CHalignFilData(); FilDataObj.sMod = strModelName; FilDataObj.sString = strLabelStr; FilDataObj.iSlno = elno; FilDataObj.iEltype = eltype; FilDataObj.dStartchn = chn1; FilDataObj.dEndchn = chn2; FilDataObj.dHipx = hipx; FilDataObj.dHipy = hipy; FilDataObj.dT1 = t1; FilDataObj.dT2 = t2; FilDataObj.dRadius = rad; FilDataObj.dEllength = l; FilDataObj.dStartx = xs; FilDataObj.dStarty = ys; FilDataObj.dEndx = xe; FilDataObj.dEndy = ye; FilDataObj.dB1 = b1; FilDataObj.dB2 = b2; FilDataObj.dDeviation = del; FilDataObj.iTurn = turn; fp2.WriteLine(FilDataObj.ToString()); //fprintf(fp2, "%8s %4s %4d %4d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f %4d\n", modnam, stglbl, elno, eltype, chn1, chn2, hipx, hipy, t1, t2, rad, l, xs, ys, xe, ye, b1, b2, del, turn); }
void ProcessData() { BinaryWriter fp2 = null; StreamWriter fp3 = null; string nam; string lbl; int ind = 0, len, ival; int slno, eltype, turn; double x, y, z; double stchn, RC, sc = 0, inc, seglen, segend; //, seginc; double RCI, num, val; double T1, T2, R, D, lastRC = -999.999; /* Select a Polyline from screen */ /* User Input data in dialog box */ modnam = this.tbModelName_.Text; stglbl = this.tbStringlabel_.Text; stchn = this.tbStartChainage_.Value; inc = this.tbChainageInterval_.Value; string csTemp = Path.Combine(this.app.AppDataPath, "MODEL.FIL"); fp2 = new BinaryWriter(new FileStream(csTemp, FileMode.Append), Encoding.Default); if (this.checkMasterString_.Checked == true) { csTemp = Path.Combine(this.app.AppDataPath, "HALIGN.FIL"); fp3 = new StreamWriter(csTemp, true); } CLabtype lab = null; CPTStype pts = null; CModType mod = null; CStgType stg = null; ClSTtype lst = null; lab = new CLabtype(); lab.attr = CLabtype.Type.Model; mod = new CModType(); mod.name = modnam; lab.Tag = mod; lab.ToStream(fp2); lab = new CLabtype(); lab.attr = CLabtype.Type.String; stg = new CStgType(); stg.label = stglbl; lab.Tag = stg; lab.ToStream(fp2); RC = stchn; //seginc=0.0; sx = sy = sz = -999.999; T1 = T2 = R = D = 0; turn = 0; B1 = B2 = 0.0; slno = 1; eltype = 1; turn = 1; ind = 0; //ind1=0; for (int vx = 0; vx < this.ptCords.Length; vx++) { /*JBLN*/ ex = this.ptCords[vx].X; ey = this.ptCords[vx].Y; ez = this.ptCords[vx].Z; // fscanf(fp1, "%lf %lf %lf", &ex, &ey, &ez); /* close in vc++ */ if (ind == 0) { lab = new CLabtype(); lab.attr = CLabtype.Type.Point; pts = new CPTStype(); pts.mc = RC; pts.mx = ex; pts.my = ey; pts.mz = ez; lab.Tag = pts; lab.ToStream(fp2); sc = RC; sx = ex; sy = ey; sz = ez; B1 = B2; ind = 1; continue; } if (ex == sx && ey == sy) { continue; } tt = string.Format("{0:f0}", inc);//sprintf(tt,"%.0f", inc); len = tt.Length; RCI = RC; num = Math.Pow(10, len); RCI = RCI / num; ival = (int)RCI; RCI = ival * num; while (RCI < RC) { RCI += inc; } RC = RCI; if (RC == sc) { RC += inc; /* NEW */ } determine_bearing(); seglen = Math.Sqrt((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); /* NEW */ segend = sc + seglen; /* NEW */ if (this.checkMasterString_.Checked == true) { if (B1 == 0) { B1 = B2; } D = B1 - B2; if (D < 0) { D += 360; } if (D > 360) { D -= 360; } CHalignFilData fildata = new CHalignFilData(); fildata.sMod = modnam; fildata.sString = stglbl; fildata.iSlno = slno; fildata.iEltype = (short)eltype; fildata.dStartchn = sc; fildata.dEndchn = segend; fildata.dHipx = ex; fildata.dHipy = ey; fildata.dT1 = T1; fildata.dT2 = T2; fildata.dRadius = R; fildata.dEllength = seglen; fildata.dStartx = sx; fildata.dStarty = sy; fildata.dEndx = ex; fildata.dEndy = ey; fildata.dB1 = B2; fildata.dB2 = B2; fildata.dDeviation = D; fildata.iTurn = (short)turn; fp3.WriteLine(fildata.ToString()); //fprintf(fp3, "%s %s %d %d %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.5f %.3f %.3f %.3f %d\n", modnam, stglbl, slno, eltype, sc, segend, ex, ey, T1, T2, R, seglen, sx, sy, ex, ey, B2, B2, D, turn); slno++; /* NEW */ } val = Math.Abs(RC - segend);/* fabs will be abs in VC++*/ if (val < 0.001) { segend = RC; } while (true) { if (segend < RC) { if (segend + inc != RC) { val = Math.Abs(segend - lastRC); if (val > 0.001) { lab = new CLabtype(); lab.attr = CLabtype.Type.Point; pts = new CPTStype(); pts.mc = segend; pts.mx = ex; pts.my = ey; pts.mz = ez; lab.Tag = pts; lab.ToStream(fp2); lastRC = segend; } } RC = segend; ind = 0; break; } else { if ((RC - sc) > 0.001) { x = sx + (RC - sc) * Math.Sin(B2 / r9); /* E */ y = sy + (RC - sc) * Math.Cos(B2 / r9); /* N */ z = sz + (RC - sc) * (ez - sz) / (segend - sc); if (RC != lastRC) { lab = new CLabtype(); lab.attr = CLabtype.Type.Point; pts = new CPTStype(); pts.mc = RC; pts.mx = x; pts.my = y; pts.mz = z; lab.Tag = pts; lab.ToStream(fp2); lastRC = RC; } } RC += inc; } } sc = RC; sx = ex; sy = ey; sz = ez; B1 = B2; ind = 1; }// end for previously while fp2.Close(); if (this.checkMasterString_.Checked == true) { fp3.Close(); } csTemp = Path.Combine(this.app.AppDataPath, "MODEL.LST"); fp2 = new BinaryWriter(new FileStream(csTemp, FileMode.Append), Encoding.Default); lst = new ClSTtype(); lst.strMod1 = modnam; lst.strStg = stglbl; lst.ToStream(fp2); fp2.Close(); csTemp = Path.Combine(this.app.AppDataPath, "MODEL.FIL"); fp2 = new BinaryWriter(new FileStream(csTemp, FileMode.Append), Encoding.Default); lab = new CLabtype(); lab.attr = CLabtype.Type.Model; mod = new CModType(); nam = modnam + "%%"; mod.name = nam; lab.Tag = mod; lab.ToStream(fp2); lab = new CLabtype(); lab.attr = CLabtype.Type.String; stg = new CStgType(); lbl = stglbl; stg.label = lbl; lab.Tag = stg; lab.ToStream(fp2); for (int vx = 0; vx < this.ptCords.Length; vx++) { ex = this.ptCords[vx].X; ey = this.ptCords[vx].Y; ez = this.ptCords[vx].Z; lab = new CLabtype(); lab.attr = CLabtype.Type.Point; pts = new CPTStype(); pts.mc = RC; pts.mx = ex; pts.my = ey; pts.mz = ez; lab.Tag = pts; lab.ToStream(fp2); } fp2.Close(); csTemp = Path.Combine(this.app.AppDataPath, "MODEL.LST"); fp2 = new BinaryWriter(new FileStream(csTemp, FileMode.Append), Encoding.Default); lst = new ClSTtype(); lst.strMod1 = nam; lst.strStg = lbl; lst.ToStream(fp2); fp2.Close(); }
/// <summary> /// Unreachable code segment /// </summary> private void save_halign() { double last_chn1 = 0.0; double last_chn2 = 0.0; string last_mod = "NULL"; string last_stg = "NULL"; string strhalignPath = Path.Combine(this.m_strWorkingDirPath, "halign.tmp"); if (File.Exists(strhalignPath) == false) { throw new Exception("Failed to open file : " + strhalignPath); } StreamReader readerfp2 = new StreamReader(strhalignPath); StreamWriter writerfp3 = new StreamWriter(Path.Combine(this.m_strWorkingDirPath, "HALIGN.FIL"), true); while (readerfp2.EndOfStream == false) { //int iIndex = 0; string strValTSV = readerfp2.ReadLine(); CHalignFilData FilDataObj = CHalignFilData.Parse(strValTSV); //string[] Values = strValTSV.Split(new char[] { '\t' }); modnam = FilDataObj.sMod; stglbl = FilDataObj.sString; if (last_mod.CompareTo(modnam) == 0 && last_stg.CompareTo(stglbl) == 0) { break; } elno = (short)FilDataObj.iSlno; eltype = FilDataObj.iEltype; chn1 = FilDataObj.dStartchn; chn2 = FilDataObj.dEndchn; hipx = FilDataObj.dHipx; hipy = FilDataObj.dHipy; t1 = FilDataObj.dT1; t2 = FilDataObj.dT2; rad = FilDataObj.dRadius; l = FilDataObj.dEllength; xs = FilDataObj.dStartx; ys = FilDataObj.dStarty; xe = FilDataObj.dEndx; ye = FilDataObj.dEndy; b1 = FilDataObj.dB1; b2 = FilDataObj.dB2; del = FilDataObj.dDeviation; turn = FilDataObj.iTurn; del = b2 - b1; if (del < 0) { del = del + 360; } if (del > 360) { del = del - 360; } FilDataObj.sMod = modnam; FilDataObj.sString = stglbl; FilDataObj.iSlno = elno; FilDataObj.iEltype = eltype; FilDataObj.dStartchn = chn1; FilDataObj.dEndchn = chn2; FilDataObj.dHipx = hipx; FilDataObj.dHipy = hipy; FilDataObj.dT1 = t1; FilDataObj.dT2 = t2; FilDataObj.dRadius = rad; FilDataObj.dEllength = l; FilDataObj.dStartx = xs; FilDataObj.dStarty = ys; FilDataObj.dEndx = xe; FilDataObj.dEndy = ye; FilDataObj.dB1 = b1; FilDataObj.dB2 = b2; FilDataObj.dDeviation = del; FilDataObj.iTurn = turn; writerfp3.WriteLine(FilDataObj.ToString()); last_chn1 = chn1; last_chn2 = chn2; last_mod = modnam; last_stg = stglbl; } readerfp2.Close(); writerfp3.Close(); }