add 3 lectures for SFedU

This commit is contained in:
Edward Emelianov
2021-11-11 20:44:40 +03:00
parent 5d6974b950
commit 0d8fbff1dd
238 changed files with 2746 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
//usr/bin/gcc $0 && exec ./a.out "$@"
#include <stdio.h>
int main(int argc, char **argv){
for(int x = 1; x < argc; ++x)
printf("arg %d is %s\n", x, argv[x]);
printf("Done\n");
return 0;
}

View File

@@ -0,0 +1,12 @@
#!/bin/bash
function chkargs(){
echo "you give $# arguments:"
for arg in "$@"; do
echo -e "\t$arg"
done
}
chkargs "$@"
chkargs "$*"
chkargs $*

View File

@@ -0,0 +1,6 @@
#!/bin/bash
array=(1 2 3 4 [5]=next [10]=last)
echo "array with size ${#array[*]} and indexes ${!array[*]}: ${array[*]}"
echo "array[4]=${array[4]}, array[10] len=${#array[10]}"

View File

@@ -0,0 +1,15 @@
BEGIN {
print "List of users and shells"
print " UserName \t HomePath"
print "-----------------------"
FS=":"
}
{
print $1 " \t " $6
}
END {
home=ENVIRON["HOME"]
name=ENVIRON["USER"]
print "-----------------------"
print "Your name is " name " and home is " home
}

View File

@@ -0,0 +1,11 @@
{
if ($1 > 20)
{
x = $1 * 2
print x
} else
{
x = $1 / 2
print x
}
}

View File

@@ -0,0 +1,11 @@
#!/bin/bash
while [ -n "$1" ];do
case "$1" in
-a) echo "Found the -a option" ;;
-b) echo "Found the -b option" ;;
-c) echo "Found the -c option" ;;
*) echo "$1 is not an option" ;;
esac
shift
done

View File

@@ -0,0 +1,7 @@
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 LEN - get random number with length LEN"
exit 1
fi
cat /dev/urandom | tr -dc '0-9' | fold -w $1 | head -n 1

View File

@@ -0,0 +1,10 @@
#!/bin/sh
for ((nl = 1; nl < 1001; ++nl)); do
one=$((RANDOM % 1001))
two=$((RANDOM % 41 - 20))
#three=$(echo "scale=3; $((SRANDOM % 100001)) / 1000" | bc -l)
R=$((SRANDOM % 100001))
three=$(echo "$R" | awk '{printf "%.3f", $1/1000}')
echo -e "$nl\t$one\t$two\t$three"
done

View File

@@ -0,0 +1,8 @@
#!/bin/sh
OUT=1000strings
./ex2 1000 > $OUT
for ((i = 2; i < 5; ++i)); do
sort -n -k $i $OUT > ${OUT}_$i
done

View File

@@ -0,0 +1,22 @@
#!/bin/sh
if [ $# -ne 1 ]; then echo "Usage: $0 word"; exit 1; fi
TOTAL=0
miss=0; hit=0;
while true; do
TOTAL=$((TOTAL+1))
ans=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 100 | head -n1 | grep $1)
if [ -x$ans = -x ]; then
miss=$((miss+1))
else
echo "$ans"
hit=$((hit+1))
fi
[ $hit -ge 5 -o $TOTAL -ge 10000 ] && break
done
part=$(echo "$hit $TOTAL" | awk '{ printf "%.2f", $1*100/$2}')
echo "Miss: $miss, Hit: $hit (${part}%)"

View File

@@ -0,0 +1,19 @@
#!/bin/bash
echo -e "\t1."
for (( a = 1; a < 11; ++a )); do
echo "a=$a"
done
echo -e "\n\t2."
for a in $(seq 1 10); do
echo "a=$a"
done
echo -e "\n\t3."
for a in one "two args" three; do
echo "a=$a"
done

View File

@@ -0,0 +1,15 @@
#!/bin/bash
echo "Enter value"
read val
if [ $val -gt 100 ]; then
echo "value $val greater than 100";
else
echo "value $val less than 100";
fi
echo "Enter filename"
read f
[ -d $f ] && echo "$f is a directory"
[ -f $f ] && echo "$f is a file"
[ ! -e $f ] && echo "Not exists"

View File

