xref: /freebsd/contrib/file/magic/Magdir/mathematica (revision 643ac419fafba89f5adda0e0ea75b538727453fb)
1
2#------------------------------------------------------------------------------
3# $File: mathematica,v 1.14 2021/11/07 16:27:36 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 PreviousEntries.dat with "invalid high" name \304P\344@\001
121>>20	ubyte	<0304
122# skip some Netwfw*.dat and $I3KREPH.dat by checking for non zero number of rows
123>>>4	ulong		!0
124# skip some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag
125>>>>0	ubelong&0xFFffFF00	0x00000300
126>>>>>0	use	matlab4
127# no example for 8-bit and 16-bit integers matrix
128>>>>0	ubelong&0xFFffFF00	0x00000400
129>>>>>0	use	matlab4
130#	branch for Little-Endian variant of Matlab MATrix version 4
131# skip big endian variant by looking for valid low lttle endian type flag
132>>>>0	ulelong		<53
133# skip tokens.dat and some Netwfw*.dat by check for valid imaginary flag value of MAT version 4
134>>>>>12	ulelong		<2
135# no misidentfied little endian MATrix example with "short" matrix name
136>>>>>>16	ulelong		<3
137>>>>>>>0	use	\^matlab4
138# little endian MATrix with "long" matrix name or some misidentified samples
139>>>>>>16	ulelong		>2
140# skip TileCacheLogo-*.dat with invalid 2nd character \001 of matrix name with length 96
141>>>>>>>21 ubyte	>0x1F
142>>>>>>>>0 use	\^matlab4
143#	display information of Matlab v4 mat-file
1440	name	matlab4		Matlab v4 mat-file
145#!:mime	application/octet-stream
146!:mime	application/x-matlab-data
147!:ext	mat
148# 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix
149# type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian
150#>0	ubelong		x	\b, type flag %u
151#>0	ubelong		x	(%#x)
152# M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray
153#>0	ubelong/1000	x	\b, M=%u
154>0	ubelong/1000	0	(little endian)
155>0	ubelong/1000	1	(big endian)
156>0	ubelong/1000	2	(VAX D-float)
157>0	ubelong/1000	3	(VAX G-float)
158>0	ubelong/1000	4	(Cray)
159# namlen; the length of the matrix name
160#>16	ubelong		x	\b, name length %u
161#>(16.L+19)	ubyte	x	\b, TERMINATING NAME CHARACTER=%#x
162# nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray
163#>20	string		x	\b, MATRIX NAME="%s"
164#>21		ubyte	x	\b, MAYBE 2ND CHAR=%c
165>16	pstring/L	x	%s
166# T indicates the matrix type: 0~numeric 1~text 2~sparse
167#>0	ubelong%10	x	\b, T=%u
168>0	ubelong%10	0	\b, numeric
169>0	ubelong%10	1	\b, text
170>0	ubelong%10	2	\b, sparse
171# mrows; number of rows in the matrix like: 1 3 8
172>4	ubelong		x	\b, rows %u
173# ncols; number of columns in the matrix like: 1 3 4 5 9 43
174>8	ubelong		x	\b, columns %u
175# imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data
176>12	ubelong		!0	\b, imaginary (%u)
177# real; Real part of the matrix consists of mrows * ncols numbers
178