Index: /palm/trunk/DOC/app/chapter_3.5.1.html
===================================================================
--- /palm/trunk/DOC/app/chapter_3.5.1.html	(revision 143)
+++ /palm/trunk/DOC/app/chapter_3.5.1.html	(revision 144)
@@ -206,5 +206,8 @@
 in the CASE
 structure of <tt><font style="font-size: 10pt;" size="2">user_actions_ij</font></tt>!</p> </td>
-</tr> <tr valign="top"> <td width="211"><p><tt><font style="font-size: 10pt;" size="2">flow_statistics.f90</font></tt>
+</tr> <tr><td style="vertical-align: top;"><code>SUBROUTINE preprocess_spectra</code> in <code>calc_spectra.f90</code>, and <code>data_output_spectra.f90</code></td><td style="vertical-align: top;"><tt><font style="font-size: 10pt;" size="2"><font face="Cumberland, monospace"><a name="user_spectra"></a>user_spectra</font></font></tt></td><td style="vertical-align: top;"><p><a href="chapter_3.5.4.html#spectra">Spectra of user-defined
+quantities</a> can be computed here.</p>The
+routine contains some simple examples (as comment lines) in order to
+demonstrate how to use it.</td></tr><tr valign="top"> <td width="211"><p><tt><font style="font-size: 10pt;" size="2">flow_statistics.f90</font></tt>
 before the summation of array <span style="font-family: monospace;">hom</span>
 (horizontal averages)<br> </p> </td> <td width="117"> <p><tt><font style="font-size: 10pt;" size="2"><font face="Cumberland, monospace"><a name="user_statistics"></a>user_statistics<br>(
Index: /palm/trunk/DOC/app/chapter_3.5.4.html
===================================================================
--- /palm/trunk/DOC/app/chapter_3.5.4.html	(revision 143)
+++ /palm/trunk/DOC/app/chapter_3.5.4.html	(revision 144)
@@ -13,12 +13,28 @@
 quantities which are not part of PALM's standard output. The basic user
 interface includes a number of subroutines which allow the calculation
-of user-defined quantities and output of these quantities as 1. (horizontally averaged) <a href="#vertical_profiles">vertical profiles</a>, 2.&nbsp;<a href="#time_series">time series</a>, 3. <a href="#2D_and_3D">2d cross
-section</a> or <a href="#2D_and_3D">3d volume data</a> and 4. <a href="#dvrp">dvrp</a> objects. The respective subroutines
-contain sample code lines (written as comment lines) for defining, calculating and
-output of such quantities.<br><br>Output times, averaging intervals, etc. are steered by the same variables as used for the standard PALM output quantities, e.g. <a href="chapter_4.2.html#dt_data_output">dt_data_output</a>.<br><br>The
-rest of this chapter explains step-by-step how to modify/extend the
-default file user_interface.f90 in order to generate the respective output.<br><br><br><h4><a name="vertical_profiles"></a>1. Output of vertical profiles</h4>This example shows the output of the
-quantity "turbulent resolved-scale horizontal momentum flux" (u*v*). If more than one user-defined
-quantity shall be output, the following steps have to be carried out in the
+of user-defined quantities and output of these quantities as 1.
+(horizontally averaged) <a href="#vertical_profiles">vertical
+profiles</a>, 2.&nbsp;<a href="#time_series">time
+series</a>, 3. <a href="#2D_and_3D">2d cross
+section</a> or <a href="#2D_and_3D">3d volume data</a>,
+4. <a href="#dvrp">dvrp</a> objects, and 5. <a href="#spectra">spectra</a>. The respective
+subroutines
+contain sample code lines (written as comment lines) for defining,
+calculating and
+output of such quantities.<br><br>Output times, averaging
+intervals, etc. are steered by the same variables as used for the
+standard PALM output quantities, e.g. <a href="chapter_4.2.html#dt_data_output">dt_data_output</a>.<br><br>The
+following five parts of&nbsp;this chapter explains step-by-step how
+to modify/extend the
+default file user_interface.f90 in order to generate the respective
+output:<br><ol><li>(horizontally averaged) <a href="chapter_3.5.4.html#vertical_profiles">vertical profiles</a>,&nbsp;</li><li><a href="chapter_3.5.4.html#time_series">time series</a>,&nbsp;</li><li><a href="chapter_3.5.4.html#2D_and_3D">2d cross
+section</a> or <a href="chapter_3.5.4.html#2D_and_3D">3d
+volume data</a>,&nbsp;</li><li><a href="chapter_3.5.4.html#dvrp">dvrp</a> objects,
+and&nbsp;</li><li><a href="chapter_3.5.4.html#spectra">spectra</a>.</li></ol><br><h4><a name="vertical_profiles"></a>1. Output of user-defined
+vertical profiles</h4>This example shows the output of the
+quantity "turbulent resolved-scale horizontal momentum flux" (u*v*). If
+more than one user-defined
+quantity shall be output, the following steps have to be carried out in
+the
 same way for each of the quantities.<br><br><ol><li>The
 quantity has to be given a unique string identifier, e.g. <span style="font-style: italic;">'u*v*'</span>.
@@ -31,30 +47,100 @@
 the
 quantity, an identification number, a physical unit, and the vertical
-grid on which it is defined (u- or w-grid), has to be assigned (subroutine <a href="chapter_3.5.1.html#user_check_data_output_pr"><span style="font-family: monospace;">user_check_data_output_pr</span></a>):<span style="font-family: monospace;"><br><br>&nbsp; &nbsp; CASE (
-'u*v*' )<br></span><span style="font-family: monospace;">&nbsp; &nbsp; &nbsp; &nbsp;index = pr_palm + <span style="color: rgb(255, 0, 0);">1<span style="color: rgb(0, 0, 0);">
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
-&nbsp; &nbsp; ! identification number</span></span><br>&nbsp; &nbsp; &nbsp; &nbsp;dopr_index(var_count) = index<br>&nbsp; &nbsp; &nbsp;&nbsp; dopr_unit(var_count) &nbsp;= '<span style="color: rgb(255, 0, 0);">m2/s2</span>'
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ! physical unit<br>&nbsp; &nbsp; &nbsp; &nbsp;hom(:,2,index,:) &nbsp; &nbsp; &nbsp;= SPREAD( <span style="color: rgb(255, 0, 0);">zu</span>, 2, statistic_regions+1 ) &nbsp; &nbsp;! vertical grid<br></span><br>Here only the those parts in <span style="color: rgb(255, 0, 0);">red</span> color have to be given by the user appropriately.<br>The identification number (<span style="font-family: Courier New,Courier,monospace;">index</span>) must be within the range [<span style="font-family: Courier New,Courier,monospace;"> pr_palm+1 , pr_palm+max_pr_user</span> ], where <span style="font-family: Courier New,Courier,monospace;">max_pr_user</span> is the number of&nbsp;user-defined profiles as given by parameter <a href="chapter_4.3.html#data_output_pr_user">data_output_pr_user</a> in the respective PALM run.&nbsp;The physical unit has to be given with respect to the NetCDF conventions. If no unit is given,
-PALM will abort. The vertical grid has to be either <span style="font-family: Courier New,Courier,monospace;">zu</span> (u-grid) or <span style="font-family: Courier New,Courier,monospace;">zw</span> (w-grid).<br><br></li><li>The quantity has to be calculated for all gridpoints (subroutine <a href="chapter_3.5.1.html#user_statistics">user_statistics</a>):<br><br><span style="font-family: monospace;">&nbsp; &nbsp; !$OMP DO</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp; DO&nbsp; i = nxl, nxr</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DO&nbsp; j = nys, nyn</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DO&nbsp; k = nzb_s_outer(j,i)+1, nzt</span><br style="font-family: monospace;"><span style="font-family: monospace;"></span><span style="font-family: monospace;"></span><span style="font-family: monospace;"></span><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sums_l(k,pr_palm+<span style="color: rgb(255, 0, 0);">1</span>,tn) = sums_l(k,pr_palm+<span style="color: rgb(255, 0, 0);">1</span>,tn) +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 0, 0);">( 0.5 * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,sr) ) * &amp;</span></span><br style="font-family: monospace; color: rgb(255, 0, 0);"><span style="font-family: monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-( 0.5 * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) ) * &amp;</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-* rmask(j,i,sr)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDDO<br>&nbsp; &nbsp; &nbsp; &nbsp;ENDDO<br>&nbsp; &nbsp; ENDDO<br></span><br style="font-family: monospace;">Once again, only those parts in <span style="color: rgb(255, 0, 0);">red</span> have to be adjusted by the user.<br>The
+grid on which it is defined (u- or w-grid), has to be assigned
+(subroutine <a href="chapter_3.5.1.html#user_check_data_output_pr"><span style="font-family: monospace;">user_check_data_output_pr</span></a>):<span style="font-family: monospace;"><br><br>&nbsp;
+&nbsp; CASE (
+'u*v*' )<br></span><span style="font-family: monospace;">&nbsp;
+&nbsp; &nbsp; &nbsp;index = pr_palm + <span style="color: rgb(255, 0, 0);">1<span style="color: rgb(0, 0, 0);">
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; ! identification number</span></span><br>&nbsp;
+&nbsp; &nbsp; &nbsp;dopr_index(var_count) = index<br>&nbsp;
+&nbsp; &nbsp;&nbsp; dopr_unit(var_count) &nbsp;= '<span style="color: rgb(255, 0, 0);">m2/s2</span>'
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !
+physical unit<br>&nbsp; &nbsp; &nbsp;
+&nbsp;hom(:,2,index,:) &nbsp; &nbsp; &nbsp;= SPREAD( <span style="color: rgb(255, 0, 0);">zu</span>, 2,
+statistic_regions+1 ) &nbsp; &nbsp;! vertical grid<br></span><br>Here
+only the those parts in <span style="color: rgb(255, 0, 0);">red</span>
+color have to be given by the user appropriately.<br>The
+identification number (<span style="font-family: Courier New,Courier,monospace;">index</span>)
+must be within the range [<span style="font-family: Courier New,Courier,monospace;">
+pr_palm+1 , pr_palm+max_pr_user</span> ], where <span style="font-family: Courier New,Courier,monospace;">max_pr_user</span>
+is the number of&nbsp;user-defined profiles as given by parameter <a href="chapter_4.3.html#data_output_pr_user">data_output_pr_user</a>
+in the respective PALM run.&nbsp;The physical unit has to be given
+with respect to the NetCDF conventions. If no unit is given,
+PALM will abort. The vertical grid has to be either <span style="font-family: Courier New,Courier,monospace;">zu</span>
+(u-grid) or <span style="font-family: Courier New,Courier,monospace;">zw</span>
+(w-grid).<br><br></li><li>The quantity has to
+be calculated for all gridpoints (subroutine <a href="chapter_3.5.1.html#user_statistics">user_statistics</a>):<br><br><span style="font-family: monospace;">&nbsp; &nbsp; !$OMP
+DO</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;
+DO&nbsp; i = nxl, nxr</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+DO&nbsp; j = nys, nyn</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+DO&nbsp; k = nzb_s_inner(j,i)+1, nzt</span><br style="font-family: monospace;"><span style="font-family: monospace;"></span><span style="font-family: monospace;"></span><span style="font-family: monospace;"></span><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+sums_l(k,pr_palm+<span style="color: rgb(255, 0, 0);">1</span>,tn)
+= sums_l(k,pr_palm+<span style="color: rgb(255, 0, 0);">1</span>,tn)
++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+&amp;</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<span style="color: rgb(255, 0, 0);">( 0.5 * ( u(k,j,i) +
+u(k,j,i+1) ) - hom(k,1,1,sr) ) * &amp;</span></span><br style="font-family: monospace; color: rgb(255, 0, 0);"><span style="font-family: monospace; color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+( 0.5 * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) ) &nbsp; &amp;</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+* rmask(j,i,sr)<br>&nbsp; &nbsp; &nbsp; &nbsp;
+&nbsp; ENDDO<br>&nbsp; &nbsp; &nbsp;
+&nbsp;ENDDO<br>&nbsp; &nbsp; ENDDO<br></span><br style="font-family: monospace;">Once again, only those parts
+in <span style="color: rgb(255, 0, 0);">red</span>
+have to be adjusted by the user.<br>The
 turbulent resolved-scale momentum flux u*v* is defined as the product
 of the deviations of the horizontal velocities from their respective
 horizontally averaged mean values. These mean values are stored in
