0% found this document useful (0 votes)
231 views60 pages

Guide Fortran 77

The document discusses different types of procedures that can be used in Fortran programs, including intrinsic functions, statement functions, external functions, and subroutines. Intrinsic functions are provided by the Fortran system and have predefined data types and behaviors. Statement functions can only be used within the program unit they are defined in. External functions and subroutines allow code reuse across multiple program units.

Uploaded by

acid94
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views60 pages

Guide Fortran 77

The document discusses different types of procedures that can be used in Fortran programs, including intrinsic functions, statement functions, external functions, and subroutines. Intrinsic functions are provided by the Fortran system and have predefined data types and behaviors. Statement functions can only be used within the program unit they are defined in. External functions and subroutines allow code reuse across multiple program units.

Uploaded by

acid94
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

9

PR'OCD UR'S

dallv a proganl shou]d on]! en conlro] t, tc opcraring systcrn from onc poin. thc d o tlc mail pga}, lhc hc END sia,tc!.nt dcs a.ll 1a iS nccssay. n pact]cc. cc n he bcst p]and po8anls. Siiuatios ca ain] w]llcn ak,r it po]t]Ss ro cont]nue. f ihcsc ac dccccd i1 the main pogim t]ere is a1ways h op]o of iumpirg hc END Siacmeni. bu ,iil poccdes ticrc ma1'be no choice but to use a ST0 staor.

Procedures

Any sct of compuarjos can be cncapslaed in a pr'ccde. The main prpose o a poceduc is o a]]ov tie Sam sci o opc:t]ons to be invoked at d]ffcnt pins jn a pgant. Poedues :lso nak. it possible usc he sac codc in sccal cliflccn plogam$. r js good pacticc to sp1it a agc prog: io Secjos g,hcncvc it becmes ioo 1agc to bc ;'nd]cd cnveicnt] ir o pie]. The optimum sizc f a pogar ni is qite sma]], pobably no nrore than 10 ies. lbr diieent fors of ploccde can be sed in otan pogams:

. . . .

nt]isic frrnions
sta.tcmcnt f11nclio1s

Exenal unctiols sboniies.

(a,1s

knon as

tcio subprogas)

nijnsic funcions ac pvidcd auonatical1y by t }btan syscm, \hcr'cas rc ohc hcc foms ofpocedue ac usc \jiicn. statement fuciioS. '',/hich ac dctji.d with thc Satcn funcion stateme, can be only be used i the pogm ui in which t1cv q.clc dclincd and ae subjec 1,o he Specja1 stictions. xterna,1 fucions and S11butins:c i$,o ]icaj {oms o cxte i pocede: each is speciIied as a. sepiile pogam unjt and .i' bc nscd (w] only a fcw cstictions) inJVhec csc in hc pglam.

9.1 ntrinsicFunctions
irisic uncios hae a ber o ui1uc popeltics. :e daa type of cac1 intnsic ircti iS knvn to 1c tan systcm and iS nt subject to he noma.l lcs. 4LCT and yrc statements a]onc ha,ve o effect on ticm. somc jntinsic frrnctions ha\.e gncic n:mcs: w}cn t1csc arc scd thc compii sc1ects the appopiate specific function accordjng io he daa iyp
of thc ag1mcns.

intinsic funct]ols S. as M, MN, and C{P,X, ae a1loq,ed o hae a iab]e nunrbc of agumcnts, but a]1 of t1e ageS nus hav le sane data typ. sc li pocdes canno have optiona] aguments gcn.ic tpc. ,{1though intjnsic functions can b. scd n ay pogan unit, hc] n:mcs ac no g]oba], n ae hcy cscIvcd \!ods. is, howvc, bcst t aoid chosjng a, nmc f a aiab] or alray vhich is idalica o ha o a ininsic funcion. Jt na"v cause colfsiolr and in e 1og n it nay nrake i more dj1ict to eace the pgam' A namc c]ash iS 1oc seious ii jt invo]ves an cxtenal fnction o subrrtincj fo in this casc he exena.] pocedc nae us bc spccified in an EXTERA Statcm.nt to ]'cso]vc 1h i]"mbiguiy. By his meaS ]t iS possib] Subst]tute :n cxtcna fncion o{ yo on fo onc f thc iniSic fuctions. The Fotal Standard speciIies a ai1y exte]sivc sct of jntr'insic funcions whjch mSt al\'avs b a.a.ilab]c but i docs not pcvcnt t1c povision of dditiona1 ones. {a,ny systcms prvide :.]d]tiona itinJic fnctios hich, o exanple. bta.in t}c crent date and time, geneac

fe\\,

PkoC:DRS

pscudo andom rrunbS, eva1uatc Ga11ssian pobabi]]iy. Thc mai dawback jn .,ir,g nU sandad ncions 15 that yol1 ma hale o ]ind a substitue if ]rot p8am ]s nov]d lo a.notler

st:ndad iniinsic lurcins fo hc aritheic ypes ara descibed in detai] it secion \jh chaacte-Stings arc coeled in Section 7.5. A comp]ele a]phabtica] jsi. is p1idcd i thc appcndix.
6.2i Lose used

Tlc

,.

',

don

9.2 StatementFunctions
Saee funcjns can be dc]icd ith]n any execable pgla unit by means of st:tcmclt uncio $aenenS. They can only bc rrscd. ho\eve, wjth]n thc same pogan unit. ,{1thugh sacIne ftlncions hav mitd uscs, thcl'ae unjuslly ncg1cced bJ, many pogammeS.

Thc statcmcnt fuction saemeni ese1b1cs an ldini1y aSSjgnmni sa"emct. o examp1c: FR(CES) = 32-0 + 1.8 ,, CELS f'he funcion E{R convcts a tcmpeae jn degees cc]sius o jts cqjQle in Fahnhc]t. hus tl.(2') 1ou1d ct!n a 'alte 68-0 a.ppordmacty. siaiem fnci1 ca have any nunrbc f dmmy argmnts {sch as cs abore) a of 11hich mst appca jn tlc cIpass]on on he lght'had sidc; his expcss]on ni], iSo inctrdc josanS, vaib]esj o atray elemcnts Scd clse$,hcle it ]e p.gaIn. Wen thc fnction iS :trl]d te cuenl va,]ues of thesc icms vjl] b lsed. br cramlc:
REAL M1, M2, G, R NE!i0N(l41, ),2, R) = G
-{ re{eence

* y\\ *'t12

R**2

o h fnctin ]n an assige Statcmrn sch aS: F0RCE = {Ei,T(x, , DST) r]]l l.iIn a t]ue depending on thc values o ihe actua.1 agumets 1 , and Ds', and hat f ti. \al]ab]e G a he t]me thc functin ]s eeencd. Dcfinit]ons of sl;.men fucions ca.n als jnc1d Iceelccs t inti1sjc functions. .]enl funis, o !.v]o1S]y deflned saeen {uctlons]

( = 3.14159265, DTR S]ND(THT) = S](T]{ET * DTR) cOsr(T11ET) = cS(]iET * DT!R)


RMETR TND(T]]ET) = SD(HET)

= /1E.0)

coSD(TET)

T}s deJir1itins al]ow lignonlei}, o angies Speci1ied in dcglcs rale la:r adians. The scope o{ each dumm} agnt nac Guch as T]lT above) tha of thc saement alonc; thcsc narncs ca bc uscd c]sc,]c ir ]lc pl'gralr uit aS va.jb1.s of thc sime data tpc 1]h no cff.ct lhatcvc on ih. cva]laio ollhe cio. Stateer ncjols can havc any data typc; thc name and arguments f]to1 ri. norrir] typc ru1es' T1ey can be sfl in chaactc hand]]g, for cxallple:

L0GCL MT, DGT'


CHRCTER c*1

DRM

DGT(C) = LGE(c, 'l]') 'AND. LLE(c, '9,) l4A](c) = NDE1('+-*/'. c) .E. 0 DoR,l(c) = DGT(c) .0R' MT(c)
1'ese thee rrnct]ns each

ment: DGT 1.s1s

1o Se.] q.

ein a togical vale 'len pcscntcJ \jt siglc chaacc agu ]e 1tc chaacr o iS a ligii, MTH crll. i iS a p'i]:o s!nb11

9 PkoCDUkS

65

and DRM wj tcst {o c]hc co]djt]on. ]!tc thc usc of hc ]eaica1 compjson fuciios LG and LL in t1c de]initjon of DcT which la{j i cn1p]ccly j]ldependc1 c ]oca] chaactc

Statement Fnction Res


statcmcnt tuncin slieis mus appei aer any i. speci1icaion Saic1nts but lrcfoc al1 .xccu1abe satcmcnS in the pogam ni. They a be ]n1nrid with DT and FRM 5tatcncnis. T}e geneal fo isj fnctio ( ]umm|! 1, d1mm2' ''' dLlnm|JN ) - cpresskn Trc functin may 1avc any data typi the eJpress'on wi]] normay have he sa:e data typc bi if ]roth h:ve in iitlmctic tyc hcn thc nomi1 cneSion ]es o ajthctic assignmc.t statcmnts a,pply. The narn of thc 1rncio st b dist]nct fon al1 othe symb1ic aes in t1e progral unit. t .y appea i typc satecnts bu no in ot]e spccifictjon Stacmcn1s. (Thcre js onc exccptio; a common b]ock is pied o have ihe Sa.no naD1e aS i' slaenen funciion but sjnc cmmn b]ck nanes aways appea bet',ccn sishes thcc is i1e jst of con1us1n). h functin ha.s chiace type its 1cngth must be , egc cnsan expcssin. hc dumn aglments ac Sjmp1y Synlro]ic nanes. ramc may no appca. moc ihan once in t}c sime ]st. lhcsc n;ms my bc used elsevhclc in ie progan uiji as ajabes of ihc

The expession nust contain ihc dtmny igumets as opca,1ds. The opclands nlav

aso

. . .

itea1 consiantr, named co]stants, ,,aiab1cs, and a,a.y c]cmeSi hese wi] havc va]s a.t t} ime thc fuction jS cxccrrcd and must thcn be dlincd. efeccs to ininsic a,nd cxtcnal functjns.

tlci

efercnccs to sateme]t funciions d.fincd eaie ]n tc sne pgra njt,


coIp]ete epcsSins enc]osed in paentheses.
it1

Nte thi't ca"acer Substings ae not pmjed. The varjab]es and aav c]ecns used thc xplession rst be dcfilcd ; lhe iine ihat he fuction cfeence is cxecuicd'

cuidelines
lrough statement fnctions hal.e a ]jnjied ole o pay in pgams becaSe tey can on1y bc defined in a sjng]e siaeen' feencs to statcmct funcions they m'y be executcd moe ei' cjently tlin lefelences to extena.] fnctjons; many modcln conpilcS axpind statcment 1unction cfccnccs to in-[ne code when jt is i'dantageous to do so. f thc same statement function js nccded in moe than one poga,m unit ]t \,ou1d js possib]c use an NCUDE faci]ty to povide the same de1inilio each imc. b ]t wj usua]v be bete to usc an cxtena fction insead.

9.3 Externalrocedures
Thcc arc tw unit.

for

s of extena,] poceduc.

boh f whjch ake thc fom of a comp1ctc pg:m

PRo(:DiRS

66

Extea] filcit]s lhich ae speci1ied by a pogI:t ni siating wit a L]1JCTN Siac mnt' They ae xecltcd lvhceve th coespolding fu1cin used is a.n opcand in
an cxpessjo.
a, poga unjt staIting wit : SUBRUTNE stacmei. They aI crrccuted in esponsc to a cLL staeme1.

Subtines, .ich c spccificd by

n eiie fom he as statcmcnt of the pogam ]nit mst b. an END statamer. ,{ny thc s;tmcniS (except RcRM o BL0cK DAT statcmcntS) a"1'be use viihin the program uni.

Tlcc ae two saefucnts oidd especia,]]y f sc in cxtcrna] pocedcs. Thc SAVE Stat.men esu1es ti:t the va]es of 1cal \aiab1cs and ;rays ae pesclved afie ihe pcdtc lctuns cono] o thc ca]]ing init: hese "]ucs 'jl1 then be aaiabe if he pocede is execued sbseqrrcnt1. fhe RETUBI statcent may be used tcmina.tc thc cxccution of hc poccduc and rrsc an immediie etn to il coto] f he cal]irlg nnit' Exccrrtin of thc END Statcmcnt at the end of thc pocede has cxactly the Same efiec- Bo of hese a.r dscibed in ft ]ae

{ost otan systems iiiso a11oi, etena] pocedlcs to bc Spccificd in 1a8lages the than Eoan: they can be cacd in the same vay as tan pocedues b thei ineal oreaioS ae. o collSc, bvond he scop of this boo. t is bcst io ihiI of thc subouine :s t]c mrc 8c1ca1 form of pocedule; he exea] nnctio] Sto]d b,] rcgardcd as a speci:l c:sc for usc hen yo oly need o eil i si1gie va]u to the ca]]ing uni. Hc is a S]mp]e exanpc of a poceduc wjch cnv.is a t]mc of day ] hS, minutcs. and secods ino a cnt of Seconds sinc. midnight. Since oly one va]e ecds o be reur ed, he pocedue n havc te {o of,n ctcnal funcio. ( c }is is sch i simp]c ,]xamp]e hi' ] rou]d ha,a hcn ossibe o definc it as a statcment funcrion.)

*TSECS convets hous, ninutes, seconds to total seconds. REL FUNCTN TSECS(!URs, MNS, SECS)

RA
E],D

Ti4E = ((NURS * 60) + MNs) * 6 + sEcs


',1e use ; fnciion refeencc ie TSECS(12,30,0.) in a explssiol elsawhclc in tc plgra, i ,i11 convert hc t]mc to s'conds sincc midtigh (about'15000.0 Sccods i1 th1s case). T1c items jn pacnheses {t thc functjn na1nc : (12,30 ,A .0) a ]rnown aS the a.ca agmets o ilc function; hse acs arc tarsfetel to the ceondjng dn1y a]gncnts (,lHURS, 4NS, SEcS) of ihe pccde befoa it ]S cxccued. h]S cxamp]e he i'gumcn ]jsi ]S uscd o1y o ansf infaion into tle tl{jtion f1 osjdc. thc funcion na itslf ctuS tie eqied a,]e ro th ca1lig pgil.]. l subtiies. holcvc, hee is no unctjon nanle to etu i1tolajon bt the agmens c:n bc usd o ilansfes in ihj dirccion, bth. Tc rlcs pormir rhom o bc sed il this e gcnc.1 1,ray in fnnctions, bu i is a p:cticc best aoided. j is o T1] n.xt ex:mplc peos th. ]nvcS :onvc1slot to ihe 'SECS fnctjn. since lciun ]']c au.s t the caling prg:l uni he fnctjnalfom is 1o ]ongcr apopiael atd : sl}lr lt] ,il bc Sd insiead.

I,ITEER NOURS, MNS SECS

Tius if

PRoc'-r'REs

0-

*Suboutine HMS converts TE


R.EAL

SUBROUTNE ]},1s(],!E' EoUES, MT]rS, SECS)

in

seconds int hors, nlns,se.s'

TME, SECS

NTGER HURS, MlrS }.oURS - NT(TME / 3600.0)

SECS MNS SECS


D

= l,lE - 3600.0 * {OnS = T(SECS / 60.0) = ME - 60.0 * MNS

n ljs ase thc sbuti]c coi]d be cxccrtcd b sig a statelcnt stch i's:

cAL Ms(4500.0,

NRS, MNS, SECS) l,lRTE(UT=*, MT=*) NIRS, M]NS, SECS ee th ]ist agument ira.nsfes jnfomat]on int the suboutine, he oihe hee ae used to ctuIn thc \a1es which it ca,lclr1ates. b d ot ha'e o Specify vhctha a p;liclal irgment is o tansfe infol'ma.iion i o ont (or i both dicc1os), bu thee a u1cs about thc fom of aclua} agment :l you can Sc in cach ca.Se. hSe ac cxp]ained in fu]] be1o'.

Pocedure ndependence
nach p1ogirm ni has its oq,n jndependenl sct of s],mbo]ic niies and ]abe]s. Type StttmetS atd MPLCT Statements may be used to specjfy ihei daa ypes' Dxtena,1 pceducs can thcmse1ves ca ay the proceducs :nd tcsc may ca.]] othes in n, but pocedic ac nt al1owed to ca themse1vs eitic diecil!, o jdiectlyi ha iS ecusivc caing is no peniied in Fo1tan.

nfrmatin Ttnsfe
n1bmatjon ca,n be tansfcrred to

ad fom an ejrtnal poccdle JJ any of he ehods.

. .

n a.gumcnt is: as s1own in he two cxamp]cs aboe' ThiS is thc pcfcicd method of indacing aS it is the mst flexibe and modu]a. iS descibcd in dctajl jn thc cm:jnde1
of this secio.

cnmon b1ocks: thcse ac lists of vaiab]es o arays which a.c stocd in areas f arcas of meoy shaed bt1een two o orc pogam units. Thex ae urefl in spccia.] ci cmstances wen procedues have o bc coupld c]osc], ogethe, bi a ohlw]se ess satisfactoy. cormon bocks are covccd in detaj in scction 12. Extenal fi]es; jnecing ia cxtcnal ]iles js neit1e conl,enienl o cfflcint bui it is ment]oned hce to poirt oul tha.t cxtena1 fi1es a glolral. oncc i' fl1e has bccn opcncd in any progain njt it cin bc ,.cccsscd any\,he in the oga povided hat the appoprjae /o unit number is avaiab1e. nit nmbe can be passcd lno i proccdc aS an intcgcr lgtmc1t.

Pcedue Exection
t is not necassay to know how he l'oan system a,ctua]1y li'nsfes ifoaiion {m one pocde to another makc usc fthc S],Stcm, bt thc r'u1es govening thc pccss ac somcwhat

PROCDRS

comp]icaed and jt ]1ay ] casicl o utdeStand hcm it you appecia,t. ihc basis on wic thcy a] ben fomu1atcd' Th rlcs in th }'ota Sia.datd are based n tc assurnp1'io that e addess of an actua1 agrrcn iS iansfcrrd ilr cach case: }iS ma], or may not bc tc in pa.cticc but lic propcies i]l be th Samo as jf it iS. This mei'ns th lhel you rfclclce a dnnry vaiab1c r assign a c a1ro to oc you uc 1]kc1 to bc usjng thc mamo}, ]ocaion ccpicd by thc cta1 ag11mt. By his mcans ccn lage i':ys ca be ansferd cfiicicnt]y to pocedues. Sigh odiicatjor of thjs syse1 is eded fo jtems of chaactc tpe so hat th tength of he iten ca ]rc linsfcd iS 'e aS ]iS addcss. When a {nc]on eeec o CALL Satenen is exectcd :ly expessions il he agumn ]rst ae cvalatcd; thc a.ddcsses f he agumcnts ac then pa,Sscd to the poceduc. \vhen it ctu]s contolthis a01!atica]y makcs pdatd ]ues availab]c o he crcsponding itcms in

c actua agument [st'

Functins with Side-etrects


'hc rlcs f fotan il]o\ fuctions t havc s]dc effecs, that iS to te thc] acua a8um.ns o change other aiab1cs wihin comlnon blc]s. Euncrions ith side etrecis cannot be sed jn pessions ,1rcrc an o[ he othe peads of he expession \ou]d be affc.ed, no can thcv be uscd jn sbscip o sbstring c1'ccnces \ ]en any l1er expession rsd i hc same rfcctlccs vou1d be iIeced. T1jS u] cnsulos ha the va1rr o an xprlrssjn cannot dclerd arllilaily on he r.a i 1t1]ch th cple chooscs cvauat i1. Tlle ile ;]s resictioS on funct]ons 'ich ma.e usc of jnpt/orrtpi Statemcnts even o1 ]nena11i1cs| thcsc c:nnoi be used i] cpcssios in oth /o satemens. This is to avoid he /o systcm bcig s.l clrsiely. B.v fi. the bes coSe iS t usc thc suboine fom f an} poccdrrc',ih sidc cfc5.

9.4 rgunents

of Extena] Procedures

8uments ca pa.Ss infornation iIo a pocedurc o oui m it, o in boh diect]ns. Thjs jusi depeds on the 1'a tha ]rc dtrny agumen iS scd 1ihjn thc prccdue. 1thugh ay agueI ode i5 pemjtd, jt iS comm pracice o pui jnpt iglments irst, hen thosa ]rai pass ]nfoI:ion boh a,ys, and thcn agumenls whic ]rrst refun ifoma.tion m thc
Tl ues fo g1nen associatio aJc thc sarnc 1b boh fos of cxternil poceduc. The list of dum1' aguts (Somct]es ci]ld foma a,rguments) ol an external pcedr is spcciicd i ]tS FU,CTON o SUBRONE saeme11t. he can bc any nmber f:gurents. inc]udin8

nne

ai a.l1. { t1cc ac no :gnc1S hen the pacthcscs caI br oniitcd ]r ihe cAL :d SUBROUTNE sateen but oi ]i a FcT0N slatleni o function efeecc. The dny aguren LiS ]s S]]p1 a 1ist o1 s.vtbo]jc namcs ic cn epcscn ar.\ n]tuc

lrsc.] v]hi

,{ naIc carot. of coscJ alpca, t\t,icc ] hc Sanlc drry aguncnr ]is. Dlllv variab1es, aays, a]d pocdulcs ac disiilgu]shc.l n1y b e wa],

hc Ircc.].. The djmcnsjon llol]s o{a dummy arays

fisl

b Spccjicd jn

thai h. ae
a

91'RO(:DlS

69

Subsqucnt tp] o DMENS0N s;cmeni dnin}' poccducs ms a.pear i a cL or xTRt statcmcn or bc uscd in : ndjn c{cencei anyrhing c]sc js, by c]iljla1ir, a dnmy agul]ni

same way as 1ocal iems of ti,] saI,:] fom,


EQUvAL\c sLaemcnts.

Durmy agulol aiabs r1 an'as can bc . ll "\ .-l ,. . 1. bi cy .1lll.n oDp,. " I sAv. c0Mr0\. D|l. n'

gument Assciation
Thc acl!:l agumcnls of lhc f]1ncion lc{ccncc o cll statcmcn lecne associaed li1 he cocspnding dunny agulclts of tle IUNCT0N o SUBRoUTNE st:tcmir. Tc majn u]cs ae as fl1ows:

. .

Thcc n1ust bc thc sam nu1nbc of:ctua] and dumJn]r agneIs;they ae associaed so1e11' by thei position in the t1v 1]sts. optional agumctts ac o eied jn 177'

t]e dmy agumet iS a vaiable, aay, o prccdlc sed aS a unction he he co1cspndjng i"ctua agune us hac e sin] data typc.

f the dummy agume]t is an aay then its a,rla1, brnds st not be ]age han those of the coesponding actual aJ8ment. A]eraiire]y thc dimcnsjr] boulds of a durnn1' ar3 can b pased in by mcans o, oi]l c po ccd o a gument S o fom an adj ust able. This option and tc a.ssucd sizc:llay ac both dcscjbcd in secio 9.6.

f thc dlrmmy agI

o h cocspondig actua,l agueni. Alternaively tec ]s ' passed . d,o, ]A, o,gUn nl c, c^. ,n, |ni ,,,q,

iS a c]araclel jten ihen js

lengil must no be gcate tan that ]eng ptio fo

m]snatchcs jn acuil ad dummy

Becise poga]r

decced by he nke, this raely seenrs to happen in pacticc. Eos, paiclaly mismatdes of data type o aay lronds. :c cspcciay ca.sv to malie bt ad o detcc. Someilcs thc o1y indication is that the pogram poduccs t}c wong a.nsle. ThiS Shows ]ow jpotat ] is o check pocedue jntclaccs'

uits ae compiled indepedent]y. it iS d]lic] o he copile o check fo agneni [sts. ,\t]ough m]Sni'thes could, in pincipte, be

Dpicate rgumentS
The same acta argumen c;1ot be sd noe han once in a proccduIc dummy agments are assigned new valcs. lo examp]e, $ith: SUBR"Ii{E FUNNY(I, ) = 2.0
ca.]]

jfihc coespndng

3.0

END

$,ou1d ty o a.Ssign both 2.0 ad 3.0 io th. vai:b]c A. ,{ Sini]al est]ction ippjcs to vaiib]es 1vhich ae etned via a comon b1oc1' and als thogh hc poccdue argtmeni ist'

c FUNIi(, ) lo1d b j1ega bccarrse he sysm

cal suc aS:

PRCr''DB|'S

70

9.5 aiables

as Dummy rguments
c]f

a poccdue is a valab]e and jt has i vaue assjgned t jt within pocede] then the coespondig acial aJgrrment can bcj f thc dumm}, agumcnt

hc

. a ?",3yn.n .

lo

a chaactcr S1bsijng.

