LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-20-2005, 11:36 AM   #1
karistouf
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Rep: Reputation: 0
expert help needed with bash and bc


hello everybody, i m writting a little bash script to render animations with BMRT 2.6.

The script replace a Keyword by the mathematical value issued from the valuestrat and the valueend , on a certain number of images we want.

I have a main problem, as bash is not treating the float caculations is that:
- using bc I have all the time an input error when i give bc float variables
-only bc is the problem, when we enter integer there is no problem
-i tried the eof way to code wich give same result
-i want to have the less dependencies and want to arrive to work only thruth bash and bc only, that the script can be use from any Linux machine without having any special dependencies or libraries to load

-by the way I use convert from Image magick to chang tiff generated in png, to assembl them under blender in AVI file

Thanks for your help

Christoph



#!/bin/bash
#dependances: bc imagemagick
function CONCATANATE {
COUNTER=0
while [ $COUNTER -lt $NbImages ] ;
do
cat SEQ_$NomFichier/Temp_$NomFichier$COUNTER | sed s/ImageNum/$COUNTER/g | sed s/"FrameBegin 1"/"FrameBegin $COUNTER"/g | cat >> SEQ_$NomFichier/OUTPUT_CONCAT_$NomFichier
let COUNTER=COUNTER+1
done
echo Concatenation OK dans le fichier SEQ_$NomFichier/OUTPUT_CONCAT_$NomFichier
}


function REPLACE {
if [[ $VariableEnd -gt $VariableBegin ]]
then
CURVAR=$(echo "scale=6; (($VariableEnd - $VariableBegin)/$NbImages)*$COUNTER" |bc)
echo $Variable $CURVAR
fi
if [[ $VariableBegin -ge $VariableEnd ]]
then
CURVAR=$(echo "scale=6; ((($VariableBegin - $VariableEnd)/$NbImages)*($NbImages - $COUNTER))" |bc )
echo $Variable $CURVAR
fi

if [[ $ENTREE -le $NbVariables ]]
then
if [[ $ENTREE -eq 1 ]]
then
echo Image $COUNTER Replacement de $Variable
( cat SEQ_$NomFichier/BASE_$NomFichier | sed s/$Variable/$CURVAR/g ) > SEQ_$NomFichier/Temp_$NomFichier$COUNTER
else
if [[ $ENTREE -gt 1 ]]
then
( cat SEQ_$NomFichier/Temp_$NomFichier$COUNTER | sed s/$Variable/$CURVAR/g ) > SEQ_$NomFichier/Temp_$NomFichier$COUNTER_bis
cp SEQ_$NomFichier/Temp_$NomFichier$COUNTER_bis SEQ_$NomFichier/Temp_$NomFichier$COUNTER
rm SEQ_$NomFichier/Temp_$NomFichier$COUNTER_bis
fi
fi
fi


}


function RENDER {
rendrib SEQ_$NomFichier/OUTPUT_CONCAT_$NomFichier
}

function CONVERSION {
echo "conversion tif en png"
for i in 'ls *.tif'
do
echo conversion en cours $NomFichier.png ...
convert $i png: SEQ_$NomFichier/$NomFichier.png
echo Ok
done
}

function ENTREEVARIABLES {

while [ $ENTREE -le $NbVariables ] ;
do
echo "*** Entrer la variable a changer :"
read Variable
echo "Entrer Valeur de depart de $Variable"
read VariableBegin
echo "Entrer Valeur d arrivee de $Variable"
read VariableEnd
while [ $COUNTER -le $NbImages ] ;
do
REPLACE
let COUNTER=COUNTER+1
done
let ENTREE=ENTREE+1
COUNTER=0
done
while [ $COUNTER -le $NbImages ] ;
do
REPLACE
let COUNTER=COUNTER+1
done
}

export SHADERS=/usr/local/shaders
echo "Entrer le nom du fichier a traiter :"
read NomFichier
mkdir SEQ_$NomFichier
cp $NomFichier SEQ_$NomFichier/BASE_$NomFichier
echo "Entrer le nombre d images :"
read NbImages
echo "Entrer le nombre de variables :"
read NbVariables


#obligation d'initialiser les variables
COUNTER=0
ENTREE=1

ENTREEVARIABLES
CONCATANATE
RENDER
CONVERSION

echo OK
unset COUNTER
unset ENTREE
unset NbVariables
unset NbImages
unset NomFichier
 
