Ejemplo n.º 1
0
        /// <summary>Check if this data is usable as an ASCII table.</summary>
        public static bool IsData(Object o)
        {
            if (ArrayFuncs.CountDimensions(o) != 2)
            {
                return(false);
            }

            Type t = ArrayFuncs.GetBaseClass(o);

            return(t != null && (t.Equals(typeof(String)) || t.Equals(typeof(int)) || t.Equals(typeof(long)) ||
                                 t.Equals(typeof(float)) || t.Equals(typeof(double))));

/*
 *    if(o is Object[])
 *                      {
 *                              System.Object[] oo = (System.Object[]) o;
 *                              for (int i = 0; i < oo.Length; i += 1)
 *                              {
 *                                      if (oo[i] is System.String[] || oo[i] is int[] || oo[i] is long[] || oo[i] is float[] || oo[i] is double[])
 *                                      {
 *                                              continue;
 *                                      }
 *                                      return false;
 *                              }
 *                              return true;
 *                      }
 *                      else
 *                      {
 *                              return false;
 *                      }
 */
        }
Ejemplo n.º 2
0
        /// <summary>Check if this data is usable as an ASCII table.</summary>
        public static bool IsData(Object o)
        {
            if (ArrayFuncs.CountDimensions(o) != 2)
            {
                return(false);
            }

            /*  Type t = ArrayFuncs.GetBaseClass(o);
             *      return t != null && (t.Equals(typeof(String)) || t.Equals(typeof(int)) || t.Equals(typeof(long)) ||
             *  t.Equals(typeof(float)) || t.Equals(typeof(double)));
             */
            if (o is Object[])
            {
                System.Object[] oo = (System.Object[])o;
                for (int i = 0; i < oo.Length; i += 1)
                {
                    if (oo[i] is System.String[] || oo[i] is int[] || oo[i] is long[] || oo[i] is float[] || oo[i] is double[])
                    {
                        continue;
                    }
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
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 (ArrayFuncs.CountDimensions(oo) == 2)            //oo is Object[][])
            {
                //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.º 4
0
 public static Data Encapsulate(Object o)
 {
     if (ArrayFuncs.CountDimensions(o) == 2)           // is Object[][])
     {
         //return new RandomGroupsData((System.Object[][]) o);
         return(new RandomGroupsData((Array)o));
     }
     else
     {
         throw new FitsException("Attempt to encapsulate invalid data in Random Group");
     }
 }
Ejemplo n.º 5
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);
            }
        }