Exemple #1
0
        public CrashData(Exception e, string Username)
        {
            this.Username = Username;
            StackTrace trace = new StackTrace(e, true);

            StackTraceData = trace.GetFrames().Select((sf) => {
                return(new StackTraceData {
                    Line = sf.GetFileLineNumber(),
                    Column = sf.GetFileColumnNumber(),
                    Filename = sf.GetFileName(),
                    ClassName = sf.GetMethod().ReflectedType.FullName,
                    Method = sf.GetMethod().Name,
                });
            }).ToList();

            ID            = Guid.NewGuid().ToString();
            ExceptionCode = e.HResult;
            Source        = e.Source;
            StackTrace    = e.StackTrace;
            ExceptionName = e.GetType().Name;
            Timestamp     = LLTools.TimestampMS();
            Date          = DateTime.Now.ToLongDateString();
            Time          = DateTime.Now.ToLongTimeString();
            XRITVersion   = LibInfo.Version;
            XRITCommit    = LibInfo.CommitID;
            if (e.InnerException != null)
            {
                InnerCrashData = new CrashData(e);
            }
        }
Exemple #2
0
 public void PutStatistic(DBStatistics statistics, bool autoTimestamp = true)
 {
     lock (statConn) {
         if (autoTimestamp)
         {
             statistics.Timestamp = LLTools.TimestampMS();
         }
         statConn.Insert(statistics);
     }
 }
Exemple #3
0
        public static void Main(string[] args)
        {
            long startTime;

            Image16 im  = new Image16(21000, 21000);
            Image16 im2 = new Image16(4096, 4096, 0x0);

            UIConsole.Log("Benchmark Draw");
            startTime = LLTools.TimestampMS();
            im.DrawImage(im2, 1024, 1024, true);
            UIConsole.Log($"Delta: {LLTools.TimestampMS() - startTime} ms");

            UIConsole.Log("Benchmark Save PGM");
            startTime = LLTools.TimestampMS();
            im.SavePGM("test.pgm");
            UIConsole.Log($"Delta: {LLTools.TimestampMS() - startTime} ms");
        }
        public static void Update(DBStatistics stats)
        {
            lock (statistics) {
                stats.Timestamp = LLTools.TimestampMS();
                if (stats.Timestamp == lastTimestamp)
                {
                    stats.Timestamp++;
                }
                lastTimestamp = stats.Timestamp;

                statistics.Add(stats);
                if (LLTools.Timestamp() - lastCheck > checkInterval)
                {
                    long startTime = LLTools.TimestampMS();
                    // Time to dump
                    foreach (var s in statistics)
                    {
                        ConfigurationManager.PutStatistics(s, false);
                    }
                    statistics.Clear();
                    lastCheck = LLTools.Timestamp();
                }
            }
        }
Exemple #5
0
 public void Refresh()
 {
     ReceivedTime = LLTools.TimestampMS();
 }
Exemple #6
0
 public MSDUInfo()
 {
     ReceivedTime = LLTools.TimestampMS();
 }
Exemple #7
0
        void ThreadLoop()
        {
            UIConsole.Debug("MSDU Thread started");
            while (running)
            {
                OpenSatelliteProject.GRB.MSDU msdu;
                if (packets.TryDequeue(out msdu))
                {
                    ProcessMSDU(msdu);
                }

                List <int> keys = msduCache.Keys.ToList();
                keys.ForEach(k => {
                    var minfo = msduCache[k];
                    if (minfo.Expired)
                    {
                        UIConsole.Warn($"Product {k:X3} expired. Dumping...");
                        string msduFile = Path.Combine(FileHandler.TemporaryFileFolder, minfo.FileName);
                        string target   = Path.Combine(FileHandler.TemporaryFileFolder, $"{k:X3}-{LLTools.TimestampMS()}-{Tools.RandomString(8)}");
                        File.Move(msduFile, target);
                        if (EnumHelpers.APID2Type(k) == PayloadType.Generic)
                        {
                            fileHandleManager.NewFile(new Tuple <string, object>(target, minfo.GenericHeader));
                        }
                        else
                        {
                            fileHandleManager.NewFile(new Tuple <string, object>(target, minfo.ImageHeader));
                        }
                        msduCache.Remove(k);
                    }
                });

                // Thread.Yield(); // This might be better
                Thread.Sleep(2);
            }
            UIConsole.Debug("Channel Thread stopped");
        }
