-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadFile.cpp
More file actions
119 lines (101 loc) · 2.01 KB
/
loadFile.cpp
File metadata and controls
119 lines (101 loc) · 2.01 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//Author Luca Zelioli
//Inclusion
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>
#include <exception>
//local inclusion
#include "loadFile.h"
//Math inclusion
#define _USE_MATH_DEFINES
#include <string>
#include <math.h>
using namespace std;
size_t VectorSize(string filename)
{
size_t temp = NULL;
try
{
//Open the stream
ifstream MyFile(filename);
//check if it is open
if (MyFile.is_open())
{
MyFile >> temp;
}
else
{
std::cout << "Impossible to open the file " + filename << std::endl;
}
return temp;
}
catch (exception& ex)
{
std::cout << "Exception thrown in the function VectorSize " << ex.what() << std::endl;
return NULL;
}
}
//this function is able to create local vector
float* CreateDeviceVector(string filename, size_t size ,bool isAscension)
{
float* vector = nullptr;
float temp = 0;
vector = new float[size];
//insert the index
int idx = 0;
try
{
//start the timer
clock_t startTimer = clock();
//open the stream
ifstream MyFile(filename);
if (MyFile.is_open())
{
for (int i = 0; i < size; i++)
{
//jump the first element
if (i == 0)
{
continue;
}
//insert and transform the data
MyFile >> temp;
temp = temp * 1 / 60 * (float)M_PI / 180.0f;
if (isAscension == true)
{
if (i % 2 == 0)
{
vector[idx] = temp;
idx++;
}
}
else
{
if (i % 2 != 0)
{
vector[idx] = temp;
idx++;
}
}
}
}
else
{
std::cout << "Impossible to open the file stream" << std::endl;
return nullptr;
}
//end the timer
clock_t endTimer = clock();
//calculate the elapsed time
float elapsed = (float)(endTimer - startTimer) / CLOCKS_PER_SEC;
//show
std::cout << "The file " << filename << " was loaded in " << elapsed << std::endl;
return vector;
}
catch (exception& ex)
{
std::cout << "Exception thrown in the function CreateDescensionVector " << ex.what() << std::endl;
return nullptr;
}
}