FUNCTION plot_wind_map, astruct, vname, $
THUMBSIZE=THUMBSIZE, FRAME=FRAME, $
XSIZE=XSIZE, YSIZE=YSIZE,$
GIF=GIF, ps=ps, REPORT=REPORT,$
TSTART=TSTART,TSTOP=TSTOP,MYSCALE=MYSCALE,$
XY_STEP=XY_STEP, $
CDAWEB=CDAWEB,DEBUG=DEBUG
w = where(tag_names(astruct) eq strupcase(vname))
if (w[0] eq -1) then begin
print,'ERROR=No variable with the name:',vname,' in param 1!' & return,-1
endif else vnum = w[0]
if keyword_set(REPORT) then reportflag=1 else reportflag=0
a = size(astruct.(vnum))
if (a[n_elements(a)-2] ne 8) then begin
print,'ERROR= 1st parameter to plot_wind_map not a structure' & return,-1
endif else begin
a = tagindex('DAT',tag_names(astruct.(vnum)))
if (a[0] ne -1) then idat = astruct.(vnum).DAT $
else begin
a = tagindex('HANDLE',tag_names(astruct.(vnum)))
if (a[0] ne -1) then handle_value,astruct.(vnum).HANDLE,idat $
else begin
print,'ERROR= 1st parameter does not have DAT or HANDLE tag' & return,-1
endelse
endelse
endelse
a = tagindex('DISPLAY_TYPE',tag_names(astruct.(vnum)))
if(a[0] ne -1) then display= astruct.(vnum).DISPLAY_TYPE $
else begin
print, 'ERROR= No DISPLAY_TYPE attribute for variable'
endelse
ipts=parse_display_type(display)
keywords=str_sep(display,'>')
wc=where(keywords eq 'THUMBSIZE')
if(wc[0] ne -1) then THUMBSIZE = fix(keywords(wc[0]+1))
wc=where(keywords eq 'MAP_PROJ')
if(wc[0] ne -1) then map_proj = fix(keywords(wc[0]+1)) else $
map_proj = 8
proj_names =["", "stereographic projection","orthographic projection","lambertconic projection",$
"lambertazimuthal projection", "gnomic projection", "azimuthal equidistant projection",$
"satellite projection", "cylindrical equidistant projection", "mercator projection", $
"molleweide projection", "sinusoidal projection", "aitoff projection", "hammeraitoff projection", $
"albers equal area conic projection", "transverse mercator projection", $
"miller cylindrical projection", "robinson projection", "lambertconic ellipsoid projection", $
"goodes homolosine projection"]
if keyword_set(XSIZE) then xs=XSIZE else begin
xs=512
if (map_proj eq 8) then xs=512
if (map_proj eq 14) then xs=512
endelse
if keyword_set(YSIZE) then ys=YSIZE else begin
ys=512
if (map_proj eq 8) then ys=350
if (map_proj eq 14) then ys=512
endelse
tip = tagindex('PROJECT',tag_names(astruct.(vnum)))
if (tip ne -1) then project=astruct.(vnum).project else project = ' '
if (project eq 'TIMED') then white_background = 1
if keyword_set(WHITE_BACKGROUND) then begin
foreground = 2
white_background = 1
endif else begin
foreground = !d.table_size-1
white_background = 0
endelse
a = tagindex(strtrim(ipts[0],2),tag_names(astruct))
if(a[0] ne -1) then begin
a1=tagindex('DAT',tag_names(astruct.(a[0])))
if(a1[0] ne -1) then glat = astruct.(a[0]).DAT $
else begin
a2 = tagindex('HANDLE',tag_names(astruct.(a[0])))
if (a2[0] ne -1) then handle_value,astruct.(a[0]).HANDLE,glat $
else begin
print,'ERROR= 2nd parameter does not have DAT or HANDLE tag'
return,-1
endelse
endelse
endif else begin
print, 'ERROR= GLAT variable missing from structure in map image'
return, -1
endelse
a = tagindex(strtrim(ipts[1],2),tag_names(astruct))
if(a[0] ne -1) then begin
a1=tagindex('DAT',tag_names(astruct.(a[0])))
if(a1[0] ne -1) then glon = astruct.(a[0]).DAT $
else begin
a2 = tagindex('HANDLE',tag_names(astruct.(a[0])))
if (a2[0] ne -1) then handle_value,astruct.(a[0]).HANDLE,glon $
else begin
print,'ERROR= 3rd parameter does not have DAT or HANDLE tag'
return,-1
endelse
endelse
endif else begin
print, 'ERROR= GLON variable missing from structure in map image'
return, -1
endelse
b = astruct.(vnum).DEPEND_0
c = tagindex(b[0],tag_names(astruct))
d = tagindex('DAT',tag_names(astruct.(c)))
if (d[0] ne -1) then edat = astruct.(c).DAT $
else begin
d = tagindex('HANDLE',tag_names(astruct.(c)))
if (d[0] ne -1) then handle_value,astruct.(c).HANDLE,edat $
else begin
print,'ERROR= Time parameter does not have DAT or HANDLE tag' & return,-1
endelse
endelse
a = tagindex('SOURCE_NAME',tag_names(astruct.(vnum)))
if (a[0] ne -1) then b = astruct.(vnum).SOURCE_NAME+', ' else b = ''
a = tagindex('DESCRIPTOR',tag_names(astruct.(vnum)))
if (a[0] ne -1) then b = b + astruct.(vnum).DESCRIPTOR+', '
a = tagindex('DATA_TYPE',tag_names(astruct.(vnum)))
if (a[0] ne -1) then begin
type=strsplit(astruct.(vnum).DATA_TYPE,'>',/extract)
if n_elements(type) eq 2 then b=b+type[1]+', '
endif
a = tagindex('FIELDNAM',tag_names(astruct.(vnum)))
if (a[0] ne -1) then window_title=(b = b + astruct.(vnum).FIELDNAM)
sedat=strarr(n_elements(edat))
for i=0L,n_elements(sedat)-1 do sedat[i]=strmid(decode_cdfepoch(edat[i]),8,2)
group=0
indices=[0]
for i=1L,n_elements(sedat)-1 do begin
if sedat[i] ne sedat[i-1] then group=group+1
indices=[indices,group]
endfor
n_days=n_elements(sedat[uniq(sedat)])
if (n_days eq 1) and (not keyword_set(frame)) then FRAME=1
idat_orig=idat
glat_orig=glat
glon_orig=glon
if not keyword_set(myscale) then begin
q=where(idat[0,*] ne astruct.(vnum).fillval)
if q[0] eq -1 then myscale =0.0 else myscale=max(sqrt(idat[0,q]^2+idat[1,q]^2))
endif
if keyword_set(FRAME) then begin
if ((FRAME ge 1)AND(FRAME le n_days)) then begin
j=frame-1
q=where(indices eq j)
idat = idat_orig[*,q]
glat = glat_orig[q]
glon = glon_orig[q]
a = tagindex('VALIDMIN',tag_names(astruct.(vnum)))
if (a[0] ne -1) then begin & b=size(astruct.(vnum).VALIDMIN)
if (b[0] eq 0) then zvmin = astruct.(vnum).VALIDMIN $
else begin
zvmin = 0
print,'WARNING=Unable to determine validmin for ',vname
endelse
endif
a = tagindex('VALIDMAX',tag_names(astruct.(vnum)))
if (a[0] ne -1) then begin & b=size(astruct.(vnum).VALIDMAX)
if (b[0] eq 0) then zvmax = astruct.(vnum).VALIDMAX $
else begin
zvmax = 2000
print,'WARNING=Unable to determine validmax for ',vname
endelse
endif
if keyword_set(DEBUG) then begin
print, 'Image valid min and max: ',zvmin, ' ',zvmax
wmin = min(idat,MAX=wmax)
print, 'Actual min and max of data',wmin,' ', wmax
endif
idmax=max(idat)
idmin=min(idat)
if (idmax eq astruct.(vnum).fillval) and $
(idmin eq astruct.(vnum).fillval) then begin
print,'ERROR= All values fillval: ',astruct.(vnum).fillval
return,-1
endif
if keyword_set(DEBUG) then begin
print, '!d.table_size = ',!d.table_size
print, 'min and max after filtering = ',idmin, ' ', idmax
endif
if keyword_set(GIF) then begin
atags=tag_names(astruct.(vnum))
b = tagindex('LOGICAL_SOURCE',atags)
b1 = tagindex('LOGICAL_FILE_ID',atags)
b2 = tagindex('Logical_file_id',atags)
if (b[0] ne -1) then psrce = strupcase(astruct.(vnum).LOGICAL_SOURCE)
if (b1[0] ne -1) then $
psrce = strupcase(strmid(astruct.(vnum).LOGICAL_FILE_ID,0,9))
if (b2[0] ne -1) then $
psrce = strupcase(strmid(astruct.(vnum).Logical_file_id,0,9))
GIF=strmid(GIF,0,(strpos(GIF,'.gif')))+'_f000.gif'
if(FRAME lt 100) then gifn='0'+strtrim(string(FRAME),2)
if(FRAME lt 10) then gifn='00'+strtrim(string(FRAME),2)
if(FRAME ge 100) then gifn=strtrim(string(FRAME),2)
GIF=strmid(GIF,0,(strpos(GIF,'.gif')-3))+gifn+'.gif'
deviceopen,6,fileOutput=GIF,sizeWindow=[xs,ys+30]
if(white_background) then begin
mapcolor = foreground
erase
endif
split=strsplit(gif,'/',/extract)
outdir='/'
for k=0L,n_elements(split)-2 do outdir=outdir+split[k]+'/'
print, 'GIF_OUTDIR=',outdir
print, 'LONG_GIF=',split[k]
if (reportflag eq 1) then begin
printf,1,'LONG_GIF=',outdir+split[k] & close,1
endif
endif
if keyword_set(PS) then begin
atags=tag_names(astruct.(vnum))
b = tagindex('LOGICAL_SOURCE',atags)
b1 = tagindex('LOGICAL_FILE_ID',atags)
b2 = tagindex('Logical_file_id',atags)
if (b[0] ne -1) then psrce = strupcase(astruct.(vnum).LOGICAL_SOURCE)
if (b1[0] ne -1) then $
psrce = strupcase(strmid(astruct.(vnum).LOGICAL_FILE_ID,0,9))
if (b2[0] ne -1) then $
psrce = strupcase(strmid(astruct.(vnum).Logical_file_id,0,9))
out_PS=strmid(PS,0,(strpos(PS,'.eps')))+'_f000.eps'
help,ps,out_ps
if(FRAME lt 100) then psn='0'+strtrim(string(FRAME),2)
if(FRAME lt 10) then psn='00'+strtrim(string(FRAME),2)
if(FRAME ge 100) then psn=strtrim(string(FRAME),2)
out_PS=strmid(out_PS,0,(strpos(out_PS,'.eps')-3))+psn+'.eps'
deviceopen,1,fileOutput=out_ps,/portrait,sizeWindow=[xs,ys]
if(reportflag eq 1) then printf,1,'PS=',out_ps
print,'PS=',out_ps
endif
if not(keyword_set(GIF) or keyword_set(ps)) then begin
window,/FREE,XSIZE=xs,YSIZE=ys+30,TITLE=window_title
endif
xmargin=!x.margin
zone=transpose(idat[0,*])
meri=transpose(idat[1,*])
case map_proj of
6: begin
wc=where(keywords eq 'NORTH')
if wc[0] ne -1 then begin
map_set,/azimuthal,90.,180.,/continents,/isotropic,$
limit=[0,-180,90,180],color=200,/noborder
endif
wc=where(keywords eq 'SOUTH')
if wc[0] ne -1 then begin
map_set,/azimuthal,-90.,180.,/continents,/isotropic,$
limit=[-90,-180,0,180],color=200,/noborder
endif
end
8: begin
map_set,/cylindrical,/continents,color=0,$
/isotropic
map_grid,/label,latlab=-180.,lonlab=-90,color=0,$
latdel=30, londel=45
end
14: begin
map_set,/mercator,/continents,color=0,/isotropic,$
central_azimuth=90.,/noborder
lats=[-80,-60,-40,-20,0,20,40,60,80]
latnames=['-80','-60','-40','','0','20','40','60','80']
map_grid,/label,latlab=-180.,lonlab=-20,color=0,$
londel=20, $
lats=lats,latnames=latnames
end
else: begin
print,' Do not recognize map projection. In plot_wind_map.'
return,-1
end
endcase
map_proj_info,/current,name=idl_projection
projection=proj_names[map_proj+1]
cdaweb_velovect,zone,meri,glon,glat,$
color=230, projection=idl_projection, error=error,$
missing=astruct.(vnum).fillval,$
length=10000, /device, xy_step=xy_step, $
myscale=myscale,myunit='m/s'
if (error eq -1) then return,error
xyouts,.06,.06,/normal,astruct.(vnum).lablaxis,color=foreground
project_subtitle,astruct.(vnum),window_title,/IMAGE,$
TIMETAG=edat[q[0]], TCOLOR=foreground
if keyword_set(GIF) or keyword_set(ps) then deviceclose
endif
endif else begin
if(n_elements(THUMBSIZE) gt 0) then begin
case map_proj of
8:begin
x_tsize = THUMBSIZE
y_tsize = THUMBSIZE-70
end
14:begin
x_tsize = THUMBSIZE
y_tsize = THUMBSIZE-30
end
else:begin
x_tsize = THUMBSIZE
y_tsize = THUMBSIZE-70
end
endcase
endif else begin
x_tsize=150
y_tsize=150
endelse
nimages=n_days
if NOT keyword_set(TSTART) then start_frame = 0 $
else begin
w = where(edat ge TSTART,wc)
if wc eq 0 then begin
print,'ERROR=No image frames after requested start time.' & return,-1
endif else start_frame = w[0]
endelse
if NOT keyword_set(TSTOP) then stop_frame = nimages $
else begin
w = where(edat le TSTOP,wc)
if wc eq 0 then begin
print,'ERROR=No image frames before requested stop time.' & return,-1
endif else stop_frame = w[wc-1]
endelse
if (start_frame gt stop_frame) then no_data_avail = 1 $
else begin
no_data_avail = 0
endelse
if (no_data_avail eq 0) then begin
a = tagindex('VALIDMIN',tag_names(astruct.(vnum)))
if (a[0] ne -1) then begin & b=size(astruct.(vnum).VALIDMIN)
if (b[0] eq 0) then zvmin = astruct.(vnum).VALIDMIN $
else begin
zvmin = 0
print,'WARNING=Unable to determine validmin for ',vname
endelse
endif
a = tagindex('VALIDMAX',tag_names(astruct.(vnum)))
if (a[0] ne -1) then begin & b=size(astruct.(vnum).VALIDMAX)
if (b[0] eq 0) then zvmax = astruct.(vnum).VALIDMAX $
else begin
zvmax = 2000
print,'WARNING=Unable to determine validmax for ',vname
endelse
endif
if keyword_set(DEBUG) then begin
print, 'Image valid min and max: ',zvmin, ' ',zvmax
wmin = min(idat,MAX=wmax)
print, 'Actual min and max of data',wmin,' ', wmax
endif
ncols = round(xs/x_tsize)
if ((nimages mod ncols) eq 0) then nrows=nimages/ncols $
else nrows=(nimages/ncols) + 1
label_space = 0
boxsize = y_tsize+label_space
ys = (nrows*boxsize) +50
if keyword_set(GIF) then begin
deviceopen,6,fileOutput=GIF,sizeWindow=[xs,ys]
if(white_background) then begin
mapcolor = foreground
erase
endif
if(reportflag eq 1) then printf,1,'IMAGE=',GIF
print,'IMAGE=',GIF
endif
if keyword_set(PS) then begin
deviceopen,1,fileOutput=ps,/portrait,sizeWindow=[xs,ys]
if(reportflag eq 1) then printf,1,'PS=',ps
print,'PS=',ps
endif
if (not keyword_set(GIF) and not keyword_set(ps)) then begin
window,/FREE,XSIZE=xs,YSIZE=ys,TITLE=window_title
endif
xmargin=!x.margin
irow=0
icol=0
for j=0L,nimages-1 do begin
if(icol eq ncols) then begin
icol=0
irow=irow+1
endif
xthb=x_tsize
ythb=y_tsize+label_space
xsp=float(xthb)/float(xs+80)
ysp=float(ythb)/float(ys+30)
yi= 1.0 - 10.0/ys
x0i=0.0095
y0i=yi-ysp
x1i=0.0095+xsp
y1i=yi
x0=x0i+icol*xsp+.01
y0=y0i-irow*ysp
x1=x1i+icol*xsp
y1=y1i-irow*ysp
position=[x0,y0,x1,y1]
q=where(indices eq j)
idat = idat_orig[*,q]
glat = glat_orig[q]
glon = glon_orig[q]
zone=transpose(idat[0,*])
meri=transpose(idat[1,*])
case map_proj of
6: begin
wc=where(keywords eq 'NORTH')
if wc[0] ne -1 then begin
map_set,/azimuthal,90.,180.,/continents,/isotropic,$
limit=[0,-180,90,180],color=200,/noborder
endif
wc=where(keywords eq 'SOUTH')
if wc[0] ne -1 then begin
map_set,/azimuthal,-90.,180.,/continents,/isotropic,$
limit=[-90,-180,0,180],color=200,/noborder
endif
end
8: begin
map_set,/cylindrical,/continents,/isotropic,color=0,$
position=position,/noerase
end
14: begin
map_set,/mercator,/continents,color=0,/isotropic, $
central_azimuth=90.,position=position,/noerase
end
else: begin
print,' Do not recognize map projection. In plot_wind_map.'
return,-1
end
endcase
map_proj_info,/current,name=idl_projection
projection=proj_names[map_proj+1]
cdaweb_velovect,zone,meri,glon,glat,$
color=230, projection=idl_projection, position=position, $
missing=astruct.(vnum).fillval, error=error, $
length=2500, /device, /clip, xy_step=xy_step, $
myscale=myscale,myunit='m/s',/nolabels
if (error eq -1) then return,error
xyouts,x0,y0, $
strmid(decode_cdfepoch(edat[q[0]]),0,10),/normal
!x.margin=xmargin
icol=icol+1
endfor
xyouts,.06,.06,/normal,astruct.(vnum).lablaxis,color=foreground
project_subtitle,astruct.(vnum),window_title,/IMAGE,$
TIMETAG=[edat[0],edat[q[0]]], TCOLOR=foreground
if (reportflag eq 1) then begin
PRINTF,1,'VARNAME=',astruct.(vnum).varname
PRINTF,1,'NUMFRAMES=',nimages
PRINTF,1,'NUMROWS=',nrows & PRINTF,1,'NUMCOLS=',ncols
PRINT,1,'THUMB_HEIGHT=',y_tsize+label_space
PRINT,1,'THUMB_WIDTH=',x_tsize
PRINTF,1,'START_REC=',start_frame
PRINTF,1,'WIND_MAP_IMAGE=1'
PRINTF,1,'MYSCALE=',myscale
PRINTF,1,'XY_STEP=',xy_step
endif
PRINT,'VARNAME=',astruct.(vnum).varname
PRINT,'NUMFRAMES=',nimages
PRINT,'NUMROWS=',nrows & PRINT,'NUMCOLS=',ncols
PRINT,'THUMB_HEIGHT=',y_tsize+label_space
PRINT,'THUMB_WIDTH=',x_tsize
PRINT,'START_REC=',start_frame
PRINT,'WIND_MAP_IMAGE=1'
PRINT,'MYSCALE=',myscale
PRINT,'XY_STEP=',xy_step
if (keyword_set(CDAWEB)) then begin
if keyword_set(gif) then fname = GIF + '.sav'
if keyword_set(ps) then fname = ps + '.sav'
save_mystruct,astruct,fname
endif
if keyword_set(GIF) or keyword_set(ps) then deviceclose
endif else begin
print,'STATUS=No data in specified time period.'
if keyword_set(GIF) then begin
xyouts,xs/2,ys/2,/device,alignment=0.5,color=foreground,$
'NO DATA IN SPECIFIED TIME PERIOD'
deviceclose
endif else begin
xyouts,xs/2,ys/2,/device,alignment=0.5,'NO DATA IN SPECIFIED TIME PERIOD'
endelse
endelse
endelse
if keyword_set(GIF) or keyword_set(ps) then device,/close
return,0
end