okoc_binary_mat_import
    
  
  Description
  Load a binary file that are in the form of a 2d array into a matrix object. 
  Syntax
  
int okoc_binary_mat_import( LPCSTR lpcszFilename, LPCSTR lpcszRangeMat, int nCols, int nElemSize, int nSign, BOOL bBigEndian = false, int nOffset = 0, int nRows = -1 )
 
  Parameters
  
    - lpcszFilename
 
    - [input] file to be imported
 
    - lpcszRangeMat
 
    - [input] range string to a matrix object
 
    - nCols
 
    - [input] number of columns in the 2d array
 
    - nElemSize
 
    - [input] data element size in bytes, 1,2,4, 8, 16 = complex. must set nSign = -1 for complex, double and float
 
    - nSign
 
    - [input] 0 if unsigned, 1 if signed for integer data types. -1 if float data type
 
    - bBigEndian
 
    - [input] false = little-endian is the most typical, for all PC data files at least.
 
    - nOffset
 
    - [input] file header offset
 
    - nRows
 
    - [input] -1 if unknown, and will determine from file size, otherwise the number of rows.
 
   
  Return
  0 if success, < 0 for error codes, some important ones are 
  -20 lpcszRangeMat does not point to an existing MatrixObject 
  -1 lpcszFilename not found or size = 0 
  -2 lpcszFilename file size too small, does not even have a single row of data 
  -3 the combincation of nElemSize and nSign does not indicate a valid internal data type in Origin 
  -6 memory allocation failed to prepare the matrix object before import 
  -10 file size not exactly correct so failed to read the last row 
  -11 failed to open the file for reading 
  Examples
  EX1 
  
#include <okocUtils.h>
void okoc_binary_mat_import_ex1()
{
        string strFile = "C:\\temp4096x5120.img";
        if ( strFile.IsFile() )
        {
                const int nCols = 128; //number of columns in the matrix
                const int nBytes = 2;
                const int nSign = 0;
                const int nBigEnd = 0;
                const int nOffset = 0;
                string strRange;
                MatrixPage mp;
                mp.Create("Origin");
                strRange.Format("[%s]1!1", mp.GetName());
                int nRet = okoc_binary_mat_import(strFile, strRange, nCols, nBytes, nSign, nBigEnd, nOffset);
                if ( nRet == 0 )
                        out_str("Import binary data from file successfully.");
                else
                        out_str("Fail to import binary data from file.");
        }
        return;
}
  Remark
  See Also
  okoc_binary_mat_export 
  header to Include
  okocUtils.h 
  Reference
             |