Index: palm/trunk/SCRIPTS/NCL/spectra.ncl
===================================================================
--- palm/trunk/SCRIPTS/NCL/spectra.ncl	(revision 183)
+++ palm/trunk/SCRIPTS/NCL/spectra.ncl	(revision 190)
@@ -2,35 +2,42 @@
 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
- 
+
+;***************************************************
+; load ncl_preferences.ncl
+;***************************************************
+   
+if (isfilepresent("~/ncl_preferences.ncl")) then
+   loadscript("~/ncl_preferences.ncl")
+else
+  if (isfilepresent("~/palm/current_version/trunk/SCRIPTS/NCL/ncl_preferences.ncl")) then
+     loadscript( "~/palm/current_version/trunk/SCRIPTS/NCL/ncl_preferences.ncl")
+  else
+      print(" ")
+      print("'ncl_preferences.ncl' does not exist in $home or $home/palm/current_version/trunk/SCRIPTS/NCL/")
+      print(" ")
+      exit
+   end if
+end if
+   
 begin
-
-   ; ***************************************************
-   ; read parameter_list
-   ; ***************************************************
-
-   if (isfilepresent("~/.ncl_preferences")) then
-      parameter = asciiread("~/.ncl_preferences",129,"string")
-      delete(parameter@_FillValue)
-   else
-      if (isfilepresent("~/palm/current_version/trunk/SCRIPTS/NCL/.ncl_preferences")) then
-         parameter = asciiread("~/palm/current_version/trunk/SCRIPTS/NCL/.ncl_preferences",129,"string")
-         delete(parameter@_FillValue)
-      else
-         print(" ")
-         print("'.ncl_preferences' does not exist in '~/palm/current_version/trunk/SCRIPTS/NCL/'")
-         print(" ")
-         exit
-      end if
-   end if
-
-   if ( .not. isvar("file_1") ) then     		  
-      if (parameter(7) .EQ. "File in") then
-         print(" ")
-         print("Please provide 1st input file 'file_1=' either in prompt or parameter_list")
-         print(" ")
-         exit
-      else
-         file_in = parameter(7)
-      end if   
+      
+   if (cross_sections .NE. 0 .OR. profiles .NE. 0 .OR. timeseries .NE. 0 .OR. spectra .NE. 1)then
+      print(" ")
+      print("Please specify the used script in 'ncl_preferences.ncl' (Line 7-10)")
+      print(" ")
+      print("Set 'spectra' equal 1 and the other variables equal 0")
+      print(" ")
+      exit
+   end if 
+
+   ;***************************************************
+   ; set up default parameter values and strings
+   ;***************************************************
+  
+   if (file_1 .EQ. "File in") then
+      print(" ")
+      print("Please provide 1st input file 'file_1=' in 'ncl_preferences.ncl'")
+      print(" ")
+      exit 
    else
       file_in = file_1   
@@ -38,144 +45,67 @@
    if (.not. isfilepresent(file_in)) then
       print(" ")
-      print("Your 1st input file: '"+file_in+"' does not exist")
+      print("1st input file: '"+file_in+"' does not exist")
       print(" ")
       exit
    end if 
 