howeve, he dmmy aiable peses its initia] value thoughout the cccutjon the t] actual aIgunent ca.n be ay of thsc thc frms a.boc o atea.tie1y| .
an expessjon of iny fIm (inc]uding a constant).
]s ca.Sy

st

Thc eason f this estrictions in hc ncxt cr.am1e:


SUBROUTNE

to sac by consjdeing thc vavs f caljne the Sbotine

.+M
F.]

SIL(,

M)

f it rs caed with a sta,teent such


NUMBER = 10

aS:

ctl SLY(NMBER,5)
thcn ihe va]ue of NUMBER l,i b pdated t 15 as a 1cs] of thc cal1. Bui the frction wit a cnstant as he ]iSt aeument, ths:

is jtegal t ca

cAL SLY(1,

7)

bccalrsc n crrit the Subrutinc \'jl] attcmpt to rcium the la,]ue f t7 io the a,cua agn vhich was spccificd aS thc constant tcn. Thc affects of committing Sich an eIo1 ie Systm dependent. Some systems detect the attcm!t to ovc lvitc a consani and issue an co eSsa8e; oiheS jgno tie attempt and alow the pogam to cntinle; bt some systens \,i[ actuitty go ahead and ove wie hc colSant wih a lew vaue, so iiat if yo11 use the constant 1 jn some Sbsequent staeen in the pogam you ay get a valuc of 17. since tlis ca, havc vc.v rrzzling cffcts and be hard t diagnose, i is impotani o avoid doing this nadvctcntly. f yo ma.c sc of pccdes ,jttcn by othc pcp1c ou ay be woied about rrninntionat eflects othis srt. pinciple ii shod be possibe o pevent a pIccdur ateing a constan agment by tuning eac one into an expession' for exa,mp1c 1ie his:

cL SLL(+1, cL SILY(
(1)

+5)

A1thou8h cithe ofthsc foms Sho]d potcct th. constanis. i ]s Si] against thc ucs f Fota fo th pocede o attempt to a.lc he va]ues of he coesponding dmmy agumcnts. o li1l havc o idgc 1.1the it iS bette to beak the rules of he languagc thn ro is coupting

'

(5) )

RCDRS

Expressins, Subscripts, and substings


hc actt:l agumet co iains crpessjons thcn hese a.] cva,uacd ]rcflc hc poccduc sas to cxccuc; cvc i{ thc pro:cdc iat modiies opcalds f thc cxpessi1 is has no e]eci n rhe va,]e passed t ihc dnlmy agtclt. '1c same uc applles o aray sbscrip ad cha.ace sbst]1 cpcssions. o exaple, if i1c poccdu ca]] consjs]js of: cAL SUB( RRAY(N), l(, S(4.0*N), ET(1:N) ) and the procedlrc assigns a nw vauc to tie second gmcntj Nl duing its e](ectjon, it has no cft'cct on rie olhe a.gmcnts ''l,hich atl use th oiginal altl of ]i' Thc udatcd valrrc of l wil1, of curse, b passcd back to thc caj]g unit'

assed-]en8th character rgmenis


h a 'c i s long se al onatica1]y to a o he cesp onding cn8th speciicat]on of * (*) is sed. To i11usitc lis. 1ec js a poccduc to cont thc nmbe o oc1s i a cha.riiclc s1ig. i SeS thc intlisic function N to detemine thc 1cng} ofis dmmy agum, 1d h ND fnction o Se hctc each cliacte1 in n is i he Set "-\Dol" o not.

A char

a,ct

actu,

algmenl i thc

e dummr arguen wil


Specia,

]NTEGER FUNcT1r vO]ELS (STRIl,G)


cRCTER*

(*)

STRING

v,LS = D0 25' ( = 1.El(STRING)

25

STRNc((:K)) 'E- 0) Tl]N VO,ELS=V0]{ELS+1 END F

F( 1NDEX('AE0U"

Col{TUE
ND

Not. tha he functjon has a diria iypc wic js no


.i usua11y bc ne:essay to specjfy its ]a]e
eteences he

This passedlength mecha.n]sm is ccommcndcd no on]y f gcncli'] purpose sofvae w1ere the i'cua] agment lcngtis a1c !knwn. but in a]] ses un]ess thcc is n god eason to spec]fy a dmy agrrcnt of fxed egh. Thce is onc esiction n dlrn1n1y agmnts wih passcd ]cngh; they cannot be operads ol te concaienation opeato (r) exccpt in assignmet Statcnents. Not thai the san1 fom o{]cngh speci1ica,jon "*(*)" can be sed o named chaacte consants bu \ih:], coIp]e dlffeen maning: n;ned cnstants ae not subjct to his esictio.

fnciion-

1e default fo

is initia 1ette so
cac pogan

a TEGER satemnt

]11

ri

tha. ]

which

9.6 Arays
f

as

rguelts
pocedue is an aay hen thc acla.l ignen can be eihe:

t1e duny a.gun o a

. .

a.n aa.y

name (without subsc]pts)

an aay c]cmcnt.

The ]ist fom ansfes he e1tie aay; the sccond fom, 1,hich jus ansfcs i scctio sl1ting:t he Spccjied e1enet, is dcscibd jn nloe detai] fte n.

9
'.-

PRoCDRS

72

Th simp1cst, ad most commnl reqjenen i o makc the entie contents of a ;1ay in a. poccdc. f thc actua] agument aJays ae alvr'ays going t be th Saae size then the d[mmy arays in thc poccduIe can se fl1ed bounds. For example:
al.ai1ab1c

(x, Y, Z) *cntes the dot product of arays x i poducin8 aay z o! he sdne size.
SUBR0UE
DT

and Y

of

10 e1nets

RL x(10) Y(100), Z(10) ' D0 15, : 1,1o0

15

Z(1)=x()*Y()

corT1UE
END

T1ris procedre co1d be used


PROGRM PR0D

vitin

a.

pogram unit l]ke this:

iEL A(10o),

(1o), c(100)
c)
c

RED(UNT=*,FMT=*),B

cA
END

DoT(A,

B,
,

i]R1TE (UlT=*

FMT=* )

This iS pafcct1v gitima.te, if inexjbe, sjnce it wj]] no1 wok on aays of any othe sizc.

djustabe rays
moe sitisfacoy solution is to genea,ise the poccdrre so that jt can be used on aa.ys of any size. Tnis js done by using an adjstabe a1a"ys declaation' eIe the peands in ach djmcns]on borrnd eprSsion may ic]ud inege vaJ]ab]as wlich ae a]so agume ts of thc pocedure (o membeS of a common bock). Thc fo11wjng exampe sho's how his may be

SBRoUTE DTPR(}IPTS, x, Y, Z) REAL ([PTS), Y(TS) , Z(NPTS)

D15,=1,NPTS

n tiis case the caing sequence wo1d b somcthing likc: cAL D0TR0(10, A, B, c) n adjstab1c a.n'a.y dc.1a.ra.tio iS pemitted on]y f i'Iays'vhich ae dumm argments, sjncc he acut aay space has i this case aleady ben aoca.tcd in the ca]]ing init o at some
higher leve. The metod can be etendcd in the obviS way to cove mu1ti_dimeSjonal ;ays and thsc with uppcr and 1olc blds, fo exap]e: sUBRorTtNE MUT(M, 1, Ll, l<2, 2, TRCE) DUBE PREc1s1N MAP (R1: L1. 2:2) REL TRCE(L1-(1+1)

l'he adjustabe aay mec;is ca, ofcouse, be sed {o aa.ys oany datayp; an adjusiablc aay c:n a]so bc pass.d :S a a.cta] agumcnt ofa proccdc w]th, ifnecessay, th iay hnds pssed on jn pa.a]lcl.

RoC'DRF:S

Eac] aa}, borrnd o a dumy aguilc] aay ma bc an ilgc cxcssin o1vjlg ot only co]stants b a1so ]iicgc 1ajab]cs passd in lo hc pcc(]c je as agumcnts o b]' reans of a comlnon lr1oct. The xn fcach dincsin fhcaa ls rclt b1css a oe and mus not bc 8ca.tcl ]an thc e o h. coespoding diensiol o ]e a{J;i] guet

a,ry inege va]:ble ( namd cnstat) used jn an a.rav bnd explcssioll has a rn] which docs nt ]mplv intge )pc ih]n the NTEGER sta.tcmc whic specifi:s js i!'pc s '1 1 ,l'l 1," .l lpl. ' . ', .,j, l

"n ".

Assumed-size rrays
Thee may be ciumstances in vhjch j G intactjc:b]. t us eil ]ixed o adjus.'Je aay dc]aatits jn a poccduc because the actua size of he ;ay is nknon whcn thc poccduc Stats eecut]ng. n th casc an ass11d-size aay is a jabe a.ltcln;tivc. Thcsc ac aSo on] perjttd fr dulm agumcnt a1ays f proccducs, but hcc 1c aav is. cflec'cly, dcclaed t] bc f unno$,n indciniic sizc. Er' cx;]plc:
REAL FlNcT0N DDT]O(TBLE, ANGLE)

RE TBLE (*) N . 1(1, NNT(SN(NGLE) * 500'0))


DDTtiO = TABLE(N) + TABLE(,+1)
E],iD

ee the pocedu on]y kno9s that aay {BL| iS ot'djmnsioni'] ih i ]ow'bund o one| tha1 iS a11 it eeds o nlr$,to acccss the apppiat ]emcnis ad ],_1-1. r cxccuiIg h pocedue it iS o csponsjbi]jty to ensue that the \?]c of ANG1- 1i11 n]e S1i in an aray sbsclipt 1'h]c is 1r of ang. ThiS iS :vays a dange \ith assumcd Sj aa]S. BccauSc ihc compjlcl docs not ac iny infona,tjn ibo1 he uppcr bnd f:.l a.SSrrmcd sjue ttiy i canno use a1, aay-bound c]eckig code even if i is orna abe to do his. ,{n asled'size aray can on]y h:e hc ppc1 bond ofjts ]is di11ensjo spcc]icd b}' :n a.Srcisk, a] thc oe ouds (if any) must lro{om t the nomal u1cs (o be adjsab]e ste jntege agumentS)' ,{n ased size dummy agument aay js Specilied nith an aslclisk as thc ppar bund of ]ts last (or oly) dielsion. ,.]1 t othe dielSion bounds, if any, ms corfm to orma1 rues or locat :rrays 1 adjsii,bl arays. Thee js onc imptant rcstr'icr]on n assumed size aa],'s: hcy cani bc Scd \jiorrt S1bscipts in /o sta.tcmcnts, 1b xanp]c in hc ]nput 1ist 01 i RED siaeneI o thc ouip1 ljs lf: JRTE saeme. ThiS is because the compier as ifrmatin about the tal Sj of he aray q,hen compi[ng ihe poccdc.

Aay sections
Thc ules of lortan equie hat tc ctcnt of an aray (n each dimensjn if it tS mltj' dimcnsiona,l) mst e at eas aS 1agc in thc a.cril agument aS j1 t] dumny argmcntl brrt }ey d t cquie actua] ageement of both ]o\c irnd pper bods. or exalnplc:
PR0GRM c01FUs
READ (UNIT=*

RL x(-1:50), Y(10:1000)

cL

0rTPUT(x)

'FM=*)

x,

PR0CDUP,S

71

cL
END

UTPUT(Y)

SBR0UTINE UTPUT(ARRAY)

RE RRA(50)
END

]RTE (U=*, FMT=*) RRY

..

The c{cct olth]s pogam \i1lbc to outpui tha elants ( 1) to (4E) sincc x(48) coresponds to RR(5), and thcn outpt (10) t Y(59) also. The sbrotie vill .or s1m]aly on a. S[ce thugh a tvo_dimensiona alay:
R0GRM Tl,iDM

REL D(100'20)

'....

NSLCE = 15

cL

oUTPUT(D(

1,NSIcE)

n his exa.mp]e the slice of tic a1y fom elements D(1,15) to D(50,15) wi11 be wiien to thc outp11 li1c. n odc to lk orrt what iS going to happcn you need to know that Fot1an a.ys ec stocd with the fiSt Subscipt most apid1y vaving, nd t]at the agumcnt associlon opeacs as if ih addless of tho specifred elenen lee taSfccd to thc base addess of the

dmmy agmcnt aay. The use of an aay clen1nt as an actua] agunent hn thc dummv alguet is a comp1ee aay is a vey misieading noation a]d thc tansfc f aa.y sections shu1d be aoided if a.t alt

possibe.

characte Arays

. ._

Whe a dumy argmen i a chaacte aay the passed lcngih mecha,ism ca,n bc uscd jn the sac a], aS fr a charactc variab1c. Evcy clec1rt o he dmmy a,ray haa ihc lcn8th that las passcd in forn lhe acta] algmcn. Fo example, a sbotine designed to sort an aa,y of characte sligs ln ascending ode
m]ght stat 1iith Spccification sta1ements 1ikc thcsc: SUBR0UTNE SOBT(ELS, IIMES) 1NTEGER ELS cRcTER NMES(NELS)x(*)

lijcnatjvcly thc acta1 a8rment can be a chaacter vai:ble o subslng. n such cascs j usuay makes oc sesc no to 11Sc thc passcd 1cngth necla,ism. o exampc an acua] iglrmcnt dccarcd:
C].ARACTER*80

coud b passed to a subotine whiclt declared SUBROUTE sPT(r}iE)

NE

as an aay of 1or 2O-ch:;cte eemcns:

clRcTER L}E(4)*2

lthough his is valid olan. i is nol a vcy s:tjsfaciory p1ogamning iechni1c o usc : pocdtc cal1 to a]tcr tnc shapc of an itcm so adjcay'

'ROCDURS
as Agunents

75

9.7 Procedues

Fot,ran aos oc pocedre io b] used is tic a.cfua] a8mni of anotc pocedc. Tis povidos a po{,cu] Ea,cj]ity, thlrugh onc iha,t mos pogammes usc o;ly a,rely. roccdurcs ae tonral1y uscd to cav ou a gjvcn se of opcat]ons on djffc]nt Scts o[ daa,: bt Somctimcs you at to cav o tle samc sct of opctjns n diffccnt lunctiona.] toms. ExaInp]cs inctdcl 1inding hc gadient of a unctjon, integailg h area der : cr.c. o simpy potng : g;ph. f e crve is Spcci]ied as a s of data points t]en yol cal1 Sip]y pass oe a, aay. bt if it is Spcc]fcd b}: eans of some algoihm thcn thc poccduc \ic1 ea,1rrates it .an jtselt be an actual igument. n the next ej{amp]c, hc subo[ine GAP p]os i' gaph of a function MYFUNC bei',vee] Specified jits, with is iIgncnt range divided Somewhat a.bjta.jly into 101 points. simpliciy i assums thc cistence o a subojn P,oT lich movcs the pct o pSitic,n (,). Sone ohe sbottes in p.ticc, a.nost caily bc cquilcd.

*P1ots functional fom of MYFic(x) {ith REAL i'1FUNc, xMN, 1l,lE

'oud. SlJBR0UTNE GRA(MUNC, xl41, xMAl)

in

rarge 4N:xMx.

- (MAx D25,=,10
XDELT

x,{)

100.

x=x){N+*DELTA
Y=

25

cAL PL0T(X,

MYFUNC()

Y)

C0,TUE
END

Thc pIocdulc GRl can then be used o p]i a function sjnlply by oiding is name thcm as tie ]iSt agmcn t of t hc ca]]. Thc onlv thc cq ujc]nct is tha1 t he nam of each frrnctio sd as an aca aJgment in this way mst be speci1ied in an NTRNSC o xTER}AL statenen] as a.ppopiie. ThlSI
R0GBAM cURvES

NTRNSC

s'

TAN

EXTERIIAL MESSY

cAL

0., 3'14159) '; o'5) cL GRP{(l,lEss, 0. 1, 0.9)

cL
END

GRAPI(SN,
GRPI(TAN,

REL FUCT0N 1ESs() MESS - cS(0.1,t) + 0.02 * Sr(SQRT(x))


Ei'D

Thjs $,j fist plo i glaph of e si function, hen of he tangcnt function ith a diffeent age: :nd final]y pduce anotler pot of he extena funcion ca,rd }1ESSY. Thcsc 1unctions musi, of couSe, havc thc sanc pccdrrc ]ntcface hense]ves ad mst bc cal1ed coecty in he GRAH poceduc. is possibe to paSS eithe a fnctjon o a Subtjnc a.s il"l1 ctua.l agrrment it this way: he o1y diffcence is that a cL sitement is used instead of a fllcion efeence o execle }c dmmy poccde. t is possib1e o pass a pocedc thogh mo tha,n onc ccl of pocedue cat1in the same \ay. Continuing thc ]ast cxample. anothe 1cc could be intodced ]ike this;

PROCLDURS
PRoGRAM cRvE2 EXTERAL 4ESS

76

c
ElrlD

NTRNsc sN, TA
GRPE2(PRTTY)
GRP{2(TA1{)

crl

SUBRoUTNE cR2(PRc) EXTERN PRoc

ctl
ED

GRAP{(PRoc,

.1, 0.7)

Thus t]e poceduc GRPH2 sts limits t ea.ch p1ot and pass{rs the pocedue nane on to GRP. The Symbjc nime PROC mus be declaed in an EXTERN staeent as it is a dmmy poccdue: an EXTERAI Statcmcnt is cqired vhcthc the a,cua1poccde at thc top leve jS intisic exeal. T] Synta of he NTR]Nsc ad EXTERI{ statcmens is gicn jn section g'12 be]ow. The name f a.n ]ntrjnsic funcio uscd as an actua agumnt must be a Speciic name and noi i 8e'elic one. ThiS iS thc nty cjrcumstace in s.1ich yo Sti11 have to use spcciflc na,mcs fo jIinsic functioS. A fri1st ofspeclfic nales is g]vcn in he appcndix. ,{ fe\v ofthe nost basic ]ntrinsic funct]os \h]ch ae oftn cxpandcd to in [n codc (thos f type conveSion. 1exjcal conpa.json as we]l a"s MN and M) ci'nno be passcd s actualaguments.

9.8 Subroutine and

Ca Statements

i is conve1ient o descibe hcsc two sa,tments ogethe

a,s thev hive to b dosey matched in lsc. The gerea form of thc SUBROTNE Statcmnt is: SUBRUTNE nan ( .Lumm1' d1mm!2, ''' dumm )

Th sccond lo just i1dicates thai jf thee ae no agumcnts then thc pacnthess ac optio]aTic Svmbolic na,ne ote sbutinc bccomes g]oba.]namc; it ]nlsi not be lsed at al1 wjthi tlc pogram unit and nus no be uscd f any oe goba1 ]tem withi] tha enie eccua,ble ploga. Thc dmmy lgumens ae a]so simp1], Symlrolic ames. Thc \ay in s'hich thcse ae intc prccd is cor,red in hc nex section. The cLL statement has simi1a geneat foms: cLL nme ( rg1' rg2' ''. r7N )
CALL rrne ga.in. if hee ae no agcnts t}e pieheses ae optina.

SUBR0UiE nam

The alne must bc that f a subrotie (ol d[mmy subotinc). Ec ag ]s an acua] agumnt whjch can be a vaia.b]e. a.ay) substi1g, aav c1cmenl or a.ny form of expcsn. The pemiited fms,'hich dcpcd o he form f hc colespondjng dumm agumcn ard h\\, ]t js usd $.it1in thc subotjnc, ae frry descjbcd in thc perding sections.

9.9

RETJRN

Statemelt

Thc RETURN Statemen jSt cnsiss of the keywd


RFT,RN

PR'oCDURS

ts cffcct is t stop ihc poccduc cx:u1]ng ad o chn conto]. ai] whl. apo]ac hc ca]ing pogarj t]it. Thc xccutio oh END sacmc :r he cnd of th poga] uni as ihc ej.act1y ihc san1e cIect, so thai RTURN is srpcflu]lS in proceducs wiich hae on]y o enhy and oIe erit pojnt (as a]l ,e_designed ptocducs snold). h is, o\ev., Sometil11es connien o usc RETUR fo o. orr".g"n., cjt. Hcc iS a .^4hal 'r ,l,._l l'. ^'"^p.j.- loi |..,d,. l|,,o'.l:
a.glre]t a.nd runctiot lalus, ro

RA UNCT l{0T(x, ) *conputes th hypoienlse of a ight-angIed triag}e. RE x,

(X.LE.0.0.0B. 'LE. o.o)


RETURN

TEN

}iRITE(UNT=*,MT=*)','ainingI ilOT = 0.0

ipssib1e va1ues,

END PT SQRT(X**2
ND

Y**2)

ThlS fIctjon co]d be scd in ano}e poga,n rrni iike this:

x
\

5.) ' HP0T(0.0, 5.0)


T(12.0

hjch \orr]d assign o X thc 1.anc of 1J.0000 approximacly. .h]]c ie second fncion ca1wo]d cause a. ''aning essa8c to be issed and ou]d etn a a.]e of zcro o ' n thc cxtena,l {ncio Shoqi abovc it Woud hal.c ben pefec]y pSsjb]c to aoid 1a1.]r1g a,o ejds poins by a aenativc cndjng t ihe pccde, Such s:

F( .E. .0.0R. Y.LE. o.)


SE
El]D
EiD

TlE

WRTE(Ul'T-*'FMT=*)',/aning: ]PoT = .0

imossib1e values)

Y0

SQRT(X**2

+ **2)

n moc 1a]isic cascs, howee. ihe main p;t of h calc11la,jt wu]d be nch ongc tha,r js one sateent and j], migLt thcn b casie o ndeStand he $.kjng i a RTURN statcenl \cc to be used than wjth aost a of thc proccdue containcd \ithin an EISE b]ock. thid '{ possibility for ee8cncy cxis is to use an urcndijna] G T0 statcmcnt to jump o a abe1
1ad n ]re ]Nl] sfil,l rjr

9.10
isr

FUNCTN Statement

The FUNCTN Statemcnt ms be

tc fist siitement ofcvcy

xtcna,]

fuction. s gcncla

on1

