Hey,
I guess I am just to stupid and am not seeing the "wood for the trees", but I am always getting strange errors.
I want to create a mesh with coordinates like:
x y z
3.1 3.0 0.75 0 0 1
3.1 2.9 0.75 0 0 1
3.1 2.8 0.75 0 0 1
3.1 2.7 0.75 0 0 1
3.0 3.0 0.75 0 0 1
3.0 2.9 0.75 0 0 1
3.0 2.8 0.75 0 0 1
3.0 2.7 0.75 0 0 1
Here is my skript:
echo "Abstand Berechnungspunkte in Meter="
read abstand
z=0.75
a=0
b=0
c=1
for (( i=$abstand; i<0; i=$i+$abstand ))
do
for (( h=$abstand; h<4.61; h=$h+$abstand ))
do
x=`echo "-3.616+$i" |bc -l `
y=`echo "-0.085+$h" |bc -l `
print $x " " $y " " $z " " $a " " $b " " $c
done
done
or I also tried this one:
echo "Abstand Berechnungspunkte in Meter="
read abstand
z=.75
a=0
b=0
c=1
ab=$abstand
i=-3.616
h=0
maxx=0
maxy=4.61
while [ $i -le $maxx ]
do
x=`echo "-3.616+$i" |bc -l`
i=`echo "$i+$ab" |bc -l`
done
But it is always creating the same problem regarding numbers with commata. Becasue my input is e.g., 0.02
line 11: ((: i=0.1: syntax error: invalid arithmetic operator (error token is ".1")
Does anyone has an idea? Thanks for any help and sorry for the stupid question,
Sam
The shell will not allow you to loop using a floating point value. As a general rule floating point values should not be used in loop counters even when the language allows it.
ok. thanks.
Do you then have an idea how to realize such a grid by a loop easily?
And thanks for your reply, sam
A possible work-around: convert all meter into centimeter values, e.g. by means of sed or awk :o
My Deutsch isn't all that great, so to make sure I'm clear on what you're doing here - you want to find the number of steps between between two constant values.
Isn't this essentially a division problem? For example if the abstand=2, your xmax is 6 and your ymax is 4 the output table would be:
6 4 0.75 0 0 1
6 2 0.75 0 0 1
6 0 0.75 0 0 1
4 4 0.75 0 0 1
4 2 0.75 0 0 1
4 0 0.75 0 0 1
2 4 0.75 0 0 1
2 2 0.75 0 0 1
2 0 0.75 0 0 1
0 4 0.75 0 0 1
0 2 0.75 0 0 1
0 0 0.75 0 0 1
Also, are you limited to using a shell script? The only way I know of to do floating point comparisons in bash is pretty kludgy. If you have perl available and my understanding is correct I could definitely create a script to handle this.
This would only push the failure point to millimeters.
Even floating point has a failure point. The question is how much accuracy is necessary.
Math::BigFloat could express atoms in meters, so I figured that wouldn't be an issue. Likewise, I assumed that more than a couple of decimal places were necessary. If this is just for a limited degree of accuracy an expr or bc kludge would be sufficient, but I wouldn't want to maintain it.
thanks, right. I am stupid...
But there is another problem. Do you know how the right syntax has to eb for such a for-loop in bash. Because the while-loop doesn't work equally.
And I am always getting errors. Do you have any idea how to transfer maybe my for-loop into another loop? Or do I have to use "["?
Thanks for help,
Sam
Here is how to do it in ksh93.
#!/bin/ksh93
float abstand=0.1
float i
float h
for (( i=3.1; i >= 3.0; i-=abstand ))
do
for (( h=3.0; h >= 2.7; h-=abstand ))
do
printf "%1.1f %1.1f 0.75 0 0 1\n" i h
done
done
Output is
3.1 3.0 0.75 0 0 1
3.1 2.9 0.75 0 0 1
3.1 2.8 0.75 0 0 1
3.1 2.7 0.75 0 0 1
3.0 3.0 0.75 0 0 1
3.0 2.9 0.75 0 0 1
3.0 2.8 0.75 0 0 1
3.0 2.7 0.75 0 0 1
ok. but the problem is, i am only having mksh and the I am never able to get the AT&T ksh93, because of their license problems....
So Do you know how the syntax should be for a for-loop in mksh? (mksh even doesn't know float then "for ((")
Thanks again for your help