Old 06-20-2005, 05:36 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I tried one of your bc calculations using constant values, it works without an error (no idea if it's the right numerical answer though). This would seem to suggest to me that one of the variables in the calculations doesn't contain a proper numberical value for bc and hasn't been set proper. Maybe something for you to explore, maybe not

Code:

#!/bin/bash

VariableEnd=200.456789
VariableBegin=399.433

COUNTER=20
NbImages=4

CURVAR=$(echo "scale=6; ((($VariableEnd -  $VariableBegin)/$NbImages) * ($NbImages - $COUNTER)) " | bc)

echo $CURVAR

#This Works okay
Code:
#!/bin/bash

VariableEnd=200.456789
VariableBegin=399.433

COUNTER=20
NbImages=""   #not a numerical value

CURVAR=$(echo "scale=6; ((($VariableEnd -  $VariableBegin)/$NbImages) * ($NbImages - $COUNTER)) " | bc)

echo $CURVAR


#This doesn't work Parse Error

Last edited by Looking_Lost; 06-20-2005 at 05:37 PM.
 
Old 06-21-2005, 02:45 AM   #3
karistouf
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
hi , and thanks for your interrest and help.

as this script is made for generating animation I will explain more precisely its utility and finality:

to create an animation , i use bmrt render machine wich generate tif

we say for example that our animation is at a frame rate of 25 images per second ( or 30 for usa or japan)

this value is an integer and never be a float value.


Imagine that the .rib file we will treat as in its code a sphere( rib and renderman language are declaration you can write in a vim editor or anything else):

Translate 2 -1.13 0
Sphere 360 ...

I first have made design / modeling thruth Ayam3d and then exported the file in rib language

This file will be treated by rendrib ( the renderer) and generate ONE image

To make animation I will first edit my rib file and change the value I want to affect by a KEYWORD:

Translate TX -1.13 0
Sphere 360...

Then I will call the script:
-script ask first wich file I want to treat
-then number of total images I want to generate ( if I want an animation of 2seconds it would be 50 images)
-and then ask how many wariables I want to change: say ONE ( we have created only one keyword)
-and finally at wich value at the begin ( first frame) it will be ; and wich value TX will be on last frame
-substitution is done then to replace TX by the value that is CURVAR
-images are generated

I agree with you that there is something wrong. I used the option scale with bc but also i tryed to scale at 6 and I tried with values start and end being for example 0.546821 and 3.514759. It stills receiving this as an error.

I still do not understand why, as read fonction rechoes the right value you will type as float.
untill now i did nt arrived to solve this problem. Wich is quite annoying, as float values are very used often in renderman object, and that if you produce 2 animations that are supposed to be edited together at the end in one avi file, you need to be precise.
( example: my ball will FIRST go to right, THEN go up)
By using Ayam 3d i have also a very precise tool thuth modeling to compose precisely the frame, and all arguments ( shaders, special funxctions) are in float.

Thanks for your help, and I hope to read you soon.

christoph
 
Old 06-21-2005, 03:01 AM   #4
karistouf
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
still same troubles

okay, i made other test. By simplifing the script as you have done it works.
Also with any float value....

But I have errors when executing the script at line 15 and 20: [[: 5.989786: syntax error in expression (error token is ".989786")
this repeated as many curvar I have ( 5.989786 is one of the resuts of CURVAR)

Do I need to put a sleep or is there a problem of my definition of loops in my script ?

Thanks for your answer.
sincerely yours
christoph
 
Old 06-21-2005, 02:18 PM   #5
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I think it's the if statements bombing out because bash can only do integers.

You can try something like this:

#!/bin/bash

VariableEnd=100.3456
VariableBegin=99.4222

if [ $(echo "scale=6; if($VariableEnd > $VariableBegin) print "1" " | bc) ]; then
echo "Hello, there, dude"
fi

#The print "1" doesn't seem do anything apart from stopping bc complaing (no expert you see) although the if statement appears at
#first sight to evaluate correctly, don't ask me the technical reasons why
 
Old 06-22-2005, 01:55 AM   #6
karistouf
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
its quite logical and i will make a try, the if statement is like in C++ condition that open an other form of logical way .
when you put a if ( like when you make a test with erors : if return=X then ...) you have a direct link to other underfunctions ( well i think its what i understood from previous coding)

Thanks, i keep in touch

sincerely
christoph
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
X11 Expert Needed hilltop*Tech Linux - Hardware 4 06-10-2005 10:11 AM
bash expert help needed illtbagu Programming 15 10-05-2004 09:15 PM
Expert help with iptables needed k1mgy Linux - Networking 2 08-01-2004 08:21 AM
Administrative tools / help needed from an expert! randyriver10 Linux - Software 10 05-09-2004 03:40 PM
Security Expert needed Lloydlec Linux - Security 1 04-27-2004 12:45 PM


All times are GMT -5. The time now is 09:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration