source: palm/trunk/SCRIPTS/NCL/spectra.ncl @ 710

Last change on this file since 710 was 585, checked in by heinze, 14 years ago

Bugfix: enable plot of data if it is of kind double instead of kind float

File size: 23.5 KB
RevLine 
[176]1load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
2load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
3load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
4
[190]5;***************************************************
[418]6; load .ncl.config or .ncl.config.default
[190]7;***************************************************
[194]8
9function which_script()
10local script
11begin
12   script="spectra"
13   return(script)
14end
[190]15   
[418]16if (isfilepresent("$PALM_BIN/../../.ncl.config")) then
17   loadscript("$PALM_BIN/../../.ncl.config")
[190]18else
[418]19  if (isfilepresent("$PALM_BIN/NCL/.ncl.config.default")) then
20     loadscript( "$PALM_BIN/NCL/.ncl.config.default")
[190]21  else
[418]22      palm_bin_path = getenv("PALM_BIN")
[190]23      print(" ")
[418]24      print("Neither the personal configuration file '.ncl.config' exists in")
25      print("~/palm/current_version")
[566]26      print("nor the default configuration file '.ncl.config.default' "+\
27            "exists in")
[418]28      print(palm_bin_path + "/NCL")
[190]29      print(" ")
30      exit
[176]31   end if
[418]32end if   
[218]33
[190]34begin
[176]35
[190]36   ;***************************************************
[532]37   ; Retrieving the NCL version used
38   ;***************************************************
39   
40   ncl_version_ch = systemfunc("ncl -V")
41   ncl_version    = stringtofloat(ncl_version_ch)
42
43   ;***************************************************
[526]44   ; Retrieving the double quote character
45   ;***************************************************
46   
47   dq=str_get_dq()
48
49   ;***************************************************
[190]50   ; set up default parameter values and strings
51   ;***************************************************
52 
53   if (file_1 .EQ. "File in") then
54      print(" ")
[418]55      print("Declare input file 'file_1=' in '.ncl.config' or prompt")
[190]56      print(" ")
57      exit
[176]58   else
59      file_in = file_1   
60   end if
61
[566]62   if (format_out .NE. "x11" .AND. format_out .NE. "pdf" .AND.   \
63       format_out .NE. "eps" .AND. format_out .NE. "ps" .AND.    \
64       format_out .NE. "epsi" .AND. format_out .NE. "ncgm" .AND. \
65       format_out .NE. "png")then
[190]66      print(" ")
67      print("'format_out = "+format_out+"' is invalid and set to'x11'")
68      print(" ")
69      format_out="x11"
70   end if
[532]71
72   if (ncl_version .LE. 5.1 .AND. format_out .EQ. "png") then
73      print(" ")
74      print("Output of png files not available")
75      print("png output is avaiable with NCL version 5.2.0 and higher ")
76      print("NCL version used: " + ncl_version_ch)
77      print(" ")
78      exit
79   end if
[190]80   
[218]81   if (log_x .NE. 0 .AND. log_x .NE. 1)then
[190]82      print(" ")
[218]83      print("'log_x'= "+log_x+" is invalid and set to 1")
[190]84      print(" ")
[218]85      log_x = 1
[190]86   end if 
87   
[218]88   if (log_y .NE. 0 .AND. log_y .NE. 1)then
[190]89      print(" ")
[218]90      print("'log_y'= "+log_y+" is invalid and set to 1")
[190]91      print(" ")
[218]92      log_y = 1
[190]93   end if   
94 
[218]95   if (norm_y .EQ. 0.) then
[190]96      print(" ")
[218]97      print("Normalising with 0 is not allowed, 'norm_y' is set to 1.0")
[190]98      print(" ")
[218]99      norm_y = 1.0
[176]100   end if
[218]101   if (norm_x .EQ. 0.) then
[190]102      print(" ")
[218]103      print("Normalising with 0 is not allowed, 'norm_x' is set to 1.0")
[190]104      print(" ")
[218]105      norm_x= 1.0
[176]106   end if
[190]107   
108   if (sort .NE. "height" .AND. sort .NE. "time") then 
109      print(" ")
110      print("'sort'= "+sort+" is invalid and set to 'height'")
111      print(" ")
112      sort = "height" 
[176]113   end if
[190]114   
115   if (black .NE. 0 .AND. black .NE. 1)then
116      print(" ")
117      print("'black'= "+black+" is invalid and set to 0")
118      print(" ")
[176]119      black = 0
120   end if
[190]121 
122   if (dash .NE. 0 .AND. dash .NE. 1)then
123      print(" ")
124      print("'dash'= "+dash+" is invalid and set to 0")
125      print(" ")
[176]126      dash = 0
127   end if
128
[190]129   ;***************************************************
130   ; open input file
131   ;***************************************************
[218]132   
133   file_in_1 = False
134   if (isStrSubset(file_in, ".nc"))then
135      start_f = -2
136      end_f = -2
137      file_in_1 = True     
138   end if
[176]139
[218]140   if (start_f .EQ. -1)then
141      print(" ")
[566]142      print("'start_f' must be one of the cyclic numbers (at least 0) of "+\
143            "your input file(s)")
[218]144      print(" ") 
145      exit
146   end if
147   if (end_f .EQ. -1)then
148      print(" ")
[566]149      print("'end_f' must be one of the cyclic numbers (at least 0) of "+\
150            "your input file(s)")
[218]151      print(" ") 
152      exit
153   end if
154
155   files=new(end_f-start_f+1,string)
[176]156   
[218]157   if (file_in_1)then
158      if (isfilepresent(file_in))then
159         files(0)=file_in
160      else
161         print(" ")
162         print("1st input file: '"+file_in+"' does not exist")
163         print(" ")
164         exit
165      end if
166   else   
167      if (start_f .EQ. 0)then
168         if (isfilepresent(file_in+".nc"))then
169            files(0)=file_in+".nc"
170            do i=1,end_f
171               if (isfilepresent(file_in+"."+i+".nc"))then   
172                  files(i)=file_in+"."+i+".nc"
173               else
174                  print(" ")
175                  print("Input file: '"+file_in+"."+i+".nc' does not exist")
176                  print(" ")
177                  exit 
178               end if       
179            end do         
180         else
181            print(" ")
182            print("Input file: '"+file_in+".nc' does not exist")
183            print(" ")
184            exit
185         end if
186      else
187         do i=start_f,end_f
188            if (isfilepresent(file_in+"."+i+".nc"))then   
189               files(i-start_f)=file_in+"."+i+".nc"
190            else
191               print(" ")
192               print("Input file: '"+file_in+"."+i+".nc' does not exist")
193               print(" ")
194               exit 
195            end if
196         end do
197      end if
198   end if
199
200   f=addfiles(files,"r")
201   f_att=addfile(files(0),"r")
202   ListSetType(f,"cat")
203   
204   vNam = getfilevarnames(f_att)
[585]205   vType = getfilevartypes(f_att,vNam)
206
207   if ((all(vType .eq. "double"))) then ;distinction if data is double or float
208      check_vType = True
209   else
210      check_vType = False
211   end if
212
[176]213   print(" ")
[190]214   print("Variables in input file:")
215   print("- "+ vNam)
[176]216   print(" ")
217   dim = dimsizes(vNam)
[218]218   vDim = getfiledimsizes(f_att)
[176]219 
[218]220   t_all = f[:]->time
[176]221   nt    = dimsizes(t_all)
222   delta_t=t_all(nt-1)/nt
223   
[218]224   k_x=f_att->k_x
[190]225   dimx=dimsizes(k_x)
[218]226   k_y=f_att->k_y
[190]227   dimy=dimsizes(k_y)
228   
229   
230   dim_level=dimsizes(height_level)
231
[176]232   do i=0,dim-1
233      if (vNam(i) .EQ. "zu_sp")then
[218]234         zu=f_att->zu_sp         
[190]235         if (height_level(0) .EQ. -1)then
236            dimz=dimsizes(zu)
237         else
238            if (dim_level .GT. dimsizes(zu))then
239               print(" ")
[566]240               print("'height_level' has more elements than available "+\
241                     "height levels in input file (= "+dimsizes(zu)+")")
[190]242               print(" ")
243               exit
244            else
245               zuh=new(dim_level,double)
246               do le=0,dim_level-1
[566]247                  if (height_level(le) .GE. dimsizes(zu)) then
248                     no_levels=dimsizes(zu)-1
249                     print(" ")
250                     print("Element "+le+" of 'height_level' is greater "  +\
251                          "than the maximum available index in input file "+\
252                          "which is "+no_levels+". Note that the first "   +\
253                          "element has the index 0.")
254                     print(" ")
255                     exit
256                  end if
[190]257                  zuh(le)=zu(height_level(le))
258               end do
259               dimz=dim_level
260            end if   
261         end if 
[176]262      else
263         if (vNam(i) .EQ. "zw_sp")then
[218]264            zw=f_att->zw_sp
[190]265            if (height_level(0) .EQ. -1)then             
266               dimz=dimsizes(zw)
267            else
268               if (dim_level .GT. dimsizes(zw))then
269                  print(" ")
[566]270                  print("'height_level' has more elements than available "+\
271                        "height levels in input file (= "+dimsizes(zw)+")")
[190]272                  print(" ")
273                  exit
274               else
275                  zwh=new(dim_level,double)
276                  do le=0,dim_level-1
[566]277                     if (height_level(le) .GE. dimsizes(zw)) then
278                        no_levels=dimsizes(zw)-1
279                        print(" ")
280                        print("Element "+le+" of 'height_level' is greater "+\
281                              "than the maximum available index in input "  +\
282                              "file which is "+no_levels+". Note that the " +\
283                              "first element has the index 0.")
284                        print(" ")
285                        exit
286                     end if
[190]287                     zwh(le)=zw(height_level(le))
288                  end do
289                  dimz=dim_level
290               end if   
291            end if
[176]292         end if
293      end if
294   end do
[190]295
296   ;****************************************************       
[176]297   ; start of time step and different types of mistakes that could be done
[190]298   ;****************************************************
[176]299   
[190]300   if (start_time_step .EQ. -1.d) then         
[176]301      start_time_step=t_all(0)/3600
[190]302   else
[176]303      if (start_time_step .GT. t_all(nt-1)/3600)then
304         print(" ")
[566]305         print("'start_time_step' = "+ start_time_step +"h is greater than "+\
306               "last time step = "+ t_all(nt-1)+"s = "+t_all(nt-1)/3600+"h")
[176]307         print(" ")
[218]308         print("Select another 'start_time_step'")
[176]309         print(" ")
310         exit
311      end if
312      if (start_time_step .LT. t_all(0)/3600)then
313         print(" ")
[566]314         print("'start_time_step' = "+ start_time_step +"h is lower than "+\
315               "first time step = "+ t_all(0)+"s = "+t_all(0)/3600+"h")       
[176]316         exit
317      end if
318   end if
319
320   do i=0,nt-1     
[566]321      if (start_time_step .GE. (t_all(i)-delta_t/2)/3600 .AND. \
322          start_time_step .LT. (t_all(i)+delta_t/2)/3600)then
[176]323         st=i
324         break
325      end if
326   end do
327   
[190]328   if (.not. isvar("st"))then
329      print(" ")
330      print("'start_time_step' = "+ start_time_step +"h is invalid")
331      print(" ")
[218]332      print("Select another 'start_time_step'")
[190]333      print(" ")
334      exit
335   end if
336   
337   ;****************************************************
[176]338   ; end of time step and different types of mistakes that could be done
[190]339   ;****************************************************
[176]340
[190]341   if (end_time_step .EQ. -1.d) then           
[176]342      end_time_step = t_all(nt-1)/3600
343   else
344      if (end_time_step .GT. t_all(nt-1)/3600)then
345         print(" ")
[566]346         print("'end_time_step' = "+ end_time_step +"h is greater than "+\
347               "last time step = " + t_all(nt-1)+"s = "+t_all(nt-1)/3600+"h")
[176]348         print(" ")
[218]349         print("Select another 'end_time_step'") 
[176]350         print(" ")
351         exit
352      end if
353      if (end_time_step .LT. start_time_step/3600)then
354         print(" ")
[566]355         print("'end_time_step' = "+ end_time_step +"h is lower than "+\
356               "'start_time_step' = "+start_time_step+"h")
[176]357         print(" ")
[218]358         print("Select another 'start_time_step' or 'end_time_step'")
[176]359         print(" ")
360         exit
361      end if
362   end if
363
364   do i=0,nt-1     
[566]365      if (end_time_step .GE. (t_all(i)-delta_t/2)/3600 .AND. \
366          end_time_step .LT. (t_all(i)+delta_t/2)/3600)then
[176]367         et=i
368         break
369      end if
370   end do
[190]371   
372   if (.not. isvar("et"))then
373      print(" ")
374      print("'end_time_step' = "+ end_time_step +"h is invalid")
375      print(" ")
[218]376      print("Select another 'end_time_step'")
[190]377      print(" ")
378      exit
379   end if
[176]380
381   delete(start_time_step)
382   start_time_step=round(st,3)
383   delete(end_time_step)
384   end_time_step=round(et,3)
385
386   print(" ")
[566]387   print("Output of time steps from "+t_all(start_time_step)/3600+" h = "+\
388         t_all(start_time_step)+" s => index = "+start_time_step)
389   print("                     till "+t_all(end_time_step)/3600+" h = "+\
390         t_all(end_time_step)+" s => index = "+end_time_step)
[176]391   print(" ")
392
393   dimt = end_time_step-start_time_step+1
394 
[190]395   ;***************************************************
[176]396   ; set up recourses
[190]397   ;***************************************************
[176]398     
399   res = True
400   res@gsnDraw                 = False
401   res@gsnFrame                = False
402   res@txFont                  = "helvetica"
403   res@tiMainFont              = "helvetica"
404   res@tiXAxisFont             = "helvetica"
405   res@tiYAxisFont             = "helvetica"
406   res@tmXBLabelFont           = "helvetica"
407   res@tmYLLabelFont           = "helvetica"
408   res@lgLabelFont             = "helvetica"
409   res@tmLabelAutoStride       = True
410   
[218]411   res@lgLabelFontHeightF     = font_size_legend
412   res@lgTitleFontHeightF     = font_size
413   res@txFontHeightF      = font_size
414   res@tiXAxisFontHeightF = font_size
415   res@tiYAxisFontHeightF = font_size
416   res@tmXBLabelFontHeightF = font_size
417   res@tmYLLabelFontHeightF = font_size
418   
419   res@tmXBMinorPerMajor = 4
420   res@tmYLMinorPerMajor = 4
421   
422   if (log_x .EQ. 1) then
[176]423      res@trXLog = True
[190]424   else
425      res@trXLog = False
426   end if
[218]427   if (log_y .EQ. 1)then
[176]428      res@trYLog = True
[190]429   else 
[178]430      res@trYLog = False
[176]431   end if
432
[566]433   legend_label=new(dimt,string)
[176]434   legend_label_zu=new(dimz,double)
435   legend_label_zw=new(dimz,double)
436   legend_label_z=new(dimz,double)
437   do p=start_time_step,end_time_step
[566]438      legend_label(p-start_time_step)=sprintf("%6.2f", t_all(p)/3600)
[176]439   end do 
440   if (sort .EQ. "time")
441      plot  = new(dim*dimz,graphic)
442      np=dimt
[534]443      res@lgTitleString = "Time (h)"
[176]444   else
445      plot  = new(dim*dimt,graphic)
446      np=dimz
[218]447     
[176]448      do p=0,dimz-1
[190]449         if (height_level(0) .EQ. -1)then
450            legend_label_zu(p)=round(zu(p),3)
451            legend_label_zw(p)=round(zw(p),3)
452         else
453            legend_label_zu(p)=round(zuh(p),3)
454            legend_label_zw(p)=round(zwh(p),3)
455         end if
[176]456      end do
457   end if
[194]458
459   if (black .eq. 0 ) then
460      if (np .EQ. 1)then
[218]461         color = 237
[194]462      else   
463         step=round(235/(np-1),3)
[218]464         color = ispan(2,237,step)
[194]465      end if
[324]466   else
467      color = 2
[176]468   end if
469   if ( dash .eq. 0 ) then
[190]470      res@xyMonoDashPattern = True
[176]471   end if
472
[532]473   if ( format_out .EQ. "pdf" .OR. format_out .EQ. "ps" ) then
474      format_out@wkPaperSize = "A4"
475   end if
476   if ( format_out .EQ. "png" ) then
477      format_out@wkWidth  = 1000
478      format_out@wkHeight = 1000
479   end if
480
[176]481   wks=gsn_open_wks(format_out,file_out)
482   gsn_define_colormap(wks,"rainbow+white")
483
484   n=0
485   do varn =dim-1,0,1
[178]486     
[176]487      check = True
488
[566]489      if ( isStrSubset( vNam(varn), "time") .OR.  \
490           isStrSubset( vNam(varn), "zu_sp") .OR. \
491           isStrSubset( vNam(varn), "zw_sp") .OR. \
492           isStrSubset( vNam(varn), "k_x") .OR.   \
493           isStrSubset( vNam(varn), "k_y")) then
[176]494            check = False
495      end if
496
[190]497      if (var .NE. "all") then
[176]498         check = isStrSubset( var,","+vNam(varn)+"," )
499      end if
500
[190]501      if(check) then
[218]502
503         temp = f[:]->$vNam(varn)$
[566]504         data = temp(start_time_step:end_time_step,0:dimz-1,:)
[218]505
506         temp_att = f_att->$vNam(varn)$
507         a=getvardims(temp_att)
[190]508         b=dimsizes(a)
[534]509         delete(temp_att)
[176]510
[190]511         if (height_level(0) .NE. -1)then
512            do te=0,dimz-1
[566]513               data(:,te,:) = temp(start_time_step:end_time_step,\
514                                                    height_level(te),:)       
[190]515            end do
516         end if
517
[566]518         data=data/(norm_y*norm_x)
[190]519           
[176]520         do i=0,b-1           
521            if (isStrSubset( a(i),"zu_sp" ))then
522               legend_label_z=legend_label_zu
[190]523               if (height_level(0) .NE. -1)then
524                  z=zuh
525               else
526                  z=zu
527               end if
[176]528            else
529               if (isStrSubset( a(i),"zw_sp" ))then
[190]530                  legend_label_z=legend_label_zw
531                  if (height_level(0) .NE. -1)then
532                     z=zwh
533                  else
534                     z=zw
535                  end if   
[176]536               end if
537            end if
538         end do 
[218]539         
[585]540         if (check_vType) then
541            min_y=new(dimz,double)
542            max_y=new(dimz,double)
543         else
544            min_y=new(dimz,float)
545            max_y=new(dimz,float)
546         end if
[218]547         min_x=new(dimz,double)
548         max_x=new(dimz,double)
[585]549         
[218]550         plot_h  = new(dimz,graphic)
551         
[176]552         if (isStrSubset(vNam(varn),"x"))then
[218]553            x_axis = new((/dimz,dimx/),double)
554            do q=0,dimz-1
555               x_axis(q,:) = f_att->k_x
556               x_axis = x_axis/norm_x
557            end do
558            if (norm_x .NE. 1.)then
[534]559               res@tiXAxisString = "k~B~x~N~ ("+unit_x+")"
[190]560            else
[218]561               if (norm_height .EQ. 1)then
[534]562                  res@tiXAxisString = "k~B~x~N~ x z (1"
[218]563               else
[534]564                  res@tiXAxisString = "k~B~x~N~ (1/m)"
[218]565               end if
[190]566            end if
[218]567            dim_r=dimx
[176]568         else
[218]569            x_axis=new((/dimz,dimy/),double)
570            do q=0,dimz-1
571               x_axis(q,:) = f_att->k_y
572               x_axis = x_axis/norm_x
573            end do
574            if (norm_x .NE. 1.)then
[534]575               res@tiXAxisString = "k~B~x~N~ ("+unit_x+")"
[190]576            else
[218]577               if (norm_height .EQ. 1)then
[534]578                  res@tiXAxisString = "k~B~x~N~ x z (1)"
[218]579               else
[534]580                  res@tiXAxisString = "k~B~x~N~ (1/m)"
[218]581               end if
[190]582            end if
[218]583            dim_r=dimy
[176]584         end if
585       
586         if (sort .EQ. "time")
[218]587            res@xyLineColors = color
588            res@pmLegendDisplayMode     = "Always"
589            res@pmLegendSide            = "Top"
590            res@pmLegendParallelPosF    = 1.2
591            res@pmLegendOrthogonalPosF  = -1.0
592            res@pmLegendWidthF          = 0.12
[566]593            res@pmLegendHeightF         = 0.04*\
594                                          (end_time_step-start_time_step+1)
[190]595            do p=dimz-1,0,1
[218]596               if (log_y .EQ. 1)then 
[190]597                  do q=0,dimt-1
[218]598                     do r=0,dim_r-1
599                        if (data(q,p,r) .EQ. 0)then
[190]600                           st=p+start_time_step
601                           print(" ")
[566]602                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' is "+\
603                                 "equal 0. Logarithmic scale for y-axis "+\
604                                 "and height "+z(p)+" cannot be used")
[190]605                           print(" ")
606                           res@trYLog = False
607                        end if
608                     end do
[176]609                  end do
[190]610               end if
[176]611               res@gsnLeftString      = vNam(varn)
[218]612               res@gsnRightString     = "Height = "+z(p)+"m"               
[534]613               res@tiYAxisString      = "("+unit_y+")"           
[218]614               res@xyExplicitLegendLabels  = legend_label             
615               if (norm_height .EQ. 1)then
616                  data(:,p,:)=data(:,p,:)*doubletofloat(z(p))
617                  x_axis(p,:) = x_axis(p,:)*z(p)
618               end if
619               res@trXMinF = min(x_axis(p,:))
620               res@trXMaxF = max(x_axis(p,:))
621               plot(n)  = gsn_csm_xy(wks,x_axis(p,:),data(:,p,:),res)
[176]622               n=n+1
623            end do
624         else
[190]625            if (sort .EQ. "height")
626               do p=0,dimt-1           
[176]627                  do q=0,dimz-1
[218]628                     do r=0,dim_r-1
629                        if (data(p,q,r) .EQ. 0)then
[176]630                           st=p+start_time_step
631                           print(" ")
[566]632                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' "+\
633                                 "is equal 0. Logarithmic scale for y-axis "+\
634                                 "and time "+legend_label(p)+" h cannot be used")
[176]635                           print(" ")
636                           res@trYLog = False
637                        end if
638                     end do
[218]639                     if (norm_height .EQ. 1 .AND. p .EQ. 0)then
[566]640                        data(p,q,:) = data(p,q,:)*\
641                                           doubletofloat(legend_label_z(q))
642                        x_axis(q,:) = x_axis(q,:)*\
643                                           doubletofloat(legend_label_z(q))
[218]644                     end if
645                     max_y(q)=max(data(p,q,:))
646                     min_y(q)=min(data(p,q,:))
647                     min_x(q)=min(x_axis(q,:))
[566]648                     max_x(q)=max(x_axis(q,:))
[218]649                  end do
650                  do q=0,dimz-1
651                     res@xyLineColor = color(q)
652                     if (dash .EQ. 1)then
653                        res@xyDashPattern = q
654                     end if
655                     if (q .EQ. 0)then
[566]656                        res@tiYAxisString      = "("+unit_y+")"
[218]657                        res@gsnLeftString      = vNam(varn)
658                        res@gsnRightString     = "Time = "+legend_label(p)+"h"
659                        res@trXMinF = min(min_x)
660                        res@trXMaxF = max(max_x)
661                        res@trYMinF = min(min_y)
662                        res@trYMaxF = max(max_y)
663                       
[566]664                        plot_h(q)  = gsn_csm_xy(wks,x_axis(q,:),\
665                                                         data(p,q,:),res)
[218]666                       
667                        lgres = True
668                        if (dash .EQ. 0)then
669                           lgres@lgMonoDashIndex = True
670                        else
671                           lgres@lgDashIndexes   = ispan(0,dimz-1,1)
672                        end if
673                        if (black .EQ. 1)then
674                           lgres@lgMonoLineColors = True
675                        else
676                           lgres@lgLineColors = color
677                        end if
[566]678                        lgres@lgTitleString      = "Height (m)" 
[218]679                        lgres@lgLabelFont        = "helvetica"
[566]680                        lgres@lgLabelFontHeightF = font_size_legend*6
681                        lgres@lgTitleFontHeightF = font_size     
[218]682                        lgres@vpWidthF           = 0.12           
[566]683                        lgres@vpHeightF          = font_size_legend*(dimz+3)
[218]684 
[566]685                        lbid = gsn_create_legend(wks,dimz,legend_label_z,lgres)
[218]686
687                        amres = True
688                        amres@amParallelPosF   = 0.75               
689                        amres@amOrthogonalPosF = 0.15           
690                        annoid1 = gsn_add_annotation(plot_h(q),lbid,amres)
691                     else
[566]692                        plot_h(q)  = gsn_csm_xy(wks,x_axis(q,:),\
693                                                        data(p,q,:),res)
[218]694                        overlay(plot_h(0),plot_h(q))
695                     end if
696                  end do             
697                  plot(n)=plot_h(0)
698                  n=n+1
[176]699               end do
700            end if
[190]701         end if
[218]702         delete(data)
703         delete(temp)
[178]704         delete(x_axis)
[218]705         delete(min_x)
706         delete(max_x)
707         delete(min_y)
708         delete(max_y)
709         delete(plot_h)
[176]710      end if
711   end do
712
713   if (n .EQ. 0) then
714      print(" ")
[190]715      print("The variables 'var="+var+"' do not exist on your input file;")
716      print("be sure to have one comma berfore and after each variable")
[176]717      print(" ")
718      exit
719   end if
720 
721   ; ***************************************************
722   ; merge plots onto one page
723   ; ***************************************************
724
725   resP                        = True
726   resP@txFont                 = "helvetica"
[218]727   resP@txString               = f_att@title
[176]728   resP@txFuncCode             = "~"
[218]729   resP@txFontHeightF          = 0.015
[176]730
[534]731   no_frames = 0
732
[566]733   if ((format_out .EQ. "eps" .OR. format_out .EQ. "epsi") .AND. \
734                                          n .gt. no_rows*no_columns) then
[183]735      gsn_panel(wks,plot,(/n,1/),resP)
[250]736      print(" ")
737      print("Outputs to .eps or .epsi have only one frame")
738      print(" ")
[176]739   else   
[218]740      do i = 0,n-1, no_rows*no_columns
741         if( (i+no_rows*no_columns) .gt. (n-1)) then
742            gsn_panel(wks,plot(i:n-1),(/no_rows,no_columns/),resP)
[534]743            no_frames = no_frames + 1
[176]744         else
[566]745            gsn_panel(wks,plot(i:i+no_rows*no_columns-1),\
746                                           (/no_rows,no_columns/),resP)
[534]747            no_frames = no_frames + 1   
[176]748         end if
749      end do
750   end if
751
[532]752   if (format_out .EQ. "png" ) then
753     png_output = new((/no_frames/), string)
754     j = 0
755     do i=0, no_frames-1
756       j = i + 1
757       if (j .LE. 9) then
758         png_output(i) = file_out+".00000"+j+".png"
759       end if
760       if (j .GT. 9 .AND. j .LE. 99) then
761         png_output(i) = file_out+".0000"+j+".png"
762       end if
763       if (j .GT. 99 .AND. j .LE. 999) then
764         png_output(i) = file_out+".000"+j+".png"
765       end if
766       if (j .GT. 999) then
767         png_output(i) = file_out+".00"+j+".png"
768       end if
769
770       ;using imagemagick's convert for reducing the white
771       ;space around the plot
772       cmd = "convert -geometry 1000x1000 -density 300 -trim " +  \
773              png_output(i) + " " + png_output(i)
774       system(cmd)
775     end do
776
777     print(" ")
778     print("Output to: "+ png_output)
779     print(" ")
780   else
781     print(" ")
782     print("Output to: " + file_out +"."+ format_out)
783     print(" ")
784   end if
[176]785   
[190]786end
Note: See TracBrowser for help on using the repository browser.