1b6cee71dSXin LI 2b6cee71dSXin LI#------------------------------------------------------------------------------ 3*a4d6d3b8SXin LI# $File: mathematica,v 1.14 2021/11/07 16:27:36 christos Exp $ 4b6cee71dSXin LI# mathematica: file(1) magic for mathematica files 5b6cee71dSXin LI# "H. Nanosecond" <aldomel@ix.netcom.com> 6b6cee71dSXin LI# Mathematica a multi-purpose math program 7b6cee71dSXin LI# versions 2.2 and 3.0 8b6cee71dSXin LI 9b6cee71dSXin LI#mathematica .mb 10b6cee71dSXin LI0 string \064\024\012\000\035\000\000\000 Mathematica version 2 notebook 115f0216bdSXin LI!:ext mb 12b6cee71dSXin LI0 string \064\024\011\000\035\000\000\000 Mathematica version 2 notebook 135f0216bdSXin LI!:ext mb 14b6cee71dSXin LI 15b6cee71dSXin LI# .ma 1643a5ec4eSXin LI# multiple possibilities: 17b6cee71dSXin LI 18b6cee71dSXin LI0 string (*^\n\n::[\011frontEndVersion\ =\ Mathematica notebook 19b6cee71dSXin LI#>41 string >\0 %s 205f0216bdSXin LI!:ext mb 21b6cee71dSXin LI 22b6cee71dSXin LI#0 string (*^\n\n::[\011palette Mathematica notebook version 2.x 23b6cee71dSXin LI 24b6cee71dSXin LI#0 string (*^\n\n::[\011Information Mathematica notebook version 2.x 25b6cee71dSXin LI#>675 string >\0 %s #doesn't work well 26b6cee71dSXin LI 2743a5ec4eSXin LI# there may be 'cr' instead of 'nl' in some does this matter? 28b6cee71dSXin LI 29b6cee71dSXin LI# generic: 30b6cee71dSXin LI0 string (*^\r\r::[\011 Mathematica notebook version 2.x 315f0216bdSXin LI!:ext mb 32b6cee71dSXin LI0 string (*^\r\n\r\n::[\011 Mathematica notebook version 2.x 335f0216bdSXin LI!:ext mb 34b6cee71dSXin LI0 string (*^\015 Mathematica notebook version 2.x 355f0216bdSXin LI!:ext mb 36b6cee71dSXin LI0 string (*^\n\r\n\r::[\011 Mathematica notebook version 2.x 375f0216bdSXin LI!:ext mb 38b6cee71dSXin LI0 string (*^\r::[\011 Mathematica notebook version 2.x 395f0216bdSXin LI!:ext mb 40b6cee71dSXin LI0 string (*^\r\n::[\011 Mathematica notebook version 2.x 415f0216bdSXin LI!:ext mb 42b6cee71dSXin LI0 string (*^\n\n::[\011 Mathematica notebook version 2.x 435f0216bdSXin LI!:ext mb 44b6cee71dSXin LI0 string (*^\n::[\011 Mathematica notebook version 2.x 455f0216bdSXin LI!:ext mb 46b6cee71dSXin LI 47b6cee71dSXin LI 48b6cee71dSXin LI# Mathematica .mx files 49b6cee71dSXin LI 50b6cee71dSXin LI#0 string (*This\ is\ a\ Mathematica\ binary\ dump\ file.\ It\ can\ be\ loaded\ with\ Get.*) Mathematica binary file 51b6cee71dSXin LI0 string (*This\ is\ a\ Mathematica\ binary\ Mathematica binary file 52b6cee71dSXin LI#>71 string \000\010\010\010\010\000\000\000\000\000\000\010\100\010\000\000\000 53b6cee71dSXin LI# >71... is optional 54b6cee71dSXin LI>88 string >\0 from %s 55b6cee71dSXin LI 56b6cee71dSXin LI 57b6cee71dSXin LI# Mathematica files PBF: 58b6cee71dSXin LI# 115 115 101 120 102 106 000 001 000 000 000 203 000 001 000 59b6cee71dSXin LI0 string MMAPBF\000\001\000\000\000\203\000\001\000 Mathematica PBF (fonts I think) 60b6cee71dSXin LI 61b6cee71dSXin LI# .ml files These are menu resources I think 62b6cee71dSXin LI# these start with "[0-9][0-9][0-9]\ A~[0-9][0-9][0-9]\ 63b6cee71dSXin LI# how to put that into a magic rule? 64b6cee71dSXin LI4 string \ A~ MAthematica .ml file 65b6cee71dSXin LI 66b6cee71dSXin LI# .nb files 67b6cee71dSXin LI#too long 0 string (***********************************************************************\n\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Mathematica-Compatible Notebook Mathematica 3.0 notebook 68b6cee71dSXin LI0 string (*********************** Mathematica 3.0 notebook 69b6cee71dSXin LI 70b6cee71dSXin LI# other (* matches it is a comment start in these langs 71b6cee71dSXin LI# GRR: Too weak; also matches other languages e.g. ML 72b6cee71dSXin LI#0 string (* Mathematica, or Pascal, Modula-2 or 3 code text 73b6cee71dSXin LI 74b6cee71dSXin LI######################### 75b6cee71dSXin LI# MatLab v5 7643a5ec4eSXin LI# URL: http://fileformats.archiveteam.org/wiki/MAT 7743a5ec4eSXin LI# Reference: https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf 7843a5ec4eSXin LI# first 116 bytes of header contain text in human-readable form 7943a5ec4eSXin LI0 string MATLAB Matlab v 8043a5ec4eSXin LI#>11 string/T x \b, at 11 "%.105s" 8143a5ec4eSXin LI#!:mime application/octet-stream 8243a5ec4eSXin LI!:mime application/x-matlab-data 8343a5ec4eSXin LI!:ext mat 8443a5ec4eSXin LI# https://de.mathworks.com/help/matlab/import_export/mat-file-versions.html 8543a5ec4eSXin LI# level of the MAT-file like: 5.0 7.0 or maybe 7.3 8643a5ec4eSXin LI#>7 string x LEVEL "%.3s" 8743a5ec4eSXin LI>7 ubyte =0x35 \b5 mat-file 8843a5ec4eSXin LI>7 ubyte !0x35 8943a5ec4eSXin LI>>7 string x \b%.3s mat-file 90b6cee71dSXin LI>126 short 0x494d (big endian) 9143a5ec4eSXin LI>>124 beshort x version %#04x 92b6cee71dSXin LI>126 short 0x4d49 (little endian) 9343a5ec4eSXin LI# 0x0100 for level 5.0 and 0x0200 for level 7.0 9443a5ec4eSXin LI>>124 leshort x version %#04x 9543a5ec4eSXin LI# test again so that default clause works 9643a5ec4eSXin LI>126 short x 9743a5ec4eSXin LI# created by MATLAB include Platform sometimes without leading comma (0x2C) or missing 9843a5ec4eSXin LI# like: GLNX86 PCWIN PCWIN64 SOL2 Windows\0407 nt posix 9943a5ec4eSXin LI>>20 search/2 Platform:\040 \b, platform 10043a5ec4eSXin LI>>>&0 string x %-0.2s 10143a5ec4eSXin LI>>>&2 ubyte !0x2C \b%c 10243a5ec4eSXin LI>>>>&0 ubyte !0x2C \b%c 10343a5ec4eSXin LI>>>>>&0 ubyte !0x2C \b%c 10443a5ec4eSXin LI>>>>>>&0 ubyte !0x2C \b%c 10543a5ec4eSXin LI>>>>>>>&0 ubyte !0x2C \b%c 10643a5ec4eSXin LI>>>>>>>>&0 ubyte !0x2C \b%c 10743a5ec4eSXin LI>>>>>>>>>&0 ubyte !0x2C \b%c 10843a5ec4eSXin LI# examples without Platform tag like one_by_zero_char.mat 10943a5ec4eSXin LI>>20 default x 11043a5ec4eSXin LI>>>11 string x "%s" 11143a5ec4eSXin LI# created by MATLAB include time like: Fri Feb 20 15:26:59 2009 11243a5ec4eSXin LI>34 search/9/c created\040on:\040 \b, created 11343a5ec4eSXin LI>>&0 string x %-.24s 11443a5ec4eSXin LI# MatLab v4 11543a5ec4eSXin LI# From: Joerg Jenderek 11643a5ec4eSXin LI# check for valid imaginary flag of Matlab matrix version 4 11743a5ec4eSXin LI13 ushort 0 11843a5ec4eSXin LI# check for valid ASCII matrix name 11943a5ec4eSXin LI>20 ubyte >0x1F 120*a4d6d3b8SXin LI# skip PreviousEntries.dat with "invalid high" name \304P\344@\001 121*a4d6d3b8SXin LI>>20 ubyte <0304 122*a4d6d3b8SXin LI# skip some Netwfw*.dat and $I3KREPH.dat by checking for non zero number of rows 123*a4d6d3b8SXin LI>>>4 ulong !0 12443a5ec4eSXin LI# skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag 125*a4d6d3b8SXin LI>>>>0 ubelong&0xFFffFF00 0x00000300 126*a4d6d3b8SXin LI>>>>>0 use matlab4 12743a5ec4eSXin LI# no example for 8-bit and 16-bit integers matrix 128*a4d6d3b8SXin LI>>>>0 ubelong&0xFFffFF00 0x00000400 129*a4d6d3b8SXin LI>>>>>0 use matlab4 130*a4d6d3b8SXin LI# branch for Little-Endian variant of Matlab MATrix version 4 13143a5ec4eSXin LI# skip big endian variant by looking for valid low lttle endian type flag 132*a4d6d3b8SXin LI>>>>0 ulelong <53 133*a4d6d3b8SXin LI# skip tokens.dat and some Netwfw*.dat by check for valid imaginary flag value of MAT version 4 134*a4d6d3b8SXin LI>>>>>12 ulelong <2 135*a4d6d3b8SXin LI# no misidentfied little endian MATrix example with "short" matrix name 136*a4d6d3b8SXin LI>>>>>>16 ulelong <3 137*a4d6d3b8SXin LI>>>>>>>0 use \^matlab4 138*a4d6d3b8SXin LI# little endian MATrix with "long" matrix name or some misidentified samples 139*a4d6d3b8SXin LI>>>>>>16 ulelong >2 140*a4d6d3b8SXin LI# skip TileCacheLogo-*.dat with invalid 2nd character \001 of matrix name with length 96 141*a4d6d3b8SXin LI>>>>>>>21 ubyte >0x1F 142*a4d6d3b8SXin LI>>>>>>>>0 use \^matlab4 14343a5ec4eSXin LI# display information of Matlab v4 mat-file 14443a5ec4eSXin LI0 name matlab4 Matlab v4 mat-file 14543a5ec4eSXin LI#!:mime application/octet-stream 14643a5ec4eSXin LI!:mime application/x-matlab-data 14743a5ec4eSXin LI!:ext mat 14843a5ec4eSXin LI# 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix 14943a5ec4eSXin LI# type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian 15043a5ec4eSXin LI#>0 ubelong x \b, type flag %u 15143a5ec4eSXin LI#>0 ubelong x (%#x) 15243a5ec4eSXin LI# M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray 15343a5ec4eSXin LI#>0 ubelong/1000 x \b, M=%u 15443a5ec4eSXin LI>0 ubelong/1000 0 (little endian) 15543a5ec4eSXin LI>0 ubelong/1000 1 (big endian) 15643a5ec4eSXin LI>0 ubelong/1000 2 (VAX D-float) 15743a5ec4eSXin LI>0 ubelong/1000 3 (VAX G-float) 15843a5ec4eSXin LI>0 ubelong/1000 4 (Cray) 15943a5ec4eSXin LI# namlen; the length of the matrix name 16043a5ec4eSXin LI#>16 ubelong x \b, name length %u 161*a4d6d3b8SXin LI#>(16.L+19) ubyte x \b, TERMINATING NAME CHARACTER=%#x 16243a5ec4eSXin LI# nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray 16343a5ec4eSXin LI#>20 string x \b, MATRIX NAME="%s" 164*a4d6d3b8SXin LI#>21 ubyte x \b, MAYBE 2ND CHAR=%c 16543a5ec4eSXin LI>16 pstring/L x %s 16643a5ec4eSXin LI# T indicates the matrix type: 0~numeric 1~text 2~sparse 16743a5ec4eSXin LI#>0 ubelong%10 x \b, T=%u 16843a5ec4eSXin LI>0 ubelong%10 0 \b, numeric 16943a5ec4eSXin LI>0 ubelong%10 1 \b, text 17043a5ec4eSXin LI>0 ubelong%10 2 \b, sparse 17143a5ec4eSXin LI# mrows; number of rows in the matrix like: 1 3 8 17243a5ec4eSXin LI>4 ubelong x \b, rows %u 17343a5ec4eSXin LI# ncols; number of columns in the matrix like: 1 3 4 5 9 43 17443a5ec4eSXin LI>8 ubelong x \b, columns %u 17543a5ec4eSXin LI# imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data 176*a4d6d3b8SXin LI>12 ubelong !0 \b, imaginary (%u) 17743a5ec4eSXin LI# real; Real part of the matrix consists of mrows * ncols numbers 178