,rpe FUcTo]i( du\nml:l' (umm!2' ''' duanu ) The ,!pe Speciicatio iS opiona,l: if it js omitted ]en ihe typc othc srr] is deemncd by he usta1 ru1es. Thc ulctin nane may havc is ype sccjfled by a tpe o l4LcT sti'tement ,hich appeais late1 in te pogam ni. he funcion js of pe c1alactc ]en the 1eng av ba spcciicd by a 1itea] consra,ni (but ]ot a amed cnsat) o mav be givcn rr he {olm

PR'oCDURS

78

cRcTER*(*) in which casc th length q.il1 be passed in a t1c tet8th dacacd for thc funcion nanc ]n ihe caig pogIam unit. Thcrc nay b ay numbc of dmrny :gme]ts inclding none, bul the Da1e1tieses 1st sjtl bc prcscnt. Dmy agm.nts ma,v' as rJnsclbed in sFcrion g.4, b. ariabl"s, arays, ol

'he fict]on name ma be rSed aS a :jabte witiin the function ubprogam lnit; a, le must bc assigncd io his vaiab1c bcforc ihe plocedurc reuns coniro to thc caig rit. If the frrnction name used the passed lcngth option thcn th. coesponding vaia.b]c cannot be used as a opand ofthe concacni'tion opea,to cxccp i an assjgnment Statcmen' Thc pissedlcngth opion iS 1eSS rrscful o chara,cte functions tha,n fo aguments bccase 1e 1cngh is jncv]abt}, ihc Sae fo a efeences from the same pogam uni. lb cxamDlc|

cLSs*6' TTLE*16 CLSS = cDE('SECRE,) TTt = cDE('Oi.DER F BTTLEJ )


ND

PRGRAM FlEx CARACTER C0DE*8J

c]RCTR*(*) FUCTN cDE(WRD)

D15,K=1,LEi(lioRD)
15

CARACTER UoRD*(*)

'

BUFFER*8o

c0]ilLE
END

BUFFR(K:() = cHR(clAR(tJoRD((:K) + 1)

coDE = BUFR
a,11 agument ofany legt 1rp o 80 chari'ceS ogandcncodei,itcanon1yrenaesultofcil.th8chiietes]onghenca.1lcdfromthe pogam iltr. so tht i wi]] nt poduce he dcs]ed esult wle prv]ded 1ith thc ]onge chaacte stjng. Thjs imjta,tion cou1d be oecoe rith he usc of i subutinc ith a Sccod :r .. l.18 @ld n, , nId|, |-|,lU|.,r. \L. ctions ithout ag[1ens do not havc a ide angc of uses but app]icitions f hem do ccu tp o tim to timc, fo example wen gcneIating andom nmbers o eadi:g atues

ifotunatey, althgh thjs funcjon caD ta}c jn

fro an inpt file. F cxampte:


PRGRM c0 RE NEXT

10

lRE (UNT=*,l1T=*) ExT() CI{TUE


E],D

1,.1,1o0

BE
li1])

NCT}J NET()

RED (UT=*, FMT=*)

ExT

The parentheses are eedcd n h fction ca1l to distjng11ish it from a ijablc. Thc 1uctin siatccnt iise] a,lso ]aS to h\'e the epty pa.i f pa1cnihescs, p.s11ma.bly to match the cal].

PRo( D0kIS
SvE

9.11

statenent

sv iS a. spccificaion S1atcme1t wlic ca,l bc uscd o cns] 1a !air]'.s ala aas scd w]thin a proccdle pcsclc thcj vaus bdncc Scccss]. ca]]s o the pocedue. Jnder nc,lrna. cicinsti]ccs oca1iicms wi]] bccone "undcfincd" r.s Soi ir,s h prcedue eus cono1to lc ci']]jng unj. t iS o{tcn useful to sioc thc l,alucs oi ctain ios used on ne cal avil ding xta \ok on the nexi. Fo cxamp]:
SUBRUTE ETR(MTLEs) NTEGER i1LES, LAST SvE LAST DAT ST // ,IRTE (U]rT=* FMT=*) MLES

AS = MES
ED

'

LST, 'ne mi1es.'

This nrbol1tinc sily savos tn r,a]u of tc agmcnt }.1Es c:ch tjrne and slbtacts it ,om t}i net onc, so that it can pint ou the icemena,] v]ue. The va]c fLAsT 1iad t bc gjn an initia] valu. sing a. DT Statcmnt in ord to pevent ]tS sc \j] i ud,]1ir]cd ]u oIE hc initia] ca]. Local laiabes and arays and comp]c. nacd conon b]ocks can be saved usin8 svE stalemets, b1rt not vaiab]cs an.] aays whjch ae dumm1'argumcnts w]ch appca ',a]ihjn
1tems '',,hich ae ]nitia1ly defied \ih i DTA stl.ncn bu licr ae nee pdied i a nev. va1e do 1ot need to be savd. T1e SvE sta,teent has t$ atenativc ons: SA., item' item' ..' iteln SAVE Wlee each irei can be a loca] vaiable o1 (u1subscipicd) aay, o thc namc of a cmmo b1ock cclscd jn slashcs. Thc sccond fn, vith no ist of itcms, sives a" hc a]o\ab. jtcms in he pogan unit. Tis fo sho]d ot t)e usod in iny poga unit q.hich uScS a cmmon bock unless a connon b1cks used in tha pogar ni ae also usd ii thc main pam saved i evey program uni in lhich i appcas. Thc SAVE saeen can b Sed in the main pogan nj (so at it co]d b,r packigcd wit1t oth. Spec]fications in ]}CUDE fi]c) br as

st:iic sloage aocatjot Schene ln whid al snaJ] copt es hicn nake use of dis systcnsl this na) no be so. ou su1d a1vays over1ays, o a8e otes with iiua ey takc cir'c to Se thr Sv statement ay{,lee ha is usc is irdic:ed o make yu plogi'ms Safc and potab]e. Een lher: ii is i pesent sictly cdndant ] Si]1 j dicatcs ro the adc hat thc pocedule woks by letajIiIg jnfo:tion fon ,]c ca]l io h cxt, a1d rhjS iS a1uabic in iise]'
vaia b]es ire s avcd hc1c svE js used or

lany.ucnt otan SysteS hae a

s1mp]e

o . B u

9.12

ExERNL

and NTRNsc Statements

Thc EXTRNA Statemen iS used o name extena1 proceducs \ic1 ae cq1ril.d in odc to ru a givcn po$am unit. t n1a] Spcci, thc na.mc of any exena fnctjn o Sbouj1e. iS quilcd in ice ahe diffccnt cir'cmsanccs:

whence an etenal pcodrrlc o dmmy proceduc iS uscd as he cua agmcnt of ano1e poceduc ca]1;

10 PT/ojTPj FCLTS

to .tlsue that a namd block da.ta subprogam is hkcd i to he comDl.to .e.rxbl. pl^',jl .1l. l.r| | *..io. '.,.l. p jal " U.n l..or..J. Thc TR]isc Stateet1t is rrscd o dc]ae ir. nam. o be that of :n intinsic function. is normaJ1y ncccssav onl \hen ta,t function js ro b usd as thc actal aglment f anote pcedure ca11, but y also be advisab1c rvhcn callilg a non st: dard j]ttinsic functjon o emov a.n ;mb1giy ,hich migi a]sc if an itenal fction o{ thc sane namc a]so existci. The getea1 fon of rhc t$]o samcnts ]s tle same: EXTERN,( eone, eme. '.' elmc INTRINSC i,l., irlne' ''' inm l\ihere en can bc the name of arr cxcrl;l function o1 suboutjnc o a, dumlnv poccdue: in1le m6 bc specific nanc ofan iIinsjc fction. o exampe. to usc the ea.1 and dob1c !ccis]on vcsins of he tigmctjc ncions as act!al argmcnis e necd: lrTRNS1c s]i, cos, TAN, DcS, Ds, DTN \\ien t,]re fctior narc SN is used as an acal agucn it refeS to th specific al sinc fnciioni jrl oh contcxtS it stil] ha.s is usa.] gcncl]c |opety. Thc use of poccdues as acrui agnts is corccd in dctajl jn section 9.7; a ]]sl ofspcific lames ofintiSjc 1tctions is gj,cn in te appendj.

. .

to calt any pccdue which as a nae dpl]cating an ininsic fnction:

|0 nu/output

Fa-ilit ies

The /o sstcr f oan i5 c1atiey p\ef , 1t.xjbe. and w.] de]iled. Pogams can be polliab]e a1d dcvicc independent evcn jf thcv make extcnsive se ofiprrt/output facjtijS: ii1s is d]ff.:ut i not impss]btc jn nt:ny othc higi ]e] ]ag11ages. The cfccts o thc ha1da,e
ad o]rcrating sstcn ci'nnot. of crrs.. be ignoed cnticly but ihc usuatty on1y aIect faji njnl mattcS sch i's 1 fo1s ofi1c na1e and tle r:raxjnn rcod lengh that can be Scd. .on.n o a .] g.1. ,| |.. |oo. |. l-i': 11, FD n JRIT .l" ., RED(U'iT=*, tT=*) NUIBER
,iRE(UNT=13

'

ERR=999) UMBER,

.ARRA (

1)

RR(N)

Thc pa] of paenhcses ae the wd READ o1 I{R]TE enc1oscs he contol-]ist: a iS of ics whiclr spcc1fies 'hee and nol thc data llase taes p]acc. The items in tiis is a.c usrral]}, sp.c]1ied \ih keaods. Thc 1]st of dara. iems o bc cad wie fo]1ow tie cntol si. olrer ilpu/upu statmctS ha. a sio]]la on exccpt tha they o1v have a conto] list. Thcc arc 1c filc n:dli g secDts , clSE, ad EJQUR, as i]] aS tlc RE}D an BcSAc sa.cmcns hich i]e thc ccni]]' :ci]c positiol wi1 a ]i]e. Befoe covcJng thc }csc stae1nentS jn dctajl1 it is necessay to .xp]ain sonc of th: concps
and tcminolog], involvcd.

10.1 Files, /o Units, and Recods


l lrortran tl tcrm filc js uscd 1b a.nvihig ha can b hand]cd witn a RD l{RE sl.aent: the ten cocS ot irrst data. fi]cs sd on disc o tapc and a.]So p.iphca dcv]c.s Such as !ilr,cs o ,1ii.'15. sicty thcsc Solrld all he ca]cd extcrna1i]es, io dist]guish thcn from ]1cia] ]ibs. rr itcna]fi1c js noirrg oc han a, chaactc 1,a]a1r]c o aay ''h]ch ]s !scd as : cpoar! ilc 1i]. 1lc ]}gra is lrrnnilg. nenat fites can bc scd v]th RED and l,lRT StalclS jn

]0

P''/

oj Pj1' 'ACLTLS

81

odc o pl.rccss c]aractc infonalion unde lhc conto o[ a fomat spcci]ication. Th]r cannot bc uscd by otnel /o statmcns. Bc1'oe a,n cxena.] fih can bc scd i musi bc cnnectcd to :. /o u]t. /o ]s al jnrcgS $hic ray bc coscl ftc.ly f1n co up o a s]'srcm depcndent imi (usuay a 1aS 99). xccpt ]n PN and QURE silc'nnlS, filcs can o1y bc l]ecd ].o lia thc] nj u]ibcr. Thc oPE statcme connecs a na'd ]ie a nmbccd unit. t usua], lcci1ies 'reh tic fie alad], cxiss o'i,hhe a nl\ one is to b. ccatcd. lo ea.p]ei
oPE],(NT=1, LE=' B : ],JUT. DT', STTUS-' LD' OPi,(UNT=9, EtE-'R]{OUT,, STTUS- J E,J J )
)

lb

sjnp1ic]ij' mos], of the cxa]p1cs in tis Scction Shw tn actua.1 incgc aS he ni identi]ie, bui ]t hclps o ake sftwa.c oc odu]a and adaptab1e if: nacd constant o a ai:ble ]s

/o unis ae a global resouce. ,{ jile ca be opened in a.1' pogam uniti onc jt ]s open /o opeat]ons can be perormed or it il ay progra.n lli providcd tha ]e same unj numbc is used. Thc uit nmb can bc hcld in an incgcl' iliib] and passd to the pocedurc as an
agumrnt.

Thc connecjo bctwcn a i]e ad a utit, once estab1]shcd, pSjsts l1nril;

. . .

ihe prog1]miniics nrmi]]- (a i STOP saecnt o ]e ED thc ma]n pogrn); anotc1 saiemcnt conncts a diffccnt fi] io le Sanc nit;
o
a,

CLSE Statcmc1 is executed ot ha

jt.

,{hogh all filcs ae closed l.len thc pgan cxits, ]t is good pacicc ro c]os hen exp[cit1y a"s /o opeatjons on h ae compeed. { thc po8am tcminatcs ibnoni]]y, f xample bccase al cr1or occS o i iS aboted by thc usc, any i1s whictr ar open, espeia1ly opt 1i1cs, may be left ',vith jncmplcc o corped ecds. T1tc QURE Statercn ci'n be used io obain infoatjon about ic culen poptjes of xona, i1es and /o units' NQURE is patjc!]al] usefu1 whcn iting ]ibay poccdles ,hich may ha.vc to ] a \aict}, of difccnt pogan envionnes. ou can fud out' fo cxmplel 1'hich unit ntmbes ae fee fr se o 1.hchc a. piicla i]c cr.ists and if s what its chiaceistics ac.
as soon

Records
o a Sequencc of ccds. n a cxt ilc a ccod coespnds t a linc of tcx: it1 othe cases a cod ha.s no physica] bsis, it is jus a convenien cllccjon of les 1osen to s11j le ippicaion. T]ere is no lccd fo a rccod to cocspod to a disc Sect o : tapc b]ock. RED and JRTE Statcmcns alwinys star Wok a the begjInin8 of a lccord and alays taSfe a whole nubc of ecods. TLe ]es of Eoan set no uppc ]imjt to rhc ]cngth of a ccod bt, in pilcticc, eich pcating syste may do so. This nav be diffeent f di]ctl foms of ecod.

i]c consists

Fmatted and Unformatted Recds


xiena,1 ]i]cs come i1 t1\. vai.t]cs a.coding o whihc thc] ecods ac fnr:rted o unlo m:tt cd. Ebmat tcd recods St oc dat a in ch:ace- coded f1 , ] -e. as 1lncs of cx . T is makes the si;b1e for a w]dc angc of a.pp]icaions since, depcnd]ng on thc] coneIts, they na], bc

lrr / oi TPi

F C'' tF'g

E2

Jcgible to urans as we]] as compus. Te al comp]iction fo thc pogranrr is tha each RT o READ statcmcnt n]!s speciy how ach al is io bc cot1vc1.ed fn ]nn.] to extea1form jce crsa. Tnis ]s usuily done 1ith a fomir" specificalio]' Unfo1mailed lccods so data in thc jnrn:] code of thr compue so t1a o fma cnvesions ae jno]ved. his has a scvcla.t a.d\anages o ]ilcs f nmbes, cspeciay floating_ pint lmbcr's. infomatcd daa ansfes ae sjmple to p.rga.n. fastc in exe.uion, a]d tee or oudig eos. hemoe te esultin8 da.ta fi]os. sometimes ca.]ed bjnay i1cs, are say much sae. ,{ ea1umbcr ou1d, fo cxa.mple. hav to bc turncd int a Stig of 10 o cvcn tj ch:a.ics to prscve is precisiot on a oattc] ecord. bu on a nfm:ed locod a ealnumbe1iypica.]]y occupies ony' bytS ].c. thc Sa.ne as 4 chaactcs' The daback ]S hat unfomattcd lilcs ac high1v syscn specific. Tey ae usual1y illgible o hmans and xo thc a[ds of cmPutcr and somcties incoInpa.ible wit fi1cs poduced by ot]ic p.gr J]mmg la.guages on he same mac.iin' nfonatcd fi1es shld ony bc rrscd lb infoaiion io be \rje ad ead by otrii po8ams nn;ng on 1lc sa,e typc of compe.

Seqirentia and Diect Access


ao\, n}s to bc poccss.d scenjaJ]y: yo Sra at 1he bBinning f the cach ccord in n. oe irrporant advantag of sequentia] iles is 1at d]fecnl coas ca ac ditree egths; thc i]jmum rccord 1egih is zc b!i he a'xum is sJ"ncm dpnde. Sequeniat fils behave as if thcc 1'.c a. poitl ;lached t thc n]: ]ic] a.1n'a.ys irldicates i]l] ex ecod io b tans{ed' on dciccs sc as emjnas and p les 1'ou cal oly ead o ite i Si]ci Scqrrcnt]a] ordc, b l]e a nle ]s stod on disc o tapc jt is possib1e t sc hc BEllD Statc.nt to csci is pjnie to the stat of t}e i]e, aowilg it ro be ead jn agaj 11jttn. on suiablc fi1cs tc Bc(SPc saeIett ca.n be sed mvc the ojI bacli by oe ecod So tha thc last ccod c:n bc ead again o ovc \iien. on un1b1ia"te oissio o thc ota standad is ha.i tle posiion ol he ecod p]jre js no deined $ihe an xising seqctialli iS op.cd. l,os lbtan SStms behave scnsjbly and ake suc hat they staJi ai t1c bcgjin]ng of tic file. bt thec ac : fcw ogue Systms :oln.t w]ci ac jt :dvjsabl., ir poab]c so\'a1c, o use nEWND;fcl e oPEN stat.mcn. nolhc pr'oblem is iow appcnd ne' recods ai ising scqcnrial file. Sorc S],stcms ploide as an cxtcns]o) an "apcnd" opion in thc 0EN statomen, but t1c bcst lcthod usltg Stadald tbta js to opcn t1e ]i]e and ead ccords onc a a. ime utj he cnd offi] cordition is ]lcolli]edi theI us] BcKSPc to mov the poite bac1r a.nd c]oa he end_of fi]c condiiD.
n1c

peipheal dejces ad ] thogh

ccords ca hcn bc added in le usual wa1'. iltclnail' acccss ct]od js djoc icccss hjch a]]og,s ccods o bc cad and \jn in :n1' odc. 'os SStcnrs n]y pei rhs ]i]cs sted andom ;cccss devjccs s11ch a5 discsi it iS So]11.ti]11cs a1so pcmiicd on tapcs. ]] ccods in a dircct accss ic 'ust bc the samc lcngth s thai hc sysicm c:n comptc tic locio of a rccord lrom 1s ecod nbcr. T. ccold lcngr a.s to hc c}osc1 th e i]c ceacd and (on no SvstjS)iS thi ixed ]ic l]fc { 1.hc j].. . dic access ecds ac numbcrcd fror on: upra.lds; each RD o WRTE s1emc spcciies t,he recol unb at $,hic1r the tansf Stas' R.cods nav b $,]ttcn t a d]cc acccss fi]c jl a.J od. -{ny ccoa ca bc rc:d povidcd ha j e-\jss. i.c. i as ]ccn u'ic a se nc ifuce tic ]i]e 1\aS :eaed. nc. i ccod ias bc.n ,]ticn thcc js o ay of dc1cillg i. bt 1tS contcnts can lrc updaed, i.c. ep1accd, a anv
'ct,

T.

,{ e. plmltnc opca]ng SJscS cqic lc ailrl]n ]cngth o{

a,

dicc acccss filc to bc

P / o

UPU']' F C' tF'g

,{l

spccificd whcn hc fi]c jS cca.d; his is


ol

tan Sandad.

ncccssa

]r

sysems

vl]lr comp] ir]] wit1 hc

ccods cano b. micd 1l the satnc fic an] on nos systc1s fi]cs dcsigned o scqucnja1 accSs ae quic d]st]]ct fom tosc ccarl o dici acccssi ths ihec ae fou dj11crcnt types of extenalfilc. Thee ]s n Specjal Suppt j Sandad brta o :ny ihc ypcs of file Such as ]ndcxed-sequeIi files o na ]iS fi]es.

10.2 External Files lbmattcd and omattcd

Formattd

Seqential Fies

Thcse ae oen jusi caed text ies. TejItr]s ad pllS sou1d alrvavs bc trcatcd as fo mattcd Scqucntial ]i1cs. D;'la fles of this tyPc can b ccacd ill a aicty o{ 1ays. fo j{ap1 hy djre( ly fro ]e keyboad. o by us]ng i tcxt cdjtol. Some l-otan svstcS d lt allog, ecods to bc 1ogc than a nona1[nc of tet, f cxamp]c 132 chaaccr. ;n]ss a tet lile jS pe_cotnected it must bc pcncd \']th an PE stacmcnt, bu ie F0RM= a1d ccESS= ]ic\vds ae n ccdd as i. dcau] va]uc$ i i:bc:
OEN(UNT=4,

foat ct]. Thec a t\o options ]\ih lies of tis ype: yoil can eithe pvidc ],ol ovr foma specificatin o us ]is dieced oajng. T]e atcjon o{js_diccted /o tia he oa Syste docs the wot, p1oviding sip]o dala anses wih ]itt]e progamming effo. They ae speci1icd by h:viIg : :st.lis as le ,onlat identifie:
]1 data tansfeS must bc cajcd out u[dc

]tE-'RE0RT',

STTUS=',E,{' )

,JRITE(U=*, MT=*)'Ente ve1ocity:' RED(U,IT=*, FMT=*, \D.999) SEED


jS qjte covenien rvhen readig lrlbcrs fro a eminil since ] aliolS v]a]] "fc foma" daa enJ. 1nay aso be sef1 hcn cadj g da? ]es \]ee he 1al is not egula enogh t be and1ed by a fonra Spcciicaion. Lis'dieced otput iS saisfactoy wlcn uscd just to outprrt a chaa.ctc stig (as in the cxample above), bu i poduccs 1ess pleasing esuts \hen used o outpt numeIic;] va,les sincc 1,o 1avc ro conro1ovcr thc positionjng of jtcms on the inc. the ic1d idt, or thc n1mbe of decimal digits disp1ayed.

is djrcclcd itpu

Thlsi kR-'](| N.1=LP, E]T='' o

'',N,' coss ',PR]'d

il1 poduce a tecod somethig like his:

B of 9.50o0 List dir.ctcd tput js bcst avoidcd cxccpt to wite simpe mcssr.gs:nd 1b diagnostic rrtput drrring pgram dcvc1opm.t' T1c u1cs fo ist-cictcd fnattjng ac .ovccd ]n dctai i1
Sectin 10.10.

he atenaive is to pvide a omat Specj]icaio1: hjs poidcs coplctc cotol ol.cr thc daa tanste. The pcvjos cxirple can bc modifled t use a foat Spc]fication 1ike this:

55
Box

JR]T(UNT=IP, FMT=55),Box FRMT(1x, , 3, A, F6.2)

oi,,,, costs,,PRCE

and will ptodce a r'cod ]]kc thjs:

12

osts

9.50

10

PUT / oUTPjT LCLI'S

Thc fomat speci1icatin js pidcd in his ca.sc by a FRMT statemnt: its ]abe1 ]s the fonlat idntiie in t1e WRTE see. oler w;ys of poviding fo s]recificatios are describcd ln section 10.6. on nusa,] feite o inpu unde conio] of ,Ioma spccifi.at]on js that cach [nc f ex \i11 appca to be paddd out on ihe igh r.ith an indelinitc number of bla,nks irespectie of the actua,] ]ength of th data cod. ThiS llca.ns tir.. among othe things. it iS no possib1e to djsthgu]S1 bet\een a11 epty ecod and ne Ii]led lih b]anks. 1f numbels a 1cad fm an mpty rccord they will sinpy be zeo.

Unformatted Seqential Files


fonattd scqrrcnt]a1 ies arc ofcn uscd as to iransfc di om ne pogam to anoihc. They are also suiable fo scach fi]es, i.e. t]ose used tempoaiy dujng pga.rn c-\euin. Thc on1]' imit on the lengh o ltfomated cods is ta.t Sct i}e opaiing sysiem; most sysems a]]ow ecods to contajn a few thorrsand dita ]ems a ]eas1. The PEI sta.t.men must spccify tle fie fona.l. but lhe defa"uit iccess ne]od is "seqntia.1'l. a.ch READ o {RTE 9alemcnt tansfcS onc foattd ccod. For examp],:, hcsc Statemcnts pcn a existing unfoImattcd 1i]e ad cad t'o ecds fom
Ir:

PE],(UT=15,
RED( RED(

E.' BN', STUS=, OLD', 15) I]EIclT, ElJcTH, ,lDTH 15) RRAYP, RRYQ

FR}{=,UNFRuTTD l )

BcKscE and RiJD satenenS ma}'geneay be scd n a]i unfolaed seqcntialf]cs.

Unformatted Diect-access FieS


Sjncc di.ct accss n1cs ae rcadab1c on1y lry achic, it Scms sensible o se nfomattad ccds to m{mis efrciency. The oPE Sta,temnt must spcc]fy ACCESS='DRCT, and a,so Spcc]fy the ecod length- Ufotunae]y tic lnils sd o measue he length of a ccrd ae not siandadiscd| Son1e stsems mease ]e in byes, theS in nueical Stoagc ]nis, i... thc numbe o lea] o1 inlcgc vaiablcs : cd ca.n lold (sec scclio 5.1). Tis js a nino obsac]c to potabj]ry a,1d means h yo11 mav c.d to kno,ho\ many b)'es your machinc ses fo eCh n!n.]ca] Stoagc un]t, a.thog] this jS jSi abo thc oly pace in otan \'hca this ]s necessa.y. Most systcms rvi1l allo, yo to open an cistng fi1c ony if thc ccod ]cngth jS thc Sa1e as tha used \,/he tc fi]c \as c.atcd. Each READ and l,iRT stalcncnt r1ansfcs cxact1y onc ccod and mst Spccifv he nunb of th:t ccod| an inegc \"uc fon onc pwads. Thc ccod lcngih mst nl bc gcae han ha dec]acd in thc oPEN Statcment;if a oupu ec.rd is nt cpetely 1ied 1 cmajndcT
rs undelined.

lcJ

Tb ]11siatc how diec access

{r1cs

can bc scd. hcrc

is: copl.tc poga ,hich a]]'s

a,

Sipc d:ta basc, such as a St of sock ecods' to be ej{ai1ed. '{ssuming 1a,t he ccod ucrica] st.]:gc units o{ ] bytcs' thc cquied cod ]gth jn this case )cngh is reasued

bc compcd as fo]1ows;

NA\E

STOCK ] NTEGR varjab1e

] CRACR*1o vaiablc

10 chas = 10 b}l.cs.

PRc 1Rtrr\La]able

tui=4bycs
1r1nit=4b}tes

1a

PUT /],lPUT E'ACLS

85

h] :l ecod 1cngth iS 18 byics o 5 nica] soagc njts (oundig intcgej.


PRoGRM DB,{SE1

RE cE

NTEGER SToCK, fERR

*ss!e recod ength in sta8e units holding 4 has ach. Elrl(UliT=1, FLE=,ST0CKS,, STTUS=, LD J, $ ccESS-,DIRECTJ, REc=s)
*Ask user fo pat nunbe rhlch \rill be sd as recod nEbe. ]RTE(U[T-r,,FMT-*),nte pat numbe (o zero to q1it):, RED(N*,FMT*) JPRT F(NPRT .LE. 0) sP RED(UNI=1, REC=NRT, ISTT=ERR) ME STCK. RcE '

CRACTER ]A1E*10

COTNU

F(NERR.E.0)
G0 T0 10

TIEN
'

l,iRT (U!,IT.*

FMT=* ) ,Unh]orn

part numbe, e_enterl

115

ED F iiBT(*,115) STc{, NM, PRIcE FOR}.1AT(1,JStock is,,4, 1x' ,,at

c0 T0
ETD

100

,, 8.2, ,

each,)

