mathematica 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #------------------------------------------------------------------------------
  2. # $File: mathematica,v 1.13 2021/07/14 09:06:24 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 some CD-ROM filesystem like test-hfs.iso by looking for valid big endian type flag
  104. >>0 ubelong&0xFFffFF00 0x00000300
  105. >>>0 use matlab4
  106. # no example for 8-bit and 16-bit integers matrix
  107. >>0 ubelong&0xFFffFF00 0x00000400
  108. >>>0 use matlab4
  109. >>0 ulelong x
  110. # skip big endian variant by looking for valid low lttle endian type flag
  111. >>0 ulelong <53
  112. >>>0 use \^matlab4
  113. # display information of Matlab v4 mat-file
  114. 0 name matlab4 Matlab v4 mat-file
  115. #!:mime application/octet-stream
  116. !:mime application/x-matlab-data
  117. !:ext mat
  118. # 20-byte header with 5 long integers that contains information describing certain attributes of the Matrix
  119. # type flag decimal MOPT; maximal 4052=FD4h; maximal 52=34h for little endian
  120. #>0 ubelong x \b, type flag %u
  121. #>0 ubelong x (%#x)
  122. # M: 0~little endian 1~Big Endian 2~VAX D-float 3~VAX G-float 4~Cray
  123. #>0 ubelong/1000 x \b, M=%u
  124. >0 ubelong/1000 0 (little endian)
  125. >0 ubelong/1000 1 (big endian)
  126. >0 ubelong/1000 2 (VAX D-float)
  127. >0 ubelong/1000 3 (VAX G-float)
  128. >0 ubelong/1000 4 (Cray)
  129. # namlen; the length of the matrix name
  130. #>16 ubelong x \b, name length %u
  131. # nul terminated matrix name like: fit_params testmatrix testsparsecomplex teststringarray
  132. #>20 string x \b, MATRIX NAME="%s"
  133. >16 pstring/L x %s
  134. # T indicates the matrix type: 0~numeric 1~text 2~sparse
  135. #>0 ubelong%10 x \b, T=%u
  136. >0 ubelong%10 0 \b, numeric
  137. >0 ubelong%10 1 \b, text
  138. >0 ubelong%10 2 \b, sparse
  139. # mrows; number of rows in the matrix like: 1 3 8
  140. >4 ubelong x \b, rows %u
  141. # ncols; number of columns in the matrix like: 1 3 4 5 9 43
  142. >8 ubelong x \b, columns %u
  143. # imagf; imaginary flag; 1~matrix has an imaginary part 0~only real data
  144. >12 ubelong !0 \b, imaginary
  145. # real; Real part of the matrix consists of mrows * ncols numbers