private static DateTime ExtractDateTime(IoffeVesselMetData meteoData)
        {
            string dateStr = meteoData.Date.ToString();
            string timeStr = meteoData.curtime.ToString("D6");

            int sec = Convert.ToInt32(timeStr.Substring(timeStr.Length - 2));

            timeStr = timeStr.Substring(0, timeStr.Length - 2);
            int min = Convert.ToInt32(timeStr.Substring(timeStr.Length - 2));

            timeStr = timeStr.Substring(0, timeStr.Length - 2);
            int hour = (timeStr.Length > 0) ? (Convert.ToInt32(timeStr)) : (0);

            int year = 2000 + Convert.ToInt32(dateStr.Substring(dateStr.Length - 2, 2));

            dateStr = dateStr.Substring(0, dateStr.Length - 2);
            int month = Convert.ToInt32(dateStr.Substring(dateStr.Length - 2, 2));

            dateStr = dateStr.Substring(0, dateStr.Length - 2);
            int day = Convert.ToInt32(dateStr);

            DateTime dt = new DateTime(year, month, day, hour, min, sec, DateTimeKind.Utc);

            return(dt);
        }
        public static Tuple <DateTime, DateTime> GetMetFileDateTimeMargins(string InputFilename)
        {
            int  bytesCountPerObj = Marshal.SizeOf(typeof(IoffeVesselMetData));
            long fileLength       = (new FileInfo(InputFilename)).Length;

            if (fileLength < bytesCountPerObj)
            {
                return(null);
            }


            BinaryReader reader = new BinaryReader(File.Open(InputFilename, FileMode.Open, FileAccess.Read, FileShare.Read));

            byte[]             buf1st    = reader.ReadBytes(bytesCountPerObj);
            GCHandle           handle1st = GCHandle.Alloc(buf1st, GCHandleType.Pinned);
            IoffeVesselMetData record1st =
                (IoffeVesselMetData)
                Marshal.PtrToStructure(handle1st.AddrOfPinnedObject(), typeof(IoffeVesselMetData));
            DateTime dt1 = ExtractDateTime(record1st);

            reader.BaseStream.Seek(-bytesCountPerObj, SeekOrigin.End);
            byte[]             buf2nd    = reader.ReadBytes(bytesCountPerObj);
            GCHandle           handle2nd = GCHandle.Alloc(buf2nd, GCHandleType.Pinned);
            IoffeVesselMetData record2nd =
                (IoffeVesselMetData)
                Marshal.PtrToStructure(handle2nd.AddrOfPinnedObject(), typeof(IoffeVesselMetData));
            DateTime dt2 = ExtractDateTime(record2nd);

            reader.Close();

            return(new Tuple <DateTime, DateTime>(dt1, dt2));
        }
        public static List <IoffeVesselMetDataConverted> ReadMetFile(string InputFilename) //, bool readOnlyThe1stRecord = false)
        {
            int bytesCountPerObj = Marshal.SizeOf(typeof(IoffeVesselMetData));

            if ((new FileInfo(InputFilename)).Length < bytesCountPerObj)
            {
                return(null);
            }
            BinaryReader reader = new BinaryReader(File.Open(InputFilename, FileMode.Open, FileAccess.Read, FileShare.Read));

            reader.Close();

            byte[] fileData = File.ReadAllBytes(InputFilename);

            reader = new BinaryReader(new MemoryStream(fileData));

            List <IoffeVesselMetData> lFileMetData = new List <IoffeVesselMetData>();

            int structCount = Convert.ToInt32(fileData.Count() / bytesCountPerObj);

            if (structCount == 0)
            {
                return(null);
            }
            int readStructs = 0;

            while (true)
            {
                byte[] readBuffer = new byte[bytesCountPerObj];
                readBuffer = reader.ReadBytes(bytesCountPerObj);
                GCHandle           handle    = GCHandle.Alloc(readBuffer, GCHandleType.Pinned);
                IoffeVesselMetData curRecord =
                    (IoffeVesselMetData)
                    Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(IoffeVesselMetData));
                readStructs++;
                lFileMetData.Add(curRecord);
                //if ((readStructs >= structCount) || (readOnlyThe1stRecord))
                if (readStructs >= structCount)
                {
                    break;
                }
            }



            List <IoffeVesselMetDataConverted> lRetList = lFileMetData.ConvertAll(meteoData =>
            {
                IoffeVesselMetDataConverted retMeteoData = new IoffeVesselMetDataConverted();

                retMeteoData.dateTime      = ExtractDateTime(meteoData);
                retMeteoData.tAir          = meteoData.tAir;
                retMeteoData.windSpeed     = meteoData.windSpeed;
                retMeteoData.windDirection = meteoData.windDirection;
                retMeteoData.dewPoint      = meteoData.dewPoint;
                retMeteoData.pressure      = meteoData.pressure;
                retMeteoData.rHumidity     = meteoData.rHumidity;
                retMeteoData.chillTemp     = meteoData.chillTemp;
                retMeteoData.percipitation = meteoData.percipitation;
                return(retMeteoData);
            });


            return(lRetList);
        }