Ejemplo n.º 1
0
        /// <summary>Check if this data is compatible with Random Groups structure.
        /// Must be an Object[ngr][2] structure with both elements of each
        /// group having the same base type and the first element being
        /// a simple primitive array.  We do not check anything but
        /// the first row.</summary>
        public static bool IsData(Object oo)
        {
            if (oo is Object[][]) //ArrayFuncs.CountDimensions(oo) == 2)
            {
                //Object[][] o = (Object[][]) oo;

                //if(o.Length > 0)
                if (ArrayFuncs.IsArrayOfArrays(oo))
                {
                    try
                    {
                        Array a  = (Array)oo;
                        Type  t1 = ArrayFuncs.GetBaseClass(((Array)a.GetValue(0)).GetValue(0));
                        Type  t2 = ArrayFuncs.GetBaseClass(((Array)a.GetValue(0)).GetValue(1));

                        return(((Array)a.GetValue(0)).Length == 2 &&
                               t1.Equals(t2) && !t1.Equals(typeof(char)) && !t1.Equals(typeof(bool)));
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                else
                {
                    try
                    {
                        Array a  = (Array)oo;
                        Type  t1 = a.GetValue(new int[] { 0, 0 }).GetType();
                        Type  t2 = a.GetValue(new int[] { 0, 1 }).GetType();

                        return(a.GetLength(1) == 2 &&
                               t1.Equals(t2) && !t1.Equals(typeof(char)) && !t1.Equals(typeof(bool)));
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }

                /*
                 *      {
                 *              if(o[0].Length == 2)
                 *              {
                 *                      if (ArrayFuncs.getBaseClass(o[0][0]) == ArrayFuncs.getBaseClass(o[0][1]))
                 *                      {
                 *                              System.String cn = o[0][0].GetType().FullName;
                 *                              if (cn.Length == 2 && cn[1] != 'Z' || cn[1] != 'C')
                 *                              {
                 *                                      return true;
                 *                              }
                 *                      }
                 *              }
                 *      }
                 */
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>Fill a single segment from memory.
        /// This routine is called recursively to handle multi-dimensional
        /// arrays.  E.g., if data is three-dimensional, this will
        /// recurse two levels until we get a call with a single dimensional
        /// datum.  At that point the appropriate data will be copied
        /// into the output.</summary>
        /// <param name="data">The in-memory image data.</param>
        /// <param name="posits">The current position for which data is requested.</param>
        /// <param name="length">The size of the segments.</param>
        /// <param name="output">The output tile.</param>
        /// <param name="outputOffset">The current offset into the output tile.</param>
        /// <param name="dim">The current dimension being</param>
        protected internal virtual void FillMemData(Array data, int[] posits, int length,
                                                    Array output, int outputOffset, int dim)
        {
            // FIX THIS n-D crap
            //if(data is Object[])
            if (ArrayFuncs.CountDimensions(data) > 1)
            {
                if (ArrayFuncs.IsArrayOfArrays(data))
                {
                    //Object[] xo = (Object[]) data;
                    //FillMemData((Array)xo[posits[dim]], posits, length, output, outputOffset, dim + 1);
                    FillMemData((Array)((Array)data).GetValue(posits[dim]), posits, length, output, outputOffset, dim + 1);
                }
                else
                {
                    throw new Exception("Called FillMemData with multi-dimensional array.");
                }
            }
            else
            {
                // Adjust the spacing for the actual copy.
                int startFrom  = posits[dim];
                int startTo    = outputOffset;
                int copyLength = length;

                if (posits[dim] < 0)
                {
                    startFrom  -= posits[dim];
                    startTo    -= posits[dim];
                    copyLength += posits[dim];
                }
                if (posits[dim] + length > dims[dim])
                {
                    copyLength -= (posits[dim] + length - dims[dim]);
                }

                Array.Copy(data, startFrom, output, startTo, copyLength);
            }
        }
Ejemplo n.º 3
0
        public static Data Encapsulate(Object o)
        {
            if (o != null && o.GetType().IsArray)
            {
                if (ArrayFuncs.IsArrayOfArrays(o))
                {
                    Array      oo = (Array)o;
                    AsciiTable d  = new AsciiTable();
                    for (int i = 0; i < oo.Length; i += 1)
                    {
                        d.AddColumn(oo.GetValue(i));
                    }
                    return(d);
                }
                else
                {
                    throw new Exception("OOPS.  FIX AsciiTableHDU.Encapsulate(Object o).");
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>Fill the subset.</summary>
        /// <param name="data">The memory-resident data image.
        /// This may be null if the image is to be read from a file.  This should
        /// be a multi-dimensional primitive array.</param>
        /// <param name="o">The tile to be filled.  This is a simple primitive array.</param>
        /// <param name="dims">The dimensions of the full image.</param>
        /// <param name="corners">The indices of the corner of the image.</param>
        /// <param name="lengths">The dimensions of the subset.</param>
        protected internal virtual void FillTile(Array data, Array o, int[] dims, int[] corners, int[] lengths)
        {
            int n = dims.Length;

            int[] posits     = new int[n];
            int   baseLength = ArrayFuncs.GetBaseLength(o);
            int   segment    = lengths[n - 1];

            Array.Copy(corners, 0, posits, 0, n);
            long currentOffset = 0;

            if (data == null)
            {
                //currentOffset = f.FilePointer;

                currentOffset = f.Position;
            }

            int outputOffset = 0;

            if (data != null && data.GetType().Equals(typeof(Array)) && !ArrayFuncs.IsArrayOfArrays(data))
            {
                int[] index = new int[posits.Length];
                Array.Copy(posits, 0, index, 0, n);
                index[index.Length - 1] -= 1;
                for (int i = outputOffset; ArrayFuncs.NextIndex(index, posits, lengths); ++i)
                {
                    o.SetValue(data.GetValue(index), i);
                }

                return;
            }

            do
            {
                // This implies there is some overlap in the last index
                // (in conjunction with other tests)
                int  mx           = dims.Length - 1;
                bool validSegment = posits[mx] + lengths[mx] >= 0 && posits[mx] < dims[mx];


                // Don't do anything for the current segment if anything but the
                // last index is out of range.
                if (validSegment)
                {
                    for (int i = 0; i < mx; i += 1)
                    {
                        if (posits[i] < 0 || posits[i] >= dims[i])
                        {
                            validSegment = false;
                            break;
                        }
                    }
                }

                if (validSegment)
                {
                    if (data != null)
                    {
                        FillMemData(data, posits, segment, o, outputOffset, 0);
                    }
                    else
                    {
                        int offset = GetOffset(dims, posits) * baseLength;

                        // Point to offset at real beginning
                        // of segment
                        int actualLen    = segment;
                        int actualOffset = offset;
                        int actualOutput = outputOffset;
                        if (posits[mx] < 0)
                        {
                            actualOffset -= posits[mx] * baseLength;
                            actualOutput -= posits[mx];
                            actualLen    += posits[mx];
                        }
                        if (posits[mx] + segment > dims[mx])
                        {
                            actualLen -= posits[mx] + segment - dims[mx];
                        }
                        FillFileData(o, actualOffset, actualOutput, actualLen);
                    }
                }
                outputOffset += segment;
            }while(IncrementPosition(corners, posits, lengths));
            if (data == null)
            {
                f.Seek(currentOffset, SeekOrigin.Begin);
            }
        }