forked from Ryanwall15/CS344-Matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom
More file actions
216 lines (162 loc) · 3.37 KB
/
Copy pathrandom
File metadata and controls
216 lines (162 loc) · 3.37 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
#echo "All parameters: $@"
#echo "Parameter 1: $1"
#echo "Parameter 2: $2"
#echo "Parameter 3: $3"
tempCol="tempcolfile"
tempRow="temprowfile"
tempMean="tempmeanfile"
if (( "$#" > 3 ))
then
echo "Matrix has too many arguments" 1>&2
exit 1
fi
: <<'END'
elif [ $# -gt 1 ]
then
fileOne=$2
fileTwo=$3
elif [ $# -eq 1 ]
then
fileOne=tmp
cat > $fileOne
#echo "Cat has finished"
fi
END
#function for dims
dims()
{
lineNum=0
while read myLine
do
lineNum=`expr $lineNum + 1`
done <$fileOne
numcol=$( head -n 1 $fileOne | wc -w) #count number of numbers in first line (-n 1) of input file provided from first argument
echo -e "$lineNum $numcol"
}
#function for transpose
transpose()
{
lineNum=0
i=1
numcol=$( head -n 1 $fileOne | wc -w)
while [[ "$i" -le "$numcol" ]]
do
cut -f $i $fileOne > $tempCol
cat $tempCol | tr -s '\n' '\t' > "$tempRow"
rev "$tempRow" >"temp222"
cat "temp222" | cut -c 2- >"temp333"
rev "temp333">$tempRow
#echo >> "$tempRow"
cat $tempRow
#cat -A $tempRow
i=`expr $i + 1`
done
}
add()
{
echo "Add function"
}
mean()
{
i=1
numcol=$( head -n 1 $fileOne | wc -w)
echo "Number Col: $numcol"
while [[ $i -le $numcol ]]
do
sum=0
cut -f $i $fileOne > $tempCol
while read num
do
sum=`expr $sum + $num`
mean=`expr $sum / 2`
done <$tempCol
echo $mean > $tempRow
cat $tempRow | tr -s '\t' > $tempMean
echo >> "$tempMean"
i=$((i+1))
cat $tempMean
done
}
mulitply()
{
echo "Multiply Function"
}
#Executing dims and mean
if [ $1 = "dims" ] || [ $1 = "mean" ]
then
if (("$#" > 2 ))
then
echo "Invalid number of arguments" 1>&2
exit 1
fi
if [ $# -gt 1 ]
then
fileOne=$2
fileTwo=$3
fi
if [ $# -eq 1 ]
then
fileOne=tmp
cat > $fileOne
#echo "Cat has finished"
fi
if [ ! -f $2 ]
then
echo "Invalid file" 1>&2 #Redirects stdout to stderr 1>&2
exit 1
fi
if [ $1 = "dims" ]
then
dims $fileOne
fi
if [ $1 = "mean" ]
then
mean $fileOne
fi
fi
#Executing transpose
if [ $1 = "transpose" ]
then
if (( "$#" > 2 ))
then
echo "Invalid number of arguments" 1>&2
exit 1
elif [ $# -gt 1 ]
then
fileOne=$2
fileTwo=$3
elif [ $# -eq 1 ]
then
fileOne=tmp
cat > $fileOne
#echo "Cat has finished"
fi
if [ ! -r $2 ]
then
echo "Invalid file" 1>&2 #Redirects stdout to stderr 1>&2
exit 1
fi
transpose $fileOne
fi
#Executing add
if [ $1 = "add" ]
then
echo "in Add"
if [ $# -eq 0 ]
then
echo "No arguments to add" 1>&2
exit 1
fi
if [ $# -ne 2 ]
then
echo "Invalid number of arguments" 1>&2
exit 1
fi
if [ ! -r $2 ] || [ ! -r $3 ]
then
echo "Invalid file" 1>&2
exit 1
fi
add $fileOne $fileTwo
fi