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

Last change on this file since 769 was 769, checked in by heinze, 13 years ago

Bugfixes in case of plot of t=0h and plot of topography zusi/zwwi possible

File size: 23.1 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
[769]325      else
326         st=0
[176]327      end if
328   end do
329   
[190]330   ;****************************************************
[176]331   ; end of time step and different types of mistakes that could be done
[190]332   ;****************************************************
[176]333
[190]334   if (end_time_step .EQ. -1.d) then           
[176]335      end_time_step = t_all(nt-1)/3600
336   else
337      if (end_time_step .GT. t_all(nt-1)/3600)then
338         print(" ")
[566]339         print("'end_time_step' = "+ end_time_step +"h is greater than "+\
340               "last time step = " + t_all(nt-1)+"s = "+t_all(nt-1)/3600+"h")
[176]341         print(" ")
[218]342         print("Select another 'end_time_step'") 
[176]343         print(" ")
344         exit
345      end if
346      if (end_time_step .LT. start_time_step/3600)then
347         print(" ")
[566]348         print("'end_time_step' = "+ end_time_step +"h is lower than "+\
349               "'start_time_step' = "+start_time_step+"h")
[176]350         print(" ")
[218]351         print("Select another 'start_time_step' or 'end_time_step'")
[176]352         print(" ")
353         exit
354      end if
355   end if
356
357   do i=0,nt-1     
[566]358      if (end_time_step .GE. (t_all(i)-delta_t/2)/3600 .AND. \
359          end_time_step .LT. (t_all(i)+delta_t/2)/3600)then
[176]360         et=i
361         break
[769]362       else
363         et=0
[176]364      end if
365   end do
366
367   delete(start_time_step)
368   start_time_step=round(st,3)
369   delete(end_time_step)
370   end_time_step=round(et,3)
371
372   print(" ")
[566]373   print("Output of time steps from "+t_all(start_time_step)/3600+" h = "+\
374         t_all(start_time_step)+" s => index = "+start_time_step)
375   print("                     till "+t_all(end_time_step)/3600+" h = "+\
376         t_all(end_time_step)+" s => index = "+end_time_step)
[176]377   print(" ")
378
379   dimt = end_time_step-start_time_step+1
380 
[190]381   ;***************************************************
[176]382   ; set up recourses
[190]383   ;***************************************************
[176]384     
385   res = True
386   res@gsnDraw                 = False
387   res@gsnFrame                = False
388   res@txFont                  = "helvetica"
389   res@tiMainFont              = "helvetica"
390   res@tiXAxisFont             = "helvetica"
391   res@tiYAxisFont             = "helvetica"
392   res@tmXBLabelFont           = "helvetica"
393   res@tmYLLabelFont           = "helvetica"
394   res@lgLabelFont             = "helvetica"
395   res@tmLabelAutoStride       = True
396   
[218]397   res@lgLabelFontHeightF     = font_size_legend
398   res@lgTitleFontHeightF     = font_size
399   res@txFontHeightF      = font_size
400   res@tiXAxisFontHeightF = font_size
401   res@tiYAxisFontHeightF = font_size
402   res@tmXBLabelFontHeightF = font_size
403   res@tmYLLabelFontHeightF = font_size
404   
405   res@tmXBMinorPerMajor = 4
406   res@tmYLMinorPerMajor = 4
407   
408   if (log_x .EQ. 1) then
[176]409      res@trXLog = True
[190]410   else
411      res@trXLog = False
412   end if
[218]413   if (log_y .EQ. 1)then
[176]414      res@trYLog = True
[190]415   else 
[178]416      res@trYLog = False
[176]417   end if
418
[566]419   legend_label=new(dimt,string)
[176]420   legend_label_zu=new(dimz,double)
421   legend_label_zw=new(dimz,double)
422   legend_label_z=new(dimz,double)
423   do p=start_time_step,end_time_step
[566]424      legend_label(p-start_time_step)=sprintf("%6.2f", t_all(p)/3600)
[176]425   end do 
426   if (sort .EQ. "time")
427      plot  = new(dim*dimz,graphic)
428      np=dimt
[534]429      res@lgTitleString = "Time (h)"
[176]430   else
431      plot  = new(dim*dimt,graphic)
432      np=dimz
[218]433     
[176]434      do p=0,dimz-1
[190]435         if (height_level(0) .EQ. -1)then
436            legend_label_zu(p)=round(zu(p),3)
437            legend_label_zw(p)=round(zw(p),3)
438         else
439            legend_label_zu(p)=round(zuh(p),3)
440            legend_label_zw(p)=round(zwh(p),3)
441         end if
[176]442      end do
443   end if
[194]444
445   if (black .eq. 0 ) then
446      if (np .EQ. 1)then
[218]447         color = 237
[194]448      else   
449         step=round(235/(np-1),3)
[218]450         color = ispan(2,237,step)
[194]451      end if
[324]452   else
453      color = 2
[176]454   end if
455   if ( dash .eq. 0 ) then
[190]456      res@xyMonoDashPattern = True
[176]457   end if
458
[532]459   if ( format_out .EQ. "pdf" .OR. format_out .EQ. "ps" ) then
460      format_out@wkPaperSize = "A4"
461   end if
462   if ( format_out .EQ. "png" ) then
463      format_out@wkWidth  = 1000
464      format_out@wkHeight = 1000
465   end if
466
[176]467   wks=gsn_open_wks(format_out,file_out)
468   gsn_define_colormap(wks,"rainbow+white")
469
470   n=0
471   do varn =dim-1,0,1
[178]472     
[176]473      check = True
474
[566]475      if ( isStrSubset( vNam(varn), "time") .OR.  \
476           isStrSubset( vNam(varn), "zu_sp") .OR. \
477           isStrSubset( vNam(varn), "zw_sp") .OR. \
478           isStrSubset( vNam(varn), "k_x") .OR.   \
479           isStrSubset( vNam(varn), "k_y")) then
[176]480            check = False
481      end if
482
[190]483      if (var .NE. "all") then
[176]484         check = isStrSubset( var,","+vNam(varn)+"," )
485      end if
486
[190]487      if(check) then
[218]488
489         temp = f[:]->$vNam(varn)$
[566]490         data = temp(start_time_step:end_time_step,0:dimz-1,:)
[218]491
492         temp_att = f_att->$vNam(varn)$
493         a=getvardims(temp_att)
[190]494         b=dimsizes(a)
[534]495         delete(temp_att)
[176]496
[190]497         if (height_level(0) .NE. -1)then
498            do te=0,dimz-1
[566]499               data(:,te,:) = temp(start_time_step:end_time_step,\
500                                                    height_level(te),:)       
[190]501            end do
502         end if
503
[566]504         data=data/(norm_y*norm_x)
[190]505           
[176]506         do i=0,b-1           
507            if (isStrSubset( a(i),"zu_sp" ))then
508               legend_label_z=legend_label_zu
[190]509               if (height_level(0) .NE. -1)then
510                  z=zuh
511               else
512                  z=zu
513               end if
[176]514            else
515               if (isStrSubset( a(i),"zw_sp" ))then
[190]516                  legend_label_z=legend_label_zw
517                  if (height_level(0) .NE. -1)then
518                     z=zwh
519                  else
520                     z=zw
521                  end if   
[176]522               end if
523            end if
524         end do 
[218]525         
[585]526         if (check_vType) then
527            min_y=new(dimz,double)
528            max_y=new(dimz,double)
529         else
530            min_y=new(dimz,float)
531            max_y=new(dimz,float)
532         end if
[218]533         min_x=new(dimz,double)
534         max_x=new(dimz,double)
[585]535         
[218]536         plot_h  = new(dimz,graphic)
537         
[176]538         if (isStrSubset(vNam(varn),"x"))then
[218]539            x_axis = new((/dimz,dimx/),double)
540            do q=0,dimz-1
541               x_axis(q,:) = f_att->k_x
542               x_axis = x_axis/norm_x
543            end do
544            if (norm_x .NE. 1.)then
[534]545               res@tiXAxisString = "k~B~x~N~ ("+unit_x+")"
[190]546            else
[218]547               if (norm_height .EQ. 1)then
[534]548                  res@tiXAxisString = "k~B~x~N~ x z (1"
[218]549               else
[534]550                  res@tiXAxisString = "k~B~x~N~ (1/m)"
[218]551               end if
[190]552            end if
[218]553            dim_r=dimx
[176]554         else
[218]555            x_axis=new((/dimz,dimy/),double)
556            do q=0,dimz-1
557               x_axis(q,:) = f_att->k_y
558               x_axis = x_axis/norm_x
559            end do
560            if (norm_x .NE. 1.)then
[534]561               res@tiXAxisString = "k~B~x~N~ ("+unit_x+")"
[190]562            else
[218]563               if (norm_height .EQ. 1)then
[534]564                  res@tiXAxisString = "k~B~x~N~ x z (1)"
[218]565               else
[534]566                  res@tiXAxisString = "k~B~x~N~ (1/m)"
[218]567               end if
[190]568            end if
[218]569            dim_r=dimy
[176]570         end if
571       
572         if (sort .EQ. "time")
[218]573            res@xyLineColors = color
574            res@pmLegendDisplayMode     = "Always"
575            res@pmLegendSide            = "Top"
576            res@pmLegendParallelPosF    = 1.2
577            res@pmLegendOrthogonalPosF  = -1.0
578            res@pmLegendWidthF          = 0.12
[566]579            res@pmLegendHeightF         = 0.04*\
580                                          (end_time_step-start_time_step+1)
[190]581            do p=dimz-1,0,1
[218]582               if (log_y .EQ. 1)then 
[190]583                  do q=0,dimt-1
[218]584                     do r=0,dim_r-1
585                        if (data(q,p,r) .EQ. 0)then
[190]586                           st=p+start_time_step
587                           print(" ")
[566]588                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' is "+\
589                                 "equal 0. Logarithmic scale for y-axis "+\
590                                 "and height "+z(p)+" cannot be used")
[190]591                           print(" ")
592                           res@trYLog = False
593                        end if
594                     end do
[176]595                  end do
[190]596               end if
[176]597               res@gsnLeftString      = vNam(varn)
[218]598               res@gsnRightString     = "Height = "+z(p)+"m"               
[534]599               res@tiYAxisString      = "("+unit_y+")"           
[218]600               res@xyExplicitLegendLabels  = legend_label             
601               if (norm_height .EQ. 1)then
602                  data(:,p,:)=data(:,p,:)*doubletofloat(z(p))
603                  x_axis(p,:) = x_axis(p,:)*z(p)
604               end if
605               res@trXMinF = min(x_axis(p,:))
606               res@trXMaxF = max(x_axis(p,:))
607               plot(n)  = gsn_csm_xy(wks,x_axis(p,:),data(:,p,:),res)
[176]608               n=n+1
609            end do
610         else
[190]611            if (sort .EQ. "height")
612               do p=0,dimt-1           
[176]613                  do q=0,dimz-1
[218]614                     do r=0,dim_r-1
615                        if (data(p,q,r) .EQ. 0)then
[176]616                           st=p+start_time_step
617                           print(" ")
[566]618                           print("'"+vNam(varn)+"("+st+","+q+","+r+")' "+\
619                                 "is equal 0. Logarithmic scale for y-axis "+\
620                                 "and time "+legend_label(p)+" h cannot be used")
[176]621                           print(" ")
622                           res@trYLog = False
623                        end if
624                     end do
[218]625                     if (norm_height .EQ. 1 .AND. p .EQ. 0)then
[566]626                        data(p,q,:) = data(p,q,:)*\
627                                           doubletofloat(legend_label_z(q))
628                        x_axis(q,:) = x_axis(q,:)*\
629                                           doubletofloat(legend_label_z(q))
[218]630                     end if
631                     max_y(q)=max(data(p,q,:))
632                     min_y(q)=min(data(p,q,:))
633                     min_x(q)=min(x_axis(q,:))
[566]634                     max_x(q)=max(x_axis(q,:))
[218]635                  end do
636                  do q=0,dimz-1
637                     res@xyLineColor = color(q)
638                     if (dash .EQ. 1)then
639                        res@xyDashPattern = q
640                     end if
641                     if (q .EQ. 0)then
[566]642                        res@tiYAxisString      = "("+unit_y+")"
[218]643                        res@gsnLeftString      = vNam(varn)
644                        res@gsnRightString     = "Time = "+legend_label(p)+"h"
645                        res@trXMinF = min(min_x)
646                        res@trXMaxF = max(max_x)
647                        res@trYMinF = min(min_y)
648                        res@trYMaxF = max(max_y)
649                       
[566]650                        plot_h(q)  = gsn_csm_xy(wks,x_axis(q,:),\
651                                                         data(p,q,:),res)
[218]652                       
653                        lgres = True
654                        if (dash .EQ. 0)then
655                           lgres@lgMonoDashIndex = True
656                        else
657                           lgres@lgDashIndexes   = ispan(0,dimz-1,1)
658                        end if
659                        if (black .EQ. 1)then
660                           lgres@lgMonoLineColors = True
661                        else
662                           lgres@lgLineColors = color
663                        end if
[566]664                        lgres@lgTitleString      = "Height (m)" 
[218]665                        lgres@lgLabelFont        = "helvetica"
[566]666                        lgres@lgLabelFontHeightF = font_size_legend*6
667                        lgres@lgTitleFontHeightF = font_size     
[218]668                        lgres@vpWidthF           = 0.12           
[566]669                        lgres@vpHeightF          = font_size_legend*(dimz+3)
[218]670 
[566]671                        lbid = gsn_create_legend(wks,dimz,legend_label_z,lgres)
[218]672
673                        amres = True
674                        amres@amParallelPosF   = 0.75               
675                        amres@amOrthogonalPosF = 0.15           
676                        annoid1 = gsn_add_annotation(plot_h(q),lbid,amres)
677                     else
[566]678                        plot_h(q)  = gsn_csm_xy(wks,x_axis(q,:),\
679                                                        data(p,q,:),res)
[218]680                        overlay(plot_h(0),plot_h(q))
681                     end if
682                  end do             
683                  plot(n)=plot_h(0)
684                  n=n+1
[176]685               end do
686            end if
[190]687         end if
[218]688         delete(data)
689         delete(temp)
[178]690         delete(x_axis)
[218]691         delete(min_x)
692         delete(max_x)
693         delete(min_y)
694         delete(max_y)
695         delete(plot_h)
[176]696      end if
697   end do
698
699   if (n .EQ. 0) then
700      print(" ")
[190]701      print("The variables 'var="+var+"' do not exist on your input file;")
702      print("be sure to have one comma berfore and after each variable")
[176]703      print(" ")
704      exit
705   end if
706 
707   ; ***************************************************
708   ; merge plots onto one page
709   ; ***************************************************
710
711   resP                        = True
712   resP@txFont                 = "helvetica"
[218]713   resP@txString               = f_att@title
[176]714   resP@txFuncCode             = "~"
[218]715   resP@txFontHeightF          = 0.015
[176]716
[534]717   no_frames = 0
718
[566]719   if ((format_out .EQ. "eps" .OR. format_out .EQ. "epsi") .AND. \
720                                          n .gt. no_rows*no_columns) then
[183]721      gsn_panel(wks,plot,(/n,1/),resP)
[250]722      print(" ")
723      print("Outputs to .eps or .epsi have only one frame")
724      print(" ")
[176]725   else   
[218]726      do i = 0,n-1, no_rows*no_columns
727         if( (i+no_rows*no_columns) .gt. (n-1)) then
728            gsn_panel(wks,plot(i:n-1),(/no_rows,no_columns/),resP)
[534]729            no_frames = no_frames + 1
[176]730         else
[566]731            gsn_panel(wks,plot(i:i+no_rows*no_columns-1),\
732                                           (/no_rows,no_columns/),resP)
[534]733            no_frames = no_frames + 1   
[176]734         end if
735      end do
736   end if
737
[532]738   if (format_out .EQ. "png" ) then
739     png_output = new((/no_frames/), string)
740     j = 0
741     do i=0, no_frames-1
742       j = i + 1
743       if (j .LE. 9) then
744         png_output(i) = file_out+".00000"+j+".png"
745       end if
746       if (j .GT. 9 .AND. j .LE. 99) then
747         png_output(i) = file_out+".0000"+j+".png"
748       end if
749       if (j .GT. 99 .AND. j .LE. 999) then
750         png_output(i) = file_out+".000"+j+".png"
751       end if
752       if (j .GT. 999) then
753         png_output(i) = file_out+".00"+j+".png"
754       end if
755
756       ;using imagemagick's convert for reducing the white
757       ;space around the plot
758       cmd = "convert -geometry 1000x1000 -density 300 -trim " +  \
759              png_output(i) + " " + png_output(i)
760       system(cmd)
761     end do
762
763     print(" ")
764     print("Output to: "+ png_output)
765     print(" ")
766   else
767     print(" ")
768     print("Output to: " + file_out +"."+ format_out)
769     print(" ")
770   end if
[176]771   
[190]772end
Note: See TracBrowser for help on using the repository browser.