-   if ( .not. isvar("format_out") ) then   		
-      format_out = "x11"
-      if (parameter(9) .NE. "x11") then
-         format_out = parameter(9)  
-         if (format_out .NE. "x11" .AND. format_out .NE. "pdf" .AND. format_out .NE. "eps" .AND. format_out .NE. "ps" .AND. format_out .NE. "epsi" .AND. format_out .NE. "ncgm")then
-            print(" ")
-            print("Your 'format_out = "+format_out+"' is invalid and set to'x11'")
-            print(" ")
-         end if  
-      end if 
-   else
-      if (format_out .NE. "x11" .AND. format_out .NE. "pdf" .AND. format_out .NE. "eps" .AND. format_out .NE. "ps" .AND. format_out .NE. "epsi" .AND. format_out .NE. "ncgm")then
-         print(" ")
-         print("Your 'format_out = "+format_out+"' is invalid and set to'x11'")
-         print(" ")
-      end if   
-   end if
-
-   if ( .not. isvar("file_out") ) then    	 
-      file_out = "test"
-      if (parameter(11) .NE. "test_ts") then
-         file_out = parameter(11)  
-     end if     
-   end if
-   if ( .not. isvar("no_columns") ) then    	
-      no_columns = 1
-      if (parameter(17) .NE. "1") then
-         no_columns = stringtointeger(parameter(17))  
-      end if
-   end if
-   if ( .not. isvar("no_lines") ) then     		
-      no_lines = 2
-      if (parameter(19) .NE. "2") then
-         no_lines = stringtointeger(parameter(19))  
-      end if
+   if (format_out .NE. "x11" .AND. format_out .NE. "pdf" .AND. format_out .NE. "eps" .AND. format_out .NE. "ps" .AND. format_out .NE. "epsi" .AND. format_out .NE. "ncgm")then
+      print(" ")
+      print("'format_out = "+format_out+"' is invalid and set to'x11'")
+      print(" ")
+      format_out="x11"
    end if 
-
-   if (.not. isvar("logy"))then
-      logy = 0
-      if (stringtointeger(parameter(77)) .NE. 0) then
-         logy = stringtointeger(parameter(77))
-         if (stringtointeger(parameter(77)) .NE. 1) then
-            print(" ")
-            print("Your 'logy'= "+logy+" is invalid and set to 0")
-            print(" ")
-            logy = 0
-         end if   
-      end if
-   else
-      if (logy .NE. 0 .AND. logy .NE. 1)then
-         print(" ")
-         print("Your 'logy'= "+logy+" is invalid and set to 0")
-         print(" ")
-         logy = 0
-      end if    
-   end if
-
-   if ( .not. isvar("sort") ) then   			
-      sort = "layer"
-      if (parameter(51) .NE. "layer") then
-         sort = parameter(51)  
-         if (sort .NE. "time") then
-            print(" ")
-            print("Your 'sort'= "+sort+" is invalid and set to 'layer'")
-            print(" ")
-            sort = "layer"  
-         end if
-      end if
-   else
-      if (sort .NE. "time" .OR. sort .NE. "layer")then
-         print(" ")
-         print("Your 'sort'= "+sort+" is invalid and set to 'layer'")
-         print(" ")
-         sort = "layer"    
-      end if
-   end if 
-
-   if ( .not. isvar("black") ) then  		 	
+   
+   if (logx .NE. 0 .AND. logx .NE. 1)then
+      print(" ")
+      print("'logx'= "+logx+" is invalid and set to 1")
+      print(" ")
+      logx = 1
+   end if  
+   
+   if (logy .NE. 0 .AND. logy .NE. 1)then
+      print(" ")
+      print("'logy'= "+logy+" is invalid and set to 1")
+      print(" ")
+      logy = 1
+   end if    
+  
+   if (normy .EQ. 0.) then 
+      print(" ")
+      print("You cannot normalise the y-axis with 0, 'normy' is set to 1.0")
+      print(" ")
+      normy = 1.0
+   end if
+   if (normx .EQ. 0.) then 
+      print(" ")
+      print("You cannot normalise the x-axis with 0, 'normx' is set to 1.0")
+      print(" ")
+      normx= 1.0
+   end if
+   
+   if (sort .NE. "height" .AND. sort .NE. "time") then  
+      print(" ")
+      print("'sort'= "+sort+" is invalid and set to 'height'")
+      print(" ")
+      sort = "height"  
+   end if
+   
+   if (black .NE. 0 .AND. black .NE. 1)then
+      print(" ")
+      print("'black'= "+black+" is invalid and set to 0")
+      print(" ")
       black = 0
