save_reteive_data.ijs

Script: ~addons/finexec/utilitry/save_retrieve_data.ijs
Contributor: William Szuch
Updated: 2022 6 26
Depend: ~addons/data/jfiles/jfiles.ijs
Definitions: loaded to locale base
Status: done
Script source: save_retrieve_data.ijs

Save the data (ie: nouns) in the base or other locale in the
workspace to a keyfile so that data can then be retrieved
and used in a job again. A keyfile allows the data to be saved
using its noun name and the data retrieved by the same
noun name.
Keyword file verbs are used to save and retrieve nouns from
a keyfile for a job. Data is saved from the base locale
unless otherwise specified.
Most likely data is only saved from base locale.
Saving data from a locale other than base’- see examples in saveData
and savedataTemp.
It is useful to save the data created in a job or project
for further use.
The default keyfile name is KEYFILE_DEFAULT that has been defined
in the base locale that allows for simple saving and retrieving of data
without having to refer to the keyfile.
Otherwise the keyfile is as specified.
The keyfile KEYFILE_DEFAULT or other keyfile
requires to be created first before any saving data.

(1) Create names for keyfiles eg:

KEYFILE_DEFAULT =: jpath ‘~user/temp/testkeyfile.ijf’
KEYFILE_OTHER =: jpath ‘~user/temp/testkeyfileother.ijf’

(2) Erase any keyfiles with the same name (as requited)

ferase KEYFILE_DEFAULT
ferase KEYFILE_OTHER

(3) Create the keyfiles

keycreate KEYFILE_DEFAULT
keycreate KEYFILE_OTHER

(4) Check that keyfiles have been created with extension: .ijf

dir ‘~user/temp’
 keydir KEYFILE_DEFAULT NB. shows the data saved in the keyfile
 keydir KEYFILE_OTHER NB. shows the data saved in the keyfile

(5) Create some data in the base locale.

DATA =: ‘N1 N2 N3’ =: (i. 3 4);‘Data’;i. 12 12

(6) Create some data in the zzz locale

DATAZ_zzz_ =: ‘NZ1_zzz_ NZ2_zzz_ NZ3_zzz_’ =: (i. 5 4);‘DataZ’;i. 15 15

(7) Save and retrieve data

saveData(‘N1’)
saveData(’’)
saveData1(‘XXX’) NB.- Writes an empty item if the noun is not defined.
savedDta(’‘;’zzz’)
(KEYFILE_OTHER)savedata(’’)
(KEYFILE_OTHER)savedata(’‘;’zzz’)
retrieveData(’’)
(KETFILE_OTHER)retrieveData(’’)
See examples in the definitions:
saveData1
retrievData1
saveDataTemp
retrieveDataTemp

Definitions

D dltLastBox, dtDots
F filesList, filesListn
N nounsloc, nounsTable, nounsTableRetrieve
R retrieveData, retrieveData1, retrieveDataTemp
S saveData, saveData1, saveDataTemp

dltLastBox (monad)

Type: tacit
Delete the last box if two or more boxes.

Syntax

dltLastBox(L)
L = boxed list

Example

  dltLastBox 'asdf';'sadf asdf';'exe'
┌────┬─────────┐
│asdf│sadf asdf│
└────┴─────────┘
  dltLastBox <'asdf zxc'
┌────────┐
│asdf zxc│
└────────┘

dtDots (monad)

Type: tacit
Delete trailing dots.
Taken from ‘strings.ijs’

Syntax

dtDots(T)
T = text

Example

  dtDots 'asdf...'
  dtDots 'as .. df'
as .. df

filesList (monad)

Type: explicit
Depend: dir,cut,each
List of files in a folder as a text with LF
Useful for producing a list for windows.
Only the files from the folder are listed. Files in sub-folders
are not listed.

Syntax

filesList(F)
F = path to folder
   filesList(jpath '~addons/finance/fp')

filesListn (monad)

Type: explicit
Depend: dir,cut,each,joinstring,each
List of files in a folder as a text with LF - no extension
Useful for producing a list for windows.
Only files from the folder are listed. Files in sub-folders
are not listed.

Syntax

filesListn(F)
F = path to folder

nounsloc (verb)

Type: explicit
Depend: cut,each
Show all the nouns in a locale with the locale extension
as a boxed list.

Syntax

nounsloc(L)
L = locale name

Example

   nounsloc 'z'
   nounsloc 'j'

nounsTable (monad)

Type: tacit
Table of nouns in a boxed table with name and value.

Syntax

nounsTable(L)
L = boxed list of noun names

Example

  nounsTable 'g' names ''
  A =: i. 2 3
  B =: 2 3 $ 'a'
  nounsTable 'A';'B'
┌─┬─────┐
│A│0 1 2│
│ │3 4 5│
├─┼─────┤
│B│aaa  │
│ │aaa  │
└─┴─────┘
   nounsTable ;: ,names_z_ 0
   nounsTable ,&'_j_' each ;: ,names_j_ 0
   nounsTable ;: names 0

nounsTableRetrieve (monad)

Type: explicit
Depend: each
Retrieve nouns from table created by nounsTable.

Syntax

nounsTableRetrieve(T)
T = boxed tabled created nounsTable

