コード例 #1
0
        /// <summary> Finds the min/max lat/long of MERRA nodes needed for specified latitude and longitude. Returns coordinates of additional MERRA data needed (if any). </summary>
        public UTM_conversion.Lat_Long[] GetRequiredNewMERRANodeCoords(double latitude, double longitude, Continuum thisInst)
        {
            UTM_conversion.Lat_Long[] newRequiredMERRANodes = new UTM_conversion.Lat_Long[0];
            int numNewReqNodes = 0;

            UTM_conversion.Lat_Long[] theseRequiredNodes = GetRequiredMERRACoords(latitude, longitude);
            UTM_conversion.Lat_Long[] existingNodes      = new UTM_conversion.Lat_Long[0];
            int numExistingNodes = 0;

            // Loop through required nodes and see what additional nodes are needed
            NodeCollection nodeList   = new NodeCollection();
            string         connString = nodeList.GetDB_ConnectionString(thisInst.savedParams.savedFileName);

            using (var context = new Continuum_EDMContainer(connString))
            {
                var theseNodes = from N in context.MERRA_Node_table select N;

                foreach (var N in theseNodes)
                {
                    numExistingNodes++;
                    Array.Resize(ref existingNodes, numExistingNodes);
                    existingNodes[numExistingNodes - 1].latitude  = N.latitude;
                    existingNodes[numExistingNodes - 1].longitude = N.longitude;
                }
            }

            for (int i = 0; i < numMERRA_Nodes; i++)
            {
                bool gotIt = false;
                for (int j = 0; j < numExistingNodes; j++)
                {
                    if (existingNodes[j].latitude == theseRequiredNodes[i].latitude && existingNodes[j].longitude == theseRequiredNodes[i].longitude)
                    {
                        gotIt = true;
                        break;
                    }
                }

                if (gotIt == false)
                {
                    numNewReqNodes++;
                    Array.Resize(ref newRequiredMERRANodes, numNewReqNodes);
                    newRequiredMERRANodes[numNewReqNodes - 1].latitude  = theseRequiredNodes[i].latitude;
                    newRequiredMERRANodes[numNewReqNodes - 1].longitude = theseRequiredNodes[i].longitude;
                }
            }

            return(newRequiredMERRANodes);
        }
コード例 #2
0
        /// <summary> Returns array of lat/long coordinates of MERRA2 coordinates for specified lat/long </summary>
        public UTM_conversion.Lat_Long[] GetRequiredMERRACoords(double latitude, double longitude)
        {
            UTM_conversion.Lat_Long[] theseReqCoords = new UTM_conversion.Lat_Long[numMERRA_Nodes];

            double minReqLat  = Math.Round(latitude / 0.5, 0) * 0.5;
            double minReqLong = Math.Round(longitude / 0.625) * 0.625;
            double maxReqLat  = minReqLat;
            double maxReqLong = minReqLong;

            if (numMERRA_Nodes == 1)
            {
                theseReqCoords[0].latitude  = minReqLat;
                theseReqCoords[0].longitude = minReqLong;
            }
            else if (numMERRA_Nodes == 4)
            {
                if (latitude > minReqLat)
                {
                    maxReqLat = minReqLat + 0.5;
                }
                else
                {
                    minReqLat = minReqLat - 0.5;
                    maxReqLat = minReqLat + 0.5;
                }

                if (longitude > minReqLong)
                {
                    maxReqLong = minReqLong + 0.625;
                }
                else
                {
                    minReqLong = minReqLong - 0.625;
                    maxReqLong = minReqLong + 0.625;
                }

                theseReqCoords[0].latitude  = minReqLat;
                theseReqCoords[0].longitude = minReqLong;

                theseReqCoords[1].latitude  = minReqLat;
                theseReqCoords[1].longitude = maxReqLong;

                theseReqCoords[2].latitude  = maxReqLat;
                theseReqCoords[2].longitude = minReqLong;

                theseReqCoords[3].latitude  = maxReqLat;
                theseReqCoords[3].longitude = maxReqLong;
            }
            else if (numMERRA_Nodes == 16)
            {
                if (latitude > minReqLat)
                {
                    minReqLat = minReqLat - 0.5;
                    maxReqLat = minReqLat + 3 * 0.5;
                }
                else
                {
                    minReqLat = minReqLat - 1;
                    maxReqLat = minReqLat + 3 * 0.5;
                }

                if (longitude > minReqLong)
                {
                    minReqLong = minReqLong - 0.625;
                    maxReqLong = minReqLong + 3 * 0.625;
                }
                else
                {
                    minReqLong = minReqLong - 2 * 0.625;
                    maxReqLong = minReqLong + 3 * 0.625;
                }

                int latInd  = 0;
                int longInd = 0;

                for (int i = 0; i < numMERRA_Nodes; i++)
                {
                    theseReqCoords[i].latitude  = minReqLat + 0.5 * latInd;
                    theseReqCoords[i].longitude = minReqLong + 0.625 * longInd;

                    latInd++;
                    if (latInd >= 4)
                    {
                        latInd = 0;
                        longInd++;
                    }
                }
            }

            return(theseReqCoords);
        }