Mel Script - Writing Binary Data




All file IO in mel requires the use of fopen and fclose to open and close files on the hard drive. When writing binary data we need to use fwrite. There are a few small issues you should be aware of, firstly mel is a high level language so you don't get the low level control you need over the binary data. For example, it is impossible to write a 4 byte float to the file since all floats in mel are stored as 8byte doubles.





Example 1 : using fwrite

All binary file writing in mel, uses fwrite to write the data to a file.



		// construct the full path to a file
		$filename = (`internalVar -userTmpDir` + "temp.dat");
		// open the file for writing
		$file = `fopen $filename "wb"`;

		// fwrite takes two parameters, the file ID and the data to write
		fwrite $file ( "Hello!! how are you?" + "\n" );
		fwrite $file 100;
		fwrite $file 10.05;

		// close the file
		fclose $file;