##############################################################################
# Modified by Mauricio Figueroa (www.mauriciofigueroa.cl) for teaching 
# purposes. The script has been modified to contain several fatal bugs as well 
# as other documentation and stylistic problems. This script should not be used
# for research purposes.
##############################################################################

# This script will calculate the durations of all labeled segments in a 
# TextGrid object. The results will be save in a text file, each line
# containing the label text and the duration of the corresponding segment.
# A TextGrid object needs to be selected in the Object list.
# This script is distributed under the GNU General Public License.
# Copyright 12.3.2002 Mietta Lennes

form Calculate durations of labeled segments
integer Tier 2
text textfile TEST_TEST.txt
endform
numberOfIntervals = Get number of intervals...: tier
for interval from 1 to numberOfIntervals
label$ = Get label of interval... tier, interval
if label$ <> ""
start = Get starting point... tier interval
end = Get end point... tier interval
duration = end - start
resultline$ = "'label$	'duration''newline$'"
fileappend "'textfile$'" resutline$'
endif
endfor