-array <span style="font-family: Courier New,Courier,monospace;">hom(..,1,1,sr)</span> and <span style="font-family: Courier New,Courier,monospace;">hom(..,1,2,sr)</span> for the u- and v-component, respectively. Since due to the staggered grid, <span style="font-family: Courier New,Courier,monospace;">u</span> and <span style="font-family: Courier New,Courier,monospace;">v</span>
+array <span style="font-family: Courier New,Courier,monospace;">hom(..,1,1,sr)</span>
+and <span style="font-family: Courier New,Courier,monospace;">hom(..,1,2,sr)</span>
+for the u- and v-component, respectively. Since due to the staggered
+grid, <span style="font-family: Courier New,Courier,monospace;">u</span>
+and <span style="font-family: Courier New,Courier,monospace;">v</span>
 are not defined at the same gridpoints, they have to be interpolated
 appropriately (here to the center of the gridbox). The result of the
 calculation is stored in array <span style="font-family: Courier New,Courier,monospace;">sums_l</span>.
 The second index of this array is the identification number of the
-profile which must match the one given in the previous step 2.</li></ol><br><h4><a name="time_series"></a>2. Output of timeseries</h4>This example shows the output of  two time series for the absolut extremal values of the horizontal velocities <span style="font-style: italic;">u</span> and <span style="font-style: italic;">v</span>. If more than one user-defined
-quantity shall be output, the following steps have to be carried out in the
-same way for each of the quantities.<br><br><ol><li>For each time series quantity you have to give a label and a unit  (subroutine <a href="chapter_3.5.1.html#user_init">user_init</a>), which will be used for the NetCDF file. They must not contain more than seven characters. The value of <code>dots_num</code> has to be increased by the number of new time series quantities. Its old value has to be stored in <code>dots_num_palm</code>.<br><br><code>&nbsp;&nbsp;&nbsp; dots_label(dots_num<span style="color: rgb(255, 0, 0);">+1</span>) = '<span style="color: rgb(255, 0, 0);">abs_umx</span>'<br>&nbsp;&nbsp;&nbsp; dots_unit(dots_num<span style="color: rgb(255, 0, 0);">+1</span>)&nbsp; = '<span style="color: rgb(255, 0, 0);">m/s</span>'<br>&nbsp;&nbsp;&nbsp; dots_label(dots_num<span style="color: rgb(255, 0, 0);">+2</span>) = '<span style="color: rgb(255, 0, 0);">abs_vmx</span>'<br>&nbsp;&nbsp;&nbsp; dots_unit(dots_num<span style="color: rgb(255, 0, 0);">+2</span>)&nbsp; = '<span style="color: rgb(255, 0, 0);">m/s</span>'<br><br>&nbsp;&nbsp;&nbsp; dots_num_palm = dots_num<br>&nbsp;&nbsp;&nbsp; dots_num = dots_num <span style="color: rgb(255, 0, 0);">+ 2</span><br><br></code>Only those parts in <span style="color: rgb(255, 0, 0);">red</span> have to be adjusted by the user.<br><br></li><li>These quantities are&nbsp;calculated and output in subroutine <a href="chapter_3.5.1.html#user_statistics">user_statistics</a> for every statistic region <code>sr</code> defined by the user,&nbsp;but at least for the region <span style="font-style: italic;">"total domain"</span>:<br>&nbsp;<br><code>&nbsp;&nbsp;&nbsp; ts_value(dots_num_palm+1,sr) = ABS( u_max )<br>&nbsp;&nbsp;&nbsp; ts_value(dots_num_palm+2,sr) = ABS( v_max )<br></code></li></ol>&nbsp;<br><h4><span style="font-weight: bold;"><a name="2D_and_3D"></a>3. Output of 2d cross sections or 3d volume data</span></h4><br>This example shows the output of the
+profile which must match the one given in the previous step 2.</li></ol><br><h4><a name="time_series"></a>2. Output of user-defined
+timeseries</h4>This example shows the output of two time series
+for the absolut extremal values of the horizontal velocities <span style="font-style: italic;">u</span> and <span style="font-style: italic;">v</span>. If more than one
+user-defined
+quantity shall be output, the following steps have to be carried out in
+the
+same way for each of the quantities.<br><br><ol><li>For
+each time series quantity you have to give a label and a unit
+(subroutine <a href="chapter_3.5.1.html#user_init">user_init</a>),
+which will be used for the NetCDF file. They must not contain more than
+seven characters. The value of <code>dots_num</code> has
+to be increased by the number of new time series quantities. Its old
+value has to be stored in <code>dots_num_palm</code>.<br><br><code>&nbsp;&nbsp;&nbsp;
+dots_label(dots_num<span style="color: rgb(255, 0, 0);">+1</span>)
+= '<span style="color: rgb(255, 0, 0);">abs_umx</span>'<br>&nbsp;&nbsp;&nbsp;
+dots_unit(dots_num<span style="color: rgb(255, 0, 0);">+1</span>)&nbsp;
+= '<span style="color: rgb(255, 0, 0);">m/s</span>'<br>&nbsp;&nbsp;&nbsp;
+dots_label(dots_num<span style="color: rgb(255, 0, 0);">+2</span>)
+= '<span style="color: rgb(255, 0, 0);">abs_vmx</span>'<br>&nbsp;&nbsp;&nbsp;
+dots_unit(dots_num<span style="color: rgb(255, 0, 0);">+2</span>)&nbsp;
+= '<span style="color: rgb(255, 0, 0);">m/s</span>'<br><br>&nbsp;&nbsp;&nbsp;
+dots_num_palm = dots_num<br>&nbsp;&nbsp;&nbsp;
+dots_num = dots_num <span style="color: rgb(255, 0, 0);">+
+2</span><br><br></code>Only those parts in <span style="color: rgb(255, 0, 0);">red</span> have to be
+adjusted by the user.<br><br></li><li>These
+quantities are&nbsp;calculated and output in subroutine <a href="chapter_3.5.1.html#user_statistics">user_statistics</a>
+for every statistic region <code>sr</code> defined by the
+user,&nbsp;but at least for the region <span style="font-style: italic;">"total domain"</span>:<br>&nbsp;<br><code>&nbsp;&nbsp;&nbsp;
+ts_value(dots_num_palm+1,sr) = ABS( u_max )<br>&nbsp;&nbsp;&nbsp;
+ts_value(dots_num_palm+2,sr) = ABS( v_max )<br></code></li></ol>&nbsp;<br><h4><span style="font-weight: bold;"><a name="2D_and_3D"></a>3.
+Output of user-defined 2d cross sections or 3d volume data</span></h4><br>This
+example shows the output of the
 quantity "square of the u-component" (<span style="font-weight: bold;">Note:</span> this quantity
 could of course easily be calculated from the u-component by
 postprocessing the PALM output so that calculation within PALM is not
 necessarily required). If more than one user-defined
