version 0.7.8

This commit is contained in:
Andreas Rumpf
2009-05-08 16:36:06 +02:00
parent 08bc9ac03c
commit db4f617afc
92 changed files with 3088 additions and 3477 deletions

View File

@@ -1,7 +1,3 @@
# Hallo world program
import strutils
echo($(parseFloat("0.5")* toFloat(5000) / toFloat(parseInt("5000"))))
echo("Hallo world!")
echo "Hallo world!"

View File

@@ -1,7 +1,6 @@
# Example program to show the new parsexml module
# This program reads an HTML file and writes all its used links to stdout.
# Errors and whitespace are ignored.
# (c) 2009 Andreas Rumpf
import os, streams, parsexml, strutils
@@ -15,7 +14,7 @@ if paramCount() < 1:
var links = 0 # count the number of links
var filename = appendFileExt(ParamStr(1), "html")
var s = newFileStream(filename, fmRead)
if s == nil: quit("cannot open the file" & filename)
if s == nil: quit("cannot open the file " & filename)
var x: TXmlParser
open(x, s, filename)
next(x) # get first event

View File

@@ -1,7 +1,6 @@
# Example program to show the new parsexml module
# This program reads an HTML file and writes its title to stdout.
# Errors and whitespace are ignored.
# (c) 2009 Andreas Rumpf
import os, streams, parsexml, strutils
@@ -10,7 +9,7 @@ if paramCount() < 1:
var filename = appendFileExt(ParamStr(1), "html")
var s = newFileStream(filename, fmRead)
if s == nil: quit("cannot open the file" & filename)
if s == nil: quit("cannot open the file " & filename)
var x: TXmlParser
open(x, s, filename)
while true:

60
examples/statcsv.nim Normal file
View File

@@ -0,0 +1,60 @@
# Example program to show the parsecsv module
# This program reads a CSV file and computes sum, mean, minimum, maximum and
# the standard deviation of its columns.
# The CSV file can have a header which is then used for the output.
import os, streams, parsecsv, strutils, math
if paramCount() < 1:
quit("Usage: sumcsv filename[.csv]")
var filename = appendFileExt(ParamStr(1), "csv")
var s = newFileStream(filename, fmRead)
if s == nil: quit("cannot open the file " & filename)
var
x: TCsvParser
header: seq[string]
res: seq[TRunningStat]
open(x, s, filename, separator=';', skipInitialSpace = true)
while readRow(x):
if processedRows(x) == 1:
newSeq(res, x.row.len) # allocate space for the result
if validIdentifier(x.row[0]):
# header line:
header = x.row
else:
newSeq(header, x.row.len)
for i in 0..x.row.len-1: header[i] = "Col " & $(i+1)
else:
# data line:
for i in 0..x.row.len-1:
push(res[i], parseFloat(x.row[i]))
x.close()
# Write results:
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(header[i])
stdout.write("\nSum")
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(res[i].sum)
stdout.write("\nMean")
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(res[i].mean)
stdout.write("\nMin")
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(res[i].min)
stdout.write("\nMax")
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(res[i].max)
stdout.write("\nStdDev")
for i in 0..header.len-1:
stdout.write("\t")
stdout.write(res[i].standardDeviation)
stdout.write("\n")