summaryrefslogtreecommitdiff
path: root/packages/base/src/C
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/C')
-rw-r--r--packages/base/src/C/vector-aux.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/base/src/C/vector-aux.c b/packages/base/src/C/vector-aux.c
index 7cdc750..f1bb371 100644
--- a/packages/base/src/C/vector-aux.c
+++ b/packages/base/src/C/vector-aux.c
@@ -12,6 +12,7 @@ typedef float complex TCF;
12#include <string.h> 12#include <string.h>
13#include <math.h> 13#include <math.h>
14#include <stdio.h> 14#include <stdio.h>
15#include <stdlib.h>
15 16
16#define MACRO(B) do {B} while (0) 17#define MACRO(B) do {B} while (0)
17#define ERROR(CODE) MACRO(return CODE;) 18#define ERROR(CODE) MACRO(return CODE;)
@@ -648,4 +649,49 @@ int zipQ(int code, KQVEC(a), KQVEC(b), QVEC(r)) {
648 } 649 }
649} 650}
650 651
652////////////////////////////////////////////////////////////////////////////////
653
654int vectorScan(char * file, int* n, double**pp){
655 FILE * fp;
656 fp = fopen (file, "r");
657 int nbuf = 100*100;
658 double * p = (double*)malloc(nbuf*sizeof(double));
659 int k=0;
660 double d;
661 int ok;
662 for (;;) {
663 ok = fscanf(fp,"%lf",&d);
664 if (ok<1) {
665 break;
666 }
667 if (k==nbuf) {
668 nbuf = nbuf * 2;
669 p = (double*)realloc(p,nbuf*sizeof(double));
670 //printf("R\n");
671 }
672 p[k++] = d;
673 }
674 *n = k;
675 *pp = p;
676 fclose(fp);
677 OK
678}
679
680int saveMatrix(char * file, char * format, KDMAT(a)){
681 FILE * fp;
682 fp = fopen (file, "w");
683 int r, c;
684 for (r=0;r<ar; r++) {
685 for (c=0; c<ac; c++) {
686 fprintf(fp,format,ap[r*ac+c]);
687 if (c<ac-1) {
688 fprintf(fp," ");
689 } else {
690 fprintf(fp,"\n");
691 }
692 }
693 }
694 fclose(fp);
695 OK
696}
651 697