Text processing/1: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments, simplified the COMMAS subroutine.
(jq)
m (→‎{{header|REXX}}: added/changed whitespace and comments, simplified the COMMAS subroutine.)
Line 2,923:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to process instrument data from a data file. */
numeric digits 20 /*allow for bigger (precision) numbers. */
ifid='READINGS.TXT' /*the name input file. of the input file. */
ofid='READINGS.OUT' /*the " outut file. " " " output " */
grandSum=0 /*the grand sum of whole file. */
grandflggrandFlg=0 /*the grand numnumber of flagged data. */
grandOKs=0
longFlagLflag=0 /*the longest period of flagged data. */
contFlagCflag=0 /*the longest continous flagged data. */
w=16 /*the width of fields when displayed. */
 
do recs=1 while lines(ifid)\==0 /*readkeep reading records until finished. */
rec=linein(ifid) /*read the next record (line). of file. */
parse var rec datestamp Idata /*pick off the dateStamp &and the data. */
sum=0
flg=0
OKs=0
 
do j=1 until Idata='' /*process the instrument data. */
parse var Idata data.j flag.j Idata
 
if flag.j>0 then do /*ifprocess good data, ...··· */
OKs=OKs+1
sum=sum+data.j
if contFlagCfag>longFlagLflag then do
longdate Ldate=datestamp
longFlag Lflag=contFlagCflag
end
contFlagCflag=0
end
else do /*process flagged data ... ··· */
flg=flg+1
contFlagCflag=contFlagCflag+1
end
end /*j*/
 
if OKs\==0 then avg=format(sum/OKs,,3)
else avg='[n/a]'
grandOKs=grandOKs+OKs
_=right(commacommas(avg),w)
grandSum=grandSum+sum
grandFlg=grandFlg+flg
if flg==0 then call sy datestamp ' average='_
else call sy datestamp ' average='_ ' flagged='right(flg,2)
end /*recs*/
 
recs=recs-1 /*adjust for reading end-of-filethe end─of─file. */
if grandOKs\==0 then Gavg=format(grandsumgrandSum/grandOKs,,3)
else Gavg='[n/a]'
call sy
call sy copies('═',60)
call sy ' records read:' right(commacommas(recs), w)
call sy ' grand sum:' right(commacommas(grandSum), w+4)
call sy ' grand average:' right(commacommas(Gavg), w+4)
call sy ' grand OK data:' right(commacommas(grandOKs), w)
call sy ' grand flagged:' right(commacommas(grandFlg), w)
if Lflag\==0 then call sy ' longest flagged:' right(commacommas(longFlagLflag),w) " ending at " longdateLdate
if longFlag\==0 then
call sy ' longest flagged:' right(comma(longFlag),w) " ending at " longdate
call sy copies('═',60)
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────SY subroutine───────────────────────*/
sycommas: procedure; parse arg stuff_; n=_'.9'; #=123456789; say stuffb=verify(n,#,"M")
e=verify(n,#'0',,verify(n,#"0.",'M'))-p-1;end4
if 1==0 then call lineout ofid,stuff
do j=e to b by -p3; while k<t;_=insert(c',',_,j);k=k+1; end /*j*/; return _</lang>
return
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────COMMA subroutine────────────────────*/
sy: say arg(1); call lineout ofid,arg(1); return</lang>
comma: procedure; parse arg _,c,p,t;arg ,cu;c=word(c ",",1)
'''output''' &nbsp; when using the default input file:
if cu=='BLANK' then c=' ';o=word(p 3,1);p=abs(o);t=word(t 999999999,1)
<pre style="height:40ex;overflow:scroll">
if \datatype(p,'W')|\datatype(t,'W')|p==0|arg()>4 then return _;n=_'.9'
#=123456789;k=0;if o<0 then do;b=verify(_,' ');if b==0 then return _
e=length(_)-verify(reverse(_),' ')+1;end;else do;b=verify(n,#,"M")
e=verify(n,#'0',,verify(n,#"0.",'M'))-p-1;end
do j=e to b by -p while k<t;_=insert(c,_,j);k=k+1;end;return _</lang>
{{out}}
<pre style="height:40ex;overflow:scroll">