mathematica 6.5 KB

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