tadd missing transpose.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 e6a23d29b0e98397210e40824f9f37929eb60c2b
 (DIR) parent 5b24cf0f0de9c6d52fa609cb59e025d2706e2e7e
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Sun, 12 Sep 2021 07:16:51 +0200
       
       add missing transpose.c
       
       Diffstat:
         A transpose.c                         |      48 +++++++++++++++++++++++++++++++
       
       1 file changed, 48 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/transpose.c b/transpose.c
       t@@ -0,0 +1,48 @@
       +#include <err.h>
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <unistd.h>
       +
       +#include "util.h"
       +
       +int
       +main(void)
       +{
       +        size_t i = 0, j = 0, nf = 0, nr = 0, linesize = 0;
       +        char *line = NULL, *data = NULL;
       +        double val, **vals = NULL;
       +
       +        if (pledge("stdio", NULL) == -1)
       +                err(2, "pledge");
       +
       +        vals = calloc(1, sizeof(double *));
       +        while (getline(&line, &linesize, stdin) > 0) {
       +                if (nr > 0)
       +                        if (!(vals = xreallocarray(vals, nr + 1, sizeof(double *))))
       +                                err(1, "reallocarray");
       +                if ((nf = allocarr(&vals[nr], line, linesize)) == 0)
       +                        errx(1, "no fields in input");
       +                data = line;
       +                for (i = 0; i < nf; i++) {
       +                        if (!scannextval(&data, &val))
       +                                errx(1, "could not parse line %ld, field %ld", nr + 1, i + 1);
       +                        vals[nr][i] = val;
       +                }
       +                nr++;
       +        }
       +        for (i = 0; i < nf; i++) {
       +                for (j = 0; j < nr; j++) {
       +                        printf("%g", vals[j][i]);
       +                        if (j < nr - 1)
       +                                printf(DELIMSTR);
       +                }
       +                puts("");
       +        }
       +
       +        free(line);
       +        for (i = 0; i < nr; i++)
       +                free(vals[i]);
       +        free(vals);
       +
       +        return 0;
       +}