-      if (parameter(31) .NE. "0") then
-         black = stringtointeger(parameter(31)) 
-         if (stringtointeger(parameter(31)) .NE. 1) then
-            print(" ")
-            print("Your 'black'= "+black+" is invalid and set to 0")
-            print(" ")
-            black = 0
-         end if
-      end if
-   else
-      if (black .NE. 0 .AND. black .NE. 1)then
-         print(" ")
-         print("Your 'black'= "+black+" is invalid and set to 0")
-         print(" ")
-         black = 0
-      end if
-   end if
-   if ( .not. isvar("dash") ) then   		 	
+   end if
+ 
+   if (dash .NE. 0 .AND. dash .NE. 1)then
+      print(" ")
+      print("'dash'= "+dash+" is invalid and set to 0")
+      print(" ")
       dash = 0
-      if (parameter(29) .NE. "0") then
-         dash = stringtointeger(parameter(29))
-         if (stringtointeger(parameter(29)) .NE. 1) then
-            print(" ")
-            print("Your 'dash'= "+dash+" is invalid and set to 0")
-            print(" ")
-            dash = 0
-         end if  
-      end if
-   else
-      if (dash .NE. 0 .AND. dash .NE. 1)then
-         print(" ")
-         print("Your 'dash'= "+dash+" is invalid and set to 0")
-         print(" ")
-         dash = 0
-      end if
-   end if
-
-   if ( .not. isvar("norm") ) then     		
-      norm = 1.0
-      if (parameter(79) .NE. "1") then
-         norm = stringtofloat(parameter(79)) 
-         if (stringtofloat(parameter(79)) .EQ. 0) then 
-            print(" ")
-            print("You cannot normalise with 0, 'norm' is set to 1")
-            print(" ")
-            norm = 1.0
-         end if
-      end if
-   else
-      if (norm .EQ. 0) then 
-         print(" ")
-         print("You cannot normalise with 0, 'norm' is set to 1")
-         print(" ")
-         norm = 1.0
-      end if
-   end if 
+   end if
+
+   ;***************************************************
+   ; open input file
+   ;***************************************************
 
    f=addfile(file_in,"r")
@@ -183,5 +113,6 @@
    vNam = getfilevarnames(f) 
    print(" ")
-   print("Variable in input file: " + vNam)
+   print("Variables in input file:")
+   print("- "+ vNam)
    print(" ")
    dim = dimsizes(vNam)
@@ -192,41 +123,61 @@
    delta_t=t_all(nt-1)/nt
    
+   k_x=f->k_x
+   dimx=dimsizes(k_x)
+   k_y=f->k_y
+   dimy=dimsizes(k_y)
+   
+   
+   dim_level=dimsizes(height_level)
+
    do i=0,dim-1
       if (vNam(i) .EQ. "zu_sp")then
-         zu=f->zu_sp
-         z=zu
-         dimz=dimsizes(zu)
+         zu=f->zu_sp	 
+	 if (height_level(0) .EQ. -1)then
+	    dimz=dimsizes(zu)
+	 else
+	    if (dim_level .GT. dimsizes(zu))then
+               print(" ")
+               print("'height_level' has more elements than available height levels in input file (= "+dimz+")")
+               print(" ")
+               exit
+	    else
+	       zuh=new(dim_level,double)
+	       do le=0,dim_level-1
+	          zuh(le)=zu(height_level(le))
+	       end do
+	       dimz=dim_level
+            end if   
+	 end if	 
       else 
          if (vNam(i) .EQ. "zw_sp")then
-            zw=f->zw_sp
-            z=zw
-            dimz=dimsizes(zw)
+	    zw=f->zw_sp
+	    if (height_level(0) .EQ. -1)then              
+               dimz=dimsizes(zw)
+	    else
+	       if (dim_level .GT. dimsizes(zw))then
+                  print(" ")
+                  print("'height_level' has more elements than available height levels in input file (= "+dimz+")")
+                  print(" ")
+                  exit
+	       else
+	          zwh=new(dim_level,double)
+	          do le=0,dim_level-1
+	             zwh(le)=zw(height_level(le))
+	          end do
+	          dimz=dim_level
+               end if   
+	    end if
          end if
       end if
    end do
-   
-   ; ****************************************************	
+
+   ;****************************************************	
    ; start of time step and different types of mistakes that could be done
-   ; ****************************************************
-   
-   if ( .not. isvar("start_time_step") ) then   	
+   ;****************************************************
+   
+   if (start_time_step .EQ. -1.d) then   	
       start_time_step=t_all(0)/3600
