5 #include <cuda_runtime.h>
6 #include "../include/fileIO.h"
11 * Reads datafile into memory.
13 double2* readIn(std::string fileR, std::string fileI,
16 f = fopen(fileR.c_str(),"r");
18 double2 *arr = (double2*) malloc(sizeof(double2)*gSize);
20 while(fscanf(f,"%lE",&line) > 0){
25 f = fopen(fileI.c_str(),"r");
27 while(fscanf(f,"%lE",&line) > 0){
36 * Writes out the parameter file.
38 void writeOutParam(std::string buffer, Grid &par, std::string file){
42 sprintf((char *)buffer.c_str(), "%s", file.c_str());
43 f = fopen(file.c_str(),"w");
44 fprintf(f,"[Params]\n");
45 for (size_t i = 0; i < arr.used(); ++i){
46 fprintf(f,"%s=",arr.array[i].title);
47 fprintf(f,"%e\n",arr.array[i].data);
54 * Writes out double2 complex data files.
56 void writeOut(std::string buffer, std::string file, double2 *data,
57 int length, int step){
59 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
60 f = fopen (buffer.c_str(),"w");
62 for (i = 0; i < length; i++)
63 fprintf (f, "%.16e\n",data[i].x);
66 sprintf ((char *)buffer.c_str(), "%si_%d", file.c_str(), step);
67 f = fopen (buffer.c_str(),"w");
68 for (i = 0; i < length; i++)
69 fprintf (f, "%.16e\n",data[i].y);
75 * Writes out double type data files.
77 void writeOutDouble(std::string buffer, std::string file, double *data,
78 int length, int step){
80 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
81 f = fopen (buffer.c_str(),"w");
83 for (i = 0; i < length; i++)
84 fprintf (f, "%.16e\n",data[i]);
89 * Writes out bool type data files.
91 void writeOutBool(std::string buffer, std::string file, bool *data,
92 int length, int step){
94 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
95 f = fopen (buffer.c_str(),"w");
97 for (i = 0; i < length; i++)
98 fprintf (f, "%u\n",data[i]);
103 * Writes out int type data files.
105 void writeOutInt(std::string buffer, std::string file, int *data,
106 int length, int step){
108 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
109 f = fopen (buffer.c_str(),"w");
111 for (i = 0; i < length; i++)
112 fprintf (f, "%d\n",data[i]);
117 * Writes out int2 data type.
119 void writeOutInt2(std::string buffer, std::string file, int2 *data,
120 int length, int step){
122 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
123 f = fopen (buffer.c_str(),"w");
125 for (i = 0; i < length; i++)
126 fprintf (f, "%d,%d\n",data[i].x,data[i].y);
131 * Writes out tracked vortex data.
133 void writeOutVortex(std::string buffer, std::string file,
134 std::vector<std::shared_ptr<Vtx::Vortex>> &data, int step){
136 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
138 f = fopen (buffer.c_str(),"w");
141 fprintf (f, "#UID,X,Xd,Y,Yd,WINDING,isOn\n");
142 for (i = 0; i < data.size(); i++)
143 //fprintf (f, "%d,%d,%e,%d,%e,%d\n",data[i]->getUID(),data[i]->getCoords().x,data[i]->getCoordsD().x,data[i]->getCoords().y,data[i]->getCoordsD().y,data[i]->getWinding());
144 fprintf (f, "%d,%e,%d,%e,%d\n",data[i]->getCoords().x,data[i]->getCoordsD().x,data[i]->getCoords().y,data[i]->getCoordsD().y,data[i]->getWinding());
149 * Opens and closes file. Nothing more. Nothing less.
151 int readState(std::string name){
153 f = fopen(name.c_str(),"r");
159 * Outputs the adjacency matrix to a file
161 void writeOutAdjMat(std::string buffer, std::string file, int *mat, unsigned int *uids, int dim, int step){
163 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
164 f = fopen (buffer.c_str(),"w");
166 for(int ii = 0; ii<dim; ++ii){
167 fprintf (f, "%d",uids[ii]);
171 for(int ii = 0; ii < dim; ++ii){
173 for(int jj = 0; jj < dim; ++jj){
174 fprintf (f, "%i",mat[ii*dim + jj]);
187 void writeOutAdjMat(std::string buffer, std::string file, double *mat,
188 unsigned int *uids, int dim, int step){
190 sprintf ((char *)buffer.c_str(), "%s_%d", file.c_str(), step);
191 f = fopen (buffer.c_str(),"w");
193 for(int ii = 0; ii<dim; ++ii){
194 fprintf (f, "%d",uids[ii]);
196 /* I am not sure what Lee wants here, but I think...
197 fprintf (f, ",",uids[ii]); */
203 for(int ii = 0; ii < dim; ++ii){
205 for(int jj = 0; jj < dim; ++jj){
206 fprintf (f, "%e",mat[ii*dim + jj]);