source: palm/trunk/SCRIPTS/process_dvr_output @ 290

Last change on this file since 290 was 262, checked in by raasch, 16 years ago

further updates for dvr output, bugfix in advec_particles concerning particle boundary condition

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 10.3 KB
RevLine 
[260]1#!/bin/ksh
2# process_dvr_output - a script processing dvr steering + data files
3# $Id: process_dvr_output 262 2009-03-18 08:32:37Z letzel $
4
[261]5     # This script determines the number of streams opened by the dvr software
6     # and creates one single dvrs- and html-file which allow the dvr-plugin
7     # to display all streams in one sequence.
8
[260]9     # Last changes:
10     # 16/03/09 - Siggi - Generating the first version
11
12
13
[262]14    # Variable declarations + default values
[260]15 camera=false
[261]16 create_sequence_output=false
17 data_catalog=`pwd`
[262]18 dvrp_output=rtsp
[261]19 file_identifier=all_streams
[260]20 groundplate=false
[262]21 palm_run_identifier=""
[260]22 topography=false
23
[261]24 typeset  -i  i j nstream nscenes
[260]25
26
[262]27    # Read shellscript options
28 while  getopts  :d:f:ls option
[260]29 do
30   case  $option  in
31       (d)   data_catalog=$OPTARG;;
32       (f)   file_identifier=$OPTARG;;
[262]33       (l)   dvrp_output=local;;
[261]34       (s)   create_sequence_output=true;;
[260]35       (\?)  printf "\n  +++ unknown option $OPTARG \n"
[262]36             printf "\n      allowed option are -d, -f, -l, -s \n"
[260]37             exit;;
38   esac
39 done
40
41
[262]42    # Find out the PALM run identifier
43 if [[ -f CPU_MEASURES ]]
44 then
45    palm_run_identifier=`head -1  CPU_MEASURES`
46 fi
[261]47
[262]48    # Process the streaming server output
49 if [[ $dvrp_output = rtsp ]]
50 then
[261]51
[262]52       # Change to the given directory
53    cd $data_catalog
54
55
56       # Find out the number of streams
57    (( i = 0 ))
58    while true
59    do
60       (( i = i + 1 ))
61       if (( i < 10 ))
62       then
63          cstream=0$i
64       else
65          cstream=$i
66       fi
67
68       if [[ $(ls -1 *.* | grep -c $cstream) = 0 ]]
69       then
70          (( i = i - 1 ))
71          break
72       fi
73
74          # find out the stream name
75       streamname[$i]=`ls -1 ${cstream}_*-ge.dvrs | cut -f1 -d"-"`
76
77          # get addres
78       adr[$i]=`grep ADR= ${streamname[$i]}.dvrs | grep '*' | cut -f2 -d"="`
79
80          # get maxbytes
81       maxbytes[$i]=`head -1 ${streamname[$i]}.max`
82
83          # get number of frames
84       frames[$i]=`tail -1 ${streamname[$i]}.max`
85
86    done
87
88    nstream=$i
89    nscenes=$nstream
90
91
92       # Check, if there are files containing the camera data, the ground plate
93       # and topography data.
94       # Check the first stream only, because all streams have the same files.
95    if [[ -f ${streamname[1]}_camera.max ]]
[260]96    then
[262]97       camera=true
98       adr_camera=`grep ADR= ${streamname[1]}.dvrs | grep 'camera' | cut -f2 -d"="`
99       maxbytes_camera=`head -1 ${streamname[1]}_camera.max`
100       (( nscenes = nscenes + 1 ))
[260]101    fi
[262]102    if [[ -f ${streamname[1]}_groundplate.max ]]
103    then
104       groundplate=true
105       adr_groundplate=`echo $adr_camera | sed "s/camera/groundplate/g"`
106       maxbytes_groundplate=`head -1 ${streamname[1]}_groundplate.max`
107       (( nscenes = nscenes + 1 ))
108    fi
109    if [[ -f ${streamname[1]}_topography.max ]]
110    then
111       topography=true
112       adr_topography=`echo $adr_camera | sed "s/camera/topography/g"`
113       maxbytes_topography=`head -1 ${streamname[1]}_topography.max`
114       (( nscenes = nscenes + 1 ))
115    fi
[260]116
[262]117
118
119       # Start with writing the dvrs file for the combined streams
120    dvr_file=${file_identifier}_streaming.dvrs
121
122    echo  "SCENES=$nscenes"  >  $dvr_file
123
124       # First, add the static scenes
125    if [[ $camera = true ]]
[260]126    then
[262]127       echo  "MED=TCP"                    >>  $dvr_file
128       echo  "ADR=$adr_camera"            >>  $dvr_file
129       echo  "MAXBYTES=$maxbytes_camera"  >>  $dvr_file
130       echo  "FRAMES=1"                   >>  $dvr_file
131       echo  "FRAMES_P_SEC=0"             >>  $dvr_file
132       echo  "SCENEEND"                   >>  $dvr_file
[260]133    fi
134
[262]135    if [[ $groundplate = true ]]
136    then
137       echo  "MED=TCP"                         >>  $dvr_file
138       echo  "ADR=$adr_groundplate"            >>  $dvr_file
139       echo  "MAXBYTES=$maxbytes_groundplate"  >>  $dvr_file
140       echo  "FRAMES=1"                        >>  $dvr_file
141       echo  "FRAMES_P_SEC=0"                  >>  $dvr_file
142       echo  "SCENEEND"                        >>  $dvr_file
143    fi
[260]144
[262]145    if [[ $topography = true ]]
146    then
147       echo  "MED=TCP"                        >>  $dvr_file
148       echo  "ADR=$adr_topography"            >>  $dvr_file
149       echo  "MAXBYTES=$maxbytes_topography"  >>  $dvr_file
150       echo  "FRAMES=1"                       >>  $dvr_file
151       echo  "FRAMES_P_SEC=0"                 >>  $dvr_file
152       echo  "SCENEEND"                       >>  $dvr_file
153    fi
[260]154
155
[262]156       # Now add the streams
157    (( i = 0 ))
158    while (( i < nstream ))
159    do
[260]160
[262]161       (( i = i + 1 ))
[260]162
[262]163       echo  "MED=TCP"                   >>  $dvr_file
164       echo  "ADR=${adr[$i]}"            >>  $dvr_file
165       echo  "MAXBYTES=${maxbytes[$i]}"  >>  $dvr_file
166       echo  "FRAMES=${frames[$i]}"      >>  $dvr_file
167       echo  "FRAMES_P_SEC=25"           >>  $dvr_file
168       echo  "SCENEEND"                  >>  $dvr_file
[260]169
[262]170    done
[260]171
172
[262]173       # Change path to the current file identifier
174    sed  "s/DATA_DVR/${file_identifier}_dvr/g"  $dvr_file > tmp_file
175    mv  tmp_file  $dvr_file
[260]176
177
[262]178       # If there is a dvr configuration file, set the BASEDIR to the parent
179       # directory of the above given path
180    if [[ -f .dvrserver.config ]]
181    then
182       old_path=`grep  BASEDIR  .dvrserver.config`
183       sed  "s&${old_path}&BASEDIR=..&g"  .dvrserver.config  >  .dvrserver.config.new
184       mv  .dvrserver.config.new  .dvrserver.config
185    fi
[260]186
187
[262]188       # Create the html file for the combined streames
189    cp  01_*-ge.html  tmp.html
190    replace=$(echo `grep src= tmp.html`)
191    sed "s&${replace}&src=\"${file_identifier}_streaming.dvrs\"&g" tmp.html > tmp1.html
192    if [[ "$palm_run_identifier" = "" ]]
193    then
194       cp  tmp1.html  ${file_identifier}_streaming.html
195    else
196       sed "s&DATA_DVR/${streamname[1]}/\*\*\*\*\*.dvr (DVR 3D Streaming)&DVR 3D streaming generated by $palm_run_identifier&g"  tmp1.html  >  ${file_identifier}_streaming.html
197    fi
198    rm  tmp.html  tmp1.html
[260]199
200
[262]201       # Informative messages
202    printf "\n\n  *** processing dvr stream output:"
203    printf "\n      number of detected streams = $nstream"
204    printf "\n      stream names:"
[260]205
[262]206    (( i = 0 ))
207    while (( i < nstream ))
208    do
[260]209
[262]210       (( i = i + 1 ))
211       printf " ${streamname[$i]}"
[260]212
[262]213    done
214    printf "\n"
[260]215
216
[262]217 else
[260]218
[262]219       # This is the branch for local output (dvrp_output=local).
220       # Find out the number of streams.
221    (( i = 0 ))
222    while true
223    do
[260]224
[262]225       (( i = i + 1 ))
226       if (( i < 10 ))
227       then
228          cstream=0$i
229       else
230          cstream=$i
231       fi
[261]232
[262]233       if [[ $(ls -1 *.* | grep -c ${cstream}_) = 0 ]]
234       then
235          (( i = i - 1 ))
236          break
237       fi
[261]238
[262]239          # find out the stream name
240       streamname[$i]=`ls -1 ${cstream}_*.camera.dvr | cut -f1 -d"."`
[261]241
[262]242    done
[261]243
[262]244       # Exit, if there are no streams.
245    [[ $i = 0 ]]  &&  exit
[261]246
[262]247    nstream=$i
[261]248
[262]249    mkdir -p  ${data_catalog}/sequence_data
[261]250
251
[262]252       # First, merge static scenes into one file
253    if [[ -f ${streamname[1]}.camera.dvr ]]
254    then
255       cat  ${streamname[1]}.camera.dvr  >>  ${data_catalog}/sequence_data/static_scenes.dvr
256    fi
[261]257
[262]258    if [[ -f ${streamname[1]}.groundplate.dvr ]]
259    then
260       cat  ${streamname[1]}.groundplate.dvr  >>  ${data_catalog}/sequence_data/static_scenes.dvr
261    fi
[261]262
[262]263    if [[ -f ${streamname[1]}.topography.dvr ]]
264    then
265       cat  ${streamname[1]}.topography.dvr  >>  ${data_catalog}/sequence_data/static_scenes.dvr
266    fi
[261]267
[262]268
269       # Find out the number of frames
270    frames[1]=`grep sequence ${streamname[1]}_00000.html | cut -f2 -d";" | cut -f1 -d'"' | cut -f2 -d"-"`
271
272
273       # Now, merge the data, frame by frame
274    (( j = 0 ))
275    while (( j < ${frames[1]} ))
276    do
277
278       nframe=`printf "%05d" $j`
279
280       (( i = 0 ))
281       while (( i < nstream ))
282       do
283          (( i = i + 1 ))
284          cat  ${streamname[$i]}_$nframe.dvr  >>  ${data_catalog}/sequence_data/$nframe.dvr
285       done
286
287       (( j = j + 1 ))
288
289    done
290
291
292       # Create the html file to be used for the sequence mode
293    cp  ${streamname[1]}_00000.html  tmp1.html
294    sed  "s&${streamname[1]}_camera.dvr&sequence_data/static_scenes.dvr&g"  tmp1.html  >  tmp2.html
295    sed  "s&${streamname[1]}_&sequence_data/&g"  tmp2.html  >  tmp3.html
296    if [[ "$palm_run_identifier" = "" ]]
297    then
298       cp  tmp3.html  ${file_identifier}_sequence.html
299    else
300       sed "s&sequence_data/%05d.dvr (DVR 3D Sequence)&DVR 3D sequence generated by $palm_run_identifier&g"  tmp3.html  >  ${file_identifier}_sequence.html
301    fi
302    rm  tmp1.html  tmp2.html  tmp3.html
303    mv  ${file_identifier}_sequence.html  ${data_catalog}
304
305
306       # Informative messages
307    printf "\n\n  *** processing dvr local output (using dvrp_output=local):"
308    printf "\n      number of detected streams = $nstream"
309    printf "\n      stream names:"
310
311    (( i = 0 ))
312    while (( i < nstream ))
313    do
314
315       (( i = i + 1 ))
316       printf " ${streamname[$i]}"
317
318    done
319    printf "\n"
320
321 fi
322
323
324    # Create output for viewing dvr data in sequence mode
[261]325 if [[ $create_sequence_output = true ]]
326 then
327
328    mkdir  sequence_data
329
[262]330       # First, merge static scenes into one file
[261]331    if [[ $camera = true ]]
332    then
333       cat  ${streamname[1]}/camera.dvr  >>  sequence_data/static_scenes.dvr
334    fi
335
336    if [[ $groundplate = true ]]
337    then
338       cat  ${streamname[1]}/groundplate.dvr  >>  sequence_data/static_scenes.dvr
339    fi
340
341    if [[ $topography = true ]]
342    then
343       cat  ${streamname[1]}/topography.dvr  >>  sequence_data/static_scenes.dvr
344    fi
345
346
[262]347       # Now, merge the data, frame by frame
[261]348    (( j = 0 ))
349    while (( j < ${frames[1]} ))
350    do
351
352       nframe=`printf "%05d" $j`
353
354       (( i = 0 ))
355       while (( i < nstream ))
356       do
357          (( i = i + 1 ))
358          cat  ${streamname[$i]}/$nframe.dvr  >>  sequence_data/$nframe.dvr
359       done
360
361       (( j = j + 1 ))
362
363    done
364
365
[262]366       # Create the html file to be used for the sequence mode
[261]367    cp  ${streamname[1]}.html  tmp1.html
368    sed  "s/camera.dvr/static_scenes.dvr/g"  tmp1.html  >  tmp2.html
[262]369    sed  "s&${streamname[1]}&sequence_data&g"  tmp2.html  >  tmp3.html
370    if [[ "$palm_run_identifier" = "" ]]
371    then
372       cp  tmp3.html  ${file_identifier}_sequence.html
373    else
374       sed "s&DATA_DVR/sequence_data/\*\*\*\*\*.dvr (DVR 3D Sequence)&DVR 3D sequence generated by $palm_run_identifier&g"  tmp3.html  >  ${file_identifier}_sequence.html
375    fi
376    rm  tmp1.html  tmp2.html  tmp3.html
[261]377
378    printf "      data for using sequence mode generated"
379
380 fi
381
382
383
[262]384    # Change back to directory from where script has been called
385 cd - > /dev/null  2>&1
Note: See TracBrowser for help on using the repository browser.