treimplement transpose in C - numtools - perform numerical operations on vectors and matrices in unix pipes
(HTM) git clone git://src.adamsgaard.dk/numtools
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 46e27e9ab6b642fc1ac57cda2e7eacb43956ee24
(DIR) parent 941edcb2fd8369e4a60c2e7e32087e500706f600
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sat, 11 Sep 2021 20:47:06 +0200
reimplement transpose in C
Diffstat:
M Makefile | 5 +++--
D transpose | 15 ---------------
M transpose.1 | 15 ++++-----------
M util.c | 4 +---
M util.h | 3 +++
5 files changed, 11 insertions(+), 31 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -14,10 +14,10 @@ BIN =\
min\
rangetest\
sum\
+ transpose\
SCRIPTS =\
histpdf\
- transpose\
SRC =\
util.c
t@@ -55,6 +55,7 @@ mean: mean.o
min: min.o
rangetest: rangetest.o
sum: sum.o
+transpose: transpose.o
${BIN}: ${LIB} ${OBJ}
${CC} ${_LDFLAGS} -o $@ ${@:=.o} ${OBJ}
t@@ -65,7 +66,7 @@ ${BIN}: ${LIB} ${OBJ}
install:
# installing executable files and scripts.
mkdir -p "${DESTDIR}${PREFIX}/bin"
- cp -f ${SCRIPTS} "${DESTDIR}${PREFIX}/bin"
+ cp -f ${BIN} ${SCRIPTS} "${DESTDIR}${PREFIX}/bin"
for f in ${BIN} ${SCRIPTS}; do chmod 755 "${DESTDIR}${PREFIX}/bin/$$f"; done
# installing documentation files.
mkdir -p "${DESTDIR}${DOCPREFIX}"
(DIR) diff --git a/transpose b/transpose
t@@ -1,15 +0,0 @@
-#!/usr/bin/awk -f
-{
- for (i = 1; i <= NF; i++)
- d[NR][i] = $i
-}
-END {
- for (i = 1; i <= NF; i++) {
- for (j = 1; j <= NR; j++) {
- printf("%s", d[j][i])
- if (j < NR)
- printf("\t")
- }
- printf("\n")
- }
-}
(DIR) diff --git a/transpose.1 b/transpose.1
t@@ -6,20 +6,13 @@
.Nd interchanges the row and column positions for each field
.Sh SYNOPSIS
.Nm
-.Op Ar
.Sh DESCRIPTION
.Nm
-flips the rows and columns, effectively transposing it around the
-diagonal axis.
-This means that an input file with N colums and M rows is output as M
-colums and N rows.
-The input is
-.Ar file
-or standard input, if no
-.Ar file
-is given.
+flips the rows and columns of a matrix given by standard input,
+effectively transposing it around the diagonal axis.
+This means that an input file with N colums and M rows is output
+as M colums and N rows.
.Sh SEE ALSO
-.Xr awk 1 ,
.Xr max 1 ,
.Xr mean 1 ,
.Xr min 1 ,
(DIR) diff --git a/util.c b/util.c
t@@ -1,9 +1,7 @@
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
-
-#define DELIM '\t'
-#define DELIMSTR "\t"
+#include "util.h"
size_t
allocarr(double **arr, const char *str, size_t maxlen)
(DIR) diff --git a/util.h b/util.h
t@@ -8,6 +8,9 @@
#define unveil(p1, p2) 0
#endif
+#define DELIM '\t'
+#define DELIMSTR "\t"
+
#undef strlcpy
size_t strlcpy(char *dst, const char *src, size_t dsize);