-quantity shall be output, the following steps have to be carried out in the
+quantity shall be output, the following steps have to be carried out in
+the
 same way for each of the quantities.<br><br><ol><li>The
 quantity has to be given a unique string identifier, e.g. <span style="font-style: italic;">'u2'</span>.
@@ -220,13 +306,105 @@
 ';&nbsp; WRITE ( 14 )&nbsp; u2_av</span><br style="font-family: monospace;"><span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;
 ENDIF</span><br><br>Otherwise, the calculated
-time-average may be wrong.</li></ol><br><h4><a name="dvrp"></a>4. Output of DVRP objects</h4>This example shows the output of the
-quantity "square of the u-component", <span style="font-style: italic;">u<sup>2</sup></span>. If more than one user-defined
-quantity shall be output, the following steps have to be carried out in the
-same way for each of the quantities. First,&nbsp;steps 1 - 6 of <a href="chapter_3.5.4.html#2D_and_3D">2d cross
-section</a> or <a href="chapter_3.5.4.html#2D_and_3D">3d volume data</a> are required. Second,&nbsp;the gridpoint data of the quantity has to
+time-average may be wrong.</li></ol><br><h4><a name="dvrp"></a>4. Output of user-defined DVRP objects</h4>This
+example shows the output of the
+quantity "square of the u-component", <span style="font-style: italic;">u<sup>2</sup></span>.
+If more than one user-defined
+quantity shall be output, the following steps have to be carried out in
+the
+same way for each of the quantities. First,&nbsp;steps 1 - 6
+of&nbsp;<a href="chapter_3.5.4.html#2D_and_3D"><span style="font-weight: bold;">part 3.</span> </a> <a href="chapter_3.5.4.html#2D_and_3D">(2d cross
+section or </a><a href="chapter_3.5.4.html#2D_and_3D">3d
+volume data)</a> are required. Second,&nbsp;the gridpoint
+data
+of the quantity has to
 be resorted to array <span style="font-family: monospace;">local_pf</span>
-in subroutine <a href="chapter_3.5.1.html#user_data_output_dvrp"><span style="font-family: monospace;">user_data_output_dvrp</span></a> as follows:<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CASE ( '<span style="color: rgb(255, 0, 0);">u2</span>', '<span style="color: rgb(255, 0, 0);">u2</span>_xy', '<span style="color: rgb(255, 0, 0);">u2</span>_xz', '<span style="color: rgb(255, 0, 0);">u2</span>_yz'&nbsp; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DO&nbsp; i = nxl, nxr+1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DO&nbsp; j = nys, nyn+1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DO&nbsp; k = nzb, nz_do3d<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local_pf(i,j,k) = <span style="color: rgb(255, 0, 0);">u2</span>(k,j,i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ENDDO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ENDDO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ENDDO</code><br><br>Only those parts in <span style="color: rgb(255, 0, 0);">red</span> have to be adjusted by the user.<br><br>After performing these steps, the user-defined quantity <code>'u2'</code> can be selected like standard model quantities by the <a href="chapter_4.2.html#dvrp_graphics">dvrp_graphics</a> package parameter <a href="chapter_4.2.html#mode_dvrp">mode_dvrp</a>.<hr>
-<p style="line-height: 100%;"><br><font color="#000080"><font color="#000080"><a href="chapter_3.5.3.html"><font color="#000080"><img src="left.gif" name="Grafik1" align="bottom" border="2" height="32" width="32"></font></a><a href="index.html"><font color="#000080"><img src="up.gif" name="Grafik2" align="bottom" border="2" height="32" width="32"></font></a><a href="chapter_3.5.5.html"><font color="#000080"><img style="border: 2px solid ; width: 32px; height: 32px;" alt="" src="right.gif" name="Grafik3"></font></a></font></font></p>
-<p style="line-height: 100%;"><i>Last
-change:&nbsp;</i> $Id$</p>
+in subroutine <a href="chapter_3.5.1.html#user_data_output_dvrp"><span style="font-family: monospace;">user_data_output_dvrp</span></a>
+as follows:<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE ( '<span style="color: rgb(255, 0, 0);">u2</span>',
+'<span style="color: rgb(255, 0, 0);">u2</span>_xy',
+'<span style="color: rgb(255, 0, 0);">u2</span>_xz',
+'<span style="color: rgb(255, 0, 0);">u2</span>_yz'&nbsp;
+)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+DO&nbsp; i = nxl, nxr+1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+DO&nbsp; j = nys, nyn+1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+DO&nbsp; k = nzb, nz_do3d<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+local_pf(i,j,k) = <span style="color: rgb(255, 0, 0);">u2</span>(k,j,i)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ENDDO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ENDDO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ENDDO</code><br><br>Only those parts in <span style="color: rgb(255, 0, 0);">red</span> have to be
+adjusted by the user.<br><br>After performing these steps,
+the user-defined quantity <code>'u2'</code> can be
+selected like standard model quantities by the <a href="chapter_4.2.html#dvrp_graphics">dvrp_graphics</a>
+package parameter <a href="chapter_4.2.html#mode_dvrp">mode_dvrp</a>.<br><br><h4><a name="spectra"></a>5. Output of user-defined spectra</h4>This
+example shows the output of the
+quantity "turbulent resolved-scale horizontal momentum flux" (u*v*). If
+more than one user-defined
+quantity shall be output, the following steps have to be carried out in
+the
+same way for each of the quantities.<br><br><ol><li>The
+calculation of user-defined spectra is closely linked with the
+calculation of <a href="chapter_3.5.4.html#vertical_profiles"><span style="font-weight: bold;">part 1.</span>
+(user-defined
+</a><a href="chapter_3.5.4.html#vertical_profiles">vertical
+profiles</a><a href="chapter_3.5.4.html#vertical_profiles">)</a><span style="font-weight: bold;"></span> and <a href="chapter_3.5.4.html#2D_and_3D"><span style="font-weight: bold;">part 3.</span> (user-defined</a><a href="chapter_3.5.4.html#2D_and_3D"> </a><a href="chapter_3.5.4.html#2D_and_3D">3d volume data</a><a href="chapter_3.5.4.html#2D_and_3D">)</a><span style="font-weight: bold;"></span>. Therefore, the
+following prerequisites apply
+for each user-defined
+spectra quantity:</li></ol><ol style="list-style-type: upper-alpha;"><ol style="list-style-type: upper-alpha;"><li>From <a href="chapter_3.5.4.html#vertical_profiles"><span style="font-weight: bold;">part 1.</span>
+(user-defined
+</a><a href="chapter_3.5.4.html#vertical_profiles">vertical
+profiles</a><a href="chapter_3.5.4.html#vertical_profiles">)</a>
+steps 2 and 3. <br>See the sample code (as comment lines) for <span style="font-style: italic;">'u*v*'</span> and <code>ustvst</code>,
+respectively. (Actual output of vertical profiles - step 1 - is not
+required.)</li><li>From <a href="chapter_3.5.4.html#2D_and_3D"><span style="font-weight: bold;">part 3.</span> (user-defined</a><a href="chapter_3.5.4.html#2D_and_3D"> </a><a href="chapter_3.5.4.html#2D_and_3D">3d volume data</a><a href="chapter_3.5.4.html#2D_and_3D">)</a> steps 2, 3,
+4, 5, and 6. <br>See the sample code (as comment lines) for <span style="font-style: italic;">'u*v*'</span> and <code>ustvst</code>,
+respectively. (Actual output of 3d volume data - step 1 - is not
+required.)</li><li>The quantity has to be given a unique
+string identifier, e.g. <span style="font-style: italic;">'u*v*'</span>.
+This identifier must be different from the identifiers used for the
+PALM standard output (see list in description of package parameter <a href="chapter_4.2.html#data_output_sp">data_output_sp</a>).
+To switch on output of this quantity, the user has to assign the string
+identifier to the package parameter <a href="chapter_4.2.html#data_output_sp">data_output_sp</a>,
+eg.:<br><br><span style="font-family: monospace;">&nbsp;
+&nbsp; data_output_sp</span> =&nbsp; <span style="font-style: italic;">'u*v*'</span><br><br></li></ol>A.
+and B. as prerequisites for C. require a naming convention of identical
+identifiers, e.g. data_output_pr_user = 'u*v*', data_output_user =
+'u*v*' and data_output_sp = 'u*v*'. This naming convention applies only
+in case of user-defined spectra.</ol><ol start="2"><li>Edit
+the subroutine <a href="chapter_3.5.1.html#user_spectra">user_spectra</a>
+(only those parts in <span style="color: rgb(255, 0, 0);">red</span>)
+as follows:<br><br><code>&nbsp;&nbsp;&nbsp;
+IF ( mode == 'preprocess' )&nbsp; THEN<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+SELECT CASE ( TRIM( data_output_sp(m) ) )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE ( 'u', 'v', 'w', 'pt', 'q' )<br>!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Not allowed here since these are the standard quantities used in <br>!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+preprocess_spectra.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<br><span style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE ( 'u*v*' )</span><br style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+pr = pr_palm+1</span><br style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);"><span style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+d(nzb+1:nzt,nys:nyn,nxl:nxr) = ustvst(nzb+1:nzt,nys:nyn,nxl:nxr)</span><br style="color: rgb(255, 0, 0); background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE DEFAULT<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+PRINT*, '+++ user_spectra/preprocess: Spectra of ', &amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+TRIM( data_output_sp(m) ), ' can not be calculated'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+END SELECT<br><br>&nbsp;&nbsp;&nbsp; ELSEIF (
+mode == 'data_output' )&nbsp; THEN<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+SELECT CASE ( TRIM( data_output_sp(m) ) )<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE ( 'u', 'v', 'w', 'pt', 'q' )<br>!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+Not allowed here since these are the standard quantities used in <br>!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+data_output_spectra.<br><br><span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE ( 'u*v*' )</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+pr = 6</span><br style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+CASE DEFAULT<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+PRINT*, '+++ user_spectra/data_output: Spectra of ', &amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+TRIM( data_output_sp(m) ), ' are not defined'<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+END SELECT<br><br>&nbsp;&nbsp;&nbsp; ENDIF</code><br></li></ol>Note
+that spectra output is an <a href="chapter_3.7.html">optional
+software package</a> (see <a href="chapter_3.7.html">chapter
+3.7</a>). Therefore user-defined spectra also require the package
+activation via <code>mrun - p spectra</code>.<hr>
+<p style="line-height: 100%;"><br><font color="#000080"><font color="#000080"><a href="chapter_3.5.3.html"><font color="#000080"><img src="left.gif" name="Grafik1" align="bottom" border="2" height="32" width="32"></font></a><a href="index.html"><font color="#000080"><img src="up.gif" name="Grafik2" align="bottom" border="2" height="32" width="32"></font></a><a href="chapter_3.5.5.html"><font color="#000080"><img style="border: 2px solid ; width: 32px; height: 32px;" alt="" src="right.gif" name="Grafik3"></font></a></font></font></p><p style="line-height: 100%;"><i>Last
+change:&nbsp;</i> $Id: chapter_3.5.4.html 136 2007-11-26
+02:47:32Z letzel $</p>
 </body></html>
Index: /palm/trunk/DOC/app/chapter_4.2.html
===================================================================
--- /palm/trunk/DOC/app/chapter_4.2.html	(revision 143)
+++ /palm/trunk/DOC/app/chapter_4.2.html	(revision 144)
@@ -11238,6 +11238,6 @@
       
       
-      <p>Allowed values are:&nbsp; <b>data_output_sp</b>
-= <span style="font-style: italic;">'u'</span>, <span style="font-style: italic;">'v'</span>, <span style="font-style: italic;">'w'</span>, <span style="font-style: italic;">'pt'</span>, <span style="font-style: italic;">'q'</span>.<br>
+      <p>Allowed standard values are:&nbsp; <b>data_output_sp</b>
+= <span style="font-style: italic;">'u'</span>, <span style="font-style: italic;">'v'</span>, <span style="font-style: italic;">'w'</span>, <span style="font-style: italic;">'pt'</span>, <span style="font-style: italic;">'q'</span>. The user may define further quantities (see <a href="chapter_3.5.4#spectra">chapter 3.5.4 part 5</a>).<br>
 
 
Index: /palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- /palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 143)
+++ /palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 144)
@@ -15,5 +15,7 @@
 necessary for the current subdomain.
 