-      if (parameter(13) .NE. "t(0)") then
-         if (stringtodouble(parameter(13)) .GT. t_all(nt-1)/3600)then
-            print(" ")
-            print("'start_time_step' = "+ parameter(13) +"h is greater than last time step = " + t_all(nt-1)+"s = "+t_all(nt-1)/3600+"h")
-            print(" ")
-            print("Please select another 'start_time_step'")
-            print(" ")
-            exit
-         end if
-         if (stringtofloat(parameter(13)) .LT. t_all(0)/3600)then
-            print(" ")
-            print("'start_time_step' = "+ parameter(13) +"h is lower than first time step = " + t_all(0)+"s = "+t_all(0)/3600+"h")           
-            exit
-         end if
-         start_time_step=stringtodouble(parameter(13)) 
-      end if
-   else 
+   else
       if (start_time_step .GT. t_all(nt-1)/3600)then
          print(" ")
@@ -243,8 +194,7 @@
       end if
    end if
-   start_time_step = start_time_step*3600
 
    do i=0,nt-1     
-      if (start_time_step .GE. t_all(i)-delta_t/2 .AND. start_time_step .LT. t_all(i)+delta_t/2)then
+      if (start_time_step .GE. (t_all(i)-delta_t/2)/3600 .AND. start_time_step .LT. (t_all(i)+delta_t/2)/3600)then
          st=i
          break
@@ -252,29 +202,19 @@
    end do
    
-   ; ****************************************************
+   if (.not. isvar("st"))then
+      print(" ")
+      print("'start_time_step' = "+ start_time_step +"h is invalid")
+      print(" ")
+      print("Please select another 'start_time_step'")
+      print(" ")
+      exit
+   end if
+   
+   ;****************************************************
    ; end of time step and different types of mistakes that could be done
-   ; ****************************************************
-
-   if ( .not. isvar("end_time_step") ) then     	
+   ;****************************************************
+
+   if (end_time_step .EQ. -1.d) then     	
       end_time_step = t_all(nt-1)/3600
-      if (parameter(15) .NE. "t(end)") then
-         if (stringtodouble(parameter(15)) .GT. t_all(nt-1)/3600)then
-            print(" ")
-            print("'end_time_step' = "+ parameter(15) +"h is greater than last time step = " + t_all(nt-1)+"s = "+t_all(nt-1)/3600+"h")
-            print(" ")
-            print("Please select another 'end_time_step'")  
-            print(" ")
-            exit
-         end if
-         if (stringtodouble(parameter(15)) .LT. start_time_step/3600)then
-            print(" ")
-            print("'end_time_step' = "+ parameter(15) +"h is lower than 'start_time_step' = "+start_time_step/3600+"h")
-            print(" ")
-            print("Please select another 'start_time_step' or 'end_time_step'")
-            print(" ")
-            exit
-         end if
-         end_time_step = stringtodouble(parameter(15))
-      end if    
    else
       if (end_time_step .GT. t_all(nt-1)/3600)then
@@ -295,12 +235,20 @@
       end if
    end if
-   end_time_step = end_time_step*3600
 
    do i=0,nt-1     
-      if (end_time_step .GE. t_all(i)-delta_t/2 .AND. end_time_step .LT. t_all(i)+delta_t/2)then
+      if (end_time_step .GE. (t_all(i)-delta_t/2)/3600 .AND. end_time_step .LT. (t_all(i)+delta_t/2)/3600)then
          et=i
          break
       end if
    end do 
+   
+   if (.not. isvar("et"))then
+      print(" ")
+      print("'end_time_step' = "+ end_time_step +"h is invalid")
+      print(" ")
+      print("Please select another 'end_time_step'")
+      print(" ")
+      exit
+   end if
 
    delete(start_time_step)
@@ -316,7 +264,7 @@
    dimt = end_time_step-start_time_step+1
  
-   ; ***************************************************
+   ;***************************************************
    ; set up recourses
-   ; ***************************************************
+   ;***************************************************
      
    res = True
