alfred client documentation · 2019-04-02 · alfred client documentation, release 0.1...

29
Alfred Client Documentation Release 0.1 Jeremy Bejanin Mar 06, 2018

Upload: others

Post on 20-May-2020

29 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client DocumentationRelease 0.1

Jeremy Bejanin

Mar 06, 2018

Page 2: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted
Page 3: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Contents

1 Features 3

2 Installation 5

3 Contribute 7

4 Support 9

5 License 115.1 Getting Started with Alfred . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.2 AlfredClient Cookbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.3 alfredClient API Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

MATLAB Module Index 23

i

Page 4: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

ii

Page 5: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

Welcome to the landing page for AlfredClient documentation. The AlfredClient, as of the time of writing, refers tothe particular MATLAB implementation of the AlfredServer client. This client is responsible for interfacing with thecorresponding AlfredServer implementation of the Alfred server. Both of these projects are authored primarily byJérémy Bejanin with feedback and assistance provided by the remainder of the Digital Quantum Matter Laboratory.

Any reference to AlfredClient herein is only a reference to that implementation written by Jérémy Bejanin. Thereexists, to date, no formal specification for AlfredClient (or AlfredServer) that would allow for alternative implementa-tions. Such a specification would be considered welcome should any individual desire to make such a contribution tothis open-source project.

Landing Page Contents

• AlfredClient

– Features

– Installation

– Contribute

– Support

– License

Contents 1

Page 6: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

2 Contents

Page 7: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

CHAPTER 1

Features

An instance of AlfredClient is only useful in the context of a corresponding AlfredServer instance. Using an Alfred-Client instance you can:

• retrieve data from past experiments;

• send custom jobs that the corresponding AlfredServer instance will execute;

• retrieve dilution refrigerator temperature information.

3

Page 8: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

4 Chapter 1. Features

Page 9: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

CHAPTER 2

Installation

AlfredClient is managed using Git1. Thus, the first thing you will need to do is clone the AlfredClient repository. Asof the time of this writing AlfredClient is stored on Gitlab.com. To clone the repository with Git use your favorite Gitinterface with the following url or execute the following Git command in the shell:

1 git clone [email protected]:DQMLab/AlfredClient.git

If successful, AlfredClient has now been installed to the directory in which git clone was called. To get startedwith AlfredClient please refer to Getting Started with Alfred.

1 A great introduction to using Git can be found at the start of the book Pro Git written by Scott Chacon.

5

Page 10: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

6 Chapter 2. Installation

Page 11: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

CHAPTER 3

Contribute

• Issue Tracker: https://gitlab.com/DQMLab/AlfredClient/issues

• Source Code: [email protected]:DQMLab/AlfredClient.git

7

Page 12: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

8 Chapter 3. Contribute

Page 13: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

CHAPTER 4

Support

If you are having issues, please let us know. The best way to get your issue resolved is to post an issue on the GitlabIssue Tracker or to contact the lead developer Jérémy Bejanin by email.

9

Page 14: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

10 Chapter 4. Support

Page 15: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

CHAPTER 5

License

Error: The license for this project has yet to be determined.

Please contact the main developer, Jérémy Bejanin at [email protected] for permissions to use or redis-tribute any work derived from the primary work of AlfredClient.

5.1 Getting Started with Alfred

5.1.1 Setting up MATLAB for AlfredClient

The first thing that you’ll need to do in order to set up AlfredClient is determine the address of the desired Alfred-Server1. In the case of the Digital Quantum Matter Laboratory, the address of the primary AlfredServer instance at thetime of writing is ws://theriddler.iqc.uwaterloo.ca:30000.

AlfredClient is implemented as an object in MATLAB. That is, an AlfredClient instance contains a set of propertiesand methods that allow one to:

1. review previously-acquired experimental data;

2. acquire new experimental data (i.e. submit jobs to an AlfredServer instance);

3. obtain temperature logs.

