Emulating APL*PLUS/PC Native Files
Vector 12:1, page 137
The text of this article is not yet online.
Read it in the PDF of the issue, page 137
Unedited OCR text, machine-read from the scan: it contains errors, and its APL is wrong. Shown for searching; read the PDF.
VECTOR Vol.12 No.1
Emulating APL*PLUS/PC Native Files by Adrian Smith
Background I never took any great delight from coding for the old O¥READ functions in APL*PLUS/PC, but at least they were fast and totally reliable. [ can also appreciate that there is a lot of application code out there which would really appreciate a no-brainer conversion to Dyalog/W. This particular collection of functions sets out to emulate the old native file standard quite closely (even failing on DOMAIN ERRORSattheright places) so please let me know where you find inconsistencies.
Howit all works The basic technique is to overload the various OWA calls so that the same code can be used to read characters or mumbers(integer / float) without the overhead of data-conversion in APL The speed on integers is quite frightening ~ this will read 4000 integers from a random offset into a 4Mbyte datafile in less time than you can measure.
Just for the funofit, I have also included a cover for 0FREAD to pull in data from an APL*PLUS/PC componentfile. If anyoneis up to the challenge of completing the set of these (and extending the set to cover PLUS I files) pleasefeelfree.
The APL Code The first stage is to declare all those external calls - this one is called automatically by all the other top-level functions. Note that is keeps a globaltable offile-tie numbers andthat positive tie-numbersaretolerated.
NInit a Set up QNA functions for native file I/0 DNA'I kernel.P16(_Icreat <oT I" ONA'IT kernel.Pi16|_Iopen <of I' ONA'U4S Kernel.Pi6|_llseek I uu I'
a Read and write characters as 1-byte unsigned ints _treads2'QWA'U kernel.P16|_lIread I >U1[] g2' '_Iwrite82'ONA'UW kernel. P16|_Iwrite I <Ui{] g2'
a Repeat the above for two-byte integers
137
VECTOR Vol.12 No.1
'_Jreadi63'GWA'uu kernel.P16j_Iread I »12C] 2' 'Iwrite163'ONA'U4 kernel.Pi6|_lwrite I <Z2{]} U2"
e Repeat the above for float '_Iread6us'QNA'Uu kernel.P1i6|_lread I >FaC) v2! '_Iwriteé4s'QWA'UG kernel.P16|_Iwrite I <F8C] u2'
QWA'I kernel.P16|_lclose I'
a Clear log for (Tie Handle Name) of each tied file _nties+o 3p0 0 't
fi NCreate tnsfh a Create new file (no result) >(3s0NC'_Icreat')+O£C+1 © NInit +(tne_nties({;020])+TieFrror fhe_Icreat fi 0 ¢ +("1=fh)+TiedError _nties;t+tn fh fi o +0 Ae = Error Handlers == TieError:'PILE TIE ERROR'OSIGNAL 18 © +0 PiedError:'FILE TIED'OSIGNAL 24
reAscii;QI0 a Make ASCII translate table r+256p'p' © TI0+1 ECB2FI2|4+! LP HSL (}et,-./0123456789:5<=>7! F[64+132)«' @ABCDEFGHISJKLMNOPQRSTUVWKYZ[\]a_! c[96+132]+! abcdefghijklmnopgrstuvwxyz{|}~ ' r[9 44 14]+0)7e
bytes NAppend tn;fp;fh;ct;len a Write to file starting at the end. fp+_nties[;O20Jitn o +(fp>2p_nties)tTieError fh+_nties(fp;1+070) a Jump to the end ct+_liseek fh 0 2 a Check data type and use correct function +(2s|sbytes)+DmnError +(Oz1+0pbytes)+Char +((3276B0,>|bytes)a(bytess.=lbytes))+Plusint +Float
Char: bytes+(-010)+255 |Asciiibytes denepbytes o ct+_lwrite82 fh bytes len o +0 PlusInt:len+2xpbytes e° ct+_lwriteié3 fh bytes len © +0 Float:len+axpbytes o ct+_lwrite645 fh bytes len o +0
== Error Handlers == se
138
VECTOR Vol.12 No.1
TieError:'FILE TIE ERROR'QSIGNAL 18 © +0 DmnError:QOSIGNAL 11 0 +0
size+NSize tn;fp;fhysink a File size of native file fp+_nties[;0lOlitn ¢ +(fp>>p_nties)+&rror fhe_nties{fp;1+0I0] a Remember where we were, seek to the end, restore! fp+«_llseek fho 1 sizet_llseek fh 0 2 9 sink+_llseek fh fp o +0 Error: 'FILE TIE ERROR'(SIGNAL 18
den WResize tn;fp;fh;fn;ct;bytes;size a Resize file starting at given byte a NB not more than 64K please!
fp+_nties(;0f@0litn o +(fp>>p_nties)+TieError fh fne_nties{fp;1 2+0ro] size+_llseek fh 0 2 © ct*+_lIseek fh 0 0 bytes+@ © +sizetNull ct bytes«_lread82 fh size size Null:bytes+lentbytes a Now untie it and rewrite from a clean file fhe_Iclose fh fhe_lcreat fn 0 © +len¢Zera ct+_Iwrites2 fh bytes len Zero: _nties(fp;i+0I0]+fh +O as Error Handlers TieError:'FILE TIE ERROR'OSIGNAL 18 © +0
NUntie tn;c;fh a Untie native file(s) fhe(_nties[;DI0letn)¢_nties[;1+070] +(Oepfh) to r+_liclose fh a Remove from file ties _nties# +~tne=_nties[;0Io]
fi NTie tn;fh a Tie another file (no result) +(3=0NC'_Icreat')+O£LC+1 o NWInit +(tne_nties[;0%0])+Tiefrror fhe_lopen fi 2 © +(71=fh)+TieError
139
VECTOR Vol.12 No.1
nties;+tn fh fi o +0 A == Error Handlers == PieError:'PILE TIE ERROR'OSIGNAL 18 o +0
fn WErase tn;fp;fh;0penFile se Erase native file (must be tied). fp+_nties(;QI0litn © +(fp>>p_nties)tEkrror fhe_nties(fp;1+0I0] fp+_lelose fh a Remove from file ties and Zap it _nties#=+tne_nties[;010] OWA'I kernel.Pi6|OpenFile <oT ={U1 U1 U u1[4] T{128)} uv! fhe>OpenFile fn(136 0 0(4p0)(128+' '))512 +0 Error:'FILE TIE ERROR'QSIGNAL 18
bytes+NRead arg;tn;tr;getsofs;fA;ctisize a Get bytes (in appropriate translation) a Number of bytes to read is mandatory! bytes+'' o +(3>parg)+LenError tn tr get ofs*utarg o +get+0 fhe_nties(;Q0i0l]itn o +(fhe=p_nties)+TieFrror fh+_nties(fh;1+0I0] ¢ size+NSize tn a Check if we fell off the end >(sizec<ofs+getx2*tr+.=163 645 645 645)+InxError a dump to offset if given (mode-independent!!) +(32parg)+Read et+_liseek fh ofs 0 Read:+((82 163 645=tr),1}/ReadByte, ReadInt ,ReadFloat ,DmnError
ReadByte:ct bytes+_lread82 fh get get bytes+«Ascii(bytestOI0] © +0 ReadInt:ct bytese«_lreadi63 fh get(2xget) ° +0 ReadFloat:ct bytes+_lread645 fh get(8xget) o +0
A = Error Handlers == TieError:'FILE TIE ERROR'(OSIGNAL 18 © +0 InxError:'FILE INDEX ERROR'QSIGNAL 20 0 +0 LenError:0SIGNAL 5 ¢ +0 DmnError:OSIGNAL 11 9 +0
bytes NReplace arg;size;tn;fp;fh;ct;len;ofs a Write to file starting at given byte +(2¥parg)tLenError o tn ofs*earg fp+_nties([;Q%0]itn 9 +(fp>2p_nties)+TieError fhe_nties(fp;1+070)
size+NSize tn o +(ofs>size)+InxError
140
VECTOR Vol.12 No.1
a Jump to the right spot et+_lilseek fh ofs 0
a Check data type and use correct function +(2s|=sbytes)+DmnError +(O41t+0pbytes)tChar +((32768a.>|bytes)a(bytesa,=lbytes) )+Plusint *Float
Char: bytes+(-0I0)+255|Asciitbytes denepbytes o ct+_lwrites2 fh bytes len o +0 PlusInt:len+2xpbytes o ct+_lwritei63 fh bytes len o +0 Float:len«8xpbytes o ct+_lwrite645 fh bytes len © +0
ASS = Error Handlers == TieError:'PILE TIE ERROR'OSIGNAL 18 © +0 TnxError:'FILE INDEX RRROR'OSIGNAL 20 © +0 LenError:QSIGWAL 5 » +0 DmanError:Q)SIGNAL 11 © +0
r+NNames e File names currently natively tied ret_nties[;2+0I0]
c+NNums a Piles currently natively tied r+_nties[;0I0]
The componentfile emulation (such asit is) simply uses the above functions to do the donkey-work! Note that to maintain separation between native and componentfiles, it would probably be a good idea to stay with the PLUS/PC standard of negative tie-numbers for nativefiles.
fi Ffie tn;O0TRAP a Tie component file to given <tn> OFRAP+(18 24)'E' 'OSIGNAL DEN' fi,e(~'.'efi)/' ASP! fi NTie tn
size+FSize tu;fp a File size of component file (always starts from 1) fp+_nties{;OfOlitn o +(fp>2p_nties)+£rror a Allows 128 components! There must be a better way!! size+1,1+h+"1170 0 0 Oe9+NRead tn 163 512 0 size,+(NSize tn),0
141
VECTOR Vol.12 No.1
+0 Error: 'FILE TIE ERROR'QSIGNAL 18
FUntie tn a Untie component file(s) NUntie tn
z+FRead arg;tn;cn;fh;sa;sh;t;tr;0I0:0;0TRAP a Read PC component file ties as <tn> Qf0+0 o +(2#parg)+LenError ¢ tn cnearg fh+_nties[s;0litn o +(fhe-p_nties)+TieError fh+_nties({fh;1]
O+_liseek fh,(axcn+1),0 sa+oir>_lread@2 fh 4 & o +(saa.=0)+InxError
sae2561(128|itsa),it+sa O+_liseek fh,(sa+9),0 0 trei1>_lreads2 fh 2 2 o t+tr[o]>8 tr(o]+(82 163 645)(1 2 81i6{er[0}]
a Long-stop trap for index errors OTRAP+20 'E' 'QSIGNAL DEN!
shtNRead tn,(163 323})[t],trlil,satit z+shpNRead tn,tr{0],(x/sh),satiittr(i}x(2 4¥)Ct] e¢ +0
== Error Handlers == FieError:'FILE TIE ERROR'QSIGNAL 18 © +0 InxError:'FILE INDEX ERROR'OSIGNAL 20 © +0 LenError:QSIGNAL 5 © +0
Limitations It is not obvious to me what happens to a componentfile with more than 128 components! The PLUS/PC strategy is to allocate space on the index for 64 components whenthefile is created. When you write the 65th, it clears space for another 64 (re-locating anything that was in the way to the end) and so on. The above FRead function will cope quite nicely, but I cannot see an easy way for FSize to know howfar to look into thefile for the one beyond the last marker of 4 consecutive zeros! To save searching the entire file redundantly, I just give up at 128.
Ps Apologies to non-Dyalog users for the gratuitous use of slash-commuute-gets in several of the functions above. I gota little carried away, but I am better now.
142
VECTOR Vo!.12 No.1
Index to Advertisers Causeway Graphical Systems Ltd 4
Dyadic Systems Ltd 24
MicroAPL 16
APLBooklist (Renaissance Data Systems) 32
Vector Back Numbers 8
All queries regarding advertising in VECTOR should be made to Gill Smith, at 01439-788385, Compuserve: 100331,644.
Submitting Material to Vector The Vector working group meets towards the end of the month in which Vector appears; we review material for issue n+1 and discuss themesfor issues n+2 onwards.Please sendthe text of submitted articles (with diskette as appropriate) to the Editor:
Anthony Camacho, 11 Auburn Road, Redland, BRISTOL,BS6 6LS Tel: 0117-973 0036 Email: acamacho@cix.compulink.co.uk
Authors wishing to use Windows Write or Word for Windows should contact Vector Production for a copy of the Vector APL TrueType font and Vector APL typebox.
Camera-ready artwork (e.g. advertisements) and diskettes of standard material (e.g. sustaining members news) should be sent to Vector Production, Brook House,Gilling East, YORK YO64JJ.
Tel: 01439-788385 Compuserve: 100331,644.
143
VECTOR Vol.12 No.1
British APL Association: Membership Form Membership is open to anyone interested in APL. The membership year normally runs from 1st May to 30th April, but new members mayjoin from Ist August, November or February if preferred. The British APL Association is a special interest groupof the British Computer Society, Reg. Charity No. 292,786
Name: Address:
Postcode / Country: Telephone Number: Email Address:
Category (please tick box) to run from: 1st May Q August O NovO FebQ) UK private membership .. 0.0... 020 eee eee eee £12 Q Overseas private membership ...........----.006. £14 Q Airmail supplement(not needed for Europe) .......... £4 Q UK Corporate membership .. 1.2... ..2.0.0....000. £100 Q Corporate membership overseas .................5 £135 Q Sustaining membership .........00.0 00.0002 c ene £430 Q Non-voting UK member(student/OAP/unemployed only) £6 Q PAYMENT in Sterling or by Visa/Mastercard/JCB only Payment should be enclosed with membership applications in the form of a UK Sterling cheque to The British APL Association , or you may quote your Mastercard, Visa or JCB number.
Tauthorise you to debit my Visa/ Mastercard/JCB account
Number: -it13 Lois pert criss Expiry dates ii] tt
for the membership category indicated above, Data Protection Act: AH + + The information supplied may be Q annually, at the prevailing rate, until further notice on computer andprocessed one year s subscription only in accordance with the registration of the British ComputerSociety.
(pleasetick the required option above)
Signature: CCC*C* é«SS@nd the completed form to:
British APL Association, c/o Rowena Small, 8 Cardigan Road, LONDON E3 SHU, UK
144
The British APL Association
The British APL Associationis a Specialist Groupofthe British Computer Society. It is administered by a Committce ofofficers whoare elected by a postal ballot of Association members prior to the Annual General Meeting. Working gtoups are also established in areas such as activity planning and journal production. Offers of assistance and involvement with any Association matters are welcomed and should be addressed in thefirst instance to the Secretary.
1995/96 Committee Chairman: Dr Alan Mayer European Business Management School, 01792-205678x4274 Swansea University, a.d.mayet @swansea.ac.uk Singleton Patk, SWANSEA SA2 8PP
Sceretary: Sylvia Camacho 11 Auburn Road, Redland, 0117-973 0036 BRISTOL, BS6 6LS 100612,1057 @compuserve.com.
Treasurer: Nicholas Small 8 Cardigan Road, 9181-980 7870 LONDON E3 5HU
Journal Editor: Anthony Camacho 11 Auburn Road, Redland, 0117-973 0036 BRISTOL, acamacho@cix.compulink.co.uk BS6 6LS
Activities: Vacant Post
Education: Dr Jan Clark 9 Hill End, Frosterley 01388-527190 Bishop Auckland 100021.3073 @compusetve.com Co. Durham DL13 2SX
Technical: Vacant Post
Publicity: David Eastwood MicroAPL Ltd, 0171-922 8866 South Bank Technopark, MicroAPL @microapl.demon.co.uk 90 London Road, LONDONSE! 6LN
Recruitment: Jon Sandles 22a Arthur Street, 01904-411635 Lawrence Street, 100257, 1756 @compusetve.com York YO 3EL
Administration: Rowena Small 8 Cardigan Road, 0181-980 7870 LONDON E3 SHU
Journal Working Group Editor: Anthony Camacho 0117-973 0036 Production: Adrian & Gill Stith Brook House, Gilling East, YORK (01439-788385) Advertising: Gill Smith Brook House, Gilling East, YORK (01439-788385) Support Team: Jonathan Barman (01488-648575), Duncan Pearson (01653-618900), Richard and Adam Weber (01302-539761), Sylvia Camacho, Ray Cannon (01252-874697), John Scarle (018 1-858 6811}, David Ziemann (0171-267 8032), Jon Sandles
Typeset by APL-385 with MS Word 5.0 and GoSctipt Printed in England by Short-Run Press Ltd, Exeter