Exemple #1
0
 /// <summary>
 /// get storage length of inner array elements 
 /// </summary>
 /// <param name="arr">base array in question</param>
 /// <returns>storage length in bytes</returns>
 private static int getElementLength(ILBaseArray arr) {
     Type arrType = arr.GetType();
     string innerType; 
     if (arr is ILLogicalArray) 
         return 1;
     if (!arrType.IsGenericType)
         throw new ILInvalidOperationException("The array type to be saved is not applicable!");
     innerType = arrType.GetGenericArguments()[0].Name;
     switch (innerType) {
         case "Double":
             return miSIZE_DOUBLE;  
         case "Single":
             return miSIZE_SINGLE;
         case "Int16":
             return miSIZE_INT16;
         case "Int32":
             return miSIZE_INT32;
         case "Int64":
             return 16;
         case "UInt16":
             return miSIZE_UINT16;
         case "UInt32":
             return miSIZE_UINT32;
         case "UInt64":
             return 16;
         case "complex":
             return miSIZE_DOUBLE;
         case "fcomplex":
             return miSIZE_SINGLE;
         case "Byte":
             return miSIZE_INT8;
         case "Char":
             return miSIZE_UINT16;
         default:
             throw new ILInvalidOperationException("Arrays of inner element type: '" + innerType + "' can not be written as Matfile!");
     }
 }
Exemple #2
0
 /// <summary>
 /// get mat file array class type corresponding to this arra element type
 /// </summary>
 /// <param name="arr">arra with generic system type or complex/fcomplex</param>
 /// <returns>mat file array class type code (int value)</returns>
 private static int getElementClass(ILBaseArray arr) {
     Type arrType = arr.GetType();
     if (arr is ILLogicalArray) 
         return (int)MatFileArrayClass.mxINT8_CLASS; 
     if (!arrType.IsGenericType)
         throw new ILInvalidOperationException("The array type to be saved is not applicable!");
     string innerType = arrType.GetGenericArguments()[0].Name;
     switch (innerType) {
         case "Double":
             return (int)MatFileArrayClass.mxDOUBLE_CLASS;
         case "Single":
             return (int)MatFileArrayClass.mxSINGLE_CLASS;
         case "Int16":
             return (int)MatFileArrayClass.mxINT16_CLASS;
         case "Int32":
             return (int)MatFileArrayClass.mxINT32_CLASS;
         case "Int64":
             throw new ILInvalidOperationException("Int64 array class can not be written as Matfile!"); 
         case "UInt16":
             return (int)MatFileArrayClass.mxUINT16_CLASS;
         case "UInt32":
             return (int)MatFileArrayClass.mxUINT32_CLASS;
         case "UInt64":
             throw new ILInvalidOperationException("UInt64 array class can not be written as Matfile!"); 
         case "complex":
             return (int)MatFileArrayClass.mxDOUBLE_CLASS; 
         case "fcomplex":
             return (int)MatFileArrayClass.mxSINGLE_CLASS; 
         case "Byte":
             return (int)MatFileArrayClass.mxINT8_CLASS;
         case "Char":
             return (int)MatFileArrayClass.mxCHAR_CLASS;
         default:
             throw new ILInvalidOperationException("Arrays of inner element type: '" + innerType + "' can not be written as Matfile!");
     }
 }