    pro plot_fields,rsite,month,day,year,scan
    COMMON misc,TRUE,FALSE
    COMMON graphics,USE_Z_BUFFER,TC,XS,YS,cols,rows
    !QUIET=1
    TRUE=1 & FALSE=0
    USE_Z_BUFFER=true
;
; *** Routine to plot individual images for specified fields
; *** and sweeps.
;
      cols=1 & rows=1
      xs=599 & ys=599
      if(USE_Z_BUFFER eq TRUE) then begin
        set_plot,'Z',/COPY
        device,set_resolution=[xs*cols,ys*rows],Z_Buffer=0
	Erase
        !P.charsize = 0.75
    endif else begin
;        set_device,TC
;        !P.charsize = 1.0
         set_plot, 'ps'
         device,/encapsul,/color,xsize=8*cols,ysize=8*rows,/inches
         device,filename=img_file
         !P.background = 255
         !P.Multi = [0,cols,rows]
         !P.font = 1
         !p.thick=3
         !x.thick=2
         !y.thick=2
         device, helvetica=1
;         ps_file = 'GV_Map.ps'
;         print,'Postscript file: ',ps_file
    endelse
    !P.background = 255
    !P.Multi = [0,cols,rows]
;     FIELDS=['CZ','DR','KD','PH','RH','VR','RR','RP','RC','NW','N2','DM','D0','FH']
      FIELDS=['FH','CZ','KD','RH','PH','DR']
;      in_dir = '/gvraid/field_campaigns/IFLOODS/UF_QC/DROPS2/' + month + day + '/' + scan + '/'
;      in_dir = '/gvs1/trmmgv/MELB/uf/08-2015/150815/DROPS/'
;       in_dir = '/gvs2/gpmgv_data/gpmgv/NPOL/1CUF/2015/0621/100km/DROPS/'
;        in_dir = '/gvs2/gpmgv_data/gpmgv/NPOL/1CUF/2015/1112/DROPS/'
;        in_dir = '/gvs2/gpmgv_data/gpmgv/INTA_Anguil/1CUF/2011/0113/DROPS/'
;       in_dir = '/gvs2/gpmgv_data/gpmgv/' + rsite + '/1CUF/' + year + '/'  + month + day + '/DROPS/'
;      in_dir = '/gvraid/field_campaigns/OLYMPEX/Radar/NPOL/UF/DROPS2/' + month + day + '/rhi_a/'
       in_dir = '/gpmraid/raw/NPOL/temp/Ali/snow_cases/' + rsite + '/HID/' + year + '/'  + month + day + '/'
;       in_dir = '/gvraid/field_campaigns/OLYMPEX/Radar/NPOL/UF/DROPS2/' + month + day + '/rhi_a/old/'
;       in_dir = '/gvs2/gpmgv_data/gpmgv/KDOX/1CUF/2015/0215/DROPS/'
;       in_dir = '/gvs2/gpmgv_data/gpmgv/NPOL/1CUF/2015/0721/DROPS/'
      wc = in_dir + '*.gz'
      files = file_search(wc,COUNT=nf)
      if(nf eq 0) then begin
       print,'No files found!'
       stop
      endif

      for i=0,nf-1 do begin
         file = files(i)
         fileb = file_basename(file)
         max_sweeps = 40
         radar = rsl_anyformat_to_radar(file,MAXSWEEPS=max_sweeps,ERROR=error)

; *** Get date info from radar structure
;
      date_str = get_date_string_from_radar(radar)
;
; *** Determine the scan mode
;
      scan_mode = radar.h.scan_mode
      print,scan_mode
;
; *** Plot fields
;
;      img_dir = '/gvs2/gpmgv_data/gpmgv/DROPS2_to_DPRain/images/'
;      img_dir = '/gvs2/gpmgv_data/gpmgv/' + rsite + '/1CUF/' + year + '/'  + month + day + '/DROPS/images/'
;      img_dir = '/gvraid/field_campaigns/OLYMPEX/Radar/NPOL/UF/DROPS2/' + month + day + '/rhi_a/images/'
      img_dir = '/gpmraid/raw/NPOL/temp/Ali/snow_cases/' + rsite + '/images/' + year + '/'  + month + day + '/'
;      img_dir = '/gvraid/field_campaigns/OLYMPEX/Radar/NPOL/UF/DROPS2/' + month + day + '/rhi_a/images/old/'
      spawn, 'mkdir -p ' + img_dir
      print,'IMG: ' + img_dir
      nfld = n_elements(fields)

      for ifld=0,nfld-1 do begin
         field = fields[ifld]
         print,'Plotting: ' + field