-check_open, read_var_list, read_3d_binary, write_3d_binary
+User-defined spectra.
+
+calc_spectra, check_open, data_output_spectra, netcdf, read_var_list, read_3d_binary, user_interface, write_3d_binary
 
 
@@ -38,5 +40,6 @@
 NetCDF files newly created by restart files (no append of existing files!)
 contained uneccessary time levels. (read_3d_binary, write_3d_binary)
+Bugfix: extra '*' removed in user_statistics sample code (user_interface)
 
-flow_statistics, plant_canopy_model, read_3d_binary, write_3d_binary
+flow_statistics, plant_canopy_model, read_3d_binary, user_interface, write_3d_binary
 
Index: /palm/trunk/SOURCE/calc_spectra.f90
===================================================================
--- /palm/trunk/SOURCE/calc_spectra.f90	(revision 143)
+++ /palm/trunk/SOURCE/calc_spectra.f90	(revision 144)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! user-defined spectra
 !
 ! Former revisions:
@@ -180,6 +180,10 @@
        
     CASE DEFAULT
-       PRINT*, '+++ preprocess_spectra: Spectra of ', &
-               TRIM( data_output_sp(m) ), ' can not be calculated'
+!
+!--    The DEFAULT case is reached either if the parameter data_output_sp(m)
+!--    contains a wrong character string or if the user has coded a special
+!--    case in the user interface. There, the subroutine user_spectra 
+!--    checks which of these two conditions applies.
+       CALL user_spectra( 'preprocess', m, pr )
           
     END SELECT
