mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-02-28 02:59:31 +00:00
Merge branch 'master' of github.com:github/linguist
Conflicts: lib/linguist/languages.yml
This commit is contained in:
@@ -10,7 +10,7 @@ Linguist defines the list of all languages known to GitHub in a [yaml file](http
|
||||
|
||||
Most languages are detected by their file extension. This is the fastest and most common situation.
|
||||
|
||||
For disambiguating between files with common extensions, we use a [bayesian classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb). For an example, this helps us tell the difference between `.h` files which could be either C, C++, or Obj-C.
|
||||
For disambiguating between files with common extensions, we use a [Bayesian classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb). For an example, this helps us tell the difference between `.h` files which could be either C, C++, or Obj-C.
|
||||
|
||||
In the actual GitHub app we deal with `Grit::Blob` objects. For testing, there is a simple `FileBlob` API.
|
||||
|
||||
@@ -27,7 +27,7 @@ See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/li
|
||||
|
||||
The actual syntax highlighting is handled by our Pygments wrapper, [pygments.rb](https://github.com/tmm1/pygments.rb). It also provides a [Lexer abstraction](https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/lexer.rb) that determines which highlighter should be used on a file.
|
||||
|
||||
We typically run on a prerelease version of Pygments, [pygments.rb](https://github.com/tmm1/pygments.rb), to get early access to new lexers. The [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) file is a dump of the lexers we have available on our server.
|
||||
We typically run on a pre-release version of Pygments, [pygments.rb](https://github.com/tmm1/pygments.rb), to get early access to new lexers. The [languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) file is a dump of the lexers we have available on our server.
|
||||
|
||||
### Stats
|
||||
|
||||
@@ -88,6 +88,6 @@ Almost all bug fixes or new language additions should come with some additional
|
||||
|
||||
### Testing
|
||||
|
||||
Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. Its okay, be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away.
|
||||
Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay, be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away.
|
||||
|
||||
Heres our current build status, which is hopefully green: [](http://travis-ci.org/github/linguist)
|
||||
Here's our current build status, which is hopefully green: [](http://travis-ci.org/github/linguist)
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'github-linguist'
|
||||
s.version = '2.4.0'
|
||||
s.version = '2.6.8'
|
||||
s.summary = "GitHub Language detection"
|
||||
|
||||
s.authors = "GitHub"
|
||||
s.authors = "GitHub"
|
||||
s.homepage = "https://github.com/github/linguist"
|
||||
|
||||
s.files = Dir['lib/**/*']
|
||||
s.executables << 'linguist'
|
||||
|
||||
s.add_dependency 'charlock_holmes', '~> 0.6.6'
|
||||
s.add_dependency 'escape_utils', '~> 0.2.3'
|
||||
s.add_dependency 'escape_utils', '~> 0.3.1'
|
||||
s.add_dependency 'mime-types', '~> 1.19'
|
||||
s.add_dependency 'pygments.rb', '~> 0.3.7'
|
||||
s.add_dependency 'pygments.rb', '~> 0.4.2'
|
||||
s.add_development_dependency 'mocha'
|
||||
s.add_development_dependency 'json'
|
||||
s.add_development_dependency 'rake'
|
||||
|
||||
@@ -58,6 +58,15 @@ module Linguist
|
||||
_mime_type ? _mime_type.binary? : false
|
||||
end
|
||||
|
||||
# Internal: Is the blob binary according to its mime type,
|
||||
# overriding it if we have better data from the languages.yml
|
||||
# database.
|
||||
#
|
||||
# Return true or false
|
||||
def likely_binary?
|
||||
binary_mime_type? and not Language.find_by_filename(name)
|
||||
end
|
||||
|
||||
# Public: Get the Content-Type header value
|
||||
#
|
||||
# This value is used when serving raw blobs.
|
||||
@@ -139,7 +148,14 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def image?
|
||||
['.png', '.jpg', '.jpeg', '.gif'].include?(extname)
|
||||
['.png', '.jpg', '.jpeg', '.gif'].include?(extname.downcase)
|
||||
end
|
||||
|
||||
# Public: Is the blob a supported 3D model format?
|
||||
#
|
||||
# Return true or false
|
||||
def solid?
|
||||
extname.downcase == '.stl'
|
||||
end
|
||||
|
||||
MEGABYTE = 1024 * 1024
|
||||
@@ -251,7 +267,7 @@ module Linguist
|
||||
|
||||
# Public: Is the blob a generated file?
|
||||
#
|
||||
# Generated source code is supressed in diffs and is ignored by
|
||||
# Generated source code is suppressed in diffs and is ignored by
|
||||
# language statistics.
|
||||
#
|
||||
# May load Blob#data
|
||||
@@ -266,7 +282,7 @@ module Linguist
|
||||
# Excluded:
|
||||
# - Files over 0.1MB
|
||||
# - Non-text files
|
||||
# - Langauges marked as not searchable
|
||||
# - Languages marked as not searchable
|
||||
# - Generated source files
|
||||
#
|
||||
# Please add additional test coverage to
|
||||
|
||||
@@ -40,7 +40,7 @@ module Linguist
|
||||
|
||||
# Public: Guess language of data.
|
||||
#
|
||||
# db - Hash of classifer tokens database.
|
||||
# db - Hash of classifier tokens database.
|
||||
# data - Array of tokens or String data to analyze.
|
||||
# languages - Array of language name Strings to restrict to.
|
||||
#
|
||||
@@ -85,7 +85,7 @@ module Linguist
|
||||
scores.sort { |a, b| b[1] <=> a[1] }.map { |score| [score[0], score[1]] }
|
||||
end
|
||||
|
||||
# Internal: Probably of set of tokens in a language occuring - P(D | C)
|
||||
# Internal: Probably of set of tokens in a language occurring - P(D | C)
|
||||
#
|
||||
# tokens - Array of String tokens.
|
||||
# language - Language to check.
|
||||
@@ -97,7 +97,7 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Probably of token in language occuring - P(F | C)
|
||||
# Internal: Probably of token in language occurring - P(F | C)
|
||||
#
|
||||
# token - String token.
|
||||
# language - Language to check.
|
||||
@@ -111,7 +111,7 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Probably of a language occuring - P(C)
|
||||
# Internal: Probably of a language occurring - P(C)
|
||||
#
|
||||
# language - Language to check.
|
||||
#
|
||||
|
||||
@@ -43,7 +43,7 @@ module Linguist
|
||||
|
||||
# Internal: Is the blob a generated file?
|
||||
#
|
||||
# Generated source code is supressed in diffs and is ignored by
|
||||
# Generated source code is suppressed in diffs and is ignored by
|
||||
# language statistics.
|
||||
#
|
||||
# Please add additional test coverage to
|
||||
@@ -86,7 +86,7 @@ module Linguist
|
||||
|
||||
# Internal: Is the blob of JS generated by CoffeeScript?
|
||||
#
|
||||
# CoffeScript is meant to output JS that would be difficult to
|
||||
# CoffeeScript is meant to output JS that would be difficult to
|
||||
# tell if it was generated or not. Look for a number of patterns
|
||||
# output by the CS compiler.
|
||||
#
|
||||
|
||||
@@ -73,7 +73,7 @@ module Linguist
|
||||
#
|
||||
# Returns Language or nil.
|
||||
def self.detect(name, data, mode = nil)
|
||||
# A bit of an elegant hack. If the file is exectable but extensionless,
|
||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||
# append a "magic" extension so it can be classified with other
|
||||
# languages that have shebang scripts.
|
||||
if File.extname(name).empty? && mode && (mode.to_i(8) & 05) == 05
|
||||
@@ -329,7 +329,7 @@ module Linguist
|
||||
|
||||
# Deprecated: Get primary extension
|
||||
#
|
||||
# Defaults to the first extension but can be overriden
|
||||
# Defaults to the first extension but can be overridden
|
||||
# in the languages.yml.
|
||||
#
|
||||
# The primary extension can not be nil. Tests should verify this.
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
# Defines all Languages known to GitHub.
|
||||
#
|
||||
# All languages have an associated lexer for syntax highlighting. It
|
||||
# defaults to name.downcase, which covers most cases. Make sure the
|
||||
# lexer exists in lexers.yml. This is a list of available in our
|
||||
# version of pygments.
|
||||
# defaults to name.downcase, which covers most cases.
|
||||
#
|
||||
# type - Either data, programming, markup, or nil
|
||||
# lexer - An explicit lexer String (defaults to name.downcase)
|
||||
# lexer - An explicit lexer String (defaults to name)
|
||||
# aliases - An Array of additional aliases (implicitly
|
||||
# includes name.downcase)
|
||||
# ace_mode - A String name of Ace Mode (if available)
|
||||
@@ -26,6 +24,11 @@
|
||||
#
|
||||
# Please keep this list alphabetized.
|
||||
|
||||
ABAP:
|
||||
type: programming
|
||||
lexer: ABAP
|
||||
primary_extension: .abap
|
||||
|
||||
ASP:
|
||||
type: programming
|
||||
color: "#6a40fd"
|
||||
@@ -109,6 +112,15 @@ AutoHotkey:
|
||||
- ahk
|
||||
primary_extension: .ahk
|
||||
|
||||
Awk:
|
||||
type: programming
|
||||
lexer: Awk
|
||||
primary_extension: .awk
|
||||
extensions:
|
||||
- .gawk
|
||||
- .mawk
|
||||
- .nawk
|
||||
|
||||
Batchfile:
|
||||
type: programming
|
||||
group: Shell
|
||||
@@ -186,6 +198,11 @@ C2hs Haskell:
|
||||
- c2hs
|
||||
primary_extension: .chs
|
||||
|
||||
CLIPS:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
primary_extension: .clp
|
||||
|
||||
CMake:
|
||||
primary_extension: .cmake
|
||||
extensions:
|
||||
@@ -224,6 +241,8 @@ CoffeeScript:
|
||||
primary_extension: .coffee
|
||||
extensions:
|
||||
- ._coffee
|
||||
- .cson
|
||||
- .iced
|
||||
filenames:
|
||||
- Cakefile
|
||||
|
||||
@@ -246,6 +265,7 @@ Common Lisp:
|
||||
- lisp
|
||||
primary_extension: .lisp
|
||||
extensions:
|
||||
- .asd
|
||||
- .lsp
|
||||
- .ny
|
||||
|
||||
@@ -285,6 +305,13 @@ D-ObjDump:
|
||||
lexer: d-objdump
|
||||
primary_extension: .d-objdump
|
||||
|
||||
DOT:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
primary_extension: .dot
|
||||
extensions:
|
||||
- .gv
|
||||
|
||||
Darcs Patch:
|
||||
search_term: dpatch
|
||||
aliases:
|
||||
@@ -302,6 +329,7 @@ Delphi:
|
||||
color: "#b0ce4e"
|
||||
primary_extension: .pas
|
||||
extensions:
|
||||
- .dfm
|
||||
- .lpr
|
||||
|
||||
DCPU-16 ASM:
|
||||
@@ -429,8 +457,7 @@ Forth:
|
||||
color: "#341708"
|
||||
lexer: Text only
|
||||
extensions:
|
||||
- .forth
|
||||
- .fth
|
||||
- .4th
|
||||
|
||||
GAS:
|
||||
type: programming
|
||||
@@ -521,7 +548,9 @@ HTML+ERB:
|
||||
- erb
|
||||
primary_extension: .erb
|
||||
extensions:
|
||||
- .erb.deface
|
||||
- .html.erb
|
||||
- .html.erb.deface
|
||||
|
||||
HTML+PHP:
|
||||
type: markup
|
||||
@@ -536,6 +565,9 @@ Haml:
|
||||
group: HTML
|
||||
type: markup
|
||||
primary_extension: .haml
|
||||
extensions:
|
||||
- .haml.deface
|
||||
- .html.haml.deface
|
||||
|
||||
Handlebars:
|
||||
type: markup
|
||||
@@ -598,8 +630,6 @@ Java:
|
||||
ace_mode: java
|
||||
color: "#b07219"
|
||||
primary_extension: .java
|
||||
extensions:
|
||||
- .pde
|
||||
|
||||
Java Server Pages:
|
||||
group: Java
|
||||
@@ -651,11 +681,6 @@ Lasso:
|
||||
ace_mode: lasso
|
||||
color: "#2584c3"
|
||||
primary_extension: .lasso
|
||||
extensions:
|
||||
- .inc
|
||||
- .las
|
||||
- .lasso9
|
||||
- .ldml
|
||||
|
||||
Less:
|
||||
type: markup
|
||||
@@ -670,6 +695,17 @@ LilyPond:
|
||||
extensions:
|
||||
- .ily
|
||||
|
||||
Literate CoffeeScript:
|
||||
type: programming
|
||||
group: CoffeeScript
|
||||
lexer: Text only
|
||||
ace_mode: markdown
|
||||
wrap: true
|
||||
search_term: litcoffee
|
||||
aliases:
|
||||
- litcoffee
|
||||
primary_extension: .litcoffee
|
||||
|
||||
Literate Haskell:
|
||||
type: programming
|
||||
group: Haskell
|
||||
@@ -690,6 +726,14 @@ LiveScript:
|
||||
filenames:
|
||||
- Slakefile
|
||||
|
||||
Logos:
|
||||
type: programming
|
||||
primary_extension: .xm
|
||||
extensions:
|
||||
- .x
|
||||
- .xi
|
||||
- .xmi
|
||||
|
||||
Logtalk:
|
||||
type: programming
|
||||
primary_extension: .lgt
|
||||
@@ -701,7 +745,6 @@ Lua:
|
||||
primary_extension: .lua
|
||||
extensions:
|
||||
- .nse
|
||||
- .pd_lua
|
||||
|
||||
Makefile:
|
||||
aliases:
|
||||
@@ -746,6 +789,9 @@ Max:
|
||||
- maxmsp
|
||||
search_term: max/msp
|
||||
primary_extension: .mxt
|
||||
extensions:
|
||||
- .maxhelp
|
||||
- .maxpat
|
||||
|
||||
MiniD: # Legacy
|
||||
searchable: false
|
||||
@@ -762,6 +808,11 @@ Mirah:
|
||||
- .mir
|
||||
- .mirah
|
||||
|
||||
Monkey:
|
||||
type: programming
|
||||
lexer: Monkey
|
||||
primary_extension: .monkey
|
||||
|
||||
Moocode:
|
||||
lexer: MOOCode
|
||||
primary_extension: .moo
|
||||
@@ -773,6 +824,9 @@ MoonScript:
|
||||
Myghty:
|
||||
primary_extension: .myt
|
||||
|
||||
NSIS:
|
||||
primary_extension: .nsi
|
||||
|
||||
Nemerle:
|
||||
type: programming
|
||||
color: "#0d3c6e"
|
||||
@@ -813,6 +867,7 @@ OCaml:
|
||||
color: "#3be133"
|
||||
primary_extension: .ml
|
||||
extensions:
|
||||
- .eliomi
|
||||
- .mli
|
||||
- .mll
|
||||
- .mly
|
||||
@@ -846,8 +901,6 @@ Omgrofl:
|
||||
primary_extension: .omgrofl
|
||||
color: "#cabbff"
|
||||
lexer: Text only
|
||||
extensions:
|
||||
- .omgrofl
|
||||
|
||||
Opa:
|
||||
type: programming
|
||||
@@ -858,6 +911,8 @@ OpenCL:
|
||||
group: C
|
||||
lexer: C
|
||||
primary_extension: .cl
|
||||
extensions:
|
||||
- .opencl
|
||||
|
||||
OpenEdge ABL:
|
||||
type: programming
|
||||
@@ -918,6 +973,20 @@ Perl:
|
||||
- .pod
|
||||
- .psgi
|
||||
|
||||
Pike:
|
||||
type: programming
|
||||
color: "#066ab2"
|
||||
lexer: C
|
||||
primary_extension: .pike
|
||||
extensions:
|
||||
- .pmod
|
||||
|
||||
PogoScript:
|
||||
type: programming
|
||||
color: "#d80074"
|
||||
lexer: Text only
|
||||
primary_extension: .pogo
|
||||
|
||||
PowerShell:
|
||||
type: programming
|
||||
ace_mode: powershell
|
||||
@@ -925,6 +994,12 @@ PowerShell:
|
||||
- posh
|
||||
primary_extension: .ps1
|
||||
|
||||
Processing:
|
||||
type: programming
|
||||
lexer: Java
|
||||
color: "#2779ab"
|
||||
primary_extension: .pde
|
||||
|
||||
Prolog:
|
||||
type: programming
|
||||
color: "#74283c"
|
||||
@@ -953,6 +1028,7 @@ Python:
|
||||
color: "#3581ba"
|
||||
primary_extension: .py
|
||||
extensions:
|
||||
- .gyp
|
||||
- .pyw
|
||||
- .wsgi
|
||||
- .xpy
|
||||
@@ -986,6 +1062,12 @@ Racket:
|
||||
- .rktd
|
||||
- .rktl
|
||||
|
||||
Ragel in Ruby Host:
|
||||
type: programming
|
||||
lexer: Ragel in Ruby Host
|
||||
color: "#ff9c2e"
|
||||
primary_extension: .rl
|
||||
|
||||
Raw token data:
|
||||
search_term: raw
|
||||
aliases:
|
||||
@@ -1004,6 +1086,13 @@ Rebol:
|
||||
Redcode:
|
||||
primary_extension: .cw
|
||||
|
||||
Rouge:
|
||||
type: programming
|
||||
lexer: Clojure
|
||||
ace_mode: clojure
|
||||
color: "#cc0088"
|
||||
primary_extension: .rg
|
||||
|
||||
Ruby:
|
||||
type: programming
|
||||
ace_mode: ruby
|
||||
@@ -1037,7 +1126,6 @@ Ruby:
|
||||
Rust:
|
||||
type: programming
|
||||
color: "#dea584"
|
||||
lexer: Text only
|
||||
primary_extension: .rs
|
||||
|
||||
SCSS:
|
||||
@@ -1097,6 +1185,8 @@ Shell:
|
||||
- bash
|
||||
- zsh
|
||||
primary_extension: .sh
|
||||
extensions:
|
||||
- .tmux
|
||||
|
||||
Smalltalk:
|
||||
type: programming
|
||||
@@ -1119,6 +1209,15 @@ SuperCollider:
|
||||
lexer: Text only
|
||||
primary_extension: .sc
|
||||
|
||||
TOML:
|
||||
type: data
|
||||
primary_extension: .toml
|
||||
|
||||
TXL:
|
||||
type: programming
|
||||
lexer: Text only
|
||||
primary_extension: .txl
|
||||
|
||||
Tcl:
|
||||
type: programming
|
||||
color: "#e4cc98"
|
||||
@@ -1170,6 +1269,14 @@ Twig:
|
||||
lexer: HTML+Django/Jinja
|
||||
primary_extension: .twig
|
||||
|
||||
TypeScript:
|
||||
type: programming
|
||||
color: "#31859c"
|
||||
lexer: Text only
|
||||
aliases:
|
||||
- ts
|
||||
primary_extension: .ts
|
||||
|
||||
VHDL:
|
||||
type: programming
|
||||
lexer: vhdl
|
||||
@@ -1188,6 +1295,10 @@ Verilog:
|
||||
lexer: verilog
|
||||
color: "#848bf3"
|
||||
primary_extension: .v
|
||||
extensions:
|
||||
- .sv
|
||||
- .svh
|
||||
- .vh
|
||||
|
||||
VimL:
|
||||
type: programming
|
||||
@@ -1217,21 +1328,29 @@ XML:
|
||||
aliases:
|
||||
- rss
|
||||
- xsd
|
||||
- xsl
|
||||
- wsdl
|
||||
primary_extension: .xml
|
||||
extensions:
|
||||
- .ccxml
|
||||
- .dita
|
||||
- .ditamap
|
||||
- .ditaval
|
||||
- .glade
|
||||
- .grxml
|
||||
- .kml
|
||||
- .mxml
|
||||
- .plist
|
||||
- .pt
|
||||
- .rdf
|
||||
- .rss
|
||||
- .scxml
|
||||
- .svg
|
||||
- .ui
|
||||
- .tmCommand
|
||||
- .tmLanguage
|
||||
- .tmPreferences
|
||||
- .tmSnippet
|
||||
- .tml
|
||||
- .vxml
|
||||
- .wsdl
|
||||
- .wxi
|
||||
@@ -1241,12 +1360,19 @@ XML:
|
||||
- .xlf
|
||||
- .xliff
|
||||
- .xsd
|
||||
- .xsl
|
||||
- .xul
|
||||
- .zcml
|
||||
filenames:
|
||||
- .classpath
|
||||
- .project
|
||||
|
||||
XProc:
|
||||
type: programming
|
||||
lexer: XML
|
||||
primary_extension: .xpl
|
||||
extensions:
|
||||
- .xproc
|
||||
|
||||
XQuery:
|
||||
type: programming
|
||||
color: "#2700e2"
|
||||
@@ -1260,9 +1386,16 @@ XS:
|
||||
primary_extension: .xs
|
||||
|
||||
XSLT:
|
||||
type: markup
|
||||
group: XML
|
||||
type: programming
|
||||
aliases:
|
||||
- xsl
|
||||
primary_extension: .xslt
|
||||
extensions:
|
||||
- .xsl
|
||||
|
||||
Xtend:
|
||||
type: programming
|
||||
primary_extension: .xtend
|
||||
|
||||
YAML:
|
||||
type: markup
|
||||
@@ -1279,6 +1412,19 @@ eC:
|
||||
extensions:
|
||||
- .eh
|
||||
|
||||
edn:
|
||||
type: data
|
||||
lexer: Clojure
|
||||
ace_mode: clojure
|
||||
color: "#db5855"
|
||||
primary_extension: .edn
|
||||
|
||||
fish:
|
||||
type: programming
|
||||
group: Shell
|
||||
lexer: Text only
|
||||
primary_extension: .fish
|
||||
|
||||
mupad:
|
||||
lexer: MuPAD
|
||||
primary_extension: .mu
|
||||
|
||||
@@ -4,7 +4,7 @@ module Linguist
|
||||
module MD5
|
||||
# Public: Create deep nested digest of value object.
|
||||
#
|
||||
# Useful for object comparsion.
|
||||
# Useful for object comparison.
|
||||
#
|
||||
# obj - Object to digest.
|
||||
#
|
||||
|
||||
@@ -67,8 +67,8 @@ module Linguist
|
||||
return if @computed_stats
|
||||
|
||||
@enum.each do |blob|
|
||||
# Skip binary file extensions
|
||||
next if blob.binary_mime_type?
|
||||
# Skip files that are likely binary
|
||||
next if blob.likely_binary?
|
||||
|
||||
# Skip vendored or generated blobs
|
||||
next if blob.vendored? || blob.generated? || blob.language.nil?
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,11 +16,15 @@
|
||||
# https://github.com/joyent/node
|
||||
- ^deps/
|
||||
- ^tools/
|
||||
- (^|/)configure$
|
||||
- (^|/)configure.ac$
|
||||
- (^|/)config.guess$
|
||||
- (^|/)config.sub$
|
||||
|
||||
# Node depedencies
|
||||
# Node dependencies
|
||||
- node_modules/
|
||||
|
||||
# Vendored depedencies
|
||||
# Vendored dependencies
|
||||
- vendor/
|
||||
|
||||
# Debian packaging
|
||||
@@ -63,8 +67,16 @@
|
||||
# MathJax
|
||||
- (^|/)MathJax/
|
||||
|
||||
# SyntaxHighlighter - http://alexgorbatchev.com/
|
||||
- (^|/)shBrush([^.]*)\.js$
|
||||
- (^|/)shCore\.js$
|
||||
- (^|/)shLegacy\.js$
|
||||
|
||||
## Python ##
|
||||
|
||||
# django
|
||||
- (^|/)admin_media/
|
||||
|
||||
# Fabric
|
||||
- ^fabfile\.py$
|
||||
|
||||
@@ -96,3 +108,6 @@
|
||||
|
||||
# Samples folders
|
||||
- ^[Ss]amples/
|
||||
|
||||
# Test fixtures
|
||||
- ^[Tt]est/fixtures/
|
||||
|
||||
219
samples/ABAP/cl_csv_parser.abap
Normal file
219
samples/ABAP/cl_csv_parser.abap
Normal file
@@ -0,0 +1,219 @@
|
||||
*/**
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2012 René van Mil
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
*----------------------------------------------------------------------*
|
||||
* CLASS CL_CSV_PARSER DEFINITION
|
||||
*----------------------------------------------------------------------*
|
||||
*
|
||||
*----------------------------------------------------------------------*
|
||||
class cl_csv_parser definition
|
||||
public
|
||||
inheriting from cl_object
|
||||
final
|
||||
create public .
|
||||
|
||||
public section.
|
||||
*"* public components of class CL_CSV_PARSER
|
||||
*"* do not include other source files here!!!
|
||||
|
||||
type-pools abap .
|
||||
methods constructor
|
||||
importing
|
||||
!delegate type ref to if_csv_parser_delegate
|
||||
!csvstring type string
|
||||
!separator type c
|
||||
!skip_first_line type abap_bool .
|
||||
methods parse
|
||||
raising
|
||||
cx_csv_parse_error .
|
||||
protected section.
|
||||
*"* protected components of class CL_CSV_PARSER
|
||||
*"* do not include other source files here!!!
|
||||
private section.
|
||||
*"* private components of class CL_CSV_PARSER
|
||||
*"* do not include other source files here!!!
|
||||
|
||||
constants _textindicator type c value '"'. "#EC NOTEXT
|
||||
data _delegate type ref to if_csv_parser_delegate .
|
||||
data _csvstring type string .
|
||||
data _separator type c .
|
||||
type-pools abap .
|
||||
data _skip_first_line type abap_bool .
|
||||
|
||||
methods _lines
|
||||
returning
|
||||
value(returning) type stringtab .
|
||||
methods _parse_line
|
||||
importing
|
||||
!line type string
|
||||
returning
|
||||
value(returning) type stringtab
|
||||
raising
|
||||
cx_csv_parse_error .
|
||||
endclass. "CL_CSV_PARSER DEFINITION
|
||||
|
||||
|
||||
|
||||
*----------------------------------------------------------------------*
|
||||
* CLASS CL_CSV_PARSER IMPLEMENTATION
|
||||
*----------------------------------------------------------------------*
|
||||
*
|
||||
*----------------------------------------------------------------------*
|
||||
class cl_csv_parser implementation.
|
||||
|
||||
|
||||
* <SIGNATURE>---------------------------------------------------------------------------------------+
|
||||
* | Instance Public Method CL_CSV_PARSER->CONSTRUCTOR
|
||||
* +-------------------------------------------------------------------------------------------------+
|
||||
* | [--->] DELEGATE TYPE REF TO IF_CSV_PARSER_DELEGATE
|
||||
* | [--->] CSVSTRING TYPE STRING
|
||||
* | [--->] SEPARATOR TYPE C
|
||||
* | [--->] SKIP_FIRST_LINE TYPE ABAP_BOOL
|
||||
* +--------------------------------------------------------------------------------------</SIGNATURE>
|
||||
method constructor.
|
||||
super->constructor( ).
|
||||
_delegate = delegate.
|
||||
_csvstring = csvstring.
|
||||
_separator = separator.
|
||||
_skip_first_line = skip_first_line.
|
||||
endmethod. "constructor
|
||||
|
||||
|
||||
* <SIGNATURE>---------------------------------------------------------------------------------------+
|
||||
* | Instance Public Method CL_CSV_PARSER->PARSE
|
||||
* +-------------------------------------------------------------------------------------------------+
|
||||
* | [!CX!] CX_CSV_PARSE_ERROR
|
||||
* +--------------------------------------------------------------------------------------</SIGNATURE>
|
||||
method parse.
|
||||
data msg type string.
|
||||
if _csvstring is initial.
|
||||
message e002(csv) into msg.
|
||||
raise exception type cx_csv_parse_error
|
||||
exporting
|
||||
message = msg.
|
||||
endif.
|
||||
|
||||
" Get the lines
|
||||
data is_first_line type abap_bool value abap_true.
|
||||
data lines type standard table of string.
|
||||
lines = _lines( ).
|
||||
field-symbols <line> type string.
|
||||
loop at lines assigning <line>.
|
||||
" Should we skip the first line?
|
||||
if _skip_first_line = abap_true and is_first_line = abap_true.
|
||||
is_first_line = abap_false.
|
||||
continue.
|
||||
endif.
|
||||
" Parse the line
|
||||
data values type standard table of string.
|
||||
values = _parse_line( <line> ).
|
||||
" Send values to delegate
|
||||
_delegate->values_found( values ).
|
||||
endloop.
|
||||
endmethod. "parse
|
||||
|
||||
|
||||
* <SIGNATURE>---------------------------------------------------------------------------------------+
|
||||
* | Instance Private Method CL_CSV_PARSER->_LINES
|
||||
* +-------------------------------------------------------------------------------------------------+
|
||||
* | [<-()] RETURNING TYPE STRINGTAB
|
||||
* +--------------------------------------------------------------------------------------</SIGNATURE>
|
||||
method _lines.
|
||||
split _csvstring at cl_abap_char_utilities=>cr_lf into table returning.
|
||||
endmethod. "_lines
|
||||
|
||||
|
||||
* <SIGNATURE>---------------------------------------------------------------------------------------+
|
||||
* | Instance Private Method CL_CSV_PARSER->_PARSE_LINE
|
||||
* +-------------------------------------------------------------------------------------------------+
|
||||
* | [--->] LINE TYPE STRING
|
||||
* | [<-()] RETURNING TYPE STRINGTAB
|
||||
* | [!CX!] CX_CSV_PARSE_ERROR
|
||||
* +--------------------------------------------------------------------------------------</SIGNATURE>
|
||||
method _parse_line.
|
||||
data msg type string.
|
||||
|
||||
data csvvalue type string.
|
||||
data csvvalues type standard table of string.
|
||||
|
||||
data char type c.
|
||||
data pos type i value 0.
|
||||
data len type i.
|
||||
len = strlen( line ).
|
||||
while pos < len.
|
||||
char = line+pos(1).
|
||||
if char <> _separator.
|
||||
if char = _textindicator.
|
||||
data text_ended type abap_bool.
|
||||
text_ended = abap_false.
|
||||
while text_ended = abap_false.
|
||||
pos = pos + 1.
|
||||
if pos < len.
|
||||
char = line+pos(1).
|
||||
if char = _textindicator.
|
||||
text_ended = abap_true.
|
||||
else.
|
||||
if char is initial. " Space
|
||||
concatenate csvvalue ` ` into csvvalue.
|
||||
else.
|
||||
concatenate csvvalue char into csvvalue.
|
||||
endif.
|
||||
endif.
|
||||
else.
|
||||
" Reached the end of the line while inside a text value
|
||||
" This indicates an error in the CSV formatting
|
||||
text_ended = abap_true.
|
||||
message e003(csv) into msg.
|
||||
raise exception type cx_csv_parse_error
|
||||
exporting
|
||||
message = msg.
|
||||
endif.
|
||||
endwhile.
|
||||
" Check if next character is a separator, otherwise the CSV formatting is incorrect
|
||||
data nextpos type i.
|
||||
nextpos = pos + 1.
|
||||
if nextpos < len and line+nextpos(1) <> _separator.
|
||||
message e003(csv) into msg.
|
||||
raise exception type cx_csv_parse_error
|
||||
exporting
|
||||
message = msg.
|
||||
endif.
|
||||
else.
|
||||
if char is initial. " Space
|
||||
concatenate csvvalue ` ` into csvvalue.
|
||||
else.
|
||||
concatenate csvvalue char into csvvalue.
|
||||
endif.
|
||||
endif.
|
||||
else.
|
||||
append csvvalue to csvvalues.
|
||||
clear csvvalue.
|
||||
endif.
|
||||
pos = pos + 1.
|
||||
endwhile.
|
||||
append csvvalue to csvvalues. " Don't forget the last value
|
||||
|
||||
returning = csvvalues.
|
||||
endmethod. "_parse_line
|
||||
endclass. "CL_CSV_PARSER IMPLEMENTATION
|
||||
121
samples/Awk/test.awk
Normal file
121
samples/Awk/test.awk
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/bin/awk -f
|
||||
|
||||
BEGIN {
|
||||
# It is not possible to define output file names here because
|
||||
# FILENAME is not define in the BEGIN section
|
||||
n = "";
|
||||
printf "Generating data files ...";
|
||||
network_max_bandwidth_in_byte = 10000000;
|
||||
network_max_packet_per_second = 1000000;
|
||||
last3 = 0;
|
||||
last4 = 0;
|
||||
last5 = 0;
|
||||
last6 = 0;
|
||||
}
|
||||
{
|
||||
if ($1 ~ /Average/)
|
||||
{ # Skip the Average values
|
||||
n = "";
|
||||
next;
|
||||
}
|
||||
|
||||
if ($2 ~ /all/)
|
||||
{ # This is the cpu info
|
||||
print $3 > FILENAME".cpu.user.dat";
|
||||
# print $4 > FILENAME".cpu.nice.dat";
|
||||
print $5 > FILENAME".cpu.system.dat";
|
||||
# print $6 > FILENAME".cpu.iowait.dat";
|
||||
print $7 > FILENAME".cpu.idle.dat";
|
||||
print 100-$7 > FILENAME".cpu.busy.dat";
|
||||
}
|
||||
if ($2 ~ /eth0/)
|
||||
{ # This is the eth0 network info
|
||||
if ($3 > network_max_packet_per_second)
|
||||
print last3 > FILENAME".net.rxpck.dat"; # Total number of packets received per second.
|
||||
else
|
||||
{
|
||||
last3 = $3;
|
||||
print $3 > FILENAME".net.rxpck.dat"; # Total number of packets received per second.
|
||||
}
|
||||
if ($4 > network_max_packet_per_second)
|
||||
print last4 > FILENAME".net.txpck.dat"; # Total number of packets transmitted per second.
|
||||
else
|
||||
{
|
||||
last4 = $4;
|
||||
print $4 > FILENAME".net.txpck.dat"; # Total number of packets transmitted per second.
|
||||
}
|
||||
if ($5 > network_max_bandwidth_in_byte)
|
||||
print last5 > FILENAME".net.rxbyt.dat"; # Total number of bytes received per second.
|
||||
else
|
||||
{
|
||||
last5 = $5;
|
||||
print $5 > FILENAME".net.rxbyt.dat"; # Total number of bytes received per second.
|
||||
}
|
||||
if ($6 > network_max_bandwidth_in_byte)
|
||||
print last6 > FILENAME".net.txbyt.dat"; # Total number of bytes transmitted per second.
|
||||
else
|
||||
{
|
||||
last6 = $6;
|
||||
print $6 > FILENAME".net.txbyt.dat"; # Total number of bytes transmitted per second.
|
||||
}
|
||||
# print $7 > FILENAME".net.rxcmp.dat"; # Number of compressed packets received per second (for cslip etc.).
|
||||
# print $8 > FILENAME".net.txcmp.dat"; # Number of compressed packets transmitted per second.
|
||||
# print $9 > FILENAME".net.rxmcst.dat"; # Number of multicast packets received per second.
|
||||
}
|
||||
|
||||
# Detect which is the next info to be parsed
|
||||
if ($2 ~ /proc|cswch|tps|kbmemfree|totsck/)
|
||||
{
|
||||
n = $2;
|
||||
}
|
||||
|
||||
# Only get lines with numbers (real data !)
|
||||
if ($2 ~ /[0-9]/)
|
||||
{
|
||||
if (n == "proc/s")
|
||||
{ # This is the proc/s info
|
||||
print $2 > FILENAME".proc.dat";
|
||||
# n = "";
|
||||
}
|
||||
if (n == "cswch/s")
|
||||
{ # This is the context switches per second info
|
||||
print $2 > FILENAME".ctxsw.dat";
|
||||
# n = "";
|
||||
}
|
||||
if (n == "tps")
|
||||
{ # This is the disk info
|
||||
print $2 > FILENAME".disk.tps.dat"; # total transfers per second
|
||||
print $3 > FILENAME".disk.rtps.dat"; # read requests per second
|
||||
print $4 > FILENAME".disk.wtps.dat"; # write requests per second
|
||||
print $5 > FILENAME".disk.brdps.dat"; # block reads per second
|
||||
print $6 > FILENAME".disk.bwrps.dat"; # block writes per second
|
||||
# n = "";
|
||||
}
|
||||
if (n == "kbmemfree")
|
||||
{ # This is the mem info
|
||||
print $2 > FILENAME".mem.kbmemfree.dat"; # Amount of free memory available in kilobytes.
|
||||
print $3 > FILENAME".mem.kbmemused.dat"; # Amount of used memory in kilobytes. This does not take into account memory used by the kernel itself.
|
||||
print $4 > FILENAME".mem.memused.dat"; # Percentage of used memory.
|
||||
# It appears the kbmemshrd has been removed from the sysstat output - ntolia
|
||||
# print $X > FILENAME".mem.kbmemshrd.dat"; # Amount of memory shared by the system in kilobytes. Always zero with 2.4 kernels.
|
||||
# print $5 > FILENAME".mem.kbbuffers.dat"; # Amount of memory used as buffers by the kernel in kilobytes.
|
||||
print $6 > FILENAME".mem.kbcached.dat"; # Amount of memory used to cache data by the kernel in kilobytes.
|
||||
# print $7 > FILENAME".mem.kbswpfree.dat"; # Amount of free swap space in kilobytes.
|
||||
# print $8 > FILENAME".mem.kbswpused.dat"; # Amount of used swap space in kilobytes.
|
||||
print $9 > FILENAME".mem.swpused.dat"; # Percentage of used swap space.
|
||||
# n = "";
|
||||
}
|
||||
if (n == "totsck")
|
||||
{ # This is the socket info
|
||||
print $2 > FILENAME".sock.totsck.dat"; # Total number of used sockets.
|
||||
print $3 > FILENAME".sock.tcpsck.dat"; # Number of TCP sockets currently in use.
|
||||
# print $4 > FILENAME".sock.udpsck.dat"; # Number of UDP sockets currently in use.
|
||||
# print $5 > FILENAME".sock.rawsck.dat"; # Number of RAW sockets currently in use.
|
||||
# print $6 > FILENAME".sock.ip-frag.dat"; # Number of IP fragments currently in use.
|
||||
# n = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
END {
|
||||
print " '" FILENAME "' done.";
|
||||
}
|
||||
BIN
samples/Binary/cube.stl
Normal file
BIN
samples/Binary/cube.stl
Normal file
Binary file not shown.
4674
samples/C++/wrapper_inner.cpp
Normal file
4674
samples/C++/wrapper_inner.cpp
Normal file
File diff suppressed because it is too large
Load Diff
15669
samples/C/sgd_fast.c
Normal file
15669
samples/C/sgd_fast.c
Normal file
File diff suppressed because it is too large
Load Diff
79
samples/Forth/KataDiversion.fth
Normal file
79
samples/Forth/KataDiversion.fth
Normal file
@@ -0,0 +1,79 @@
|
||||
\ KataDiversion in Forth
|
||||
|
||||
\ -- utils
|
||||
|
||||
\ empty the stack
|
||||
: EMPTY
|
||||
DEPTH 0 <> IF BEGIN
|
||||
DROP DEPTH 0 =
|
||||
UNTIL
|
||||
THEN ;
|
||||
|
||||
\ power
|
||||
: ** ( n1 n2 -- n1_pow_n2 ) 1 SWAP ?DUP IF 0 DO OVER * LOOP THEN NIP ;
|
||||
|
||||
\ compute the highest power of 2 below N.
|
||||
\ e.g. : 31 -> 16, 4 -> 4
|
||||
: MAXPOW2 ( n -- log2_n ) DUP 1 < IF 1 ABORT" Maxpow2 need a positive value."
|
||||
ELSE DUP 1 = IF 1
|
||||
ELSE
|
||||
1 >R
|
||||
BEGIN ( n |R: i=1)
|
||||
DUP DUP I - 2 *
|
||||
( n n 2*[n-i])
|
||||
R> 2 * >R ( … |R: i*2)
|
||||
> ( n n>2*[n-i] )
|
||||
UNTIL
|
||||
R> 2 /
|
||||
THEN
|
||||
THEN NIP ;
|
||||
|
||||
\ -- kata
|
||||
|
||||
\ test if the given N has two adjacent 1 bits
|
||||
\ e.g. : 11 -> 1011 -> -1
|
||||
\ 9 -> 1001 -> 0
|
||||
: ?NOT-TWO-ADJACENT-1-BITS ( n -- bool )
|
||||
\ the word uses the following algorithm :
|
||||
\ (stack|return stack)
|
||||
\ ( A N | X ) A: 0, X: N LOG2
|
||||
\ loop: if N-X > 0 then A++ else A=0 ; X /= 2
|
||||
\ return 0 if A=2
|
||||
\ if X=1 end loop and return -1
|
||||
0 SWAP DUP DUP 0 <> IF
|
||||
MAXPOW2 >R
|
||||
BEGIN
|
||||
DUP I - 0 >= IF
|
||||
SWAP DUP 1 = IF 1+ SWAP
|
||||
ELSE DROP 1 SWAP I -
|
||||
THEN
|
||||
ELSE NIP 0 SWAP
|
||||
THEN
|
||||
OVER
|
||||
2 =
|
||||
I 1 = OR
|
||||
R> 2 / >R
|
||||
UNTIL
|
||||
R> 2DROP
|
||||
2 <>
|
||||
ELSE 2DROP INVERT
|
||||
THEN ;
|
||||
|
||||
\ return the maximum number which can be made with N (given number) bits
|
||||
: MAX-NB ( n -- m ) DUP 1 < IF DROP 0 ( 0 )
|
||||
ELSE
|
||||
DUP IF DUP 2 SWAP ** NIP 1 - ( 2**n - 1 )
|
||||
THEN
|
||||
THEN ;
|
||||
|
||||
|
||||
\ return the number of numbers which can be made with N (given number) bits
|
||||
\ or less, and which have not two adjacent 1 bits.
|
||||
\ see http://www.codekata.com/2007/01/code_kata_fifte.html
|
||||
: HOW-MANY-NB-NOT-TWO-ADJACENT-1-BITS ( n -- m )
|
||||
DUP 1 < IF DUP 0
|
||||
ELSE
|
||||
0 SWAP
|
||||
MAX-NB 1 + 0 DO I ?NOT-TWO-ADJACENT-1-BITS - LOOP
|
||||
THEN ;
|
||||
|
||||
42
samples/Forth/block.fth
Normal file
42
samples/Forth/block.fth
Normal file
@@ -0,0 +1,42 @@
|
||||
( Block words. )
|
||||
|
||||
variable blk
|
||||
variable current-block
|
||||
|
||||
: block ( n -- addr )
|
||||
current-block ! 0 ;
|
||||
|
||||
: buffer ( n -- addr )
|
||||
current-block ! 0 ;
|
||||
|
||||
\ evaluate (extended semantics)
|
||||
\ flush ( -- )
|
||||
|
||||
: load ( ... n -- ... )
|
||||
dup current-block !
|
||||
blk !
|
||||
save-input
|
||||
0 >in !
|
||||
blk @ block ''source ! 1024 ''#source !
|
||||
( interpret )
|
||||
restore-input ;
|
||||
|
||||
\ save-buffers ( -- )
|
||||
\ update ( -- )
|
||||
|
||||
( Block extension words. )
|
||||
|
||||
\ empty-buffers ( -- )
|
||||
|
||||
variable scr
|
||||
|
||||
: list ( n -- )
|
||||
dup scr !
|
||||
dup current-block !
|
||||
block 1024 bounds do i @ emit loop ;
|
||||
|
||||
\ refill (extended semantics)
|
||||
|
||||
: thru ( x y -- ) +1 swap do i load loop ;
|
||||
|
||||
\ \ (extended semantics)
|
||||
136
samples/Forth/core-ext.fth
Normal file
136
samples/Forth/core-ext.fth
Normal file
@@ -0,0 +1,136 @@
|
||||
\ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
|
||||
|
||||
\ Kernel: #tib
|
||||
\ TODO: .r
|
||||
|
||||
: .( ( "<string><paren>" -- )
|
||||
[char] ) parse type ; immediate
|
||||
|
||||
: 0<> ( n -- flag ) 0 <> ;
|
||||
|
||||
: 0> ( n -- flag ) 0 > ;
|
||||
|
||||
\ Kernel: 2>r
|
||||
|
||||
: 2r> ( -- x1 x2 ) ( R: x1 x2 -- ) r> r> r> rot >r swap ;
|
||||
|
||||
: 2r@ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 ) 2r> 2dup 2>r ;
|
||||
|
||||
: :noname align here 0 c, 15 allot lastxt dup @ , !
|
||||
[ ' enter >code @ ] literal , 0 , ] lastxt @ ;
|
||||
|
||||
\ Kernel: <>
|
||||
|
||||
\ : ?do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
|
||||
\ here postpone 2>r unresolved branch here ;
|
||||
|
||||
: again ( -- ) ( C: dest -- )
|
||||
postpone branch , ; immediate
|
||||
|
||||
: string+ ( caddr -- addr )
|
||||
count + aligned ;
|
||||
|
||||
: (c") ( -- caddr ) ( R: ret1 -- ret2 )
|
||||
r> dup string+ >r ;
|
||||
|
||||
: c" ( "<string><quote>" -- caddr )
|
||||
postpone (c") [char] " parse dup c, string, ; immediate
|
||||
|
||||
: case ( -- ) ( C: -- case-sys )
|
||||
0 ;
|
||||
|
||||
: compile, ( xt -- )
|
||||
, ;
|
||||
|
||||
\ TODO: convert
|
||||
|
||||
: endcase ( x -- ) ( C: case-sys -- )
|
||||
0 do postpone then loop
|
||||
postpone drop ;
|
||||
|
||||
: endof ( -- ) ( C: case-sys1 of-sys -- case-sys2 )
|
||||
postpone else swap 1+ ;
|
||||
|
||||
\ TODO: erase
|
||||
\ TODO: expect
|
||||
|
||||
: false ( -- 0 )
|
||||
0 ;
|
||||
|
||||
: hex ( -- )
|
||||
16 base ! ;
|
||||
|
||||
\ TODO: marker
|
||||
\ Kernel: nip
|
||||
|
||||
: of ( x x -- | x y -- x ) ( C: -- of-sys )
|
||||
postpone over postpone = postpone if postpone drop ;
|
||||
|
||||
\ Kernel: pad
|
||||
\ Kernel: parse
|
||||
|
||||
: pick ( xn ... x0 n -- xn ... x0 xn )
|
||||
2 + cells 'SP @ + @ ;
|
||||
|
||||
: query ( -- )
|
||||
tib ''source ! #tib ''#source ! 0 'source-id !
|
||||
refill drop ;
|
||||
|
||||
\ Kernel: refill
|
||||
\ Kernel: restore-input
|
||||
|
||||
\ TODO: roll ( xn xn-1 ... x0 n -- xn-1 ... x0 xn ) ;
|
||||
|
||||
\ Kernel: save-input
|
||||
\ Kernel: source-id
|
||||
\ TODO: span
|
||||
\ Kernel: tib
|
||||
|
||||
: to ( x "word" -- )
|
||||
' >body , ;
|
||||
|
||||
: true ( -- -1 )
|
||||
-1 ;
|
||||
|
||||
: tuck ( x y -- y x y )
|
||||
swap over ;
|
||||
|
||||
\ TODO: u.r
|
||||
|
||||
: u> ( x y -- flag )
|
||||
2dup u< if 2drop false else <> then ;
|
||||
|
||||
\ TODO: unused
|
||||
|
||||
: value ( x "word" -- )
|
||||
create ,
|
||||
does> ( -- x )
|
||||
@ ;
|
||||
|
||||
: within over - >r - r> u< ;
|
||||
|
||||
\ TODO: [compile]
|
||||
|
||||
\ Kernel: \
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Forth2012 core extension words. )
|
||||
|
||||
\ TODO: action-of
|
||||
|
||||
\ TODO: buffer:
|
||||
|
||||
: defer create ['] abort , does> @ execute ;
|
||||
|
||||
: defer! ( xt2 xt1 -- ) >body ! ;
|
||||
|
||||
: defer@ ( xt1 -- xt2 ) >body @ ;
|
||||
|
||||
\ TODO: holds
|
||||
|
||||
: is ( xt "word" -- ) ' defer! ;
|
||||
|
||||
\ TODO: parse-name
|
||||
|
||||
\ TODO: s\"
|
||||
252
samples/Forth/core.fth
Normal file
252
samples/Forth/core.fth
Normal file
@@ -0,0 +1,252 @@
|
||||
: immediate lastxt @ dup c@ negate swap c! ;
|
||||
|
||||
: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
|
||||
|
||||
: char \ ( "word" -- char )
|
||||
bl-word here 1+ c@ ;
|
||||
|
||||
: ahead here 0 , ;
|
||||
|
||||
: resolve here swap ! ;
|
||||
|
||||
: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
|
||||
|
||||
: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
|
||||
|
||||
: create dovariable_code header, reveal ;
|
||||
|
||||
create postponers
|
||||
' postpone-nonimmediate ,
|
||||
' abort ,
|
||||
' , ,
|
||||
|
||||
: word \ ( char "<chars>string<char>" -- caddr )
|
||||
drop bl-word here ;
|
||||
|
||||
: postpone \ ( C: "word" -- )
|
||||
bl word find 1+ cells postponers + @ execute ; immediate
|
||||
|
||||
: unresolved \ ( C: "word" -- orig )
|
||||
postpone postpone postpone ahead ; immediate
|
||||
|
||||
: chars \ ( n1 -- n2 )
|
||||
;
|
||||
|
||||
: else \ ( -- ) ( C: orig1 -- orig2 )
|
||||
unresolved branch swap resolve ; immediate
|
||||
|
||||
: if \ ( flag -- ) ( C: -- orig )
|
||||
unresolved 0branch ; immediate
|
||||
|
||||
: then \ ( -- ) ( C: orig -- )
|
||||
resolve ; immediate
|
||||
|
||||
: [char] \ ( "word" -- )
|
||||
char postpone literal ; immediate
|
||||
|
||||
: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
|
||||
|
||||
: does> postpone (does>) ; immediate
|
||||
|
||||
: begin \ ( -- ) ( C: -- dest )
|
||||
here ; immediate
|
||||
|
||||
: while \ ( x -- ) ( C: dest -- orig dest )
|
||||
unresolved 0branch swap ; immediate
|
||||
|
||||
: repeat \ ( -- ) ( C: orig dest -- )
|
||||
postpone branch , resolve ; immediate
|
||||
|
||||
: until \ ( x -- ) ( C: dest -- )
|
||||
postpone 0branch , ; immediate
|
||||
|
||||
: recurse lastxt @ compile, ; immediate
|
||||
|
||||
: pad \ ( -- addr )
|
||||
here 1024 + ;
|
||||
|
||||
: parse \ ( char "string<char>" -- addr n )
|
||||
pad >r begin
|
||||
source? if <source 2dup <> else 0 0 then
|
||||
while
|
||||
r@ c! r> 1+ >r
|
||||
repeat 2drop pad r> over - ;
|
||||
|
||||
: ( \ ( "string<paren>" -- )
|
||||
[ char ) ] literal parse 2drop ; immediate
|
||||
\ TODO: If necessary, refill and keep parsing.
|
||||
|
||||
: string, ( addr n -- )
|
||||
here over allot align swap cmove ;
|
||||
|
||||
: (s") ( -- addr n ) ( R: ret1 -- ret2 )
|
||||
r> dup @ swap cell+ 2dup + aligned >r swap ;
|
||||
|
||||
create squote 128 allot
|
||||
|
||||
: s" ( "string<quote>" -- addr n )
|
||||
state @ if
|
||||
postpone (s") [char] " parse dup , string,
|
||||
else
|
||||
[char] " parse >r squote r@ cmove squote r>
|
||||
then ; immediate
|
||||
|
||||
: (abort") ( ... addr n -- ) ( R: ... -- )
|
||||
cr type cr abort ;
|
||||
|
||||
: abort" ( ... x "string<quote>" -- ) ( R: ... -- )
|
||||
postpone if postpone s" postpone (abort") postpone then ; immediate
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Core words. )
|
||||
|
||||
\ TODO: #
|
||||
\ TODO: #>
|
||||
\ TODO: #s
|
||||
|
||||
: and ( x y -- x&y ) nand invert ;
|
||||
|
||||
: * 1 2>r 0 swap begin r@ while
|
||||
r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
|
||||
repeat r> r> 2drop drop ;
|
||||
|
||||
\ TODO: */mod
|
||||
|
||||
: +loop ( -- ) ( C: nest-sys -- )
|
||||
postpone (+loop) postpone 0branch , postpone unloop ; immediate
|
||||
|
||||
: space bl emit ;
|
||||
|
||||
: ?.- dup 0 < if [char] - emit negate then ;
|
||||
|
||||
: digit [char] 0 + emit ;
|
||||
|
||||
: (.) base @ /mod ?dup if recurse then digit ;
|
||||
|
||||
: ." ( "string<quote>" -- ) postpone s" postpone type ; immediate
|
||||
|
||||
: . ( x -- ) ?.- (.) space ;
|
||||
|
||||
: postpone-number ( caddr -- )
|
||||
0 0 rot count >number dup 0= if
|
||||
2drop nip
|
||||
postpone (literal) postpone (literal) postpone ,
|
||||
postpone literal postpone ,
|
||||
else
|
||||
." Undefined: " type cr abort
|
||||
then ;
|
||||
|
||||
' postpone-number postponers cell+ !
|
||||
|
||||
: / ( x y -- x/y ) /mod nip ;
|
||||
|
||||
: 0< ( n -- flag ) 0 < ;
|
||||
|
||||
: 1- ( n -- n-1 ) -1 + ;
|
||||
|
||||
: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
|
||||
|
||||
: 2* ( n -- 2n ) dup + ;
|
||||
|
||||
\ Kernel: 2/
|
||||
|
||||
: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
|
||||
|
||||
\ Kernel: 2drop
|
||||
\ Kernel: 2dup
|
||||
|
||||
\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
|
||||
\ 3 pick 3 pick ;
|
||||
|
||||
\ TODO: 2swap
|
||||
|
||||
\ TODO: <#
|
||||
|
||||
: abs ( n -- |n| )
|
||||
dup 0< if negate then ;
|
||||
|
||||
\ TODO: accept
|
||||
|
||||
: c, ( n -- )
|
||||
here c! 1 chars allot ;
|
||||
|
||||
: char+ ( n1 -- n2 )
|
||||
1+ ;
|
||||
|
||||
: constant create , does> @ ;
|
||||
|
||||
: decimal ( -- )
|
||||
10 base ! ;
|
||||
|
||||
: depth ( -- n )
|
||||
data_stack 100 cells + 'SP @ - /cell / 2 - ;
|
||||
|
||||
: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
|
||||
postpone 2>r here ; immediate
|
||||
|
||||
\ TODO: environment?
|
||||
\ TODO: evaluate
|
||||
\ TODO: fill
|
||||
\ TODO: fm/mod )
|
||||
\ TODO: hold
|
||||
|
||||
: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
|
||||
'RP @ 3 cells + @ ;
|
||||
|
||||
\ TODO: leave
|
||||
|
||||
: loop ( -- ) ( C: nest-sys -- )
|
||||
postpone 1 postpone (+loop)
|
||||
postpone 0branch ,
|
||||
postpone unloop ; immediate
|
||||
|
||||
: lshift begin ?dup while 1- swap dup + swap repeat ;
|
||||
|
||||
: rshift 1 begin over while dup + swap 1- swap repeat nip
|
||||
2>r 0 1 begin r@ while
|
||||
r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
|
||||
repeat r> r> 2drop drop ;
|
||||
|
||||
: max ( x y -- max[x,y] )
|
||||
2dup > if drop else nip then ;
|
||||
|
||||
\ Kernel: min
|
||||
\ TODO: mod
|
||||
\ TODO: move
|
||||
|
||||
: (quit) ( R: ... -- )
|
||||
return_stack 100 cells + 'RP !
|
||||
0 'source-id ! tib ''source ! #tib ''#source !
|
||||
postpone [
|
||||
begin
|
||||
refill
|
||||
while
|
||||
interpret state @ 0= if ." ok" cr then
|
||||
repeat
|
||||
bye ;
|
||||
|
||||
' (quit) ' quit >body cell+ !
|
||||
|
||||
\ TODO: s>d
|
||||
\ TODO: sign
|
||||
\ TODO: sm/rem
|
||||
|
||||
: spaces ( n -- )
|
||||
0 do space loop ;
|
||||
|
||||
\ TODO: u.
|
||||
|
||||
: signbit ( -- n ) -1 1 rshift invert ;
|
||||
|
||||
: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
|
||||
|
||||
: u< ( x y -- flag ) signbit xor swap signbit xor > ;
|
||||
|
||||
\ TODO: um/mod
|
||||
|
||||
: variable ( "word" -- )
|
||||
create /cell allot ;
|
||||
|
||||
: ['] \ ( C: "word" -- )
|
||||
' postpone literal ; immediate
|
||||
133
samples/Forth/tools.fth
Normal file
133
samples/Forth/tools.fth
Normal file
@@ -0,0 +1,133 @@
|
||||
\ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
|
||||
|
||||
( Tools words. )
|
||||
|
||||
: .s ( -- )
|
||||
[char] < emit depth (.) ." > "
|
||||
'SP @ >r r@ depth 1- cells +
|
||||
begin
|
||||
dup r@ <>
|
||||
while
|
||||
dup @ .
|
||||
/cell -
|
||||
repeat r> 2drop ;
|
||||
|
||||
: ? @ . ;
|
||||
|
||||
: c? c@ . ;
|
||||
|
||||
: dump bounds do i ? /cell +loop cr ;
|
||||
|
||||
: cdump bounds do i c? loop cr ;
|
||||
|
||||
: again postpone branch , ; immediate
|
||||
|
||||
: see-find ( caddr -- end xt )
|
||||
>r here lastxt @
|
||||
begin
|
||||
dup 0= abort" Undefined word"
|
||||
dup r@ word= if r> drop exit then
|
||||
nip dup >nextxt
|
||||
again ;
|
||||
|
||||
: cabs ( char -- |char| ) dup 127 > if 256 swap - then ;
|
||||
|
||||
: xt. ( xt -- )
|
||||
( >name ) count cabs type ;
|
||||
|
||||
: xt? ( xt -- flag )
|
||||
>r lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
dup r@ = if r> 2drop -1 exit then
|
||||
>nextxt
|
||||
repeat r> drop 0 ;
|
||||
|
||||
: disassemble ( x -- )
|
||||
dup xt? if
|
||||
( >name ) count
|
||||
dup 127 > if ." postpone " then
|
||||
cabs type
|
||||
else
|
||||
.
|
||||
then ;
|
||||
|
||||
: .addr dup . ;
|
||||
|
||||
: see-line ( addr -- )
|
||||
cr ." ( " .addr ." ) " @ disassemble ;
|
||||
|
||||
: see-word ( end xt -- )
|
||||
>r ." : " r@ xt.
|
||||
r@ >body do i see-line /cell +loop
|
||||
." ;" r> c@ 127 > if ." immediate" then ;
|
||||
|
||||
: see bl word see-find see-word cr ;
|
||||
|
||||
: #body bl word see-find >body - ;
|
||||
|
||||
: type-word ( end xt -- flag )
|
||||
xt. space drop 0 ;
|
||||
|
||||
: traverse-dictionary ( in.. xt -- out.. )
|
||||
\ xt execution: ( in.. end xt2 -- in.. 0 | in.. end xt2 -- out.. true )
|
||||
>r here lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
r> 2dup >r >r execute
|
||||
if r> r> 2drop exit then
|
||||
r> dup >nextxt
|
||||
repeat r> 2drop ;
|
||||
|
||||
: words ( -- )
|
||||
['] type-word traverse-dictionary cr ;
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Tools extension words. )
|
||||
|
||||
\ ;code
|
||||
|
||||
\ assembler
|
||||
|
||||
\ in kernel: bye
|
||||
|
||||
\ code
|
||||
|
||||
\ cs-pick
|
||||
|
||||
\ cs-roll
|
||||
|
||||
\ editor
|
||||
|
||||
: forget ' dup >nextxt lastxt ! 'here ! reveal ;
|
||||
|
||||
\ Kernel: state
|
||||
|
||||
\ [else]
|
||||
|
||||
\ [if]
|
||||
|
||||
\ [then]
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Forth2012 tools extension words. )
|
||||
|
||||
\ TODO: n>r
|
||||
|
||||
\ TODO: nr>
|
||||
|
||||
\ TODO: synonym
|
||||
|
||||
: [undefined] bl-word find nip 0= ; immediate
|
||||
|
||||
: [defined] postpone [undefined] invert ; immediate
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
: @+ ( addr -- addr+/cell x ) dup cell+ swap @ ;
|
||||
|
||||
: !+ ( x addr -- addr+/cell ) tuck ! cell+ ;
|
||||
|
||||
: -rot swap >r swap r> ;
|
||||
10
samples/INI/filenames/.editorconfig
Normal file
10
samples/INI/filenames/.editorconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
; editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
File diff suppressed because it is too large
Load Diff
117
samples/Literate CoffeeScript/scope.litcoffee
Normal file
117
samples/Literate CoffeeScript/scope.litcoffee
Normal file
@@ -0,0 +1,117 @@
|
||||
The **Scope** class regulates lexical scoping within CoffeeScript. As you
|
||||
generate code, you create a tree of scopes in the same shape as the nested
|
||||
function bodies. Each scope knows about the variables declared within it,
|
||||
and has a reference to its parent enclosing scope. In this way, we know which
|
||||
variables are new and need to be declared with `var`, and which are shared
|
||||
with external scopes.
|
||||
|
||||
Import the helpers we plan to use.
|
||||
|
||||
{extend, last} = require './helpers'
|
||||
|
||||
exports.Scope = class Scope
|
||||
|
||||
The `root` is the top-level **Scope** object for a given file.
|
||||
|
||||
@root: null
|
||||
|
||||
Initialize a scope with its parent, for lookups up the chain,
|
||||
as well as a reference to the **Block** node it belongs to, which is
|
||||
where it should declare its variables, and a reference to the function that
|
||||
it belongs to.
|
||||
|
||||
constructor: (@parent, @expressions, @method) ->
|
||||
@variables = [{name: 'arguments', type: 'arguments'}]
|
||||
@positions = {}
|
||||
Scope.root = this unless @parent
|
||||
|
||||
Adds a new variable or overrides an existing one.
|
||||
|
||||
add: (name, type, immediate) ->
|
||||
return @parent.add name, type, immediate if @shared and not immediate
|
||||
if Object::hasOwnProperty.call @positions, name
|
||||
@variables[@positions[name]].type = type
|
||||
else
|
||||
@positions[name] = @variables.push({name, type}) - 1
|
||||
|
||||
When `super` is called, we need to find the name of the current method we're
|
||||
in, so that we know how to invoke the same method of the parent class. This
|
||||
can get complicated if super is being called from an inner function.
|
||||
`namedMethod` will walk up the scope tree until it either finds the first
|
||||
function object that has a name filled in, or bottoms out.
|
||||
|
||||
namedMethod: ->
|
||||
return @method if @method.name or !@parent
|
||||
@parent.namedMethod()
|
||||
|
||||
Look up a variable name in lexical scope, and declare it if it does not
|
||||
already exist.
|
||||
|
||||
find: (name) ->
|
||||
return yes if @check name
|
||||
@add name, 'var'
|
||||
no
|
||||
|
||||
Reserve a variable name as originating from a function parameter for this
|
||||
scope. No `var` required for internal references.
|
||||
|
||||
parameter: (name) ->
|
||||
return if @shared and @parent.check name, yes
|
||||
@add name, 'param'
|
||||
|
||||
Just check to see if a variable has already been declared, without reserving,
|
||||
walks up to the root scope.
|
||||
|
||||
check: (name) ->
|
||||
!!(@type(name) or @parent?.check(name))
|
||||
|
||||
Generate a temporary variable name at the given index.
|
||||
|
||||
temporary: (name, index) ->
|
||||
if name.length > 1
|
||||
'_' + name + if index > 1 then index - 1 else ''
|
||||
else
|
||||
'_' + (index + parseInt name, 36).toString(36).replace /\d/g, 'a'
|
||||
|
||||
Gets the type of a variable.
|
||||
|
||||
type: (name) ->
|
||||
return v.type for v in @variables when v.name is name
|
||||
null
|
||||
|
||||
If we need to store an intermediate result, find an available name for a
|
||||
compiler-generated variable. `_var`, `_var2`, and so on...
|
||||
|
||||
freeVariable: (name, reserve=true) ->
|
||||
index = 0
|
||||
index++ while @check((temp = @temporary name, index))
|
||||
@add temp, 'var', yes if reserve
|
||||
temp
|
||||
|
||||
Ensure that an assignment is made at the top of this scope
|
||||
(or at the top-level scope, if requested).
|
||||
|
||||
assign: (name, value) ->
|
||||
@add name, {value, assigned: yes}, yes
|
||||
@hasAssignments = yes
|
||||
|
||||
Does this scope have any declared variables?
|
||||
|
||||
hasDeclarations: ->
|
||||
!!@declaredVariables().length
|
||||
|
||||
Return the list of variables first declared in this scope.
|
||||
|
||||
declaredVariables: ->
|
||||
realVars = []
|
||||
tempVars = []
|
||||
for v in @variables when v.type is 'var'
|
||||
(if v.name.charAt(0) is '_' then tempVars else realVars).push v.name
|
||||
realVars.sort().concat tempVars.sort()
|
||||
|
||||
Return the list of assignments that are supposed to be made at the top
|
||||
of this scope.
|
||||
|
||||
assignedVariables: ->
|
||||
"#{v.name} = #{v.type.value}" for v in @variables when v.type.assigned
|
||||
|
||||
28
samples/Logos/example.xm
Normal file
28
samples/Logos/example.xm
Normal file
@@ -0,0 +1,28 @@
|
||||
%hook ABC
|
||||
- (id)a:(B)b {
|
||||
%log;
|
||||
return %orig(nil);
|
||||
}
|
||||
%end
|
||||
|
||||
%subclass DEF: NSObject
|
||||
- (id)init {
|
||||
[%c(RuntimeAccessibleClass) alloc];
|
||||
return nil;
|
||||
}
|
||||
%end
|
||||
|
||||
%group OptionalHooks
|
||||
%hook ABC
|
||||
- (void)release {
|
||||
[self retain];
|
||||
%orig;
|
||||
}
|
||||
%end
|
||||
%end
|
||||
|
||||
%ctor {
|
||||
%init;
|
||||
if(OptionalCondition)
|
||||
%init(OptionalHooks);
|
||||
}
|
||||
12
samples/Matlab/Check_plot.m
Normal file
12
samples/Matlab/Check_plot.m
Normal file
@@ -0,0 +1,12 @@
|
||||
x_0=linspace(0,100,101);
|
||||
vx_0=linspace(0,100,101);
|
||||
z=zeros(101,101);
|
||||
for i=1:101
|
||||
for j=1:101
|
||||
z(i,j)=x_0(i)*vx_0(j);
|
||||
end
|
||||
end
|
||||
|
||||
figure
|
||||
pcolor(x_0,vx_0,z)
|
||||
shading flat
|
||||
149
samples/Matlab/FTLEH.m
Normal file
149
samples/Matlab/FTLEH.m
Normal file
@@ -0,0 +1,149 @@
|
||||
tic
|
||||
clear all
|
||||
%% Choice of the mass parameter
|
||||
mu=0.1;
|
||||
|
||||
%% Computation of Lagrangian Points
|
||||
[xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu);
|
||||
|
||||
%% Computation of initial total energy
|
||||
E_L1=-Omega(xl1,yl1,mu);
|
||||
E=E_L1+0.03715; % Offset as in figure 2.2 "LCS in the ER3BP"
|
||||
|
||||
%% Initial conditions range
|
||||
x_0_min=-0.8;
|
||||
x_0_max=-0.2;
|
||||
|
||||
vx_0_min=-2;
|
||||
vx_0_max=2;
|
||||
|
||||
y_0=0;
|
||||
|
||||
% Elements for grid definition
|
||||
n=200;
|
||||
|
||||
% Dimensionless integrating time
|
||||
T=2;
|
||||
|
||||
% Grid initializing
|
||||
[x_0,vx_0]=ndgrid(linspace(x_0_min,x_0_max,n),linspace(vx_0_min,vx_0_max,n));
|
||||
vy_0=sqrt(2*E+2*Omega(x_0,y_0,mu)-vx_0.^2);
|
||||
|
||||
% Kinetic energy computation
|
||||
E_cin=E+Omega(x_0,y_0,mu);
|
||||
|
||||
%% Transforming into Hamiltonian variables
|
||||
px_0=vx_0-y_0;
|
||||
py_0=vy_0+x_0;
|
||||
|
||||
% Inizializing
|
||||
x_T=zeros(n,n);
|
||||
y_T=zeros(n,n);
|
||||
px_T=zeros(n,n);
|
||||
py_T=zeros(n,n);
|
||||
filtro=ones(n,n);
|
||||
E_T=zeros(n,n);
|
||||
a=zeros(n,n); % matrix of numbers of integration steps for each integration
|
||||
np=0; % number of integrated points
|
||||
|
||||
fprintf(' con n = %i\n',n)
|
||||
|
||||
%% Energy tolerance setting
|
||||
energy_tol=inf;
|
||||
|
||||
%% Computation of the Jacobian of the system
|
||||
options=odeset('Jacobian',@cr3bp_jac);
|
||||
|
||||
%% Parallel integration of equations of motion
|
||||
parfor i=1:n
|
||||
for j=1:n
|
||||
if E_cin(i,j)>0 && isreal(vy_0(i,j)) % Check for real velocity and positive Kinetic energy
|
||||
[t,Y]=ode45(@fH,[0 T],[x_0(i,j); y_0; px_0(i,j); py_0(i,j)],options);
|
||||
% Try to obtain the name of the solver for a following use
|
||||
% sol=ode45(@f,[0 T],[x_0(i,j); y_0; vx_0(i,j); vy_0(i,j)],options);
|
||||
% Y=sol.y';
|
||||
% solver=sol.solver;
|
||||
a(i,j)=length(Y);
|
||||
%Saving solutions
|
||||
x_T(i,j)=Y(a(i,j),1);
|
||||
px_T(i,j)=Y(a(i,j),3);
|
||||
y_T(i,j)=Y(a(i,j),2);
|
||||
py_T(i,j)=Y(a(i,j),4);
|
||||
%Computation of final total energy and difference with
|
||||
%initial one
|
||||
E_T(i,j)=EnergyH(x_T(i,j),y_T(i,j),px_T(i,j),py_T(i,j),mu);
|
||||
delta_E=abs(E_T(i,j)-E);
|
||||
if delta_E > energy_tol; %Check of total energy conservation
|
||||
fprintf(' Ouch! Wrong Integration: i,j=(%i,%i)\n E_T=%.2f \n delta_E=%.2f\n\n',i,j,E_T(i,j),delta_E);
|
||||
filtro(i,j)=2; %Saving position of the point
|
||||
end
|
||||
np=np+1;
|
||||
else
|
||||
filtro(i,j)=0; % 1=interesting point; 0=non-sense point; 2= bad integration point
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
t_integrazione=toc;
|
||||
fprintf(' n = %i\n',n)
|
||||
fprintf(' energy_tol = %.2f\n',energy_tol)
|
||||
fprintf('total \t%i\n',n^2)
|
||||
fprintf('nunber \t%i\n',np)
|
||||
fprintf('time to integrate \t%.2f s\n',t_integr)
|
||||
|
||||
%% Back to Lagrangian variables
|
||||
vx_T=px_T+y_T;
|
||||
vy_T=py_T-x_T;
|
||||
%% FTLE Computation
|
||||
fprintf('adesso calcolo ftle\n')
|
||||
tic
|
||||
dphi=zeros(2,2);
|
||||
ftle=zeros(n-2,n-2);
|
||||
|
||||
for i=2:n-1
|
||||
for j=2:n-1
|
||||
if filtro(i,j) && ... % Check for interesting point
|
||||
filtro(i,j-1) && ...
|
||||
filtro(i,j+1) && ...
|
||||
filtro(i-1,j) && ...
|
||||
filtro(i+1,j)
|
||||
|
||||
dphi(1,1)=(x_T(i-1,j)-x_T(i+1,j))/(x_0(i-1,j)-x_0(i+1,j));
|
||||
|
||||
dphi(1,2)=(x_T(i,j-1)-x_T(i,j+1))/(vx_0(i,j-1)-vx_0(i,j+1));
|
||||
|
||||
dphi(2,1)=(vx_T(i-1,j)-vx_T(i+1,j))/(x_0(i-1,j)-x_0(i+1,j));
|
||||
|
||||
dphi(2,2)=(vx_T(i,j-1)-vx_T(i,j+1))/(vx_0(i,j-1)-vx_0(i,j+1));
|
||||
|
||||
if filtro(i,j)==2 % Manual setting to visualize bad integrated points
|
||||
ftle(i-1,j-1)=-Inf;
|
||||
else
|
||||
ftle(i-1,j-1)=1/(2*T)*log(max(abs(eig(dphi'*dphi))));
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Plotting results
|
||||
% figure
|
||||
% plot(t,Y)
|
||||
% figure
|
||||
% plot(Y(:,1),Y(:,2))
|
||||
% figure
|
||||
|
||||
xx=linspace(x_0_min,x_0_max,n);
|
||||
vvx=linspace(vx_0_min,vx_0_max,n);
|
||||
[x,vx]=ndgrid(xx(2:n-1),vvx(2:n-1));
|
||||
figure
|
||||
pcolor(x,vx,ftle)
|
||||
shading flat
|
||||
|
||||
t_ftle=toc;
|
||||
fprintf('tempo per integrare \t%.2f s\n',t_integrazione)
|
||||
fprintf('tempo per calcolare ftle \t%.2f s\n',t_ftle)
|
||||
|
||||
% save(['var_' num2str(n) '_' num2str(clock(4)])
|
||||
|
||||
nome=['var_xvx_', 'ode00', '_n',num2str(n),'_e',num2str(energy_tol),'_H'];
|
||||
save(nome)
|
||||
178
samples/Matlab/FTLE_reg.m
Normal file
178
samples/Matlab/FTLE_reg.m
Normal file
@@ -0,0 +1,178 @@
|
||||
tic
|
||||
clear all
|
||||
%% Elements for grid definition
|
||||
n=100;
|
||||
|
||||
%% Dimensionless integrating time
|
||||
T=2;
|
||||
|
||||
%% Choice of the mass parameter
|
||||
mu=0.1;
|
||||
|
||||
%% Computation of Lagrangian Points
|
||||
[xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu);
|
||||
|
||||
%% Computation of initial total energy
|
||||
E_L1=-Omega(xl1,yl1,mu);
|
||||
C_L1=-2*E_L1; % C_L1 = 3.6869532299 from Szebehely
|
||||
E=E_L1+0.03715; % Offset as in figure 2.2 "LCS in the ER3BP"
|
||||
|
||||
%% Initial conditions range
|
||||
x_0_min=-0.8;
|
||||
x_0_max=-0.2;
|
||||
|
||||
vx_0_min=-2;
|
||||
vx_0_max=2;
|
||||
|
||||
y_0=0;
|
||||
|
||||
% Grid initializing
|
||||
[x_0,vx_0]=ndgrid(linspace(x_0_min,x_0_max,n),linspace(vx_0_min,vx_0_max,n));
|
||||
vy_0=sqrt(2*E+2.*Omega(x_0,y_0,mu)-vx_0.^2);
|
||||
% Kinetic energy computation
|
||||
E_cin=E+Omega(x_0,y_0,mu);
|
||||
|
||||
% Inizializing
|
||||
x_T=zeros(n,n);
|
||||
y_T=zeros(n,n);
|
||||
vx_T=zeros(n,n);
|
||||
vy_T=zeros(n,n);
|
||||
filtro=ones(n,n);
|
||||
E_T=zeros(n,n);
|
||||
delta_E=zeros(n,n);
|
||||
a=zeros(n,n); % matrix of numbers of integration steps for each integration
|
||||
np=0; % number of integrated points
|
||||
|
||||
fprintf('integro con n = %i\n',n)
|
||||
|
||||
%% Energy tolerance setting
|
||||
energy_tol=0.1;
|
||||
|
||||
%% Setting the options for the integrator
|
||||
RelTol=1e-12;AbsTol=1e-12; % From Short
|
||||
% RelTol=1e-13;AbsTol=1e-22; % From JD James Mireles
|
||||
% RelTol=3e-14;AbsTol=1e-16; % HIGH accuracy from Ross
|
||||
options=odeset('AbsTol',AbsTol,'RelTol',RelTol);
|
||||
%% Parallel integration of equations of motion
|
||||
h=waitbar(0,'','Name','Integration in progress, please wait!');
|
||||
S=zeros(n,n);
|
||||
r1=zeros(n,n);
|
||||
r2=zeros(n,n);
|
||||
g=zeros(n,n);
|
||||
for i=1:n
|
||||
waitbar(i/n,h,sprintf('Computing i=%i',i));
|
||||
parfor j=1:n
|
||||
r1(i,j)=sqrt((x_0(i,j)+mu).^2+y_0.^2);
|
||||
r2(i,j)=sqrt((x_0(i,j)-1+mu).^2+y_0.^2);
|
||||
g(i,j)=((1-mu)./(r1(i,j).^3)+mu./(r2(i,j).^3));
|
||||
if E_cin(i,j)>0 && isreal(vy_0(i,j)) % Check for real velocity and positive Kinetic energy
|
||||
S(i,j)=g(i,j)*T;
|
||||
[s,Y]=ode45(@f_reg,[0 S(i,j)],[x_0(i,j); y_0; vx_0(i,j); vy_0(i,j)],options,mu);
|
||||
a(i,j)=length(Y);
|
||||
% if s(a(i,j)) < 2
|
||||
% filtro(i,j)=3;
|
||||
% end
|
||||
% Saving solutions
|
||||
x_T(i,j)=Y(a(i,j),1);
|
||||
vx_T(i,j)=Y(a(i,j),3);
|
||||
y_T(i,j)=Y(a(i,j),2);
|
||||
vy_T(i,j)=Y(a(i,j),4);
|
||||
|
||||
% Computation of final total energy and difference with
|
||||
% initial one
|
||||
E_T(i,j)=Energy(x_T(i,j),y_T(i,j),vx_T(i,j),vy_T(i,j),mu);
|
||||
delta_E(i,j)=abs(E_T(i,j)-E);
|
||||
if delta_E(i,j) > energy_tol; % Check of total energy conservation
|
||||
fprintf(' Ouch! Wrong Integration: i,j=(%i,%i)\n E_T=%.2f \n delta_E=%f\n\n',i,j,E_T(i,j),delta_E(i,j));
|
||||
filtro(i,j)=2; % Saving position of the point
|
||||
end
|
||||
np=np+1;
|
||||
else
|
||||
filtro(i,j)=0; % 1 = interesting point; 0 = non-sense point; 2 = bad integration point
|
||||
end
|
||||
end
|
||||
end
|
||||
close(h);
|
||||
t_integrazione=toc;
|
||||
%%
|
||||
filtro_1=filtro;
|
||||
for i=2:n-1
|
||||
for j=2:n-1
|
||||
if filtro(i,j)==2 || filtro (i,j)==3
|
||||
filtro_1(i,j)=2;
|
||||
filtro_1(i+1,j)=2;
|
||||
filtro_1(i-1,j)=2;
|
||||
filtro_1(i,j+1)=2;
|
||||
filtro_1(i,j-1)=2;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fprintf('integato con n = %i\n',n)
|
||||
fprintf('integato con energy_tol = %f\n',energy_tol)
|
||||
fprintf('numero punti totali \t%i\n',n^2)
|
||||
fprintf('numero punti integrati \t%i\n',np)
|
||||
fprintf('tempo per integrare \t%.2f s\n',t_integrazione)
|
||||
|
||||
%% FTLE Computation
|
||||
fprintf('adesso calcolo ftle\n')
|
||||
tic
|
||||
dphi=zeros(2,2);
|
||||
ftle=zeros(n-2,n-2);
|
||||
ftle_norm=zeros(n-2,n-2);
|
||||
|
||||
ds_x=(x_0_max-x_0_min)/(n-1);
|
||||
ds_vx=(vx_0_max-vx_0_min)/(n-1);
|
||||
|
||||
for i=2:n-1
|
||||
for j=2:n-1
|
||||
if filtro_1(i,j) && ... % Check for interesting point
|
||||
filtro_1(i,j-1) && ...
|
||||
filtro_1(i,j+1) && ...
|
||||
filtro_1(i-1,j) && ...
|
||||
filtro_1(i+1,j)
|
||||
% La direzione dello spostamento la decide il denominatore
|
||||
|
||||
% TODO spiegarsi teoricamente come mai la matrice pu<EFBFBD>
|
||||
% essere ridotta a 2x2
|
||||
dphi(1,1)=(x_T(i+1,j)-x_T(i-1,j))/(2*ds_x); %(x_0(i-1,j)-x_0(i+1,j));
|
||||
|
||||
dphi(1,2)=(x_T(i,j+1)-x_T(i,j-1))/(2*ds_vx); %(vx_0(i,j-1)-vx_0(i,j+1));
|
||||
|
||||
dphi(2,1)=(vx_T(i+1,j)-vx_T(i-1,j))/(2*ds_x); %(x_0(i-1,j)-x_0(i+1,j));
|
||||
|
||||
dphi(2,2)=(vx_T(i,j+1)-vx_T(i,j-1))/(2*ds_vx); %(vx_0(i,j-1)-vx_0(i,j+1));
|
||||
|
||||
if filtro_1(i,j)==2 % Manual setting to visualize bad integrated points
|
||||
ftle(i-1,j-1)=0;
|
||||
else
|
||||
ftle(i-1,j-1)=(1/abs(T))*log(max(sqrt(abs(eig(dphi*dphi')))));
|
||||
ftle_norm(i-1,j-1)=(1/abs(T))*log(norm(dphi));
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Plotting results
|
||||
% figure
|
||||
% plot(t,Y)
|
||||
% figure
|
||||
% plot(Y(:,1),Y(:,2))
|
||||
% figure
|
||||
|
||||
xx=linspace(x_0_min,x_0_max,n);
|
||||
vvx=linspace(vx_0_min,vx_0_max,n);
|
||||
[x,vx]=ndgrid(xx(2:n-1),vvx(2:n-1));
|
||||
figure
|
||||
pcolor(x,vx,ftle)
|
||||
shading flat
|
||||
|
||||
t_ftle=toc;
|
||||
fprintf('tempo per integrare \t%.2f s\n',t_integrazione)
|
||||
fprintf('tempo per calcolare ftle \t%.2f s\n',t_ftle)
|
||||
|
||||
% ora=fstringf %TODO
|
||||
% save(['var_' num2str(n) '_' num2str(clock(4)])
|
||||
|
||||
nome=['var_xvx_', 'ode00', '_n',num2str(n)];
|
||||
save(nome)
|
||||
40
samples/Matlab/Integrate1.m
Normal file
40
samples/Matlab/Integrate1.m
Normal file
@@ -0,0 +1,40 @@
|
||||
function [ x_T, y_T, vx_T, e_T, filter ] = Integrate_FILE( x_0, y_0, vx_0, e_0, T, N, mu, options)
|
||||
%Integrate
|
||||
% This function performs Runge-Kutta-Fehlberg integration for given
|
||||
% initial conditions to compute FILE
|
||||
nx=length(x_0);
|
||||
ny=length(y_0);
|
||||
nvx=length(vx_0);
|
||||
ne=length(e_0);
|
||||
vy_0=zeros(nx,ny,nvx,ne);
|
||||
x_T=zeros(nx,ny,nvx,ne);
|
||||
y_T=zeros(nx,ny,nvx,ne);
|
||||
vx_T=zeros(nx,ny,nvx,ne);
|
||||
vy_T=zeros(nx,ny,nvx,ne);
|
||||
e_T=zeros(nx,ny,nvx,ne);
|
||||
%% Look for phisically meaningful points
|
||||
filter=zeros(nx,ny,nvx,ne); %0=meaningless point 1=meaningful point
|
||||
|
||||
%% Integrate only meaningful points
|
||||
h=waitbar(0,'','Name','Integration in progress, please wait!');
|
||||
for i=1:nx
|
||||
waitbar(i/nx,h,sprintf('Computing i=%i',i));
|
||||
for j=1:ny
|
||||
parfor k=1:nvx
|
||||
for l=1:ne
|
||||
vy_0(i,j,k,l)=sqrt(2*Potential(x_0(i),y_0(j),mu)+2*e_0(l)-vx_0(k)^2);
|
||||
if isreal(vy_0(i,j,k,l))
|
||||
filter(i,j,k,l)=1;
|
||||
ci=[x_0(i), y_0(j), vx_0(k), vy_0(i,j,k,l)];
|
||||
[t,Y,te,ye,ie]=ode45(@f,[0 T], ci, options, mu);
|
||||
x_T(i,j,k,l)=ye(N+1,1);
|
||||
y_T(i,j,k,l)=ye(N+1,2);
|
||||
vx_T(i,j,k,l)=ye(N+1,3);
|
||||
vy_T(i,j,k,l)=ye(N+1,4);
|
||||
e_T(i,j,k,l)=0.5*(vx_T(i,j,k,l)^2+vy_T(i,j,k,l)^2)-Potential(x_T(i,j,k,l),y_T(i,j,k,l),mu);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
close(h);
|
||||
60
samples/Matlab/Integrate2.m
Normal file
60
samples/Matlab/Integrate2.m
Normal file
@@ -0,0 +1,60 @@
|
||||
function [ x_T, y_T, vx_T, e_T, filter, delta_e ] = Integrate_FTLE_Gawlick_ell( x_0, y_0, vx_0, e_0, T, mu, ecc, nu, options)
|
||||
%Integrate
|
||||
% This function performs Runge-Kutta-Fehlberg integration for given
|
||||
% initial conditions to compute FTLE to obtain the image in the Gawlick's
|
||||
% article "Lagrangian Coherent Structures in the Elliptic Restricted
|
||||
% Three-Body Problem".
|
||||
nx=length(x_0);
|
||||
ny=length(y_0);
|
||||
nvx=length(vx_0);
|
||||
ne=length(e_0);
|
||||
vy_0=zeros(nx,ny,nvx,ne);
|
||||
x_T=zeros(nx,ny,nvx,ne);
|
||||
y_T=zeros(nx,ny,nvx,ne);
|
||||
vx_T=zeros(nx,ny,nvx,ne);
|
||||
vy_T=zeros(nx,ny,nvx,ne);
|
||||
e_T=zeros(nx,ny,nvx,ne);
|
||||
delta_e=zeros(nx,ny,nvx,ne);
|
||||
%% Look for phisically meaningful points
|
||||
filter=zeros(nx,ny,nvx,ne); %0=meaningless point 1=meaningful point
|
||||
useful=ones(nx,ny,nvx,ne);
|
||||
%% Integrate only useful points
|
||||
useful(:,1,:,1)=0;
|
||||
useful(:,1,:,3)=0;
|
||||
useful(:,3,:,1)=0;
|
||||
useful(:,3,:,3)=0;
|
||||
|
||||
%% Integrate only meaningful points
|
||||
h=waitbar(0,'','Name','Integration in progress, please wait!');
|
||||
for i=1:nx
|
||||
waitbar(i/nx,h,sprintf('Computing i=%i',i));
|
||||
for j=1:ny
|
||||
parfor k=1:nvx
|
||||
for l=1:ne
|
||||
if useful(i,j,k,l)
|
||||
vy_0(i,j,k,l)=-sqrt(2*(Omega(x_0(i),y_0(j),mu)/(1+ecc*cos(nu)))+2*e_0(l)-vx_0(k)^2);
|
||||
if isreal(vy_0(i,j,k,l))
|
||||
filter(i,j,k,l)=1;
|
||||
|
||||
ci=[x_0(i), y_0(j), vx_0(k), vy_0(i,j,k,l)];
|
||||
[t,Y]=ode45(@f_ell,[0 T], ci, options, mu, ecc);
|
||||
|
||||
if abs(t(end)) < abs(T) % Consider also negative time
|
||||
filter(i,j,k,l)=3
|
||||
end
|
||||
|
||||
x_T(i,j,k,l)=Y(end,1);
|
||||
y_T(i,j,k,l)=Y(end,2);
|
||||
vx_T(i,j,k,l)=Y(end,3);
|
||||
vy_T(i,j,k,l)=Y(end,4);
|
||||
e_T(i,j,k,l)=0.5*(vx_T(i,j,k,l)^2+vy_T(i,j,k,l)^2)-Omega(x_T(i,j,k,l),y_T(i,j,k,l),mu);
|
||||
|
||||
% Compute the goodness of the integration
|
||||
delta_e(i,j,k,l)=abs(e_T(i,j,k,l)-e_0(l));
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
close(h);
|
||||
28
samples/Matlab/Lagr.m
Normal file
28
samples/Matlab/Lagr.m
Normal file
@@ -0,0 +1,28 @@
|
||||
function [xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu)
|
||||
% [xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu)
|
||||
% Lagr This function computes the coordinates of the Lagrangian points,
|
||||
% given the mass parameter
|
||||
yl1=0;
|
||||
yl2=0;
|
||||
yl3=0;
|
||||
yl4=sqrt(3)/2;
|
||||
yl5=-sqrt(3)/2;
|
||||
c1=roots([1 mu-3 3-2*mu -mu 2*mu -mu]);
|
||||
c2=roots([1 3-mu 3-2*mu -mu -2*mu -mu]);
|
||||
c3=roots([1 2+mu 1+2*mu mu-1 2*mu-2 mu-1]);
|
||||
xl1=0;
|
||||
xl2=0;
|
||||
for i=1:5
|
||||
if isreal(c1(i))
|
||||
xl1=1-mu-c1(i);
|
||||
end
|
||||
if isreal(c2(i))
|
||||
xl2=1-mu+c2(i);
|
||||
end
|
||||
if isreal(c3(i))
|
||||
xl3=-mu-c3(i);
|
||||
end
|
||||
end
|
||||
xl4=0.5-mu;
|
||||
xl5=xl4;
|
||||
end
|
||||
16
samples/Matlab/Lagrangian_points.m
Normal file
16
samples/Matlab/Lagrangian_points.m
Normal file
@@ -0,0 +1,16 @@
|
||||
% Plot dei Lagrangian points
|
||||
n=5;
|
||||
mu=linspace(0,0.5,n);
|
||||
for i=1:n
|
||||
[xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu(i));
|
||||
figure (1)
|
||||
hold all
|
||||
plot(xl1, yl1, 's')
|
||||
plot(xl2, yl2, 's')
|
||||
plot(xl3, yl3, 's')
|
||||
plot(xl4, yl4, 's')
|
||||
plot(xl5, yl5, 's')
|
||||
plot(-mu,0,'o')
|
||||
plot(1-mu,0, 'o')
|
||||
plot([-mu(i) xl4],[0 yl4])
|
||||
end
|
||||
18
samples/Matlab/Poincare.m
Normal file
18
samples/Matlab/Poincare.m
Normal file
@@ -0,0 +1,18 @@
|
||||
clear
|
||||
%% Initial Conditions
|
||||
mu=0.012277471;
|
||||
T=10;
|
||||
N=5;
|
||||
C=3.17;
|
||||
x_0=0.30910452642073;
|
||||
y_0=0.07738174525518;
|
||||
vx_0=-0.72560796964234;
|
||||
vy_0=sqrt(-C-vx_0^2+2*Potential(x_0,y_0,mu));
|
||||
k=0;
|
||||
%% Integration
|
||||
options=odeset('AbsTol',1e-22,'RelTol',1e-13,'Events',@cross_y);
|
||||
[t,y,te,ye,ie]=ode113(@f,[0 T],[x_0; y_0; vx_0; vy_0],options,mu);
|
||||
|
||||
figure
|
||||
%plot(ye(:,1),ye(:,3),'rs')
|
||||
plot(ye(:,1),0,'rs')
|
||||
24
samples/Matlab/RK4.m
Normal file
24
samples/Matlab/RK4.m
Normal file
@@ -0,0 +1,24 @@
|
||||
function x = RK4( fun, tspan, ci, mu )
|
||||
%RK4 4th-order Runge Kutta integrator
|
||||
% Detailed explanation goes here
|
||||
h=1e-5;
|
||||
t=tspan(1);
|
||||
T=tspan(length(tspan));
|
||||
dim=length(ci);
|
||||
%x=zeros(l,dim);
|
||||
x(:,1)=ci;
|
||||
i=1;
|
||||
while t<T
|
||||
k1=fun(t,x(:,i),mu);
|
||||
k2=fun(t+h/2,x(:,i)+k1*h/2,mu);
|
||||
k3=fun(t+h/2,x(:,i)+k2*h/2,mu);
|
||||
k4=fun(t+h,x(:,i)+h*k3,mu);
|
||||
x(:,i+1)=x(:,i)+(h/6*(k1+2*k2+2*k3+k4));
|
||||
t=t+h;
|
||||
i=i+1;
|
||||
end
|
||||
x=x';
|
||||
% function events(x)
|
||||
% dist=
|
||||
% return
|
||||
end
|
||||
54
samples/Matlab/Traj.m
Normal file
54
samples/Matlab/Traj.m
Normal file
@@ -0,0 +1,54 @@
|
||||
clear all
|
||||
%mu=0.012151; %Earth-Moon
|
||||
mu=0.012277471 %Earth-Moon
|
||||
[xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5] = Lagr(mu);
|
||||
C=3.17;
|
||||
%C=2*Potential(xl1,yl1,mu);
|
||||
x_0=1;
|
||||
y_0=0;
|
||||
vx_0=0;
|
||||
vy_0=sqrt(-C-vx_0^2+2*Potential(x_0,y_0,mu));
|
||||
%vy_0=0;
|
||||
T=2;
|
||||
C_star=2*Potential(x_0,y_0,mu)-(vx_0^2+vy_0^2)
|
||||
%C=-(vx_0^2+vy_0^2)+2*Omega(x_0,y_0,mu);
|
||||
E=-C/2;
|
||||
|
||||
options=odeset('AbsTol',1e-22,'RelTol',1e-13);
|
||||
|
||||
%Integrate first orbit
|
||||
[t0,Y0]=ode113(@f,[0 T],[x_0; y_0; vx_0; vy_0],options,mu);
|
||||
x0=Y0(:,1);
|
||||
y0=Y0(:,2);
|
||||
vx0=Y0(:,3);
|
||||
vy0=Y0(:,4);
|
||||
l0=length(Y0);
|
||||
|
||||
% Precisionfirst orbit
|
||||
delta_E0=abs(Energy(x0,y0,vx0,vy0,mu)-E);
|
||||
|
||||
% figure
|
||||
% plot(delta_E0)
|
||||
|
||||
%Hill's region
|
||||
points=500;
|
||||
bb=3; % Bounding box
|
||||
x=linspace(-bb,bb,points);
|
||||
y=linspace(-bb,bb,points);
|
||||
[x,y]=meshgrid(x,y);
|
||||
z=(Potential(x,y,mu));
|
||||
% figure
|
||||
% surfc(x,y,z,'Edgecolor','none')
|
||||
|
||||
%Plot orbit
|
||||
%figure
|
||||
hold on
|
||||
contour(x,y,z,[C/2,C/2])
|
||||
plot(x0,y0)
|
||||
text(-2,-2,sprintf('C=%.2f',C))
|
||||
%plotto actractors
|
||||
plot(-mu,0,'ok')
|
||||
plot(1-mu,0,'ok')
|
||||
% Plot points
|
||||
plot(x0(1),y0(1),'sg')
|
||||
plot(x0(l0),y0(l0),'sr')
|
||||
74
samples/Matlab/adapting_structural_model.m
Normal file
74
samples/Matlab/adapting_structural_model.m
Normal file
@@ -0,0 +1,74 @@
|
||||
function [dx, y] = adapting_structural_model(t, x, u, varargin)
|
||||
%
|
||||
% Returns the time derivatives of the states and the output of the
|
||||
% structural control model with an adapting controller.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% t : double
|
||||
% The current time.
|
||||
% x : double, size(8, 1)
|
||||
% The current state.
|
||||
% u : double, size(1, 1)
|
||||
% The current input.
|
||||
% varargin : cell array
|
||||
% m1, m2, m3, m4, b1, b2, b3, b4 : double
|
||||
% The slope of the four gains and the offset of the four gains.
|
||||
% aux : cell array containing a single structure
|
||||
% The structure contains:
|
||||
% pars : double, size(1,9)
|
||||
% The controller parameters.
|
||||
% timeDelay : logical
|
||||
% If true a 1st order Pade approximation of the human's time delay
|
||||
% is included.
|
||||
% plantFirst : integer
|
||||
% The number of the first plant.
|
||||
% plantSecond : integer
|
||||
% The number of the second plant.
|
||||
% m : double, size(2, 1)
|
||||
% The slope of the transfer function adaption function.
|
||||
% b : double, size(2, 1)
|
||||
% The offset of the transfer function adaption function.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% dx : double, size(8, 1)
|
||||
% The derivatives of the states.
|
||||
% y : double, size(1, 1)
|
||||
% The output, theta.
|
||||
|
||||
% MATLAB SUCKS! This is unbelievable. On the first iteration varargin is 1x2
|
||||
% and after that it is 1x9.
|
||||
%size(varargin, 2)
|
||||
|
||||
% Unpack varargin.
|
||||
aux = varargin{end}{1};
|
||||
m = zeros(4, 1);
|
||||
b = zeros(4, 1);
|
||||
for i=1:4
|
||||
if size(varargin, 2) == 2
|
||||
m(i) = varargin{1}(i);
|
||||
b(i) = varargin{1}(i + 4);
|
||||
elseif size(varargin, 2) == 9
|
||||
m(i) = varargin{i};
|
||||
b(i) = varargin{i + 4};
|
||||
else
|
||||
display('Matlab is stupid.')
|
||||
end
|
||||
end
|
||||
|
||||
% First compute the gains at this time.
|
||||
aux.pars(1:4) = m .* t + b;
|
||||
% Compute the controller.
|
||||
Yp = human(aux.pars, aux.timeDelay);
|
||||
% Compute the plant and this time.
|
||||
c1 = aux.m(1) * t + aux.b(1) + 1e-10;
|
||||
c2 = aux.m(2) * t + aux.b(2) + 1e-10;
|
||||
Yc = parallel(c1 * plant(aux.plantFirst), c2 * plant(aux.plantSecond));
|
||||
% Compute the closed loop system.
|
||||
Ys = feedback(Yp * Yc, 1);
|
||||
% Convert to state space.
|
||||
[A, B, C, D] = tf2ss(Ys.num{1}, Ys.den{1});
|
||||
% Compute the derivatives of the states and the outputs.
|
||||
dx = A * x + B * u;
|
||||
y = C * x + D * u;
|
||||
168
samples/Matlab/bicycle_state_space.m
Normal file
168
samples/Matlab/bicycle_state_space.m
Normal file
@@ -0,0 +1,168 @@
|
||||
function bicycle = bicycle_state_space(bicycle, speed, varargin)
|
||||
% function bicycle = bicycle_state_space(bicycle, speed, varargin)
|
||||
%
|
||||
% Returns the state space system of the Whipple model linearized about the
|
||||
% nominal configuration and the supplied speed.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% bicycle : char
|
||||
% The name of a bicycle in the parameters directory.
|
||||
% speed : double
|
||||
% The forward speed at which to linearize the model about.
|
||||
% varargin : char/cell array pairs, optional
|
||||
% Specify a subset of states, inputs or outputs by setting one of the
|
||||
% following: `states`, `inputs`, `outputs` as a cell array of
|
||||
% chars which include the subset variable names. Beaware that not all
|
||||
% state, input and output combinations are necessarily possible.
|
||||
% Valid state names: 'xP', 'yP', 'psi', 'phi', 'thetaB', 'thetaR', 'delta',
|
||||
% 'thetaF', 'phiDot', 'thetaRDot', 'deltaDot'
|
||||
% Valid input names: 'tPhi', 'tDelta', 'fB'
|
||||
% Valid output names: 'xP', 'yP', 'psi', 'phi', 'thetaB', 'thetaR', 'delta',
|
||||
% 'thetaF', 'xPDot', 'yPDot', 'psiDot', 'phiDot', 'thetaBDot',
|
||||
% 'thetaRDot', 'deltaDot', 'thetaFDot', 'xQ', 'yQ'
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% bicycle : ss
|
||||
% The state space model of the bicycle.
|
||||
%
|
||||
% Notes
|
||||
% -----
|
||||
% The variable names are defined as in Meijaard2007.
|
||||
%
|
||||
% Examples
|
||||
% --------
|
||||
% bicycle = bicycle_state_space('Benchmark', 5.0, ...
|
||||
% 'states', {'phi', 'phiDot', 'delta', 'deltaDot'}, ...
|
||||
% 'inputs', {'tDelta'}, ...
|
||||
% 'outputs', {'delta', 'phi'})
|
||||
|
||||
% get the directory which this m-file is in
|
||||
S = dbstack('-completenames');
|
||||
[CURRENT_DIRECTORY, ~, ~] = fileparts(S(1).file);
|
||||
|
||||
% load the paramaters
|
||||
par = par_text_to_struct([CURRENT_DIRECTORY filesep 'parameters' ...
|
||||
filesep bicycle 'Par.txt']);
|
||||
|
||||
% generate the state space matrices
|
||||
[A, B, C, D] = whipple_pull_force_abcd(par, speed);
|
||||
|
||||
% name the states, outputs and inputs
|
||||
states = {'xP',
|
||||
'yP',
|
||||
'psi',
|
||||
'phi',
|
||||
'thetaB',
|
||||
'thetaR',
|
||||
'delta',
|
||||
'thetaF',
|
||||
'phiDot',
|
||||
'thetaRDot',
|
||||
'deltaDot'};
|
||||
|
||||
outputs = {'xP',
|
||||
'yP',
|
||||
'psi',
|
||||
'phi',
|
||||
'thetaB',
|
||||
'thetaR',
|
||||
'delta',
|
||||
'thetaF',
|
||||
'xPDot',
|
||||
'yPDot',
|
||||
'psiDot',
|
||||
'phiDot',
|
||||
'thetaBDot',
|
||||
'thetaRDot',
|
||||
'deltaDot',
|
||||
'thetaFDot',
|
||||
'xQ',
|
||||
'yQ'};
|
||||
|
||||
inputs = {'tPhi',
|
||||
'tDelta',
|
||||
'fB'};
|
||||
|
||||
defaultSettings.states = states;
|
||||
defaultSettings.inputs = inputs;
|
||||
defaultSettings.outputs = outputs;
|
||||
% load in user supplied settings
|
||||
if size(varargin, 2) >= 1
|
||||
userSettings = varargin_to_structure(varargin);
|
||||
else
|
||||
userSettings = struct();
|
||||
end
|
||||
% combine the defaults with the user settings
|
||||
settings = overwrite_settings(defaultSettings, userSettings);
|
||||
|
||||
% Will the system have the bare minimum states?
|
||||
minStates = {'phi', 'delta', 'phiDot', 'deltaDot'};
|
||||
if sum(ismember(settings.states, minStates)) < 4
|
||||
error(['You have not specified the minimum set of states. Please ' ...
|
||||
'include at least phi, delta, phiDot, and deltaDot'])
|
||||
end
|
||||
|
||||
% Have state derivatives been specified that can't be computed with the
|
||||
% specified states?
|
||||
keepStates = find(ismember(states, settings.states));
|
||||
removeStates = find(~ismember(states, settings.states));
|
||||
for row = keepStates'
|
||||
for col = removeStates'
|
||||
if abs(A(row, col)) > 1e-10
|
||||
s = sprintf(['It is not possible to compute the derivative ' ...
|
||||
'of state %s because it depends on state %s'], ...
|
||||
states{row}, states{col});
|
||||
error(s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
removeInputs = find(~ismember(inputs, settings.inputs));
|
||||
|
||||
% Have outputs been specified that can't be computed with the specified
|
||||
% states and inputs?
|
||||
keepOutputs = find(ismember(outputs, settings.outputs));
|
||||
for row = keepOutputs'
|
||||
for col = removeStates'
|
||||
if abs(C(row, col)) > 1e-10
|
||||
s = sprintf(['It is not possible to keep output %s because ' ...
|
||||
'it depends on state %s'], outputs{row}, ...
|
||||
states{col});
|
||||
error(s)
|
||||
end
|
||||
end
|
||||
for col = removeInputs'
|
||||
if abs(D(row, col)) > 1e-10
|
||||
s = sprintf(['It is not possible to keep output %s because ' ...
|
||||
'it depends on input %s'], outputs{row}, ...
|
||||
inputs{col});
|
||||
error(s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
removeOutputs = find(~ismember(outputs, settings.outputs));
|
||||
|
||||
A(removeStates, :) = [];
|
||||
A(:, removeStates) = [];
|
||||
|
||||
B(removeStates, :) = [];
|
||||
B(:, removeInputs) = [];
|
||||
|
||||
C(removeOutputs, :) = [];
|
||||
C(:, removeStates) = [];
|
||||
|
||||
D(removeOutputs, :) = [];
|
||||
D(:, removeInputs) = [];
|
||||
|
||||
states(removeStates) = [];
|
||||
inputs(removeInputs) = [];
|
||||
outputs(removeOutputs) = [];
|
||||
|
||||
% build the ss structure
|
||||
bicycle = ss(A, B, C, D, ...
|
||||
'StateName', states, ...
|
||||
'OutputName', outputs, ...
|
||||
'InputName', inputs);
|
||||
68
samples/Matlab/convert_variable.m
Normal file
68
samples/Matlab/convert_variable.m
Normal file
@@ -0,0 +1,68 @@
|
||||
function [name, order] = convert_variable(variable, output)
|
||||
% Returns the name and order of the given variable in the output type.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% variable : string
|
||||
% A variable name.
|
||||
% output : string.
|
||||
% Either `moore`, `meijaard`, `data`.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% name : string
|
||||
% The variable name in the given output type.
|
||||
% order : double
|
||||
% The order of the variable in the list.
|
||||
|
||||
[coordinates, speeds, inputs] = get_variables();
|
||||
|
||||
columns = {'data', 'meijaard', 'moore'};
|
||||
|
||||
if find(ismember(coordinates, variable))
|
||||
|
||||
[order, ~] = find(ismember(coordinates, variable));
|
||||
name = coordinates{order, find(ismember(columns, output))};
|
||||
|
||||
elseif find(ismember(speeds, variable))
|
||||
|
||||
[order, ~] = find(ismember(speeds, variable));
|
||||
name = speeds{order, find(ismember(columns, output))};
|
||||
|
||||
elseif find(ismember(inputs, variable))
|
||||
|
||||
[order, ~] = find(ismember(inputs, variable));
|
||||
name = inputs{order, find(ismember(columns, output))};
|
||||
|
||||
else
|
||||
error('Beep: Done typed yo variable name wrong')
|
||||
end
|
||||
|
||||
function [coordinates, speeds, inputs] = get_variables()
|
||||
|
||||
coordinates = {'LongitudinalRearContact', 'xP', 'q1';
|
||||
'LateralRearContact', 'yP','q2';
|
||||
'YawAngle', 'psi','q3';
|
||||
'RollAngle', 'phi','q4';
|
||||
'PitchAngle', 'thetaB','q5';
|
||||
'RearWheelAngle', 'thetaR','q6';
|
||||
'SteerAngle', 'delta','q7';
|
||||
'FrontWheelAngle', 'thetaF','q8';
|
||||
'LongitudinalFrontContact', 'xQ','q9';
|
||||
'LateralFrontContact', 'yQ', 'q10'};
|
||||
|
||||
speeds = {'LongitudinalRearContactRate', 'xPDot', 'u1';
|
||||
'LateralRearContactRate', 'yPDot', 'u2';
|
||||
'YawRate', 'psiDot', 'u3';
|
||||
'RollRate', 'phiDot', 'u4';
|
||||
'PitchRate', 'thetaDot', 'u5';
|
||||
'RearWheelRate', 'thetaRDot', 'u6';
|
||||
'SteerRate', 'deltaDot', 'u7';
|
||||
'FrontWheelRate', 'thetaFDot','u8';
|
||||
'LongitudinalFrontContactRate', 'xQDot', 'u9';
|
||||
'LateralFrontContactRate', 'yQDot', 'u10'};
|
||||
|
||||
inputs = {'RollTorque', 'tPhi', 'T4';
|
||||
'RearWheelTorque', 'tThetaR', 'T6';
|
||||
'SteerTorque', 'tDelta', 'T7';
|
||||
'PullForce', 'fB', 'F'};
|
||||
1119
samples/Matlab/create_ieee_paper_plots.m
Normal file
1119
samples/Matlab/create_ieee_paper_plots.m
Normal file
File diff suppressed because it is too large
Load Diff
13
samples/Matlab/distance.m
Normal file
13
samples/Matlab/distance.m
Normal file
@@ -0,0 +1,13 @@
|
||||
function [ value,isterminal,direction ] = distance( t,y,mu )
|
||||
% DISTANCE compute the distance from the attactors
|
||||
% [ value,terminal,direction ] = distance( t,y )
|
||||
|
||||
d=1e-2; % FIXME
|
||||
|
||||
% TODO mettere if se tolleranza D-d<tol -> value=0
|
||||
D=sqrt((y(1)+mu).^2+y(2).^2); % distance from the largest primary
|
||||
|
||||
value=d-D;
|
||||
isterminal=1;
|
||||
direction=0;
|
||||
end
|
||||
49
samples/Matlab/double_gyre.m
Normal file
49
samples/Matlab/double_gyre.m
Normal file
@@ -0,0 +1,49 @@
|
||||
clear all
|
||||
tic
|
||||
% initialize integration time T, f(x,t), discretization size n ----------------
|
||||
T = 8;
|
||||
x_min=0;
|
||||
x_max=2;
|
||||
y_min=0;
|
||||
y_max=1;
|
||||
n=50; % how many points per one measure unit (both in x and in y)
|
||||
ds=1/(n-1);
|
||||
x_res=(x_max-x_min)*n;
|
||||
y_res=(y_max-y_min)*n;
|
||||
grid_x=linspace(x_min,x_max,x_res);
|
||||
grid_y=linspace(y_min,y_max,y_res);
|
||||
|
||||
advected_x=zeros(x_res,y_res);
|
||||
advected_y=zeros(x_res,y_res);
|
||||
% integrate all initial points for t in [0,T] --------------------------------
|
||||
parfor i = 1:x_res
|
||||
for j = 1:y_res
|
||||
[t,X] = ode45(@dg,[0,T],[grid_x(i),grid_y(j)]);
|
||||
% store advected positions as they would appear in (x,y) coords ------
|
||||
advected_x(i,j) = X(length(X(:,1)),1);
|
||||
advected_y(i,j) = X(length(X(:,2)),2);
|
||||
end
|
||||
end
|
||||
%% Compute FTLE
|
||||
sigma=zeros(x_res,y_res);
|
||||
% at each point in interior of grid, store FTLE ------------------------------
|
||||
for i = 2:x_res-1
|
||||
for j = 2:y_res-1
|
||||
% compute Jacobian phi -----------------------------------------------
|
||||
phi(1,1) = (advected_x(i+1,j)-advected_x(i-1,j))/(2*ds);
|
||||
phi(1,2) = (advected_x(i,j-1)-advected_x(i,j+1))/(2*ds);
|
||||
phi(2,1) = (advected_y(i+1,j)-advected_y(i-1,j))/(2*ds);
|
||||
phi(2,2) = (advected_y(i,j-1)-advected_y(i,j+1))/(2*ds);
|
||||
% find max eigenvalue of phi'*phi ------------------------------------
|
||||
lambda_max = max(abs(eig(phi'*phi)));
|
||||
% store FTLE ---------------------------------------------------------
|
||||
sigma(i,j) = log(lambda_max)/abs(2*T);
|
||||
end
|
||||
end
|
||||
toc
|
||||
%% plot FTLE field ------------------------------------------------------------
|
||||
figure
|
||||
contourf(grid_x,grid_y,sigma');
|
||||
colorbar('location','EastOutside');
|
||||
axis equal
|
||||
shading flat
|
||||
41
samples/Matlab/example.m
Normal file
41
samples/Matlab/example.m
Normal file
@@ -0,0 +1,41 @@
|
||||
clear all
|
||||
tic
|
||||
% initialize integration time T, f(x,t), discretization size n ----------------
|
||||
T = 20;
|
||||
f_x_t = inline('[v(2);-sin(v(1))]','t','v');
|
||||
grid_min = -3.4;
|
||||
grid_max = 3.4;
|
||||
grid_width = grid_max-grid_min;
|
||||
n = 35;
|
||||
grid_spacing = grid_min:(grid_width/(n-1)):grid_max;
|
||||
advected_x=zeros(n,n);
|
||||
advected_y=zeros(n,n);
|
||||
% integrate all initial points for t in [0,T] --------------------------------
|
||||
for i = 1:n
|
||||
for j = 1:n
|
||||
[t,x] = ode45(f_x_t,[0,T],[grid_spacing(i),grid_spacing(j)]);
|
||||
% store advected positions as they would appear in (x,y) coords ------
|
||||
advected_x(n-j+1,i) = x(length(x(:,1)),1);
|
||||
advected_y(n-j+1,i) = x(length(x(:,2)),2);
|
||||
end
|
||||
end
|
||||
sigma=zeros(n,n);
|
||||
% at each point in interior of grid, store FTLE ------------------------------
|
||||
for i = 2:n-1
|
||||
for j = 2:n-1
|
||||
% compute Jacobian phi -----------------------------------------------
|
||||
phi(1,1) = (advected_x(i,j+1)-advected_x(i,j-1))/(2*grid_width/(n-1));
|
||||
phi(1,2) = (advected_x(i-1,j)-advected_x(i+1,j))/(2*grid_width/(n-1));
|
||||
phi(2,1) = (advected_y(i,j+1)-advected_y(i,j-1))/(2*grid_width/(n-1));
|
||||
phi(2,2) = (advected_y(i-1,j)-advected_y(i+1,j))/(2*grid_width/(n-1));
|
||||
% find max eigenvalue of phi'*phi ------------------------------------
|
||||
lambda_max = max(abs(eig(phi'*phi)));
|
||||
% store FTLE ---------------------------------------------------------
|
||||
sigma(i,j) = log(lambda_max)/abs(T);
|
||||
end
|
||||
end
|
||||
toc
|
||||
%% plot FTLE field ------------------------------------------------------------
|
||||
figure
|
||||
contourf(grid_spacing,grid_spacing,sigma);
|
||||
colorbar('location','EastOutside');
|
||||
57
samples/Matlab/fit_adapt.m
Normal file
57
samples/Matlab/fit_adapt.m
Normal file
@@ -0,0 +1,57 @@
|
||||
data = load_data('jason_adapt.mat');
|
||||
|
||||
t0 = 0;
|
||||
t1 = 30;
|
||||
t2 = 60;
|
||||
t3 = 90;
|
||||
|
||||
dataPlantOne = data(1:t1 / data.Ts);
|
||||
dataAdapting = data(t1 / data.Ts:t2 / data.Ts);
|
||||
dataPlantTwo = data(t2 / data.Ts:end);
|
||||
|
||||
% k1, k2, k3, k4, tau, zetanm, wnm, zetafs, wfs
|
||||
|
||||
% ron's guess
|
||||
guessPlantOne = [4.85, 1.79, 20, 20, 0.2, 0.707, 10, 0.707, 65];
|
||||
% best solution from ron's guess
|
||||
%guessPlantOne = [4.1129, 2.1327, 52.3747, 48.6997, 0.2, 0.707, 10, 0.707, 65];
|
||||
resultPlantOne = find_structural_gains(dataPlantOne, guessPlantOne, 1);
|
||||
[yh, fit, x0] = compare(dataPlantOne, resultPlantOne.fit);
|
||||
display(sprintf('The self validation VAF is %f.', fit(1, 1, 1)))
|
||||
|
||||
% ron's guess
|
||||
guessPlantTwo = [3.36, 9.49, 20, 0, 0.2, 0.707, 10, 0.707, 65];
|
||||
% best solution from ron's guess
|
||||
%guessPlantTwo = [2.6686, 7.0431, 14.4623, 3.1532, 0.2, 0.707, 10, 0.707, 65];
|
||||
resultPlantTwo = find_structural_gains(dataPlantTwo, guessPlantTwo, 5);
|
||||
[yh, fit, x0] = compare(dataPlantTwo, resultPlantTwo.fit);
|
||||
display(sprintf('The self validation VAF is %f.', fit(1, 1, 1)))
|
||||
|
||||
% compute the slope and offset for each gain for initial guesses
|
||||
kP1 = resultPlantOne.fit.par(1:4);
|
||||
kP2 = resultPlantTwo.fit.par(1:4);
|
||||
gainSlopeOffset = [t1 * eye(4), eye(4); t2 * eye(4), eye(4)] \ [kP1; kP2];
|
||||
|
||||
aux.pars = guessPlantOne; % this only uses tau through wfs
|
||||
aux.timeDelay = true;
|
||||
aux.plantFirst = 1; % 1 / s
|
||||
aux.plantSecond = 5; % 5 / (s + 10)
|
||||
% compute the slope and offset of the plant for t1 < t < t2
|
||||
plantOneSlopeOffset = [t1, 1; t2, 1] \ [1; 0];
|
||||
plantTwoSlopeOffset = [t1, 1; t2, 1] \ [0; 1];
|
||||
aux.m = [plantOneSlopeOffset(1); plantTwoSlopeOffset(1)];
|
||||
aux.b = [plantOneSlopeOffset(2); plantTwoSlopeOffset(2)];
|
||||
|
||||
%[dx, y] = adapting_structural_model(45, ones(8, 1), 10, gainSlopeOffset, {aux});
|
||||
|
||||
% NOTE: 'FileArgument' has to be a cell array, the is why aux is in
|
||||
% brackets. Also, if you pass the parameters in as a vector here, as I have,
|
||||
% they get mapped to a structure and your ode file/function must accept each
|
||||
% parameter as individual arguments.
|
||||
mod = idnlgrey('adapting_structural_model', [1, 1, 8], gainSlopeOffset, ...
|
||||
zeros(8, 1), 0, 'FileArgument', {aux}, 'InputName', 'thetac', ...
|
||||
'OutputName', 'theta');
|
||||
|
||||
fit = pem(dataAdapting, mod);
|
||||
|
||||
compare(dataAdapting, fit);
|
||||
86
samples/Matlab/fit_adapt_linear.m
Normal file
86
samples/Matlab/fit_adapt_linear.m
Normal file
@@ -0,0 +1,86 @@
|
||||
% This file identifies a series of models for a time varying plant.
|
||||
|
||||
% k1, k2, k3, k4, tau, zetanm, wnm, zetafs, wfs
|
||||
|
||||
%data = load_data('jason_adapt.mat');
|
||||
%filename = 'adapt';
|
||||
%guess.plantOne = [4.85, 1.79, 20, 20, 0.2, 0.707, 10, 0.707, 65];
|
||||
%guess.plantTwo = [3.36, 9.49, 20, 0, 0.2, 0.707, 10, 0.707, 65];
|
||||
%plantNum.plantOne = 1;
|
||||
%plantNum.plantTwo = 5;
|
||||
|
||||
data = load_data('adapt_hard.mat');
|
||||
filename = 'hard-adapt';
|
||||
guess.plantOne = [1.23, 0.354, 0.2, 20.0, 0.2, 0.707, 10, 0.707, 65];
|
||||
guess.plantTwo = [4.85, 1.79, 20, 20, 0.2, 0.707, 10, 0.707, 65];
|
||||
plantNum.plantOne = 6;
|
||||
plantNum.plantTwo = 1;
|
||||
|
||||
t = [0, 30, 40, 50, 60, 90];
|
||||
|
||||
sections = {'plantOne', 'adaptOne', 'adaptTwo', 'adaptThree', 'plantTwo'};
|
||||
for i = 1:length(sections)
|
||||
secData.(sections{i}) = data(t(i) / data.Ts + 1:t(i + 1) / data.Ts);
|
||||
end
|
||||
|
||||
% compute the slope and offset for each gain for initial guesses
|
||||
kP1 = guess.plantOne(1:4)';
|
||||
kP2 = guess.plantTwo(1:4)';
|
||||
gainSlopeOffset = [t(2) * eye(4), eye(4); t(5) * eye(4), eye(4)] \ [kP1; kP2];
|
||||
m = gainSlopeOffset(1:4);
|
||||
b = gainSlopeOffset(5:8);
|
||||
|
||||
for i = 1:length(sections)
|
||||
|
||||
if strcmp(sections{i}, sections{1}) || strcmp(sections{i}, sections{end})
|
||||
display('boo')
|
||||
else
|
||||
if i > 1
|
||||
% use the best fit gains from the previous section
|
||||
guess.(sections{i}) = result.(sections{i - 1}).fit.par;
|
||||
else
|
||||
currentGuess = m .* (t(i) + t(i + 1)) / 2 + b;
|
||||
guess.(sections{i}) = [currentGuess', guess.plantOne(5:end)];
|
||||
end
|
||||
percent = ((t(i) + t(i + 1)) / 2 - t(2)) / (t(5) - t(2));
|
||||
plantNum.(sections{i}) = {plantNum.plantOne, plantNum.plantTwo, percent};
|
||||
end
|
||||
|
||||
result.(sections{i}) = find_structural_gains(secData.(sections{i}), ...
|
||||
guess.(sections{i}), plantNum.(sections{i}), 'warning', false, ...
|
||||
'randomGuess', true);
|
||||
|
||||
[yh, vaf, x0] = compare(secData.(sections{i}), result.(sections{i}).fit);
|
||||
result.(sections{i}).vaf = vaf(1, 1, 1);
|
||||
display(sprintf('The self validation VAF is %f.', vaf(1, 1, 1)))
|
||||
|
||||
p = plantNum.(sections{i});
|
||||
if size(plantNum.(sections{i}), 2) > 1
|
||||
result.(sections{i}).plant = plant(p{:});
|
||||
else
|
||||
result.(sections{i}).plant = plant(p);
|
||||
end
|
||||
end
|
||||
|
||||
save(['data/' filename '-results.mat'], 'sections', 'guess', 'plantNum', 'result')
|
||||
|
||||
for i = 1:length(sections)
|
||||
result.(sections{i}).fig = figure;
|
||||
compare(secData.(sections{i}), result.(sections{i}).fit);
|
||||
saveas(result.(sections{i}).fig, ['plots/' filename '-' sections{i} '.png'])
|
||||
[yh, fit, x0] = compare(secData.(sections{i}), result.(sections{i}).fit);
|
||||
display('-----------------')
|
||||
display('The task plant is:')
|
||||
display(result.(sections{i}).plant)
|
||||
display(sprintf('The order of the closed loop system is %u.', ...
|
||||
size(result.(sections{i}).mod.A, 1)))
|
||||
display(sprintf('The gain guesses: k1=%f, k2=%f, k3=%f, k4=%f', ...
|
||||
result.(sections{i}).mod.par(1:4)))
|
||||
display(sprintf('The identified gains: k1=%f+\\-%f, k2=%f+\\-%f, k3=%f+\\-%f, k4=%f+\\-%f', ...
|
||||
result.(sections{i}).fit.par(1), result.(sections{i}).uncert(1), ...
|
||||
result.(sections{i}).fit.par(2), result.(sections{i}).uncert(2), ...
|
||||
result.(sections{i}).fit.par(3), result.(sections{i}).uncert(3), ...
|
||||
result.(sections{i}).fit.par(4), result.(sections{i}).uncert(4)))
|
||||
display(sprintf('The self validation VAF is %f.', ...
|
||||
result.(sections{i}).vaf))
|
||||
end
|
||||
156
samples/Matlab/gpu_RKF45_FILE.m
Normal file
156
samples/Matlab/gpu_RKF45_FILE.m
Normal file
@@ -0,0 +1,156 @@
|
||||
tic
|
||||
clear
|
||||
%% Range definition
|
||||
n=200;
|
||||
|
||||
mu=0.1;
|
||||
[xl1,yl1,xl2,yl2,xl3,yl3,xl4,yl4,xl5,yl5]=Lagr(mu);
|
||||
C_L1=2*Omega(xl1,yl1,mu);
|
||||
E_0=-C_L1/2+0.03715;
|
||||
Y_0=0;
|
||||
|
||||
nx=n;
|
||||
x_0_min=-0.8;
|
||||
x_0_max=-0.15;
|
||||
x_0=linspace(x_0_min, x_0_max, nx);
|
||||
dx=(x_0_max-x_0_min)/(nx-1);
|
||||
|
||||
nvx=n;
|
||||
vx_0_min=-2;
|
||||
vx_0_max=2;
|
||||
vx_0=linspace(vx_0_min, vx_0_max, nvx);
|
||||
dvx=(vx_0_max-vx_0_min)/(nvx-1);
|
||||
|
||||
ny=3;
|
||||
dy=(dx+dvx)/2;
|
||||
y_0=[Y_0-dy Y_0 Y_0+dy];
|
||||
|
||||
|
||||
|
||||
ne=3;
|
||||
de=dy;
|
||||
e_0=[E_0-de E_0 E_0+de];
|
||||
|
||||
%% Definition of arrays of initial conditions
|
||||
|
||||
%In this approach, only useful pints are stored and integrated
|
||||
|
||||
m=1;
|
||||
% x=zeros(1,nx*ny*nvx*ne);
|
||||
% y=zeros(1,nx*ny*nvx*ne);
|
||||
% vx=zeros(1,nx*ny*nvx*ne);
|
||||
% e=zeros(1,nx*ny*nvx*ne);
|
||||
% vy=zeros(1,nx*ny*nvx*ne);
|
||||
filter=zeros(nx,3,nvx,3);
|
||||
|
||||
for i=1:nx
|
||||
for j=1:ny
|
||||
for k=1:nvx
|
||||
for l=1:ne
|
||||
v_y=-sqrt(2*Omega(x_0(i),y_0(j),mu)+2*e_0(l)-vx_0(k)^2);
|
||||
if ~((j~=2) && (l~=2)) && isreal(v_y)
|
||||
x(m)=x_0(i);
|
||||
y(m)=y_0(j);
|
||||
vx(m)=vx_0(k);
|
||||
e(m)=e_0(l);
|
||||
vy(m)=v_y;
|
||||
filter(i,j,k,l)=1;
|
||||
m=m+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Selection of useful points
|
||||
|
||||
%% Data transfer to GPU
|
||||
x_gpu=gpuArray(x);
|
||||
y_gpu=gpuArray(y);
|
||||
vx_gpu=gpuArray(vx);
|
||||
vy_gpu=gpuArray(vy);
|
||||
|
||||
%% Integration on GPU
|
||||
N=1;
|
||||
t0=0;
|
||||
|
||||
[x_f,y_f,vx_f,vy_f]=arrayfun(@RKF45_FILE_gpu,t0,N,x_gpu,y_gpu,vx_gpu,vy_gpu,mu);
|
||||
|
||||
%% Data back to CPU and GPU memory cleaning
|
||||
clear x_gpu y_gpu vx_gpu vy_gpu
|
||||
x_T=gather(x_f);
|
||||
clear x_f
|
||||
y_T=gather(y_f);
|
||||
clear y_f
|
||||
vx_T=gather(vx_f);
|
||||
clear vx_f
|
||||
vy_T=gather(vy_f);
|
||||
clear vy_f
|
||||
|
||||
%% Construction of matrix for FTLE computation
|
||||
|
||||
X_T=zeros(nx,ny,nvx,ne);
|
||||
Y_T=zeros(nx,ny,nvx,ne);
|
||||
VX_T=zeros(nx,ny,nvx,ne);
|
||||
VY_T=zeros(nx,ny,nvx,ne);
|
||||
E_T=zeros(nx,ny,nvx,ne);
|
||||
m=1;
|
||||
for i=1:nx
|
||||
for j=1:ny
|
||||
for k=1:nvx
|
||||
for l=1:ne
|
||||
if filter(i,j,k,l)==1
|
||||
X_T(i,j,k,l)=x_T(m);
|
||||
Y_T(i,j,k,l)=y_T(m);
|
||||
VX_T(i,j,k,l)=vx_T(m);
|
||||
VY_T(i,j,k,l)=vy_T(m);
|
||||
E_T(i,j,k,l)=0.5*(VX_T(i,j,k,l)^2+VY_T(i,j,k,l)^2)-Omega(X_T(i,j,k,l),Y_T(i,j,k,l),mu);
|
||||
m=m+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Compute filter for FTLE
|
||||
filter_ftle=filter;
|
||||
for i=2:(nx-1)
|
||||
for j=2:(ny-1)
|
||||
for k=2:(nvx-1)
|
||||
for l=2:(ne-1)
|
||||
if filter(i,j,k,l)==0 || filter (i,j,k,l)==3
|
||||
filter_ftle(i,j,k,l)=0;
|
||||
|
||||
filter_ftle(i+1,j,k,l)=0;
|
||||
filter_ftle(i-1,j,k,l)=0;
|
||||
|
||||
filter_ftle(i,j+1,k,l)=0;
|
||||
filter_ftle(i,j-1,k,l)=0;
|
||||
|
||||
filter_ftle(i,j,k+1,l)=0;
|
||||
filter_ftle(i,j,k-1,l)=0;
|
||||
|
||||
filter_ftle(i,j,k,l+1)=0;
|
||||
filter_ftle(i,j,k,l-1)=0;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
%% FTLE computation
|
||||
|
||||
[ftle, dphi]=Compute_FILE_gpu( X_T, Y_T, VX_T, E_T, dx, dy, dvx, de, N, filter_ftle);
|
||||
|
||||
%% Plot results
|
||||
figure
|
||||
FTLE=squeeze(ftle(:,2,:,2));
|
||||
FTLE(1,:)=[];
|
||||
% FTLE(2,:)=[];
|
||||
FTLE(:,1)=[];
|
||||
% FTLE(:,2)=[];
|
||||
x_0(1)=[];
|
||||
vx_0(1)=[];
|
||||
pcolor(x_0, vx_0, FTLE')
|
||||
shading flat
|
||||
toc
|
||||
13
samples/Matlab/ieee.m
Normal file
13
samples/Matlab/ieee.m
Normal file
@@ -0,0 +1,13 @@
|
||||
% This script loads in the data used for the IEEE paper and creates the plots.
|
||||
clc; close all;
|
||||
|
||||
bikes = {'Benchmark', 'Browserins', 'Browser', 'Pista', ...
|
||||
'Fisher', 'Yellow', 'Yellowrev'};
|
||||
|
||||
data = load_bikes(bikes, 'Steer');
|
||||
|
||||
rollData = generate_data('Benchmark', 5.0, ...
|
||||
'input', 'Roll', ...
|
||||
'gains', [1, 55, 3.76, 0.413, 0.076]);
|
||||
|
||||
create_ieee_paper_plots(data, rollData)
|
||||
56
samples/Matlab/lane_change.m
Normal file
56
samples/Matlab/lane_change.m
Normal file
@@ -0,0 +1,56 @@
|
||||
function [x, y, t] = lane_change(start, width, slope, pathLength, speed, num, ...
|
||||
type, varargin)
|
||||
% Generates the time and coordinates for either a single or double lane change
|
||||
% manuever at a particular speed.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% start : float
|
||||
% The starting point along the x axis in meters.
|
||||
% width : float
|
||||
% The width of the lane deviation.
|
||||
% slope : float
|
||||
% The slope of the lane change.
|
||||
% pathLength : float
|
||||
% The length of path.
|
||||
% speed : float
|
||||
% Speed of travel.
|
||||
% num : integer
|
||||
% Number of time steps.
|
||||
% type : string
|
||||
% Either 'single' or 'double'. A double lane change return to x = 0.
|
||||
% laneLength : float, optional
|
||||
% Length of the lane for a double lane change.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% x : matrix, (num, 1)
|
||||
% The longitudinal path.
|
||||
% y : matrix, (num, 1)
|
||||
% The lateral path.
|
||||
% t : matrix, (num, 1)
|
||||
% Time.
|
||||
|
||||
x = 0:pathLength / num:pathLength;
|
||||
x = x';
|
||||
t = x / speed;
|
||||
|
||||
y = zeros(length(x), 1);
|
||||
endOfSlope = width / slope + start;
|
||||
slopeInd = find((x > start) & (x <= endOfSlope));
|
||||
y(slopeInd) = slope * (x(slopeInd) - start);
|
||||
if strcmp(type, 'single')
|
||||
theRest = slopeInd(end) + 1:length(y);
|
||||
y(theRest) = width * ones(length(theRest), 1);
|
||||
elseif strcmp(type, 'double');
|
||||
if length(varargin) < 1
|
||||
error('Double lane change needs length of lane.')
|
||||
else
|
||||
laneLength = varargin{1};
|
||||
startOfSlope = start + laneLength - width / slope;
|
||||
lane = find((x > endOfSlope) & (x <= startOfSlope));
|
||||
y(lane) = width * ones(length(lane), 1);
|
||||
downSlope = find((x > startOfSlope) & (x <= start + laneLength));
|
||||
y(downSlope) = slope * (start + laneLength - x(downSlope));
|
||||
end
|
||||
end
|
||||
55
samples/Matlab/load_bikes.m
Normal file
55
samples/Matlab/load_bikes.m
Normal file
@@ -0,0 +1,55 @@
|
||||
function data = load_bikes(bikes, input)
|
||||
% function data = load_bikes(bikes, input)
|
||||
% Returns the data for a set of bicycles at three speeds.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% bikes : cell array
|
||||
% A cell array that lists the bicyle short names.
|
||||
% input : string
|
||||
% 'Steer' or 'Roll'
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% data : structure
|
||||
% A structure containg a node for each bicycle and each speed.
|
||||
|
||||
speeds = [2.5, 5.0, 7.5];
|
||||
speedNames = {'Slow', 'Medium', 'Fast'};
|
||||
|
||||
% these are the gains that were selected manually by Ron Hess, taken from
|
||||
% the paper
|
||||
gains.Benchmark.Slow = [22.0, -0.090, 23.3, 0.058, 0.195]; % place holder
|
||||
gains.Browserins.Slow = [22.0, -0.090, 23.3, 0.058, 0.195];
|
||||
gains.Browser.Slow = [20.5, -0.086, 24.1, 0.053, 0.199];
|
||||
% the gains in the paper give an unstable bike, the uncommented one were the ones from his
|
||||
% simulink model
|
||||
gains.Pista.Slow = [22.3000,-0.1300,15.6410,0.0645,0.1990]; %[22.3, -0.130, 15.6, 0.662, 0.198];
|
||||
gains.Fisher.Slow = [23.0, -0.120, 17.7, 0.065, 0.198];
|
||||
gains.Yellow.Slow = [18.0, -0.110, 20.2, 0.062, 0.200];
|
||||
gains.Yellowrev.Slow = [48.0, -0.070, 27.9, 0.063, 0.191];
|
||||
|
||||
gains.Benchmark.Medium = [ 46.5, -0.052, 12.8, 0.177, 0.097];
|
||||
gains.Browserins.Medium = [ 48.0, -0.080, 9.03, 0.161, 0.097];
|
||||
gains.Browser.Medium = [ 43.0, -0.087, 8.50, 0.173, 0.100];
|
||||
gains.Pista.Medium = [ 49.0, -0.080, 8.06, 0.170, 0.101];
|
||||
gains.Fisher.Medium = [ 50.5, -0.084, 8.26, 0.168, 0.100];
|
||||
gains.Yellow.Medium = [ 39.0, -0.085, 8.61, 0.160, 0.101];
|
||||
gains.Yellowrev.Medium = [105.0, -0.070, 8.90, 0.165, 0.100];
|
||||
|
||||
gains.Benchmark.Fast = [ 74.0, -0.063, 6.31, 0.332, 0.065]; % place holder
|
||||
gains.Browserins.Fast = [ 74.0, -0.063, 6.31, 0.332, 0.065];
|
||||
gains.Browser.Fast = [ 68.0, -0.060, 6.74, 0.330, 0.065];
|
||||
gains.Pista.Fast = [ 80.0, -0.058, 5.82, 0.321, 0.066];
|
||||
gains.Fisher.Fast = [ 82.0, -0.062, 5.83, 0.315, 0.065];
|
||||
gains.Yellow.Fast = [ 61.0, -0.063, 6.34, 0.345, 0.065];
|
||||
gains.Yellowrev.Fast = [170.0, -0.050, 6.45, 0.300, 0.066];
|
||||
|
||||
% load the data for all speeds for all the bikes
|
||||
for i = 1:length(bikes)
|
||||
for j = 1:length(speeds)
|
||||
data.(bikes{i}).(speedNames{j}) = ...
|
||||
generate_data(bikes{i}, speeds(j), 'input', input, ...
|
||||
'gains', gains.(bikes{i}).(speedNames{j}));
|
||||
end
|
||||
end
|
||||
33
samples/Matlab/load_data.m
Normal file
33
samples/Matlab/load_data.m
Normal file
@@ -0,0 +1,33 @@
|
||||
function data = load_data(filename, varargin)
|
||||
% function data = load_data(filename, varargin)
|
||||
%
|
||||
% Returns an iddata object with the input thetac and output theta for the
|
||||
% given file.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% filename : char
|
||||
% Filename for the data file.
|
||||
% varargin : char value pairs, optional
|
||||
% sampleTime : double, default=0.0005
|
||||
% detread : boolean, default=true
|
||||
% directory : char, default='data'
|
||||
|
||||
parser = inputParser;
|
||||
parser.addRequired('filename');
|
||||
parser.addParamValue('sampleTime', 0.0005);
|
||||
parser.addParamValue('detrend', true);
|
||||
parser.addParamValue('directory', 'data');
|
||||
parser.parse(filename, varargin{:});
|
||||
args = parser.Results;
|
||||
|
||||
raw = load([args.directory filesep filename]);
|
||||
|
||||
data = iddata(raw.theta, raw.theta_c, args.sampleTime, ...
|
||||
'InterSample', 'foh', ...
|
||||
'InputName', {'thetac'}, ...
|
||||
'OutputName', {'theta'});
|
||||
|
||||
if args.detrend
|
||||
data = detrend(data);
|
||||
end
|
||||
27
samples/Matlab/overwrite_settings.m
Normal file
27
samples/Matlab/overwrite_settings.m
Normal file
@@ -0,0 +1,27 @@
|
||||
function settings = overwrite_settings(defaultSettings, overrideSettings)
|
||||
% function settings = overwrite_settings(defaultSettings, overrideSettings)
|
||||
% Returns the settings based on a combination of the defaults and the override settings.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% defaultSettings : structure
|
||||
% A structure with all of the default settings.
|
||||
% overrideSettings : structure
|
||||
% Contains any settings that should override the defaults.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% settings : structure
|
||||
% A stucture containing the overrideSettings and any defaults that weren't
|
||||
% supplied in the overrideSettings.
|
||||
|
||||
% add the default options if not specified by the user
|
||||
overrideNames = fieldnames(overrideSettings);
|
||||
defaultNames = fieldnames(defaultSettings);
|
||||
notGiven = setxor(overrideNames, defaultNames);
|
||||
settings = overrideSettings;
|
||||
if length(notGiven) > 0
|
||||
for i = 1:length(notGiven)
|
||||
settings.(notGiven{i}) = defaultSettings.(notGiven{i});
|
||||
end
|
||||
end
|
||||
27
samples/Matlab/par_text_to_struct.m
Normal file
27
samples/Matlab/par_text_to_struct.m
Normal file
@@ -0,0 +1,27 @@
|
||||
function par = par_text_to_struct(pathToFile)
|
||||
% function par = par_text_to_struct(pathToFile)
|
||||
% Returns a structure of the parameters that were stored in a csv text file.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% pathToFile : string
|
||||
% Path to a text file containing the benchmark parameters for a single
|
||||
% bicycle. The parameters should be on seperate lines and take this form:
|
||||
%
|
||||
% c = 0.08+/-0.01
|
||||
% lam = 0.31
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% par : structure
|
||||
% A structure containing the bicycle parameters.
|
||||
|
||||
fid = fopen(pathToFile);
|
||||
data = textscan(fid, '%s %s', 'delimiter', '=');
|
||||
fclose(fid);
|
||||
names = strtrim(data{1});
|
||||
vals = strtrim(regexp(data{2}, '+/-', 'split'));
|
||||
for i = 1:length(names)
|
||||
v = vals{i};
|
||||
par.(names{i}) = str2num(v{1});
|
||||
end
|
||||
75
samples/Matlab/plant.m
Normal file
75
samples/Matlab/plant.m
Normal file
@@ -0,0 +1,75 @@
|
||||
function Yc = plant(varargin)
|
||||
% function Yc = plant(varargin)
|
||||
%
|
||||
% Returns the system plant given a number.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% varargin : variable
|
||||
% Either supply a single argument {num} or three arguments {num1, num2,
|
||||
% ratio}. If a single argument is supplied, then one of the six transfer
|
||||
% functions will be chosen from the list. If three arguments are chosen, a
|
||||
% parallel sum of the two plants will be returned.
|
||||
%
|
||||
% Option 1
|
||||
% --------
|
||||
% num : integer, {1, 2, 3, 4, 5, 6}
|
||||
% A number between 1 and 6 corresponding to the five plants.
|
||||
% Option 2
|
||||
% --------
|
||||
% num1 : integer, {1, 2, 3, 4, 5, 6}
|
||||
% A number between 1 and 6 corresponding to the five plants.
|
||||
% num2 : integer, {1, 2, 3, 4, 5, 6}
|
||||
% A number between 1 and 6 corresponding to the five plants.
|
||||
% percent : double
|
||||
% The percentage multiplier of the first plant. Should be between 0
|
||||
% and 1. The percentage multiplier of the second plant will be 1 -
|
||||
% percent.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% Either a single plant or a parallel sum of scaled plants.
|
||||
%
|
||||
% Option 1
|
||||
% --------
|
||||
% Yc : transfer function
|
||||
% 1 : 1 / s
|
||||
% 2 : 1 / s(s + 1)
|
||||
% 3 : 1 / s(s + 0.2)
|
||||
% 4 : 10 / (s + 10)
|
||||
% 5 : 5 / (s + 10)
|
||||
% 6 : 10 / (s^2 +.2 * s)
|
||||
%
|
||||
% Option 2
|
||||
% --------
|
||||
% Yc : transfer function
|
||||
% Yc = percent * Yc1 + (1 - percent) * Yc2, where Yc1 and Yc2 are plants
|
||||
% from the list shown in Option 1.
|
||||
|
||||
if size(varargin, 2) > 1
|
||||
if 0 <= varargin{3} & varargin{3} <= 1
|
||||
Yc = parallel(varargin{3} * choose_plant(varargin{1}), ...
|
||||
(1 - varargin{3}) * choose_plant(varargin{2}));
|
||||
else
|
||||
error('Ratio must be between 0 and 1.')
|
||||
end
|
||||
else
|
||||
Yc = choose_plant(varargin{1});
|
||||
end
|
||||
|
||||
function p = choose_plant(num)
|
||||
if num == 1;
|
||||
p = tf(1.0, [1.0, 0.0]);
|
||||
elseif num == 2;
|
||||
p = tf(1.0, [1.0, 1.0, 0.0]);
|
||||
elseif num == 3;
|
||||
p = tf(1.0, [1.0, 0.2, 0.0]);
|
||||
elseif num == 4;
|
||||
p = tf(10.0, [1.0, 10.0]);
|
||||
elseif num == 5;
|
||||
p = tf(5.0, [1.0, 10.0]);
|
||||
elseif num == 6;
|
||||
p = tf(10.0, [1.0, 0.2, 0.0]);
|
||||
else
|
||||
display('Invalid plant number.')
|
||||
end
|
||||
19
samples/Matlab/test_rk_par.m
Normal file
19
samples/Matlab/test_rk_par.m
Normal file
@@ -0,0 +1,19 @@
|
||||
clear
|
||||
mu=0.1;
|
||||
x_0=linspace(-0.8, -0.15, 2)
|
||||
y_0=zeros(1,2)
|
||||
vx_0=linspace(-2, 2, 2)
|
||||
vy_0=zeros(1,2)
|
||||
ci=[1-mu-0.05 0 0.005 0.5290]
|
||||
t0=[0;0]
|
||||
T=[2;2]
|
||||
tspan=2
|
||||
arg1={@f;@f}
|
||||
%tspan={[0 2],[0 2]};
|
||||
arg=[mu;mu]
|
||||
[X]=arrayfun(RK4_par,t0,T,x_0',y_0',vx_0',vy_0',arg)
|
||||
% [X]=arrayfun(@f,[0;1],[ci;ci],[mu;mu]);
|
||||
%Y=RK4(@f,tspan,ci,mu);
|
||||
% figure
|
||||
% plot(Y(:,1),Y(:,2))
|
||||
% Y(end,1)
|
||||
69
samples/Matlab/test_system_state_space.m
Normal file
69
samples/Matlab/test_system_state_space.m
Normal file
@@ -0,0 +1,69 @@
|
||||
gains = [76.3808, -0.0516, 7.2456, 0.2632, 0.0708];
|
||||
wnm = 30;
|
||||
zetanm = 0.707;
|
||||
|
||||
data = generate_data('Rigid', 7.0, 'gains', gains, 'neuroFreq', wnm, ...
|
||||
'loopTransfer', 0, 'handlingQuality', 0, 'simulate', 0);
|
||||
|
||||
bicycle = ss(data.modelPar.A, data.modelPar.B, data.modelPar.C, ...
|
||||
data.modelPar.D);
|
||||
|
||||
bicycle.StateName = {'xP', 'yP', 'psi', 'phi', 'thetaB', 'thetaR', 'delta', ...
|
||||
'thetaF', 'phiDot', 'thetaRDot', 'deltaDot'};
|
||||
bicycle.OutputName = {'xP', 'yP', 'psi', 'phi', 'thetaB', 'thetaR', 'delta', ...
|
||||
'thetaF', 'xPDot', 'yPDot', 'psiDot', 'phiDot', ...
|
||||
'thetaBDot', 'thetaRDot', 'deltaDot', 'thetaFDot', 'xQ', 'yQ'};
|
||||
bicycle.InputName = {'tPhi', 'tDelta', 'fB'};
|
||||
|
||||
inputs = {'fB'};
|
||||
outputs = [bicycle.OutputName; 'tDelta'];
|
||||
|
||||
analytic = system_state_space('lateral', bicycle, gains, [wnm, zetanm], inputs, outputs);
|
||||
|
||||
numeric = ss(data.system.A, data.system.B, data.system.C, data.system.D);
|
||||
%numeric.StateName = data.bicycle.states;
|
||||
%numeric.InputName = data.bicycle.inputs;
|
||||
%numeric.OutputName = data.bicycle.outputs;
|
||||
|
||||
figure()
|
||||
pzplot(analytic, numeric)
|
||||
|
||||
% plot the transfer function roll-rate/lateral force for both
|
||||
figure()
|
||||
hold all
|
||||
% plot my analytic model
|
||||
[num, den] = ss2tf(analytic.A, analytic.B, analytic.C, analytic.D, 1);
|
||||
mine = tf(num(find(strcmp('phiDot', outputs)), :), den);
|
||||
bode(tf(num(find(strcmp('phiDot', outputs)), :), den))
|
||||
% plot the data from the simulink model
|
||||
bode(tf(data.forceTF.PhiDot.num, data.forceTF.PhiDot.den))
|
||||
[num, den] = ss2tf(numeric.A, numeric.B, numeric.C, numeric.D, 1);
|
||||
bode(tf(num(12, :), den))
|
||||
|
||||
display('Analytic Eigenvalues')
|
||||
eig(analytic.A)
|
||||
display('Numeric Eigenvalues')
|
||||
eig(numeric.A)
|
||||
|
||||
% Now see if the heading tracking works.
|
||||
gains = [76.3808, -0.0516, 7.2456, 0.2632];
|
||||
wnm = 30;
|
||||
zetanm = 0.707;
|
||||
|
||||
par = par_text_to_struct('parameters/RigidPar.txt');
|
||||
[A, B, C, D] = whipple_pull_force_ABCD(par, 7.0);
|
||||
bicycle = ss(A([3, 4, 7, 9, 11], [3, 4, 7, 9, 11]), ...
|
||||
B([3. 4, 7, 9, 11], [2, 3]), eye(5), 0);
|
||||
bicycle.StateName = {'psi', 'phi', 'delta', 'phiDot', 'deltaDot'};
|
||||
bicycle.OutputName = {'psi', 'phi', 'delta', 'phiDot', 'deltaDot'};
|
||||
bicycle.InputName = {'tDelta', 'fB'};
|
||||
|
||||
inputs = {'fB'};
|
||||
outputs = [bicycle.OutputName; 'tDelta'];
|
||||
|
||||
analytic = system_state_space('heading', bicycle, gains, [wnm, zetanm], inputs, outputs);
|
||||
% the following two should be the same
|
||||
analytic.A(end, :)
|
||||
bottomRow = [-wnm^2 * prod(gains), -wnm^2 * prod(gains(1:3)), ...
|
||||
-wnm^2 * gains(1), -wnm^2 * prod(gains(1:2)), 0, -wnm^2, ...
|
||||
-2 * wnm * zetanm]
|
||||
37
samples/Matlab/varargin_to_structure.m
Normal file
37
samples/Matlab/varargin_to_structure.m
Normal file
@@ -0,0 +1,37 @@
|
||||
function options = varargin_to_structure(arguments)
|
||||
% function options = varargin_to_structure(arguments)
|
||||
% Returns a structure from a cell array of pairs.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% arguments : cell array (1, n)
|
||||
% A cell array where n is an even number greater than or equal to 2. The odd
|
||||
% cells must be a character string and the even cells can be any data type.
|
||||
%
|
||||
% Returns
|
||||
% -------
|
||||
% options : structure
|
||||
% The fields of the structure correspond to the odd cells in the array and
|
||||
% the value for that field corresponds to the even cells.
|
||||
%
|
||||
% This is useful for functions that have varargin as an input where the
|
||||
% variable inputs are keyword pairs.
|
||||
|
||||
% make sure there are enough arguments
|
||||
if length(arguments) <= 1
|
||||
error('Please supply 2 or more arguments')
|
||||
end
|
||||
|
||||
% make sure they provided and even number of inputs
|
||||
if mod(length(arguments), 2) ~= 0
|
||||
error('There must be an even numbers of arguments')
|
||||
end
|
||||
|
||||
% store the values in the structure
|
||||
for i = 1:2:length(arguments)
|
||||
% make sure they have character strings as all the odd cells
|
||||
if ~ischar(arguments{i})
|
||||
error('The odd arguments must be character strings.')
|
||||
end
|
||||
options.(arguments{i}) = arguments{i + 1};
|
||||
end
|
||||
48
samples/Matlab/write_gains.m
Normal file
48
samples/Matlab/write_gains.m
Normal file
@@ -0,0 +1,48 @@
|
||||
function write_gains(pathToFile, speeds, gains)
|
||||
% function write_gains(pathToFile, speeds, gains)
|
||||
%
|
||||
% Adds the provided gains to the file.
|
||||
%
|
||||
% Parameters
|
||||
% ----------
|
||||
% pathToFile : string
|
||||
% The path to a gain file.
|
||||
% speeds : matrix(n, 1)
|
||||
% gains : matrix (n, 5)
|
||||
% A matrix of gains where each row corresponds to a speed and the columns
|
||||
% correspond to the loops starting at the innermost loop.
|
||||
|
||||
contents = importdata(pathToFile);
|
||||
|
||||
speedsInFile = contents.data(:, 1);
|
||||
gainsInFile = contents.data(:, 2:end);
|
||||
|
||||
% remove any speeds that are very close to the speeds provided
|
||||
sameSpeedIndices = [];
|
||||
for i = 1:length(speedsInFile)
|
||||
for j = 1:length(speeds)
|
||||
if abs(speedsInFile(i) - speeds(j)) < 1e-3
|
||||
sameSpeedIndices = [sameSpeedIndices i];
|
||||
end
|
||||
end
|
||||
end
|
||||
speedsInFile(sameSpeedIndices) = [];
|
||||
gainsInFile(sameSpeedIndices, :) = [];
|
||||
|
||||
% concatenate data
|
||||
allGains = [gainsInFile; gains];
|
||||
allSpeeds = [speedsInFile; speeds];
|
||||
|
||||
% sort the data
|
||||
[allSpeeds, order] = sort(allSpeeds);
|
||||
allGains = allGains(order, :);
|
||||
|
||||
% recombine
|
||||
all = [allSpeeds, allGains];
|
||||
|
||||
% rewrite the file
|
||||
fid = fopen(pathToFile, 'w');
|
||||
h = contents.colheaders;
|
||||
fprintf(fid, '%s,%s,%s,%s,%s,%s\n', h{1}, h{2}, h{3}, h{4}, h{5}, h{6});
|
||||
fprintf(fid, '%1.3f,%1.4f,%1.4f,%1.4f,%1.4f,%1.4f\n', all');
|
||||
fclose(fid);
|
||||
152
samples/Monkey/example.monkey
Normal file
152
samples/Monkey/example.monkey
Normal file
@@ -0,0 +1,152 @@
|
||||
Strict
|
||||
|
||||
' single line comment
|
||||
|
||||
#rem
|
||||
multi
|
||||
line
|
||||
comment
|
||||
#end
|
||||
|
||||
#rem
|
||||
nested
|
||||
#rem
|
||||
multi
|
||||
line
|
||||
#end
|
||||
comment
|
||||
#end
|
||||
|
||||
Import mojo
|
||||
|
||||
Const ONECONST:Int = 1
|
||||
Const TWOCONST := 2
|
||||
Const THREECONST := 3, FOURCONST:Int = 4
|
||||
|
||||
Global someVariable:Int = 4
|
||||
|
||||
' sample class from the documentation
|
||||
Class Game Extends App
|
||||
|
||||
Function New()
|
||||
End
|
||||
|
||||
Function DrawSpiral(clock)
|
||||
Local w=DeviceWidth/2
|
||||
For Local i#=0 Until w*1.5 Step .2
|
||||
Local x#,y#
|
||||
x=w+i*Sin(i*3+clock)
|
||||
y=w+i*Cos(i*2+clock)
|
||||
DrawRect x,y,1,1
|
||||
Next
|
||||
hitbox.Collide(event.pos)
|
||||
End
|
||||
|
||||
Field updateCount
|
||||
|
||||
Method OnCreate()
|
||||
Print "spiral"
|
||||
|
||||
SetUpdateRate 60
|
||||
End
|
||||
|
||||
Method OnUpdate()
|
||||
updateCount+=1
|
||||
End
|
||||
|
||||
Method OnRender()
|
||||
Cls
|
||||
DrawSpiral updateCount
|
||||
DrawSpiral updateCount*1.1
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
Class Enemy
|
||||
Method Die () Abstract
|
||||
End
|
||||
|
||||
' extending
|
||||
Class Hoodlum Extends Enemy
|
||||
' field
|
||||
Field testField:Bool = True
|
||||
|
||||
' naming class with modulepath
|
||||
Local currentNode:list.Node<Vector2D>
|
||||
|
||||
Method Die ()
|
||||
Print "B'oss, he-- he killed me, b'oss!"
|
||||
End
|
||||
End
|
||||
|
||||
' extending with generics
|
||||
Class VectorNode Extends Node<Vector2D>
|
||||
End
|
||||
|
||||
' interfaces
|
||||
Interface Computer
|
||||
Method Boot ()
|
||||
Method Process ()
|
||||
Method Display ()
|
||||
End
|
||||
|
||||
Class PC Implements Computer
|
||||
End
|
||||
|
||||
' array syntax
|
||||
Global listOfStuff:String[42]
|
||||
Global lessStuff:String[5] = listOfStuff[4..8]
|
||||
Global oneStuff:String = listOfStuff[23]
|
||||
|
||||
'a comma separated sequence
|
||||
Global scores:Int[]=[10,20,30]
|
||||
'a comma separated sequence
|
||||
Global text:String[]=["Hello","There","World"]
|
||||
Global worstCase:worst.List<String[]>
|
||||
|
||||
' string type
|
||||
Global string1:String = "Hello world"
|
||||
Global string2$ = "Hello world"
|
||||
|
||||
' escape characers in strings
|
||||
Global string3 := "Hello~zWorld"
|
||||
Global string4 := "~qHello World~q"
|
||||
Global string5 := "~tIndented~n"
|
||||
Global string6 := "tilda is wavey... ~~"
|
||||
|
||||
' string pseudofunctions
|
||||
Print " Hello World ~n".Trim() ' prints "Hello World"
|
||||
Print "Hello World".ToUpper() ' prints "HELLO WORLD"
|
||||
|
||||
' Boolean shorttype
|
||||
Global boolVariable1:Bool = True
|
||||
Global boolVariable2? = False
|
||||
|
||||
' number formats
|
||||
Global hexNum1:Int = $3d0dead
|
||||
Global hexNum2% = $CAFEBABE
|
||||
|
||||
Global floatNum1:Float = 3.141516
|
||||
Global floatNum2# = 3.141516
|
||||
Global floatNum3 := .141516
|
||||
|
||||
' preprocessor keywords
|
||||
#If TARGET = "android"
|
||||
DoStuff()
|
||||
#ElseIf TARGET = "ios"
|
||||
DoOtherStuff()
|
||||
#End
|
||||
|
||||
' preprocessor variable
|
||||
#SOMETHING = True
|
||||
#Print SOMETHING
|
||||
#If SOMETHING
|
||||
#End
|
||||
|
||||
' operators
|
||||
Global a = 32
|
||||
Global b = 32 ~ 0
|
||||
b ~= 16
|
||||
b |= 16
|
||||
b &= 16
|
||||
Global c = a | b
|
||||
308
samples/NSIS/bigtest.nsi
Normal file
308
samples/NSIS/bigtest.nsi
Normal file
@@ -0,0 +1,308 @@
|
||||
; bigtest.nsi
|
||||
;
|
||||
; This script attempts to test most of the functionality of the NSIS exehead.
|
||||
|
||||
;--------------------------------
|
||||
|
||||
!ifdef HAVE_UPX
|
||||
!packhdr tmp.dat "upx\upx -9 tmp.dat"
|
||||
!endif
|
||||
|
||||
!ifdef NOCOMPRESS
|
||||
SetCompress off
|
||||
!endif
|
||||
|
||||
;--------------------------------
|
||||
|
||||
Name "BigNSISTest"
|
||||
Caption "NSIS Big Test"
|
||||
Icon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-install.ico"
|
||||
OutFile "bigtest.exe"
|
||||
|
||||
SetDateSave on
|
||||
SetDatablockOptimize on
|
||||
CRCCheck on
|
||||
SilentInstall normal
|
||||
BGGradient 000000 800000 FFFFFF
|
||||
InstallColors FF8080 000030
|
||||
XPStyle on
|
||||
|
||||
InstallDir "$PROGRAMFILES\NSISTest\BigNSISTest"
|
||||
InstallDirRegKey HKLM "Software\NSISTest\BigNSISTest" "Install_Dir"
|
||||
|
||||
CheckBitmap "${NSISDIR}\Contrib\Graphics\Checks\classic-cross.bmp"
|
||||
|
||||
LicenseText "A test text, make sure it's all there"
|
||||
LicenseData "bigtest.nsi"
|
||||
|
||||
RequestExecutionLevel admin
|
||||
|
||||
;--------------------------------
|
||||
|
||||
Page license
|
||||
Page components
|
||||
Page directory
|
||||
Page instfiles
|
||||
|
||||
UninstPage uninstConfirm
|
||||
UninstPage instfiles
|
||||
|
||||
;--------------------------------
|
||||
|
||||
!ifndef NOINSTTYPES ; only if not defined
|
||||
InstType "Most"
|
||||
InstType "Full"
|
||||
InstType "More"
|
||||
InstType "Base"
|
||||
;InstType /NOCUSTOM
|
||||
;InstType /COMPONENTSONLYONCUSTOM
|
||||
!endif
|
||||
|
||||
AutoCloseWindow false
|
||||
ShowInstDetails show
|
||||
|
||||
;--------------------------------
|
||||
|
||||
Section "" ; empty string makes it hidden, so would starting with -
|
||||
|
||||
; write reg info
|
||||
StrCpy $1 "POOOOOOOOOOOP"
|
||||
DetailPrint "I like to be able to see what is going on (debug) $1"
|
||||
WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "Install_Dir" "$INSTDIR"
|
||||
|
||||
; write uninstall strings
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "DisplayName" "BigNSISTest (remove only)"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "UninstallString" '"$INSTDIR\bt-uninst.exe"'
|
||||
|
||||
SetOutPath $INSTDIR
|
||||
File /a "silent.nsi"
|
||||
CreateDirectory "$INSTDIR\MyProjectFamily\MyProject" ; 2 recursively create a directory for fun.
|
||||
WriteUninstaller "bt-uninst.exe"
|
||||
|
||||
Nop ; for fun
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "TempTest"
|
||||
|
||||
SectionIn 1 2 3
|
||||
Start: MessageBox MB_OK "Start:"
|
||||
|
||||
MessageBox MB_YESNO "Goto MyLabel" IDYES MyLabel
|
||||
|
||||
MessageBox MB_OK "Right before MyLabel:"
|
||||
|
||||
MyLabel: MessageBox MB_OK "MyLabel:"
|
||||
|
||||
MessageBox MB_OK "Right after MyLabel:"
|
||||
|
||||
MessageBox MB_YESNO "Goto Start:?" IDYES Start
|
||||
|
||||
SectionEnd
|
||||
|
||||
SectionGroup /e SectionGroup1
|
||||
|
||||
Section "Test Registry/INI functions"
|
||||
|
||||
SectionIn 1 4 3
|
||||
|
||||
WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "StrTest_INSTDIR" "$INSTDIR"
|
||||
WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0xDEADBEEF" 0xdeadbeef
|
||||
WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_123456" 123456
|
||||
WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0123" 0123
|
||||
WriteRegBin HKLM SOFTWARE\NSISTest\BigNSISTest "BinTest_deadbeef01f00dbeef" "DEADBEEF01F00DBEEF"
|
||||
StrCpy $8 "$SYSDIR\IniTest"
|
||||
WriteINIStr "$INSTDIR\test.ini" "MySection" "Value1" $8
|
||||
WriteINIStr "$INSTDIR\test.ini" "MySectionIni" "Value1" $8
|
||||
WriteINIStr "$INSTDIR\test.ini" "MySectionIni" "Value2" $8
|
||||
WriteINIStr "$INSTDIR\test.ini" "IniOn" "Value1" $8
|
||||
|
||||
Call MyFunctionTest
|
||||
|
||||
DeleteINIStr "$INSTDIR\test.ini" "IniOn" "Value1"
|
||||
DeleteINISec "$INSTDIR\test.ini" "MySectionIni"
|
||||
|
||||
ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
|
||||
StrCmp $1 "" INIDelSuccess
|
||||
MessageBox MB_OK "DeleteINISec failed"
|
||||
INIDelSuccess:
|
||||
|
||||
ClearErrors
|
||||
ReadRegStr $1 HKCR "software\microsoft" xyz_cc_does_not_exist
|
||||
IfErrors 0 NoError
|
||||
MessageBox MB_OK "could not read from HKCR\software\microsoft\xyz_cc_does_not_exist"
|
||||
Goto ErrorYay
|
||||
NoError:
|
||||
MessageBox MB_OK "read '$1' from HKCR\software\microsoft\xyz_cc_does_not_exist"
|
||||
ErrorYay:
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "Test CreateShortCut"
|
||||
|
||||
SectionIn 1 2 3
|
||||
|
||||
Call CSCTest
|
||||
|
||||
SectionEnd
|
||||
|
||||
SectionGroup Group2
|
||||
|
||||
Section "Test Branching"
|
||||
|
||||
BeginTestSection:
|
||||
SectionIn 1 2 3
|
||||
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
IfFileExists "$INSTDIR\LogicLib.nsi" 0 BranchTest69
|
||||
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to overwrite $INSTDIR\LogicLib.nsi?" IDNO NoOverwrite ; skipped if file doesn't exist
|
||||
|
||||
BranchTest69:
|
||||
|
||||
SetOverwrite ifnewer ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
|
||||
|
||||
NoOverwrite:
|
||||
|
||||
File "LogicLib.nsi" ; skipped if answered no
|
||||
SetOverwrite try ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
|
||||
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to skip the rest of this section?" IDYES EndTestBranch
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to go back to the beginning of this section?" IDYES BeginTestSection
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to hide the installer and wait five seconds?" IDNO NoHide
|
||||
|
||||
HideWindow
|
||||
Sleep 5000
|
||||
BringToFront
|
||||
|
||||
NoHide:
|
||||
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to call the function 5 times?" IDNO NoRecurse
|
||||
|
||||
StrCpy $1 "x"
|
||||
|
||||
LoopTest:
|
||||
|
||||
Call myfunc
|
||||
StrCpy $1 "x$1"
|
||||
StrCmp $1 "xxxxxx" 0 LoopTest
|
||||
|
||||
NoRecurse:
|
||||
|
||||
EndTestBranch:
|
||||
|
||||
SectionEnd
|
||||
|
||||
SectionGroupEnd
|
||||
|
||||
Section "Test CopyFiles"
|
||||
|
||||
SectionIn 1 2 3
|
||||
|
||||
SetOutPath $INSTDIR\cpdest
|
||||
CopyFiles "$WINDIR\*.ini" "$INSTDIR\cpdest" 0
|
||||
|
||||
SectionEnd
|
||||
|
||||
SectionGroupEnd
|
||||
|
||||
Section "Test Exec functions" TESTIDX
|
||||
|
||||
SectionIn 1 2 3
|
||||
|
||||
SearchPath $1 notepad.exe
|
||||
|
||||
MessageBox MB_OK "notepad.exe=$1"
|
||||
Exec '"$1"'
|
||||
ExecShell "open" '"$INSTDIR"'
|
||||
Sleep 500
|
||||
BringToFront
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "Test ActiveX control registration"
|
||||
|
||||
SectionIn 2
|
||||
|
||||
UnRegDLL "$SYSDIR\spin32.ocx"
|
||||
Sleep 1000
|
||||
RegDLL "$SYSDIR\spin32.ocx"
|
||||
Sleep 1000
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
|
||||
Function "CSCTest"
|
||||
|
||||
CreateDirectory "$SMPROGRAMS\Big NSIS Test"
|
||||
SetOutPath $INSTDIR ; for working directory
|
||||
CreateShortCut "$SMPROGRAMS\Big NSIS Test\Uninstall BIG NSIS Test.lnk" "$INSTDIR\bt-uninst.exe" ; use defaults for parameters, icon, etc.
|
||||
; this one will use notepad's icon, start it minimized, and give it a hotkey (of Ctrl+Shift+Q)
|
||||
CreateShortCut "$SMPROGRAMS\Big NSIS Test\silent.nsi.lnk" "$INSTDIR\silent.nsi" "" "$WINDIR\notepad.exe" 0 SW_SHOWMINIMIZED CONTROL|SHIFT|Q
|
||||
CreateShortCut "$SMPROGRAMS\Big NSIS Test\TheDir.lnk" "$INSTDIR\" "" "" 0 SW_SHOWMAXIMIZED CONTROL|SHIFT|Z
|
||||
|
||||
FunctionEnd
|
||||
|
||||
Function myfunc
|
||||
|
||||
StrCpy $2 "MyTestVar=$1"
|
||||
MessageBox MB_OK "myfunc: $2"
|
||||
|
||||
FunctionEnd
|
||||
|
||||
Function MyFunctionTest
|
||||
|
||||
ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
|
||||
StrCmp $1 $8 NoFailedMsg
|
||||
MessageBox MB_OK "WriteINIStr failed"
|
||||
|
||||
NoFailedMsg:
|
||||
|
||||
FunctionEnd
|
||||
|
||||
Function .onSelChange
|
||||
|
||||
SectionGetText ${TESTIDX} $0
|
||||
StrCmp $0 "" e
|
||||
SectionSetText ${TESTIDX} ""
|
||||
Goto e2
|
||||
e:
|
||||
SectionSetText ${TESTIDX} "TextInSection"
|
||||
e2:
|
||||
|
||||
FunctionEnd
|
||||
|
||||
;--------------------------------
|
||||
|
||||
; Uninstaller
|
||||
|
||||
UninstallText "This will uninstall example2. Hit next to continue."
|
||||
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-uninstall.ico"
|
||||
|
||||
Section "Uninstall"
|
||||
|
||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest"
|
||||
DeleteRegKey HKLM "SOFTWARE\NSISTest\BigNSISTest"
|
||||
Delete "$INSTDIR\silent.nsi"
|
||||
Delete "$INSTDIR\LogicLib.nsi"
|
||||
Delete "$INSTDIR\bt-uninst.exe"
|
||||
Delete "$INSTDIR\test.ini"
|
||||
Delete "$SMPROGRAMS\Big NSIS Test\*.*"
|
||||
RMDir "$SMPROGRAMS\BiG NSIS Test"
|
||||
|
||||
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR\cpdest?" IDNO NoDelete
|
||||
Delete "$INSTDIR\cpdest\*.*"
|
||||
RMDir "$INSTDIR\cpdest" ; skipped if no
|
||||
NoDelete:
|
||||
|
||||
RMDir "$INSTDIR\MyProjectFamily\MyProject"
|
||||
RMDir "$INSTDIR\MyProjectFamily"
|
||||
RMDir "$INSTDIR"
|
||||
|
||||
IfFileExists "$INSTDIR" 0 NoErrorMsg
|
||||
MessageBox MB_OK "Note: $INSTDIR could not be removed!" IDOK 0 ; skipped if file doesn't exist
|
||||
NoErrorMsg:
|
||||
|
||||
SectionEnd
|
||||
54
samples/NSIS/x64.nsh
Normal file
54
samples/NSIS/x64.nsh
Normal file
@@ -0,0 +1,54 @@
|
||||
; ---------------------
|
||||
; x64.nsh
|
||||
; ---------------------
|
||||
;
|
||||
; A few simple macros to handle installations on x64 machines.
|
||||
;
|
||||
; RunningX64 checks if the installer is running on x64.
|
||||
;
|
||||
; ${If} ${RunningX64}
|
||||
; MessageBox MB_OK "running on x64"
|
||||
; ${EndIf}
|
||||
;
|
||||
; DisableX64FSRedirection disables file system redirection.
|
||||
; EnableX64FSRedirection enables file system redirection.
|
||||
;
|
||||
; SetOutPath $SYSDIR
|
||||
; ${DisableX64FSRedirection}
|
||||
; File some.dll # extracts to C:\Windows\System32
|
||||
; ${EnableX64FSRedirection}
|
||||
; File some.dll # extracts to C:\Windows\SysWOW64
|
||||
;
|
||||
|
||||
!ifndef ___X64__NSH___
|
||||
!define ___X64__NSH___
|
||||
|
||||
!include LogicLib.nsh
|
||||
|
||||
!macro _RunningX64 _a _b _t _f
|
||||
!insertmacro _LOGICLIB_TEMP
|
||||
System::Call kernel32::GetCurrentProcess()i.s
|
||||
System::Call kernel32::IsWow64Process(is,*i.s)
|
||||
Pop $_LOGICLIB_TEMP
|
||||
!insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
|
||||
!macroend
|
||||
|
||||
!define RunningX64 `"" RunningX64 ""`
|
||||
|
||||
!macro DisableX64FSRedirection
|
||||
|
||||
System::Call kernel32::Wow64EnableWow64FsRedirection(i0)
|
||||
|
||||
!macroend
|
||||
|
||||
!define DisableX64FSRedirection "!insertmacro DisableX64FSRedirection"
|
||||
|
||||
!macro EnableX64FSRedirection
|
||||
|
||||
System::Call kernel32::Wow64EnableWow64FsRedirection(i1)
|
||||
|
||||
!macroend
|
||||
|
||||
!define EnableX64FSRedirection "!insertmacro EnableX64FSRedirection"
|
||||
|
||||
!endif # !___X64__NSH___
|
||||
48
samples/OCaml/example.eliom
Normal file
48
samples/OCaml/example.eliom
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
{shared{
|
||||
|
||||
open Eliom_content
|
||||
open Html5.D
|
||||
open Eliom_parameter
|
||||
|
||||
}}
|
||||
|
||||
{server{
|
||||
|
||||
module Example =
|
||||
Eliom_registration.App
|
||||
(struct
|
||||
let application_name = "example"
|
||||
end)
|
||||
|
||||
let main =
|
||||
Eliom_service.service
|
||||
~path:[]
|
||||
~get_params:unit
|
||||
()
|
||||
|
||||
}}
|
||||
|
||||
{client{
|
||||
|
||||
let hello_popup () =
|
||||
Dom_html.window##alert(Js.string ("Hello Popup!"))
|
||||
|
||||
}}
|
||||
|
||||
{server{
|
||||
|
||||
let _ =
|
||||
|
||||
Example.register
|
||||
~service:main
|
||||
(fun () () ->
|
||||
Lwt.return
|
||||
(html
|
||||
(head (title (pcdata "Hello World of Ocsigen")) [])
|
||||
(body [h1 [pcdata "Hello World!"];
|
||||
p [pcdata "Welcome to my first Ocsigen website."];
|
||||
h2 ~a:[a_onclick {{ hello_popup () }}]
|
||||
[pcdata "Click me!"]])))
|
||||
|
||||
}}
|
||||
44
samples/PogoScript/squashy.pogo
Normal file
44
samples/PogoScript/squashy.pogo
Normal file
@@ -0,0 +1,44 @@
|
||||
httpism = require 'httpism'
|
||||
async = require 'async'
|
||||
resolve = require 'url'.resolve
|
||||
|
||||
exports.squash (url) ! =
|
||||
html = httpism.get ! (url).body
|
||||
squash html ! (html, url)
|
||||
|
||||
squash html (html, url, callback) =
|
||||
replacements = sort (links in (html).concat(scripts in (html)))
|
||||
for each @(r) in (replacements) @{ r.url = resolve(url, r.href) }
|
||||
async.map (replacements, get) @(err, requested)
|
||||
callback (err, replace (requested) in (html))
|
||||
|
||||
sort (replacements) =
|
||||
replacements.sort @(a, b) @{ a.index - b.index }
|
||||
|
||||
get (replacement) =
|
||||
replacement.body = httpism.get ! (replacement.url).body
|
||||
replacement
|
||||
|
||||
replace (replacements) in (html) =
|
||||
i = 0
|
||||
parts = ""
|
||||
for each @(rep) in (replacements)
|
||||
parts := "#(parts)#(html.substring(i, rep.index))<#(rep.tag)>#(rep.body)</#(rep.tag)>"
|
||||
i := rep.index + rep.length
|
||||
|
||||
parts + html.substr(i)
|
||||
|
||||
links in (html) =
|
||||
link reg = r/<link\s[^>]*href=["']?([^"']+)["'][^\>]*(\/\>|\>\s*\<\/link\>)/gi
|
||||
elements in (html) matching (link reg) as 'style'
|
||||
|
||||
scripts in (html) =
|
||||
script reg = r/<script\s[^>]*src=["']?([^"']+)["'][^\>]*(\/\>|\>\s*\<\/script\>)/gi
|
||||
elements in (html) matching (script reg) as 'script'
|
||||
|
||||
elements in (html) matching (reg) as (tag) =
|
||||
elements = []
|
||||
while (m = reg.exec (html))
|
||||
elements.push { tag = tag, index = m.index, length = m.0.length, href = m.1 }
|
||||
|
||||
elements
|
||||
36
samples/Processing/hello.pde
Normal file
36
samples/Processing/hello.pde
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Shape Primitives.
|
||||
*
|
||||
* The basic shape primitive functions are triangle(),
|
||||
* rect(), quad(), ellipse(), and arc(). Squares are made
|
||||
* with rect() and circles are made with ellipse(). Each
|
||||
* of these functions requires a number of parameters to
|
||||
* determine the shape's position and size.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360);
|
||||
background(0);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
fill(204);
|
||||
triangle(18, 18, 18, 360, 81, 360);
|
||||
|
||||
fill(102);
|
||||
rect(81, 81, 63, 63);
|
||||
|
||||
fill(204);
|
||||
quad(189, 18, 216, 18, 216, 360, 144, 360);
|
||||
|
||||
fill(255);
|
||||
ellipse(252, 144, 72, 72);
|
||||
|
||||
fill(204);
|
||||
triangle(288, 18, 351, 360, 288, 360);
|
||||
|
||||
fill(255);
|
||||
arc(479, 300, 280, 280, PI, TWO_PI);
|
||||
}
|
||||
|
||||
96
samples/Ragel in Ruby Host/ephemeris_parser.rl
Normal file
96
samples/Ragel in Ruby Host/ephemeris_parser.rl
Normal file
@@ -0,0 +1,96 @@
|
||||
=begin
|
||||
%%{
|
||||
|
||||
machine ephemeris_parser;
|
||||
|
||||
action mark { mark = p }
|
||||
|
||||
action parse_start_time {
|
||||
parser.start_time = data[mark..p].pack('c*')
|
||||
}
|
||||
|
||||
action parse_stop_time {
|
||||
parser.stop_time = data[mark..p].pack('c*')
|
||||
}
|
||||
|
||||
action parse_step_size {
|
||||
parser.step_size = data[mark..p].pack('c*')
|
||||
}
|
||||
|
||||
action parse_ephemeris_table {
|
||||
fhold;
|
||||
parser.ephemeris_table = data[mark..p].pack('c*')
|
||||
}
|
||||
|
||||
ws = [ \t\r\n];
|
||||
|
||||
adbc = ('A.D.'|'B.C.');
|
||||
year = digit{4};
|
||||
month = upper lower{2};
|
||||
date = digit{2};
|
||||
hours = digit{2};
|
||||
minutes = digit{2};
|
||||
seconds = digit{2} '.' digit{4};
|
||||
tz = 'UT';
|
||||
datetime = adbc ' ' year '-' month '-' date ' ' hours ':' minutes ':' seconds ' ' tz;
|
||||
|
||||
time_unit = ('minute' [s]? | 'calendar year' [s]?);
|
||||
|
||||
soe = '$$SOE' '\n';
|
||||
eoe = '$$EOE' '\n';
|
||||
ephemeris_table = (alnum | ws | [*-./:])*;
|
||||
|
||||
start_time = 'Start time' ' '* ':' ' ' datetime >mark %parse_start_time space* '\n';
|
||||
stop_time = 'Stop time' ' '* ':' ' ' datetime >mark %parse_stop_time space* '\n';
|
||||
step_size = 'Step-size' ' '* ':' ' ' (digit+ ' '* time_unit) >mark $parse_step_size '\n';
|
||||
|
||||
ephemeris = soe ephemeris_table >mark %parse_ephemeris_table eoe;
|
||||
|
||||
main := (
|
||||
any*
|
||||
start_time
|
||||
stop_time
|
||||
step_size
|
||||
any*
|
||||
ephemeris
|
||||
any*
|
||||
);
|
||||
|
||||
}%%
|
||||
=end
|
||||
|
||||
require 'date'
|
||||
|
||||
module Tengai
|
||||
EPHEMERIS_DATA = Struct.new(:start_time, :stop_time, :step_size, :ephemeris_table).freeze
|
||||
|
||||
class EphemerisParser < EPHEMERIS_DATA
|
||||
def self.parse(data)
|
||||
parser = new
|
||||
data = data.unpack('c*') if data.is_a? String
|
||||
eof = data.length
|
||||
|
||||
%% write init;
|
||||
%% write exec;
|
||||
|
||||
parser
|
||||
end
|
||||
|
||||
def start_time=(time)
|
||||
super parse_time(time)
|
||||
end
|
||||
|
||||
def stop_time=(time)
|
||||
super parse_time(time)
|
||||
end
|
||||
|
||||
%% write data;
|
||||
|
||||
# % fix syntax highlighting
|
||||
|
||||
private
|
||||
def parse_time(time)
|
||||
DateTime.parse(time)
|
||||
end
|
||||
end
|
||||
end
|
||||
69
samples/Ragel in Ruby Host/simple_scanner.rl
Normal file
69
samples/Ragel in Ruby Host/simple_scanner.rl
Normal file
@@ -0,0 +1,69 @@
|
||||
=begin
|
||||
%%{
|
||||
machine simple_scanner;
|
||||
|
||||
action Emit {
|
||||
emit data[(ts+8)..(te-7)].pack('c*')
|
||||
}
|
||||
|
||||
foo = 'STARTFOO' any+ :>> 'ENDFOO';
|
||||
|
||||
main := |*
|
||||
foo => Emit;
|
||||
any;
|
||||
*|;
|
||||
}%%
|
||||
=end
|
||||
|
||||
|
||||
# Scans a file for "STARTFOO[...]ENDFOO" blocks and outputs their contents.
|
||||
#
|
||||
# ENV['CHUNK_SIZE'] determines how much of the file to read in at a time, allowing you to control memory usage.
|
||||
#
|
||||
# Uses ragel's scanner functionality even though it's not strictly necessary.
|
||||
class SimpleScanner
|
||||
attr_reader :path
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
%% write data;
|
||||
# % (this fixes syntax highlighting)
|
||||
end
|
||||
|
||||
def emit(foo)
|
||||
$stdout.puts foo
|
||||
end
|
||||
|
||||
def perform
|
||||
# So that ragel doesn't try to get it from data.length
|
||||
pe = :ignored
|
||||
eof = :ignored
|
||||
|
||||
%% write init;
|
||||
# % (this fixes syntax highlighting)
|
||||
|
||||
leftover = []
|
||||
|
||||
File.open(path) do |f|
|
||||
while chunk = f.read(ENV['CHUNK_SIZE'].to_i)
|
||||
data = leftover + chunk.unpack('c*')
|
||||
p ||= 0
|
||||
pe = data.length
|
||||
|
||||
%% write exec;
|
||||
# % (this fixes syntax highlighting)
|
||||
if ts
|
||||
leftover = data[ts..pe]
|
||||
p = p - ts
|
||||
ts = 0
|
||||
else
|
||||
leftover = []
|
||||
p = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
s = SimpleScanner.new ARGV[0]
|
||||
s.perform
|
||||
73
samples/Ragel in Ruby Host/simple_tokenizer.rl
Normal file
73
samples/Ragel in Ruby Host/simple_tokenizer.rl
Normal file
@@ -0,0 +1,73 @@
|
||||
=begin
|
||||
%%{
|
||||
machine simple_tokenizer;
|
||||
|
||||
action MyTs {
|
||||
my_ts = p
|
||||
}
|
||||
action MyTe {
|
||||
my_te = p
|
||||
}
|
||||
action Emit {
|
||||
emit data[my_ts...my_te].pack('c*')
|
||||
my_ts = nil
|
||||
my_te = nil
|
||||
}
|
||||
|
||||
foo = 'STARTFOO' any+ >MyTs :>> 'ENDFOO' >MyTe %Emit;
|
||||
main := ( foo | any+ )*;
|
||||
|
||||
}%%
|
||||
=end
|
||||
|
||||
# Scans a file for "STARTFOO[...]ENDFOO" blocks and outputs their contents.
|
||||
#
|
||||
# ENV['CHUNK_SIZE'] determines how much of the file to read in at a time, allowing you to control memory usage.
|
||||
#
|
||||
# Does not use ragel's scanner functionality because no backtracking is needed.
|
||||
class SimpleTokenizer
|
||||
attr_reader :path
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
%% write data;
|
||||
# % (this fixes syntax highlighting)
|
||||
end
|
||||
|
||||
def emit(foo)
|
||||
$stdout.puts foo
|
||||
end
|
||||
|
||||
def perform
|
||||
# So that ragel doesn't try to get it from data.length
|
||||
pe = :ignored
|
||||
eof = :ignored
|
||||
|
||||
%% write init;
|
||||
# % (this fixes syntax highlighting)
|
||||
|
||||
leftover = []
|
||||
my_ts = nil
|
||||
my_te = nil
|
||||
|
||||
File.open(path) do |f|
|
||||
while chunk = f.read(ENV['CHUNK_SIZE'].to_i)
|
||||
data = leftover + chunk.unpack('c*')
|
||||
p = 0
|
||||
pe = data.length
|
||||
%% write exec;
|
||||
# % (this fixes syntax highlighting)
|
||||
if my_ts
|
||||
leftover = data[my_ts..-1]
|
||||
my_te = my_te - my_ts if my_te
|
||||
my_ts = 0
|
||||
else
|
||||
leftover = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
s = SimpleTokenizer.new ARGV[0]
|
||||
s.perform
|
||||
27
samples/Ruby/jenkinsci.pluginspec
Normal file
27
samples/Ruby/jenkinsci.pluginspec
Normal file
@@ -0,0 +1,27 @@
|
||||
Jenkins::Plugin::Specification.new do |plugin|
|
||||
plugin.name = "foo"
|
||||
plugin.display_name = "Foo Plugin"
|
||||
plugin.version = '0.0.1'
|
||||
plugin.description = 'TODO: enter description here'
|
||||
|
||||
# You should create a wiki-page for your plugin when you publish it, see
|
||||
# https://wiki.jenkins-ci.org/display/JENKINS/Hosting+Plugins#HostingPlugins-AddingaWikipage
|
||||
# This line makes sure it's listed in your POM.
|
||||
plugin.url = 'https://wiki.jenkins-ci.org/display/JENKINS/Foo+Plugin'
|
||||
|
||||
# The first argument is your user name for jenkins-ci.org.
|
||||
plugin.developed_by "david.calavera", "David Calavera <david.calavera@gmail.com>"
|
||||
|
||||
# This specifies where your code is hosted.
|
||||
# Alternatives include:
|
||||
# :github => 'myuser/foo-plugin' (without myuser it defaults to jenkinsci)
|
||||
# :git => 'git://repo.or.cz/foo-plugin.git'
|
||||
# :svn => 'https://svn.jenkins-ci.org/trunk/hudson/plugins/foo-plugin'
|
||||
plugin.uses_repository :github => "foo-plugin"
|
||||
|
||||
# This is a required dependency for every ruby plugin.
|
||||
plugin.depends_on 'ruby-runtime', '0.10'
|
||||
|
||||
# This is a sample dependency for a Jenkins plugin, 'git'.
|
||||
#plugin.depends_on 'git', '1.1.11'
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
fn main() {
|
||||
log "Hello, world!";
|
||||
}
|
||||
1212
samples/Rust/task.rs
Normal file
1212
samples/Rust/task.rs
Normal file
File diff suppressed because it is too large
Load Diff
51
samples/SuperCollider/example.scd
Normal file
51
samples/SuperCollider/example.scd
Normal file
@@ -0,0 +1,51 @@
|
||||
// SuperCollider Examples
|
||||
|
||||
//boot server
|
||||
s.boot;
|
||||
|
||||
// SC as system for sound synthesis and sound processing
|
||||
|
||||
|
||||
// patching synth moduls by writing synth defs:
|
||||
|
||||
(
|
||||
SynthDef("mod", {
|
||||
var sig, resfreq;
|
||||
sig = Saw.ar(100);
|
||||
resfreq = SinOsc.kr(2) * 200 + 500;
|
||||
sig = RLPF.ar(sig, resfreq, 0.1);
|
||||
sig = sig * 0.3;
|
||||
Out.ar(0, sig);
|
||||
}).play;
|
||||
)
|
||||
|
||||
// SuperCollider: a powerful expressive DSP language:
|
||||
|
||||
(
|
||||
30.do { arg i;
|
||||
{ Pan2.ar(
|
||||
SinOsc.ar(exprand(100.0, 3000.0) * LFNoise2.kr(rrand(0.1, 0.2)).range(0.95, 1.1), 0,
|
||||
LFNoise2.kr(rrand(0.3, 0.7)).range(0,0.5) ** 4),
|
||||
1.0.rand2)
|
||||
}.play
|
||||
}
|
||||
)
|
||||
|
||||
// plot envelopes
|
||||
a = Env.perc(0.05, 1, 1, -4);
|
||||
b = a.delay(2);
|
||||
a.test.plot;
|
||||
b.test.plot;
|
||||
|
||||
a = Env([0.5, 1, 0], [1, 1]).plot;
|
||||
a.delay(1).plot;
|
||||
|
||||
// examples asStream function
|
||||
(
|
||||
{
|
||||
e = Env.sine.asStream;
|
||||
5.do({
|
||||
e.next.postln;
|
||||
0.25.wait;
|
||||
})}.fork
|
||||
)
|
||||
80
samples/TXL/Cal.txl
Normal file
80
samples/TXL/Cal.txl
Normal file
@@ -0,0 +1,80 @@
|
||||
% Calculator.Txl - simple numerical expression evaluator
|
||||
|
||||
% Part I. Syntax specification
|
||||
define program
|
||||
[expression]
|
||||
end define
|
||||
|
||||
define expression
|
||||
[term]
|
||||
| [expression] [addop] [term]
|
||||
end define
|
||||
|
||||
define term
|
||||
[primary]
|
||||
| [term] [mulop] [primary]
|
||||
end define
|
||||
|
||||
define primary
|
||||
[number]
|
||||
| ( [expression] )
|
||||
end define
|
||||
|
||||
define addop
|
||||
'+
|
||||
| '-
|
||||
end define
|
||||
|
||||
define mulop
|
||||
'*
|
||||
| '/
|
||||
end define
|
||||
|
||||
|
||||
% Part 2. Transformation rules
|
||||
rule main
|
||||
replace [expression]
|
||||
E [expression]
|
||||
construct NewE [expression]
|
||||
E [resolveAddition] [resolveSubtraction] [resolveMultiplication]
|
||||
[resolveDivision] [resolveParentheses]
|
||||
where not
|
||||
NewE [= E]
|
||||
by
|
||||
NewE
|
||||
end rule
|
||||
|
||||
rule resolveAddition
|
||||
replace [expression]
|
||||
N1 [number] + N2 [number]
|
||||
by
|
||||
N1 [+ N2]
|
||||
end rule
|
||||
|
||||
rule resolveSubtraction
|
||||
replace [expression]
|
||||
N1 [number] - N2 [number]
|
||||
by
|
||||
N1 [- N2]
|
||||
end rule
|
||||
|
||||
rule resolveMultiplication
|
||||
replace [term]
|
||||
N1 [number] * N2 [number]
|
||||
by
|
||||
N1 [* N2]
|
||||
end rule
|
||||
|
||||
rule resolveDivision
|
||||
replace [term]
|
||||
N1 [number] / N2 [number]
|
||||
by
|
||||
N1 [/ N2]
|
||||
end rule
|
||||
|
||||
rule resolveParentheses
|
||||
replace [primary]
|
||||
( N [number] )
|
||||
by
|
||||
N
|
||||
end rule
|
||||
86
samples/Text/cube.stl
Normal file
86
samples/Text/cube.stl
Normal file
@@ -0,0 +1,86 @@
|
||||
solid
|
||||
facet normal 0.000000E+00 -1.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 -2.450000E+01 3.100000E+01
|
||||
vertex -1.850000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex 1.250000E+01 -2.450000E+01 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 -1.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 -2.450000E+01 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex 1.250000E+01 -2.450000E+01 3.100000E+01
|
||||
endloop
|
||||
endfacet
|
||||
facet normal -1.000000E+00 0.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 3.100000E+01
|
||||
vertex -1.850000E+01 6.500000E+00 -1.000000E-03
|
||||
vertex -1.850000E+01 -2.450000E+01 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal -1.000000E+00 0.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 3.100000E+01
|
||||
vertex -1.850000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex -1.850000E+01 -2.450000E+01 3.100000E+01
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 1.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 -1.000000E-03
|
||||
vertex -1.850000E+01 6.500000E+00 3.100000E+01
|
||||
vertex 1.250000E+01 6.500000E+00 3.100000E+01
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 1.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 -1.000000E-03
|
||||
vertex 1.250000E+01 6.500000E+00 3.100000E+01
|
||||
vertex 1.250000E+01 6.500000E+00 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 1.000000E+00 0.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex 1.250000E+01 6.500000E+00 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 1.000000E+00 0.000000E+00 0.000000E+00
|
||||
outer loop
|
||||
vertex 1.250000E+01 6.500000E+00 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex 1.250000E+01 6.500000E+00 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 0.000000E+00 -1.000000E+00
|
||||
outer loop
|
||||
vertex 1.250000E+01 6.500000E+00 -1.000000E-03
|
||||
vertex 1.250000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex -1.850000E+01 -2.450000E+01 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 0.000000E+00 -1.000000E+00
|
||||
outer loop
|
||||
vertex 1.250000E+01 6.500000E+00 -1.000000E-03
|
||||
vertex -1.850000E+01 -2.450000E+01 -1.000000E-03
|
||||
vertex -1.850000E+01 6.500000E+00 -1.000000E-03
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 0.000000E+00 1.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 3.100000E+01
|
||||
vertex -1.850000E+01 -2.450000E+01 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 3.100000E+01
|
||||
endloop
|
||||
endfacet
|
||||
facet normal 0.000000E+00 0.000000E+00 1.000000E+00
|
||||
outer loop
|
||||
vertex -1.850000E+01 6.500000E+00 3.100000E+01
|
||||
vertex 1.250000E+01 -2.450000E+01 3.100000E+01
|
||||
vertex 1.250000E+01 6.500000E+00 3.100000E+01
|
||||
endloop
|
||||
endfacet
|
||||
endsolid
|
||||
28
samples/TypeScript/classes.ts
Normal file
28
samples/TypeScript/classes.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
class Animal {
|
||||
constructor(public name) { }
|
||||
move(meters) {
|
||||
alert(this.name + " moved " + meters + "m.");
|
||||
}
|
||||
}
|
||||
|
||||
class Snake extends Animal {
|
||||
constructor(name) { super(name); }
|
||||
move() {
|
||||
alert("Slithering...");
|
||||
super.move(5);
|
||||
}
|
||||
}
|
||||
|
||||
class Horse extends Animal {
|
||||
constructor(name) { super(name); }
|
||||
move() {
|
||||
alert("Galloping...");
|
||||
super.move(45);
|
||||
}
|
||||
}
|
||||
|
||||
var sam = new Snake("Sammy the Python")
|
||||
var tom: Animal = new Horse("Tommy the Palomino")
|
||||
|
||||
sam.move()
|
||||
tom.move(34)
|
||||
0
samples/TypeScript/empty.ts
Normal file
0
samples/TypeScript/empty.ts
Normal file
1
samples/TypeScript/hello.ts
Normal file
1
samples/TypeScript/hello.ts
Normal file
@@ -0,0 +1 @@
|
||||
console.log "Hello, World!"
|
||||
11
samples/XProc/xproc.xpl
Normal file
11
samples/XProc/xproc.xpl
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
|
||||
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
|
||||
<p:input port="source">
|
||||
<p:inline>
|
||||
<doc>Hello world!</doc>
|
||||
</p:inline>
|
||||
</p:input>
|
||||
<p:output port="result"/>
|
||||
<p:identity/>
|
||||
</p:declare-step>
|
||||
93
samples/Xtend/BasicExpressions.xtend
Normal file
93
samples/Xtend/BasicExpressions.xtend
Normal file
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package example2
|
||||
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.*
|
||||
|
||||
|
||||
class BasicExpressions {
|
||||
|
||||
@Test def void literals() {
|
||||
// string literals work with single or double quotes
|
||||
assertEquals('Hello', "Hello")
|
||||
|
||||
// number literals (big decimals in this case)
|
||||
assertEquals(42, 20 + 20 + 1 * 2)
|
||||
assertEquals(42.00bd, 0.00bd + 42bd)
|
||||
|
||||
// boolean literals
|
||||
assertEquals(true, !false)
|
||||
|
||||
// class literals
|
||||
assertEquals(getClass(), typeof(BasicExpressions))
|
||||
}
|
||||
|
||||
@Test def void collections() {
|
||||
// There are various static methods to create collections
|
||||
// and numerous extension methods which make working with them
|
||||
// convenient.
|
||||
val list = newArrayList('Hello', 'World')
|
||||
assertEquals('HELLO', list.map[toUpperCase].head)
|
||||
|
||||
val set = newHashSet(1, 3, 5)
|
||||
assertEquals(2, set.filter[ it >= 3].size)
|
||||
|
||||
val map = newHashMap('one' -> 1, 'two' -> 2, 'three' -> 3)
|
||||
assertEquals( 2 , map.get('two'))
|
||||
}
|
||||
|
||||
@Test def void controlStructures() {
|
||||
// 'if' looks like in Java
|
||||
if ('text'.length == 4) {
|
||||
// but it's an expression so it can be used in more flexible ways:
|
||||
assertEquals( 42 , if ('foo' != 'bar') 42 else -24 )
|
||||
} else {
|
||||
fail('Never happens!')
|
||||
}
|
||||
|
||||
// in a switch the first match wins
|
||||
switch (t : 'text') {
|
||||
// use predicates
|
||||
case t.length > 8 :
|
||||
fail('Never happens!')
|
||||
// use equals
|
||||
case 'text' :
|
||||
assertTrue(true)
|
||||
default :
|
||||
fail('never happens!')
|
||||
}
|
||||
|
||||
// switch also supports type guards, which provide a safe
|
||||
// and convenient alternative to Java's 'instanceof'-cascades.
|
||||
val Object someValue = 'a string typed to Object'
|
||||
assertEquals('string',
|
||||
switch someValue {
|
||||
Number : 'number'
|
||||
String : 'string'
|
||||
})
|
||||
}
|
||||
|
||||
@Test def void loops() {
|
||||
// for loop
|
||||
var counter = 1
|
||||
for (i : 1 .. 10) {
|
||||
assertEquals(counter, i)
|
||||
counter = counter + 1
|
||||
}
|
||||
|
||||
// while loop
|
||||
val iterator = newArrayList(1,2,3,4,5).iterator
|
||||
counter = 1
|
||||
while(iterator.hasNext) {
|
||||
val i = iterator.next
|
||||
assertEquals(counter, i)
|
||||
counter = counter + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
60
samples/Xtend/Movies.xtend
Normal file
60
samples/Xtend/Movies.xtend
Normal file
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Author - Sven Efftinge
|
||||
*******************************************************************************/
|
||||
package example6
|
||||
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.*
|
||||
import java.io.FileReader
|
||||
import java.util.Set
|
||||
import static extension com.google.common.io.CharStreams.*
|
||||
|
||||
class Movies {
|
||||
|
||||
/**
|
||||
* @return the total number of action movies
|
||||
*/
|
||||
@Test def void numberOfActionMovies() {
|
||||
assertEquals(828, movies.filter[categories.contains('Action')].size)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the year the best rated movie of 80ies (1980-1989) was released.
|
||||
*/
|
||||
@Test def void yearOfBestMovieFrom80ies() {
|
||||
assertEquals(1989, movies.filter[(1980..1989).contains(year)].sortBy[rating].last.year)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sum of the number of votes of the two top rated movies.
|
||||
*/
|
||||
@Test def void sumOfVotesOfTop2() {
|
||||
val long movies = movies.sortBy[-rating].take(2).map[numberOfVotes].reduce[a, b| a + b]
|
||||
assertEquals(47_229, movies)
|
||||
}
|
||||
|
||||
val movies = new FileReader('data.csv').readLines.map[ line |
|
||||
val segments = line.split(' ').iterator
|
||||
return new Movie(
|
||||
segments.next,
|
||||
Integer::parseInt(segments.next),
|
||||
Double::parseDouble(segments.next),
|
||||
Long::parseLong(segments.next),
|
||||
segments.toSet
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
@Data class Movie {
|
||||
String title
|
||||
int year
|
||||
double rating
|
||||
long numberOfVotes
|
||||
Set<String> categories
|
||||
}
|
||||
76
samples/edn/bigger-than-pluto.edn
Normal file
76
samples/edn/bigger-than-pluto.edn
Normal file
@@ -0,0 +1,76 @@
|
||||
[{:db/id #db/id [db.part/db]
|
||||
:db/ident :object/name
|
||||
:db/doc "Name of a Solar System object."
|
||||
:db/valueType :db.type/string
|
||||
:db/index true
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db.install/_attribute :db.part/db}
|
||||
{:db/id #db/id [db.part/db]
|
||||
:db/ident :object/meanRadius
|
||||
:db/doc "Mean radius of an object."
|
||||
:db/index true
|
||||
:db/valueType :db.type/double
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db.install/_attribute :db.part/db}
|
||||
{:db/id #db/id [db.part/db]
|
||||
:db/ident :data/source
|
||||
:db/doc "Source of the data in a transaction."
|
||||
:db/valueType :db.type/string
|
||||
:db/index true
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db.install/_attribute :db.part/db}]
|
||||
[{:db/id #db/id [db.part/tx]
|
||||
:db/doc "Solar system objects bigger than Pluto."}
|
||||
{:db/id #db/id [db.part/tx]
|
||||
:data/source "http://en.wikipedia.org/wiki/List_of_Solar_System_objects_by_size"}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Sun"
|
||||
:object/meanRadius 696000.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Jupiter"
|
||||
:object/meanRadius 69911.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Saturn"
|
||||
:object/meanRadius 58232.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Uranus"
|
||||
:object/meanRadius 25362.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Neptune"
|
||||
:object/meanRadius 24622.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Earth"
|
||||
:object/meanRadius 6371.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Venus"
|
||||
:object/meanRadius 6051.8}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Mars"
|
||||
:object/meanRadius 3390.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Ganymede"
|
||||
:object/meanRadius 2631.2}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Titan"
|
||||
:object/meanRadius 2576.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Mercury"
|
||||
:object/meanRadius 2439.7}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Callisto"
|
||||
:object/meanRadius 2410.3}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Io"
|
||||
:object/meanRadius 1821.5}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Moon"
|
||||
:object/meanRadius 1737.1}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Europa"
|
||||
:object/meanRadius 1561.0}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Triton"
|
||||
:object/meanRadius 1353.4}
|
||||
{:db/id #db/id [db.part/user]
|
||||
:object/name "Eris"
|
||||
:object/meanRadius 1163.0}]
|
||||
98
samples/fish/config.fish
Normal file
98
samples/fish/config.fish
Normal file
@@ -0,0 +1,98 @@
|
||||
#
|
||||
# Main file for fish command completions. This file contains various
|
||||
# common helper functions for the command completions. All actual
|
||||
# completions are located in the completions subdirectory.
|
||||
#
|
||||
|
||||
#
|
||||
# Set default field separators
|
||||
#
|
||||
|
||||
set -g IFS \n\ \t
|
||||
|
||||
#
|
||||
# Set default search paths for completions and shellscript functions
|
||||
# unless they already exist
|
||||
#
|
||||
|
||||
set -l configdir ~/.config
|
||||
|
||||
if set -q XDG_CONFIG_HOME
|
||||
set configdir $XDG_CONFIG_HOME
|
||||
end
|
||||
|
||||
# __fish_datadir, __fish_sysconfdir, __fish_help_dir, __fish_bin_dir
|
||||
# are expected to have been set up by read_init from fish.cpp
|
||||
|
||||
# Set up function and completion paths. Make sure that the fish
|
||||
# default functions/completions are included in the respective path.
|
||||
|
||||
if not set -q fish_function_path
|
||||
set fish_function_path $configdir/fish/functions $__fish_sysconfdir/functions $__fish_datadir/functions
|
||||
end
|
||||
|
||||
if not contains $__fish_datadir/functions $fish_function_path
|
||||
set fish_function_path[-1] $__fish_datadir/functions
|
||||
end
|
||||
|
||||
if not set -q fish_complete_path
|
||||
set fish_complete_path $configdir/fish/completions $__fish_sysconfdir/completions $__fish_datadir/completions
|
||||
end
|
||||
|
||||
if not contains $__fish_datadir/completions $fish_complete_path
|
||||
set fish_complete_path[-1] $__fish_datadir/completions
|
||||
end
|
||||
|
||||
#
|
||||
# This is a Solaris-specific test to modify the PATH so that
|
||||
# Posix-conformant tools are used by default. It is separate from the
|
||||
# other PATH code because this directory needs to be prepended, not
|
||||
# appended, since it contains POSIX-compliant replacements for various
|
||||
# system utilities.
|
||||
#
|
||||
|
||||
if test -d /usr/xpg4/bin
|
||||
if not contains /usr/xpg4/bin $PATH
|
||||
set PATH /usr/xpg4/bin $PATH
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Add a few common directories to path, if they exists. Note that pure
|
||||
# console programs like makedep sometimes live in /usr/X11R6/bin, so we
|
||||
# want this even for text-only terminals.
|
||||
#
|
||||
|
||||
set -l path_list /bin /usr/bin /usr/X11R6/bin /usr/local/bin $__fish_bin_dir
|
||||
|
||||
# Root should also have the sbin directories in the path
|
||||
switch $USER
|
||||
case root
|
||||
set path_list $path_list /sbin /usr/sbin /usr/local/sbin
|
||||
end
|
||||
|
||||
for i in $path_list
|
||||
if not contains $i $PATH
|
||||
if test -d $i
|
||||
set PATH $PATH $i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Launch debugger on SIGTRAP
|
||||
#
|
||||
function fish_sigtrap_handler --on-signal TRAP --no-scope-shadowing --description "Signal handler for the TRAP signal. Lanches a debug prompt."
|
||||
breakpoint
|
||||
end
|
||||
|
||||
#
|
||||
# Whenever a prompt is displayed, make sure that interactive
|
||||
# mode-specific initializations have been performed.
|
||||
# This handler removes itself after it is first called.
|
||||
#
|
||||
function __fish_on_interactive --on-event fish_prompt
|
||||
__fish_config_interactive
|
||||
functions -e __fish_on_interactive
|
||||
end
|
||||
|
||||
28
samples/fish/eval.fish
Normal file
28
samples/fish/eval.fish
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
function eval -S -d "Evaluate parameters as a command"
|
||||
|
||||
# If we are in an interactive shell, eval should enable full
|
||||
# job control since it should behave like the real code was
|
||||
# executed. If we don't do this, commands that expect to be
|
||||
# used interactively, like less, wont work using eval.
|
||||
|
||||
set -l mode
|
||||
if status --is-interactive-job-control
|
||||
set mode interactive
|
||||
else
|
||||
if status --is-full-job-control
|
||||
set mode full
|
||||
else
|
||||
set mode none
|
||||
end
|
||||
end
|
||||
if status --is-interactive
|
||||
status --job-control full
|
||||
end
|
||||
|
||||
echo "begin; $argv ;end eval2_inner <&3 3<&-" | . 3<&0
|
||||
set -l res $status
|
||||
|
||||
status --job-control $mode
|
||||
return $res
|
||||
end
|
||||
101
samples/fish/funced.fish
Normal file
101
samples/fish/funced.fish
Normal file
@@ -0,0 +1,101 @@
|
||||
function funced --description 'Edit function definition'
|
||||
set -l editor $EDITOR
|
||||
set -l interactive
|
||||
set -l funcname
|
||||
while set -q argv[1]
|
||||
switch $argv[1]
|
||||
case -h --help
|
||||
__fish_print_help funced
|
||||
return 0
|
||||
|
||||
case -e --editor
|
||||
set editor $argv[2]
|
||||
set -e argv[2]
|
||||
|
||||
case -i --interactive
|
||||
set interactive 1
|
||||
|
||||
case --
|
||||
set funcname $funcname $argv[2]
|
||||
set -e argv[2]
|
||||
|
||||
case '-*'
|
||||
set_color red
|
||||
printf (_ "%s: Unknown option %s\n") funced $argv[1]
|
||||
set_color normal
|
||||
return 1
|
||||
|
||||
case '*' '.*'
|
||||
set funcname $funcname $argv[1]
|
||||
end
|
||||
set -e argv[1]
|
||||
end
|
||||
|
||||
if begin; set -q funcname[2]; or not test "$funcname[1]"; end
|
||||
set_color red
|
||||
_ "funced: You must specify one function name
|
||||
"
|
||||
set_color normal
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l init
|
||||
switch $funcname
|
||||
case '-*'
|
||||
set init function -- $funcname\n\nend
|
||||
case '*'
|
||||
set init function $funcname\n\nend
|
||||
end
|
||||
|
||||
# Break editor up to get its first command (i.e. discard flags)
|
||||
if test -n "$editor"
|
||||
set -l editor_cmd
|
||||
eval set editor_cmd $editor
|
||||
if not type -f "$editor_cmd[1]" >/dev/null
|
||||
_ "funced: The value for \$EDITOR '$editor' could not be used because the command '$editor_cmd[1]' could not be found
|
||||
"
|
||||
set editor fish
|
||||
end
|
||||
end
|
||||
|
||||
# If no editor is specified, use fish
|
||||
if test -z "$editor"
|
||||
set editor fish
|
||||
end
|
||||
|
||||
if begin; set -q interactive[1]; or test "$editor" = fish; end
|
||||
set -l IFS
|
||||
if functions -q -- $funcname
|
||||
# Shadow IFS here to avoid array splitting in command substitution
|
||||
set init (functions -- $funcname | fish_indent --no-indent)
|
||||
end
|
||||
|
||||
set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)'
|
||||
# Unshadow IFS since the fish_title breaks otherwise
|
||||
set -e IFS
|
||||
if read -p $prompt -c "$init" -s cmd
|
||||
# Shadow IFS _again_ to avoid array splitting in command substitution
|
||||
set -l IFS
|
||||
eval (echo -n $cmd | fish_indent)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
set -q TMPDIR; or set -l TMPDIR /tmp
|
||||
set -l tmpname (printf "$TMPDIR/fish_funced_%d_%d.fish" %self (random))
|
||||
while test -f $tmpname
|
||||
set tmpname (printf "$TMPDIR/fish_funced_%d_%d.fish" %self (random))
|
||||
end
|
||||
|
||||
if functions -q -- $funcname
|
||||
functions -- $funcname > $tmpname
|
||||
else
|
||||
echo $init > $tmpname
|
||||
end
|
||||
if eval $editor $tmpname
|
||||
. $tmpname
|
||||
end
|
||||
set -l stat $status
|
||||
rm -f $tmpname >/dev/null
|
||||
return $stat
|
||||
end
|
||||
@@ -2,7 +2,7 @@ require 'linguist/file_blob'
|
||||
require 'linguist/samples'
|
||||
|
||||
require 'test/unit'
|
||||
require 'mocha'
|
||||
require 'mocha/setup'
|
||||
require 'mime/types'
|
||||
require 'pygments'
|
||||
|
||||
@@ -132,6 +132,11 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert !blob("Binary/octocat.psd").image?
|
||||
end
|
||||
|
||||
def test_solid
|
||||
assert blob("Binary/cube.stl").solid?
|
||||
assert blob("Text/cube.stl").solid?
|
||||
end
|
||||
|
||||
def test_viewable
|
||||
assert blob("Text/README").viewable?
|
||||
assert blob("Ruby/foo.rb").viewable?
|
||||
@@ -169,6 +174,9 @@ class TestBlob < Test::Unit::TestCase
|
||||
# CoffeeScript-generated JS
|
||||
# TODO
|
||||
|
||||
# TypeScript-generated JS
|
||||
# TODO
|
||||
|
||||
# PEG.js-generated parsers
|
||||
assert blob("JavaScript/parser.js").generated?
|
||||
|
||||
@@ -187,7 +195,7 @@ class TestBlob < Test::Unit::TestCase
|
||||
assert !blob("Text/README").vendored?
|
||||
assert !blob("ext/extconf.rb").vendored?
|
||||
|
||||
# Node depedencies
|
||||
# Node dependencies
|
||||
assert blob("node_modules/coffee-script/lib/coffee-script.js").vendored?
|
||||
|
||||
# Rails vendor/
|
||||
@@ -196,7 +204,7 @@ class TestBlob < Test::Unit::TestCase
|
||||
# C deps
|
||||
assert blob("deps/http_parser/http_parser.c").vendored?
|
||||
assert blob("deps/v8/src/v8.h").vendored?
|
||||
|
||||
|
||||
# Debian packaging
|
||||
assert blob("debian/cron.d").vendored?
|
||||
|
||||
@@ -265,6 +273,10 @@ class TestBlob < Test::Unit::TestCase
|
||||
|
||||
# NuGet Packages
|
||||
assert blob("packages/Modernizr.2.0.6/Content/Scripts/modernizr-2.0.6-development-only.js").vendored?
|
||||
|
||||
# Test fixtures
|
||||
assert blob("test/fixtures/random.rkt").vendored?
|
||||
assert blob("Test/fixtures/random.rkt").vendored?
|
||||
end
|
||||
|
||||
def test_indexable
|
||||
|
||||
@@ -109,6 +109,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal Language['Shell'], Language.find_by_alias('shell')
|
||||
assert_equal Language['Shell'], Language.find_by_alias('zsh')
|
||||
assert_equal Language['TeX'], Language.find_by_alias('tex')
|
||||
assert_equal Language['TypeScript'], Language.find_by_alias('ts')
|
||||
assert_equal Language['VimL'], Language.find_by_alias('vim')
|
||||
assert_equal Language['VimL'], Language.find_by_alias('viml')
|
||||
assert_equal Language['reStructuredText'], Language.find_by_alias('rst')
|
||||
@@ -132,7 +133,6 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal Language['Shell'], Language['Gentoo Ebuild'].group
|
||||
assert_equal Language['Shell'], Language['Gentoo Eclass'].group
|
||||
assert_equal Language['Shell'], Language['Tcsh'].group
|
||||
assert_equal Language['XML'], Language['XSLT'].group
|
||||
|
||||
# Ensure everyone has a group
|
||||
Language.all.each do |language|
|
||||
@@ -186,6 +186,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal :programming, Language['PowerShell'].type
|
||||
assert_equal :programming, Language['Python'].type
|
||||
assert_equal :programming, Language['Ruby'].type
|
||||
assert_equal :programming, Language['TypeScript'].type
|
||||
end
|
||||
|
||||
def test_markup
|
||||
@@ -279,6 +280,7 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal '#701516', Language['Ruby'].color
|
||||
assert_equal '#3581ba', Language['Python'].color
|
||||
assert_equal '#f15501', Language['JavaScript'].color
|
||||
assert_equal '#31859c', Language['TypeScript'].color
|
||||
end
|
||||
|
||||
def test_colors
|
||||
@@ -317,8 +319,9 @@ class TestLanguage < Test::Unit::TestCase
|
||||
assert_equal '.js', Language['JavaScript'].primary_extension
|
||||
assert_equal '.coffee', Language['CoffeeScript'].primary_extension
|
||||
assert_equal '.t', Language['Turing'].primary_extension
|
||||
assert_equal '.ts', Language['TypeScript'].primary_extension
|
||||
|
||||
# This is a nasty requirement, but theres some code in GitHub that
|
||||
# This is a nasty requirement, but there's some code in GitHub that
|
||||
# expects this. Really want to drop this.
|
||||
Language.all.each do |language|
|
||||
assert language.primary_extension, "#{language} has no primary extension"
|
||||
|
||||
@@ -24,4 +24,8 @@ class TestRepository < Test::Unit::TestCase
|
||||
def test_linguist_size
|
||||
assert linguist_repo.size > 30_000
|
||||
end
|
||||
|
||||
def test_binary_override
|
||||
assert_equal repo(File.expand_path("../../samples/Nimrod", __FILE__)).language, Language["Nimrod"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,8 +23,6 @@ class TestSamples < Test::Unit::TestCase
|
||||
actual.write Yajl::Encoder.encode(latest, :pretty => true)
|
||||
actual.close
|
||||
|
||||
warn `diff #{expected.path} #{actual.path}`
|
||||
|
||||
expected.unlink
|
||||
actual.unlink
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user