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