Index: /palm/trunk/SOURCE/data_output_spectra.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_spectra.f90	(revision 143)
+++ /palm/trunk/SOURCE/data_output_spectra.f90	(revision 144)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! user-defined spectra
 !
 ! Former revisions:
@@ -117,6 +117,11 @@
 
              CASE DEFAULT
-                PRINT*, '+++ data_output_spectra: Spectra of ', &
-                             TRIM( data_output_sp(m) ), ' are not defined'
+!
+!--             The DEFAULT case is reached either if the parameter 
+!--             data_output_sp(m) contains a wrong character string or if the 
+!--             user has coded a special case in the user interface. There, the 
+!--             subroutine user_spectra checks which of these two conditions 
+!--             applies.
+                CALL user_spectra( 'data_output', m, pr )
 
           END SELECT
Index: /palm/trunk/SOURCE/netcdf.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf.f90	(revision 143)
+++ /palm/trunk/SOURCE/netcdf.f90	(revision 144)
@@ -7,5 +7,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! user-defined spectra
 !
 ! Former revisions:
@@ -2867,4 +2867,28 @@
           i = 1
           DO WHILE ( data_output_sp(i) /= ' '  .AND.  i <= 10 )
+!
+!--          First check for the vertical grid
+             found = .TRUE.
+             SELECT CASE ( data_output_sp(i) )
+!
+!--             Most variables are defined on the zu levels
+                CASE ( 'e', 'p', 'pc', 'pr', 'pt', 'q', 'ql', 'ql_c', 'ql_v', &
+                       'ql_vp', 'qv', 'rho', 's', 'sa', 'u', 'v', 'vpt' )
+
+                   grid_z = 'zu'
+!
+!--             zw levels
+                CASE ( 'w' )
+
+                   grid_z = 'zw'
+
+                CASE DEFAULT
+!
+!--                Check for user-defined quantities (found, grid_x and grid_y
+!--                are dummies)
+                   CALL user_define_netcdf_grid( data_output_sp(i), found,  &
+                                                 grid_x, grid_y, grid_z )
+
+             END SELECT
 
              IF ( INDEX( spectra_direction(i), 'x' ) /= 0 )  THEN
