file
The Origin C file class provides read/write access to binary files using unbuffered io (immediate disk access) similar to the MFC CFile class. See also the stdioFile class for buffered stream io to text files.
EX1
//generate a binary file with 4 integer void file_ex1() { char szTemp[MAXFULLPATH]; GetTempPath(MAXFULLPATH, szTemp); // Get temp folder path. string strFile = szTemp + "\\test.Dat"; file ff(strFile, file::modeCreate | file::modeWrite); // Create a new write only file. int bb[4] = {1, 2, 3, 4}; int iSize = sizeof(bb); ff.Write(bb,iSize); ff.Close(); }
EX2
//generate a binary file of unsigned short in the form of cell=r + c //you can read this type of file into Origin with the impbin2d X-Function void file_ex2(int nCols = 128, int nRows = 10) { string strFile = GetAppPath() + "test" + nCols + "x" + nRows + ".img"; file ff; if(ff.Open(strFile, file::modeCreate | file::modeWrite)) { for(int ii = 0; ii < nRows; ii++) { for(int jj = 0; jj < nCols; jj++) { unsigned short us = ii + jj; ff.Write(&us, 2); } } ff.Close(); printf("file successfully created:\n%s\n", strFile); } else printf("failed to create file:%s\n", strFile); }
origin.h