Supporting scripts and use with movie

The following scripts generates a short movie and depends on output from an external script, output.sh.

This external script “needs” to be in the same directory as the executing script/frame command, which I understand - in this case - will be under globe/globe_[frame].

Since the supporting script is in my “top movie folder”, I need to define full path to the script (with $(pwd). Or else it’s not found.

Any better way to do this? I tried using -I, but did not succeed.

cat <<eof > globe.sh
gmt begin
   gmt coast -Rg -JG\${MOVIE_FRAME}/20/10c -Gmaroon -Sturquoise -Bg -X0 -Y0
   bash $(pwd)/output.sh 0 60 | gmt plot -Sc.2c -Gred -W -l"well hello (there)"
gmt end
eof

cat <<eof > output.sh
echo \$1 \$2
eof

gmt movie globe.sh -Nglobe -T30 -Fmp4 -Chd -Lf -Pb+ap -Z

rm globe.sh output.sh

This is a constructed example. My real problem involves a gnuplot script (.gpl).

Another thing (which I think is good), is the warning when gmt sees ();

movie [WARNING]: Main script appears to have a sub-shell call $(...) without the leading $: bash /home/anbj/anbj-tmp-7H1/output.sh 0 60 | gmt plot -Sc.2c -Gred -W -l"well hello (there)"

Does it do any checking, or is it always giving a warning if it sees a pair of ()?

Hi,

TIP : you can use ' around EOF to get rid of the \ in front of $

cat << 'EOF' > output.sh
echo $1 $2
EOF

How does bash can run $(pwd)/output.sh when it’s created after ?

For the warning, for some reason it doesn’t like special character in -l"..."
You can probably get rid of it by assigning the string to a variable

label="well hello (there)"
[...] -l$label

The message “Main script appears to have a sub-shell” is a failed attempt to try to figure out if someone tries to run a subshell (i.e., $(commands) ) but forgot the dollar sign. This is a hopeless mission since I cannot uniquely determine if what is inside the parenthesis is a command or just text in a label. So for now I will (1) drop from warning to information (so it won’t be seen unless -Vi is used) and (2) see if I can catch more cases like this from even being flagged in the first place.

As for the path to some script needed by main. I would add a parameter via -I that sets the full path to where that script lives, e.g.

MY_SCRIPT_BIN=/some/place/where/scripts/live

and then the main.sh script can run

${MY_SCRIPT_BIN)/my_special_script.sh

PlanetGus: Thanks for the eof tip; did not know that!

$(pwd) is substituted with the absolute path to the folder where my supporting script is located (i.e. current folder where the script in my post is started), so it’s found no matter where the frame scripts are run.

Paul: Thanks for the tips. I think it’s a good ideaa to have such warnings; if not as default, then at least when including -Vi. It’s bound to happen at some time that you forget $ (or that it’s eaten up because you don’t escape it).

My solution of just giving $(pwd) directly in the script is a bit simpler then. Instead of 1)creating a support.sh (containing ${MY_SCRIPT_BIN)=path) and substituting $(pwd) with ${MY_SCRIPT_BIN).

Another thing related to generating movies.

I made a movie in which the PS_MEDIA is too small (figure is clipped).

I thought gmt modern mode used a huge PS_MEDIA? Why would this happen?

So I added gmt set PS_MEDIA A0 to make command. Then ffmpeg got problems:

[..]
movie [NOTICE]: Running: ffmpeg -loglevel warning -f image2 -framerate 24 -y -i "/home/anbj/faavnefilm/faavnefilm/faavnefilm_%01d.png" -vcodec libx264  -pix_fmt yuv420p faavnefilm.mp4
[png @ 0x5587c3365000] chunk too big
[png @ 0x5587c336a540] chunk too big
Error while decoding stream #0:0: Invalid data found when processing input
[libx264 @ 0x5587c3369b00] height not divisible by 2 (3358x4753)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
movie [ERROR]: Running FFmpeg conversion to MP4 returned error 256 - exiting.

How does PS_MEDIA interfere with this command chain? And how is it connected to the choice of canvas (-C<canvas>|<width>x<height>x<dpu>) in the -movie command?