@@ -0,0 +1,43 @@
#!/bin/bash
# array with filter positions (0 - hole, 1 - B, 2 - V, 3 - R, 4 - r')
POSITIONS=( 1 2 3 )
# array with expositions (in milliseconds!!!) for each position from POSITIONS
EXPTIME=( 600000 300000 400000 )
# array with focus (mm*10000) for each position
FOCUS=( 45000 45500 45300 )
# array size
len=${#POSITIONS[*]}
__x=0
function chkweather(){
local y=$__x
__x=$((__x+1))
return $y
}
function move_focuser(){
echo "move focuser to $1"
}
function move_turret(){
echo "move turret to $1"
}
function capture_frame(){
echo "capture frame with exposition $1 to file prefix $2"
}
function take_image(){
for (( i=0; i<$len; i++ )); do
move_focuser ${FOCUS[i]}
move_turret ${POSITIONS[i]}
capture_frame ${EXPTIME[i]} filename
done
}
while chkweather; do
take_image
done
echo "stop_observations"

View File

@@ -0,0 +1,7 @@
#!/bin/bash
while read X; do
echo "You entered: $X"
done
echo "End"

View File

@@ -0,0 +1,6 @@
function C = checkX(x)
if(x < -5) C = sprintf("%d less than -5\n", x);
elseif (x > 5) C = sprintf("%d more than 5\n", x);
else C = sprintf("%d between -5 and 5\n", x);
endif;
endfunction

View File

@@ -0,0 +1,7 @@
1 3
2 12
3 56
4 0
9 11
12 5

View File

@@ -0,0 +1,5 @@
3 12
5 15
10 20
11 1
15 2

View File

@@ -0,0 +1,7 @@
22 12
30 32
33 11
45 1
46 5
70 112
80 32

View File

@@ -0,0 +1,53 @@
110 19 -7 4.50 1635722064
120 17 -22 4.20 1635722064
121 15 -13 4.46 1635722064
130 22 -17 4.37 1635722064
140 25 -10 4.34 1635722064
141 27 -4 4.43 1635722064
150 27 4 4.58 1635722064
151 25 10 4.73 1635722064
170 10 25 4.86 1635722064
171 17 22 4.78 1635722064
200 4 27 4.87 1635720574
210 -4 27 4.86 1635720574
211 -10 25 4.83 1635720574
220 -17 22 4.78 1635722069
221 -22 17 4.71 1635722069
230 -25 10 4.56 1635722069
240 -27 -4 4.40 1635722069
241 -27 4 4.51 1635722069
260 -22 -17 4.18 1635722069
261 -17 -22 4.25 1635722069
270 -10 -25 4.11 1635722069
271 -4 -27 4.04 1635722069
300 -3 -20 4.22 1635722075
301 -10 -17 4.29 1635722075
310 -15 -13 4.39 1635722075
320 -19 -7 4.51 1635722075
321 -20 0 4.61 1635722075
330 -19 7 4.62 1635722075
340 -15 13 4.70 1635722075
341 -10 17 4.84 1635722075
350 -3 20 4.89 1635722075
400 9 9 4.80 1635722081
410 3 13 4.88 1635722081
420 -9 9 4.78 1635722081
421 -3 13 4.92 1635722081
430 -13 3 4.71 1635722081
440 -13 -3 4.59 1635722081
450 -9 -9 4.52 1635722081
451 -3 -13 4.44 1635722081
460 3 -13 4.51 1635722081
470 3 -20 4.33 1635722081
500 4 -27 4.09 1635722083
510 10 -17 4.35 1635722083
511 10 -25 4.23 1635722083
520 9 -9 4.57 1635722083
530 3 -5 4.61 1635722083
540 -3 -5 4.59 1635722083
541 -6 0 4.69 1635722083
550 -3 5 4.72 1635722083
560 3 5 4.84 1635722083
561 6 0 4.70 1635722083
570 13 -3 4.69 1635722083
571 13 3 4.80 1635722083

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

View File

@@ -0,0 +1,53 @@
#!/bin/bash
#
# run it like
# ./plot 19.12.25/11\:20_T0.dat
#
OUT=tmpfile.txt
awk '{print $2 "\t" $3 "\t" $4}' $1 > $OUT
DATE=$(echo $1 | sed -e 's|/| |' -e 's|_.*||')
TX=$(echo $1 | sed 's|.*_\(.*\).dat|\1|')
if [ $TX = "T0" ]; then Tname="TOP side"
else Tname="BOTTOM side"
fi
VAL=$(head -n1 $1 | awk '{print $4}')
echo -e "30\t30\t$VAL\n-30\t-30\t$VAL" >> $OUT
cat << EOF > gnutplt
#!/usr/bin/gnuplot
set contour
unset surface
set cntrparam order 4
set cntrparam bspline
#set cntrparam levels auto 6
#set cntrparam levels incremental -30,0.1,30
set view map
set size square
set xrange [-40:40]
set yrange [-40:40]
set dgrid3d 100,100,4
set table "contour.txt"
splot '$OUT' u 1:2:3
unset table
unset contour
set surface
set table "dgrid.txt"
splot '$OUT' u 1:2:3
unset table
reset
set terminal jpeg enhanced size 1024,768
set output "$TX.jpg"
set size square
set xrange [-30:30]
set yrange [-30:30]
set xlabel "X, dm"
set ylabel "Y, dm"
set title "Mirror temperature $TX for $DATE ($Tname)"
set pm3d map
unset key
circle(x,y,z) = x**2+y**2 > 900 ? NaN : z
splot 'dgrid.txt' u 1:2:(circle(\$1,\$2,\$3)) w pm3d, 'contour.txt' u 1:2:(circle(\$1,\$2,\$3)) w l lc rgb "black", '$OUT' u 1:2:(circle(\$1,\$2,\$3)):3 with labels font ",8"
EOF
chmod 755 gnutplt
./gnutplt
rm -f gnutplt $OUT contour.txt dgrid.txt

View File

@@ -0,0 +1,3 @@
%x = [0:0.1:2*pi];
y = cos(x);
plot(x,y);

View File

@@ -0,0 +1,5 @@
if(!exist("x", "var"))
x = [0:0.1:2*pi];
endif
y = cos(x);
plot(x,y);