1b6cee71dSXin LI 2b6cee71dSXin LI#------------------------------------------------------------------------------ 3*43a5ec4eSXin LI# $File: mathematica,v 1.13 2021/07/14 09:06:24 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 16*43a5ec4eSXin 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 27*43a5ec4eSXin 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 76*43a5ec4eSXin LI# URL: http://fileformats.archiveteam.org/wiki/MAT 77*43a5ec4eSXin LI# Reference: https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf 78*43a5ec4eSXin LI# first 116 bytes of header contain text in human-readable form 79*43a5ec4eSXin LI0 string MATLAB Matlab v 80*43a5ec4eSXin LI#>11 string/T x \b, at 11 "%.105s" 81*43a5ec4eSXin LI#!:mime application/octet-stream 82*43a5ec4eSXin LI!:mime application/x-matlab-data 83*43a5ec4eSXin LI!:ext mat 84*43a5ec4eSXin LI# https://de.mathworks.com/help/matlab/import_export/mat-file-versions.html 85*43a5ec4eSXin LI# level of the MAT-file like: 5.0 7.0 or maybe 7.3 86*43a5ec4eSXin LI#>7 string x LEVEL "%.3s" 87*43a5ec4eSXin LI>7 ubyte =0x35 \b5 mat-file 88*43a5ec4eSXin LI>7 ubyte !0x35 89*43a5ec4eSXin LI>>7 string x \b%.3s mat-file 90b6cee71dSXin LI>126 short 0x494d (big endian) 91*43a5ec4eSXin LI>>124 beshort x version %#04x 92b6cee71dSXin LI>126 short 0x4d49 (little endian) 93*43a5ec4eSXin LI# 0x0100 for level 5.0 and 0x0200 for level 7.0 94*43a5ec4eSXin LI>>124 leshort x version %#04x 95*43a5ec4eSXin LI# test again so that default clause works 96*43a5ec4eSXin LI>126 short x 97*43a5ec4eSXin LI# created by MATLAB include Platform sometimes without leading comma (0x2C) or missing 98*43a5ec4eSXin LI# like: GLNX86 PCWIN PCWIN64 SOL2 Windows\0407 nt posix 99*43a5ec4eSXin LI>>20 search/2 Platform:\040 \b, platform 100*43a5ec4eSXin LI>>>&0 string x %-0.2s 101*43a5ec4eSXin LI>>>&2 ubyte !0x2C \b%c 102*43a5ec4eSXin LI>>>>&0 ubyte !0x2C \b%c 103*43a5ec4eSXin LI>>>>>&0 ubyte !0x2C \b%c 104*43a5ec4eSXin LI>>>>>>&0 ubyte !0x2C \b%c 105*43a5ec4eSXin LI>>>>>>>&0 ubyte !0x2C \b%c 106*43a5ec4eSXin LI>>>>>>>>&0 ubyte !0x2C \b%c 107*43a5ec4eSXin LI>>>>>>>>>&0 ubyte !0x2C \b%c 108*43a5ec4eSXin LI# examples without Platform tag like one_by_zero_char.mat 109*43a5ec4eSXin LI>>20 default x 110*43a5ec4eSXin LI>>>11 string x "%s" 111*43a5ec4eSXin LI# created by MATLAB include time like: Fri Feb 20 15:26:59 2009 112*43a5ec4eSXin LI>34 search/9/c created\040on:\040 \b, created 113*43a5ec4eSXin LI>>&0 string x %-.24s 114*43a5ec4eSXin LI# MatLab v4 115*43a5ec4eSXin LI# From: Joerg Jenderek 116*43a5ec4eSXin LI# check for valid imaginary flag of Matlab matrix version 4 117*43a5ec4eSXin LI13 ushort 0 118*43a5ec4eSXin LI# check for valid ASCII matrix name 119*43a5ec4eSXin LI>20 ubyte >0x1F 120*43a5ec4eSXin LI# skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag 121*43a5ec4eSXin LI>>0 ubelong&0xFFffFF00 0x00000300 122*43a5ec4eSXin LI>>>0 use matlab4 123*43a5ec4eSXin LI# no example for 8-bit and 16-bit integers matrix 124*43a5ec4eSXin LI>>0 ubelong&0xFFffFF00 0x00000400 125*43a5ec4eSXin LI>>>0 use matlab4 126*43a5ec4eSXin LI>>0 ulelong x 127*43a5ec4eSXin LI# skip big endian variant by looking for valid low lttle endian type flag 128*43a5ec4eSXin LI>>0 ulelong <53 129*43a5ec4eSXin LI>>>0 use \^matlab4 130*43a5ec4eSXin LI# display information of Matlab v4 mat-file 131*43a5ec4eSXin LI0 name matlab4 Matlab v4 mat-file 132*43a5ec4eSXin LI#!:mime application/octet-stream 133*43a5ec4eSXin LI!:mime application/x-matlab-data 134*43a5ec4eSXin LI!:ext mat 135*43a5ec4eSXin LI# 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix 136*43a5ec4eSXin LI# type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian 137*43a5ec4eSXin LI#>0 ubelong x \b, type flag %u 138*43a5ec4eSXin LI#>0 ubelong x (%#x) 139*43a5ec4eSXin LI# M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray 140*43a5ec4eSXin LI#>0 ubelong/1000 x \b, M=%u 141*43a5ec4eSXin LI>0 ubelong/1000 0 (little endian) 142*43a5ec4eSXin LI>0 ubelong/1000 1 (big endian) 143*43a5ec4eSXin LI>0 ubelong/1000 2 (VAX D-float) 144*43a5ec4eSXin LI>0 ubelong/1000 3 (VAX G-float) 145*43a5ec4eSXin LI>0 ubelong/1000 4 (Cray) 146*43a5ec4eSXin LI# namlen; the length of the matrix name 147*43a5ec4eSXin LI#>16 ubelong x \b, name length %u 148*43a5ec4eSXin LI# nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray 149*43a5ec4eSXin LI#>20 string x \b, MATRIX NAME="%s" 150*43a5ec4eSXin LI>16 pstring/L x %s 151*43a5ec4eSXin LI# T indicates the matrix type: 0~numeric 1~text 2~sparse 152*43a5ec4eSXin LI#>0 ubelong%10 x \b, T=%u 153*43a5ec4eSXin LI>0 ubelong%10 0 \b, numeric 154*43a5ec4eSXin LI>0 ubelong%10 1 \b, text 155*43a5ec4eSXin LI>0 ubelong%10 2 \b, sparse 156*43a5ec4eSXin LI# mrows; number of rows in the matrix like: 1 3 8 157*43a5ec4eSXin LI>4 ubelong x \b, rows %u 158*43a5ec4eSXin LI# ncols; number of columns in the matrix like: 1 3 4 5 9 43 159*43a5ec4eSXin LI>8 ubelong x \b, columns %u 160*43a5ec4eSXin LI# imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data 161*43a5ec4eSXin LI>12 ubelong !0 \b, imaginary 162*43a5ec4eSXin LI# real; Real part of the matrix consists of mrows * ncols numbers 163