-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatmax
More file actions
executable file
·396 lines (381 loc) · 11.9 KB
/
Copy pathmatmax
File metadata and controls
executable file
·396 lines (381 loc) · 11.9 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/bin/bash
#Copyright 2018 Maxime Jay-Allemand
# This file is part of Statmax.
# Statmax is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Statmax is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Statmax. If not, see <https://www.gnu.org/licenses/>.
pathressource=$(dirname $0)"/lib/"
#cas d'une installation sur le système
if [ -e /usr/local/bin/matmax ]
then
$pathressource=/usr/local/lib/statmax/
fi
if [[ -z $1 ]]
then
echo "Statmax is a tiny statistical software written in awk !"
echo "Statmax is released under the GNU licence"
echo "Type statmax --help to see options"
exit 0
fi
#Liste des arguments
opt=""
kfile=0
until [ $# = 0 ]
do
case $1 in
-m|--mode)
shift
mode="${1}"
shift
;;
-f1|--file1)
shift
file1="${1}"
shift
;;
-f2|--file2)
shift
file2="${1}"
shift
;;
--skipline)
shift
skipline=${1}
shift
opt=$opt" -v skipline="$skipline
;;
--scalefactor)
shift
scalefactor=${1}
shift
opt=$opt" -v scalefactor="$scalefactor
;;
--addscalaire)
shift
addscalaire=${1}
shift
opt=$opt" -v addscalaire="$addscalaire
;;
--scalefunction)
shift
scalefunction=${1}
shift
opt=$opt" -v scalefunction="$scalefunction
;;
--modecompmat)
shift
modecompmat=${1}
shift
opt=$opt" -v modecompmat="$modecompmat
;;
--xdim)
shift
xdim=${1}
shift
opt=$opt" -v xdim="$xdim
;;
--ydim)
shift
ydim=${1}
shift
opt=$opt" -v ydim="$ydim
;;
--cellsize)
shift
cellsize=${1}
shift
opt=$opt" -v cellsize="$cellsize
;;
--xllcorner)
shift
xllcorner=${1}
shift
opt=$opt" -v xllcorner="$xllcorner
;;
--yllcorner)
shift
yllcorner=${1}
shift
opt=$opt" -v yllcorner="$yllcorner
;;
--geomatrix)
shift
geomatrix="geomatrix=1"
shift
opt=$opt" -v "$geomatrix
;;
--xstart)
shift
xstart=${1}
shift
opt=$opt" -v xstart="$xstart
;;
--ystart)
shift
ystart=${1}
shift
opt=$opt" -v ystart="$ystart
;;
--minvalue)
shift
minvalue=${1}
shift
opt=$opt" -v minvalue="$minvalue
;;
--maxvalue)
shift
maxvalue=${1}
shift
opt=$opt" -v maxvalue="$maxvalue
;;
--trunctype)
shift
trunctype=${1}
shift
opt=$opt" -v trunctype="$trunctype
;;
--nan)
shift
nan=${1}
shift
opt=$opt" -v nan="$nan
;;
--datablock)
shift
datablock=${1}
shift
opt=$opt" -v datablock="$datablock
;;
--lstart)
shift
lstart=${1}
shift
opt=$opt" -v lstart="$lstart
;;
--lend)
shift
lend=${1}
shift
opt=$opt" -v lend="$lend
;;
--fs)
shift
fs=${1}
shift
opt=$opt" -F fs="$fs
;;
--awk)
shift
awkparam=${1}
shift
opt=$opt" -v "$awkparam
;;
--help)
echo "Liste des options disponibles :"
echo "-m|--mode :"
echo " * = Action à exécuter dans la liste suivante (défault checkmat) :"
echo " flip : transpose le fichier d'entrée"
echo " diffmat : Différence entre 2 matrices : A-B"
echo " absreldiffmat : différence absolue reltive entre 2 matrice : abs(A-B)/abs(B)"
echo " compmat: comparaison de 2 matrice : centereddiffmat,centeredfracmat,centeredrelativfracmat,centeredreductionfracmat,diffabsoluterelative... and many more see the source code compmat.awk"
echo " addmat : Somme membre à membre de 2 matrice"
echo " prodmat : Produit membre à membre de 2 matrice"
echo " fracmat : fraction membre à membre de 2 matrice (matmax --fracmatrix A B compute A/B)"
echo " scalemat : Mise à l'echelle d'une matrice selon scalefactor*x+addfactor"
echo " derivmat : Calcul la différence entre 2 valeurs consécutives en colonnes"
echo " truncatemat : Tronque les valeurs d'une matrice par une borne min et max"
echo " linearisemat : Linéarise une matrice vers un vecteur"
echo " unlinearisemat : Transforme un vecteur vers une matrice"
echo " initmat : Initialise une matrice"
echo " extractmat : Extrait une partie d'une matrice"
echo " cut : cut datafile from lstart lines to lend line"
echo " checkmat : Vérifie l'intégrité des données d'une matrice"
echo " split : split a datafile by block"
echo " crop: extract/crop/cut matrix values within a path given by w,y corrds. file1 is the matrix. file2 is the path (2 columns wit x and y coords)"
echo ""
echo "*"
echo " Une chaine de caratère seule sera considéré comme étant le chemin relatif ou absolu vers le fichier d'entrée"
echo ""
echo "-f1|--file1"
echo " * = nom du fichier 1 à traiter"
echo ""
echo "-f2|--file2"
echo " * = nom du fichier 2 à traiter"
echo ""
echo "--skipline"
echo " * = nombre de ligne à sauter en début de fichier"
echo ""
echo "--scalefactor"
echo " * = Mise à l echelle par un facteur multiplicateur"
echo ""
echo "--addscalaire"
echo " * = Mise à l echelle par un scalaire que l'on additionne"
echo ""
echo "--scalefunction"
echo " * = Mise à l echelle par une fonction : lineaire, exp, log, sqrt, power, abs"
echo ""
echo "--modecompmat"
echo " * = mode de comparaison du mode compmat : centereddiffmat,centeredfracmat,centeredrelativfracmat,centeredreductionfracmat"
echo ""
echo "--xdim"
echo " * = nombre de lignes"
echo ""
echo "--ydim"
echo " * = nombre de colonnes"
echo ""
echo "--xstart"
echo " * = numéro de lignes"
echo ""
echo "--ystart"
echo " * = numéro de colonnes"
echo ""
echo "--lstart"
echo " * = numéro de ligne de début pour cut"
echo ""
echo "--lend"
echo " * = numéro de ligne de fin pour cut"
echo ""
echo ""
echo "--minvalue"
echo " * = truncate at min value"
echo ""
echo "--maxvalue"
echo " * = truncate at max value"
echo ""
echo "--trunctype"
echo " * = way to tuncate the matrix among these two options :"
echo " [bounds] : by the bounded values"
echo " [nan] : by nan value."
echo " Use --minvalue or --maxvalue as bounded value. If option [bounds], matrix will be toncated toward these minimum or a maximum values. If option [nan], vlues outside bounds will take the nan value. Use --nan to define the nan value"
echo ""
echo "--nan"
echo " * = the nan value, by default it is set to NA."
echo ""
echo "--datablock"
echo " * = the Nht block of the file, by default it is set to NA and the file is splited. All blocks are succesively printed into new numbered files. By default block separators are blank lines. Each block correspond to one different record and the Awk record separator RS control this behavior. By default RS is set to RS= (empty). Thus each blank line are treated as a records separator. The records separator can be adjusted by passing the awk parameter RS. For instance, setting RS='\n' revert the records separator to the standard (i.e newline) and thus each line will be considered as 1 block !"
echo ""
echo "--fs"
echo " * = caractère de séparation des colonnes"
echo ""
echo "--awk"
echo " * = pass any awk parameters. example : --awk='RS=RECORDSEPARATOR'"
exit 0
;;
*)
if [ -e $1 ] && [ -f $1 ]
then
kfile=$((kfile+1))
#It likely input files
eval file$kfile=$1
shift
else
echo "Unknown parameter or file does not exist : " ${i}
echo "type --help to show available options"
exit 1
fi
;;
esac
done
#echo $mode
#echo $file1
#echo $opt
if [ -z $mode ]
then
#si mode est abscent, on print les stats (default)
mode="checkmat"
fi
case $mode in
flip)
#echo "flip matrix"
awk $opt -f ${pathressource}func.awk -f ${pathressource}flip.awk $file1
;;
diffmat)
#echo "Effectue la différence membre à membre de 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}diffmatrix.awk $file1 $file2
;;
absreldiffmat)
#echo "Effectue la différence relative absolue membre à membre de 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}absoluterelativediffmatrix.awk $file1 $file2
;;
compmat)
#echo "Effectue la comparaison entre 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}compmat.awk $file1 $file2
;;
addmat)
#echo "Effectue la somme membre à membre de 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}addmatrix.awk $file1 $file2
;;
prodmat)
#echo "Effectuel le produit membreà membre de 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}prodmatrix.awk $file1 $file2
;;
fracmat)
#echo "Effectuel le produit membreà membre de 2 matrice de meme taille"
awk $opt -f ${pathressource}func.awk -f ${pathressource}fracmatrix.awk $file1 $file2
;;
scalemat)
#echo "met à l'echelle une matrice par un facteur multiplicateur et/ou en addionnant un scalaire"
awk $opt -f ${pathressource}func.awk -f ${pathressource}scalematrix.awk $file1
;;
derivmat)
#echo "met à l'echelle une matrice par un facteur multiplicateur et/ou en addionnant un scalaire"
awk $opt -f ${pathressource}func.awk -f ${pathressource}derivmatrix.awk $file1
;;
truncatemat)
#echo "Tronque un matrice avec une valeur min et/ou max"
if [ -z $minvalue ]
then
minvalue="na"
opt=$opt" -v minvalue="$minvalue
fi
if [ -z $maxvalue ]
then
maxvalue="na"
opt=$opt" -v maxvalue="$maxvalue
fi
awk $opt -f ${pathressource}func.awk -f ${pathressource}truncmatrix.awk $file1
;;
linearisemat)
opt=${opt}" -v mode_linmat=linearise"
awk $opt -f ${pathressource}func.awk -f ${pathressource}linearisematrix.awk $file1
;;
unlinearisemat)
opt=${opt}" -v mode_linmat=unlinearise"
awk $opt -f ${pathressource}func.awk -f ${pathressource}linearisematrix.awk $file1
;;
initmat)
#echo "initialise une matrice"
awk $opt -f ${pathressource}func.awk -f ${pathressource}initmatrix.awk /dev/null
;;
extractmat)
#echo "initialise une matrice"
awk $opt -f ${pathressource}func.awk -f ${pathressource}extractmatrix.awk $file1
;;
cut)
#echo "cut un fichier"
awk $opt -f ${pathressource}func.awk -f ${pathressource}cut.awk $file1
;;
crop)
#echo "cut un fichier"
awk $opt -f ${pathressource}func.awk -f ${pathressource}crop.awk $file1 $file2
;;
checkmat)
#echo "check les données"
awk $opt -f ${pathressource}func.awk -f ${pathressource}checkmatrix.awk $file1
;;
split)
#echo "split un fichier"
opt=" -v RS= "$opt
awk $opt -f ${pathressource}func.awk -f ${pathressource}split.awk $file1
;;
*)
echo "--mode="$mode" : ??? Sorry, this statistic doesn't still exist. But you can code it !"
;;
esac