예제 #1
0
        public static Transaction Decode(XdrDataInputStream stream)
        {
            Transaction decodedTransaction = new Transaction();

            decodedTransaction.SourceAccount = AccountID.Decode(stream);
            decodedTransaction.Fee           = Uint32.Decode(stream);
            decodedTransaction.SeqNum        = SequenceNumber.Decode(stream);
            int TimeBoundsPresent = stream.ReadInt();

            if (TimeBoundsPresent != 0)
            {
                decodedTransaction.TimeBounds = TimeBounds.Decode(stream);
            }

            decodedTransaction.Memo = Memo.Decode(stream);
            int operationssize = stream.ReadInt();

            decodedTransaction.Operations = new Operation[operationssize];

            for (int i = 0; i < operationssize; i++)
            {
                decodedTransaction.Operations[i] = Operation.Decode(stream);
            }

            decodedTransaction.Ext = TransactionExt.Decode(stream);
            return(decodedTransaction);
        }
예제 #2
0
        public void TestTimeBoundsWithoutMaxTime()
        {
            var timeBounds = new TimeBounds(100, 0);

            Assert.AreEqual(100, timeBounds.MinTime);
            Assert.AreEqual(0, timeBounds.MaxTime);
        }
예제 #3
0
        public static void Encode(XdrDataOutputStream stream, Transaction encodedTransaction)
        {
            AccountID.Encode(stream, encodedTransaction.SourceAccount);
            Uint32.Encode(stream, encodedTransaction.Fee);
            SequenceNumber.Encode(stream, encodedTransaction.SeqNum);

            if (encodedTransaction.TimeBounds != null)
            {
                stream.WriteInt(1);
                TimeBounds.Encode(stream, encodedTransaction.TimeBounds);
            }
            else
            {
                stream.WriteInt(0);
            }

            Memo.Encode(stream, encodedTransaction.Memo);
            int operationssize = encodedTransaction.Operations.Length;

            stream.WriteInt(operationssize);

            for (int i = 0; i < operationssize; i++)
            {
                Operation.Encode(stream, encodedTransaction.Operations[i]);
            }

            TransactionExt.Encode(stream, encodedTransaction.Ext);
        }
예제 #4
0
        public static TimeBounds Decode(IByteReader stream)
        {
            TimeBounds decodedTimeBounds = new TimeBounds();

            decodedTimeBounds.MinTime = Uint64.Decode(stream);
            decodedTimeBounds.MaxTime = Uint64.Decode(stream);
            return(decodedTimeBounds);
        }
예제 #5
0
        public void TestTimeBoundsHashEquality()
        {
            var timeBounds  = new TimeBounds(56, 65);
            var timeBounds2 = new TimeBounds(56, 65);

            Assert.AreEqual(timeBounds.GetHashCode(), timeBounds.GetHashCode());
            Assert.AreEqual(timeBounds2, timeBounds2);
        }
예제 #6
0
        public void TestTimeBoundsWithDateTimeWithoutMinTime()
        {
            var now        = new DateTime(2018, 12, 01, 17, 30, 30, DateTimeKind.Utc);
            var timeBounds = new TimeBounds(maxTime: now);

            Assert.AreEqual(0, timeBounds.MinTime);
            Assert.AreEqual(1543685430, timeBounds.MaxTime);
        }
예제 #7
0
        public static TimeBounds Decode(XdrDataInputStream stream)
        {
            TimeBounds decodedTimeBounds = new TimeBounds();

            decodedTimeBounds.MinTime = TimePoint.Decode(stream);
            decodedTimeBounds.MaxTime = TimePoint.Decode(stream);
            return(decodedTimeBounds);
        }
예제 #8
0
        public static TimeBounds Decode(XdrDataInputStream stream)
        {
            var decodedTimeBounds = new TimeBounds();

            decodedTimeBounds.MinTime = Uint64.Decode(stream);
            decodedTimeBounds.MaxTime = Uint64.Decode(stream);
            return(decodedTimeBounds);
        }
예제 #9
0
        public void TestTimeBoundsWithDuration()
        {
            var now        = new DateTime(2018, 12, 01, 17, 30, 30, DateTimeKind.Utc);
            var duration   = TimeSpan.FromDays(2.0);
            var timeBounds = new TimeBounds(now, duration);

            Assert.AreEqual(1543685430, timeBounds.MinTime);
            Assert.AreEqual(1543858230, timeBounds.MaxTime);
        }
예제 #10
0
        public void TestTimeBoundsWithDurationFromUtcNow()
        {
            var now         = DateTimeOffset.UtcNow;
            var duration    = TimeSpan.FromDays(2.0);
            var timeBounds  = new TimeBounds(duration);
            var maxDateTime = DateTimeOffset.FromUnixTimeSeconds(timeBounds.MaxTime);

            Assert.AreNotEqual(0, timeBounds.MinTime);
            Assert.IsTrue(maxDateTime > now);
        }
예제 #11
0
 public RilDataConverter()
 {
     this.rilDataReader =
         (RilDataReader)FactoryDataReader.GetInstance(FactoryDataReader.AvailableDataReaderTypes.RIL);
     this.geoBounds =
         (GeographicBatBounds)BoundsFactory.GetInstance(BoundsFactory.AvailableBoundsTypes.BATIMENT);
     this.timeBounds =
         (TimeBounds)BoundsFactory.GetInstance(BoundsFactory.AvailableBoundsTypes.TIME);
     this.dataBounds =
         (RilBounds)BoundsFactory.GetInstance(BoundsFactory.AvailableBoundsTypes.RIL);
 }
예제 #12
0
        public RingBufferStatus GetTimeBounds(ref long startTime, ref long endTime)
        {
            for (int i = 0; i < 8; ++i) // fail after a few tries
            {
                uint       curPtr = TimeBoundsQueuePtr;
                uint       index  = curPtr & GENERAL_RING_TIME_BOUNDS_QUEUE_MASK;
                TimeBounds bounds = _timeBoundsQueue[index];

                startTime = bounds.StartTime;
                endTime   = bounds.EndTime;
                uint newPtr = bounds.UpdateCounter;

                if (newPtr == curPtr)
                {
                    return(RingBufferStatus.OK);
                }
            }

            return(RingBufferStatus.CPUOverload);
        }
예제 #13
0
        public static void Encode(IByteWriter stream, Transaction encodedTransaction)
        {
            AccountID.Encode(stream, encodedTransaction.SourceAccount);
            Uint32.Encode(stream, encodedTransaction.Fee);
            SequenceNumber.Encode(stream, encodedTransaction.SeqNum);
            if (encodedTransaction.TimeBounds != null)
            {
                XdrEncoding.EncodeInt32(1, stream);
                TimeBounds.Encode(stream, encodedTransaction.TimeBounds);
            }
            else
            {
                XdrEncoding.EncodeInt32(0, stream);
            }
            Memo.Encode(stream, encodedTransaction.Memo);
            int operationssize = encodedTransaction.Operations.Length;

            XdrEncoding.EncodeInt32(operationssize, stream);
            for (int i = 0; i < operationssize; i++)
            {
                Operation.Encode(stream, encodedTransaction.Operations[i]);
            }
            TransactionExt.Encode(stream, encodedTransaction.Ext);
        }
