File: readfile.c

package info (click to toggle)
cufflinks 1.3.0-2
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 3,864 kB
  • sloc: cpp: 48,999; ansic: 12,297; sh: 3,381; python: 432; makefile: 209
file content (81 lines) | stat: -rw-r--r-- 1,837 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 *   Copyright (c) 1996-2000 Lucent Technologies.
 *   See README file for details.
 *
 *
 *
 *   Function to read and create Locfit variables from an ASCII file.
 *
 *   Command syntax:
 *     locfit> readfile filename v1 v2 v3
 *   filename is the file to be read (no default extension or path is added).
 *   v1 v2 v3  etc are the names of the variables to create.
 *
 *   File format: The file should be a plain ASCII file organized
 *     in matrix format, with one variable per column and one observation
 *     per row. Fields are separated by spaces.
 *     
 */

#include "local.h"

extern char filename[];
static FILE *aaa;

void readfile(vc)
vari *vc;
{ int i, j, k, n, nv;
  char wc[50], *fn;
  double *dpr;
  vari *v;

  i = getarg(vc,"file",1);
  if (i==0)
  { ERROR(("readfile: no file"));
    return;
  }

  fn = argval(vc,i);
  setfilename(fn,"","r",0);
  if (lf_error) return;

  i = getarg(vc,"arith",0); /* now automatic - leave for backward compat. */

  aaa = fopen(filename,"r");
  v = createvar("readfile",STREADFI,0,VDOUBLE);

  n = 0;
  do
  { k = fscanf(aaa,"%s",wc);
    if (k==1)
    { vassn(v,n,darith(wc));
      n++;
    }
  } while (k==1);
  fclose(aaa);
  dpr = vdptr(v);
  deletevar(v);

  nv = 0;
  for (i=1; i<vlength(vc); i++)
    if (!argused(vc,i)) nv++;
  if (nv==0) { ERROR(("readfile: no variables specified")); return; }
  if (n%nv != 0)
    WARN(("number of items not multiple of number of variables"));

  n /= nv;
  transpose(dpr,n,nv);
  nv = 0;
  for (i=1; i<vlength(vc); i++)
    if (!argused(vc,i))
    { v = createvar(argval(vc,i),STREGULAR,n,VDOUBLE);
      if (v==NULL) return;
      for (j=0; j<n; j++) vassn(v,j,dpr[nv*n+j]);
      nv++;
      if (lf_error) return;
    }
  if (argarg(vc,0)!=NULL)
    dosavedata(vc,0);
  else
    for (i=1; i<vlength(vc); i++) setused(vc,i);
}