This builds on the basic wxploop commands introduced in the previous tutorial, but concentrates on getting multiple plots as overlays, and in creating loops for animation. We will construct a script to run a display loop for animation. The script will use the C-Shell. A good reference for the C-Shell is:
To get the most out of this tutorial, please have your user's manual on hand so that you can refer to the manual pages. As new options are introduced, we will refer to the manual pages for explanations. This process will show how information can be retrieved from the manual.
Notation: In the text below, the percent sign % refers to the system prompt. You will see a similar prompt in your working window. You should type any text following the % sign at your system prompt; you then hit return on the keyboard to enter the command. Text on the lines immediately following will show the expected response to your action. Where the next line starts with the % sign in the text below, type that line at your system prompt.
% wxploop -batch -title DEMO -geometry 800x600+200+200 -command open
To remove the window, move the cursor into the window. While holding down
the shift key on your keyboard, hit the middle mouse button. This
kills the wxploop window and the wxploop process associated with it. The
command entry to do the same removal is:
% loopset k
#!/bin/csh -f
#
# demo: a script to show surface temperature contoured over the U.S.
# sfccalc plots the contours. wxpfile finds the latest data
#
set reg = us # specify region covered by plot
set var = st # specify variable to plot
set filename = `wxpfile -in_file cvtsfc -output file -current la`
echo latest file is $filename
sfccalc -region $reg -variable $var -name demo -message mess \
-device d $filename &
exit
# end of script
####################################################################
SAVE the script as a file called demo in your home
directory for now and make sure it is executable (use the chmod
Unix command.)You also need to add the following lines to your Wxp.res file in your home account (there is no need to put them in the site Wxp.res file.)
demo.plot_type: cf demo.con_interval: 4 demo.file_param: useTo run the script type:
% demoA contour plot of current surface temperatures over the U.S. will be displayed in a window called demo. Note: by using the name option, we are using the resources we placed in the Wxp.res file. To get rid of the display, put the cursor into the display and hit return.
% wxploop -batch -command open % loopset query window 14680075 % loopset kThe ID number (14680075, above) is returned by the X-server. Your system will return a different number. If we specify the geometry of the window, the window size is returned along with the window ID:
% wxploop -batch -geometry 800x600+200+200 -command open % loopset query window 14680075:800x600Note that loopset is sending wxploop commands to wxploop. Descriptions of wxploop commands are found in the WXP Program Reference under the section on the program wxploop.
The window number and the server ID number are not the same. As we didn't specify the window_num parameter, the window defaults to number 0. The ID reply is the X-server window 14680075 and it's size is 800x600 when the geometry option is set. Each wxploop window will have a specific X-server ID. Remember that each invocation of wxploop will have only one window (and hence ID) for that window. We can have more than one wxploop operating if we use the window_num option. For example, type:
% wxploop -window_num 4 -batch -geometry 800x600+200+200 -command openNow get the ID of window 4 by typing:
% loopset -window_num 4 query window 15728651:800x600We see that window 4 has a server ID 15728651 (and the first window had an ID 14680075). We can get rid of the windows by typing the following:
% loopset k % loopset -window_num 4 k
% wxploop -batch -geometry 800x600+200+200 -command open % loopset query window 14680075:800x600Now, let's do a pixmap query by typing:
% loopset query pixmap Invalid query commandAn error occurs because pixmaps are numbered as they are created, starting at pixmap 0. The open command only opens a window. Thus the correct command line should specify the pixmap number as well:
% loopset query pixmap 0 0:800x600No pixmap exists yet, hence the ID of 0. loopset is sending wxploop commands to wxploop. Now create two consecutive pixmaps in the following manner:
% loopset create Created pixmap 0 % loopset create Created pixmap 1We can now do a pixmap ID query by typing:
% loopset query pixmap 0 14680080:800x600 % loopset query pixmap 1 14680081:800x600Thus, we see that as we create consecutive pixmaps, we create new X-server ID's associated with each pixmap. In a script, we can program a loop to create a number of pixmaps. This technique is the basic idea of many of the sample animation scripts that come with the WXP distribution.
And how does the animation work?
Well, go to the wxploop window we created. You will notice that the cursor symbol (when placed in the demo window) is no longer a solid circle. It is now two arrows forming a circle. Press the middle mouse button and you will see the symbol change to a solid circle. Press again and the circular-arrows symbol is back. The circular-arrows symbol means wxploop is looping through pixmaps, the two pixmaps we've created. As yet nothing is drawn in them, so all we get is black window.
TO REMOVE THE WINDOW, type:
% loopset k
sfccalc -region $reg -variable $var -file_param use -message mess \
-device d $filename &
So how can we put this plot into a wxploop window?The solution is to use the device option. In earlier tutorials, we had this option set to d for display, but there is also the entry w for specifying a window. In the Program Reference section on sfccalc, the following entry occurs for the device option:
-device device[,name]
d Display where name is the X-server (optional)
w Window where name is [X-server ID] ====NOTE!
p printer or postscript
q plotter
The X-server ID can relate to a window or to a pixmap as we saw above.
So let's adapt the demo script. Here is the new script, the
changes are discussed after it. Save this as a new demo, or edit
the old demo to reflect the changes:
#!/bin/csh -f
#
# demo: a script to show surface temperature contoured over the U.S.
# sfccalc plots the contours. wxpfile finds the latest data
#
# As before:
set reg = us # specify region covered by plot
set var = st # specify variable to plot
set filename = `wxpfile -in_file cvtsfc -output file -current la`
echo latest file is $filename
# Add in lines to start up wxploop and get the window ID
#
wxploop -batch -title DEMO -geometry 800x600+200+200 -command open
set winID = `loopset query window`
sfccalc -region $reg -variable $var -name demo -message mess \
-device w,,$winID $filename
exit
# end of script
#################################################################
To run the script, type:
% demoPoints about the script:
-device w,,$winID
-device w,saturn:0,$winID
-device w,jupiter:0,$winID
gopen_ws: unable to connect to display
% loopset k
How?
Well, let's just add a few lines to the script demo and change the variable var. Either edit your demo script to reflect this script, or save the following as script demo:
#!/bin/csh -f
#
# demo: a script to show surface temperature contoured over the U.S.
# sfccalc plots the contours. wxpfile finds the latest data
#
# As before but moving var:
set reg = us # specify region covered by plot
set filename = `wxpfile -in_file cvtsfc -output file -current la`
echo latest file is $filename
# Add in lines to start up wxploop and get the window ID
#
wxploop -batch -title DEMO -geometry 800x600+200+200 -command open
set winID = `loopset query window`
# We've moved the var variable down
#
set var = st # specify variable to plot = temperature
sfccalc -region $reg -variable $var -name demo -message mess \
-device w,,$winID $filename
# and now repeat the var variable, but set to a new spec. wv
#
set var = wv # specify variable to plot = wind vectors
sfccalc -region $reg -variable $var -name demo -message mess \
-draw data -device w,,$winID $filename
exit
# end of script
################################################################
Now, run the script.Points about the script:
% loopset set name Temps_and_WindThis renames the title bar. This line can be placed in the script at a line after the wxploop command line. DO NOT USE MORE THAN 30 CHARACTERS FOR THE TITLE STRING. The underscore is required to keep the name as one string.
REMOVE THE WINDOW BY TYPING:
% loopset k
Below is the new demo script showing this. Edit your current copy of demo, or save the following into a new demo:
#!/bin/csh -f
#
# demo: a script to show surface temperature contoured over the U.S.
# sfccalc plots the contours. wxpfile finds the latest data
#
set reg = us # specify region covered by plot
set filename = `wxpfile -in_file cvtsfc -output file -current la`
echo latest file is $filename
# Add in lines to start up wxploop and get the window ID
#
wxploop -batch -title DEMO -geometry 800x600+200+200 -command open
set winID = `loopset query window`
set var = st # specify variable to plot = temperature
#
# add -geometry to sfccalc routines and take out -draw option
#
sfccalc -region $reg -variable $var -name demo -message mess \
-geometry 400x300+0+0 -device w,,$winID $filename
set var = wv # specify variable to plot = wind vectors
sfccalc -region $reg -variable $var -name demo -message mess \
-geometry 400x300+400+300 -device w,,$winID $filename
exit
# end of script
################################################################
To run the script, type:
% demoPoints about the script:
ONE MORE THING: We've been writing to the X-server ID for the wxploop window. If we now create a pixmap with the following command (with the wxploop display still up):
% loopset create Created pixmap 0the wxploop window goes black as a blank pixmap has overwritten the data we put in the window.
REMOVE THE WINDOW BY TYPING:
% loopset k
% wxploop -batch -geometry 800x600+200+200 -command open % loopset create Created pixmap 0 % loopset create Created pixmap 1 % loopset query pixmap 0 14680080:800x600 % loopset query pixmap 1 14680081:800x600We created pixmaps and then queried wxploop for their ID's. Another way to get the ID and create the pixmap at the same time is to type:
% loopset create pix
14680082:800x600
which returns an ID. Loopset is using wxploop commands.But which pixmap is this now? We have 0 and 1, so let's query wxploop:
% loopset query last
2
which means pixmap 2 was the last one created. And how many pixmaps are
there now? Type:
% loopset query number
3
There are three, pixmaps 0, 1, and 2. And if we look at the wxploop window,
the circular-arrows indicate wxploop is looping through the three pixmaps.
The window is black because the three pixmaps don't have images in
them yet. Terminate the window by typing:
% loopset k
We use the pixmap ID to specify the X-server ID in the -device w,,pixID
option of wxp program command lines. Either edit your current script to
reflect the changes below, or create a new one.
#!/bin/csh -f
#
# demo: a script to show surface temperature contoured over the U.S.
# sfccalc plots the contours. wxpfile finds the latest data
#
set reg = us # specify region covered by plot
# Open a wxploop window
#
wxploop -title DEMO -batch -geometry 800x600+200+200 -command open
# Loop through 4 hours of data and display
#
foreach hour (1 2 3 4)
set filename = `wxpfile -in_file cvtsfc -output file -current $hour`
echo latest file is $filename
set pixID = `loopset create pix`
set var = st # specify variable to plot
sfccalc -region $reg -variable $var -name demo -message mess \
-device w,,$pixID $filename
end
loopset set name Temperature_Loop
exit
#
# end script
##################################################################
To run the script, type:
% demoPoints about the script:
foreach hour (1 2 3 4)
.
.
end
set pixID = `loopset create pix`
With an understanding of this simple example, more complex analyses become possible.
Overlays can be done to a pixmap as well, in the same manner as we did with the window earlier, by specifying the same pixmap ID for more than one command (such as sfccalc.) Thus overlay plots can be animated as well.
xsat can be used to write to pixmaps so that satellite images can be looped (up to 64 images.)