Since the AlfredClient object is the portal by which this information is obtained from the AlfredServer it is importantto know how to instantiate an AlfriedClient object. An instance of the AlfredClient object can be instantiated byexecuting the AlfredClient class’s constructor:

ac = alfredClient(<ServerAddress>)

ServerAddress is a URL string pointing to the relevant AlfredServer.

1 Each AlfredServer instance is responsible for accepting Alfred jobs, coordinating instrument usage, and storing and retrieving Alfred job data.So, knowing where to find the AlfredServer that you need is very important.

11

Page 16: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

5.1.2 Deleting Custom Jobs from Alfred

Sometimes, it is desirable to interrupt a custom job submitted to an AlfredServer instance. However, checking todetermine if jobs are to be cancelled are currently not in the event loop of AlfredServer. Thus, conditions for de-termining the cancellation of jobs must be provided within the job file submitted to an AlfredServer instance. Thisfunctionality is provided by utils.checkpoint as seen in each of the example Alfred jobs. AlfredServer includesthe definition of this function (see jobs/abstractJob.m) which checks for the existence of a file comm.json at the path<AlfredServerRoot>/temp/job_<ID>_temp/comm.json. Depending on the existence of such a file, oneof two things will occur:

1. If this file contains a top-level object with the key-value pair abort: 1, then the job is aborted.

2. If the file does not exist and/or does not contain the key-value pair abort:1, then the experimental data issaved to a temporary MAT file at <AlfredServerRoot>/temp/job_<ID>_temp.mat.

5.1.3 Changing Credentials

If credentials are entered improperly the solution, currently, is to destroy the AlfredClient object and reinstantiate it.This can be done by delete(c), for c being the AlfredClient. It is important to never clear an AlfredClient object(by clear c). clear ing a client object leaves the connection to the server open, which is undesirable.

5.2 AlfredClient Cookbook

5.3 alfredClient API Documentation

5.3.1 alfredClient Class Documentation

class src.alfredClient(URI)alfredClient Implements the client corresponding to the Alfred server.

c = alfredClient(“ws://somelocation:someport”)

AlfredClientRootPath = NoneRoot path to alfredClient.m

InstrumentsRepoDir = u'"D:\\Jeremy\\Dropbox\\Documents\\School\\Waterloo\\Research\\Programming\\MATLAB\\AlfredInstruments"'None

Password = NoneUser’s password

Reports = NoneStructure containing job reports

TemperatureLog = NoneTemperature log

Username = NoneUsername

alfredClient(URI)alfredClient(URI) takes the URI of the alfredServer as the only argument

static checkJavaClasses(RootPath)checkJavaClasses checks if the required java classes are on the Matlab static class path file. If they are not,it adds them and prompts the user to restart Matlab. Default settings

12 Chapter 5. License

Page 17: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

dateRangeQuery(startDate, endDate)Request job information between and including the specified dates. Result is printed to the MATLAB com-mand line. c.dateRangeQuery(‘2015-01-01’,‘2016-01-01’): get job information for jobs started betweenJanuary 1, 2016 and January 1, 2016.

getDiary()Request the diary of the currently running job. The output is printed to the MATLAB command window.

c.getDiary()

getReport(jobID)Download the full report of the specified job.

c.getReport(56). Retrieves job 56 from the database.

getTempLog(varargin)Request temperature data for the last n days or for a specific date range. Result is stored in the propertyc.TemperatureLog.

c.getTempLog(5): obtain temperature logs from the last 5 days.

or

c.getTempLog(‘2000-01-01’,‘2000-06-01’): obtain temperature logs from January 1, 2001 -> June 1,2001.

loadCustomJob(mfile, sampleName, projectName, experimentName, notes)Add a custom (not debug) job to the Alfred server queue. This method requires a valid set of credentials.

Usage: c.loadCustomJob(‘some_experiment.m’, . . . ‘Name of Sample’, . . . ‘Name of Project’, . . . ‘Nameof Experiment’, . . . ‘Notes’)

e.g.: c.loadCustomJob(‘some_experiment.m’, . . . ‘Si-Al 05’, . . . ‘Die bonding’, . . . ‘S2P TransmissionLine Measurement’, . . . ‘Transmission line measurement at room temperature. VNA is uncalibrated.’)

loadDebugJob(filename)Add a debug job to the Alfred server queue. This method requires no credentials.

c.loadDebugJob(‘some_experiment.m’)

metadataQuery(qstring)Query metadata of jobs using JSON string. The JSON string may use embedded/nested fields (see Mongodocumentation). For this reason, it is impossible to use MATLAB’s JSON library. I don’t want to writecustom processing for this case. It’s not hard to write the JSON string. The match(es) is(are) printed to theMATLAB command line as with dateRangeQuery().

Examples: 1. To find the job with an ID of 1: c.metadataQuery(‘{metadata.jobID: 1}’) 2. To find the jobwith an experiment name containing “traces” (case-insensitive) c.metadataQuery(‘{

metadata.experimentName: { $regex: “traces”, $options: “i”,

}}’)

3. To find all jobs performed by user “jbejanin” with “uncalibrated” (case-insensitive) in the notesc.metadataQuery(‘{ metadata.username: “jbejanin”,

metadata.notes: {

$regex: “uncalibrated”, $options: “i”,

}

}’)

5.3. alfredClient API Documentation 13

Page 18: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

onMessage(message)This function parses the incoming message and decides what to do with it. This is where the magic happens

First, we check what the message type is. There are two possible types: 1. A string, json formatted. 2.A binary blob, which can be either a mat file or a matlab serial object. The json message is processedaccording to the COMMAND field. The binary messaged is processed according to the first byte.

reauthenticate()Submit an alternate set of credentials (username and password).

c.reauthenticate()

5.3.2 alfredClient Dependencies Documentation

JSONLab

src.deps.jsonlab.jsonopt(key, default, varargin)val=jsonopt(key,default,optstruct)

setting options based on a struct. The struct can be produced by varargin2struct from a list of ‘param’,’value’pairs

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)

$Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $

input: key: a string with which one look up a value from a struct default: if the key does not exist, return defaultoptstruct: a struct where each sub-field is a key

output: val: if key exists, val=optstruct.key; otherwise val=default

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.loadjson(fname, varargin)data=loadjson(fname,opt)

or

data=loadjson(fname,’param1’,value1,’param2’,value2,. . . )

parse a JSON (JavaScript Object Notation) file or string

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) created on 2011/09/09, including previous works from

Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713

created on 2009/11/02

François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393

created on 2009/03/22

Joel Feenstra: http://www.mathworks.com/matlabcentral/fileexchange/20565

created on 2008/07/03

$Id$

input:

fname: input file name, if fname contains “{}” or “[]”, fname will be interpreted as a JSON string

14 Chapter 5. License

Page 19: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

opt: a struct to store parsing options, opt can be replaced by a list of (‘param’,value) pairs - the paramstring is equivallent to a field in opt. opt can have the following fields (first in [.|.] is the default)

opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat for each element of the JSON data,and group arrays based on the cell2mat rules.

opt.FastArrayParser [1|0 or integer]: if set to 1, use a speed-optimized array parser when loadingan array object. The fast array parser may collapse block arrays into a single large array similarto rules defined in cell2mat; 0 to use a legacy parser; if set to a larger-than-1 value, this optionwill specify the minimum dimension to enable the fast array parser. For example, if the input is a3D array, setting FastArrayParser to 1 will return a 3D array; setting to 2 will return a cell arrayof 2D arrays; setting to 3 will return to a 2D cell array of 1D vectors; setting to 4 will return a 3Dcell array.

opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.

output:

dat: a cell array, where {. . . } blocks are converted into cell arrays, and [. . . ] are converted to arrays

examples: dat=loadjson(‘{“obj”:{“string”:”value”,”array”:[1,2,3]}}’) dat=loadjson([‘examples’ filesep ‘exam-ple1.json’]) dat=loadjson([‘examples’ filesep ‘example1.json’],’SimplifyCell’,1)

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.loadubjson(fname, varargin)data=loadubjson(fname,opt)

