Text processing/1: Difference between revisions
Content added Content deleted
(fixed output of max false reading) |
m (→{{header|R}}) |
||
Line 1,627: | Line 1,627: | ||
times <- strptime(dfr[1,1], "%Y-%m-%d", tz="GMT") + 3600*seq(1,24*nrow(dfr),1) |
times <- strptime(dfr[1,1], "%Y-%m-%d", tz="GMT") + 3600*seq(1,24*nrow(dfr),1) |
||
hours.between.good.measurements <- diff(times[t(flags)])/3600</lang> |
hours.between.good.measurements <- diff(times[t(flags)])/3600</lang> |
||
=={{header|REXX}}== |
|||
<lang rexx> |
|||
/*REXX program to process semi-hourly data from a data file. */ |
|||
numeric digits 20 /*allow for bigger numbers. */ |
|||
ifid='READINGS.TXT' /*the input file. */ |
|||
ofid='READINGS.OUT' /*the outut file. */ |
|||
grandSum=0 /*grand sum of whole file. */ |
|||
grandflg=0 /*grand num of flagged data. */ |
|||
longFlag=0 /*longest period of flagged data.*/ |
|||
contFlag=0 /*longest continous flagged data.*/ |
|||
goods =0 |
|||
do j=1 while lines(ifid)\==0 /*read until finished. */ |
|||
rec=linein(ifid) /*read the next record (line). */ |
|||
parse var rec datestamp Hdata /*pick off the dateStamp & data. */ |
|||
sum=0 |
|||
flg=0 |
|||
good=0 |
|||
do h=1 until Hdata='' /*process the semi-hourly data. */ |
|||
parse var Hdata data.h flag.h Hdata |
|||
if flag.h>0 then do /*if good data, ... */ |
|||
good=good+1 |
|||
sum=sum+data.h |
|||
if contFlag>longFlag then do |
|||
longdate=datestamp |
|||
longFlag=contFlag |
|||
end |
|||
contFlag=0 |
|||
end |
|||
else do /*flagged data ... */ |
|||
flg=flg+1 |
|||
contFlag=contFlag+1 |
|||
end |
|||
end |
|||
goods=goods+good |
|||
avg='[n/a]' |
|||
if good\==0 then avg=format(sum/good,,3) |
|||
if flg==0 then call sy datestamp 'average='right(avg,15) |
|||
else call sy datestamp 'average='right(avg,15) ' flagged='right(flg,2) |
|||
grandSum=grandSum+sum |
|||
grandFlg=grandFlg+flg |
|||
end |
|||
Gavg='[n/a]' |
|||
if goods\==0 then Gavg=format(grandsum/goods,,3) |
|||
call sy |
|||
call sy ' records read='j-1 |
|||
call sy ' grand sum='grandSum |
|||
call sy ' grand average='Gavg |
|||
call sy ' grand flagged='grandFlg |
|||
call sy 'longest glagged='longFlag "ending at" longdate |
|||
call sy |
|||
exit |
|||
sy: procedure; parse arg stuff |
|||
say stuff |
|||
if 1==0 then call lineout ofid,stuff |
|||
return |
|||
</lang> |
|||
Output: |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
2004-12-28 average= 3.383 flagged= 1 |
|||
2004-12-29 average= 2.448 flagged= 1 |
|||
2004-12-30 average= 2.839 flagged= 1 |
|||
2004-12-31 average= 2.057 flagged= 1 |
|||
records read=5471 |
|||
grand sum=1358393.400 |
|||
grand average=10.497 |
|||
grand flagged=1901 |
|||
longest glagged=589 ending at 1993-03-05 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |