metaprogramming


Save variables to file at runtime


I'm looking for some functionality in Julia comparable to Matlab's
save('myfile.mat', 'myvar1', 'myvar2')
For example, using HDF5.jl, it is easy to do
#write filename myvar1 myvar2
But this requires that I know exactly which variables I want to write to the file.
I'd like to be able to choose which variables to write at run time, in a function scope, and specify their names using symbols or strings.
vars = [:myvar1, :myvar2]
#write filename vars
What would be the best way to accomplish this?
EDIT
I know that I can use save from JLD.jl as save("file.jld", "myvar1", myvar1). But I want to be able to save a list of variables that are not known at compile time, allowing a single call to save (or similar):
if condition
myvar1 = 1
vars = [:myvar1]
else
myvar1 = 1
myvar2 = 2
vars = [:myvar1, :myvar2]
end
# what goes here?
save(filename, vars...)
You may want to take a look at the JLD package, which builds on HDF5 with better support of user-defined Julia types. Both HDF5 and JLD provide functions for save that take run-time names for variables.
You can use serialize and deserialize:
vars = Dict()
if condition
myvar = 1
vars[:myvar1] = myvar1
else
myvar1 = 1
myvar2 = 2
vars[:myvar1] = myvar1
vars[:myvar2] = myvar2
end
f = open( filename, "w" )
serialize( f, vars )
close( f )
to read:
f = open( filename, "r" )
vars = deserialize( f )
close( f )
if you don't need to save variable names you can use array instead of dict: vars = []

Related Links

What is the correct syntax in metaprogramming assignment in Julia?
How can I call .WHY on a subroutine in a class in Perl 6?
Using Roslyn, if I have an IdentifierNameSyntax, can I find the member type it refers to (field, property, method…)
Elixir - Define functions in module by metaprogramming
Disambiguate the various quoting mechanisms in Julia metaprogramming
How to initialize list using macros and then generate same set of functions in 2 different modules?
Type-safe metaprogramming? Using strings to query ceylon.language for meta information?
Interpolating an Expression into an Expression
Loop unrolling? in Julia with metaprogramming
Macro for a function template: escaping issues
Macro that defines macro returning struct constant
Array of Expressions to an Array Definition
Code generation from restricted set of input
System of equations using metaprogramming
How to define a partial copy constructor metaprogramically in Julia?
How to interpolate into a Julia “for” expression?

Categories

HOME
uml
webdriver
themes
access
ado.net
nuget-package
angularfire2
flume
jquery-ui-sortable
drop-down-menu
google-chrome-app
fhir
why3
linear-algebra
esoteric-languages
video-editing
ag
squashfs
imageresizer
bulletphysics
angularjs-components
entity-relationship-model
bioinformatics
aws-codecommit
scatter3d
database-comparison
angularjs-material
baidu-map
magento-1.9.2.4
openproject
typesafe-config
p4merge
c9.io
setup.py
kill
datacachefactory
linqpad
sharp-snmp
tcc
zenhub
opengl-4
pdf-conversion
check-mk
mouseleave
trigger.io
offline.js
rxtx
javafx-css
jboss-tools
respondcms
google-query-language
freepbx
boomerang
decimalformat
qt5.2
fiware-monitoring
file-move
microsoft-reporting
alloy-ui
zend-currency
phpldapadmin
android-vibration
browserify-shim
machine-instruction
genymotion-call
personalization
xml-dsig
koala
conditionaltagsupport
ecslidingviewcontroller
ice-cube
abstract-data-type
argouml
resource-management
wimax
nokia-s40
wcf-configuration
garbage
mapping-by-code
entitydatasource
uipagecontrol
massive
nhprof
tabpanel
lobo-cobra
httpcookie

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App