or

data=loadubjson(fname,’param1’,value1,’param2’,value2,. . . )

parse a JSON (JavaScript Object Notation) file or string

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) created on 2013/08/01

$Id$

input:

fname: input file name, if fname contains “{}” or “[]”, fname will be interpreted as a UBJSON string

opt: a struct to store parsing options, opt can be replaced by a list of (‘param’,value) pairs - theparam string is equivallent to a field in opt. opt can have the following fields (first in [.|.] is thedefault)

opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat for each element of the JSONdata, and group arrays based on the cell2mat rules.

opt.IntEndian [B|L]: specify the endianness of the integer fields in the UBJSON input data. B -Big-Endian format for integers (as required in the UBJSON specification); L - input integer fieldsare in Little-Endian order.

opt.NameIsString [0|1]: for UBJSON Specification Draft 8 or earlier versions (JSONLab 1.0 fi-nal or earlier), the “name” tag is treated as a string. To load these UBJSON data, you need tomanually set this flag to 1.

output:

dat: a cell array, where {. . . } blocks are converted into cell arrays, and [. . . ] are converted to arrays

5.3. alfredClient API Documentation 15

Page 20: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

examples: obj=struct(‘string’,’value’,’array’,[1 2 3]); ubjdata=saveubjson(‘obj’,obj); dat=loadubjson(ubjdata)dat=loadubjson([‘examples’ filesep ‘example1.ubj’]) dat=loadubjson([‘examples’ filesep ‘exam-ple1.ubj’],’SimplifyCell’,1)

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.mergestruct(s1, s2)s=mergestruct(s1,s2)

merge two struct objects into one

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) date: 2012/12/22

input: s1,s2: a struct object, s1 and s2 can not be arrays

output: s: the merged struct object. fields in s1 and s2 will be combined in s.

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.savejson(rootname, obj, varargin)json=savejson(rootname,obj,filename)

or

json=savejson(rootname,obj,opt) json=savejson(rootname,obj,’param1’,value1,’param2’,value2,. . . )

convert a MATLAB object (cell, struct or array) into a JSON (JavaScript Object Notation) string

author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) created on 2011/09/09

$Id$

input:

rootname: the name of the root-object, when set to ‘’, the root name is ignored, however, whenopt.ForceRootName is set to 1 (see below), the MATLAB variable name will be used as the rootname.

obj: a MATLAB object (array, cell, cell array, struct, struct array, class instance).

filename: a string for the file name to save the output JSON data.

opt: a struct for additional options, ignore to use default values. opt can have the following fields (first in[. or .] is the default)

opt.FileName [‘’ or string]: a file name to save the output JSON data

opt.FloatFormat [‘%.10g’ or string]: format to show each numeric element of a 1D/2D ar-ray;

opt.ArrayIndent [1 or 0]: if 1, output explicit data array with precedent indentation; if 0, noindentation

opt.ArrayToStruct [0 or 1]: when set to 0, savejson outputs 1D/2D array in JSON array for-mat; if sets to 1, an array will be shown as a struct with fields “_ArrayType_”, “_ArraySize_”and “_ArrayData_”; for sparse arrays, the non-zero elements will be saved to _ArrayData_field in triplet-format i.e. (ix,iy,val) and “_ArrayIsSparse_” will be added with a value of 1;for a complex array, the _ArrayData_ array will include two columns (4 for sparse) to recordthe real and imaginary parts, and also “_ArrayIsComplex_”:1 is added.

opt.ParseLogical [0 or 1]: if this is set to 1, logical array elem will use true/false rather than1/0.

16 Chapter 5. License

Page 21: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

opt.SingletArray [0 or 1]: if this is set to 1, arrays with a single numerical element will beshown without a square bracket, unless it is the root object; if 0, square brackets are forcedfor any numerical arrays.

opt.SingletCell [1 or 0]: if 1, always enclose a cell with “[]” even it has only one element; if0, brackets are ignored when a cell has only 1 element.

opt.ForceRootName [0 or 1]: when set to 1 and rootname is empty, savejson will use thename of the passed obj variable as the root object name; if obj is an expression and doesnot have a name, ‘root’ will be used; if this is set to 0 and rootname is empty, the root levelwill be merged down to the lower level.

opt.Inf [‘”$1_Inf_”’ or string]: a customized regular expression pattern to represent +/-Inf.The matched pattern is ‘([-+]*)Inf’ and $1 represents the sign. For those who want to use1e999 to represent Inf, they can set opt.Inf to ‘$11e999’

opt.NaN [‘“_NaN_”’ or string]: a customized regular expression pattern to represent NaN

opt.JSONP [‘’ or string]: to generate a JSONP output (JSON with padding), for example,if opt.JSONP=’foo’, the JSON data is wrapped inside a function call as ‘foo(. . . );’

opt.UnpackHex [1 or 0]: conver the 0x[hex code] output by loadjson back to the string form

opt.SaveBinary [0 or 1]: 1 - save the JSON file in binary mode; 0 - text mode.

opt.Compact [0 or 1]: 1- out compact JSON format (remove all newlines and tabs)

opt can be replaced by a list of (‘param’,value) pairs. The param string is equivallent to a field inopt and is case sensitive.

output: json: a string in the JSON format (see http://json.org)

examples:

jsonmesh=struct(‘MeshNode’,[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],. . . ‘MeshTetra’,[1 2 48;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],. . . ‘MeshTri’,[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;. . .2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],. . . ‘MeshCreator’,’FangQ’,’MeshTitle’,’T6 Cube’,. . . ‘Special-Data’,[nan, inf, -inf]);

savejson(‘jmesh’,jsonmesh) savejson(‘’,jsonmesh,’ArrayIndent’,0,’FloatFormat’,’t%.5g’)

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.saveubjson(rootname, obj, varargin)json=saveubjson(rootname,obj,filename)

or

json=saveubjson(rootname,obj,opt) json=saveubjson(rootname,obj,’param1’,value1,’param2’,value2,. . . )

convert a MATLAB object (cell, struct or array) into a Universal Binary JSON (UBJSON) binary string

author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) created on 2013/08/17

$Id$

input:

rootname: the name of the root-object, when set to ‘’, the root name is ignored, however, whenopt.ForceRootName is set to 1 (see below), the MATLAB variable name will be used as the rootname.

5.3. alfredClient API Documentation 17

Page 22: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

obj: a MATLAB object (array, cell, cell array, struct, struct array, class instance)

filename: a string for the file name to save the output UBJSON data

opt: a struct for additional options, ignore to use default values. opt can have the following fields(first in [. or .] is the default)

opt.FileName [‘’ or string]: a file name to save the output JSON data

opt.ArrayToStruct[0 or 1]: when set to 0, saveubjson outputs 1D/2D array in JSON array format;if sets to 1, an array will be shown as a struct with fields “_ArrayType_”, “_ArraySize_” and“_ArrayData_”; for sparse arrays, the non-zero elements will be saved to _ArrayData_ field intriplet-format i.e. (ix,iy,val) and “_ArrayIsSparse_” will be added with a value of 1; for a com-plex array, the _ArrayData_ array will include two columns (4 for sparse) to record the real andimaginary parts, and also “_ArrayIsComplex_”:1 is added.

opt.ParseLogical [1 or 0]: if this is set to 1, logical array elem will use true/false rather than 1/0.

opt.SingletArray [0 or 1]: if this is set to 1, arrays with a single numerical element will be shownwithout a square bracket, unless it is the root object; if 0, square brackets are forced for anynumerical arrays.

opt.SingletCell [1 or 0]: if 1, always enclose a cell with “[]” even it has only one element; if 0,brackets are ignored when a cell has only 1 element.

opt.ForceRootName [0 or 1]: when set to 1 and rootname is empty, saveubjson will use thename of the passed obj variable as the root object name; if obj is an expression and does not havea name, ‘root’ will be used; if this is set to 0 and rootname is empty, the root level will be mergeddown to the lower level.

