Jump to content

Text processing/1: Difference between revisions

m
Fixed lang tags.
m (Fixed lang tags.)
Line 37:
=={{header|Ada}}==
{{libheader|Simple components for Ada}}
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
<lang ada>
with Ada.Text_IO; use Ada.Text_IO;
with Strings_Edit; use Strings_Edit;
with Strings_Edit.Floats; use Strings_Edit.Floats;
Line 113 ⟶ 112:
Close (File);
Put_Line ("Syntax error at " & Image (Current.Line) & ':' & Image (Max.Pointer));
end Data_Munging;</lang>
</lang>
The implementation performs minimal checks. The average is calculated over all valid data. For the maximal chain of consequent invalid data, the source line number, the column number, and the time stamp of the first invalid data is printed. Sample output:
<pre>
Line 126 ⟶ 124:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!--{{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - argc and argv are extensions}} -->
<lang algolalgol68>INT no data := 0; # Current run of consecutive flags<0 in lines of file #
INT no data max := -1; # Max consecutive flags<0 in lines of file #
FLEX[0]STRING no data max line; # ... and line number(s) where it occurs #
Line 241 ⟶ 239:
 
=={{header|AWK}}==
<lang cawk># Author Donald 'Paddy' McCarthy Jan 01 2007
 
BEGIN{
Line 322 ⟶ 320:
=={{header|Common Lisp}}==
 
<lang lisp>(defstruct (measurement
(defstruct (measurement
(:conc-name "MEASUREMENT-")
(:constructor make-measurement (counter line date flag value)))
Line 423 ⟶ 420:
(measurement-date worst-beginning)
(measurement-counter worst-beginning)
worst-length))</lang>
</lang>
 
Example output:
Line 530 ⟶ 526:
=={{header|Forth}}==
{{works with|GNU Forth}}
<lang forth>\ data munging
\ data munging
 
\ 1991-03-30[\t10.000\t[-]1]*24
Line 623 ⟶ 618:
total-sum f@ total-n @ .mean cr ;
 
main bye</lang>
</lang>
 
=={{header|Haskell}}==
Line 702 ⟶ 696:
589
]StartDates=: Dates {~ (>:@I.@e.&MaxRun (24 <.@%~ +/)@{. ]) RunLengths
1993-03-05</lang>
</lang>
'''Formatting Output'''<br>
Define report formatting verbs:
<lang j>formatDailySumry=: dyad define
formatDailySumry=: dyad define
labels=. , ];.2 'Line: Accept: Line_tot: Line_avg: '
labels , x ,. 7j0 10j3 10j3 ": y
Line 719 ⟶ 711:
)</lang>
Show output:
<lang j> (_4{.Dates) formatDailySumry _4{. DailySummary
Line: Accept: Line_tot: Line_avg:
2004-12-28 23 77.800 3.383
Line 1,042 ⟶ 1,034:
 
=={{header|R}}==
<lang R>#Read in data from file
#Read in data from file
dfr <- read.delim("readings.txt")
#Calculate daily means
Line 1,051 ⟶ 1,042:
#Calculate time between good measurements
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>
</lang>
 
=={{header|Ruby}}==
Line 1,147 ⟶ 1,137:
Vedit does not have floating point data type, so fixed point calculations are used here.
 
<lang vedit>#50 = Buf_Num // Current edit buffer (source data)
<lang vedit>
#50 = Buf_Num // Current edit buffer (source data)
File_Open("output.txt")
#51 = Buf_Num // Edit buffer for output file
Line 1,215 ⟶ 1,204:
IT("Maximum run(s) of ") Num_Ins(#13, LEFT+NOCR)
IT(" consecutive false readings ends at line starting with date(s): ") Reg_Ins(15)
IN</lang>
</lang>
 
Sample output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.