The t'"pjca otprr cord ih pogli'l \i] bc f the fom: Stock is 123 idgets at 556'89 each This plogram cou1d be xtcndcd aily casj]y lo ir,l]ow thc contns of t}e ecod io b pda.i.d aS thc stock ch:ges.

Fomatted Direct'access Fies


onattcd diect a.cccss fi1cs are sLigt1 moc poab1c tha,n tic 1tnlomated fom bcciuse he] ecod 1cngth is always mased in Chaactcs. ohe\isc the is 1ite t J sajd fo hc. The 0E1 statnct must spcify bot ccSS=,D1REcl ad FORM=JrRMTTED, and each RED an1 WRTE sta.lenent nus conta.in boh fomat and ccord_numbcr identifieS' ]st dileced tansfs ae not peittcd. f the fon2" Spcjficatjn qies moe han one ecod io be tsed. those addjional ccods fo11o o Seqcnti:]]y ftoI that spccid by REc=. iS a eo o y io road bevond 1e ed o{ a cod. but ir,n jcop1ctcl}, fled ecod j]l be padled orrt wir

10.3 nterna

Fies

n inenal fe is an aea of centlal mcmory whlch can bc sed as ili werc ;:tbmated scqerja fi1c. t exisls, of couSc, ny vhite he pogram ]s executig. nt.na] files ac cd fo a vaicti, f puposes, paticu1a1ly to cai].y ot data conveSjons o and fro chaacte daa t}'pc. srne ea1lic velsjons of otan inc]ded EC0DE and DEcD staicnentsI tne intnal li] i.EAD q.i]ch pacS DEcDE) and intcln]"t ]ie lRTE (1rhich rcp1acS EC0DE) ae Sjmp1c, moe nP,{ih", an.l cntjc]y ptablc.

10 ]PU/oTPj

'L'

I^CLTS

n intrna.] fie can on1y bc sed 1ih RED and l,iRTE Staiements and an expcit fomirt spcci1icaion is eqied: ]isi diected tansfers arc no pcmited. Th unjt st hale ctaace dai type but it ca,n be a vaiab]e, aay e1cmcnt, Stbsirig, a, cmp]ce aay. i is il cnplctc aIay icn :ch arav clcnent consitues a recold; in a.11 othe cases tie fl]e onlv consiss o oe recod. Dati tla.nsfes a]iys sat a the bginning of te intena] fi1. tha.t js an ]mpic]t cwind is perfomed each timc. The ccod 1cngth ]s t]re egth ofthc chaacte jre. t is i]1cgal to ty to tansfc ]1oc chaactcS tha.n hc intcnal ]i1e contains' but jf a,1ccod of too ew (haci.s is wlittci it lvi11bc paddcd t w]th blinks. The END= and 1STAT= mc]anisms ca be sed to detec te end o 1ie. ,{n ]ntena]li1lr i,iRTE is typicay used t conct a nlrmelica vilue to a cla]acc s1ing b using a Suiable fona speciicaio1, for exape:
CI{ARCTER*8 cvL BvrE = 98.6

I,\RTE(cvL,

'(SP,

F7.2)

'

RVLUE

Te RTE staeen \i]1 ]i]1 he chaacte vaiable c,{ \ith e chaa"cteS J +98.6 , (note hat ]rcc ]s onc b1anft a.t each cnd of thc n1rmbcl, he 1is bcause the nub ]S igh-jrrstificd }e Jie]d of 7 chalaces, the second beciuse ]e ecod is paddcd o11 to he decla,red 1cngth

oncc a numbc has been hrncd ]nto a chaactc sting 1 can be proccsscd fthe in thc rarious wa,ys descIibed in secjon 7. This ma.kes it possjbc, fo cxamp]e, to vriie nubes lc1 jstificd i a.1ic]d, o mak ncga.ie tnbes w]th "DR" (aS in b:nk saemeS) in o1een se a pai of parentheses (as i balancc shects). \ith sitble aithmctjc you cin evn outpu ales fu other ntrmbe_bases such as octal hcxadccima"l. Even oe c1abora"c onvesros nay be achieed b1 iist witjng a sitalr1c foma spccifici'jon ino a. chaacte sing and then 'o .Jt'.t' .on'.l o,.. ll a "] fo|l ^..I l.. d.-,"d '.| ]ntena] :fi]. READ stacmcnts c:n be used io decde a c1aactc sting (ontaining a. meica, ale. onc obl'ious app[cation iS to hand1 thc Scr input to a conmand diven prgaI. Suppse the command line cosiss o{ a 'ord fo]1o'cd, opjonay, by a numbcr (i intege lcal fomat)' wih at ]eas one b]ank Sepaatjng the tw. Tius the ip cmmands migh be
Somcthing

of 8 cnaractcS).

[c:

UP4

RcHT 123.45
].o d he !ho]e ne ]no a chaactc vaiable and then usc jiIsi 1ocat thc bank. Thc prccding ch:actes constitutc thc comnd ]r{] N]]Ex firnctjon \,/ord, rosc fo]owing can be conctcd to a ca1numbe Sing i.n inena file READ. o cxamp]e:

simp1e way

o deal \]h is is

cHRcTER cLJE*80

1o

iR (UNT=*,lMT=*)
RED (*, ,()',

*The counand.rd is noJ in cN(1:(-1)j tssue the * nurnber is in the neit 20 chaacters: tead it into RVLUE

1F((DE.NE.0) ST0P K = rDE (cL1'iE, ")

0STT=KODE) CLNE

JEnter cand: '

READ(CLNE(+1:),'(BN,F20.0)"

]STAT=KDE)

1a

NP'-'/ oTP

T FCLS
THN
)

87

F(KD . NE. o)
G

'{R]TE(UNT=*,FMT=*)

END E

T0

Eor in

n',]rnb

10

: try again,

f bla"nks $,i1 bc conletcd jnto Zo.

Ne thai h cdit descipto BN is n.cdcd o elsc iat a.ry a.i]jn8 bla.nks wilt bc ignorcd: thc 20.0 11,il1 rhen hand1c any cal o ]nte8c consan ani,wherc iI thc ncx 20 ciaa,ces. ficld

10.4 Pre-connectedFies
Temina nput/output
Many poga.S ac jneactivc and ned io accfss thc ls\ .ine.]. A]hogh t. t a1is a f]e wl]c cin bc coInectcd \ih an 0PE1J satemenlj is name rs sysem_lcpedent. !bt;'n so1ves he pblcm by povidng tw specia fi]cs sa y cacd lhc stant input fte ad he Standad utpu fi1c. Thesc fi1cs a.le prc clnected j.e. no OEN si:met js neded o1 pcmied). They arc bor {olmed sequcnia] files and) n jneact]e Systcms. andle irpu and utpt o thc temina1. ou can RED and tiRTE fm thesc 1i]S simp] by ha.ving an astcjsk (*j! as tlc unit jdcnlifie. Tcs 1i]es ma.ke emjna]/o s]mp1c anr] potablc; cxnpls of heir uS ca bc fo1d hght tiis book. when a pogrim iS n in batc ode msl systems iangc fo Si.dad utpu o bc djvetcd o aog fi]c o to thc sysem pjne. Tlcrc nay bc soe sjmila aangcmen f ho sandald ]nplt i]c. Thc asteist notation has ne S]igl dawba.ck: ie uni nrrrnbs iS otcn spcciied bJ an intgc a iab1e so ]a,t ihc soce 1 ipu o dcstjnatio ol outp1r]j can b srvitchcd fror onc fi1c to anoihe e1y be alteig the value olthis intgc. Thjs canot bo tole 1irh he Stada.d jnput o output fl]es'

other Pe-connected FieS


lo have unjt5!onncctcdolnc,adrc.]d.xnilnlt6hene p]nte. oth units \ee usua.]]y connectcd to disc i]cs {.]th rppopriae narcs: hus u]i 39 might be connectcd toalic c:ed FTo39.DTo ctJTPE39 i p"_"olnecions arc ".e complee.1y obso]cte ad Shou]d be jgnocd: an OPN stamci cal stpcsede a ple_conncction on any numbcred tnit. 1{otunatcl hese obso1c pe-conncctions can havc tnexpectcd side fects. f )u fg t opcn an outptlt fi1. yo may find lha your pogan ,i un \jhoui nlol o ,' ]l,"| |r''| o']] o".i"1 o1 " l^lo," n"'",n..',, ,"..'
cusonay
n ode t etajn copatibi1ity \rith Ftan66, many Systcms povid

uscd o be

ohcr De-conccd ies.

1,5 Error and End_of-File Conditions


ES in mos executab] Statcents ca bc pevened by a1in3 stff]cicni ca it l./itig pogam, bu in /o Satemcns eos can bc caused b vets beyond he cottl of he poganne: for cxanp1e through tjng o pcn ; 1i] i.hich o inge e]sts. \ijng to ' djsc vhich is ful, or eading a data ]i]c hich 1aS been cca.]d .ith he wog forna. s]ncc t/o sa,cnts ae so vunea.b], lbtan pvidcs in eol han.]]ing echanjsm r thcl. hec alc i'cta]]y wo dif'ccn ways o handling eors ,hich ma" be uscd jndepedt]y o in

te

la

PT/ojTPjT F'C]LTS
F]si.y you can nrc]ude in thc

/o conio1 l]st an jtm f lc fom: STAT=inte8er-vaiab1e whe he staicmcn has xecutcd ]lr. ite]c alib1 (o aa}, c]nent) wi]t be assigc a 1?1c cpesenitg thc /o sta"us' lf thc stieelt lras compld succcssfuy h vaia.b1c iS s.l to zero. orlr.wis. ]r is st snn the va]uc. a psiive numbel jf an cro ha.s occured, o a negatjvc .:tu i lhe ed of a.n inpu fie was dct]ctd. s]nce he alu of th]s Satus co.]c ]s Systcn dcpelden' in porab1c sowae thc most you cal d is to co]npae it .] Zeo ad. possib]}, ept the a,ct:] c1o code to thc sc. T]uS:

10

IRTE(UT=*, FM-*),Enter na RED(U'iIT=*, ,1T=*) E]IME

of input fit:

F(oDE.NE.0)
ND

OPEJ

UNIT=PUT

, FE-NME, STTUS=JoD,,
TEN

STT=XODE)

tlRTE(UNT=*,FMT=*)FNME,, cannt be pned, G0 T 100

]I

Thjs sjmp1c erro handling scheme akes t1tc pog}a just : jt]e moc ser_fricnd1y: if the fi1e cannot be pcnd, pehaps bcaSc jt ies no eist. the pogam isks lo anoe fie_name. The second mcthod is to in.]dc an itc1 o tle fom

'hich

a.ro. T]is

RR=1abe1 ca,uses con1ro] to be tans1ed ro

must, of couSej be

a.n

ihc st:ietet atta1ed to thai abe in the ent f cxc{ab1e statcnent and i t1 sam pogam tnit. 1
,{PS

'

]TS=vlTS*AMS re- l progral l1he]e


E]D

RED(NT=, IMT=*, EBR-999) VLTS,

999

sT0 WBTE(UT=*,FMT=*),Ero

and

fjna
VOLS

]J

reading

AMS,

T1r metld has ]ts scs bu is opcn to thc saJne o]ject]ons as thc G0 T0 sl,atemcnt: i oftcn ]cads o b:d] stuctiued pogans .ih 1iS of ab1ttay jmps. Bv sing bh 0STAT= and ERe= ir th samc Statment it ]S possjbe id oul he act;] cor nunbcr and jrlrnp o he co h:lJling code. Thc pesencc of cithc ]reywod in an /o sratent wi11 al]lv tllc poga.n to continc ae an l/o cror: on ns svscms ]t a.]So pevntS i co nessage bcing isslcd. Tle ERR= and 0STT= itcnS can bc uscd in al1 /o statcnens. Pofcssinal pgares s]rk] makc cxtenslc usc of tlese eo_ha.nd1irg echanisms to cLace thc obustncss an user ied]iless of thi softae. lcc js olc 1ir'ly comon misakc lrich des noi corrnt a,S an cos or this prposc: if yo 'i'jil] a ntmlre o a fomattcd c.od using a, fic1d lvid too nalw to cniain ii, ]e ]ic]ij i1 simp1 bc fillcd wj aseSks. an eo occuls 1n a dati]" ansfe siatcrncnt tho thc pS]ion of tho flte bccns ]n{tc teinatc. t nla b. qujie difljc1t t ]ocar ]le ending rccJ if an co ]s dctc.i,d w]le ]:as[eri]g a agc aa\'o lsi11g ]aqe numbc f rccods.

r / o

1'P''

t'C']TS

End_of-fle Deteciion RED Staclncn , ]ich iics to ead ,. ocd b.yond ije ctd of a scqria o ina.] ]itc $,ill liggr le cnd of fit: co1dition. f at1iicm f ic fom| ST=intege-variab1e ncl(]d in is conto1_1is thcn h Sas a]rrc wil] be tcd as snc n,,gaic nnlbc. fjt icludcs atl itc of ihc lom: ND-label hen corol iS transfclcd to thc labe11cl] sti'cent wcn he
'he END= kcy\od rna"v on]y bc usel]n RED statelnents, bu it

cnd'of

ite condition dctcctcd.

know1 length, bt so11c ca.utjon ]s ncc.ssat.' f you read svera1 ccotcls at a. imc lom a foa,ttcd file thcc is no ca.sy s,ay of kol,ing cxacr]y 1hcr he end o fi1e c.]iiion occcd. The da.a ]is items beyond tha. poir wi]] havc rheir valucs una1tcd. Notc :1so at thee iS no concpt ofcnd of']ilc n dject-acccss iies| it is Sjmp]y an co to cid a ecoli hich docs ot e]st, \hthe i is belrd he ,,end', of ih fie o no. {ost Sstms povjdc somc mcthod fo sign:]lng cnd of'fr1c on cm]n jIput: those base on rhe sc code olrcn se thc chaiace ET hic1 is ualty produccd by pess]ig co1,ro1/Z n i]e cyba"d ( EoT hich is cotro1/D). Ae a.i end-of ne condiio has bccn is.l in h]s waJ, i may pesist pventing fhe temina]it1put to thal pogam. Ena]y, thc ota.1 Sandad only equ]eS Foran sy..ms to 1"ec thc ld-of_fi]c c]ndi_ tion o .xea} i]cs if tcc is a specia] ,,cnd 1ie,, rccol on ti ed. Te END FL] siamcnl is povjdcd specifca.]]y t wiic sch a. ccod. pactic., howcvc, viia.]y a] .ota.n sysems espond pc1cty $.c.] wn you ty o ad thl] fir.s on_cr{isent r.cod' S t: 1he D Stat.e]t is ctrecie]y bso]ete and is no ecormcded fo golea] use.

ot both RR=

id

0STT= keywods' nd of ]ile dctcction

vcry scfl

1s

ca

bc selin hc pcsecc when rcading filc f

10.6 Fornat Speciffcations


Evey RED or iRTE Sta.m 1hich uscs a fom:ttcd etcna] fi1c or ilc]udc a fomat identificl. ThiS ma ia'e a.ry oft}e fooring {oms;
FMT=* This spccjfiS a.1]s djecicd :.ansfe (a,nd is oly Detailcd u]es ac gien i Sccijon 10.10 bclo.

a int.i]

fite 11
]i1es).

pcitted

fo eicna.l Squentja]

FMT-la6el The ]abe1 mS be att:ched a povides iic {mat spcjficajon.


Fl=chr-e.r:p

FoRfA

statclent ]n the samc pogam rr]i. q,]t]ch

T]

va]ue of the chaacte cr.pcSion iS a cop1etc

oa speci]icatin.

-chr rru The lcments ofthe cha,acl,e aay cona,ln tie fomal speci]icatjon. which n:v occpy as maly eleents of the a ay aS a. necessa.

Nte h: ]e c1aaces MT= miy be omitted if i ]s the sccnd itc in t1tc /o cono1 tisi and j the unit identilie wih UT= om]icd comes ]ilst. ,{ 1oiat spccification consists a p:i o paethcscs ellclsing a list o iems ca]]cd edii descitos. _{ny b1anks befoe the et paelth.sis \j]1 bc lgnored ald (xccp ii a FOR,T staemcnt) a]] characeS aftc the naiching ]gh paenthcsis arc ignored. n nost ca.Scs the frmat can b] chosen \hen thc pogam js witten id h Sjmp]cs optio] is to usc a cialice consant: FJRE(U]T=, FMT=, ( 1,, F11]. 5), ), lr:equency =,, ERTZ ]tcnativc1y yo1 can usc a ER}1A staement:

915

],iBTE

(UNT=, El,1T=915) ')Frequency =,, ERZ FR1AT( 1x ' ' F10.5)

]a

PUT/UTPUT FACLTS

90

i]e sae fonat to bc tsed by n1oc ia.n ie da,ta tansfc s1atcrent. Te FBMAT sijIlen may also bc thc na.re iE tlc spccificai.i iS 1ong atd comp]catc]. o if ch:?crcI coIsa dScipts ac invo]ed. sjnc thc cnc1sing aposophs have to b db]ed p ]f ihc ilc foal is pa o aJohc cha.acte consa,l1. t is aso possiblc to coinplrte i oma Specilica.tion un_timc by usjng a Sujtable cha.racrel exptession. By iis ans yo cou1d, for exmpe. aangc io rad the formit specification of a daa fi]e fom hc first ccod o the fie. Te pogram fa.gett bc1o1 shorvs 1o$ to oplt a rcal numbcr in fixed pojn foat (110.2) vhcn jt is snal. c1raig]ng o expnntiat fmat (18.j) en i is ]age. A tcshd of a mil]io has bccn ciosen ]ec. CHRCTER l1*(*), F2*12' F3'l(*) *tels E1' F2, F3 ho1d the the pats of a forat specification. ;l1 and F3 a constants' 12 is a vaiabl. BMETER (E1 = '(1,"eak size ="") PRAMETER (l3 = ,),) *... ca1cu1ation of E( assumed to be in he F(Ex .LT. 1.oE6) TiEN F2 = 'FtA.2' EISE F2 ='E18.6' EJ| F
,{RTE(UNT=*

l'his allols

ha"-e bcn dou_ ].d i1 he PRi'1ETER St:ten ecaus thcy a.rc inside anhe chaa,ctc coSant. Hce ac wo eamp]S f tplrt ecods. ith b1aks Slro\\,n exp]cit]1.:

i'o a he apostophcs SlIomdjng he chaacl cnsant ,poak siz =,

'

F1=F1/ /F2/

/F3)

P'Y'

PeakLsize!-!!12345. 67 eak!size!=U!!!U!0. 987654E+8


FR}4T

Statement

is classcd as non cecuab]e and can. ii pnrc]p]e, go;los a1'lere poga in he nit' FoRMAT stlnen caj of coSc1 b corinued so its i'jmun lcngh ]s 20 1i1*. Th: Sam FoRMT statcmcn calr be used by moc h. one data tanse sta.temc and, un1css it conta.ins c]]iade colstnt descjpiol.s, used fo bth inp11 and outpur. Sin.e i is e}'easy to ma.c: misakc jn aic]n3 th] itcms in a data, tansfc iS ith thc edit ls1pos ir 1e fomat specificai]on, it rnir,kes sens io pt tic FORMT statcmen], as c1osc as possib]e o he READ and iRE St:te.nls W]rjh us ji.

Tc

ORMT saeet

10.7 Format Edit Descriptors


1'hcc ac two 1'pcs of cdit dscjpo; daa dcsciptos and col,o1 desc]pts. _q data dcscipto. mus bc poidcd fo ach daa jren ansfccd bv a READ o URTE Saomet1,; ]e drsciptors pcm]ttcd dcpcnd on the daa tlpe of thc it.r. The da.ta dcs]iptos a1l Sta 1vith a. ]cttc indicating th. daa typc follold by an us]gcd ].t.gc deotjg tc e]d idth, fo examp]e: 5 dc1oiS an int.gc ficlrl 5 clr:l.cers lvide. F9.2 dcnlcs a floating po]n ied 9 caac 11id witr 2 digns aft thc dccjmal ]ojn' u1] da]]S ofa.11th daa, desc1!toS al] g]|cn ]n h nc sccl,io.

1' /

1U'L'PUT''ACL]7']S

91

Thc coltlo1 dcsciptos :rc uscd fo a \.alicy f pr'poses, suc1 :s r,abbin8 i., spcific co]tns. poducing o Slijppjng l!]ods, ad cnto]ig ] asc o1ssequcn ncica1 ta. ,'hc\-

. . n... ._ . ll.. " o .0.. Noe that oy 1ic.l .oSa]ts sia s ajaJ]es.

ae pemitted w]ihin

folma spcc]ficaio1S. 1ot [a]d co' L

10.8 Format Data Descriptos A, E, F, G, ,

da.t, descipto nrs be pojdd o eac.l data item pcsn ( nnp]icd) in a daa tansfc ist. Rca, double pccjsio, i'nd corp]ea ienls nay usc any of he , , o G dscipos blt jn a ohcl c:ses te dat a t]rp c rn ust m ar ci . Two i oaing- po]nt d esciptoS a,c nccdcd 1bl ea ch
Data tlpe Dara d,sripors

Rcal. Dub1c Prccision, or Complex E\,.d, Er.dEe, Fr.d, GJ.d, c.dEe ogica] Lr
chaac1.e

{r, r.n

The]etteS !r, m, d. and e Scd',vih hcse daia descipioS epScnt unsiged jntege con Sta.tsi and e must bc gea han zcl.

, n d e

otal i1d width' is h minin nmbc ol digjs poduccd o put. js the nurnbc of digits ae te decini'l poit. js the numbc f d]gis lsed f t1c cxpnen.
]s he

ny daia descjptol cin be prcccdcd by a lepeat_colt so 3F6. ]s equivaleni to F6.0,F6.0,F6. T}js faciiy iS pa.rtic1 ay useful icn hndling aravs'

ai

rrnsigned itege), tlus:

Geneal Rues for Numeric npt/otput nnbel ba.sc: hce iS no poisjon in Sandad ola.n for tansfes in the nbe bases such as octal o hxadccimal. ]{oe copicated conversions such aS these cal1 be pcrfolncd \jth he ajd of intcna.l fi]es. on utpt nmbe a.e generatiy r1g justifLed in the Speciicd ]ietd; eading b1ans ac sup plied vhee necessay. Ncgatie vaues ae alvays pcccdcd b a mils sig (fo hich space nus be a]1ed in the fie1d); zc is aways nsign.di tc SP id ss dcs..jptos cono] whetle positjvc num]rcrs ac to be peceded b}, a plus sig o not. nu b 1hjch iS to 1ago t fit into its ic]d wi]] appcl insead aS a. Sat of aseists. on input nllnbels shold b jght jstj1ied in each ndd. _{ fms of cons;l, pcliied in a }btan pogan can sa.fcly bc sed in an input ficld o the clsponding type. a.S 1ong thr] ac no embcddd o taiing b1ans. Leading ba.nks ;e aways ignred: : fid \hich ]s eniey btank li bc rcad:'s zco. Te tea,tmcnt ol embedded and aiing b]alks can be cono]]cd witi the BN a,nd BZ descjpos. The ulcs clc a-e anothc reic of vcry eaty }btan sysns. \icn cading a ]ile whjch ha.s bccn conneced by means of an PEN sta.tan (proided i does no contajn BA}i(='ER') a]l embedded and trai[ng b]:'nks in numcic inpu fre]ds ae eaed aS nls, i.e. tiey tre ignoed. n a 1ihe cascs, such as input from the standad pe coccicd ile ol fom a.n intcnal n]e' elbeddcd ald ta]ng b1ans ae tea,ed as zcos.
ac lways cotvctcd usig he decina

Nubes

1a

Pi /OUTPL FCLTS

Tcse dcfau]s n }] alerea e'itlr r]r. BN and BZ conto1 desriptos. t is ha.l o imagjne dny .ilcu1snces i1 a.]jch it is dcsjable o intrprct cmbdded blanks aS Zes; thc defautt scttings ac pajc]ay i11-choscn sincc nunbes entecd by a s] at a tcina,1 a oftcn 1f'jus1,i1i]d and may appca to be padded o $,ith zcos. Elots om tis so1c can be a]ded bv usig nN ; the beginnjng of al] input format Sp.ciiciio1s.

nieger Data
,{n intege

(tv, v.n)

laiuc wriitcn''it1 ,:ppeals ighi_jlstilicd il a ed of cha.races $,th ]ading l is s;mi 3 hr.ns.q rlrit eas m digjts lli ppa c\'cn i1 eding zcrs le ncessay. This is usef], {o instancc, to utpu the timcs in oS and minrrtcs:

;lAns

ITIHoURS

M]NUT = 6

=8
FM= J

WRT(UT=*,

(]4.

2,

12. 2) l

\i]URS, 1'JTE

Tie otput
!086

ccod

(wti

b1anks slown exp1icit1v) is:

on jnpnt 1and r. ae idnical. Notc tha.t an intege ficd l1s not co]ta]n a decia, point. cpncnt. o anv pu]1caion c1aact.S such i's conmas.

roatin8 Point Data (E..d, Ev.dEe, FJ.d, c.d'


sing an of thc desc]ps E. F, o

Gr.dE)

fo1atSpecilicatioofthefom(15.,TL1).-.sohathencIrfi]dSasoncp]accto1e1fi and ove wiS he decima] pint. thc $.:y is to copy the nmb to an integc 1aiab]e a,nd w]tc it wit1 an dcscito- b no he imited an]. rrf ]negeS on most sysems. F fomi iS.spcci:llv convcnien in ab]a layouts sincc t]c d.c]mit] poits',ill lin p in Succcssl\e ]cods, but it is o suitab]e fo cj, llgc o smi]] numbcS. output jth Er.d pdlccs a. nunbe i expolential o "scjentiic" notation. The mantjssi], i] 1re be\en 0.1ad 1(jfthe scaic f:cto is zc). Te o E.dEe Spcins tha.t tcc sho1d be cxact11' e digiS in thc cponcn. Tis nst bc Scd if he e]poncnt vi]l htve mo han thee digjs (ahough lis pob1cm does n ar]sc o nachincs on whjch te numbc a.nge n oo sIal). E o1at can be usd t hand1c numbcrs o a,nr' magnltrrd.. The disad'a,ntag is hat exceptiona,1]' largc o sma11 valucs do not St:d out very wc]1in tnc jsu]tin8 co1mns f igucs' Gl.diS ihc gccal prrposc dcscipo: iha,]uiS gca.tc th:n 0.1bu not too1agco1i ] th fid.] ]1 1il] ,.] usin8 a 1ired_poil foaat $'j d digi, jn iota:nd wirh 4 banks '/i1 a e cId ]f h.] f{r]a: ocjre i ]s cquia.1c to E.d {a. Tic fon Gr'.dEe a]o1,s \'ou

Daa otanr' ofthc floating poinr iypes (Rea,l! Dbtc Pecisio, ald Copx) a.), be taSfcned G. 'o each comptex numbc wo desciptols mst bc provided, nc for ach conponent; thcsc conpo1ents mar be sepaacd, if reqied, b1' cotol dcscr.oS. on ouur ubcs a.e rdect to thc sp.ilied nmbe of digits. A1 floating lint daa anses ae atrectd b), he seiig of thc scae ractor; this is i]jtjal1y zo bt can bc altd by iho cto] dsciptol.:S oxplained in th scction 10.9. otp using Ir.d poduccs a fed poin ',l,1 in a n.ld o 1 chaacteIs \,ith act]v d djgits afc thc dccimal poirlt. The decira,i pojnt iS pesent even jfr, is zeo, So that ifa sign ]s podccd ihee js only space flrJj at most1 -2 digjts bioe thc d:ina] pofut. f jt jS ea]1y ]mpoIta.nt to srrpp]ss e decimat poin in nmbcrs with o fracijona] pa one i\'ay iS to nse a

]N P U1' / o UTL'

1' F ( r'l.F)'.i

9;l

to Spccjfy the lngti f th exponeni: if a fixcd po]ni omai is c}scn


t]e end.

cc

i|c +2 b]anks

hc rxt cxa,mp]e sholl.s th. diffccnt popcltics o{ t1ese ihec fonats on ouiput:

o"o. , n
U.

= 0.09876543

= 123.45679

]RTE(UT=*, FMT=, (E12. 'o ., oid. .l

5' F 2' 5,

G12.
D

5)'
:

) ,x,x, ,Y,Y

Il o_ f j :ll8 l.

Jl \

U. 12346E+3!!!123. 45679!U123. 46

98766E-1!!!!!. 9877!o. 98766-1

on inp a"ll the E, , and G desclipts have identjcal cfccts; i he inp fiekl conta,rns al exp1]ci decima pojn1 i a1vays takcs pcccdencc, ot1c\]sc he ]ast d digits arc ta.cn is lc dccia1 faction. an cxpnet iS Sed i lay be poceded lry E o1 D (bu h exponent 1ettcl is optiona] if he expnent is signed). { he input 1ied povidcs noe djts tha ihc incnal Soa,gc cil. utijse, ihc cxta pccisiol is ignoed. t iS lrsta]]y best ro sc (..J whic wi cope wii :1 common flating point o cven incgcr forns. Logica Daia ()
Whcn a. log11 va.]le is witten \ith L1 he ]ie]d wj contain the ]ettc T o F pcccdcd by (j-1) bI;nks. o inpu t] fiek musi co1tai the ette T or F; he ]ettc may bc pcccdcd by a dcimal point and iry nlnlbc o bl:rks- Chaacters aft thc T o ae ignoed. Thus hc o m .TRE. -1d .FLSE. u-.. .p'.ol".

chaacie Data
{

( and )

he ,{ descripto is sed ,ithoirt : cxp]jcit fild \jdh the hc ]cngih of the chaace itcm ]n thc data tli'nsfe [St dteminS it. ThiS iS gecr.l1y \ha is equied bt ote ha he pos]tin jn f the emaining itms rie ccold wil cangc if ihe 1ngt of the 1aact item iS altcd. f is im po ant to S 1ixed c] layou S he {om r m ay be pefccd : jt :hviys 11scs a ]leld w chaaces lide. on otput ifthc actua11cngth lcn js ]ess than\vtheva]ueis igh jsiied in ihe ield and pleceded by (-1en) b1alls; othc,isc on1y the liSt r chaact.s lc otpu' thc st ie igIed. on iput i the egth en is ]eSS than w thcn he ighi-most et chaactcS a rrsed, theiise 11 thaacteS wi]] be read into ie chaacc vtiab1e 1vjih (1en-v) b]anks appendcd.

l0.9 Fomr

cono Descripfors

cono] desciptS do not coespond to any item in the dati' tnsfe jst: hey ae obeyed when tlc fomat scan eaches h point in the si. foat Speciicain crlsiSting of nlhng but contl descrjptoS is vaid only if t]e RED o l,iRTE statcmcn has an eply daa.tanse lisr

1a

PUT / oTP UT L1ACLS

94

to next rccd [ovc to spccificd colun posiin otput a chaactc cnstat Stop fomat scan if data 1ist mpy cono1 + befe positjve numbers Tiea b]anks a.s nus/zeros

sip

conto]Fnction

Control Descriptr

Tn, TLn, TRn, nX 'any cha sting,

." SS,
BN,
KP

sct

Sca.1c

fa.cto fo

ncic

tans[es

clc n and k ic iniegc consas, k iy ha1e a sig bit r1usi be non zero ad unsigned. The cono desciptols sch a SP' B, kP aIect a,l] umbcrs tans1'eed subsequently. The seitings ac na1cctcd lry foccd cvelsjon but th sysm defau1ts ac estord at thc start o
the next RED o {RtT opeation. ,A.ny ]is ofedit descipos may be elcloscd
a,S

a epetition ctt, e.g.

parcnteses al]d prccedcd b an integ

consta

]s equi1a,le

'('

\-'\

'

These stb ists can be nstod o anv ea,soni'b]e deph, bt tha pesence of itcn.l pais of palcnthcscs can havc Spccial cffccs',vhen frced eversion takcs p1a.cc, a.s explained atc. commas may be omited between items in thc fol1owing specia cases: eithcr side of a s1ash (/) o coon (:) desc pto, and afte a sca1c factol (k) ifit ]mnediatcly plecedes a. D, E, F, G dScipto.

Record Cntt (/)


Tie slash descipor (/) sta'tS a ne$. ccod o orrtput or skjps to a nc', ccord on input1 ignoring Iyhing lf on he cuc1t ecord. on a tert Jile a ecod nma]y corsponds t a. ie f icx. Note tht a folmitted 1ansfe always pcess at ]ca.sl one cod: ]f thc foIIi' contains N S1ashcs thcn a tta1of (N+1) rords a.e processed. \jtl N consccrrtjve s]ishes in an utpt {omat thcrc wi11 be (-t) blak l]ncs; or jnplt then (],{'1) Lnes n1]1 bc ignoed. Notc tha.r if a fmatted sequeti: file iS sent to a Pinte thc iSt chitice of evey tccod liy b uscd fo cariage_cont (se section 1.11). t is 8ood pactice o put 1x at thc bcgin1ing of evey ola $peci]lcalion and afte eey Slash o nsue singc 1i. spicing. ee, fo exampe, }e is a blank lie ae he colunn headings.

95

WRTE(UT=L, FMT=95) (NEAR(), PP

!RMT(1,'Year Ppu1ation',

//' tao(x' 4' F12'(), /))

(),

=1,ERS)

Coumn Position control (n' TLn' TRn, nx)


Thsc dcs.jpiols .;rrsc sbscqcn va]ues o be ansfeed stating i't i diteent co1umn pos ion in the recod. T]ey can, fo instatcc, bc uscd to sc p a ab1e w]th icdings positioncd ovc cach co]umn. n a1l thcse dcsciptos he vaue of must bc ] mor. Co]mns a. nurbcrcd forr 1 on he eft (but eembe that co1unn ] ma}, be 1sed fo ca]agc cntlo]i ic rrtpt is scnt to a pinc).

10

PT
Tn
TPm

/oU'lP(; AC]LS
call'cs subscqrrc ouip io start at corrrn n. ca1t9cs slifi to hc ighl bv r cols. causcs ) shifi to the 1cf by n co1umns b i \i]] no mol,c hc posiin the cft ot co1umn t). jS cxac]v cqui\.acnt io'Rn.

95

TLn nx

b1aks. Ths:

on input Tn c:.l be scd to e cad thc sa.c fi.]d again' possibly using a djcc da' descipol'. on oipu t1csc descrjpos do not ne:css;i]y havc any d]ec ]1ec on hc ecod: hey d no causc aly eising d]aactcS o bc cp1aced b}'bl:ns, b]ti \hcn tlc ccod iS comp1cto anv coml plsiios cmbcddcd n hc ecd q,hjch ac Sti]] nsc 11i1] b cpa.ccd b
WRE(UNT=LP, M=9000)

90 oaMT(,A" TR1000, TL95,'Z')


11j11

causc a ecod of 5, chaactcs to b otp, ]dd]e 50 f hen b1an]s.

chaacte constant output ('string')


The c;'a.ctc coSani descipo can o1'-, bc sd wj1 ,lRTE Statcmcnts: lhc c.h:a.ctr St]ng ]s S]mpl cop]ed to he op ecod. s jn al c}aa.cie co]stanS an aposiophc can b cpcsntcd in ti.1 sting lrJ t,o scc]ssivc aposrophcs, and bla ks ae significan.

Sig conto (S, SS, S)

ftcl SP has bcen used, positivc nmbes i b] wie a ]c:ding + sjgn; :1c SS ias '\.ith lrc.n used ric + sjgn is suppsscd' The S descipo eses thc ]nji:l de1li \ici jS Sysem dpcnde. Tese desciptos hac n efect n ue]ca1 inpui. T1e i]ial dea] is ested a thc stal of cvcly 1e\' fomaited ansfe.

Bank cnto (B,


rfc
B,

B)

js rrscd a embecded and trailig b1anks i nmeic]r,] inpi ie]d; :c rcal as nulb. i.c. ignoed. ,.fe BZ they ae teated aS Zes. These descripts ]ravc t jfcc1. n nnjcal oltput. The initia1 dcfarr]i. \}ich dcpcndS on ihe Bt= iteft in 1 PEN Samen, iS ]Stoed a.t ihc stai of cvcy new foied lr:sfcl.

Scae Facto conto (k)


Thc scalc taco can be used o inoduce i' scai]ng by an} powe of ]0 bet1ee nlinal a,rrd ej.tenal values l.hcn E, , o G dcscjptoS ae used. ln pjncip]c thjs cold bc rrscfu] wicn dcaling with data w]c ae oo ]argc, or oo smal1. { thc cxpoen a8e of h ioatjng pojt d:ta iypes o the ma.c1jIe, but j o}e difhcrr]tjcs nsay i1ae this impacjcab]e. Th sca]] {aco can esu]t in paticu1aiy insidjos eos whe used iith F dcsc]poS and s[oud bc avoidcd by al1 scnsib1c progarnmcrs. The u1es ae as fool.s. Tlc ititii sca] ficto i each fo1icd ta.1ts1'c is zco. he descipto k iS used, llee js k a Sna (opioIay Siged) futege, hen it js sot o k. aects al1subscqucnt floating po]nt va.]res talseed bi, the sta"een. on inpr i]r.rc iS no cft'c1 i he input 1ield con.]S an cxp]icit cxpoett, oeise l ' ' ''' a'' l. on output ]c cffect depends on tl descjpo uscd. Wi11 descipts thc dcina pi is

10

Pj/oj1'Pa

ACLTS

96

movcd k p]]s o thc jght and the expoent cduccd by k so ihc e1'ectje a.ue is ua,Eercd. W]ti F dcs(ipos hee is atways a scain8: e[l'.:rnl'ue = em irltcnal \,2re * ] ir wjth G desciptS th sca1'facto is iglocd if he va]e ]s jn the angc fo F{yp otlut1 thcwjsc il ias thc samc c{ccts i's \]h E desciptoS.

scan Conlrol (:) and orced Rersion


Thc 1jst of edit descjptos is scancd fom ]ef o llgh (apat fm he effect f paetheses) Stating at thc bcgnnng of thc ]]St wheneveI a nel data transfcr Saeent iS cxced. Thc action of thc /o systcm dcpnds jointly on th ext edlt dcscitol and tie nct itcm in datataSfc ist. f a. da,ta dcscjto clne ext he the net data item is tansfcrd j o1e exists. oterwisc thc {oln:t scan coes to an end. { a co1n dcsciptor (: ) comcs nejr and thc daia" lansfe is js empty e fona Scal ends, othcrvisc le descipto has no ffect. f any ole corto1 descipto cmes ncxt thcn it is obc!'ed \hehe nt ihe data_tansfar lis is epty. f ihc fmai ]lst iS cr.ha.usted when thee ae Si]l mc iteIns in tic data tr.anse tist thcn foced eesj occus; he fi]e ]S ositjo]cd a.t thc bgining of thc ncxi. ecod and thc 1br mat ]iS iS scanncd agajn| Sating irt the 1,]t paenthesis matclil8 he ]ast prcccaing ight_ pitenhesis. f tis iS p.ceded by a. epea count hen t]s cont iS e-uscd. f there rs precedig igh paenesjs tlen the 1'1o1e fnrat jS rc sed. oced cl.crsiol has no cffcct upon h sings to scae acto, sign, or b1ank cnto]. oced rcvcrsin cn be sef .ien eading r lrjing a aay coniai1ed on a sequence oecods since j is not ncccssay t kno\ ho11 many ecds thec ac in totai, b \ieil poducilg printad oput it is csy to oge that a cajag contl c:racte is qujed fo each ccord. cve those prodccd by foccd rcvrsion.

10.1 List_Directed Formatting


,jst djreclad outpui uses a ,oma clsen
b}. thc systcm accoding t thc dia type of thc ile1. Thc cxact 1ayot iS S'stm dcpcndc, b he geea u1cs arc as foos'

List'diected outpt
Each i.JR1TE Sttcneni stats a nc rccordl a.dd]tiona1 ecods ae prodccd r]n necessay. a,ch ccod Siarts i,ith a sin8c b1ak o rovidc cariag. con on pintin]. ji}nctic daa Jpes ae coneed to dcimi va]es wi] he umbe of digits appopjae fo the ntcnai pocisioni jItege lal.s \']ll not hae a dccia] poin, t1e syscm a} choose ]ixd_point o expoeIia (scieIiic) fo fo floaing-potl vaes depeding on rheir' magnitc. conplex aLucs alc cnc1oscd in pacnthcscs lvjth a conrma Scpalating i}e .o pats. Logjca.l vlucs ac tpt aS a singl lcttc, ciic. o . chaacte a.1ucs ae oupu ithout cnclos]g apostophes; if a chaactc Stjng jS too 1og for olr: ecold it ay 1rc cnijnued n e n]xt' xcpt fo craacter vaJues, each item iS foved bl' ar leas oe blank or a comla (ot boh) o Sepaie i fron] thc ncx a]u.

,ist-directed npi
diected jnpt cjcctivey a1 free-frmat ty f nueica1 dia. Eac1t READ satcmct Starts wit a nc]r ccod and eads as man1, ccords as ac n.ccssit o s;isy jtS daa-;rsfer lis.. Thc inpt ccods mrrst contain a suiab] scqclcc f alues and scpaatos.

Tie 1!.s f ]st

10

'] /oPjT FACI'S

valcs ay b] givcn itl a.i fo ,nich oukl b accepab1c jn a lbtan plog.n {r a corsta.l of the cocspod]ng typc, caccpt that bcddcd hlanks a.rc onl),' p.nir.d in chaactc iucs' \\ lrcn cadjng a oa] dob]c ccis]n val1re a ili]ge cosant 1v]] bc accptcdi whcn eading a log]ca1 lahc on]]'th ]ticr T or E is equ]ed (a peccding do a,nd anr fol1owing chaacicS \'i1] bc ignc]). ]iote iha] a (l]a.race cniia]t mst be enclosed il apostophcs and a cmp]x constai 1ust bc ec]osed jI paenthcscs \'ith a coma betcl h \ro conpone]ts. f; chalacte cons:nt js oo og o n on e ccord it ay be cnt]nue.l on to tc nex; thc tlvo pats of a colplcx consan ray a1so be givc n t1' ccds. The scpaato beq.een Successie valucs nust bc oc o mrc bia.s, o a cnma' o bth. e\v ccold m}'stat at any pint at lhjc : b]an \rr]d be pcnjed' seeal sccssivc itcn1s ae to ha\,c thc sam vaue a cpctjtion 1:ct can b used: hrs has thc fm n*consllll hce n jS an usigcd incge. Blans ae o a]oicd citic Sidc f tic asteis. To successie commas pcscnt a nu]1 va,ue: e cospond]ng l?ja]r]c jn the RD sta'e has its va1uc unchangcd. t iS a]so pssiblc to sc lho fo 1+ o epese a s of nu] ,{ dash (/) ay bo sed instcad of an jtem Sepaao; it has tic cfcct of complcting tn crrlcn READ wjti flt}e ]nput; a] emaining iens in its da.ta. tins1 list arc nchangcd
]n a,]e.

Ti

Lis'diected oup
\h]c1

laacte iteS.

copatibe ll.ith ist ditcccd jp. un1css th.v contajn wj] not ave the c]s1ng apostphs which are equied on inpot.
fi]es a'c gcnc.al]}

10.11 Carriage-Contol and Pinting


though a foi1i Spccification ao,s :onpl]e conl ove the 1ayot of each line o ex, i doas not i]clde :n way o :trlllng pa.ginat]n. Thc only \ o do lris by usirg .l lli1" and extaodiary mechanism da,ting back o th ea]ies days of F1ir';n' vcn if you ac not cocerncd -ith paginatin you st]1 nccd to knol about th calliilgc co] connlon Sincc r is l]ablc o alec eey Jrt 1i]e you podcc.

Whenve omated orrtp iS sent o ''pin". he fis caactc of ccy ecod 1s ctovcd and uscd t contl] thc vcr]ca1 spac]ng' Thjs ca.iagc co] chaacic sl be one f ho fo1r isted in he lhe ab]e be]\.

chalactc

blank 0 1 +

spacing b{e pinthg -,\dalce to nexi [e \'tica]

dancc two ]jnlrs Adance io op f nex page No idance, ].e' pint sac 1inc

,{n empty recd is teatd ?s jf it starlcd with a singe bank. o crQmp1c, these SatemnS stit i ncw pagc 1'iti : p:gc nbe a e op i1d a litlc on e hird jc:

55

iiRTE(r, 55) NUMBER, 'Report ]d ccounts'


FORi4T('1PcE''

4' /, '0'' )

This caiage-cool covelion is an absud cic w1ich causes a n1titrrdc ,f prob1cms in pacicc. FjSt1y1 sysems dile o wha hcy ca]] a "pintc'': it nay m:y no ipplJ, to isal display teil:ls o to txt lnitiay saved on a disc i1c and ]atc ptirrcd ou- Some opcain8 Sysc1ns have a $pcc]a1 1i1e type fo Fo; oatcd rrtprrt \hjch js eated di1leent1y bv

PU /OL|TPU 'AC]LTS

9t

pr'in]s (and teina]s). othes 1ravc bcn kown o chop of thc ]ist chaacc o{ a]1 ilcs Sn lo the Syste pint so ihat sp,rc]a1 ti]ities ae neded to pint odinay iext. T b on th Safe Side you shuid a.hal's povid a ep]cit caiage contol .:haa.ce a 1.he stat of ac flma spe.ificio and afte each sias1. Spe:ia cac is nceded jn fomals q,ljch se forced eersion' Nomal siglc Sp.cing ]s bta.]ned \ih a b1ank, cn,enje1tly podced by tha 1 adit dcscipt. f foge and ac.identa1]y pint a nrlbe at he sta.t feach ecod i a leadng digi 1 hen cach ecd wi] staJt a nc''l' pigcT1e etreci of + aS a caiage-cont1 c1aactc worr1d be more uscfu1 if its eIlecs wc me pcdictab1c. Somc dcviccs ovc pl]nt the prcios ecod (al1oing the otnation of cmposite chaaceS lie ), otheIs appcnd it, ad sone (inc]uding lany isal disp]ay tcmiias) easc hat nas thec bcfor. porta|1c Softvaa tale is o a}tcnativc brrt io ignoe tic a ci'se i,ltogcthcr. Saldad otan can oly se the fou cajag. coiol charactcrs 1jsted i the talr1 bu may syses use oh syrrbols fr specia1 omatjng puposes. srrc1 a.S sctrig vtja Spacing. changing fonts, and so on. one exlsio 1hich ]dc]v aj]abe iS thc uS ofhe curcnc}. Sl'mbo] $ to supless caliage lel a he ed of ihc ]jn. Tis cal be uscfll rvhen pduciig temin:l pTmpts as ji a]o', s the epy o be etccd on the sa"re ine. Thcc is. n1bnac1}', o wa} o ding is jn Staitdald otan. T1e ules f ]st'dilected utpt ensuc that the 1ines ae singlc spaccd b} equiing ar lcis onc bl:nk at thc s:l of cvcr ecord.

10.12 nput/output Statements and Keywods '/o . . l,"l. a]l i o '. t" .: . Thc da.ta ta.nsfc sa.tcmenls RED ad i,RTE.
Thc ji]c con:cion Saements 0PE1i, CL0SE, and QURE.
The lile posilioning statements REl.ilD and
BC{SPACE.

t] }csc statcmcnts h2.vc; sini]a gcie] fo.m (cccpt tha n]y he RE! and WRTE statcmcntS can havc a daa tansfc 1is): RAD( contro'ist ) iput'List wRT( contro-List ) an-ist Thc ]tcms i ca.ch isi ac scpiira.d bj] coEIas. Those i thc contoljs ae srra]y spcified b ke)wods. i lhic] casc he order does noi mate, a1tio11gh i is ]oventiona. t hae hc rlnii ideniifie flrs. o coInpijbjjy i] oan66' jf thc uni1 ideniie does con is iLet hc kcwd U= may bc oit.d. !'11t1c]noc. vhe his ]c1'',old is nji]d jn D :nd .,RTE Stacmcnts ,.nd thc fomat idcilia is second jS kcy$,rd may :lso be omittcd. Thus
thcse two Siatmen1s a exact]], cq]va1ctI

READ(UT=1, FMT=*, RR=999) l4S, vOLTs, IERTZ READ(1, *, ERR=999) l,{PS, V0LTS, IRTZ
t,sc of 1js a,bbrviaed {o ]s a mate o iasie: fo thc Sak. of cla]t 1l]o ea,..ls ']ll .ll 1lo sh, Jn othc cxamp1cs. May ot le kcywolts Jn l cono] ]js in ke a chaactc crpcssion as a ;8umn: jn sch cascs an1'aiing banks n the laue ,i bc igord. ThjS ma.s il asy o us cha.ra.cc

x.L,..o-l

|'"l

.'l

'.

]a

PU/oj']'PlT

I'ACLDS

99

Thcro is onc gcncral .csi.1ion on cxpess]ons used nr all /o sacnctS: thcy mus ot c:ll excna fucins 1lljcli hcnsclvcs cxcuc fir1,r /o 3iarrr]rs. Th]s cstjct] avo]t5 pssiD]1ji of ccuSil.c cas r,o ric /o syscm.

1.13

PEN

Statenent

Th ]i statcmcn is uscd l cone:i : fic o an ,/o uni aId dcscibc its c]l:actcics' ca]1 open all cxjsting fllc or' cate a nc$ one. f e ui iS alcady conl..td to anotie ]illr hen h]s js c]ose befoe the ncw conn,rcion is madc, So t1ta jt js ipossible o conncct 1o filcs sirul::usly io th samc unit iS an c to ty to conec moe ha one tn1t Sjan.osly to thc s:mc fi]c. n he speci,:l casc ]n 'ic ]e ui an1 ]i]e ae:1eady conncctcd to .:c1 otc, thc PE]i Satcmct Inay bc uscd to a1te the popeties o{ the cnecjon, at1ough ]n 1:(rjcc on]y thc BLN(= 1a.nd Soei1cs Rc=) va1ucs ca bc chagcd in this $,ay. Tlc otan Standad does o spccif}' thc li1e posjtio 'hen an er'rsting scqltr]tia] Ji] opencd. _{1hugh n1ost pa1,ig sStns beha1,'e Sen5jb1y' in potab1 sofwae a RE?ai\D saenle shoud be uscd o ens]]rc hat the file jS el'ound bfoe yo ea1i. Th. gcnca] 1'n o{ tn. 0E Statemen is jusl: oPEN( corrol'l'J, ) The con,rol'lisl ca conain a of thc fo11oa.jng ies in ay de:
oNI=integer ePrcSsin spccics he /o rlnit ]lrbc \1ich mSt bc Zcro o above; he ppc lini is systcm dependcnt, ylr]c,i1],' 99 255. Thc uni jd.ntifi nrrst a]',vays be gin, thcc js no dcfau1t va,lue.
STATS=chrcter express,n dScibS
,

o spccjt]cS hc Ji]c

sats. T}e val!c must

be one fi

OLD'

Tc

',EH'

,SCRATC'
,

Tc cffect is SStern-depeden, bu usaly means ha al old fle wjll b scd if one exists. othewise a n11 fi]e ill be creaed. js Thc dcfau1 :1uc 'U1i0i{', b i is isc t mj the SATUS kc-11,od bccasc te cflect of 'U]i(Jol.iN' is so i-deIicd.
UN0I,IN

js1, a n(]w f]c is e]aed. -{ rlnn:mcd cmpay 1ile is ceaedi i iS de1ted \he thc pogan1 crjtS.

fi1c
fi1e

ms is.

The

s o arcad c

auomar]ca]lj'

'

FL- cha ( l.e'pcsJion sp.ciJics t he ]ile n a m . (bn1 a}, t a]]] ng b]an ks 1 i]] b,r ignoed). Thc forms of ire icccpta]r1c ae sysrcm dpcdcnt: a cmp1cc ]itc Spccilicajo1 on somc opcating'ile sStcls may includ hc dcic, se nIe, direcoy pal, 1ilc typc \rsion nmlrc ctc. and may equje ,a1js Puctuatj maks to separate hsc. n portab1e sttwae, lee he amc ]las to be 2"cccpt:r.blc t a va]cty f pcating Systems] slor' and simple ames shoud be uscd. ieaivc]y thc FE= ideniiic1 nay be a claac l'aiabLe ( aray elene) so that the rrse ca1 c1oose i i]e nae a lun ti]nc. Thee iS dea] fo he fi]e-Iac so one Shou]d b spccifi.d in a c;scs n]css STTUS = ' SCRATCH ' in hich case he ]e mst not be naned. ccESS=.dra.t
eJpr.ssio

specifies ]lc fi]c access

ehod. 'e a1e nay bc cihcr:

'SEQUEA' ,DRECT'

a seqeniia] ]c: th]s iS the defau1t. a dicct access ]iei in ]js casc hc REc= kcylod ]s ilso eede.

Fa=..tamc|.r epressil,n speci1]s ihc cod

{o. Thc atue may be eihe:

10

PUT/oUPUT IACLS

100

'UNIRMATTED, the

'FORMTTED'

the defalt { a scqlentia,l i1c.


defarr]t {or :' diect-acc]Ss f].

RcL=inte!]eT'epress'ion spccjics

le ecod 1engh. This ist be g1ven ol a direc access fi1c but not oticv]se. The recod-length iS meased it ca.i'ctes o a forinattcd fite. bt iS in sysen-dependet unjts (ften numeric stoagc nis) lo an unfornattcd file

L^=chrcter explession Specilies ho$. ctbcdded and tii]jng b]aks in nmeica1 ]nput ]ie]ds of formatcd fi1cs arc o be tea,ted (in thc absencc of plicj fomat descipts B o Bz). 1'he l'a1c ay b eihe;

']ilUL, 'zRo'

bla,nks teated as u]ls, i-ebans eaed aS zcos.

igoed: t}e deau]t.


a,]

The dcfaul value is ikely to bc thc scnsibe clo]cc in


SAT=i1'tescr-riabe (o aray e1ement) etns

cascs.

0E] Siatent. This \,]]t be zeo SySe_depedent poSit jve 1,a,1e.


the event f an e1.

te / Sta.tus code aft. execlltion of h if no cro has occu1ed. othe$.ise i wj cur a


unj in

ERR=ll

ta.nsfas contro] to te labc11cd cxctbe statcmenl jn the same pogam

10.14

cLs Statement

Thc cSE stai.ent is used to c1se ; 1i]e and bca ]is connection o a unit. The unit and h filc (i it sti ensts) ae th fee fo c Se jn i'ny \ray. f the specifid ani iS nt con ected to a i]e the Stat.mni has no eilect. The generat fom of the satcten iS: cLoS( control ist ) vhee t conrml lisl may cona"i th1r fo]1o{ing iems:
1T=integer epression specjfies

tc

unjt nmbe o closc (the same

a.s

in he EN stemnt).

STA\JS=ChaceT'epression spcc-ifies rhe status

ofthc {i]e aJte closnlc. Te cpcssion must he a va,]e of ejtie: ,](EE, o the li1c t be prescrvcd, o ,DELETE, fo thlr i]e t bc de1ctcd i'fte c]ose. 'hc dcfah is STUS=JEEP, except for ]i]es openci witt STATUS- J ScRTc] l : slch fi1cs ac Jvys deeed aftc c]osue and STATS=,(EE,is not pemjttd.

aST^T=integer'r1ble and ERR=lel are both penjtt.d, i's in thc 0EN Siatemlrnt (but not mcl can g .rog vih a closE statcmcnt).

10.15 NQUREstatement
Thc ]QURE statemet ca] bc nsed in s'o sglt1y djffc..nl oms: QURE(UT= integer' exprs sion, inE'ire' i5 ) NQURE(FE= cm chaaccI expessionj inquic ]st ) Te fist folm, an iqie by unit, ctuns info1ma'io bout thc lnjt a]d. if it jS connecied t a fL]e, abou the lile as ,e11. f it 1S noi connccted io a fie th 1nos of the a.lgmcnts a,j bc ndcfilcd or rcrl a. va.]uc f ,UNroJ, as a,ppopiatc. T1rc sccnd lbIn, inqulrc by 1i1, can atways bc uscd o ]itd out whcthcr a amed file cxSs. j.' .an be opcncd hy a Forta ploga. Ay taj[g btanks jn th chaacte cxpsion alc

10

P]/o]''PT t|ACt't'TS

101

igocd, and hc fos offi1c nae :cccptab1c a.l. aS ]n hc E], sta]lc]t, SySt.]n (]cpdet1. f tc filc cxists :nd is concccd to u]t n rllch m., irrfoatio]1 catr bc obra]ncd. Tile inquic ]n may conta]n a) f the icms lrc]ol. Noc that al] of thcm (.xccp fo ERR=1abe1) ctun jnfoajon by assigning a ale o a namcd va]ahlc (r aay ol]n]. c nomal ]S of a.Ssigrrmcnt stacrcnis app]y. s that So thai .iaadc is ra hae an"v rasoab1c ]ength $i]] cun : vale whjch ]S paddcd out \jh blanks its dec1aed ]]gt1 jf asA1=int.ler'riable and ERR=l.il can bot1 be used fu thc same va), S jn OEN CLOS; note that th,]y deec oIs duing he cxecuion o, th NQURE Sacmct it5c1f, atd d not cflc]. he State of rh. fi1c o unjt q'hich is ]e slbject f th. iniy'
xS=ogic.l-IlariabeseS e ar]abc (o aa1'-e1cment) to 'TRU. j he Speci]ied unj o fi]e ejrisS, . LS ' if jr docs n' ,{ nj eJStS i, jt la.s a. llnbe i1 hc pe]tld age. A lile exiss if it can be used fu a OPN sinenent. A 1ie may appca ot o cxjs mce]y bcca.se the opeating sysem p1cvenis its us. fo1 examp]e bccasc a. p:ssvol'd is ncdod o because Somc othc cr 1ras alrcad ocncd jt.
]PD=logica nrible sets rho l,,iab]

conncct.d o a li]e (o

uj) i

'RUEhe pogam-

to

jf the speci]ied ur]t (r fi1c) iS cuIntly


a.

L'R=inteser'Tibl reuns h unit othewis it beconcs undenned.

nbc f

ilc

\hich is

coeced o e

,'jab]ei

lA=chrcter ,ar;a1e

becomes deIined. n the case an speciflcd ig FE= (because a dev]ce+a,e o djectoy pith iy hae been added)

lcins thc

fi]c namc

o thc v:]a]]e if tle file has a namei iE oi ]i iquje by file t1re namc nr.' no Jc hc si'c a.5 ha

thc namc ctned

v]11

a],ays be sujablc f1se

an oPEN statcm.t.

ccESS=./l,l.r ] ,1arle cuns t1c cod iccess ncd. ejthc , SEQET]AL, o ,DREcJ i the i1e iS conncctcdi jf it iS nt conncctcd tc var'ii]"ble becomcs undcnncd.
sEQuTL=c.jlcr'?riole iuns

'N0' if i canno. and

'U(N' ohewise.

'ES' jf the fi]e can bc opced

sequial access,

DRcT=.ra.fr ,.lribl cturns 'ES' jf t]re li1e ca be opcnd o diec ccess, ,0, jf canot. and'UN(NliN' ohe..ise'
F|l11=charcer'riabl 'UNIRMATTED' i

il:

ens 'FRMTED' jf the fl]e is cectcd fo fonatted accSs. i jS co lected for lnfmtcd :cccgs. o becomes undelied if thec js
]ar1le

no contcijon.

0BMTTED=.aa.e

o'UNNoJ' othc,isc.

lctulns 'ES' if fomatted access is pemitcd, '10' if it is not,

UNFR!,1TTED=chiace

runs 'aiable no. o 'UN[0i.JN' tcl'isc.

'Es'

jf nformi'ted access iS pemid'

'N!'

]f 1 is

RcL=inte9r'r'ibe etns thc ccod lcngth ]f he fi1 iS coneced fo diloci acccss brrt bccnes unde1incd olc1ise. ]'{ote hat the units ae chalactcrs fo formattd fies' but aIc system_dcpcndcn fol unoaed n]cs.

PU/9UTPUT FACLS

102

NETREc=inre,e-rriile

etuns a numbc which is one highe ha'n thc asi recod ead or w]tten if the li1e is conncctcd f dicci ;ccess. f ji is connected fo di.ct ,.ccess bu1j no records 1ae been aSfced, ihc va] able re uns onc. t e file is not conncctcd fo dicct acccss thc 1'a]ab1 becomes nde1ined.
1

L!.N= ch0'lce-|ori] rle

i'ccording o h Wa}, beome, ndtEned.


RED

elu s

' o ' BtI]( ' if thc fite is connect ed fo fr al ed access embedded and ing b]anS :c to be reaed. n othcr cases it
'

NULL

10.16

and

,/R]TE

Statments

'-

The READ Statement eads infomatjon fIom ne ol moe crds on a Jie into a jst o{ 12.]ib]es. aray e1ements, ctc. T1c I{RTE statment writes infomatjon m a is of items which nay inc1udc vaiab]cs. aays, nd expIessios and poduccs one ol more ecds on a. ite. Each RED o ]RTE staee1 can on]y ansfe one ecord on an ufomattrd i1c bt on formattcd fites. 1]c]rding internal iles, moc than nc .cod la"y be tasfercd. dependig n thc contens of ihc fomat Specificat]on. The 1o saeents ae the Sam geealfom: RAD( contro list ) tlt ist ]R1T( contr ist ) .1'1t0 ist The .onrrol'lisf us conii a nit identifie; thc oth. ieS may be optiona] depending on he ype ot ]i]e. The dr'ist is a]so optia: if i iS absent he Statemcnt ta.nsres oe ecod (or possiby oe unde the conto1 of a fomat Spcci]icain)'

Unit dentiie
This may lave any of the fowing forms: NT- itteJer-epres9ion The value of te expessin mus be zeo o gca.tc ind mlst cfc to a valid /o unil.
U],T-*

o he Sandad pe connected input o ottput


1'he

fi1c.

Ul,T='ntena]5l
],ote 1lst.

,.'o1

iteral
,0
:l

1i1c

may be a laia.b1c, ara}, eicen. Sbstfug. o aJa ftype

that the

key11,od UNT= js

optioa,] ]f the unit

idctjic is ihe

1is iem jn the cnto

Frmat dentitrer
oat idntjlie st be povided $,he silg a formatcd (or incrna.1) fil bu not oihcwise. t ay havc any of the f1lol.ing forms:
FMT=lrel The ]abcl f RMAT statemcn in thc aamc pogam l,{=lorna, Thc foma.t may bc a c1aact foa. spccif]cation (Scctin 10.6 ).

it.
coai
ig a cmp1etc

expcssir o cha.actcl ariy

MT=* Fo ]St diected ,ona.ttig (Section 10.i0).

Noc ha thc k.vwod FMT= is als optiona i }e fomat identifi iS the sccond itcm in tc conh'oll]St ad t1tc fiSt icm G a i iilcl spe.i1ied ihou is kcy\od'

10

NP

LT

/oUP]1'

'-ACl |'TDS

03

Recd Number
A ccold n1bc. identijic musi bc rvked fo dicct acccss ics t]u o o]cisc. t has ih
REc=itcge'Prcssion Thc ecd nmbcr nusl bc gcate han zclo; fo RED it
mus1.

cfc to a ccod

ljch

eiss.

Eor and End-of-fie dentifies


Thcs ma. bc povided in any combjnat]on, bui o, r c_'r_J re. Se. 0 5 r mo c j_ oa l , END-1abe1
ERR=}ab1
E]D=1abc1 iS

on] va]jd wh,r eading a scqueia]

ISTT=inte8e-vaiab1e
The da is of a RED Statemet may colain laiab]es. a.ay c1cincn1s, char'acij sbsjngs, o compete arays f any data ty,r. ,.n aray'name $.jtho!r sbscipS epeses aJ1 t1t e]elents of thr aa.i ti]s is not pcmittcd f assmed sizc duy aguets in pcedues (bccause ih aIay sje iS indeteinae). Thc st ma| a.lso otain imp[cd D 1oops (cxp]a]nrd

hc daa 1ist of a. ,RE si'cmcnt may contain any fhc iicms pemjtted in a RD saeeni addil cxpressions t ay dti iypc. s in :tl /o satenrets, expss]ons must not lcnsees fuvo]e tie exccutio of othe 'i o sac]ens.
and ]n

mpied D-oops
The simplest and nSt cficjcnt ay to ead o wite aJ thc c]cmcS of an aay is pu i, namc, u1slbsciped, in the daa_transe Ls. n case f a ltj dimnsional aay he .leeIs wil] be ransferrcd in he noa] Soage sequnce, wirh re fs1, s1bscrp .J]18
]11ost

1oop a.lo\s ihe c]cmcnts to bc ta.nsfccd scleci'ely or in soe on-standad odc. Thc nrcs fo it implied'Do ae sii:rr lo ai of odinay D ]oop brrt thc lop folms a sing]e itn iI he data-aSfe jst and is eclsed by a pai f pacntlcscs athc1 than by D0

apid1y. ,{n imptid

Do

.'d C0NTTNUEs." 1

lo'"xa',.r.:

READ(rl,IT=*, FMT-*) (ARRY(), = MN, 1)

15
,4.

WR1TE(NT=*, FMT=15) (,

FRMAT(1x, 6

dim:nsina] al:y.in be pjned o1rt jn a.ianspscd fo. The nex ex:mp]c or1tp1tis an arlav (100,5) bu $,ih 5 e]ments a,coss and 100 [nes vetica:

lj

'

2F12.3)

x(l{), (l,1),

M=1,101,5)

,IRTE(UNT=*, MT-s)

(,=1,5),
(

FoRMT(1,'NE" 510, 100(/,1x,14, 5F10.2))

(L, (L, ) , =1,5) ,=1,100)

'hc fist oop lritcs headjgs fo t flve coumns, len re double 1op wits a ie'nbe for each [ne fo11owed by fivc array elenens. Notc that thc pajcnhcss vc to bc atchcd ad thit i co]1tna js nceded ac1 the jnne igpacnthcsjs s]nca he iner op is jr]s an itcm in the list cotaicd jn the outc ]oop.

11

DT

sT']l/r'T

10l

Thc implJed D loop hs he geteal fom: ( dat-ist oop'1)ribLe = start' imit' s|ep ) wee te ules o the strt, l1'r?ii, and sep alncs o exactly aS in an odinav D stacmcnt. T\e loo arible (norma]ly a] i eg) may bc scd ']t]lirr the daia-ist and this tist mv, in tur. iIclude fler cople impJid Do Jists. f:n c1o. o cnd of fi] conditit o:crs il an imped D_loop tcn rhe ]op_conto1 vaiab]e wi be ude]ied on exii t]is means that an e1p]icit D0 1op is eqiled to ca.d an ]de]injtc 1 of data ecods and cx]t $,jh o\l,icdgc of ' m:n ]es we actual] inpu.

10.17

RWND

and BCKSPACE Statements

These fi]e_positjoning Statenenis may on1y bc scd on exea,] Sequent]a.] fi]esl inSt systcS i[ estjct hem t fi1cs strcd on sitab]c peiphea] dvjces such as discs o tapes. REl,l]D eposijons a 1ie o t1c beginning of infomation so that th nct RED siatemcnt wj ead tie fist ecod; if a ,RTE Statcmcn rrsed afrel RE,IND all cxisting records on thc 1ile ae desoyed. Rj{D las no felr if thc fi1c iS a]ca.d], r\otnd. f a REIiIID staeent is us.d o a uni ,hich conlectd bt dcs n cxist (c'g. : prc conected output flle) i cleats the
lile. Bc(SAcE mves the i]e posijon back b"v e ecod so ha, the ecod can ba e ed o ove_1ittel. T]e js no effcct if hc fi]c ]s a.haa.]y posjioned ai thc bcg]nnjng f in{ma.tion but j iS an cro to bac Spacc a. filc'\.n]c} does no e-ts' t is a]S illega" o back space ov rccods ,ittcn b!' ]]si dje(ed fomattig (becaus thc n1nbe of rcods produced each tinc ]s s),s1{1 dcpenden)- ,{ fc.opeating systcns find ] diIiclt t implcmen he BACSPACE saIcn dic]y and actuay nanagc i ony bv cv]dng he fie atd spac]g fo$,aJd t the appropjaic rccord. i is someines possib] to aojd backspaciIg a fi1c ]ry aocijg bfics \irin rc pogarn id. fo a foad ji1e, using an intcrnal ille RED ad WRTE satemcnts. hcsc statc1]ns havc sii]: g.neli] otmsj REl.llND( conr?/ lisi ) Bc(ScE( Cnho ]is ) hee he conlr,1'l'sl ay contan:

UT=intege-ex!ression 0STT=integer-variab1e
ERR=1ab1

Thc un]t idcntilic is compSy, thc thcS optiona1. f on]y the njt identifi. is lsed he (f compatjbi1]ty ith 'otan6j) :n abhr'ej:tcd fm of te Jjamcnt js pcrnitcd:
RF-\:]

ACSP

1D cg e - c ? c s s i o 1 A.c inc' c cp Tes s i o11


; 7
1

hee he ]nie8e ]pcssin

jdcntifis hc unjt

nbc'

1L
Tic

DATA

Statement

DATA stacmcnt iS Scd io spccjfy initia] aiucs fo viabls iId iay e]c}cnis' Tc D statcmt iS non_cxecutable, bt i] a ma]n pogam unit it as thc si]e eflct aS a sct ot assignlcnt Statets at the ry bcginning of tlrc prograln. Ths in a rain poga a DT

satc]1ln like hjsi


DT

ES/625/, lREQ/50. /, ME/'AL'/

DT

.S1TEME]

105

cod ep]acc scvea,l assignmen s1anljrs: LES = 625 FREQ - 5.0

AIE =,Lj
'1js is noc colvenierr, espcci.l]y l]cn jnijalisjng alaysj and cfiicicni, sfu]e hc 1o iS donc e thc program is oaded. n ; pocedulc, iovc, h.S] t\o nlcthods ac ni cquial]1. especia1ly l he caso oitems thic1 ate rodificd as thcpoccdue excutes. A DT statcmcnt only ss 1hc v:i]lrcs oncc at 1llc sar fcxccutiol, whcreas assignn Siaicn.rrs wil] do so ever tjmc th pocedue js caed. t iS jmpotant t dist]nguish b.twcn lc DAT a.nd AR}1ETER stateeliS. heDT saire eely speci]ies an initia1 ,alue fo a laiab1e (o aay) \,lich ay be:]led drig ]e cosc o{ cj{.clion. T]e PRMETER slaenen specifics valucs fo consans ,]jch canno b changcd \ithot rccompiling he pogrm. f, howeve' you need a :av of.onsits] f n{ic hcc js n.r dijt suppot in btan. yo shod use ali oldin:ry ay wih a DAT saemen to iniialis. its clem.ns (and tae ca not to coupt he cn1nts awads)'

11.1 Defined and Undeffned Yalues


Thc vallre of each valia.bc and i"a, clcrncni is unde:d at the stat f cxocuj. n]css i has bcn niijased wit] a D]\T sicmcnt. n undcincd va]ue nay or,1y bc used il erecuabc slaeneS i il.Js 4riclr causc it to becone dcfincd. r\ itcr ca become dc1ined by is se i any of thc foo.nrg vays:

on the 1eft_had sidc

.rf an

assigncnt s2.cmenl,

.
.

aS hc cono] vaJiab1e of a D Statcmcn.

', |'p

. . . .

'

, nL 'a'4 l '.

as h jnenal fi1c

idct]fi. of a IRTE stacncni,


an

is he

/o slaS idcntjfic il

/o

Stacmcnt,

in

a.n NQURE

saenent xcep

as file

ui rrbe,

in a pcedue ca proided ha he coresponding dumn argmcnt is dcfincd bfoc te pocede ctuns cnr1.

use ofundefined

must ni be 1sed in any ohe 1'av. Es cilScd by thc indeicn va]cs c c:sy l make and Sometimes hac vc] obscu] eecs. is inpoin, heetoe, o identify eery item lrich needs o be iIiitlised and pr,idc a sitab. sc of DATA

,{ uldefied vaiable

roden opeainB Systems often cea th aea of eoy into \'hich thcy ]ad a pogam to pe]t unarrthojzcd a.cccss t hlr dta scd n thc prcccdilg.job. A few opatinB systems pcsct thci ncmory to i bi piteI whic} coIcsponds t an iegal nmcjcal a1uel this js a ey lrelpu} diagnosjc facity shce 1'henever an defucd ,aibl is sed in i, yplsj jt geeates an e at un tjr.- othc s]rstcms mcc1v sct l1ci nemo o zeo: hjs akes j oe diicl o ick dwn hc usc of undeficd vaiablcs aild r1ey i oly coe o ]iglt whcn a pogra is lr'anspoled to anothe syste. :o c1 on ndeji ed and aals ';jab]cs js hal'ing an iliial vaue f zero to leave hc pograr conpleely a thc mccy f c1ranges to hc opeaing sstcm.

l]

DTA

S,1TMEN?

]6

11.2 nitialising

Variabes
o{ a

Thc simplsr folrn of tc DA stieme1 consists by a. cosan eIc]osed in a pai of slashes:


DUBIE PRECs01 EP0cH

ist of

1.he 1,aiab1c

na.mes ea,ch fol]we]

Lccl

ENED

cARCTER NFEx20 DT EPCH/1950. 0D0/, PEI,ED/. TRUE.

/,

NFLE/,B : 0BS. DT, /

Noc thai DAT stitcIcnts mus o]low a] specilication statenens. ,{n atenatjc foIm js gie to a comp]ee ist o naes can be giel 1is ald f11owed by a sepaatc ]ist of consants:
DT EPoCH, NED,

NiILE

1950.D0, .TRE., 'B:0BS.DlT'/

._

\hcn tee a manv itcms t be jnjti:ised i is a mattcr of tase whthc to Sa 6eea] DT siiiemeis o to 1se one wit any coltinai]on 1iles. t is, f ousc, i]lgal io hav thc Same nae appeajn8 1'ice. Characte variab1es can be initialjscd jn scct]ons us]ng he substing notaio i this iS o.e
co1venien:

c{RcTER*52 LETTER DT LETTER( 1:26) / ' BcnEFG

J(L],{11PQ

RSTUvwxYZ

LETTER(27:) /'abcdefghijk11opqrstuvrxyz,/

'

1e lngth f he chaactc constant d]ffcs lom la f ihc varii'b]e hen the stjng is i,'ncaed o padded \,ith blanks :.s in an ass]gnren Statemcnt. Te ype.on1-cs]on r]es { assignmcn sitcmcnls i]so app]}. o aithmetic items in DTA statemcntS.

'

11.3 nitialising Arrays


Ticc ac
seveal lir),s of using ,ATA statments to in]tiaisc arays. al1 of ticm simper ad m. cfi]cicnt han lhc cqivalen sei of D ]ops. Pehaps t1c mos cono equiemcnt js o ]n]tia.]]sc a]1 rhc alcmcnts f an aiy: i his case ]le aay natnc ca.n app.a1 wihot SbScipts. f seea of he e]ements ae o 1ave he 6ae jnjtia ,,'auc a, pcai cu1 caI bc pccdc aiy onstantI

RE FU(1000) DT FUx / 512*0.0, 488x-1. /

Thc toa] nmlrc of constaxts mr1si cqnal c lrurbe { ara c1cmcnts. The consians coespond to thlr c]emcnts jl thc aay in thc non:l soag sequcncc, that ]S iih he fist SbSc1pt vaving nost ap]d1y. Namcd constinls lr.1c p.n1id, bu no onsan expcssjcrns. Tic opea couni ay bc ]irjea o n:ned inege cons1an. To iiia.lise a ntdnnclSjonal a.y \jih paanctcisd ara bounds it iS nccessa,y to dfinc anoi1c inic8c consta o hod the tota1 numbcl of
ecncts:
PRI.{ETER (Nx = 80c), NY =

DoUBLE PREc]sO SCREE}J(NX',Y), ZERO PARMETEB (ZR = !] . c)D ) DTA SCREI / TTL * ER /

360, T0 = N *

NY)

1]

DT sT.4',l',rNT

107

lf n]v a tel\, aray c].mcnts ae to bc iitja]iscd hc ca lrc ]isd fudi]dualll: RL SPARSE(5,5o)


DT

'lic iid.

SARSE(1,1), SRSE(50,5)

/ 1.0'

99.99999 /
ir

nuc1r t1rc samc vay as an irnp]icd

ird os conp]icirtcd. ]t iS to use an irnplied Do loop. This operaes Do n a /o sateent:

NTEGER oDD(1o) DT (DD(]),=1,1l]'2)/ s * 43/ DT (ODD(),=2.1.2)/ 5 * a /

This cxamplc has jnit]a]ised a odd nmbclcd ccnens o onc a,lue and a]1 c ccn nunbccd ccmcnts to a]the. Noe hai thc lop conol vaiab]e ( in ]is cxane) Las a scope ,hicil docs nl extcnd utsidc t1 sct]on of he DT Statcmcnt ]n w1t]c1t jt js Scd' Any jnteg aiable may be used is : loop cnto1 fudx ]n : DT saement $,,jhoul cffocis c1sci,hcc; thc va]uc of itsclf is o deined by hes saements' Whc initja.1ising pa ol:. nru1ti'dimensiona] aa it may occilsio aly bc uscf] to .s D0 ]ops jke his;
DOUBLE RECS0

DATA

((FELD(,J),=1,J), J=1'5)

iELD(5,5)

15 * -1.D0 /

ThiS spcci1ics ]n]iia1 va1cs on1y fo tle uppe ingl] of he Squae aray FELD.

11.4

DAT

staternents in Pocedues
DT statemens peorr] a llc fT

wh]c assigninen Siatene1s ae no subsile. oftcn nccessiy o i;ngc f Somr actjon to be caicd ou a he sa i)I c fl9 ci] bl]t not sbscqe]y, such ir.s opning a fi]c ol jitja]jng a aiable ot a.ay vrich accuuaes jifomaio duinB stbsec1uent cas. f intomaio is peserved in a oca aj:ble o1 aiy fom onc i]vcation t anote a SvE saicmnt (descibed ]n Sec]o1 9.11) is also nccdcd. ndccd, i general any object jniiaised nl a DT statemnt in a proccdrc a.1so needs o b named jn a SvE staicmcnt n]l]ss ]tS alrrc
n poceds,

t jS qrjc

neve ated.

h the next example thc poccdre opes a data lc orr is 1ist cal1, using a 1ogica aiable OP]'ED to remembc he sie f thc i1c.
SUBRUTNE L0oKP(DEx. REcRD) ]NTEGER NDx

REL REciJ
SAVE 0PE1]D D oPENED

LGIcAL PENED
*0n

.FLSE. / fist ca11 OEED is fa1se so open the fi1. F(.NT. oPENED) TlEi oEN(U1iT=57, FLE=' 1DDEN. DT,, STATUS=, OLD,, ccESS=lDREcT, , REc-10) $ PE,ED = .TRU. ED F
RED(UT-57, REc=NDx) REcORD
E\D

12 Co\fN

r'C|{S

1n8

}e, fo S]mp]ic]tl', th. /o nJ numbe is a ]itca coi]Sant. Thc po.ed 1vo]d b] mor d]ar if } ui nLber ,ee a,lso an algumcnt of the poceduc o if ii cota.in.rd soc cod. rSjng hc NQUR saleei. detem]ne fo jtstf a suiab1 unsd ni nub. Tnetc ts. f coursc' lo corcsponding \ a o 1eemtc 1vich is ihe ]isi caJ1 he plocedtc So tiat tic fi]c c;n be closd, bu ilis js o stjct1], ncccss.y as h lotan Syster oss al]

o'og|a1| n(: ote that DT.q Statccnts cannot 'c usd to inijas varia.blcs or ra"ys rich ar drrny agumcnts of a. poccdrrrc, no le aiable wici has thc samc nne aS he functi.
ot,

'. ,

" "1J, | i4
Ru]es

11.5 Geneal
l

g. nlal . "nD'.ol", ""' '' /' DlA"".//''''/'']''!/ '' \1ee nl'.diS aist of ftiab1c na.s' inlay nnes. substing lames, and jmpcd Do iss, and clis, ]S a iS of ]tcls lvhjch a}, e itea or a,ed consa.ns ol' eii,he of these recedect by a rpeat_cou]t ad ar astrjsl. T1rc pai cotn cn a]so b an nsjgned intcgc cnsiant o
The cona vhich pecdes cach 1ist of namcs ]xcept ti fiSt ]S optjoniil. imp1Jd Do gceal fo1: ( Llist, intr = st't, ini' itep ) \ill.c . dis is a Jist of npLed-Do Jists ard aray e]eents; inr js an lnegr laiab]e caled he loop_cltr aiablc; srdr'l, limit, afu ste}) ?\lc jntcge expess]otS in \h]ch a] thc opeads mus be intge consants or ]oop cono] !a]ab1cs of oue npcd Do liss. DAT statements ca.ot lre Scd to in]ialise ieS ]n tc blir,k conmol b1ockl ies il named common blocks cin oI]y be jitjaisd within a BLc{ DTA pgam li (see Scctin 12.1). Thc DATA Statcmcnts in cach pgam rrjt mrrst fot]w a]1 Spcci1icaiio Siatcmcnts b tlc caI b inteSpeSed ''1ii1 eecuab]c stacerS and statcme uncio statclnes. t is, ]ro\v_ e!er, best to fo]lo. t1c usra1 pl:.icc of pulig a.1 DAT-q siiements bcfoe a! of thc cxe ciab1c Sta.icm.ts.
1jst has t1

12

Common Bcks

i ljs of viiab]s ald ara"vs stoed n a nancd ea ivhich 11ay bc accc.rsed dirct1y in mo han one pogam ujt. Commol b]ocks ae ain1y scd to tansler iImatin fom oe pgam unit to anotlc; thcr can bc lScd i1 as an ilenatie to a.gul.nt is aSfcS o l addiio to '. Cono blocks ae soeies used o it lagc prgams ino sna compcls by a angng {r' scvcal pogl nis to shic a cornon poo1 o{ mcmov. Th]s jS no a ccommended pogl:ming pliclicc and js lik]ly o becole redundant \vj lhc spcid of vitra mcmoy

A common block js

op1rat]ng SyStc]1}S.

g]oba1 n,mcs. such as hosc of

socd 11ith th,] boc]i cao be jnjt]aiscd jn t1r nrmal,;y. unii n hich q,a,s 'eied spcciay f this ppos'

Thc nanc of a comon b1ck iS an c.n:l nac r]ic ust ]rc d]ff..n tlom a1 othc poccdrcs. in ti. cxc.i:'bk,pga. hc vai:bles i d aays

onlJ in a BLc]( DT plogam

]2

C\,'t\'oN BL}CS

i09

12.1 Using Common Bocks


n ms cascs bcsr va}' o pass itfomatio tom olc p.ar ui o anothr iS l. sc hc pocrlu agu]cr jst meclanisn. h]s pcs]!S tic odu1ai]' ad indcpcrll1eIcc f ocedurcs as ch as possibtc. gumcn ]iss ie, 1owcv., k]ss Sitjsfacto}' in : goup of poccdus fojng a packgc whi.]l :vc o s:e ; ]agc amoun of infoma.ion \ih ac othc. occdc alI ]iss h{ end o b conrc 1olg. cubeslnlc. and ven ieflic].ntf is package of plordures is inended o gena,] se it ]s l1uit i1pan o keep the crtca] futcfrce aS nconpicatd as posslb1e. This ca bc cied by sig tre poccduc:gureni ]iss ol11' for impor f ilfrmaiol fom and cxpo o 1c csr o h prgram and handling he cojn m uniciios b.iwc.n onc proccdre il he pacag.:nd aot. lih cornmon lr1l:,cks. Th usc is ihen {rce.t ]gnole h,r i enal v]ijngs of ie pacagc. F examp1c, in a snnplc packagc t nand]c a. pen pot you may /an povide shptc poccdle ca]1s suc asi

cL cLt

set hc Scaling 1cto . ]'{OvE(x,) \,e he pen to posit]n (X,Y) cLL DR,l(x,Y) Dar. a 1]e fom hc lasl cn posiion to

PIoEN scLE()

iliase

he p1otting device

(}a

Y).

These pocedrcs clea1y 1avc o pass inflnaion {o1 nc o aothcr abou he cent pcn positin, Scaling acto, ct.. -q suilablr comnon b1ock dcfiniio ighi too} ]lke ttris:
c0MM01i /LOT/ PENED, oRGN(2), Psct, L0GcL 0PEED
Ul4

RE ScA' RGIN SvE /P/


Thcsc spcci]icatj sticnentS wuld bc nccdcd il each pccde in

NEGER

UMPEN

ii.

packae.

Common Block Names ogan


comon blc b qoting is nae in a cMo statcert. corJon bock namcs alc alays eIc]osed in a pa] ols1ashcs and ca, only be scd in c,{Mo nd SvE Statcmcns. The co]11non bock itself a"s n data type ad aS a. g]ba] ae wijch nust bc dis]nc om thc namcs of:1l pogam units. Te namc sho1d i].]So be djstici
a11

u1i ca.n access the concns of

ay

from

m;ke use of a.n1' nunber of dil1ercnt commn blocks. Thee is ;lso a specia1 b]ank ol naned connn block wi unique pctics \}icn ac coeed jn Sccijon 2.2 be1\. T}c a iab1es ad i'ays w]thin a comron block do t havc a.ny g1obal stats: thc]' ae associatd with ]cns in b1cks lrca]ng thc samc nae j thcr pogam njts on]v bv hej posiion \vjthi rhe b1ocli. Thrrs, if in one progam nit spci:fies:
CoMMoN /OBUS/

locl amcs in cich pogam nits whici i.ccss the blck. Eac} pogam unit ca

(3)

ad in

anothc:

c01M0rI

/oBTUSE/

, B,

c. Thc

hen' assir1g hc dn1a lypes c hc samcl \(1) coresotds o,{, (2) to B, ad \(:]) r cMt1ON statenents hcc ic e]ectielv Seithg p dieen ancs o a]iascs f tc Siro

12

Col\'ll B'cS

I10

the coespoding itcms havc t } e sa me da.a ype. f thcy do not. w1cn one item becmcs dcincd a]l imes fo Le sane ]caion w]c1 havc a diflee data t]rpe becom undefined. Thce is one ino ej.ception to this u1c: infolnat]on ma,y be tansfced fom a coptex vaia.b1c (o aay elemen) o t1\,o aiib]es of type aJ (o v]cc vcsa,) since thcsc ae direct1y associa"ed ih its ea] ad inaginary pats' Usua1ly it is nccessi'y o aange o coesponding itcms to have idntica] data ypesi it also minjnjses confsion if the samc symbolic ams a1e used as wcl1' The simptest wa to ac1ievc his js to se an NCLUDE Statcment, ifyour syste providcs ne. Tre inc]de_fi]e should cntain lot nly the c0}1M0N statement bt a1so a th a.Ssociated type and SvE sateents which ae necessay. t is, of cuse, Stj] neccssay to rccompj]e evey pIogim nit wijch ccesses thc omml b1oct whenev ts de]iiin jS alteed Sjniicai1l1,.

Sct ofnemory ]ocatjots. The data iypes do not hae t mach pvided th ovca]] ength js th 6ane] but jt iS geneaJ1], on1], possjble o ransfe inf.'ma.tion fom ona pogam nit to anoh if

Dec}aing Aays
T1te bounds o an aray can be dec1a.rcd ]n the coMN statemcnt DMNS1o staicmcnt, bt on1v in ne o hem. Thus: c1}1 /DEMo/ ARRAY(500) Do]EE RECS0N RRY

jse o in a scpaae

,yp

js e-.aci]y equia]ent toI


cM}10}

DUBL PRECs}i RRA(500)

/rE}10/ ARR

DoELE REcS0 RR
D},1ES0 RR(5000)

CMMON /DEMO/ ARR

but he vebosity of ihe

tird

om has [tt]e to ecmmcnd it.

Data Types
The omai daa ype es app1y to vaiablcs and a.a"s in each comon bloc' ype $atement is not eqied i thc init]al 1cttcr ute wou]d 1avc thc cqlired flectl bt ype Statcmcnts arc advisablc, .spcja.]tv il he jnpLied lype 1cs ac anJ,hee aflectcd by MP]cT stateents. Type sems may pcede o loo$ thc cMi40N Statencnt' Simialy he lengt1rs of chaactc jtons sio1rld be specined in a sepaJate tyc stiiemen: thesc canno be specificd ]n thc cM}{, Statecnt'

stoage Units
Th lcgth of eich comon b]ock js measled in Soagc unjts, as dscibed in Sectin 5.1. summay, incgc, rca1, i'd logicil ieIns occlpy one nmcric Sloage unit each; conplex nd dube plecisjon icins occupy vo eich. To a"\imisc talrjt],, c}aa,cer stoagc unjts ae consideed icoInensuae \]h nneica] Stoage units. Fo th]S eason chaactc ani] nn chaaccr itcms cannot bc rnixcd in thc sac common bock.

12

(:O\'1o BLOCL|S

I11

pactice ihjs ofc mcans l: \o commo] b1ocks ac ecdcd o ]d a laicu]a data stuctc: on fo thc cha.actcr is ad c o a] hc lhcS. t. in . ]ist examp].. i had lcl eccssay fo thc pi8 pa(]kag. ro soc a plot ]lo this oul] avc ax:a il .
Spa.a].e Cm]on b1ock

sch

as:

cMM /0c/ TTE CARACTER TTlE*4

SvE /LTc/

is good pat]cc t usc clatcd .n.mcs l1 hc b]o:ks jnijcate hat hc chaace aid o ch:aclc iicms ].e uscd it conjttction. Thc lengh ot a namcd cnlon bLo& nrsi lrc lhc sao jn caci pIogin uIi jn 1hich ] appeas. obvious1y t1rc ca.sics \a o cnse ihis is ma]r thc colnon b1ok cntcnts identjca] iI each plogram un]. ]\o1], holee. tha hc is 1o cquin fo daa t]'pcs to al.h. o] fo t1cr o bc ljscd jn an}'pat]cu1ar dc, ovld.d rh. ies ac nri uscd fo infonjI tansfel. ind povjded thc ota.] lcngth ofhe b]o:k js e samc ]n eac case. 1ts ticsc cmnln b]cks ae bot 2000 nur.ical soage Ijs jIt ngth:
coMMoll /SAfi/ G(1000) DoUBLE PRECSO G
c0MM01 /SME/ A, REt A, R LGCL B

B, c,

R(1997)

NTEGR c
tems in a comol b1ock ae Ster in cs.cntjv. memoy 1caions. nfotunaie]y hcc a 1w copue SyStS 'hi]] eqie duble prccjs]on and corrplcx icms io c sed it een nuitbccd store 1ocations: isc }'lind i had to copc',t] b]ocks $1i. coniain a nuc of daa ypcs. \,achins with his detec can nearly a.]vays be pa.ca.tcd by angig fo al] doble prcc]sion ind cop]cx itcms io com he beginnilg of cach b1ock.

SvE Statements

and common Bocks

es in commn b]ocs y bece de]ind \hn a, pccdlle urns cnto1 to the ca]]hg un]t jst likc ]oca] vaiables and aays. T1is i not. \eve. occu ] th ca.sc o{ tt blank common b]ock no in any comnlon b]ock iS :lso declid jn a progan ni lhich is ige "hich up tic cucnt chait opocedue cas. Sjnce he majn poganl uIi js a,li.a}'s at the top ofhc cajn any cotrrmo b1c1 dcclarcd ]n 1c main gra.m can ve beconc rrdlincd jn tiis ,ay. n a]] he cases it ]s pudcn io usc slvE statcmcnS. The indjvidua, items in cmmon blcs calnoi bc ci]icd in a SAVE Statc.n, only ih cmmon bock ame itself. Thus:

SvE /SAi'1E/, /DEM/


fa. cnon btock is sacd in an}r pgam njt ic i us bc Sa1.cd in a]l ofhc. The SvE Siacmcn o!gh leefore to be inc]uded ith t1c coMM ad aisociatd type StatecntS if IicLDE sta.tcncns ae used. f the pogram is 1ater mdifi:d s that the comon bock iS also dcclarcd in thc ai pogam his \i]1 bing a Sv statemcnt into lhc rn:ir pog,'a uIi. bi although it the ]las o cec, jl docs harr.

12 CoMo LCS
Restrictions

112

pt'cdrc .i],nnoi be memhes of a onnon bloc no, ]n a fnction, aS s;ne nane as thc unct]on. Thee ac i]so some st;ict]ns oi thc usc of commn b]oc] icms aS acua,] aguments o prccdue cas bccase of hc possibil]ty of mu]ip1lr dcfiiion. Fo eamlle. if a poceduc is defined ic is:

ca thc v:iabc which

Te dmmy a,gumcnts of

SUBRUTE SL(Rc)
cMl1N

/BL0c(/ c1

,{nd he samc cmmon lr]ock ]s also used in he catling rrnit' w]th a comnn bock jicm as ]c actra] agunen, such as:
PRGRA}4 DUMi{Y

coMMll

/Btc/ v1LlF

cLt sL(VALUE)
Thc both,{RG and CoM rvihin 1i subouiinc sLY ire associatd with the Sanre ie1, V,{,E, and j is thc1be jt]cgal o ass]gn a, nc1\l va1ue t eithc oi ihcm.

12.2

B1ank Common Rlcks

Comnon b1ocks ac sometjm.s a]so useI t a(1uce the tta.l amoan f emv uslrd bv . oogla bJ,",a. g lo' l.|:). nlg% n l|j "._ h. ."., .r,l,j.' _ ' ..".,i'..'' j '.. di]'Lla , -.{J o'^,r.*.i..| l|ou. ' n" ln'p" l.."r_ Mosr otan systms pa.tc a Stagc a]toca.ion sysem hich is comp1etely staic: c;ch pogam nit ha.s i spaa.e aocation f memoy fo jts ]ocal aiab1cs and aays. sevcra plocedes eac1r need to USc largc aays ]rlcnal1y ih tota] aount of meloy ccupied by he pg:m may lrc tahe ];.ge' f ; Set of pocedes can be id.i1icd vEcn ae jlvke] in seqenca. athc than onc ca]ing a.no]te. jt may bc feasible to c{iuce he tota] mmo! aocatio by aangin8 fo them t shae a Stoage aea. ach \i11 use the sate common bock .p.... lo' l"ll',l ,-l " a ld }iaed common b]ocs ae requiled o al.e he Same tength i cach pogr.m it: i{ thcy a scd i iS necessiy to wok ou wh]c ot ncds he nost sto.age and pi'd orrt a1l the ohS o Sam. legth. An iltena.tie iS to the use thc special blank t un_named) connon block ]ich has he uscfl popty tha it may h:e a difleent 1egth ]n difient poeam uits. i o" , lr3 Jr .l1; .lo, ,""ln. .l p.lJ:

'o.o|

CMMON

//

DUMM(100)

and

anoh

c0l,1Ex SERES(512,512),
c0Ml.{N

//

SERES, StcE, EPECT

ScE(512).

ExPEcT(1o24)

Thc bt:nk commn btock as o othc specia popaics. Fist]y jt ci'nnot bc initialisc b], a iT Staient cvcn \iihin a BOCK DT plogam ]]it (bt l]js ni a scjols iitaion f a b]ock rrscd just { scat] stEag.). Second]y iems \ihfu tlc ballk cornol bto ..vc bcome dcfned as a rcsu] of a procedute cxi. Fo this ea.Son b]a.n conon hl. can]ot bc speciicd in a SvE Simen.

12

(|O{o 'ocKS
c0M0N

1l;1

12.3

Statement

pgam uni may cnta.jn any nunber of cl4MN saecnls, Qa.c1 of$,hic can dcJi.] conictS any nunbc of difeen .ommn bocks. cMM stat.rnlcnis ac Spoci'icaion satemetS and have a gcncal folr: coM],{\ / namc/ lls f j.ms , / namc / ]rsf-its ... Each a.lc is dofied as a coon block nac. 1h]ch as g1oba] scp. 'hc Fortral Stadad i.l1vs it o use the Same name as an jnilsjc cio, a 1ocal v:riabe, o tocal aay b n ha oi a namcd consant or :n intjnsjc function. ac ljs1. ot iens can contajn nancs f ajables and arra.s. T}e alr'ay namc nlay bc foi1o',cd b a dinesio specificaion pided that ch aay is nly diensioned onc n ach pogam unit. 1hc comna s]own bcfoc thc sccond and Subseqent blo.k nanre is ptiona]. Ttrc amc of the b1ak comnon b]ock js ornJly lecified aS tro consccutjvc s]ashcs (jg1o ing an!' inclvcnjng b]anks) ]rt i{ i js the rsi bo* n he Stacmn i]en ]te pi]l of s]as]es may bc omittcd. c cnt.nts f a. common b]ock ae a concacnaio f the a io dfini].jons fo ]t in he pogam uni. Thus:
coMM}l
c0}.1,lN

/E/ , B, /Tl0/ DELT

c,

/l0/ ALPHA, BT,

c}{

dc1ilcs wo bocks, /oNE/ conanrs hee iels ivhile /TW/ contains fol ofthcn. n prccdues, ari;blcs whjch ac dnmy agurncnts o which a hc Sae as the {uction namc ca.nnot appcar in conron b]ocks.

12.4

BLOCK DAA

Program Units

The b]ock daa. pogam ni iS a Specia] fonr of pograr tlit rhich is equied onh' jf ]t is nccessaty to Specify jnirial vi'l.s 1'or vaja]r]cs and ; iys in named colnn b1cis. Thc pogim unit SatS iih a BLOC( DTA staccnt, ends \iih an END stalccnt, and conajS o]y specifl:ion a DT stacncnS- cmcnt ]incs ale a]so pniticd. T1c b1c d:ta. poga. i]nit is ol exccutable and jt iS not a poccdurc. Thc ncxt.ximp]e iiia,lises he ies in he coon boc]r fo th poin8 pacage used jn scctjon 12.1, so a, ihe iitia pen position is a the oigi], thc Sca.]ing faco sas ai one, ind so on. Ths a suitar1c pogam unit wou1d be|
*SETpLT

BcI{ DAT SPLT

iniiialises

GIc-q
REL

c0M10N

the values used in th plotting package. /PrT/ OENED, oRcN(2), PSCLE, NUMPE1f
0Rc1

ElfED ,TEGR NU}4PN

PS,

SvE /PLT/
DTA OPE]IED/. FALSE. DT ]UMPE]'Jl-1l
END

/'

]RG / 2*a.

/'

SCLE/1. 0/

,{ block data unjt c:n spccify initja1 va,lues r ay rumber of narncd cnnn b]cks (b]ank comor cannot bc initjaisd). ach onmn bock us be cmpcc bu jt iS 1o ne.essay o spec]y jnitia,1 vaues {o a] of h jins witiin ]t. Th.c c b moe ]a on b]oc data prog.in unit, but a g]vn coo b]ock canot app.a ]n moc tir on f he.

13 oSoLT r 1.
o'o3-1

D DPLCATD EIURFj,s
]s a]so Jossjbtc to have onc

i,

lb copatibi[y $]ti Fan66 it

n_namd

b]oc] ]ta pogam

Linking Bock Daia rogam Units


, ute llnk]g a proga,, oe of thc mdu]es cotan]ng a poccdrc ]s accidcta.] onited the ]rnk iS a]os etain to poduce an o mcssagc- But' rrnlcss addiiona.] pecautjons i akcn. t1is vi]] no occu if a lrloc dala subpogam rni js o]litcd. The poga ra' even appea to a.o \]tho it, b is i]c1y to poduce tie rvlong ansvel' Th: is a, sip1c 'a.y to guad agaist this lossibifity: he nac f he b1oc data i sho1d bc specified i an ]iTERl saeent in a leas Smc of he pgam u1its in \'hich th cmon blck is used. Thc is no ham in dcclajng it in a.11 of hcm. This ensucs that a 1jnk i1ne eferenc witl be geneated if any of these othcr program units ie rrscd. Thec js a sight snag to this chiqe ]f an NCLUD sta.tcm.t is used to bing t1c conmon b1ock dclinitiol1 j each pogl':m ni icldjng th block da,ta unit. n dr o avjd a se1{-rcfcrcce, thc inc1dc_1i1c slou]d ot conta.in tc ExRL statcncnDespie ]is s1igh comp1icion, tis iS a simpe and vauabe pcc:utjoI. t also makcs is pssjb]e to h1d b]ck daa iS on obic.t libajes and cliev thcm atomatica]]y hcn hey ae eqjed, jst lie il] ohe typcs f s]rbpoeam unii.

13

Obsolete and Deprecated Features

Nole o{ thc fcalues .oveed hc slou]d be used ]n ne\, Softale: soc of them arc corpletc1}' obsoete. othcS av pacical dc{cts vjc1 makc thcr suita.b]e fo usc i 1e]1_stucircd ,oftwae. Thse bief dSciptjns ar povided only fo thc bcne]it f pogamcrs who 1ave to ndcsta.nd and updatc pogams designcd in ei],ie ycas.

13.1

Stoage of character Strings in Nol-chaacte tems

Bcflc ihc a"dvn of hc cha:clcl da yp ii $Ias possjb]e to stol lext in ar'ithnet]c l.aia,bes ad ara1's' a1tiorg} on]y ve], initcd manipt]a"ion was possiblc. Tho numbcr of chaactcS which cou1d be soed in each jtcm wa.s enie]y Systcm dpendct. one sid_cffcct is tiat ma.n}. svstcnrs sli a]low thc -,\ fomal descipio io ma.ich ]nput/otpui iiems f a.ilhmtic types; iis Sometimcs a11ws rnismatc1es bcta'cc d;. ansf iss and foat desciptos to pass

13.2 rithmetic

F Statement

Th js a executab]c statcont \ith hc {o]m: F( aithmctjc cxpcJsjon ) labe1. 1abc]2. ]abe13 geneal1y povidcs : h.cc a bach (but t1,o ofh labc]s ay be idcntica] o a trv ,a bani). T1e cxpssin a be a intege' cal. r double_pccislon ir]ue: ctolis anSfcn'd io h saLem]t attaccd t iabe]1 i js a1c is ncgative, 1abc12 if zcro, o 1abc13' if posiivc.

13.3

SSGN and assigned G! T! statements

TeSe tqo cxccutab1c S:l.m.ns ac olnall1 sed rgoth.. Ti. SSG Stdi.mnnt a.SsigS a Sti:rncnt lrl value io a itcgc aiab]c. \n.n ris a' bccn donc 1le aiab]c no ]onge has an itn.ti.: a]ue. f tlc abci is attacd to al ]]ctab1c statc.n ]c air.ble can o]v b.

1:] oSL AND DPRF)(:']'') FT]RS


usd

115

in a ass]gcd c0 T statcnc|ti j, attac1ed to a FoRMT siatcmcni th vaiab]c c:n onl be rrsed 1i a RED o IRTE Stacncnt. Thc genet lrs of tlesc statcrcs a.rc:

ASSGN ]abe T intcgc vaiab1e G T0 integc vaialr]o,(label. Jab:], ... ]abc]) n thc assj8ncd G T] statccnt the connr: a.nd

thc cn1]e pacncsisd 1isi of ab.ls

]s

opriona,l.

a.jng

Assjgci G0 T0 can be s.d to povide a [1age to and fom a section of a pogam nj a.s a intcnal subotjnc, bu is not a vey conicnt 1 saisacioy way of ding l]is.
USE Statement

13.4 *

UsE is an execiabe statement w1ich hatts thc pogram in such a way tlat exccution can bc esumcd in e way by the use (o o1 So11 systcms by thc compte peat). Thc gcnca oms of the statcmcnt ae idcntical o tose ol SToP, fr examp]c:

PUSE 'Ni MoUNT TH ExT TPE'

PUSE 54321
PUSE can bc fepl;rced by o1e WRTE ad o]c READ satee| this iS mc 1]cxiblc ,.nd ]ss

sySem-dpendent'

13.5,dtenateRET1RN
Tha i]xenat RETURN mcchanisn ca be used jn Suboincs (b1t not c1cna] functins) io arangc a tans1'cr of cotol io some labecd sta.tcrncn on conp1cti1 o{ a ctl Statement. 1r de to s ji he aguments of thc cLL Stteet musi jncludc a ]ist of 1a.bels. cach pccded by a a.stclisk. These ]abe1s ac aiiachcd o poins iI h ca1ling pogan uit at ,ihic} cxccutio may eSumc aicr he ct Stacmcnt is cxcc11ed. o examplc:

..

cAL BD(x,
1a.bc1

, ,

*15a

'

*220, *390)
ha.vc as]sks as dummy a.glmanis f each

Thc crcspolding subotinc Statemc]t wi]]


Spccjficaion: SLERoUTE BAD(, Ttus:
Rt.l LB 2

B, c, *, *,

*)
a.n

The 1etun pint decnds o thc alc of

irtegel cxpessiol1 given ]n thc lETUi.lf statcmeni.

wl caSe executin to be 1esumed i he Seent atached t he second abe1 gumeni, 220 in his case' f t]c vahlc of he jnegcl expession in the RETUR stieIlen is no jn he range 1 o n (\hee here ac n abc1 agmcnts) o a p]ajn RETURN Stir,tcm.nt iS xccrrd. hen cccutlon reses a the satmcnt aftc t1c cAL in thc s] wa],.. Thc mcchanism can be uscd lo e_hadling bui iS noi vcty flexjb]c aS jnfomation ca]]o be passed hough oc tha or prccdure level. h js bette to se an intege agument to retun a status va]c and use t}ai wjth an r (o cvt a comp1rtcd G To Statement) fu thc
cling prgram.

13 oSoLT

ND DLPRCATD -A/R'S

ll6

13.6
E],TRY

]TR

Statemet
:r.

staemens. f te Ina,n enty po]nt iS a SUBRUTE satemet 1an al] i']enativc cnti, points can bc cal1ed in th Samc $ay as subou1jnes; j i ]s a INCTO] sament ta.n :11 a}enatic cnt pin nirncs c:n be sed as t]ctiot1s. f tle m:in e1y point ]s : chaacc functjot hcn ,.]1 hc a]tcrnajvc cntr"v poiIs mS also 1avc thr.r ype. 1tcnatj\.e eIy pojits lav ]ave dieen lists o dummy agmcrts; it js up to ihe Se to .nsrle ]at aJ1 ths etuning inomijon o ihe caing pogam ac popc]y aeried befoc exi. Thc u1cs fo tic ENTR stane1i a,e necessai1y compicated so it is ea,sy to matc risikes. t gcncal1 ]cltcl l i't 1eis' ]ess isatisfactoy, to 1se a sct f spil,lie poccduTcs l'hich Shae infonnatin sing rmon blocks.

sp..iiy addiiona,1 niy pinS it extcna] functjns and s1bo Saee qlhich has t. samc fm as a SUBRUTNE Siaicmcni. ,{ ERY s:nen rnay be scd at an}r pint J poceduc b a specifica.tio siaencnts c 1ating to its dr]mmy a1grrmcns rnts ppea i he appopjtc p1a,ce 11ith thc h specilica.tjon

iics.

Saemns

ETR ]s

can bc uscd to
xec1rtab]e

13'7

QUvLNcStateme]t

EQUVLECE iS a spci]ication statcmcni lh1c calscs r o mo iems (aiab1cs alla"ys) o bc assoc]atcd ,ith cach ti1. i.e. o colSpond o thc sa.me aea ofmcmo. cha,d.e jtcms can on]y bc assoc]atcd /ith othe c]aacte itms; thc\rjse } data typcs do no havc t match. s 1\,jh colmon b1cLs, hocvcr, rnse of infomatjn is o1 pc]m]ttcd ia associatcd ]ems if hcjr' dr.a rypes matc]. -{ Specj.l cxccptj is ad fo a colpex iten , hic ]S assocjaed wjii t11.o ca] ones. EQUvLEicE s:t.mts cii be sed fai1 s;f.l o po\.j.] a sip1e valiabl name as a. a1ias fo : paiicu]a aay c1emnt o to associ;],t a chaacc varjable with in aJav of t]ra si'e ]cngh' o exanp1c: cARAcR STRNG*80, RR(80) *1 EQUIvtENcE (SRNG, RR)

ThjS S1ig]tt simp]ifi]s .:ess a sing]e c1aaccr in h stin] aS t]c bc uscd jnslcad o STRNG{;r). he genera1 form of th Satcrnt is:

1br

,{Ri,{Y({) can

EQU1vrENcE ( .,,', .. ( ' ), ', ', - '), .. ]ee each v is a vaiable. ara1,, aay c1cmcnt, ., susjng. Dummy arges of pocc dures (and vatiab1cs which ac ctc1na] fnction naes) cannot app:lr. n aa]- namc wiot sbscips c1s 1o i. tr'sr.lern o the aay. lt j5 i11cga.] o associate 11,o o morc eents

,{lthough the EQUVENC Sae1en does ha,c a fcw lcgirimae uscs it iS uS1r]1 cncountecd in pograms .1ee h rues of }brra arc blo]<cn t obtajn Somc spccia.1 1.ci. ogams 1\'1]ch do his ilc lie]y loabl.

o{samc:rrav,diteclilJ']djech:,doanyin811niccoflicts1,iththcsagcsq]encc llcs. Var]ab]s ;d aays i connon b1ocks ca] apcar jn EQUVANCE St:oenS bt this 1as the effc o{ binging al1thc assocjacd itcrns ino e b1ocL. Tiy ca.i be used to cxtrrd th contcns o{thc b1ock p\,ads, subjcc to tie t]es to common b]ock lcngh, but 1ot d\wilds.

13.8 specific Names

of ntrinsic Furctions

Sp]ific ancs s}ri] }c tscd ilsla.d hc 1cic amc o{ an ]nt].irlsjc tunct]on on i1 rc namc s be ric actua,] agent of : proccduc falli ]. nal1 thc mus a]So bc d1ad

]J

or.soET

AND DF'PRCTD EURES

117

in an ]{TRNSC] sta,temcn. Thc fo]o\ig ithsic fnctions cannt bc used ] ris ,ay, ad ci spcci1ic ancs ac t1ceoc c]npe1c1y obSo].tc.

, DNT Lo.'T, SNGL


{-{, M,.1,
,4.M-.x0,

Obsolctc spccic name

Prcfced genci ftm NT

{A1 M]io, -{,]\ 1, ]]\{N1 MNo, {],1

D},{]

RBA
],\x

Mx
,N fuN

he fncions AMx. i_4.1. AfuN0, and MN1 'hich have a daa ypc di1cen honr hat ofthcjr a.rgumcnts ca1 o ly bc cp1aced by appopjae ivpc.onvcsin fuctions in adl]rin ro M_ o 1'\.
*

13.9

PRNT

statement and sitnpified

RAD

Thc PRNT Sialee ca poducc fatd o St-dieced oup o he siand:d pe'coeced otpt 1ilc. Ths these two staemcnts ha\'e exa.ct1y ihc Samc 1lcct|
R],T

fnt

,iRTE(*, ft

' data-list

) data-]ist

The RNT statcmen is jmi1ed ]n itS fuctia.iiy and mis}eadnrg, sjrc,] hcc js 1o ]ccssit}' foJ its output o appcat jn pinted [m. n a sinia wa hcc jS a simp[fied form of READ statcmcnt, So t]csc have t1e sa. c{fcct:
READ
RD

fnt, data-1ist (*, fmt) data-1ist


FILE Statement
o1ms i's

13.10
he
ErD

END

LE Siit.m.rl has h samc gcneal

RE\'\D and BAc(ScE:

END !LE(U\T=unit' END ILE un j.t

ERR=label, STAT=int_var)

Sequntla.] ]i]c hich is dcs]gned to tIiggc tie jnpu. No fi1e ecods can be nliitcn tohe on Sbseqnct end ofilc dctcction mecLa1ism fi]c aftcl't1is end-fle ecol, i.c. te ext opcation us be c!SE, BE']ND, o Bc](SPcE. The satement Seems o lrc Supefluous on aL1os il crcnt systc1ns Since hc\' can de thc end of a jnpl l1 \itiorrt iis aid. Tle Foa1 Standald cqujcs tha he cnd fle e:od hc lcated s a p1ysjal ecod, so that ae an cnd-of'fie condjion 1as bccn deecrcd an expljc]i

t appcnds a speci "end ]i]e" ecod to a

!cSPcE opeItjon is reqid bcfoe any ne data ecods are appcnded' This olion is some'hat atifi.i?} ind not a systcms imp]ecn jt ceci1y' his is onc o{ ' 1?'w 's's shce i dc]ibcatc deparc from te Fotan standad can ha.nce potabi]ity.

13.11 Obsolete Fotmat Descriptors


Thc 1ra.]escipto Djl.d iS exact1y eqjlaenl to '.d on inpt; on olpt i is simi]a ccept that he ejrponcnt \vi]1 se c 1ete D instead ol E. Rc;] ,nd dob]. pecjsiol d:ia' itms ca L'n .-d q la l o} D' r. . o, c d, .' p'o" .

11

APPND A -

s? oF -rNTRNslc UNcToNs

118

The fmat deciptor nsting is eactly equivalent to ,sting, (whee n ls an u iged iniege constat giving tle ength of the sijg). When sed rrit a fomatted WRITE statement the sting iS copied t the output ecd. The nl fm does nt equie apostophs to be doubled ithin the sting but does require an aclate ca,racter count.

14

ppendix A

- List

of ntrinsic Functions

This tab]e shows th numbe of aguments f a.ch functioi aJ1d what data types ae peitted. The data. type codes ae: = ntege, R = Rea,, D = Double pcision, x = Complex, C = Character, = Lcai, * means the eslt has the ame daa, typ as the agument(s). Note tha,t if thee i moe than one agument in sch cases they must a ha,ve the sane iata type.

]4 PEN,]
R=

r,rsT o -}_rNsC lNc1oNs


Takcs hc modu]us f a conpox ube (].. 1 sqac loo of hc sum o thc Squaics of thc two componc]ts). ,{rc_cosjre; thc es] is j th angc 0 o +ri xtacis hcima8inaJ cornponcnl fn]mpcx nmbe. Usc RE,{ to exract the ea componnt. Rouds ihc ncarest vole unbe. 'Lrc tagen of rr1/ara, csolvcd int thc coec quadat. hc csut is jrl thc agc , +. t ]s an eol t havc bo arguments eo. Rctns N] chaactc ]n 1ca1 chaactcl codc ab]e. Ces to com!1e) second ag optioat. cpucs thc complcx conjug;e of a coplcx mbc'

E9

BS()

AC0S(RD) R = A{G(x)
*= * *
= =

N[T(D) cR()

N2(RD,RD)

X *

cosinc of the ange in a.d]ins. coIve1ts to doub1e pecjsion. * i.erns hc positive diierence ofrrql andoTr?.i..if.91 > a,'r72 it ctuns (arr1 - or92), oihervise ze. D = DPRD(R,R) comues the doub1e pccisjon poduc tio rcal a1cs. * -Ex(RDx) Rtuns . exponcnial, i.e. to thc po1c of the agen. Tis is hc ]ncSc of ihe ata 1ogalt1m. = cHR(c) Rens psitiol o S chiace the sLrig il thc 1ocal chaace codc ablc. = NDE(c,c) Scrchcs jist sitg and chrns psjiiol ot Sccond sting ihjn i stating at 1, ohevise Zeo. - NT(BD) convS to jncgc b tru]cation. - tEN(c) Rctuns 1e1gh o, ihc agumnt i chn"1accsLGE(c,c) Lcxica1 conpajson sing SC col]aig sequancc: etns L rue ]f 1J"4r >= ror. r = rcT(c'c) Lxic:l comparison sing Asc coatjng sequence: lns rre i a|g > arg2. L = LE(c,c) jrjcit] complison using SC co]1iig scqrrcnce: etuns '.. il 0'r91 <= 92' = LT(c,c) Lexica comparison using ASo co11ating Seqence: ctlns ffc \l r91 < 192' * = c(RDx) Logalihm io base e llhete e=2.718...). * = LG1o(RD) ogalihn to base 10. IAx(IRD,RD,...) Rctuns the lages ofits agumcts. = * 1N(RD,RD,'..) Reiuns the Sma]lesi of its :gumcnts. * = MoD(RD,RD) Retuns .ir1 mdu1o argz, i.e. he emadel :fic dividjg rh hy 92' R = REA(RD) colts o rca.1. = Sc(RD,RD) Pcrfoms sign r:nsfc: ]{ ar92 is ncgaijvc the esu iS -91, i{ afg2 iS zero o ps]tie the esrrt iS +.91. * = SQRT(RD) Squae oot erol if ag negati). * = TA(RD) Tange of thc ane1 in adias.

= = = = =

c\JG(x) CS(RD) DBLE(RDX) = D (RD,RD)

C}4L(RD,RD)

15

APPD

sPEcr'/c Nn4Js o GElrRJc Nc1.ol{s

120

15 Appendix B

Specific Names of Generic F\,rnctions

Spccific namer ae sti needed whcn the lunction namc is used aS the acta1agument of anothe procedurc. The specific nam must thcn a1so be dec]aed in :n NTRSc statcment. Tiis tab]e isis a1 thc spaciic i'mes \rhic aJc Stili qsef in Ftan77 in tesc ae cicmstances. ic othcr functions eihel do no hav gcnc]c names cannot be passcd a.s a.cua] aJgmnts. Generic ame

Bs

NTEGER REAL
-4Bs

Specific namcs

ABS

DoUBLD PRECsoN
D,{BS

coMPE
CABS

.4.COS

NT
.4.sN

.4.NNT

.{TA
..TA_2

NT NN AsN TN
AT.{2

coS

DCoS DNT DNNT


D.4.sN
D.{T..

COS

coS

cs
DM

DT.N2
D

xP

DM

oG

oG10
MOD NNT
SGN SN S SQRT

MOD

scN

DM E ALOG ALOGl{} AMOD NNT


SGN SN SN SQRT

c oS

COS

DD DEXP D,oG DLOGlO DMOD DNT

cos

cc os

CLO G

cEP

DsGli
DsN DsNH

csN
CSQRT

TAN

TA N

TN TNH

DSQR,T

DTAN DTANH

]
]

ndex
djStable gmc1ts ithmctic jihmctjc
aa.ys

iihmeiic lrays 38

69 cxpessions .1 Satcmcnt 1t, opci'tos.11


of pocdues

72

compted G To Statcmcnt oStant cxpcssjns :4


cnsta.nts, namcd 36

61

constats

32

l ._ l __ !

A1ray ecmcnts 39 Arays, adjustable 72


Ara1,s as aguacnts

Contjnutjo1 1iIes 23 Cuency symbol 22 D_{',{ statement 11

71 ays, ssmcd sizc 73 ays, chaacte 74 ravs, dec1aring size of 38 la.ys, initia]]sing 106 ASc co]aing sqrrcncc 5t SSGN Statemnt 114
Ssjgncd

Daa tpc convarsions 43 Daa' ype defa]ts 3.1


Da.ta typcs. non Standad 31

Di'1a typcs 28

: ]

.*

'

Assignmet' chaace 50 Ass]gnmcnt statements 47 ,q.ssumed siza aays 73 B,{CKSP,{CE stiemen 14 Bit'vise logica] opeations 44 Blank chalactes 22 BLoC{ DAT.{ progam units 113 cLL statcment 76 aiage-conto 97 chaacie a.ays 74 chaacie coating sequence 53 chaace constants 33 chaacte data typ 30 chaacte expessjons 50 chaacte f1ctions 51 chaacte handting 48 chaacte set, otIa.n 21 Ci,{R,A.CTER Statcmcnt 34 chalactes, non standad 22 cLoSE sa,emcn 100 co1rrmn cotol in fomats 94 comment 1incs 23 Cmmn b1ocks 108

G T

Statemnt

11,

DMENSO Statemer Diect acccss fics 82,84 Do WlE 1oops 7 Do oops 58

38

Double pecision cnstants 33

Doublc plecision dita lypc 30 ELSE and ELSE l saeens 57 N]] Do statement 7 END F],E si:ement 117 End offie condi1jo 89 DNTRY sta.temcnt t16 EQU\LENC statemenr 116 EoS, /o 87 S 2r Execltjon squelce 26 Expessions, aithmic 40 Expressions, ogica, 5' Expess]ons' elationa 52 Exensions 7 Extcna] filcs 83 Extenal poccdcs 65 F,XTRR, siatemcn]] 79 ies' extena 81 ljes, inerni1 80
jes 80

I'o1mit dita, descripors Foat spci]ication 89

9l

coM4oN

sta,tem1t

mpaisons, aithmtic compajsons, chaIactc

Compiing 18 comp]ex constants Coplcx data typc

113 53 53

FoRMAT

sta.tement 90

FomaS. cha.a.cte 93 Fomais, floa'ting'point 92 Eomats1jntcgc 92

33 3
121

Fomats' logjca] 93
!'o1tan90 6

FUNCTON sitement

77

N/l F]

122

Fmcins, inisic.5 Euncjons, statment 6'1 Functions, iype convesion


G]oba nanes

unctions'

cxtcnal68 27

READ staemen 80,

12

,16 7

Go To statcmcnt 61 t b]ocks 57 MILCT NoNE statenent

Rcal consta.nts 32 Rcal data typc 29 Recod cfirol in fma.ts 94 Rcords 81 Re]i'jona,l cpcssions 52

_ '.

ntege constaiits

MPLCT statcmcnt 35 lpL]cd Do loops ]n /o ]03 NCLUDE saemen 7, 18 niiasig vaiab]s 106 hput/ottput fa.c1titjes 8 NQURD Sta,tcmeni 81. 100

RETURN. a]enat

Reseved wo1ds 27

REWND Statcm.nt 104 SVE stateme and common b]cks

RTURN

115

statemcnt 76

sAvE

staemnt

111

?9

tcg da.ta typc 29 ntege divisio 43


ntna, nes

32

ntjnsjc fnction namcs 27,

80,85

nilSjc tnctions 45.63.

NTRliSc sieen
un]ts 3t Labe]s 24

/o

] 16 1lE 79

' _

Linkjng 19 LiSt dieced iput 96 List-dicctcd / 83 List djcctcd oput 96 Logjca,] constatts 33 ogica1 da,ta typc 30 Logical cxprcssions 5. Logica statement 60
],ops

Namcd cnstants 36 Namcs, scope o 27


Names, symb1ic 26

56

in foats 95 seqntial ccss 1i]es 82 souce code 17 statemet fnctjns 64 Statment ]abets 24 statcment ]ayut 23 statenent odc 25 sToP saemet 57,62 stagc sequence 4 stoage rrnjts 31 SUBRoUTNE satement 76 Substings, chaace 49 symboic namcs 26 Temajnat /o 87 Text i]ls 83 Tjgonomtic fnctions 45 Tpe convesin 46 ypc stiteents 34 Udefined va.]ucs 44 lriab]es 38 Wi]TE sr'1.eent 8n. 10,
sca,]e factos

object IbaJies

oPEN

19

pcr rs. ol.l bb

sa.icnct 8]. 99
37

PMTR statement
P,{]sE Statcment 11;
Pc'co]nectcd i1lrs 87

PRNT slirtemeni 117 Plfuting and caJiage-contol

97

Proccdurcs :s a.gumcnts 75 Pccdrcs, cxtcna] 65 ocedes 25.63 P}l.GR._ .M stateme] 28


Pog1a'n

tnis

25

You might also like