opt.JSONP [‘’ or string]: to generate a JSONP output (JSON with padding), for example, ifopt.JSON=’foo’, the JSON data is wrapped inside a function call as ‘foo(. . . );’

opt.UnpackHex [1 or 0]: conver the 0x[hex code] output by loadjson back to the string form

opt can be replaced by a list of (‘param’,value) pairs. The param string is equivallent to a field in optand is case sensitive.

output: json: a binary string in the UBJSON format (see http://ubjson.org)

examples:

jsonmesh=struct(‘MeshNode’,[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],. . . ‘MeshTetra’,[1 2 48;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],. . . ‘MeshTri’,[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;. . .2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],. . . ‘MeshCreator’,’FangQ’,’MeshTitle’,’T6 Cube’,. . . ‘Special-Data’,[nan, inf, -inf]);

saveubjson(‘jsonmesh’,jsonmesh) saveubjson(‘jsonmesh’,jsonmesh,’meshdata.ubj’)

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.struct2jdata(data, varargin)newdata=struct2jdata(data,opt,. . . )

convert a JData object (in the form of a struct array) into an array

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)

input:

data: a struct array. If data contains JData keywords in the first level children, these fields areparsed and regrouped into a data object (arrays, trees, graphs etc) based on JData specification. The

18 Chapter 5. License

Page 23: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

JData keywords are “_ArrayType_”, “_ArraySize_”, “_ArrayData_” “_ArrayIsSparse_”, “_ArrayIs-Complex_”

opt: (optional) a list of ‘Param’,value pairs for additional options

The supported options include

‘Recursive’, if set to 1, will apply the conversion to every child; 0 to disable

output:

newdata: the covnerted data if the input data does contain a JData structure; otherwise, the same asthe input.

examples:

obj=struct(‘_ArrayType_’,’double’,’_ArraySize_’,[2 3], ‘_ArrayIsSparse_’,1 ,’_ArrayData_’,null);

ubjdata=struct2jdata(obj);

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

src.deps.jsonlab.varargin2struct(varargin)opt=varargin2struct(‘param1’,value1,’param2’,value2,. . . )

or

opt=varargin2struct(. . . ,optstruct,. . . )

convert a series of input parameters into a structure

authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) date: 2012/12/22

input:

‘param’, value: the input parameters should be pairs of a string and a value optstruct: if a parame-ter is a struct, the fields will be merged to the output struct

output: opt: a struct where opt.param1=value1, opt.param2=value2 . . .

license: BSD License, see LICENSE_BSD.txt files for details

– this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)

utils

src.deps.utils.git(AlfredSettings, varargin)A thin MATLAB wrapper for Git for Alfred based on http://www.mathworks.com/matlabcentral/fileexchange/29154-a-thin-matlab-wrapper-for-the-git-source-control-system. Use this exactly as you would use the OScommand-line verison of Git. We can call the real git with the arguments

src.deps.utils.grabInstRep(AlfredSettings, dirpath)grabInstRep Downloads the master branch of the AlfredInstruments repo Clone

src.deps.utils.mat_deserialize(input, temporarydir)MAT_DESERIALIZE Summary of this function goes here Detailed explanation goes here

src.deps.utils.mat_serialize(data, temporarydir)MAT_SERIALIZE Summary of this function goes here Detailed explanation goes here

src.deps.utils.passwordEntryDialog(varargin)PASSWORDENTRYDIALOG [Password, UserName] = passwordEntryDialog(varargin)

5.3. alfredClient API Documentation 19

Page 24: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

Create a password entry dialog for entering a password that is visibly hidden. Java must be enabled for thisfunction to work properly.

It has only been tested on the Windows platform in R2008a. It should work in R2007a or later.

The password box is created using the Java Swing component JPasswordField.

Optional Input Arguments

‘enterUserName’ DEFAULT: false Display the user name entry box. The user name entered must be at least onecharacter or an error dialog is displayed.

