Jump to content

Text processing/1: Difference between revisions

m
Line 1,630:
=={{header|REXX}}==
<lang rexx>
/*REXX program to process semi-hourlyinstrument data from a data file. */
 
numeric digits 20 /*allow for bigger numbers. */
Line 1,637:
grandSum=0 /*grand sum of whole file. */
grandflg=0 /*grand num of flagged data. */
grandOKs=0
longFlag=0 /*longest period of flagged data.*/
contFlag=0 /*longest continous flagged data.*/
w=16 /*width of fields when displayed.*/
goods =0
 
do jrecs=1 while lines(ifid)\==0 /*read until finished. */
rec=linein(ifid) /*read the next record (line). */
parse var rec datestamp HdataIdata /*pick off the dateStamp & data. */
sum=0
flg=0
goodOKs=0
 
do hj=1 until HdataIdata='' /*process the semi-hourlyinstrument data. */
parse var HdataIdata data.hj flag.hj HdataIdata
 
if flag.h>0 then do /*if good data, ... */
if flag.j>0 then do /*if good=good+1 data, ... */
sumOKs=sumOKs+data.h1
sum=sum+data.j
if contFlag>longFlag then do
longdate=datestamp
Line 1,665 ⟶ 1,667:
end
 
if goodOKs\==0 then avg=format(sum/goodOKs,,3)
goods=goods+good
else avg='[n/a]'
grandOKs=grandOKs+OKs
if good\==0 then avg=format(sum/good,,3)
if flg_==0 then call sy datestamp 'average='right(comma(avg),15w)
else call sy datestamp 'average='right(avg,15) ' flagged='right(flg,2)
grandSum=grandSum+sum
grandFlg=grandFlg+flg
 
if flg==0 then call sy datestamp ' average='_
else call sy datestamp ' average='right(avg,15)_ ' flagged='right(flg,2)
end
 
recs=recs-1 /*adjust for reading end-of-file.*/
 
if goodsgrandOKs\==0 then Gavg=format(grandsum/goodsgrandOKs,,3)
Gavg='[n/a]'
else Gavg='[n/a]'
if goods\==0 then Gavg=format(grandsum/goods,,3)
call sy
call sy copies(' records read='j-1,60)
call sy ' grand records sum=read:'grandSum right(comma(recs-1),w)
call sy ' grand average= sum:'Gavg right(comma(grandSum),w+4)
call sy ' grand flagged=average:'grandFlg right(comma(Gavg),w+4)
call sy ' grand OK data:' right(comma(grandOKs),w)
call sy 'longest glagged='longFlag "ending at" longdate
call sy ' grand flagged:' right(comma(grandFlg),w)
if longFlag\==0 then
call sy ' longest glagged=flagged:' right(comma(longFlag),w) " ending at " longdate
call sy copies('=',60)
call sy
exit
 
 
/*─────────────────────────────────────SY subroutine────────────────────*/
sy: procedure; parse arg stuff
say stuff
if 1==0 then call lineout ofid,stuff
return
 
 
/*─────────────────────────────────────COMMA subroutine─────────────────*/
comma: procedure; parse arg _,c,p,t;arg ,cu;c=word(c ",",1);
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");
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>
Output:
<pre style="height:35ex40ex;overflow:scroll">
20041991-1210-2816 average= 3 4.383167 flagged= 16
20041991-1210-2917 average= 210.448867 flagged= 19
20041991-1210-3018 average= 2 3.839 flagged= 1083
2004-12-31 average= 2.057 flagged= 1
 
records read=5471
============================================================
grand sum=1358393.400
records read=5471: 5,470
grand average=10.497
grand sum=1358393: 1,358,393.400
grand flagged=1901
2004-12-31 grand average=: 2.057 flagged= 1 10.497
longest glagged=589 ending at 1993-03-05
grand OK data: 129,403
grand flagged=1901: 1,901
longest glagged=flagged: 589 ending at 1993-03-05
============================================================
 
</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.