@@ -337,5 +285,5 @@
    res@pmLegendDisplayMode     = "Always"
    res@pmLegendSide            = "Top"
-   res@pmLegendParallelPosF    = 1.15
+   res@pmLegendParallelPosF    = 1.2
    res@pmLegendOrthogonalPosF  = -1.0
    res@pmLegendWidthF          = 0.12
@@ -345,15 +293,18 @@
       res@pmLegendHeightF         = 0.04*dimz
    end if
-   res@lgLabelFontHeightF     = .02 
-   res@lgTitleFontHeightF     = .02
-   res@txFontHeightF      = 0.02
-   res@tiXAxisFontHeightF = 0.02
-   res@tiYAxisFontHeightF = 0.02
-   
-   if (logy .EQ. 1) then
+   res@lgLabelFontHeightF     = .025 
+   res@lgTitleFontHeightF     = .025
+   res@txFontHeightF      = 0.025
+   res@tiXAxisFontHeightF = 0.025
+   res@tiYAxisFontHeightF = 0.025
+   
+   if (logx .EQ. 1) then
       res@trXLog = True 
+   else
+      res@trXLog = False 
+   end if
+   if (logy .EQ. 1)then
       res@trYLog = True 
-   else 
-      res@trXLog = False 
+   else  
       res@trYLog = False
    end if
@@ -379,18 +330,26 @@
       res@lgTitleString = "Height [m]"  
       do p=0,dimz-1
-         legend_label_zu(p)=round(zu(p),3)
-         legend_label_zw(p)=round(zw(p),3)
+         if (height_level(0) .EQ. -1)then
+            legend_label_zu(p)=round(zu(p),3)
+            legend_label_zw(p)=round(zw(p),3)
+	 else
+	    legend_label_zu(p)=round(zuh(p),3)
+	    legend_label_zw(p)=round(zwh(p),3)
+	 end if
       end do
    end if
-
-   if ( black .eq. 0 ) then  
-      res@xyLineColors = ispan(2,237,235/np)
+   
+   step=round(235/(np-1),3)
+   if (black .eq. 0 ) then  
+      res@xyLineColors = ispan(2,237,step)
    end if
    if ( dash .eq. 0 ) then
-      res@xyMonoDashPattern       = True 
+      res@xyMonoDashPattern = True 
    end if
 
    wks=gsn_open_wks(format_out,file_out)
    gsn_define_colormap(wks,"rainbow+white") 
+
+   temp=new((/dimt,dimz,dimx/),float)
 
    n=0
@@ -403,57 +362,82 @@
       end if
 
-      if (.not. isvar("var")) then
-         if (parameter(21) .NE. "variables") then
-            var=parameter(21)
-            check = isStrSubset( var,","+vNam(varn)+"," )
-         end if
-      else          
+      if (var .NE. "all") then
          check = isStrSubset( var,","+vNam(varn)+"," )
       end if
 
-      if(check) then
-
+      if(check) then 
+      
          temp = f->$vNam(varn)$(start_time_step:end_time_step,0:dimz-1,:)
-
-         temp=temp/norm  ;SMOOTHING: #temp=smth9(temp/norm, 0.50, -0.25, False)#
-   
+	    
          a=getvardims(temp)
-         b=dimsizes(a)            
+         b=dimsizes(a)
+
+         if (height_level(0) .NE. -1)then
+	    do te=0,dimz-1
+	       temp(:,te,:) = f->$vNam(varn)$(start_time_step:end_time_step,height_level(te),:)	       
+	    end do
+	 end if
+
+         temp=temp/(normy*normx)  ;SMOOTHING: #temp=smth9(temp/norm, 0.50, -0.25, False)#
+            
          do i=0,b-1            
             if (isStrSubset( a(i),"zu_sp" ))then
                legend_label_z=legend_label_zu
+	       if (height_level(0) .NE. -1)then
+	          z=zuh
+	       else
+	          z=zu
+	       end if
             else
                if (isStrSubset( a(i),"zw_sp" ))then
