Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
JuliaTikzModule.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Regler
JuliaTikzModule.jl
Commits
713b8b93
Commit
713b8b93
authored
4 years ago
by
Leif Andersson
Browse files
Options
Downloads
Patches
Plain Diff
Adjusting module name
parent
46fb0fa8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Project.toml
+8
-0
8 additions, 0 deletions
Project.toml
src/JuliaTikz.jl
+105
-0
105 additions, 0 deletions
src/JuliaTikz.jl
with
113 additions
and
0 deletions
Project.toml
0 → 100644
+
8
−
0
View file @
713b8b93
name
=
"JuliaTikz"
uuid
=
"9c98e656-dfbc-11ea-2f36-4b421b45bbac"
authors
=
[
"Leif Andersson <leif.andersson@control.lth.se>"
]
version
=
"0.1.0"
[deps]
Printf
=
"de0858da-6303-5e67-8744-51eddeeeb8d7"
This diff is collapsed.
Click to expand it.
src/JuliaTikz.jl
0 → 100644
+
105
−
0
View file @
713b8b93
module
JuliaTikzModule
export
printcsv
,
JuliaTikz
;
using
ControlSystems
# ControlSystems v0.5.4
using
Plots
using
Printf
function
sprintdatarow
(
r
)
join
(
map
(
n
->
@sprintf
(
"%#11.5G"
,
n
),
r
),
';'
)
end
function
sprintheader
(
r
)
join
(
map
(
n
->
@sprintf
(
"%11s"
,
n
),
r
),
';'
)
end
function
printcsv
(
csv
::
String
,
data
::
Array
{
Any
})
@warn
"""printcsv(csv::String, data::Array{Any}) is deprecated
Use printcsv(data::Array{Any}, csv="") instead"""
;
printcsv
(
data
,
csv
);
end
"""
printcsv(data::Array{Any}, csv="")
Print the array `data` to a file suitable for inclusion in pgfplots.
The columns of `data` should have a string as first element, and Float64
as the remaining elements.
The default name of the file will be `<name>.csv`, where `<name>` is the value
of the global variable `name`, typically given by `JuliaTikz`. Another name may
be specified whith the second argument of `printcsv`.
"""
function
printcsv
(
data
::
Array
{
Any
},
csv
=
""
)
if
cmp
(
csv
,
""
)
==
0
global
name
;
csv
=
name
*
".csv"
;
end
;
open
(
csv
,
"w"
)
do
f
hh
=
Array
{
String
}(
data
[
1
,
:
]);
dd
=
convert
(
Array
{
Float64
,
2
},
data
[
2
:
end
,
1
:
end
]);
println
(
f
,
sprintheader
(
hh
));
map
(
r
->
println
(
f
,
sprintdatarow
(
r
)),
eachrow
(
dd
));
end
end
#@deprecate printcsv(csv::String, data::Array{Any}) printcsv(data::Array{Any}, csv="")
"""
JuliaTikz(tikzfile,delete=true)
Extract and run the Julia part of a combined tikz/Julia file.
The boundary between the two is the string
\\
endinput Julia <name>
where `<name>` is the name that will be given to the Julia file
(with .jl appended), and also to a variable `name` in the program,
i.e. name = "
<
name
>
".
The Julia file will be extracted to a temporary directory, which will be
deleted after the run unless the optional argument `delete` is false.
"""
function
JuliaTikz
(
tikzfile
,
delete
=
true
)
dir
=
mktempdir
();
filespec
=
""
;
out
=
""
;
if
!
delete
println
(
"Opening "
*
tikzfile
)
end
;
open
(
tikzfile
)
do
file
res
=
nothing
;
while
res
===
nothing
if
eof
(
file
)
error
(
"
\"\\
endinput Julia
\"
not found"
);
end
;
line
=
readline
(
file
);
res
=
match
(
r
"(\s*
\\
endinput\s+Julia\s+)([[:alnum:]]+)"
,
line
);
end
;
name
=
res
.
captures
[
2
];
filespec
=
join
([
dir
,
name
*
".jl"
],
"/"
);
out
=
open
(
filespec
,
"w"
);
if
!
delete
println
(
"Writing "
*
filespec
);
end
;
firstline
=
"name =
\"
"
*
name
*
"
\"
"
;
println
(
out
,
firstline
);
while
!
eof
(
file
)
println
(
out
,
readline
(
file
));
end
;
close
(
out
);
end
;
include
(
filespec
);
if
delete
rm
(
dir
,
recursive
=
true
);
else
return
filespec
;
end
;
end
;
end
;
# end module
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment