Text processing/1: Difference between revisions
Content added Content deleted
(jq) |
m (→{{header|REXX}}: added/changed whitespace and comments, simplified the COMMAS subroutine.) |
||
Line 2,923: | Line 2,923: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program to process instrument data from a data file. */ |
<lang rexx>/*REXX program to process instrument data from a data file. */ |
||
numeric digits 20 /*allow for bigger numbers. |
numeric digits 20 /*allow for bigger (precision) numbers.*/ |
||
ifid='READINGS.TXT' /*the |
ifid='READINGS.TXT' /*the name of the input file. */ |
||
ofid='READINGS.OUT' /* |
ofid='READINGS.OUT' /* " " " " output " */ |
||
grandSum=0 /*grand sum of whole file. */ |
grandSum=0 /*the grand sum of whole file. */ |
||
grandFlg=0 /*the grand number of flagged data. */ |
|||
grandOKs=0 |
grandOKs=0 |
||
Lflag=0 /*the longest period of flagged data. */ |
|||
Cflag=0 /*the longest continous flagged data. */ |
|||
w=16 /*width of fields when displayed.*/ |
w=16 /*the width of fields when displayed. */ |
||
do recs=1 while lines(ifid)\==0 /* |
do recs=1 while lines(ifid)\==0 /*keep reading records until finished. */ |
||
rec=linein(ifid) /*read the next record (line) |
rec=linein(ifid) /*read the next record (line) of file. */ |
||
parse var rec datestamp Idata /*pick off the dateStamp |
parse var rec datestamp Idata /*pick off the dateStamp and the data. */ |
||
sum=0 |
sum=0 |
||
flg=0 |
flg=0 |
||
OKs=0 |
OKs=0 |
||
do j=1 until Idata='' /*process the instrument data. */ |
do j=1 until Idata='' /*process the instrument data. */ |
||
parse var Idata data.j flag.j Idata |
parse var Idata data.j flag.j Idata |
||
if flag.j>0 then do /* |
if flag.j>0 then do /*process good data ··· */ |
||
OKs=OKs+1 |
OKs=OKs+1 |
||
sum=sum+data.j |
sum=sum+data.j |
||
if |
if Cfag>Lflag then do |
||
Ldate=datestamp |
|||
Lflag=Cflag |
|||
end |
end |
||
Cflag=0 |
|||
end |
end |
||
else do /*flagged data |
else do /*process flagged data ··· */ |
||
flg=flg+1 |
flg=flg+1 |
||
Cflag=Cflag+1 |
|||
end |
end |
||
end /*j*/ |
end /*j*/ |
||
if OKs\==0 then avg=format(sum/OKs,,3) |
if OKs\==0 then avg=format(sum/OKs,,3) |
||
else avg='[n/a]' |
else avg='[n/a]' |
||
grandOKs=grandOKs+OKs |
grandOKs=grandOKs+OKs |
||
_=right( |
_=right(commas(avg),w) |
||
grandSum=grandSum+sum |
grandSum=grandSum+sum |
||
grandFlg=grandFlg+flg |
grandFlg=grandFlg+flg |
||
if flg==0 then call sy datestamp ' average='_ |
if flg==0 then call sy datestamp ' average='_ |
||
else call sy datestamp ' average='_ ' flagged='right(flg,2) |
else call sy datestamp ' average='_ ' flagged='right(flg,2) |
||
end /*recs*/ |
end /*recs*/ |
||
recs=recs-1 /*adjust for reading |
recs=recs-1 /*adjust for reading the end─of─file. */ |
||
if grandOKs\==0 then Gavg=format( |
if grandOKs\==0 then Gavg=format(grandSum/grandOKs,,3) |
||
else Gavg='[n/a]' |
else Gavg='[n/a]' |
||
call sy |
call sy |
||
call sy copies('═',60) |
call sy copies('═',60) |
||
call sy ' records read:' right( |
call sy ' records read:' right(commas(recs), w) |
||
call sy ' grand sum:' right( |
call sy ' grand sum:' right(commas(grandSum), w+4) |
||
call sy ' grand average:' right( |
call sy ' grand average:' right(commas(Gavg), w+4) |
||
call sy ' grand OK data:' right( |
call sy ' grand OK data:' right(commas(grandOKs), w) |
||
call sy ' grand flagged:' right( |
call sy ' grand flagged:' right(commas(grandFlg), w) |
||
⚫ | |||
if longFlag\==0 then |
|||
⚫ | |||
call sy copies('═',60) |
call sy copies('═',60) |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're all done. */ |
||
/*────────────────────────────────────────────────────────────────────────────*/ |
|||
/*──────────────────────────────────SY subroutine───────────────────────*/ |
|||
commas: procedure; parse arg _; n=_'.9'; #=123456789; b=verify(n,#,"M") |
|||
⚫ | |||
if 1==0 then call lineout ofid,stuff |
|||
⚫ | |||
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''' when using the default input file: |
|||
if cu=='BLANK' then c=' ';o=word(p 3,1);p=abs(o);t=word(t 999999999,1) |
|||
⚫ | |||
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") |
|||
⚫ | |||
⚫ | |||
{{out}} |
|||
⚫ | |||
∙ |
∙ |
||
∙ |
∙ |