Example

  'A B C' =: 'AAA';123;i. 3 4
  T =: nounsTable('A';'B';'C')
  D =: 0{ T
   erase('A B C')
   nounsTableRetrieve(T)

retrieveData (verb)

Type: explicit
Depend: retrieveData1,ketdir,smoutput
Retrieves all nouns or selected nouns from a keyfile to
the base locale or other locale with noun names.

Syntax

([K])retrieveData(N)
[K] = optional keyfile name
      default =  KETFILE_DEFAULT
N  = '' all nouns in locale are saved to the keyfile
     noun name to be retrieved from keyfile
     can have locale extension eg: N_zzz_

Example

  retrieveData('')
  retrieveData('N1')
  (KEYFILE_OTHER)retreiveData('')

retrieveData1 (verb)

Type: explicit
Depend: keyread
Retrieves one noun from a keyfile to base locale or other locales.
Assumes that keyfile exits.

Syntax

 ([K])retrieveData1(N)
[K] = Optional keyfile name
      DEFAULT = KEYFILE_DEFAULT - as defined in the base locale
N   = noun name to be retrieved from keyfile
      and written to the workspace
      can have locale extension eg: N_zzz_

Example

  keydir KEYFILE_DEFAULT  NB. shows the data saved in the keyfile
  keydir KEYFILE_OTHER    NB. shows the data saved in the keyfile

   retrieveData1('D1')
   retrieveData1('DZ_zzz_')
   KEYFILE_OTHER retrieveData1('D1')

retrieveDataTemp (verb)

Syntax

([K])retrieveDataTemp(N;[L]) y
 [K] = optional path and keyfile
       default = jpath '~user/temp/tempkeyfile.ijf'

Example

  retrieveDataTemp('')

saveData (verb)

Type: explicit
Depend: each,fexist,ketfile,saveData1,smoutput
Saves the nouns in base locale or another locale to a keyfile.
Assumes that the keyfile has been created.

Syntax

([K])saveData(N;[L])
[K] = Optional file name
      DEFAULT = KEYFILE_DEFAULT as defined in the base locale
N =  noun names of data to be saved to keyfile
     ''  all nouns in locale are saved to the keyfile
     'D1'  is saved to the keyfile
     'D1 D2' are saved to keyfile
[L] = optional locale name
      default locale = base
      locale extension is added to noun name

Example

Create data in the base locale
   DATA =: 'N1 N2 N3' =: (i. 3 4);'Data';i. 12 12
   names 0  NB. show nouns in the base locale
Create data in the zzz locale
   DATAZ_zzz_ =: 'NZ1_zzz_ NZ2_zzz_ NZ3_zzz_' =: (i. 5 4);'DataZ';i. 15 15
   names_zzz_ 0  NB. show the nouns in the zzz locale

  keydir KEYFILE_DEFAULT  NB. shows the data saved in the keyfile
  keydir KEYFILE_OTHER    NB. shows the data saved in the keyfile

  saveData('')
  saveData('NZ1')
  saveData('NZ1 NZ2';'zzz')
  saveData('';'zzz')

  KEYFILE_OTHER saveData('')
  KEYFILE_OTHER saveData('N1 N2')
  KEYFILE_OTHER saveData('N1 N2 DATAZ';'zzz')

saveData1 (verb)

Type: explicit
Depend: boxopen,keywrite
Saves one noun in base locale or another locale to the keyfile.
Assumes that the keyfile has been created.
Data in a locale other than the base locale is saved with the
locale extension. This allows the data to be retrieved to the
originating locale.

Syntax

([K]savedata1(N;[L])
[K] = Optional keyfile name
      DEFAULT = KEYFILE_DEFAULT - as defined in the base locale
(N) = noun name of data to be saved to the keyfile
[L] = optional locale name
      default locale = base
      locale extension is added to noun name

Example

  D1 =: i. 3 4            NB. base locale
  DZ_zzz_ =: 4 5 $'asd'   NB. zzz locale
  keydir KEYFILE_DEFAULT  NB. shows the data saved in the keyfile
  keydir KEYFILE_OTHER    NB. shows the data saved in the keyfile

  saveData1('D1')
  saveData1('' )    NB. nothing written to keyfile
  saveData1('XXX')  NB. writes an empty item if no data.
  saveData1('DZ';'zzz')
  saveData1('DZ')   NB. writes an empty item as DZ not in base locale
  saveData1('DZ_zzz_')   NB. writes an empty item as DZ not in base locale

  KEYFILE_OTHER saveData1('D1')
  KEYFILE_OTHER saveData1('DZ';'zzz')
  KEYFILE_OTHER saveData1('DZ')   NB. DZ not defined in base locale

saveDataTemp (verb)

Type: explicit
Depend: ferase,saveData,keycreate
Saves the nouns in base or other locale to the
default keyfile.
jpath ‘~user/temp/tempkeyfile.ijf’
This can be used to save the nouns when developing a job and
the nouns can be retrieved later.
If required for other use the file can be renamed
and relocated to another folder.
The default file is erased if already created - so make sure
that it is not required.

Syntax

([K])saveDataTemp(N;[L]) y
 [K] = optional path and keyfile
       default = jpath '~user/temp/tempkeyfile.ijf'
N =  noun names of data to be saved to keyfile
     ''  all nouns in locale are saved to the keyfile
     'D1'  is saved to the keyfile
     'D1 D2' are saved to keyfile
[L] = optional locale name
      default locale = base
      locale extension is added to noun name

Example

   saveDataTemp ''