Exemple #8
0
        void ProcessMSDU(OpenSatelliteProject.GRB.MSDU msdu)
        {
            try {
                if (msdu.APID == 2047)
                {
                    // Skip fill packet
                    return;
                }

                bool firstOrSinglePacket = msdu.Sequence == SequenceType.FIRST_SEGMENT || msdu.Sequence == SequenceType.SINGLE_DATA;

                Packets++;

                if (!msdu.Valid || !msdu.Full)
                {
                    if (msdu.FrameLost)
                    {
                        UIConsole.Error($"Lost some frames on MSDU, the file will be corrupted. CRC Match: {msdu.Valid} - Size Match: {msdu.Full}");
                    }
                    else
                    {
                        UIConsole.Error($"Corrupted MSDU. CRC Match: {msdu.Valid} - Size Match: {msdu.Full}");
                    }
                }

                if (!msdu.Valid)
                {
                    CRCFails++;
                    return;
                }

                var payloadType = EnumHelpers.APID2Type(msdu.APID);

                if (msdu.Sequence == SequenceType.FIRST_SEGMENT || msdu.Sequence == SequenceType.SINGLE_DATA)
                {
                    if (msduCache.ContainsKey(msdu.APID))
                    {
                        var minfo = msduCache[msdu.APID];
                        UIConsole.Warn($"Received First Segment for {msdu.APID:X3} but last data wasn't saved to disk yet! Forcing dump.");
                        // This can only happen for multi-segment file.
                        string msduFile = Path.Combine(FileHandler.TemporaryFileFolder, minfo.FileName);
                        string target   = Path.Combine(FileHandler.TemporaryFileFolder, $"{msdu.APID:X3}-{LLTools.TimestampMS()}-{Tools.RandomString(8)}");
                        File.Move(msduFile, target);
                        if (payloadType == PayloadType.Generic)
                        {
                            fileHandleManager.NewFile(new Tuple <string, object>(target, minfo.GenericHeader));
                        }
                        else
                        {
                            fileHandleManager.NewFile(new Tuple <string, object>(target, minfo.ImageHeader));
                        }
                        msduCache.Remove(msdu.APID);
                    }

                    var msInfo = new MSDUInfo()
                    {
                        APID          = msdu.APID,
                        FileName      = msdu.TemporaryFilename,
                        GenericHeader = payloadType == PayloadType.Generic ? new GRBGenericHeader(msdu.APID, msdu.Data.Skip(8).Take(21).ToArray()) : null,
                        ImageHeader   = payloadType == PayloadType.ImageData ? new GRBImageHeader(msdu.APID, msdu.Data.Skip(8).Take(34).ToArray()) : null,
                    };

                    msduCache.Add(msdu.APID, msInfo);
                }
                else if (msdu.Sequence == SequenceType.LAST_SEGMENT || msdu.Sequence == SequenceType.CONTINUED_SEGMENT)
                {
                    if (!msduCache.ContainsKey(msdu.APID))
                    {
                        UIConsole.Warn("Orphan Packet!");
                        return;
                    }
                }

                var msduInfo = msduCache[msdu.APID];
                msduInfo.Refresh();

                string path = FileHandler.TemporaryFileFolder;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string filename = Path.Combine(FileHandler.TemporaryFileFolder, msduInfo.FileName);

                int totalOffset;

                if (firstOrSinglePacket)
                {
                    totalOffset = 8;
                    if (payloadType == PayloadType.Generic)
                    {
                        totalOffset += 21;
                    }
                    else
                    {
                        totalOffset += 34;
                    }
                }
                else
                {
                    totalOffset = 8;
                }

                byte[] dataToSave = msdu.Data.Skip(totalOffset).ToArray();
                dataToSave = dataToSave.Take(dataToSave.Length - 4).ToArray();                 // Remove CRC

                using (FileStream fs = new FileStream(filename, firstOrSinglePacket ? FileMode.Create : FileMode.Append, FileAccess.Write)) {
                    using (BinaryWriter sw = new BinaryWriter(fs)) {
                        sw.Write(dataToSave);
                        sw.Flush();
                    }
                }

                if (msdu.Sequence == SequenceType.LAST_SEGMENT || msdu.Sequence == SequenceType.SINGLE_DATA)
                {
                    string target = Path.Combine(FileHandler.TemporaryFileFolder, $"{msdu.APID:X3}-{LLTools.TimestampMS()}-{Tools.RandomString(8)}");
                    File.Move(filename, target);
                    if (payloadType == PayloadType.Generic)
                    {
                        fileHandleManager.NewFile(new Tuple <string, object>(target, msduInfo.GenericHeader));
                    }
                    else
                    {
                        fileHandleManager.NewFile(new Tuple <string, object>(target, msduInfo.ImageHeader));
                    }
                    msduCache.Remove(msdu.APID);
                }
            } catch (Exception e) {
                UIConsole.Error(String.Format("Exception on FinishMSDU: {0}", e));
            }
        }
 static StatisticsManager()
 {
     statistics    = new List <DBStatistics> ();
     lastCheck     = LLTools.Timestamp();
     lastTimestamp = LLTools.TimestampMS();
 }
