ExaGeoStat
ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems.
flat_file.c
Go to the documentation of this file.
1 
20 #include "../include/flat_file.h"
21 //***************************************************************************************
22 location* readLocsFile(char *locs_file, int n)
24 
29 {
30 
31  FILE *fp;
32  int i = 0;
33  char *line = NULL;
34  size_t len = 0;
35  ssize_t read;
36  char *pch;
37  location *locations;
38 
39 
40  fp = fopen(locs_file, "r");
41  if (fp == NULL)
42  {
43  printf("cannot read locations file\n");
44  printf("%s: \n",locs_file);
45  return NULL;
46  }
47  else
48  {
49  //Allocate memory
50  locations = (location *) malloc(sizeof(location*));
51  locations->x = (double *) malloc(n * sizeof(double));
52  locations->y = (double *) malloc(n * sizeof(double));
53  }
54 
55  while ((read = getline(&line, &len, fp)) != -1) {
56  pch = strtok(line, ",");
57  while (pch != NULL)
58  {
59  locations->x[i] = atof(pch);
60  pch = strtok (NULL, ",");
61  locations->y[i] = atof(pch);
62  pch = strtok (NULL, ",");
63  }
64  i++;
65  }
66  fclose(fp);
67  if (line)
68  free(line);
69  // zsort_locations(n,locations);
70  return locations;
71 }
72 
73 
74 double * readObsFile(char *obsfile, int n)
76 /* Returns observations struct.
77 * @param[in] obsfile: observation file path.
78 * @param[in] n : number of spatial locations (observations).
79 * @param[out] streamdata: observations vector.
80 */
81 {
82 
83  FILE * fp;
84  char * line = NULL;
85  size_t len = 0;
86  ssize_t read;
87  int count = 0;
88 
89  double *z_vec = (double *) malloc(n * sizeof(double));
90 
91  fp = fopen(obsfile, "r");
92  if (fp == NULL)
93  {
94  printf("cannot open observations file\n");
95  exit(EXIT_FAILURE);
96  }
97 
98  while ((read = getline(&line, &len, fp)) != -1)
99  z_vec[count++]=atof(line);
100 
101  fclose(fp);
102  free(line);
103 
104  return z_vec;
105 }
106 
double * y
Values in Y dimension.
Definition: MLE_misc.h:83
double * x
Values in X dimension.
Definition: MLE_misc.h:82
double * readObsFile(char *obsfile, int n)
Read real observation file.
Definition: flat_file.c:74
location * readLocsFile(char *locs_file, int n)
Read 2D locations from a given.
Definition: flat_file.c:22