‘DefaultUserName’ DEFAULT: ‘’ String value of user name to populate in User Name box upon creation.

‘ValidatePassword’ DEFAULT: false Display dialog box to reenter password for validation purposes.

‘CheckPasswordLength’ DEFAULT: true Check the password length to ensure it meets the specified criteria.

‘PasswordLengthMin’ DEFAULT: 2 Minimum password length allowed.

‘PasswordLengthMax’ DEFAULT: 8 Maximum password length allowed.

‘WindowName’ DEFAULT: ‘Login’ Title of the password entry window.

Examples

1. Create a password dialog box with the default options.

[Password] = passwordEntryDialog;

2. Create a user name and password entry dialog box without password verification.

[Password, UserName] = passwordEntryDialog(‘enterUserName’, true)

3. Create a user name and password entry dialog box without password verification. Set the user name to ‘jdoe’upon startup.

[Password, UserName] = passwordEntryDialog(‘enterUserName’, true,. . . ‘DefaultUserName’, ‘jdoe’)

4. Create a password dialog box with password validation

[Password] = passwordEntryDialog(‘ValidatePassword’, true);

5. Create a user name and password entry dialog box with password verification.

[Password, UserName] = passwordEntryDialog(‘enterUserName’, true,. . . ‘ValidatePassword’, true)

6. Check the length of the password to be between 5 and 8 characters

[Password, UserName] = passwordEntryDialog(‘CheckPasswordLength’, true,. . . ‘PasswordLengthMin’,5,. . . ‘PasswordLengthMax’, 8)

Copyright (C) 2007-2008, Jesse B. Lai

This program is free software: you can redistribute it and/or modify it under the terms of the GNU LesserGeneral Public License as published by the Free Software Foundation, either version 3 of the License, or (atyour option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without eventhe implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see<http://www.gnu.org/licenses/>

20 Chapter 5. License

Page 25: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

src.deps.utils.rdir(rootdir, varargin)RDIR - Recursive directory listing

D = rdir(ROOT) D = rdir(ROOT, TEST) D = rdir(ROOT, TEST, RMPATH) D = rdir(ROOT, TEST,1) D = rdir(ROOT, ‘’, . . . ) [D, P] = rdir(. . . ) rdir(. . . )

Inputs

• ROOT

rdir(ROOT) lists the specified files. ROOT can be a pathname, filename, or can include both. One can useabsolute and relative pathnames and wildcards (*). Wildcard can be placed anywhere and used many times like‘path**.m’

One can also use a double wildcard (**) to match multiple directory levels. For example ROOT = ‘path***.m’will match all “.m” files in “path” and all subdirectories of “path”.

NOTE : “.svn” directories created by SubVersion (SVN) are excluded from the recursive listing.

• TEST

Optional test that can be performed on the returned files.

TEST is a string indicating expression to be evaluated on selected field of rdir output. All fields (ie name, date,bytes, isdir and datenum) can be used.

Tests are strings similar to what one would use in a “if” statement e.g. ‘bytes>1024 & datenum>now-7’

One can also use function like “regexp” or “strfind” with string fields like “name” and “date” e.g ‘regexp(name,‘expr’)’. In that case, tests that return a non empty value are considered as true.

regexp(name, ‘(.m$)|(.mdl$)’)

Test can also be a function handle as used in arrayfun/cellfun, e.g. @(f)f.bytes>1024

• RMPATH

Optional path to remove from beginning of “name” field in returned output. Specified path must be common toall items found.

If RMPATH = 1 or true, path to remove is part of ROOT before the first wildcard.

Outputs

• D

D is a structure with the same fields as Matlab DIR output.

The “name” field includes the relative path as well as the name to the file that was found. Path can be shorten orommited when using 3rd argument RMPATH.

• P

Common path or RMPATH (if specified) for the file list returned in D.

• Screen output

If not output variable is specified then the output is sent to the screen.

Versions

• 1.0 * - 2009, Gus Brown

• 2.0 * - 26/05/2011 Thomas Vanaret No longer exclude all directories from a simple search (no ); %sphinx cmnt Fixing bug on returned path; Exclude “.svn” directories; Extended test possibilies; Sub-functions created;

5.3. alfredClient API Documentation 21

Page 26: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

• 2.1 * - 14/07/2011 Thomas Vanaret New argument allowing to remove common path from name; Com-ments review;

• 2.2 * - 20/12/2011 Thomas Vanaret Fixing bug on display with 0b files; Specific display when no filematch filter;

• 2.3 * - 19/01/2014 Thomas Vanaret Adding improvements suggested by X. Mo : - function handle asTEST input - code optimisation (avoiding loop) Fixing possible bug when using a wildcard at thebeginning; Common path as 2nd optionnal output;

Examples

D = rdir(‘.m’); % comment for Sphinx for ii=1:length(D), disp(D(ii).name); end;

% to find all files in the current directory and sub directories D = rdir(‘*’) % comment for Sphinx

% If no output is specified then the files are sent to % the screen. rdir(‘c:program fileswindows*.exe’); rdir(‘c:program fileswindows ***.dll’);

% Using the test function to find files modified today rdir(‘c:win**’,’datenum>floor(now)’); % Us-ing the test function to find files of a certain size rdir(‘c:program fileswin**.exe’,’bytes>1024 &bytes<1048576’); % Using the test function to find files modified in 2011 rdir(‘c:win**’,’strfind(date,“2011’‘)’);

% Using the 3rd input to shorten output name rdir([matlabroot, ‘*.txt’], ‘’, ‘C:Program Files’) %Using the 3rd input to shorten output name rdir([matlabroot, ‘*.txt’], ‘’, 1)

See also DIR

22 Chapter 5. License

Page 27: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

MATLAB Module Index

ssrc, 12src.deps.jsonlab, 14src.deps.utils, 19

23

Page 28: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Alfred Client Documentation, Release 0.1

24 MATLAB Module Index

Page 29: Alfred Client Documentation · 2019-04-02 · Alfred Client Documentation, Release 0.1 5.1.2Deleting Custom Jobs from Alfred Sometimes, it is desirable to interrupt a custom job submitted

Index

AalfredClient (class in src), 12alfredClient() (src.alfredClient method), 12AlfredClientRootPath (src.alfredClient attribute), 12

CcheckJavaClasses() (src.alfredClient static method), 12

DdateRangeQuery() (src.alfredClient method), 12

GgetDiary() (src.alfredClient method), 13getReport() (src.alfredClient method), 13getTempLog() (src.alfredClient method), 13git() (in module src.deps.utils), 19grabInstRep() (in module src.deps.utils), 19

IInstrumentsRepoDir (src.alfredClient attribute), 12

Jjsonopt() (in module src.deps.jsonlab), 14

LloadCustomJob() (src.alfredClient method), 13loadDebugJob() (src.alfredClient method), 13loadjson() (in module src.deps.jsonlab), 14loadubjson() (in module src.deps.jsonlab), 15

Mmat_deserialize() (in module src.deps.utils), 19mat_serialize() (in module src.deps.utils), 19mergestruct() (in module src.deps.jsonlab), 16metadataQuery() (src.alfredClient method), 13

OonMessage() (src.alfredClient method), 13

PPassword (src.alfredClient attribute), 12passwordEntryDialog() (in module src.deps.utils), 19

Rrdir() (in module src.deps.utils), 20reauthenticate() (src.alfredClient method), 14Reports (src.alfredClient attribute), 12

Ssavejson() (in module src.deps.jsonlab), 16saveubjson() (in module src.deps.jsonlab), 17src (module), 12src.deps.jsonlab (module), 14src.deps.utils (module), 19struct2jdata() (in module src.deps.jsonlab), 18

TTemperatureLog (src.alfredClient attribute), 12

UUsername (src.alfredClient attribute), 12

Vvarargin2struct() (in module src.deps.jsonlab), 19

25