1 2#------------------------------------------------------------------------------ 3# $File: mathematica,v 1.13 2021/07/14 09:06:24 christos Exp $ 4# mathematica: file(1) magic for mathematica files 5# "H. Nanosecond" <aldomel@ix.netcom.com> 6# Mathematica a multi-purpose math program 7# versions 2.2 and 3.0 8 9#mathematica .mb 100 string \064\024\012\000\035\000\000\000 Mathematica version 2 notebook 11!:ext mb 120 string \064\024\011\000\035\000\000\000 Mathematica version 2 notebook 13!:ext mb 14 15# .ma 16# multiple possibilities: 17 180 string (*^\n\n::[\011frontEndVersion\ =\ Mathematica notebook 19#>41 string >\0 %s 20!:ext mb 21 22#0 string (*^\n\n::[\011palette Mathematica notebook version 2.x 23 24#0 string (*^\n\n::[\011Information Mathematica notebook version 2.x 25#>675 string >\0 %s #doesn't work well 26 27# there may be 'cr' instead of 'nl' in some does this matter? 28 29# generic: 300 string (*^\r\r::[\011 Mathematica notebook version 2.x 31!:ext mb 320 string (*^\r\n\r\n::[\011 Mathematica notebook version 2.x 33!:ext mb 340 string (*^\015 Mathematica notebook version 2.x 35!:ext mb 360 string (*^\n\r\n\r::[\011 Mathematica notebook version 2.x 37!:ext mb 380 string (*^\r::[\011 Mathematica notebook version 2.x 39!:ext mb 400 string (*^\r\n::[\011 Mathematica notebook version 2.x 41!:ext mb 420 string (*^\n\n::[\011 Mathematica notebook version 2.x 43!:ext mb 440 string (*^\n::[\011 Mathematica notebook version 2.x 45!:ext mb 46 47 48# Mathematica .mx files 49 50#0 string (*This\ is\ a\ Mathematica\ binary\ dump\ file.\ It\ can\ be\ loaded\ with\ Get.*) Mathematica binary file 510 string (*This\ is\ a\ Mathematica\ binary\ Mathematica binary file 52#>71 string \000\010\010\010\010\000\000\000\000\000\000\010\100\010\000\000\000 53# >71... is optional 54>88 string >\0 from %s 55 56 57# Mathematica files PBF: 58# 115 115 101 120 102 106 000 001 000 000 000 203 000 001 000 590 string MMAPBF\000\001\000\000\000\203\000\001\000 Mathematica PBF (fonts I think) 60 61# .ml files These are menu resources I think 62# these start with "[0-9][0-9][0-9]\ A~[0-9][0-9][0-9]\ 63# how to put that into a magic rule? 644 string \ A~ MAthematica .ml file 65 66# .nb files 67#too long 0 string (***********************************************************************\n\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Mathematica-Compatible Notebook Mathematica 3.0 notebook 680 string (*********************** Mathematica 3.0 notebook 69 70# other (* matches it is a comment start in these langs 71# GRR: Too weak; also matches other languages e.g. ML 72#0 string (* Mathematica, or Pascal, Modula-2 or 3 code text 73 74######################### 75# MatLab v5 76# URL: http://fileformats.archiveteam.org/wiki/MAT 77# Reference: https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf 78# first 116 bytes of header contain text in human-readable form 790 string MATLAB Matlab v 80#>11 string/T x \b, at 11 "%.105s" 81#!:mime application/octet-stream 82!:mime application/x-matlab-data 83!:ext mat 84# https://de.mathworks.com/help/matlab/import_export/mat-file-versions.html 85# level of the MAT-file like: 5.0 7.0 or maybe 7.3 86#>7 string x LEVEL "%.3s" 87>7 ubyte =0x35 \b5 mat-file 88>7 ubyte !0x35 89>>7 string x \b%.3s mat-file 90>126 short 0x494d (big endian) 91>>124 beshort x version %#04x 92>126 short 0x4d49 (little endian) 93# 0x0100 for level 5.0 and 0x0200 for level 7.0 94>>124 leshort x version %#04x 95# test again so that default clause works 96>126 short x 97# created by MATLAB include Platform sometimes without leading comma (0x2C) or missing 98# like: GLNX86 PCWIN PCWIN64 SOL2 Windows\0407 nt posix 99>>20 search/2 Platform:\040 \b, platform 100>>>&0 string x %-0.2s 101>>>&2 ubyte !0x2C \b%c 102>>>>&0 ubyte !0x2C \b%c 103>>>>>&0 ubyte !0x2C \b%c 104>>>>>>&0 ubyte !0x2C \b%c 105>>>>>>>&0 ubyte !0x2C \b%c 106>>>>>>>>&0 ubyte !0x2C \b%c 107>>>>>>>>>&0 ubyte !0x2C \b%c 108# examples without Platform tag like one_by_zero_char.mat 109>>20 default x 110>>>11 string x "%s" 111# created by MATLAB include time like: Fri Feb 20 15:26:59 2009 112>34 search/9/c created\040on:\040 \b, created 113>>&0 string x %-.24s 114# MatLab v4 115# From: Joerg Jenderek 116# check for valid imaginary flag of Matlab matrix version 4 11713 ushort 0 118# check for valid ASCII matrix name 119>20 ubyte >0x1F 120# skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag 121>>0 ubelong&0xFFffFF00 0x00000300 122>>>0 use matlab4 123# no example for 8-bit and 16-bit integers matrix 124>>0 ubelong&0xFFffFF00 0x00000400 125>>>0 use matlab4 126>>0 ulelong x 127# skip big endian variant by looking for valid low lttle endian type flag 128>>0 ulelong <53 129>>>0 use \^matlab4 130# display information of Matlab v4 mat-file 1310 name matlab4 Matlab v4 mat-file 132#!:mime application/octet-stream 133!:mime application/x-matlab-data 134!:ext mat 135# 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix 136# type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian 137#>0 ubelong x \b, type flag %u 138#>0 ubelong x (%#x) 139# M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray 140#>0 ubelong/1000 x \b, M=%u 141>0 ubelong/1000 0 (little endian) 142>0 ubelong/1000 1 (big endian) 143>0 ubelong/1000 2 (VAX D-float) 144>0 ubelong/1000 3 (VAX G-float) 145>0 ubelong/1000 4 (Cray) 146# namlen; the length of the matrix name 147#>16 ubelong x \b, name length %u 148# nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray 149#>20 string x \b, MATRIX NAME="%s" 150>16 pstring/L x %s 151# T indicates the matrix type: 0~numeric 1~text 2~sparse 152#>0 ubelong%10 x \b, T=%u 153>0 ubelong%10 0 \b, numeric 154>0 ubelong%10 1 \b, text 155>0 ubelong%10 2 \b, sparse 156# mrows; number of rows in the matrix like: 1 3 8 157>4 ubelong x \b, rows %u 158# ncols; number of columns in the matrix like: 1 3 4 5 9 43 159>8 ubelong x \b, columns %u 160# imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data 161>12 ubelong !0 \b, imaginary 162# real; Real part of the matrix consists of mrows * ncols numbers 163