Exemple #10
0
        public static void CLApply2DLUT(ComputeContext context)
        {
            ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Bgra, ComputeImageChannelType.UnsignedInt8);
            var startTime             = LLTools.TimestampMS();

            #region Visible / Temporary Source
            BitmapData     bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
            ComputeImage2D source0    = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, format, bmp.Width, bmp.Height, bitmapData.Stride, bitmapData.Scan0);
            bmp.UnlockBits(bitmapData);
            #endregion
            #region Infrared Source
            bitmapData = irBmp.LockBits(new Rectangle(0, 0, irBmp.Width, irBmp.Height), ImageLockMode.ReadOnly, irBmp.PixelFormat);
            ComputeImage2D source1 = new ComputeImage2D(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, format, irBmp.Width, irBmp.Height, bitmapData.Stride, bitmapData.Scan0);
            irBmp.UnlockBits(bitmapData);
            #endregion
            #region Output
            ComputeImage2D output = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.AllocateHostPointer, format, bmp.Width, bmp.Height, 0, IntPtr.Zero);
            #endregion
            #region Variable Initialization
            ComputeEventList    eventList = new ComputeEventList();
            ComputeCommandQueue commands  = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
            #region Apply Curve
            applyCurveKernel.SetMemoryArgument(0, source0);
            applyCurveKernel.SetMemoryArgument(1, output);
            applyCurveKernel.SetMemoryArgument(2, curveLutBuffer);
            #endregion
            #region Apply LUT 2D
            apply2DLUTKernel.SetMemoryArgument(0, source1);
            apply2DLUTKernel.SetMemoryArgument(1, output);
            apply2DLUTKernel.SetMemoryArgument(2, source0);
            apply2DLUTKernel.SetMemoryArgument(3, lut2DBuffer);
            #endregion
            #region Reprojection
            var latRangeBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, latRange);
            var lonRangeBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, lonRange);
            var coverageBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, coverage);
            var trimBuff     = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, trim);
            var sizeBuff     = new ComputeBuffer <uint>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, size);
            reprojectKernel.SetMemoryArgument(0, source0);
            reprojectKernel.SetMemoryArgument(1, output);
            reprojectKernel.SetValueArgument(2, satelliteLongitude);
            reprojectKernel.SetValueArgument(3, coff);
            reprojectKernel.SetValueArgument(4, cfac);
            reprojectKernel.SetValueArgument(5, loff);
            reprojectKernel.SetValueArgument(6, lfac);
            reprojectKernel.SetValueArgument(7, (uint)(fixAspect ? 1 : 0));
            reprojectKernel.SetValueArgument(8, aspectRatio);
            reprojectKernel.SetMemoryArgument(9, latRangeBuff);
            reprojectKernel.SetMemoryArgument(10, lonRangeBuff);
            reprojectKernel.SetMemoryArgument(11, coverageBuff);
            reprojectKernel.SetMemoryArgument(12, trimBuff);
            reprojectKernel.SetMemoryArgument(13, sizeBuff);
            #endregion
            #endregion
            #region Run Pipeline
            UIConsole.Log("Executing curve kernel");
            commands.Execute(applyCurveKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            UIConsole.Log("Executing LUT2D kernel");
            commands.Execute(apply2DLUTKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            UIConsole.Log("Executing kernel");
            commands.Execute(reprojectKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            #endregion
            #region Dump Bitmap
            UIConsole.Log("Dumping bitmap");
            Bitmap     obmp    = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);
            BitmapData bmpData = obmp.LockBits(new Rectangle(0, 0, obmp.Width, obmp.Height), ImageLockMode.ReadWrite, obmp.PixelFormat);
            commands.ReadFromImage(output, bmpData.Scan0, true, null);
            obmp.UnlockBits(bmpData);

            var delta = LLTools.TimestampMS() - startTime;
            UIConsole.Log($"Took {delta} ms to Apply Curve -> Apply Lut2D (FalseColor) -> Reproject");
            UIConsole.Log("Saving bitmap");
            obmp.Save("teste.png");
            UIConsole.Log("Done");
            bmp.Save("original.png");
            #endregion
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"XRIT Version: {LibInfo.Version}");
            AppDomain.CurrentDomain.UnhandledException += CrashReport.DefaultExceptionHandler;
            //*
            //Organizer org = new Organizer("./himawari");
            //org.Update();
            //var gd = org.GroupData[1490489400];
            //var od = gd.Infrared;

            /*
             *          Console.WriteLine("Initializing organizer");
             *          Organizer org = new Organizer("/home/lucas/Works/OpenSatelliteProject/split/goesdump/XRITLibraryTest/bin/Debug/channels/Images/Full Disk/");
             *          org.Update();
             *          int k = 0;
             *          int c = 0;
             *          foreach (var z in org.GroupData.Keys) {
             *                  k = z;
             *                  c++;
             *                  if (c == 2) { // 20 For US
             *                          break;
             *                  }
             *          }
             *          var gd = org.GroupData[k];
             *          var od = gd.Visible;
             *
             *          Console.WriteLine("Initializing GeoConverter");
             *          var gc = new GeoConverter(gd.SatelliteLongitude, gd.ColumnOffset, gd.LineOffset, gd.ColumnScalingFactor, gd.LineScalingFactor, true, od.Columns);
             *
             * Console.WriteLine("Generating BMP");
             *          //var bmp = ImageTools.GenerateFullImage(od);
             *          var bmp = ImageTools.GenerateFalseColor(gd);
             *          var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_10m_admin_1_states_provinces.shp");
             *          //var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_50m_admin_0_countries.shp");
             *          Console.WriteLine("Drawing Map");
             *          mapDrawer.DrawMap(ref bmp, gc, Color.Aqua, 2, true);
             *
             *          Console.WriteLine("Drawing LatLon Lines");
             *          ImageTools.DrawLatLonLines(ref bmp, gc, Color.Brown, 1, true);
             *
             *          bmp.Save("unitedstates.jpg", ImageFormat.Jpeg);
             *          bmp.Dispose();
             *          // */
            ///*
            string     filename    = "./OR_ABI-L2-CMIPF-M3C13_G16_s20170861545382_e20170861556160_c20170861556231.lrit";
            string     visFilename = "./OR_ABI-L2-CMIPF-M3C02_G16_s20170861545382_e20170861556149_c20170861556217.lrit";
            XRITHeader header      = FileParser.GetHeaderFromFile(filename);

            Console.WriteLine($"Parsing file {header.Filename}");
            Regex x                  = new Regex(@".*\((.*)\)", RegexOptions.IgnoreCase);
            var   regMatch           = x.Match(header.ImageNavigationHeader.ProjectionName);
            float satelliteLongitude = float.Parse(regMatch.Groups[1].Captures[0].Value, CultureInfo.InvariantCulture);
            var   inh                = header.ImageNavigationHeader;
            var   gc                 = new GeoConverter(satelliteLongitude, inh.ColumnOffset, inh.LineOffset, inh.ColumnScalingFactor, inh.LineScalingFactor);

            var od = new OrganizerData();

            od.Segments.Add(0, filename);
            od.FirstSegment = 0;
            od.Columns      = header.ImageStructureHeader.Columns;
            od.Lines        = header.ImageStructureHeader.Lines;
            od.ColumnOffset = inh.ColumnOffset;
            od.PixelAspect  = 1;
            var bmp = ImageTools.GenerateFullImage(od);

            od = new OrganizerData();
            od.Segments.Add(0, visFilename);
            od.FirstSegment = 0;
            od.Columns      = header.ImageStructureHeader.Columns;
            od.Lines        = header.ImageStructureHeader.Lines;
            od.ColumnOffset = inh.ColumnOffset;
            od.PixelAspect  = 1;
            var vbmp = ImageTools.GenerateFullImage(od);

            UIConsole.GlobalEnableDebug = true;
            var shapeFile = ShapeFiles.InitShapeFiles();

            //bmp.Save(filename + "-orig.png", ImageFormat.Png);
            //vbmp.Save(visFilename + "-orig.png", ImageFormat.Png);

            var mapDrawer = new MapDrawer(shapeFile);

            //ImageTools.DrawLatLonLines(ref bmp, gc, Color.Brown);
            ImageTools.ApplyCurve(OpenSatelliteProject.Presets.NEW_VIS_FALSE_CURVE, ref vbmp);

            vbmp = ImageTools.ToFormat(vbmp, PixelFormat.Format32bppArgb, true);
            bmp  = ImageTools.ToFormat(bmp, PixelFormat.Format32bppArgb, true);

            ImageTools.Apply2DLut(OpenSatelliteProject.Presets.FalseColorLUTVal, ref vbmp, bmp);

            var startTime = LLTools.TimestampMS();

            mapDrawer.DrawMap(ref vbmp, gc, Color.Yellow, 2, false, true);
            var delta = LLTools.TimestampMS() - startTime;

            Console.WriteLine($"Took {delta} ms to generate map.");

            vbmp.Save(visFilename + ".jpg", ImageFormat.Jpeg);

            Bitmap landMap = mapDrawer.GenerateLandMap(gc, bmp.Width, bmp.Height);

            landMap.Save(filename + "-landmap.jpg", ImageFormat.Jpeg);
            landMap.Dispose();
            bmp.Dispose();


            return;

            // */

            /*
             *          Bitmap test0 = (Bitmap) Bitmap.FromFile("test0.jpg");
             *          Bitmap test1 = (Bitmap) Bitmap.FromFile("test1.jpg");
             *          Bitmap overlay = (Bitmap) Bitmap.FromFile("goes13-fulldisk.jpg");
             *
             *          test0 = test0.ToFormat(PixelFormat.Format24bppRgb, true);
             *
             *          overlay.Save("hue.jpg", ImageFormat.Jpeg);
             *
             *          ImageTools.ApplyOverlay(ref test0, overlay);
             *          test0.Save("test0-ovl.jpg", ImageFormat.Jpeg);
             *
             *          ImageTools.ApplyOverlay(ref test1, overlay);
             *          test1.Save("test1-ovl.jpg", ImageFormat.Jpeg);
             *
             *          test0.Dispose();
             *          test1.Dispose();
             *          overlay.Dispose();
             */
            //*
            //string dcsFile = "/home/lucas/Works/OpenSatelliteProject/split/goesdump/XRITLibraryTest/bin/Debug/channels/DCS/pM-17085003239-A.dcs";
            //List<DCSHeader> d = DCSParser.parseDCS(dcsFile);
            //*
            //string debugFrames = "/media/ELTN/tmp/demuxdump-1490627438.bin";
            //string debugFrames = "/media/ELTN/tmp/debug5/demuxdump-1492732814.bin";
            //string debugFrames = "/home/lucas/Works/OpenSatelliteProject/split/issues/trango/3/debug_frames.bin";
            //string debugFrames = "/media/ELTN/tmp/debug3/raw_data.bin";

            /*
             * var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_50m_admin_0_countries.shp");
             * var fList = mapDrawer.ShapeFile.Features.ToList ();
             * var bmp = new Bitmap (1280, 720, PixelFormat.Format24bppRgb);
             * using (var graphics = Graphics.FromImage (bmp)) {
             *  Brush bgBrush = new SolidBrush (Color.Black);
             *  Brush polyBrush = new SolidBrush (Color.White);
             *  graphics.FillRectangle (bgBrush, 0, 0, 1280, 720);
             *  int o = 0;
             *  foreach (var fo in fList) {
             *      Console.WriteLine ($"Writting Geometry {o}");
             *      Pen pen = new Pen(Color.FromArgb((int)((255.0 * o) / fList.Count), 127, 127), 3);
             *      o++;
             *      for (var n = 0; n < fo.NumGeometries; n++) {
             *          //Console.WriteLine ($"Writting Geometry {n}");
             *          var fg = fo.GetBasicGeometryN (n);
             *          var k = fg.Coordinates;
             *
             *          float lastX = float.NaN;
             *          float lastY = float.NaN;
             *
             *          List<PointF> points = new List<PointF> ();
             *          foreach (var z in k) {
             *              float lon = (float)z.X;
             *              float lat = (float)z.Y;
             *
             *              float X = bmp.Width / 2 + bmp.Width * (lon / 360);
             *              float Y = bmp.Height / 2 - bmp.Height * (lat / 180);
             *
             *              if (!float.IsNaN (lastX) && !float.IsNaN (lastY)) {
             *                  //graphics.DrawLine (pen, lastX, lastY, X, Y);
             *              }
             *              lastX = X;
             *              lastY = Y;
             *
             *              points.Add (new PointF (X, Y));
             *          }
             *          graphics.FillPolygon(polyBrush, points.ToArray());
             *      }
             *  }
             * }
             * Console.WriteLine ("Saving");
             * bmp.Save ("/home/lucas/test.png", ImageFormat.Png);
             * bmp.Dispose ();
             * Console.WriteLine ("Done");
             * return;
             */

            EventMaster.On("newFile", d => {
                var ed = (NewFileReceivedEventData)d.Data;
                //Console.WriteLine($"Received event for new file {ed.Name} at {ed.Path}");
                //Console.WriteLine(ed.ToString());
            });
            Console.WriteLine("Hash: " + LibInfo.CommitID);
            Console.WriteLine("Log: " + LibInfo.LogLines);
            Console.WriteLine("Short Hash: " + LibInfo.ShortCommitID);
            Console.WriteLine("Version: " + LibInfo.Version);
            //string debugFrames = "/media/ELTN/tmp/demuxdump-1490627438.bin";
            //string debugFrames = "/media/ELTN/tmp/G16JuneTest/demuxdump-1496790733.bin";
            //string debugFrames = "/media/ELTN/tmp/G16JuneTest/demuxdump-1500179126.bin";
            //string debugFrames = "/media/ELTN/tmp/debug14/demuxdump-1495166529.bin";
            string debugFrames = "/media/ELTN/tmp/trango/demuxdump-1500736657.bin";
            //var mapDrawer = new MapDrawer("/home/lucas/Works/OpenSatelliteProject/split/borders/ne_10m_admin_1_states_provinces.shp");

            var im0 = new ImageManager("output/Images/Full Disk/");
            var im1 = new ImageManager("output/Images/Northern Hemisphere/");
            var im2 = new ImageManager("output/Images/Southern Hemisphere/");
            var im3 = new ImageManager("output/Images/Area of Interest/");
            var im4 = new ImageManager("output/Images/United States/");
            var im5 = new ImageManager("output/Images/FM1/");
            var im6 = new ImageManager("output/Images/Unknown/");

            im0.InitMapDrawer();
            im1.InitMapDrawer();
            im2.InitMapDrawer();
            im3.InitMapDrawer();
            im4.InitMapDrawer();
            im5.InitMapDrawer();
            im6.InitMapDrawer();

            ImageManager.GenerateVisible        = true;
            ImageManager.GenerateInfrared       = true;
            ImageManager.GenerateFalseColor     = true;
            ImageManager.GenerateWaterVapour    = true;
            ImageManager.GenerateOtherImages    = true;
            ImageManager.EraseFiles             = false;
            ImageManager.UseNOAAFileFormat      = true;
            ImageManager.GenerateLatLonOverlays = true;
            ImageManager.GenerateMapOverlays    = true;
            ImageManager.GenerateLabels         = true;
            ImageManager.GenerateLatLonLabel    = true;
            ImageManager.SaveNonOverlay         = false;
            //im0.Start ();
            //im1.Start ();
            //im2.Start ();
            //im3.Start ();
            //im4.Start ();
            im5.Start();
            //im6.Start ();
            // */
            //*/
            // /*

            /*
             * DemuxManager dm = new DemuxManager ();
             * FileHandler.SkipDCS = true;
             * FileHandler.SkipEMWIN = true;
             * //const int startFrame = 956000;
             * const int startFrame = 0;
             * FileStream file = File.OpenRead (debugFrames);
             * byte[] data = new byte[892];
             * long bytesRead = startFrame * 892;
             * long bytesToRead = file.Length;
             * int frameN = startFrame;
             * file.Position = bytesRead;
             * while (bytesRead < bytesToRead) {
             *  if (frameN % 1000 == 0) {
             *      //Console.WriteLine("Injecting Frame {0}", frameN);
             *  }
             *  bytesRead += file.Read (data, 0, 892);
             *  dm.parseBytes (data);
             *  frameN++;
             * }
             *
             * Console.WriteLine ("CRC Fails: {0}", dm.CRCFails);
             * Console.WriteLine ("Bugs: {0}", dm.Bugs);
             * Console.WriteLine ("Frame Loss: {0}", dm.FrameLoss);
             * Console.WriteLine ("Length Fails: {0}", dm.LengthFails);
             * Console.WriteLine ("Packets: {0}", dm.Packets);
             *
             * Console.WriteLine ("Received Products: ");
             * foreach (int pID in dm.ProductsReceived.Keys) {
             *  Console.WriteLine ("\t{0}: {1}", ((NOAAProductID)pID).ToString (), dm.ProductsReceived [pID]);
             * }
             * //*/
            //im.Stop();
            //*/
            //ProcessFile("/home/lucas/Works/OpenSatelliteProject/split/goesdump/goesdump/bin/Debug/channels/Text/NWSTEXTdat043204159214.lrit");

            /*
             * Organizer organizer = new Organizer("/home/lucas/Works/OpenSatelliteProject/split/goesdump/goesdump/bin/Debug/channels/Images/Full Disk");
             * organizer.Update();
             *
             * var data = organizer.GroupData;
             *
             * foreach (var z in data) {
             *  var mData = z.Value;
             *  var bmp = ImageTools.GenerateFalseColor(mData);
             *
             *  if (bmp != null) {
             *      bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "FLSCLR", z.Key), ImageFormat.Jpeg);
             *      bmp.Dispose();
             *      mData.IsProcessed = true;
             *  } else {
             *      if (mData.Visible.IsComplete && mData.Visible.MaxSegments != 0) {
             *          bmp = ImageTools.GenerateFullImage(mData.Visible);
             *          bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "VIS", z.Key), ImageFormat.Jpeg);
             *          bmp.Dispose();
             *      }
             *      if (mData.Infrared.IsComplete && mData.Infrared.MaxSegments != 0) {
             *          bmp = ImageTools.GenerateFullImage(mData.Infrared);
             *          bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "IR", z.Key), ImageFormat.Jpeg);
             *          bmp.Dispose();
             *      }
             *      if (mData.WaterVapour.IsComplete && mData.WaterVapour.MaxSegments != 0) {
             *          bmp = ImageTools.GenerateFullImage(mData.WaterVapour);
             *          bmp.Save(string.Format("{0}-{1}-{2}-{3}.jpg", mData.SatelliteName, mData.RegionName, "WV", z.Key), ImageFormat.Jpeg);
             *          bmp.Dispose();
             *      }
             *      Console.WriteLine("Not all segments available!");
             *  }
             * }
             *
             *
             * //*/

            /*
             *          string visFile = "/home/lucas/Works/OpenSatelliteProject/split/samples/FD 26-02-17 2106 G13VI.jpg";
             *          string irFile = "/home/lucas/Works/OpenSatelliteProject/split/samples/FD 26-02-17 2106 G13IR.jpg";
             *
             *          Bitmap vis = new Bitmap(visFile);
             *          ImageTools.ApplyCurve(Presets.VIS_FALSE_CURVE, ref vis);
             *          vis.Save("test.jpg", ImageFormat.Jpeg);
             *          //vis = vis.ToFormat(PixelFormat.Format32bppArgb, true);
             *
             *          Bitmap ir = new Bitmap(irFile);
             *          ir = ir.ToFormat(PixelFormat.Format32bppArgb, true);
             *          ImageTools.ApplyLUT(Presets.THERMAL_FALSE_LUT, ref ir, 3);
             *          ir.Save("test2.jpg", ImageFormat.Jpeg);
             *
             *          ir = ir.ToFormat(PixelFormat.Format32bppArgb);
             *          ImageTools.CombineHStoV(ref ir, vis);
             *
             *          ir.Save("final.jpg", ImageFormat.Jpeg);
             *          //*/
            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(1000);
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }