Index: palm/trunk/SCRIPTS/NCL/timeseries.ncl
===================================================================
--- palm/trunk/SCRIPTS/NCL/timeseries.ncl	(revision 308)
+++ palm/trunk/SCRIPTS/NCL/timeseries.ncl	(revision 310)
@@ -139,4 +139,5 @@
 
    vNam=getfilevarnames(f_att)
+   vNam_static=vNam
 
    print(" ")
@@ -147,11 +148,11 @@
    if (dim .EQ. 0) then
       print(" ")
-      print("There are no data on file")
+      print("There is no data on file")
       print(" ")
    end if
 
-   t_all = f[:]->time
-   nt  = dimsizes(t_all)
-   delta_t=t_all(nt-1)/nt
+   t_all   = f[:]->time
+   nt      = dimsizes(t_all)
+   delta_t = t_all(nt-1)/nt
 
    ;****************************************************	
@@ -344,6 +345,60 @@
    end if
 
-   count_var=0
-   do varn = dim-1,0,1 
+
+   if (var .NE. "all") then
+      vNam_temp = new((/dim/),string)
+      comma     = 0
+      var_char  = stringtocharacter(var)
+      no_char   = dimsizes(var_char)
+       
+      do j = 0, no_char-1
+         if(var_char(j) .eq. ",")
+            comma = comma + 1
+         end if
+      end do
+
+      indices = new((/comma/), integer)
+      comma   = 0
+        
+      do j = 0, no_char-1
+         if(var_char(j) .eq. ",")
+           indices(comma) = j
+           comma = comma + 1
+         end if
+      end do
+
+      do j = 0, comma -2
+         vNam_temp(j) = charactertostring(var_char(indices(j)+1:indices(j+1)-1))
+      end do
+     
+      delete(vNam)
+      vNam = new((/comma-1/),string)
+      do varn = 0, comma - 2
+         vNam(varn) = vNam_temp(comma - 2 - varn)
+      end do
+     
+      do j = 0, comma-2
+        count_check = 0
+        do varn = 0, dim-1 
+           if(vNam(j) .ne. vNam_static(varn)) 
+             count_check=count_check+1
+           end if
+        end do  
+   
+        if(count_check .eq. dim)
+            print(" ")
+            print("The variables 'var="+var+"'" )
+            print("do not exist on your input file;")
+            print("be sure to have one comma before and after each variable")
+            print(" ")
+            exit
+        end if
+      end do
+
+      dim = comma-1
+    end if
+
+
+   do varn = dim-1, 0, 1 
 
       if( isStrSubset (vNam(varn), "time") )
@@ -351,18 +406,13 @@
       else
          check = True
-      end if 
-  
-      if (var .NE. "all") then
-         check = isStrSubset( var,","+vNam(varn)+"," )
-      end if 
-    
+      end if
      
       if(check) then
-         count_var=count_var+1
 
          data_all = f[:]->$vNam(varn)$ 
 	 data_att = f_att->$vNam(varn)$
          unit(varn) = data_att@units
-                
+  
+      
          data(varn,:)=data_all(start_time_step:end_time_step)
          
@@ -508,14 +558,14 @@
       end if
    end do
-
-   if (count_var .EQ. 0) then
-      print(" ")
-      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
+ 
+  if (isStrSubset(data@long_name," SR " ))then
+      print(" ")
+      print("If you have outputs of statistic regions you cannot overlay variables;")
+      print("'over' is set to 0" )
+      print(" ")
+      over = 0
    end if
 
-   do varn = dim-1,0,1 
+   do varn = dim-1, 0, 1 
       
       if( isStrSubset (vNam(varn), "time") )
@@ -530,12 +580,5 @@
   
       if(check) then
-
-        if (isStrSubset(vNam(varn),"_0 " ))then
-            print(" ")
-            print("If you have Outputs of statistic regions you cannot overlay variables; 'over' is set to 0")
-            print(" ")
-            over = 0
-         end if
-
+       
         if (over .EQ. 1) then
  
@@ -557,6 +600,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minE
-               res@trYMinF           = maxE
+               res@trYMaxF           = maxE
+               res@trYMinF           = minE
                plot_E = gsn_csm_xy(wks_ps,t,data(varn,:),res)
             end if
@@ -574,6 +617,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minus
-               res@trYMinF           = maxus
+               res@trYMaxF           = maxus
+               res@trYMinF           = minus
                plot_us = gsn_csm_xy(wks_ps,t,data(varn,:),res)
             end if             
@@ -591,6 +634,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minu
-               res@trYMinF           = maxu
+               res@trYMaxF           = maxu
+               res@trYMinF           = minu
                plot_umax = gsn_csm_xy(wks_ps,t,data(varn,:),res)
             end if
@@ -615,6 +658,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minz
-               res@trYMinF           = maxz 
+               res@trYMaxF           = maxz
+               res@trYMinF           = minz 
                plot_z_i_wpt = gsn_csm_xy(wks_ps,t,data(varn,:),res)
             end if
@@ -632,6 +675,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minw
-               res@trYMinF           = maxw
+               res@trYMaxF           = maxw
+               res@trYMinF           = minw
                plot_wpptp0 = gsn_csm_xy(wks_ps,t,data(varn,:),res)
             end if
@@ -656,6 +699,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = minp
-               res@trYMinF           = maxp
+               res@trYMaxF           = maxp
+               res@trYMinF           = minp
                plot_pt_0_ = gsn_csm_xy(wks_ps,t,data(varn,:),res)  
             end if
@@ -673,6 +716,6 @@
                res@xyLineLabelFontHeightF = 0.05 
                res@xyLineLabelFontColor   = 237
-               res@trYMaxF           = mins
-               res@trYMinF           = maxs
+               res@trYMaxF           = maxs
+               res@trYMinF           = mins
                plot_splptx = gsn_csm_xy(wks_ps,t,data(varn,:),res)    
             end if
@@ -695,7 +738,8 @@
       end if
    end do
+
+
+   do varn = dim-1, 0, 1 
    
-   do varn = dim-1,0,1
- 
       if( isStrSubset (vNam(varn), "time") )
          check = False
@@ -819,4 +863,5 @@
                   overlay(plot_umax,plot_vmax)
                   overlay(plot_umax,plot_wmax)
+                
                   n=n+1
                   plot_ps(n) = plot_umax
@@ -1177,22 +1222,41 @@
                res@gsnLeftString  = vNam(varn)
                res@gsnRightString = unit(varn) 
-               res@trYMaxF        = min(data(varn,:))
-               res@trYMinF        = max(data(varn,:))
+               res@trYMaxF        = max(data(varn,:))
+               res@trYMinF        = min(data(varn,:))
                if (min(data(varn,:)) .EQ. max(data(varn,:))) then
                   if (min(data(varn,:)) .EQ. 0)then
-                     res@trYMaxF = min(data(varn,:))-0.1
-                     res@trYMinF = max(data(varn,:))+0.1
+                     res@trYMaxF = max(data(varn,:))-0.1
+                     res@trYMinF = min(data(varn,:))+0.1
                   end if
                   if (min(data(varn,:)) .LT. 0)then
-                     res@trYMaxF = min(data(varn,:))+(min(data(varn,:)))/2
-                     res@trYMinF = max(data(varn,:))-(max(data(varn,:)))/2
+                     res@trYMaxF = max(data(varn,:))+(min(data(varn,:)))/2
+                     res@trYMinF = min(data(varn,:))-(max(data(varn,:)))/2
                   end if
                   if (min(data(varn,:)) .GT. 0)then
-                     res@trYMaxF = min(data(varn,:))-(min(data(varn,:)))/2
-                     res@trYMinF = max(data(varn,:))+(max(data(varn,:)))/2
+                     res@trYMaxF = max(data(varn,:))-(min(data(varn,:)))/2
+                     res@trYMinF = min(data(varn,:))+(max(data(varn,:)))/2
                   end if
                end if
                plot_ps(n) = gsn_csm_xy(wks_ps,t,data(varn,:),res)  
             end if
+
+            ; ***************************************************
+            ; transparent legend as placeholder for single plots
+            ; ***************************************************
+            lgresmono                    = True
+            lgMonoDashIndex              = False
+            lgresmono@lgMonoLineColor    = True
+            lgresmono@lgLabelFont        = "helvetica"    
+            lgresmono@lgLabelFontHeightF = .1            
+            lgresmono@vpWidthF           = 0.4           
+            lgresmono@vpHeightF          = 0.4          
+            lgresmono@lgLineColor        = 0
+            lgresmono@lgPerimOn          = False
+            lbid = gsn_create_legend(wks_ps,1,(/""/),lgresmono)       
+
+            amres = True
+            amres@amParallelPosF   = 0.6		    
+            amres@amOrthogonalPosF = -0.2            
+            annoid1 = gsn_add_annotation(plot_ps(n),lbid,amres)
        
          else
@@ -1204,4 +1268,5 @@
             res@gsnLeftString       = vNam(varn)
             res@gsnRightString      = unit(varn)
+        
 	    if (norm_t .NE. 1.)then
                res@tiXAxisString        = "t ["+unit_t+"]"
@@ -1215,18 +1280,18 @@
 	    res@tmXBLabelFontHeightF = font_size
             res@tmYLLabelFontHeightF = font_size
-            res@trYMaxF        = min(data(varn,:))
-            res@trYMinF        = max(data(varn,:)) 
+            res@trYMaxF        = max(data(varn,:))
+            res@trYMinF        = min(data(varn,:)) 
             if (min(data(varn,:)) .EQ. max(data(varn,:))) then
                if (min(data(varn,:)) .EQ. 0)then
-                     res@trYMaxF = min(data(varn,:))-0.1
-                     res@trYMinF = max(data(varn,:))+0.1
+                     res@trYMaxF = max(data(varn,:))-0.1
+                     res@trYMinF = min(data(varn,:))+0.1
                   end if
                   if (min(data(varn,:)) .LT. 0)then
-                     res@trYMaxF = min(data(varn,:))+(min(data(varn,:)))/2
-                     res@trYMinF = max(data(varn,:))-(max(data(varn,:)))/2
+                     res@trYMaxF = max(data(varn,:))+(min(data(varn,:)))/2
+                     res@trYMinF = min(data(varn,:))-(max(data(varn,:)))/2
                   end if
                   if (min(data(varn,:)) .GT. 0)then
-                     res@trYMaxF = min(data(varn,:))-(min(data(varn,:)))/2
-                     res@trYMinF = max(data(varn,:))+(max(data(varn,:)))/2
+                     res@trYMaxF = max(data(varn,:))-(min(data(varn,:)))/2
+                     res@trYMinF = min(data(varn,:))+(max(data(varn,:)))/2
                   end if
             end if
