示例#1
0
        static void Main(string[] args)
        {
            // Focus.exe [basis] [test list] [out folder] [optional: zx plane fields]
            //XmlDocument xmlDoc = new XmlDocument();
            //xmlDoc.Load("H:/Documents/PhD/KNU/Tasks/Task_14_Fields/test_points.xml");
            //XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/testPoints/testPoint");

            //nodeList[0].SelectSingleNode("/x").Value

            //if (args.Length != 3)
            //{
            //    Console.WriteLine("Usage: Focus.exe c:/basis/b.basbin c:/out c:/zx_fields");
            //    return;
            //}

            // x, y, basis, out file, zx folder

            if (args.Length != 5)
            {
                Console.WriteLine("Usage: Focus.exe [x node] [y node] [basis] [out file] [zx folder]");
                Console.WriteLine("ROI size: 9x9 fixed. Binary input files allower only.");
                Console.WriteLine("Example: Focus.exe 76 76 c:/basis/b.basbin c:/out.bin c:/zx_fields");
                return;
            }

            int    node_x, node_y;
            int    roi_w = 9, roi_h = 9;
            string s_nodeX = args[0], s_nodeY = args[1];
            string s_basisPath = args[2];
            string s_outFile   = args[3];
            string s_zxFolder  = args[4];

            if (!int.TryParse(s_nodeX, out node_x) || !int.TryParse(s_nodeY, out node_y))
            {
                Console.Error.WriteLine("Node X or Y has wrong format.");
                return;
            }
            if (!File.Exists(s_basisPath))
            {
                Console.Error.WriteLine("File \"{0}\" does not exist.", s_basisPath);
                return;
            }
            if (!Directory.Exists(Path.GetDirectoryName(s_outFile)))
            {
                Console.Error.WriteLine("Directory \"{0}\" does not exist.", Path.GetDirectoryName(s_outFile));
                return;
            }
            if (Path.GetExtension(s_outFile).ToUpper() != ".BIN" && Path.GetExtension(s_outFile).ToUpper() != ".CSV")
            {
                string ext = Path.GetExtension(s_outFile).ToUpper();
                bool   b   = ext == ".CSV";
                Console.Error.WriteLine("Unsupported output file format. Use .bin or .csv instead.");
                return;
            }
            if (!Directory.Exists(s_zxFolder))
            {
                Console.Error.WriteLine("Directory \"{0}\" does not exist.", s_zxFolder);
                return;
            }

            Basis bas = new Basis(s_basisPath);

            string[] zxFiles = Directory.EnumerateFiles(s_zxFolder, "*.bin", SearchOption.TopDirectoryOnly).ToArray();

            if (bas.UsedFields != zxFiles.Length)
            {
                Console.Error.WriteLine("Quantities of basis ({0}) and ZX ({1}) fields are not equal.",
                                        bas.UsedFields, zxFiles.Length);
                return;
            }

            NearField nf = null;

            NearField.op_Assign(ref nf, WavefrontShaping.Focus(bas, new Rectangle(node_x, node_y, roi_w, roi_h)));

            Complex[]   decomp_coefs = bas.Decompose(nf, NearFieldType.Scattered);
            Complex[][] conv_coefs   = bas.GetConversionCoefficients(Basis.CoefficientType.Scattered);

            NearField[] zxFields = new NearField[zxFiles.Length];

            for (int i = 0; i < zxFields.Length; i++)
            {
                NearField.op_Assign(ref zxFields[i], new NearField(zxFiles[i]));
            }

            NearField summary = new NearField(zxFields[0], true);

            for (int i = 0; i < conv_coefs.Length; i++)
            {
                Complex coef = Complex.Zero;

                for (int j = 0; j < conv_coefs[i].Length; j++)
                {
                    coef += conv_coefs[i][j] * decomp_coefs[j];
                }

                NearField.op_Assign(ref summary, summary + zxFields[i] * coef);
            }

            if (Path.GetExtension(s_outFile).ToUpper() == ".BIN")
            {
                summary.SaveToFile(s_outFile);
            }
            else if (Path.GetExtension(s_outFile).ToUpper() == ".CSV")
            {
                summary.Export(s_outFile);
            }

            summary.Dispose();
            bas.Dispose();
            for (int i = 0; i < zxFields.Length; i++)
            {
                zxFields[i].Dispose();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            //NearField[] x_fields, y_fields;

            //string[] y_files = Directory.EnumerateFiles(@"d:\Documents\PhD\KNU\Tasks\Task_10_New_program\Fields_440_30x30_X\",
            //    "*.dat", SearchOption.TopDirectoryOnly).ToArray();

            //y_fields = new NearField[y_files.Length];

            //for (int i = 0; i < y_fields.Length; ++i)
            //{
            //    NearField.op_Assign(ref y_fields[i], NearField.ParseMSTM(y_files[i], 0.440));
            //    //y_fields[i].SaveToFile(y_files[i].Replace("dat", "bin"));
            //}

            ////----------------
            //x_fields = new NearField[81];
            //int[] order = { -1, -2, -3, -4, 0, 1, 2, 3, 4 };
            //double beam_width = 0.6328 * y_fields[0].Wavenumber;
            //for (int x = 0, i = 0; x < order.Length; x++)
            //{
            //    for (int y = 0; y < order.Length; y++, i++)
            //    {
            //        NearField.op_Assign(ref x_fields[i],
            //            NearField.GenerateGaussianBeam(order[x] * y_fields[0].Wavelength * y_fields[0].Wavenumber,
            //            order[y] * y_fields[0].Wavelength * y_fields[0].Wavenumber, beam_width, y_fields[0].NodesX,
            //            y_fields[0].NodesY, y_fields[0].StepX, y_fields[0].StepY, y_fields[0].MinX,
            //            y_fields[0].MinY, y_fields[0].Wavelength));

            //        x_fields[i].SaveToFile(
            //            string.Format("d:/Documents/PhD/KNU/Tasks/Task_10_New_program/Fields_440_30x30_X/Incident/nf_sp1872_111_{0}{1}_{2}{3}_440_X.dat",
            //            order[x] < 0 ? "m" : "p", Math.Abs(order[x]), order[y] < 0 ? "m" : "p", Math.Abs(order[y])));
            //    }
            //}
            //----------------

            //string[] x_files = Directory.EnumerateFiles(@"d:\Documents\PhD\KNU\Tasks\Task_10_New_program\Fields\",
            //    "*.bin", SearchOption.TopDirectoryOnly).ToArray();
            //x_fields = new NearField[x_files.Length];

            //for (int i = 0; i < x_fields.Length; ++i)
            //{
            //    NearField.op_Assign(ref x_fields[i], new NearField(x_files[i]));
            //}

            //Basis basis = new Basis(x_fields, y_fields);
            //basis.Save(@"d:\Documents\PhD\KNU\Tasks\Task_10_New_program\Basis_81f_440X\basis_81f.basbin");

            //-------------------

            Basis basis = new Basis(@"d:\Documents\PhD\KNU\Tasks\Task_10_New_program\Basis_81f_440X\basis_81f.basbin");

            basis.UsedFields = 81;

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

            int x_max, y_max;
            List <OptResult> results = new List <OptResult>((240 - 20) / 10); // (161 - 4) / 9 for 0.6328 20x20

            for (int x1 = 20; x1 <= 220; x1 += 10)                            // 4, 148, 9
            {
                NearField nf = null;

                stopwatch.Start();
                // 76 for 0.6328
                NearField.op_Assign(ref nf, WavefrontShaping.Focus(basis, new System.Drawing.Rectangle(x1, 120, 9, 9),
                                                                   1000, 10000, 1E-8));
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed.ToString());
                nf.SaveToFile(string.Format(@"d:\Documents\PhD\KNU\Tasks\Task_10_New_program\Fields_440_30x30_X\Focus_AxisX\{0}.bin", x1.ToString("D3")));
                stopwatch.Reset();

                double    average_energy = 0.0;
                OptResult temp_res       = new OptResult();

                temp_res.PeakIntensity = nf.GetMaxIntensity(out x_max, out y_max);
                temp_res.PeakX         = x_max;
                temp_res.PeakY         = y_max;

                for (int y = 0; y < nf.NodesY; ++y)
                {
                    for (int x = 0; x < nf.NodesX; ++x)
                    {
                        average_energy += (nf[0, x, y] * Complex.Conjugate(nf[0, x, y]) +
                                           nf[1, x, y] * Complex.Conjugate(nf[1, x, y]) +
                                           nf[2, x, y] * Complex.Conjugate(nf[2, x, y])).Real;
                    }
                }

                average_energy /= nf.NodesX * nf.NodesY;
                temp_res.AverageEnergySingle = average_energy;
                temp_res.EnhancementSingle   = temp_res.PeakIntensity / temp_res.AverageEnergySingle;

                //double fwhm_x_min = 0.0, fwhm_x_max = 0.0, fwhm_y_min = 0.0, fwhm_y_max = 0.0, fwhm_area = 0.0;
                FWHM fwhm = nf.CalculateFWHM();
                //nf.CalculateFWHM(out fwhm_x_min, out fwhm_x_max, out fwhm_y_min, out fwhm_y_max, out fwhm_area);

                temp_res.XminFWHM = fwhm.Box.Width;
                temp_res.YminFWHM = fwhm.Box.Height;
                temp_res.AreaFWHM = fwhm.Area;
                temp_res.Energy   = nf.GetElectricFieldEnergy();

                results.Add(temp_res);

                nf.Dispose();
            }

            int i = 20;

            foreach (OptResult res in results)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", i,
                                  res.PeakX.ToString(),
                                  res.PeakY.ToString(), res.PeakIntensity.ToString("E4"),
                                  res.AverageEnergySingle.ToString("E4"), res.XminFWHM.ToString("F2"), res.YminFWHM.ToString("F2"),
                                  res.AreaFWHM.ToString(), res.Energy);

                i += 10;
            }

            basis.Dispose();
            Console.ReadKey();
            //-------------------

            //NearField nf = null;
            ////System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            ////stopwatch.Start();
            //NearField.op_Assign(ref nf, NearField.Focus(basis, new System.Drawing.Rectangle(76, 76, 9, 9)));
            ////stopwatch.Stop();
            //nf.Export("d:/foc_temp.csv");
            //nf.Dispose();

            //Console.WriteLine("Focusing time: {0}", stopwatch.Elapsed.ToString());
        }