;
; *** Create directory to hold images (one dir per field)
;
;        if (gpmgv or gpmvn) then begin
;     plot_dir = img_dir + '/'
; endif else begin
;             plot_dir = img_dir + field + '/'
              plot_dir = img_dir
;	 endelse
         spawn,'mkdir -p ' + plot_dir
;
; *** Extract field type info from 
; 
         index = where(radar.volume.h.field_type eq field, c_index)
         if(c_index eq 0) then begin
            print,field + ' field not available for plotting!'
            goto,next_field
         endif
         index = index[0]
         vol = radar.volume[index]
         nsweeps = vol.h.nsweeps
         if(max_sweeps gt nsweeps) then max_sweeps=nsweeps
	 if(scan_mode eq 'RHI') then max_sweeps=nsweeps
         if(scan eq 'pps') then max_sweeps=4
         if(scan_mode eq 'RHI') then begin
	         mrange=100
        	 mheight=12
         endif else begin
	         mrange=150
                 mheight=10
         endelse
         site = radar.h.radar_name
         for iswp=0,max_sweeps-1 do begin
            sweep = vol.sweep[iswp]
	    azimuth = strtrim(string(sweep.ray.h.azimuth,format='(f5.1)'),1)
            
            if(scan_mode eq 'RHI') then begin
               if (field eq 'SQ') then begin
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RH'
                 rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RH'
                 img_file = plot_dir + date_str + '_' + field + '_' +  azimuth(0) + 'AZ_RHI.png'
;                  img_file = plot_dir + date_str + '_' + field + '_' +  azimuth(0) + 'AZ_RHI.ps'
                  goto,next_f
               endif
               if (field eq 'FH') then begin
;                  rsl_plotsweep_from_radar,radar,zoom=[40,0,80,20],postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='FHSUM'
                   rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='FHSUM'
                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
                  goto,next_f
               endif
               if (field eq 'DM') then begin
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='D0'
                   rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='D0'
                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
                  goto,next_f
               endif
               if (field eq 'N2') then begin
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='NW'
                  rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='NW'
                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
                  goto,next_f
               endif
               if (field eq 'RP') then begin
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RR'
                  rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RR'
                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
                  goto,next_f
               endif
               if (field eq 'RC') then begin
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RR'
                  rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='RR'
                  img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                   img_file = plot_dir  + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps' 
                  goto,next_f
               endif
               if (field eq 'ZZ' or field eq 'SD') then begin
;                   rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='ZT'
                   rsl_plotsweep_from_radar,radar,maxheight=mheight,maxrange=mrange,sweep_index=iswp,field=field,like_field='ZT'
                   img_file = plot_dir + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                    img_file = plot_dir + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
                   goto,next_f
               endif
;                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],sweep_index=iswp,maxheight=mheight,maxrange=mrange,field=field
                  rsl_plotsweep_from_radar,radar,sweep_index=iswp,maxheight=mheight,maxrange=mrange,field=field
                  img_file = plot_dir + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.png'
;                   img_file = plot_dir + date_str + '_' + field + '_' + azimuth(0) + 'AZ_RHI.ps'
               endif else begin
               if (field eq 'SQ') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='RH',/postscript
                  img_file = plot_dir + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'FH') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='FHSUM',/postscript
                  img_file = plot_dir  + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'DM') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='D0',/postscript
                  img_file = plot_dir  + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'N2') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='NW',/postscript
                  img_file = plot_dir  + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'RP') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='RR',/postscript
                  img_file = plot_dir  + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'RC') then begin
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='RR',/postscript
                  img_file = plot_dir  + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                  goto,next_f
               endif
               if (field eq 'ZZ' or field eq 'SD') then begin
	           rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],maxrange=mrange,sweep_index=iswp,field=field,like_field='ZT',/postscript
                   img_file = plot_dir + date_str + '_' + field + '_sw' + string(iswp,format='(i2.2)') + '_PPI.png'
                   goto,next_f
               endif
                  rsl_plotsweep_from_radar,radar,postion=[0,0,xs,ys],sweep_index=iswp,maxrange=mrange,field=field,/postscript
                  img_file = plot_dir + date_str + '_' + field + '_sw' + $
                  string(iswp,format='(i2.2)') + '_PPI.png'
	 endelse
next_f:
            print,'  --> ' + img_file
            pngit,img_file
;
; *** Convert .ps file to .png
;
;    print,'    --> ' + img_file
;    device,/close
;    fileb = file_basename(img_file,'.ps')
;    new_png = fileb + '.png'
;    c = 'convert -density 150 ' + img_file + ' ' + new_png
;    spawn,c
;    print,'    --> ' + new_png
         endfor

next_field:
      endfor 
endfor
      return
      end