-                  legend_label_z=legend_label_zw     
+                  legend_label_z=legend_label_zw 
+		  if (height_level(0) .NE. -1)then
+	             z=zwh
+	          else
+	             z=zw
+	          end if   
                end if
             end if
          end do  
+
          if (isStrSubset(vNam(varn),"x"))then
             x_axis = f->k_x
-            res@tiXAxisString = "k_x"
+	    x_axis = x_axis/normx
+	    if (normx .NE. 1.)then
+               res@tiXAxisString = "k_x / "+normx
+	    else
+	       res@tiXAxisString = "k_x" 
+	    end if
          else
             x_axis = f->k_y 
-            res@tiXAxisString = "k_y"
+	    x_axis = x_axis/normx
+	    if (normx .NE. 1.)then
+               res@tiXAxisString = "k_y / "+normx
+	    else
+	       res@tiXAxisString = "k_y" 
+	    end if
          end if
         
          if (sort .EQ. "time")
-            do p=dimz-1,0,1  
-               do q=0,dimt-1
-                  do r=0,dimsizes(x_axis)-1 
-                     if (temp(q,p,r) .EQ. 0)then
-                        st=p+start_time_step
-                        print(" ")
-                        print("'"+vNam(varn)+"("+st+","+q+","+r+")' is equal 0; Logarithmic scale for y-axis cannot be used")
-                        print(" ")
-                        res@trYLog = False
-                     end if
+            do p=dimz-1,0,1
+	       if (logy .EQ. 1)then  
+                  do q=0,dimt-1
+                     do r=0,dimsizes(x_axis)-1 
+                        if (temp(q,p,r) .EQ. 0)then
+                           st=p+start_time_step
+                           print(" ")
+                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' is equal 0; Logarithmic scale for y-axis and height "+z(p)+" cannot be used")
+                           print(" ")
+                           res@trYLog = False
+                        end if
+                     end do
                   end do
-               end do
+	       end if
                res@trXMinF = min(x_axis)
                res@trXMaxF = max(x_axis)
                res@gsnLeftString      = vNam(varn)
                res@gsnRightString     = "Height = "+z(p)+"m"
-               if (norm .NE. 1)then
-                  res@tiYAxisString      = vNam(varn)+" / "+norm
+               if (normy .NE. 1.)then
+                  res@tiYAxisString      = vNam(varn)+" / "+normy
                else
                   res@tiYAxisString      = vNam(varn)
@@ -464,6 +448,6 @@
             end do
          else
-            if (sort .EQ. "layer")
-               do p=dimt-1,0,1 
+            if (sort .EQ. "height")
+               do p=0,dimt-1 	       
                   do q=0,dimz-1
                      do r=0,dimsizes(x_axis)-1 
@@ -471,5 +455,5 @@
                            st=p+start_time_step
                            print(" ")
-                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' is equal 0; Logarithmic scale for y-axis cannot be used")
+                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' is equal 0; Logarithmic scale for y-axis and time "+legend_label(p)+" cannot be used")
                            print(" ")
                            res@trYLog = False
@@ -481,6 +465,6 @@
                   res@gsnLeftString      = vNam(varn)
                   res@gsnRightString     = "Time = "+legend_label(p)+"h"
-                  if (norm .NE. 1)then
-                     res@tiYAxisString      = vNam(varn)+" / "+norm
+                  if (normy .NE. 1.)then
+                     res@tiYAxisString      = vNam(varn)+" / "+normy
                   else
                      res@tiYAxisString      = vNam(varn)
@@ -490,11 +474,6 @@
                   n=n+1
                end do
-            else
-               print(" ")
-               print("Please choose 'sort' either equal 'time' or 'height'")
-               print(" ")
-               exit
             end if
-         end if
+	 end if
          delete(temp)
          delete(x_axis)
@@ -504,5 +483,6 @@
    if (n .EQ. 0) then
       print(" ")
-      print("The variables 'var=Â°"+var+"Â°' do not exist on your input file")
+      print("The variables 'var="+var+"' do not exist on your input file;")
+      print("be sure to have one comma berfore and after each variable")
       print(" ")
       exit