@@ -2873,5 +2897,6 @@
 !--             Define the variable
                 netcdf_var_name = TRIM( data_output_sp(i) ) // '_x'
-                IF ( data_output_sp(i) == 'w' )  THEN
+                CALL clean_netcdf_varname( netcdf_var_name )
+                IF ( TRIM( grid_z ) == 'zw' )  THEN
                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
                                            nc_precision(7), (/ id_dim_x_sp, &
@@ -2903,5 +2928,6 @@
 !--             Define the variable
                 netcdf_var_name = TRIM( data_output_sp(i) ) // '_y'
-                IF ( data_output_sp(i) == 'w' )  THEN
+                CALL clean_netcdf_varname( netcdf_var_name )
+                IF ( TRIM( grid_z ) == 'zw' )  THEN
                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
                                            nc_precision(7), (/ id_dim_y_sp, &
Index: /palm/trunk/SOURCE/user_interface.f90
===================================================================
--- /palm/trunk/SOURCE/user_interface.f90	(revision 143)
+++ /palm/trunk/SOURCE/user_interface.f90	(revision 144)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! new subroutine user_spectra
 !
 ! Former revisions:
@@ -56,4 +56,5 @@
 !-- Sample for user-defined output
 !    REAL, DIMENSION(:,:,:), ALLOCATABLE ::  u2, u2_av
+!    REAL, DIMENSION(:,:,:), ALLOCATABLE ::  ustvst
 
     SAVE
@@ -198,4 +199,5 @@
 !-- Sample for user-defined output
 !    ALLOCATE( u2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
+!    ALLOCATE( ustvst(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
 !
 !    IF ( initializing_actions == 'read_restart_data' )  THEN
@@ -456,4 +458,13 @@
 !                ENDDO
 !             ENDDO
+!             DO  i = nxl-1, nxr+1
+!                DO  j = nys-1, nyn+1
+!                   DO  k = nzb, nzt+1
+!                      ustvst(k,j,i) =  &
+!                         ( 0.5 * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,0) ) * &
+!                         ( 0.5 * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,0) )
+!                   ENDDO
+!                ENDDO
+!             ENDDO
 
 
@@ -561,4 +572,74 @@
  END MODULE user_actions_mod
 
+
+
+ SUBROUTINE user_spectra( mode, m, pr )
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+! Calculation of user-defined spectra.
+! See section 3.5.4 on how to define, calculate, and output user defined
+! quantities.
+!------------------------------------------------------------------------------!
+
+    USE arrays_3d
+    USE indices
+    USE spectrum
+    USE statistics
+    USE user
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=*) ::  mode
+
+    INTEGER ::  i, j, k, m, pr
+
+
+!
+!-- Sample on how to calculate spectra of user-defined quantities. 
+!-- Each quantity is identified by the corresponding user profile index
+!-- "pr_palm+#" where "#" is an integer starting from 1. These
+!-- user-profile-numbers must also be assigned to the respective strings
+!-- given by data_output_pr_user in routine user_check_data_output_pr.
+    IF ( mode == 'preprocess' )  THEN
+
+       SELECT CASE ( TRIM( data_output_sp(m) ) )
+          
+          CASE ( 'u', 'v', 'w', 'pt', 'q' )
+!--          Not allowed here since these are the standard quantities used in 
+!--          preprocess_spectra.
+       
+!          CASE ( 'u*v*' )
+!             pr = pr_palm+1
+!             d(nzb+1:nzt,nys:nyn,nxl:nxr) = ustvst(nzb+1:nzt,nys:nyn,nxl:nxr)
+       
+          CASE DEFAULT
+             PRINT*, '+++ user_spectra/preprocess: Spectra of ', &
+                  TRIM( data_output_sp(m) ), ' can not be calculated'
+          
+       END SELECT
+
+    ELSEIF ( mode == 'data_output' )  THEN
+
+       SELECT CASE ( TRIM( data_output_sp(m) ) )
+
+          CASE ( 'u', 'v', 'w', 'pt', 'q' )
+!--          Not allowed here since these are the standard quantities used in 
+!--          data_output_spectra.
+
+!          CASE ( 'u*v*' )
+!             pr = 6
+
+          CASE DEFAULT
+             PRINT*, '+++ user_spectra/data_output: Spectra of ', &
+                          TRIM( data_output_sp(m) ), ' are not defined'
+
+          END SELECT
+
+    ENDIF
+
+ END SUBROUTINE user_spectra
 
 
@@ -600,5 +681,5 @@
 !       DO  i = nxl, nxr
 !          DO  j = nys, nyn
-!             DO  k = nzb_s_outer(j,i)+1, nzt
+!             DO  k = nzb_s_inner(j,i)+1, nzt
 !!
 !!--             Sample on how to calculate the profile of the resolved-scale
@@ -606,5 +687,5 @@
 !                sums_l(k,pr_palm+1,tn) = sums_l(k,pr_palm+1,tn) +           &
 !                      ( 0.5 * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,sr) ) * &
-!                      ( 0.5 * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) ) * &
+!                      ( 0.5 * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) )   &
 !                                                 * rmask(j,i,sr)
 !!
@@ -796,4 +877,7 @@
 !--    Uncomment and extend the following lines, if necessary
 !       CASE ( 'u2' )
+!          unit = 'm2/s2'
+!
+!       CASE ( 'u*v*' )
 !          unit = 'm2/s2'
 !
@@ -890,4 +974,9 @@
 !       CASE ( 'u2', 'u2_xy', 'u2_xz', 'u2_yz' )
 !          grid_x = 'xu'
+!          grid_y = 'y'
+!          grid_z = 'zu'
+
+!       CASE ( 'u*v*', 'u*v*_xy', 'u*v*_xz', 'u*v*_yz' )
+!          grid_x = 'x'
 !          grid_y = 'y'
 !          grid_z = 'zu'
