mathematica 6.7 KB

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