public void parseXY() { try { MainWindow L = new MainWindow(); string commandXY = "./tablist " + "solve-indx.xyls"; tabList(commandXY); StreamReader reader = new StreamReader(@"c:\cygwin\home\astro\text2.txt"); //read the cygwin log file // reader = FileInfo.OpenText("filename.txt"); string line; // while ((line = reader.ReadToEnd()) != null) { line = reader.ReadToEnd(); string[] items = line.Split('\n'); // string[,] FieldLine = new String[4, 2]; string find = " 1 "; int count = 0; L.FileLog(" X " + " Y "); foreach (string item in items) { if (item.Contains(find) && count < 10) { // Log("found pos " + pos.ToString()); XYfound = true; } if (XYfound && count < 10) { //get and item for each x and y (then RA and DEc...later) // 4 x 2 array with x,y of first 4 stars starsXY[count, 0] = Convert.ToDouble(item.Substring(12, 15)); starsXY[count, 1] = Convert.ToDouble(item.Substring(36, 15)); // int nextSpace = IndexOfSecond(item, " "); // FieldLine[count, 1] = item.Substring(36, 15); L.FileLog(starsXY[count, 0] + " " + starsXY[count, 1]); count++; } } if (!XYfound) { L.Log("ParseXY Error - Aborted"); return; } reader.Close(); } catch (Exception e) { MainWindow L = new MainWindow(); L.Log("failed to parse X,Y data"); L.FileLog("failed to parse X,Y data: " + e.ToString()); } }
private void filteradvance() { try { MainWindow m = new MainWindow(); MainWindow.FlatCalcDone = false; if (MainWindow.SequenceRunning == true) { m.DisableUpDwn(); // fileSystemWatcher1.EnableRaisingEvents = true; } toolStripStatusLabel1.Text = "Filter Moving"; this.Refresh(); string movedone; port.DiscardOutBuffer(); port.DiscardInBuffer(); Thread.Sleep(20); port.Write("A"); filterMoving = true; Thread.Sleep(50); while (filterMoving == true) { movedone = port.ReadExisting(); if (movedone == "D") { filterMoving = false; toolStripStatusLabel1.Text = "Capturing"; this.Refresh(); // toolStripStatusLabel1.Text = " "; // toolStripStatusLabel1.Text = " "; } } Thread.Sleep(50); port.DiscardInBuffer(); if (currentfilter == 0)//allows advance without count to set to starting pos. { return; } /* *********************rem'd 4-11 put currentfilter asignment in filtersequence() // if (checkBox5.Checked == false) // { if (currentfilter != 7)//***************changed from 4 on 2_29 to ? fix dark2 { currentfilter++; } else currentfilter = 1;//reset at end */ // toolStripStatusLabel1.Text = " "; DisplayCurrentFilter(); } catch { Log("Filter Advance Error - Make Sure Arduino Connected"); Send("Filter Advance Error - Make Sure Arduino Connected"); FileLog("Filter Advance Error - Make Sure Arduino Connected"); } }
private void GetHandles() { try { Callback myCallBack = new Callback(EnumChildGetValue); // NebhWnd = FindWindow(null, "Nebulosity v3.0-a6"); // LoadScripthwnd = FindWindow(null, "Load script"); // Log("Load script " + LoadScripthwnd.ToString()); // SetForegroundWindow(NebhWnd); // if (NebhWnd == 0) // { // MessageBox.Show("Please Start Calling Window Application"); // } EnumChildWindows(_loadScripthwnd, myCallBack, 0); } catch (Exception e) { MainWindow L = new MainWindow(); L.Log("GetHandles Error" + e.ToString()); L.Send("GetHandles Error" + e.ToString()); L.FileLog("GetHandles Error" + e.ToString()); } }
public int Serverhwnd() { MainWindow L = new MainWindow(); IntPtr ServerhwndPtr = Handles.SearchForWindow("WindowsForms10", "scopefocus - Main"); L.Log("scopefocus-server handle found -- " + ServerhwndPtr.ToInt32()); int _serverhwnd = ServerhwndPtr.ToInt32(); return _serverhwnd; }
// private bool FindHandlesDone = false; public void FindHandles() { string MainWindowName; //******5-30 this might be problem, maybe this should just be done once...not sure if //finding the loadscript though. consider doing seperate for the 2 neb windows. one //with (spawned) try { MainWindow L = new MainWindow(); MainWindowName = "Nebulosity"; IntPtr hWnd2 = SearchForWindow("wxWindow", MainWindowName); L.Log("Neb Handle Found -- " + hWnd2.ToInt32()); _nebhWnd = hWnd2.ToInt32(); if (_nebhWnd != 0) { string NebVersion; //finds the Neb version (the number after the "v") StringBuilder sb = new StringBuilder(1024); SendMessage(_nebhWnd, MainWindow.WM_GETTEXT, 1024, sb); // GetWindowText(camera, sb, sb.Capacity); // L.Log("test"); L.Log(sb.ToString());//*****^%%$ None of the L.Log Works ****$%%^ NebVersion = sb.ToString(); int NebVposNumber = NebVersion.IndexOf("v"); string NebVNumberAfter = NebVersion.Substring(NebVposNumber + 1, 1); _nebVNumber = Convert.ToInt16(NebVNumberAfter); } if (!L.SlaveModeEnabled())//don't need for slave mode { IntPtr PHDhwnd2 = SearchForWindow("wxWindow", "PHD2 Guiding"); L.Log("PHD Handle Found -- " + PHDhwnd2.ToInt32()); _pHDhwnd = PHDhwnd2.ToInt32(); string PHDVersion; //finds the Neb version (the number after the "v") StringBuilder sb = new StringBuilder(1024); SendMessage(_pHDhwnd, MainWindow.WM_GETTEXT, 1024, sb); // GetWindowText(camera, sb, sb.Capacity); // L.Log("test"); L.Log(sb.ToString());//*****^%%$ None of the L.Log Works ****$%%^ PHDVersion = sb.ToString(); int PHDVposNumber = PHDVersion.IndexOf("g"); string NebVNumberAfter = PHDVersion.Substring(PHDVposNumber + 2, 1); _phdVNumber = Convert.ToInt16(NebVNumberAfter); } // PHDhwnd = FindWindow(null, "PHD Guiding 1.13.0b - www.stark-labs.com (Log active)"); _loadScripthwnd = FindWindow(null, "Load script"); // Log("PHD " + PHDhwnd.ToString()); // Log("Load script " + LoadScripthwnd.ToString()); } catch (Exception e) { // MainWindow L = new MainWindow(); // L.Log("FindHandles Error" + e.ToString()); // L.Send("FindHandles Error" + e.ToString()); // L.FileLog("FindHandles Error" + e.ToString()); } }
public int EnumChildGetValue(int hWnd, int lParam) { MainWindow L = new MainWindow(); StringBuilder formDetails = new StringBuilder(256); StringBuilder formClass = new StringBuilder(256); int txtValue; int txtValue2; string editText = ""; string classtext = ""; txtValue = GetWindowText(hWnd, formDetails, 256); editText = formDetails.ToString().Trim(); txtValue2 = GetClassName(hWnd, formClass, 256); classtext = formClass.ToString().Trim(); if (lParam == 0) { if (editText == "panel")//doesn't work w/ msctls_statusbar32 either { _panelhwnd = hWnd; } if (classtext == "Edit") { _editfound++; if (_editfound == 2) { _hwndDuration = hWnd; } } if (editText == "Advanced") { int Advancedhwnd = hWnd; } //*****************************need to test after writing auto camera find stuff *********************************** if (editText == _nebCamera + " Setup") { if (_setupWindowFound == false)//picks first one { int Advhwnd = hWnd; // Log("Adv" + Advhwnd.ToString()); _setupWindowFound = true; } } if (editText == "Capture Series") _captureMainhWnd = hWnd; if (editText == "Abort") { _aborthwnd = hWnd; // Log("Abort " + Aborthwnd.ToString()); } if (editText == "Frame and Focus") { _framehwnd = hWnd; // Log("Frame " + Framehwnd.ToString()); } if (editText == "Fine Focus") { _finehwnd = hWnd; // Log("Fine " + Finehwnd.ToString()); } if (editText == "Load script")//not finding it { _loadScripthwnd = hWnd; // Log("LoadScript " + LoadScripthwnd.ToString()); } } if (lParam == 2)//added to find handles of second instence of Neb { if (editText == "panel")//doesn't work w/ msctls_statusbar32 either { _panelhwnd2 = hWnd; } if (classtext == "Edit") { _editfound++; if (_editfound == 2) { _hwndDuration2 = hWnd; } } if (editText == "Advanced") { int Advancedhwnd2 = hWnd; // Advancedhwnd2 = hWnd; } //*****************************need to test after writing auto camera find stuff *********************************** if (editText == _nebCamera + " Setup") { if (_setupWindowFound == false)//picks first one { int Advhwnd2 = hWnd; // Log("Adv" + Advhwnd.ToString()); _setupWindowFound = true; } } if (editText == "Abort") { _aborthwnd2 = hWnd; // Log("Abort " + Aborthwnd.ToString()); } if (editText == "Frame and Focus") { _framehwnd2 = hWnd; // Log("Frame " + Framehwnd.ToString()); } if (editText == "Fine Focus") { _finehwnd2 = hWnd; // Log("Fine " + Finehwnd.ToString()); } if (editText == "Load script")//not finding it { _loadScripthwnd2 = hWnd; // Log("LoadScript " + LoadScripthwnd.ToString()); } } if (L.ServerEnabled()) { if (editText == "GotoFocus") { _gotofocushwnd = hWnd; // Log("Slave Gotofocus handle found " + _gotofocushwnd.ToString()); } if (editText == "Capture") { _capturehwnd = hWnd; // Log("Slave Capture Handle Found " + _capturehwnd.ToString()); } if (editText == "Flat") { _flathwnd = hWnd; // Log("Slave Flat handle found " + _flathwnd.ToString()); } if (editText == "Pause") { _pausehwnd = hWnd; // Log("SlavePause Handle found " + _pausehwnd.ToString()); } if (editText == "Not Connected") { _slaveStatushwnd = hWnd; // Log("Status Handle " + _slaveStatushwnd.ToString()); } } //MessageBox.Show("Contains text of control "+ editText); return 1; }
public void WriteSQLdata() { try { using (SqlCeConnection con = new SqlCeConnection(conString)) { con.Open(); int num =MainWindow.HFRarraymin; int num2 =MainWindow.apexHFR; int num4 = MainWindow.PosminHFR; float up = (float)MainWindow.SlopeHFRup; float down = (float)MainWindow.SlopeHFRdwn; //row numbering adds 1 to max value, allows for deletion of rows without number dulpication //can always modify or re-number in excel then import using (SqlCeCommand com1 = new SqlCeCommand("SELECT MAX (Number) FROM table1", con)) { SqlCeDataReader reader = com1.ExecuteReader(); while (reader.Read()) { if (reader.IsDBNull(0)) { _rows = 0; } else { _rows = reader.GetInt32(0); } } } using (SqlCeCommand com = new SqlCeCommand("INSERT INTO table1 (Date, PID, SlopeDWN, SlopeUP, Number, Equip, BestHFR, FocusPos) VALUES (@Date, @PID, @SlopeDWN, @SlopeUP, @Number, @equip, @BestHFR, @FocusPos)", con)) { com.Parameters.AddWithValue("@Date", DateTime.Now); com.Parameters.AddWithValue("@PID",MainWindow.PID); com.Parameters.AddWithValue("@SlopeDWN", down); com.Parameters.AddWithValue("@SlopeUP", up); com.Parameters.AddWithValue("@Number", _rows + 1); com.Parameters.AddWithValue("@equip",MainWindow.Eqiup); com.Parameters.AddWithValue("@BestHFR",MainWindow.HFRarraymin); com.Parameters.AddWithValue("@FocusPos",MainWindow.intersectPos); com.ExecuteNonQuery(); _rows++; } con.Close(); } } catch (Exception ex) { MainWindow m = new MainWindow(); m.Log("WriteSQLData Error" + ex.ToString()); } }
public void Update() { try { MainWindow m = new MainWindow(); if (MainWindow.Eqiup == null) { MessageBox.Show("Must select equipment first", "scopefocus", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Data d = new Data(); GetAvg(); FillData(); //try adding std dev and display in textbox16 // Std Dev UP if (this.dataGridView1.RowCount > 2) { List<double> StdDevCalcUP = new List<double>(); for (int i = 0; i < (dataGridView1.Rows.Count - 1); i++) { StdDevCalcUP.Add(Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value)); } double standardDeviationUP = m.CalculateSD(StdDevCalcUP); double sdUP = Math.Round(standardDeviationUP, 5); m.TB16 = sdUP.ToString(); } /* make sure there is enough data *****remd 6-28. not needed annoying if (dataGridView1.RowCount <= 2) { DialogResult result; result = MessageBox.Show("Need More Data for Calculation", "scopefocus", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { return; } } */ //Std Dev DWN if (this.dataGridView1.RowCount > 2) { List<double> StdDevCalcDWN = new List<double>(); for (int i = 0; i < (dataGridView1.Rows.Count - 1); i++) { StdDevCalcDWN.Add(Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value)); } double standardDeviationDWN = m.CalculateSD(StdDevCalcDWN); double sdDWN = Math.Round(standardDeviationDWN, 5); m.TB14 = sdDWN.ToString(); } /* ****remd 6-29 not needed if (dataGridView1.RowCount <= 2) { DialogResult result; result = MessageBox.Show("Need More Data for Calculation", "scopefocus", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { return; } } */ } catch (Exception ex) { // Log("Update Error - Line 1817" + ex.ToString()); } }
public void importDataFromExcel() { string sSQLTable = "table1"; //this works string myExcelDataQuery = "SELECT Date, PID, SlopeDWN, SlopeUP, Number, Equip, BestHFR, FocusPos FROM [Sheet1$]"; try { if (MainWindow.ImportPath == null) { MainWindow m = new MainWindow(); // DialogResult result = openFileDialog1.ShowDialog(); // ImportPath = openFileDialog1.FileName.ToString(); // ImportPath = Filename; m.TB34 = Filename; // textBox34.Text = ImportPath.ToString(); } string sSqlConnectionString = conString; string sExcelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +MainWindow.ImportPath + @";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""; // string sExcelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\Users\kevin\Documents\scopefocusData.xls;Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""; string sClearSQL = "DELETE FROM " + sSQLTable; SqlCeConnection SqlConn = new SqlCeConnection(conString); SqlCeCommand SqlCmd = new SqlCeCommand(sClearSQL, SqlConn); SqlConn.Open(); SqlCmd.ExecuteNonQuery(); SqlConn.Close(); OleDbConnection OleDbConn = new OleDbConnection(sExcelConnectionString); OleDbCommand OleDbCmd = new OleDbCommand(myExcelDataQuery, OleDbConn); OleDbConn.Open(); OleDbDataReader dr = OleDbCmd.ExecuteReader(); using (SqlCeBulkCopy bc = new SqlCeBulkCopy(conString)) { bc.DestinationTableName = "table1"; bc.WriteToServer(dr); } OleDbConn.Close(); MessageBox.Show("Data Import Successful", "scopefocus"); } catch { MessageBox.Show("Import Failed", "scopefocus"); } }
//analyze SQL data public void GetAvg() { try { using (SqlCeConnection con = new SqlCeConnection(conString)) { con.Open(); using (SqlCeCommand com = new SqlCeCommand("SELECT AVG(PID) FROM table1 WHERE Equip = @equip", con)) { com.Parameters.AddWithValue("@equip", MainWindow.Eqiup); SqlCeDataReader reader = com.ExecuteReader(); while (reader.Read()) { if (!reader.IsDBNull(0)) { int numb5 = reader.GetInt32(0); MainWindow.EnteredPID = numb5; } } reader.Close(); } using (SqlCeCommand com1 = new SqlCeCommand("SELECT AVG(SlopeDWN) FROM table1 WHERE Equip = @equip", con)) { com1.Parameters.AddWithValue("@equip",MainWindow.Eqiup); SqlCeDataReader reader1 = com1.ExecuteReader(); while (reader1.Read()) { if (!reader1.IsDBNull(0)) { MainWindow main = new MainWindow(); double numb5 = reader1.GetDouble(0); double numb5Rnd = Math.Round(numb5, 5); main.TB3 = numb5Rnd.ToString(); // textBox3.Text = numb5Rnd.ToString(); MainWindow.EnteredSlopeDWN = numb5Rnd; } } reader1.Close(); } using (SqlCeCommand com2 = new SqlCeCommand("SELECT AVG(SlopeUP) FROM table1 WHERE Equip = @equip", con)) { com2.Parameters.AddWithValue("@equip", MainWindow.Eqiup); SqlCeDataReader reader2 = com2.ExecuteReader(); while (reader2.Read()) { if (!reader2.IsDBNull(0)) { double numb5 = reader2.GetDouble(0); double numb5Rnd = Math.Round(numb5, 5); MainWindow m = new MainWindow(); m.TB10 = numb5Rnd.ToString(); // textBox10.Text = numb5Rnd.ToString(); MainWindow.EnteredSlopeUP = numb5Rnd; } } reader2.Close(); } using (SqlCeCommand com3 = new SqlCeCommand("SELECT AVG(BestHFR) FROM table1 WHERE Equip = @equip", con)) { com3.Parameters.AddWithValue("@equip", MainWindow.Eqiup); SqlCeDataReader reader3 = com3.ExecuteReader(); while (reader3.Read()) { if (!reader3.IsDBNull(0)) { int numb6 = reader3.GetInt32(0); MainWindow m = new MainWindow(); m.TB15 = numb6.ToString(); // textBox15.Text = numb6.ToString(); } } reader3.Close(); } /* // rem'd ****moved to mainWindow load so it puts focus position value in at startup using (SqlCeCommand com4 = new SqlCeCommand("SELECT AVG(FocusPos) FROM table1 WHERE Equip = @equip", con)) { com4.Parameters.AddWithValue("@equip", equip); SqlCeDataReader reader4 = com4.ExecuteReader(); while (reader4.Read()) { if (!reader4.IsDBNull(0)) { int numb7 = reader4.GetInt32(0); // textBox4.Text = numb7.ToString();******88888rem'd 4-10 } } reader4.Close(); } */ con.Close(); } } catch (Exception ex) { MainWindow m = new MainWindow(); m.Log("GetAvg Error" + ex.ToString()); } }
public void FillData() { try { using (SqlCeConnection con = new SqlCeConnection(conString)) { con.Open(); using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM table1", con)) { DataTable t = new DataTable(); a.Fill(t); dataGridView1.DataSource = t; a.Update(t); } con.Close(); } MainWindow m = new MainWindow(); ((DataTable)this.dataGridView1.DataSource).DefaultView.RowFilter = "Equip =" + "'" + m.TS3 + "'"; // ((DataTable)this.dataGridView1.DataSource).DefaultView.RowFilter = "Equip =" + "'" + m.toolStripStatusLabel3.Text.ToString() + "'"; // ((DataTable)this.dataGridView1.DataSource).DefaultView.RowFilter = "Equip =" + "'" + textBox13.Text.ToString() + "'"; } catch (Exception ex) { MainWindow m = new MainWindow(); m.Log("FillData Error" + ex.ToString()); } }
//start cygwin term, save log, execute tablist command public void tabList(string file) { try { Process proc = new Process(); proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.FileName = @"C:\cygwin\bin\mintty.exe"; // @"c:/cygwin/bin/mintty.exe"; proc.StartInfo.Arguments = "--log /home/astro/text2.txt -i /Cygwin-Terminal.ico -"; //creates text file of the cygwin terminal. //parse the needed info from the txt file proc.Start(); StreamWriter sw = proc.StandardInput; StreamReader reader = proc.StandardOutput; // StreamReader sr = proc.StandardOutput; StreamReader se = proc.StandardError; //C:\cygwin\lib\astrometry\bin sw.AutoFlush = true; Thread.Sleep(2000); // string command = "./tablist " + "solve.xyls"; SendKeys.Send("cd" + " " + "/home/astro"); Thread.Sleep(200); SendKeys.Send("~"); Thread.Sleep(200); // SendKeys.Send("solve-field" + " " + "--sigma" + " " + "100" + " " + "-L" + " " + "0.5" + " " + "-H" + " " + "2" + " " + Path.GetFileName(solveImage)); SendKeys.Send(file); Thread.Sleep(200); SendKeys.SendWait("~"); SendKeys.Send("exit"); SendKeys.Send("~"); sw.Close(); reader.Close(); proc.WaitForExit(); proc.Close(); } catch (Exception e) { MainWindow L = new MainWindow(); L.Log("tablist.exe failed"); L.FileLog("tablist.exe failed: " + e.ToString()); } }
//*****combine w/ parse XY ***** only diff is command private void ParseRD() { try { MainWindow L = new MainWindow(); int count; string find = " 1 "; // int pos = 0; string commandRD = "./tablist " + "solve.rdls"; tabList(commandRD); //not reading a new text2 file w/ RD data...its using the prev XY one.... StreamReader reader2 = new StreamReader(@"c:\cygwin\home\astro\text2.txt"); //read the cygwin log file // reader = FileInfo.OpenText("filename.txt"); string line2; // while ((line = reader.ReadToEnd()) != null) { line2 = reader2.ReadToEnd(); string[] items2 = line2.Split('\n'); // string[,] FieldLine2 = new String[4, 2]; // string find = " 1 "; // int pos = 0; RDfound = false; count = 0; L.FileLog(" RA " + " Dec "); foreach (string item2 in items2) { if (item2.Contains(find) && count < 10) { // Log("found pos " + pos.ToString()); // Log("RA Dec data RDfound = true; } if (RDfound && count < 10) { //get and item for each x and y (then RA and DEc...later) // 4 x 2 array with x,y of first 4 stars starsRD[count, 0] = Convert.ToDouble(item2.Substring(12, 15)); starsRD[count, 1] = Convert.ToDouble(item2.Substring(34, 15)); // int nextSpace = IndexOfSecond(item, " "); //FieldLine2[count, 1] = item2.Substring(34, 15); L.FileLog(starsRD[count, 0] + " " + starsRD[count, 1]); count++; } } if (!RDfound) { L.Log("ParseRD Error - Aborted"); return; } } catch (Exception e) { MainWindow L = new MainWindow(); L.Log("failed to parse RA/Dec data"); L.FileLog("failed to parse RA/Dec data: " + e.ToString()); } }
private void cramersRule() { try { MainWindow L = new MainWindow(); double centerDec = DEC; double centerRA = RA; if (DEC == 0 || RA == 0) { MessageBox.Show("must slew to plate solve location first"); return; } var FL = 1;//arbitrary var dr = Math.PI / 180; double a0 = centerRA * dr; // was * 15 as well double a0deg = centerRA;// was * 15 double d0 = centerDec * dr; double d0deg = centerDec; var n = 10; //number of stars var sd = Math.Sin(d0); var cd = Math.Cos(d0); double[] ra = new double[10]; double[] rd = new double[10]; double r1 = 0; double r2 = 0; double r3 = 0; double r7 = 0; double r8 = 0; double r9 = 0; double xs = 0; double ys = 0; double[,] r = new double[10, 9]; double[] starsY1 = new double[10]; double[] starsX1 = new double[10]; for (int i = 0; i < n; i++) { starsRD[i, 0] = starsRD[i, 0] * dr;// was * 15 as well starsRD[i, 1] = starsRD[i, 1] * dr; } for (var j = 0; j < n; j++) { var sj = Math.Sin(starsRD[j, 1]); var cj = Math.Cos(starsRD[j, 1]); var hh = sj * sd + cj * cd * Math.Cos(starsRD[j, 0] - a0); starsX1[j] = cj * Math.Sin(starsRD[j, 0] - a0) / hh; starsY1[j] = (sj * cd - cj * sd * Math.Cos(starsRD[j, 0] - a0)) / hh; } for (var j = 0; j < n; j++) { xs = (xs) + (starsXY[j, 0]); ys = (ys) + (starsXY[j, 1]); r[j, 0] = starsXY[j, 0] * starsXY[j, 0]; r1 = (r1) + (r[j, 0]); r[j, 1] = starsXY[j, 1] * starsXY[j, 1]; r2 = (r2) + (r[j, 1]); r[j, 2] = starsXY[j, 0] * starsXY[j, 1]; r3 = (r3) + (r[j, 2]); r[j, 6] = starsY1[j] - starsXY[j, 1] / FL; r7 = (r7) + (r[j, 6]); r[j, 7] = r[j, 6] * starsXY[j, 0]; r8 = (r8) + (r[j, 7]); r[j, 8] = r[j, 6] * starsXY[j, 1]; r9 = (r9) + (r[j, 8]); } // Now solve for plate constants d, e, f, by Cramer's Rule var dd = r1 * (r2 * n - ys * ys) - r3 * (r3 * n - xs * ys) + xs * (r3 * ys - xs * r2); var ddd = r8 * (r2 * n - ys * ys) - r3 * (r9 * n - r7 * ys) + xs * (r9 * ys - r7 * r2); var eee = r1 * (r9 * n - r7 * ys) - r8 * (r3 * n - xs * ys) + xs * (r3 * r7 - xs * r9); var fff = r1 * (r2 * r7 - ys * r9) - r3 * (r3 * r7 - xs * r9) + r8 * (r3 * ys - xs * r2); ddd = ddd / dd; eee = eee / dd; fff = fff / dd; double r4 = 0; double r5 = 0; double r6 = 0; for (int j = 0; j < n; j++) { r[j, 3] = starsX1[j] - starsXY[j, 0] / FL; r4 = (r4) + (r[j, 3]); r[j, 4] = r[j, 3] * starsXY[j, 0]; r5 = (r5) + (r[j, 4]); r[j, 5] = r[j, 3] * starsXY[j, 1]; r6 = (r6) + (r[j, 5]); } // Now solve for plate constants a, b, c, by Cramer's Rule var aaa = r5 * (r2 * n - ys * ys) - r3 * (r6 * n - r4 * ys) + xs * (r6 * ys - r4 * r2); var bbb = r1 * (r6 * n - r4 * ys) - r5 * (r3 * n - xs * ys) + xs * (r3 * r4 - xs * r6); var ccc = r1 * (r2 * r4 - ys * r6) - r3 * (r3 * r4 - xs * r6) + r5 * (r3 * ys - xs * r2); aaa = aaa / dd; bbb = bbb / dd; ccc = ccc / dd; //Log("a = " + aaa.ToString()); //Log("b = " + bbb.ToString()); //Log("c = " + ccc.ToString()); //Log("d = " + ddd.ToString()); //Log("e = " + eee.ToString()); //Log("f = " + fff.ToString()); // Now find the rms residuals double s = 0;//orig is as double ds = 0; double res2 = 0; for (var j = 0; j < n; j++) { ra[j] = starsXY[j, 0] - FL * (starsX1[j] - (aaa * starsXY[j, 0] + bbb * starsXY[j, 1] + ccc)); rd[j] = starsXY[j, 1] - FL * (starsY1[j] - (ddd * starsXY[j, 0] + eee * starsXY[j, 1] + fff)); s = (s) + Math.Pow(ra[j], 2); ds = (ds) + Math.Pow(rd[j], 2); res2 = (res2) + Math.Pow(ra[j], 2) + Math.Pow(rd[j], 2); } double xt; double yt; //if (checkBox31.Checked == true) //{ // int StatusstripHandle = FindWindowEx(Handles.NebhWnd, 0, "msctls_statusbar32", null); // IntPtr statusHandle = new IntPtr(StatusstripHandle); // StatusHelper sh = new StatusHelper(statusHandle); // int comma = sh.Captions[2].IndexOf(","); // int length = sh.Captions[2].Length; // xt = Convert.ToDouble(sh.Captions[2].Substring(0,comma)); // yt = Convert.ToDouble(sh.Captions[2].Substring(comma,length)); // Log("X = " + xt.ToString() + " Y = " + yt.ToString()); // } // else // { xt = Convert.ToDouble(textBox2.Text);//arbitrary for now //input x pixel for target yt = Convert.ToDouble(textBox1.Text); L.FileLog("Offset X = " + xt.ToString() + " Y = " + yt.ToString()); L.FileLog("Using solved Image CenterRA = " + centerRA.ToString() + " CenterDec = " + centerDec.ToString()); // } var sigma1 = Math.Sqrt(s / (n - 3)); var sigma2 = Math.Sqrt(ds / (n - 3)); var sigma3 = (sigma1 / FL) * 3600 / (dr * 15 * Math.Cos(d0)); var sigma4 = (sigma2 / FL) * 3600 / dr; var sigma5 = Math.Sqrt(res2 / (n - 3)); var sigma6 = (sigma5 / FL) * 3600 / dr; L.Log("RMS residual RA = " + sigma3.ToString() + " arcsec"); L.FileLog("RMS residual RA = " + sigma3.ToString() + " arcsec"); L.Log("RMS residual Dec = " + sigma4.ToString() + " arcsec"); L.FileLog("RMS residual Dec = " + sigma4.ToString() + " arcsec"); L.Log("RMS residual = " + sigma6.ToString() + " arcsec"); L.FileLog("RMS residual = " + sigma6.ToString() + " arcsec"); // form.sigma3.value = sigma3;//****not sure what these are... // form.sigma4.value = sigma4; // form.sigma6.value = sigma6; // Compute the standard coordinates of target // result = xy(form.xyt.value); // var xt = result.x; var yt = result.y; // var a0 = nRA * 15 * dr; // var a0 = centerRA * 15 * dr; var xx = aaa * xt + bbb * yt + ccc + xt / FL; var yy = ddd * xt + eee * yt + fff + yt / FL; bbb = cd - yy * sd; var g = Math.Sqrt((xx * xx) + (bbb * bbb)); // Find right ascension of target var a5 = Math.Atan(xx / bbb); if (bbb < 0) a5 = a5 + Math.PI; var a6 = (a5) + (a0); if (a6 > 2 * Math.PI) a6 = a6 - 2 * Math.PI; if (a6 < 0) a6 = (a6) + 2 * Math.PI; centerHereRA = a6 / (dr * 15);//was * 15 L.Log("Calculated RA = " + centerHereRA.ToString()); // result = sexagesimal(v); //use this to convert to hh:mm:ss // var ia1=result.hours; // var ia2=result.minutes; // var a3=result.seconds; // Find declination of target double d6 = Math.Atan((sd + yy * cd) / g); centerHereDec = d6 / dr; L.Log("Calculated Dec = " + centerHereDec.ToString()); L.FileLog("Calculated Offset: Dec = " + centerHereDec.ToString() + " RA = " + centerHereRA.ToString()); // result = sexagesimal(v); // var id1=result.hours; // var id2=result.minutes; // var d3=result.seconds; // form.radect.value = ia1+" "+ia2+" "+a3+" "+id1+" "+id2+" "+d3; } catch (Exception e) { MainWindow L = new MainWindow(); L.Log("Calculation failed"); L. FileLog("Calculation Failed : " + e.ToString()); } }