예제 #14
0
        public static Transaction Decode(IByteReader stream)
        {
            Transaction decodedTransaction = new Transaction();

            decodedTransaction.SourceAccount = AccountID.Decode(stream);
            decodedTransaction.Fee           = Uint32.Decode(stream);
            decodedTransaction.SeqNum        = SequenceNumber.Decode(stream);
            int timeBoundsPresent = XdrEncoding.DecodeInt32(stream);

            if (timeBoundsPresent != 0)
            {
                decodedTransaction.TimeBounds = TimeBounds.Decode(stream);
            }
            decodedTransaction.Memo = Memo.Decode(stream);
            int operationssize = XdrEncoding.DecodeInt32(stream);

            decodedTransaction.Operations = new Operation[operationssize];
            for (int i = 0; i < operationssize; i++)
            {
                decodedTransaction.Operations[i] = Operation.Decode(stream);
            }
            decodedTransaction.Ext = TransactionExt.Decode(stream);
            return(decodedTransaction);
        }
        private static void FillMetadata(Variable v, TimeBounds[] climatlogyIntervals, Climate.Conventions.FetchClimateBatchResponce response, string longName)
        {
            if (climatlogyIntervals != null)
                v.Metadata["cell_methods"] = "time: mean within days  time: mean over days  time: mean over years";

            string[] dataSources = response.Values.Select(r => r.Provenance).Distinct().ToArray();
            StringBuilder bld = new StringBuilder();
            bool firstDataSource = true;
            for (int i = 0; i < dataSources.Length; i++)
            {
                if (firstDataSource)
                    firstDataSource = false;
                else
                    bld.Append(", ");
                bld.Append(dataSources[i]);
            }
            string sources = bld.ToString();

            v.Metadata["long_name"] = longName;
            v.Metadata["DisplayName"] = longName;
            v.Metadata["Provenance"] = String.Format("Data sources: {0}; served by FetchClimate Service (http://fetchclimate.cloudapp.net/)", sources);
            v.Metadata["references"] = "http://fetchclimate.cloudapp.net/";
            v.Metadata["source"] = string.Format("Interpolated from {0}", sources);
            v.Metadata["institution"] = string.Format("FetchClimate service ({0})", response.ServiceVersion);
        }
        private static Variable Fetch(this DataSet ds, ClimateParameter parameter, string name, Variable lat, Variable lon, Variable timeSlices, string nameUncertainty, string nameProvenance, EnvironmentalDataSource dataSource, TimeBounds[] climatologyBounds = null)
        {
            if (ds == null) throw new ArgumentNullException("ds");
            if (String.IsNullOrWhiteSpace(name)) throw new ArgumentException("name is incorrect");
            if (lat == null) throw new ArgumentNullException("lat");
            if (lon == null) throw new ArgumentNullException("lon");
            if (timeSlices == null) throw new ArgumentNullException("timeSlices");
            if (lat.Rank != 1) throw new ArgumentException("lat is not one-dimensional");
            if (lon.Rank != 1) throw new ArgumentException("lon is not one-dimensional");
            if (timeSlices.Rank != 1) throw new ArgumentException("time is not one-dimensional");

            DataRequest[] req = null;
            MultipleDataResponse resp = null;
            if (climatologyBounds == null)
            {
                req = new DataRequest[3];
                req[0] = DataRequest.GetData(lat);
                req[1] = DataRequest.GetData(lon);
                req[2] = DataRequest.GetData(timeSlices);
                resp = ds.GetMultipleData(req);
            }
            else
            {
                req = new DataRequest[2];
                req[0] = DataRequest.GetData(lat);
                req[1] = DataRequest.GetData(lon);
                resp = ds.GetMultipleData(req);
            }

            double[] _latmaxs = null;
            double[] _lonmaxs = null;
            double[] _latmins = null;
            double[] _lonmins = null;
            if (lat.Metadata.ContainsKey("bounds") && lon.Metadata.ContainsKey("bounds")) //case of cells
            {
                Variable latBounds = ds.Variables[(string)lat.Metadata["bounds"]];
                Variable lonBounds = ds.Variables[(string)lon.Metadata["bounds"]];
                if (latBounds.Rank == 2 && lonBounds.Rank == 2
                    && lonBounds.Dimensions[0].Name == lon.Dimensions[0].Name
                    && latBounds.Dimensions[0].Name == lat.Dimensions[0].Name)
                {
                    Array latBoundsData = latBounds.GetData();
                    Array lonBoundsData = lonBounds.GetData();
                    int dimLatLen = latBounds.Dimensions[0].Length;
                    int dimLonLen = lonBounds.Dimensions[0].Length;
                    _latmins = new double[dimLatLen];
                    _latmaxs = new double[dimLatLen];
                    _lonmins = new double[dimLonLen];
                    _lonmaxs = new double[dimLonLen];
                    for (int i = 0; i < dimLatLen; i++)
                    {
                        _latmins[i] = Convert.ToDouble(latBoundsData.GetValue(i, 0));
                        _latmaxs[i] = Convert.ToDouble(latBoundsData.GetValue(i, 1));
                    }
                    for (int i = 0; i < dimLonLen; i++)
                    {
                        _lonmins[i] = Convert.ToDouble(lonBoundsData.GetValue(i, 0));
                        _lonmaxs[i] = Convert.ToDouble(lonBoundsData.GetValue(i, 1));
                    }
                }
            }
            if (_latmins == null || _lonmins == null) //case of grid without cells
            {
                _latmins = GetDoubles(resp[lat.ID].Data);
                _lonmins = GetDoubles(resp[lon.ID].Data);
            }
            DateTime[] _times = null;
            if (climatologyBounds == null)
                _times = (DateTime[])resp[timeSlices.ID].Data;

            if (climatologyBounds != null)
                return Fetch(ds, parameter, name, _latmins, _lonmins, lat.Dimensions[0].Name, lon.Dimensions[0].Name, dimTime: timeSlices.Dimensions[0].Name, latmaxs: _latmaxs, lonmaxs: _lonmaxs, climatologyIntervals: climatologyBounds, nameUncertainty: nameUncertainty, nameProvenance: nameProvenance, dataSource: dataSource);
            else
                return Fetch(ds, parameter, name, _latmins, _lonmins, lat.Dimensions[0].Name, lon.Dimensions[0].Name, dimTime: timeSlices.Dimensions[0].Name, latmaxs: _latmaxs, lonmaxs: _lonmaxs, timeSlices: _times, nameUncertainty: nameUncertainty, nameProvenance: nameProvenance, dataSource: dataSource);
        }
        private static Variable Fetch(this DataSet ds, ClimateParameter parameter, string name, double[] latmins, double[] lonmins, string dimLat, string dimLon, double[] latmaxs = null, double[] lonmaxs = null, string dimTime = null, DateTime[] timeSlices = null, TimeBounds[] climatologyIntervals = null, string nameUncertainty = null, string nameProvenance = null, EnvironmentalDataSource dataSource = EnvironmentalDataSource.ANY)
        {
            if (timeSlices == null && climatologyIntervals == null)
                throw new ArgumentNullException("Both timeSlices and ClimatologyIntervals are null");
            if (latmaxs == null ^ lonmaxs == null)
                throw new ArgumentException("Only one of latmax and lonmax is set. please set both of them or none");
            object mv = double.NaN;
            string longName = GetLongName(parameter);

            bool isFetchingGrid = dimLat != dimLon; // otherwise, fetching point set, when all axes depend on the same dimension

            // Preparing FetchClimate method parameters
            int index = 0;
            int[] starthour, stophour, startday, stopday, startyear, stopyear;
            double[] minLats, minLons, maxLats, maxLons;

            int timesN = (climatologyIntervals != null) ? (climatologyIntervals.Length) : (timeSlices.Length);
            if (isFetchingGrid)
            {
                #region Preparing request for grid
                int latN = latmins.Length;
                int lonN = lonmins.Length;
                if (latN <= 0)
                    throw new ArgumentException("lats. Too short latitude axis");
                if (lonN <= 0)
                    throw new ArgumentException("lons. Too short longitude axis");
                int n = latN * lonN * timesN;
                if (n == 0) throw new ArgumentException("Empty region is requested");
                starthour = new int[n]; stophour = new int[n]; startday = new int[n]; stopday = new int[n]; startyear = new int[n]; stopyear = new int[n];
                minLats = new double[n]; minLons = new double[n];
                maxLats = new double[n]; maxLons = new double[n];
                if (climatologyIntervals != null)
                {
                    for (int j = 0; j < latN; j++)
                    {
                        double latmax = (latmaxs == null) ? latmins[j] : latmaxs[j];
                        double latmin = latmins[j];
                        for (int k = 0; k < lonN; k++)
                        {
                            double lonmax = (lonmaxs == null) ? lonmins[k] : lonmaxs[k];
                            double lonmin = lonmins[k];
                            for (int i = 0; i < timesN; i++)
                            {
                                startyear[index] = climatologyIntervals[i].MinYear;
                                startday[index] = climatologyIntervals[i].MinDay;
                                starthour[index] = climatologyIntervals[i].MinHour;

                                stopyear[index] = climatologyIntervals[i].MaxYear;
                                stopday[index] = climatologyIntervals[i].MaxDay;
                                stophour[index] = climatologyIntervals[i].MaxHour;

                                minLats[index] = latmin;
                                minLons[index] = lonmin;

                                maxLats[index] = latmax;
                                maxLons[index] = lonmax;

                                index++;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < latN; j++)
                    {
                        double latmin = latmins[j];
                        double latmax = (latmaxs == null) ? latmins[j] : latmaxs[j];
                        for (int k = 0; k < lonN; k++)
                        {
                            double lonmax = (lonmaxs == null) ? lonmins[k] : lonmaxs[k];
                            double lonmin = lonmins[k];

                            for (int i = 0; i < timesN; i++)
                            {
                                starthour[index] = stophour[index] = timeSlices[i].Hour;
                                startday[index] = stopday[index] = timeSlices[i].DayOfYear;
                                startyear[index] = stopyear[index] = timeSlices[i].Year;

                                minLats[index] = latmin;
                                minLons[index] = lonmin;

                                maxLats[index] = latmax;
                                maxLons[index] = lonmax;

                                index++;
                            }
                        }
                    }
                }
                #endregion
            }
            else // preparing request for pointset 
            {
                #region Preparing request for pointset
                int coordN = latmins.Length;
                int n = coordN * timesN;
                if (n == 0) throw new ArgumentException("Empty region is requested");
                if (latmaxs != null || lonmaxs != null)
                    throw new InvalidOperationException("In case of pointset fetching latmaxs and lonmaxs must be omited");
                starthour = new int[n]; stophour = new int[n]; startday = new int[n]; stopday = new int[n]; startyear = new int[n]; stopyear = new int[n];
                minLats = new double[n]; minLons = new double[n];
                maxLats = new double[n]; maxLons = new double[n];
                if (climatologyIntervals != null)
                {
                    for (int i = 0; i < timesN; i++)
                        for (int j = 0; j < coordN; j++)
                        {
                            startyear[index] = climatologyIntervals[i].MinYear;
                            startday[index] = climatologyIntervals[i].MinDay;
                            starthour[index] = climatologyIntervals[i].MinHour;

                            stopyear[index] = climatologyIntervals[i].MaxYear;
                            stopday[index] = climatologyIntervals[i].MaxDay;
                            stophour[index] = climatologyIntervals[i].MaxHour;

                            minLats[index] = maxLats[index] = latmins[j];
                            minLons[index] = maxLons[index] = lonmins[j];
                            index++;
                        }
                }
                else
                {
                    for (int i = 0; i < timesN; i++)
                        for (int j = 0; j < coordN; j++)
                        {
                            starthour[index] = stophour[index] = timeSlices[i].Hour;
                            startday[index] = stopday[index] = timeSlices[i].DayOfYear;
                            startyear[index] = stopyear[index] = timeSlices[i].Year;
                            minLats[index] = maxLats[index] = latmins[j];
                            minLons[index] = maxLons[index] = lonmins[j];
                            index++;
                        }
                }
                #endregion
            }

            // Fetching the data
            var resp = ClimateService.FetchClimateEx(parameter, new FetchingOptions() { DataSourceToUse = dataSource }, minLats, maxLats, minLons, maxLons, starthour, stophour, startday, stopday, startyear, stopyear);
            ClimateParameterValue[] climateData = resp.Values;
            string units = climateData.First().DefaultClientUnitsString;

            // Saving result in the dataset
            bool _ac = ds.IsAutocommitEnabled;
            Variable varData = null, varUncertainty = null, varProv = null;
            bool saveUncertainty = !String.IsNullOrWhiteSpace(nameUncertainty);
            bool saveProv = !String.IsNullOrWhiteSpace(nameProvenance);

            try
            {
                ds.IsAutocommitEnabled = false;
                index = 0;
                if (isFetchingGrid)
                {
                    #region Putting grid data into DataSet
                    int latN = latmins.Length;
                    int lonN = lonmins.Length;
                    if (dimTime != null)
                    {
                        double[, ,] data = new double[timesN, latmins.Length, lonmins.Length];
                        double[, ,] uncertainty = saveUncertainty ? new double[timesN, latmins.Length, lonmins.Length] : null;
                        string[, ,] provenance = saveProv ? new string[timesN, latmins.Length, lonmins.Length] : null;                        
                            for (int j = 0; j < latN; j++)
                                for (int k = 0; k < lonN; k++)
                                    for (int i = 0; i < timesN; i++)                        
                                {
                                    var cd = climateData[index++];
                                    data[i, j, k] = cd.GetValueInDefaultClientUnits();
                                    if (saveUncertainty)
                                        uncertainty[i, j, k] = cd.GetUncertaintyInDefaultClientUnits();
                                    if (saveProv)
                                        provenance[i, j, k] = cd.Provenance;
                                }                        
                        varData = ds.Add(name, units, mv, data, dimTime, dimLat, dimLon);
                        if (saveUncertainty) varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimTime, dimLat, dimLon);
                        if (saveProv) varProv = ds.Add(nameProvenance, provenance, dimTime, dimLat, dimLon);
                    }
                    else
                    {
                        double[,] data = new double[latmins.Length, lonmins.Length];
                        double[,] uncertainty = saveUncertainty ? new double[latmins.Length, lonmins.Length] : null;
                        string[,] provenance = saveProv ? new string[latmins.Length, lonmins.Length] : null;
                        for (int i = 0; i < latN; i++)
                            for (int j = 0; j < lonN; j++)
                            {
                                var cd = climateData[index++];
                                data[i, j] = cd.GetValueInDefaultClientUnits();
                                if (saveUncertainty)
                                    uncertainty[i, j] = cd.GetUncertaintyInDefaultClientUnits();
                                if (saveProv)
                                    provenance[i, j] = cd.Provenance;
                            }
                        varData = ds.Add(name, units, mv, data, dimLat, dimLon);
                        varData.Metadata["Time"] = timeSlices[0];
                        if (saveUncertainty)
                        {
                            varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimLat, dimLon);
                            varUncertainty.Metadata["Time"] = timeSlices[0];
                        }
                        if (saveProv)
                        {
                            varProv = ds.Add(nameProvenance, provenance, dimLat, dimLon);
                            varProv.Metadata["Time"] = timeSlices[0];
                        }
                    }
                    #endregion
                }
                else // saving pointset into the dataset
                {
                    #region Putting pointset data into Dataset
                    int coordN = latmins.Length;
                    if (dimTime != null)
                    {
                        double[,] data = new double[timesN, coordN];
                        double[,] uncertainty = saveUncertainty ? new double[timesN, coordN] : null;
                        string[,] provenance = saveProv ? new string[timesN, coordN] : null;
                        for (int i = 0; i < timesN; i++)
                            for (int j = 0; j < coordN; j++)
                            {
                                var cd = climateData[index++];
                                data[i, j] = cd.GetValueInDefaultClientUnits();
                                if (saveUncertainty)
                                    uncertainty[i, j] = cd.GetUncertaintyInDefaultClientUnits();
                                if (saveProv)
                                    provenance[i, j] = cd.Provenance;
                            }
                        varData = ds.Add(name, units, mv, data, dimTime, dimLat);
                        if (saveUncertainty) varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimTime, dimLat);
                        if (saveProv) varProv = ds.Add(nameProvenance, provenance, dimTime, dimLat);
                    }
                    else
                    {
                        double[] data = new double[coordN];
                        double[] uncertainty = saveUncertainty ? new double[coordN] : null;
                        string[] provenance = saveProv ? new string[coordN] : null;
                        for (int i = 0; i < coordN; i++)
                        {
                            var cd = climateData[index++];
                            data[i] = cd.GetValueInDefaultClientUnits();
                            if (saveUncertainty)
                                uncertainty[i] = cd.GetUncertaintyInDefaultClientUnits();
                            if (saveProv)
                                provenance[i] = cd.Provenance;
                        }
                        varData = ds.Add(name, units, mv, data, dimLat);
                        varData.Metadata["Time"] = timeSlices[0];
                        if (saveUncertainty)
                        {
                            varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimLat);
                            varUncertainty.Metadata["Time"] = timeSlices[0];
                        }
                        if (saveProv)
                        {
                            varProv = ds.Add(nameProvenance, provenance, dimLat);
                            varProv.Metadata["Time"] = timeSlices[0];
                        }
                    }
                    #endregion
                }

                FillMetadata(varData, climatologyIntervals, resp, longName);
                if (saveUncertainty) FillUncertaintyMetadata(varUncertainty, resp, longName);
                if (saveProv) FillProvenanceMetadata(varProv, resp, longName);
                ds.Commit();
            }
            finally
            {
                ds.IsAutocommitEnabled = _ac;
            }
            return varData;
        }
 public static TimeBounds Decode(IByteReader stream) {
   TimeBounds decodedTimeBounds = new TimeBounds();
   decodedTimeBounds.MinTime = Uint64.Decode(stream);
   decodedTimeBounds.MaxTime = Uint64.Decode(stream);
   return decodedTimeBounds;
 }
 private static TimeBounds[] GetClimatologyBounds(DataSet ds, int timeAxisID = -1)
 {
     List<TimeBounds> tbList = new List<TimeBounds>();
     IEnumerable<Variable> q = timeAxisID < 0 ? ds.Variables.Where(va => va.Rank == 1 && va.Metadata.ContainsKey("climatology")) :
         new Variable[] { ds.Variables.GetByID(timeAxisID) };
     foreach (Variable timeVar in q)
     {
         Dimension timeDim = timeVar.Dimensions[0];
         var climAxes = ds.Variables.Where(cv => cv.Rank == 2 && cv.TypeOfData == typeof(DateTime) && cv.Dimensions[0].Name == timeDim.Name && cv.Dimensions[1].Length == 2);
         if (climAxes.Count() > 1)
             throw new ArgumentException(string.Format("There are {0} possible climatological axes. Ambiguous specification", climAxes.Count()));
         Variable climatologyAxis = climAxes.FirstOrDefault();
         if (climatologyAxis == null)
             continue;
         DateTime[,] bounds = (DateTime[,])climatologyAxis.GetData();
         for (int i = 0; i < bounds.GetLength(0); i++)
         {
             TimeBounds tb = new TimeBounds()
             {
                 MinYear = bounds[i, 0].Year,
                 MinDay = bounds[i, 0].DayOfYear,
                 MinHour = bounds[i, 0].Hour,
                 MaxYear = bounds[i, 1].Year,
                 MaxDay = bounds[i, 1].DayOfYear,
                 MaxHour = bounds[i, 1].Hour
             };
             if (tb.MaxDay == 1 && tb.MaxHour == 0)
             {
                 tb.MaxDay = 365;
                 tb.MaxHour = 24;
                 tb.MaxYear--;
             }
             if (tb.MaxHour == tb.MinHour)
             {
                 tb.MinHour = 0;
                 tb.MaxHour = 24;
             }
             tbList.Add(tb);
         }
         break;
     }
     return tbList.ToArray();
 }
 public static void Encode(IByteWriter stream, TimeBounds encodedTimeBounds) {
   Uint64.Encode(stream, encodedTimeBounds.MinTime);
   Uint64.Encode(stream, encodedTimeBounds.MaxTime);
 }
예제 #21
0
 public MultipleRequestDescriptor(ClimateParameter p, TimeBounds tb, FetchingTimeModes mode)
 {
     parameter = p;
     timeBounds = tb;
     timeMode = mode;
 }
예제 #22
0
 public MultipleRequestDescriptor(ClimateParameter p, TimeBounds tb, FetchingTimeModes mode)
 {
     parameter  = p;
     timeBounds = tb;
     timeMode   = mode;
 }
예제 #23
0
 public static void Encode(IByteWriter stream, TimeBounds encodedTimeBounds)
 {
     Uint64.Encode(stream, encodedTimeBounds.MinTime);
     Uint64.Encode(stream, encodedTimeBounds.MaxTime);
 }
예제 #24
0
 public static void Encode(XdrDataOutputStream stream, TimeBounds encodedTimeBounds)
 {
     Uint64.Encode(stream, encodedTimeBounds.MinTime);
     Uint64.Encode(stream, encodedTimeBounds.MaxTime);
 }