;***************************************************************************** ; Author : Josh Grant ; Description: The name of this file says it all. Several of the programs in ; this project require the same operations only with different ; data. With this in mind I tried my best to organize the code ; in a manner that would reduce the amount of changes needed to ; be made. I have created procedures for the following... ; ; GLOBALS ; - sets all the common global variables used throughout the project, like ; the months, project base directory, colors, etc. ; GIFHEADER ; - prepares a gif image to be written to. ; WRITETOIMAGE ; - The bulk of the gif image is written in this procedure ; FINISHIMAGE ; - Finishes up the gif images and writes everything to a specified file. ; WEEKLYTITLE ; - Returns a string containing the title to be used when plotting weekly ; divergence. ; TICKVALUES ; - Determines what interval the latitude and longitude tickmarks should be ; placed at in the zonal average plot. ; INTERP ; - Can either make a given array larger or smaller depending on the factor ; specified. The added values will be linearly interpolated. ; PLOTZONALAVG ; - Plots the zonal average over a specified area. All the longitudes at a ; given latitude are averaged and a graph is produced. The zonal averages ; for the different methods (gridded vs swathed) are compared as well. ;***************************************************************************** PRO define_common_block common colors, white, rose, dkrose, red, ltyellow, yellow, dkyellow, ltgreen, $ green, dkgreen, ltaqua, aqua, dkaqua, ltblue, blue, dkblue, ltpink, pink, $ dkpink, dkred, ltpurple, purple, dkpurple, ltgray, gray, dkgray, ltbrown, $ brown, dkbrown, black, earth0, earth1, earth2, earth3, earth4, earth5, $ earth6, earth7, earth8, earth9, ice0, ice1, ice2, ice3, ice4, ice5, ice6, $ ice7, ice8, ice9, orange, oceanblue common map, title, maplimit, mappos, mapcolor, textcolor, poscolor, negcolor, $ elon, elat, eltopo, vhead, maplevels, mapcolors, levels, colors, labels, $ unit, lonlatratio end common colors common map ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : GLOBALS ; ; Description: Used by each program in the project to initialize some common ; variables used in the program. If any value needs to be ; changed for just one program than it can be done so within ; that program without effecting any other programs. ; ***IF ANY CHANGES ARE MADE HERE THEY WILL EFFECT ALL PROGRAMS ; THAT CALL THIS PROCEDURE.*** ;***************************************************************************** PRO GLOBALS, miss, baseDirectory, levels, colors, labels, unit, months1, $ months2, mapcolor, textcolor, starttime, endtime, landlevels, $ landcolors, stringFormat, plotcolors common colors miss = 99999.0 baseDirectory = "/Net/NSCAT/people/grant/diverg_proj/" stringFormat = STRCOMPRESS( '(i' + STRING( 2 ) + '.' $ + STRING( 2 ) + ')', /REMOVE_ALL ) mapcolor = black textcolor = black levels = [-124, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12] colors = [dkpurple, purple, ltpurple, dkblue, blue, aqua, ltgray, $ ltgray, ltgreen, green, dkgreen, dkpink, red, dkred] labels = [' ','-12','-10','-8','-6','-4','-2','0','2','4','6','8',$ '10','12'] unit = 'x10!U-6!Nsec!U-1!N' months1 = ["January", "February", "March", "April", "May", "June", $ "July", "August", "September (15th - 30th)", "October", $ "November", "December"] months2 = ["January", "February", "March", "April", "May", "June", $ "July", "August", "September", "October", $ "November", "December"] startTime = 0l endTime = 0l landlevels = [-1,0,250,500,750,1000,1250,1500,1750,2000] landcolors = [white, earth0, earth1, earth2, earth3, earth4, earth5, $ earth6, earth7, earth8] plotcolors = [dkgreen, dkblue, dkred] END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : GIFHEADER ; ; Description: Sets the plotting device needed to write GIF files. Caller ; passes in the number of xpixels, ypixels and the background ; color (bgcolor) the image will be. ;***************************************************************************** PRO GIFHEADER, xpixels, ypixels, bgcolor SET_PLOT, 'Z' !P.BACKGROUND = bgcolor dcolor = !D.N_COLORS DEVICE, SET_RESOLUTION = [xpixels, ypixels] XYOUTS, '!6' ERASE END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : WRITETOIMAGE ; ; Description: Plots a contour plot of the dataset (data) that is passed from ; the caller. In addition the latitude and longitude ; coordinates are printed onto the plot, and a colorbar at the ; bottom. ; Parameters: ; mappos - sets the position on the plot that the contour will be ; plotted. ; maplimit - the latitude and longitude limits of the contour plot. Must ; be in the form [latitude1, longitude1, latitude2, ; longitude2] ; landlevels- There is an option to plot the topography of the continents, ; but when this was originally written that section was ; commented out. However, the landlevels array must still be ; passed. A zero could be passed if no topography is to be ; plotted. ; landcolors- same as landlevels ; mapcolor - This is the outer edge color of the map including the ; outline of the continents ; data - 2D array of data points that will represent the contour ; plot. ; longitude - must have the same dimensions as the number of longitude ; points in the data array. ; latitude - must have the same dimensions as the number of latitude ; points in the data array. ; levels - an integer array of values used to specify at which levels ; the contours will be placed on the plot. ; colors - The color that will be used for each respective contour ; level. ; labels - string array of values to be placed under each respective ; color when the colorbar is printed. ; miss - the missing value of the dataset. ; textcolor - color used to display all text written to image ; unit - units of the data. Not used for anything but the colorbar. ;***************************************************************************** PRO WRITETOIMAGE, mappos, maplimit, landlevels, landcolors, mapcolor, data, $ longitude, latitude, levels, colors, labels, miss, $ textcolor, unit !P.POSITION = mappos ; Set map coordinate. polon = (maplimit(1) + maplimit(3)) / 2.0 MAP_SET, /NOERASE, 0, (maplimit(1) + maplimit(3)) / 2.0, $ /CYLINDRICAL, LIMIT = maplimit, COLOR = mapcolor ; TOPOGRAPHY, maplimit, landlevels, landcolors CONTOUR, data, longitude, latitude, /OVERPLOT, /CELL_FILL, $ LEVELS = levels, C_COLORS = colors, MAX_VALUE = miss - 1 MAP_CONTINENTS, COLOR = mapcolor, /COASTS ; Write tick marks and label. MAPTICK, maplimit, textcolor COLORBAR, labels, colors, unit, 0.10, 0.90, 0.13, $ COLOR = textcolor, YLABEL = 0.075, XUNIT = 0.87, $ BOXWIDTH = 6.8 XYOUTS, /NORMAL, 0.01, 0.01, "!17Grant", ALIGNMENT = 0.0, $ CHARSIZE = 0.9, CHARTHICk = 1.0, COLOR = textcolor XYOUTS, /NORMAL, 0.99, 0.01, "!17COAPS-FSU 2000", $ ALIGNMENT = 1.0, CHARSIZE = 0.9, CHARTHICk = 1.0, $ COLOR = textcolor END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : FINISHIMAGE ; ; Description: Once the plotting is complete and everything has been written ; to the image it is written to a file. The image is passed and ; the filename is used to save the file. ;***************************************************************************** PRO FINISHIMAGE, image, filename TVLCT, red, green, blue, /GET red = BYTE( red ) green = BYTE( green ) blue = BYTE( blue ) WRITE_GIF, fileName, image, red, green, blue END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : WEEKLYTITLE ; Return Type : String ; ; Description: When plotting the weekly divergences it is nice to have the ; current week being plotted written to the top of the image. ; The string to be written is created here and then return to ; the caller. ; Parameters: ; year - the current year of the plot ; number - the current frame number of the plot ; months - an array containing the months of the year ; abbrev - gives the option of printing an abbreviated date. If abbrev=1 ; then the string will have the format like 10/20/1996, otherwise ; October 20, 1996. ;***************************************************************************** FUNCTION WEEKLYTITLE, year, number, months, ABBREV = abbrev IF N_ELEMENTS(abbrev) EQ 0 THEN abbrev = 0 IF ( year EQ 1996 ) THEN BEGIN firstday = ( number - 1 ) * 7 firstyear = year lastday = ( number * 7 ) - 1 lastyear = year ENDIF ELSE BEGIN IF ( number EQ 1 ) THEN BEGIN firstday = 364 firstyear = 1996 lastday = 4 lastyear = 1997 ENDIF ELSE BEGIN firstday = ( number - 1 ) * 7 - 2 firstyear = year lastday = ( number * 7 ) - 3 lastyear = year ENDELSE ENDELSE jday2date, firstday, firstmonth, dayofmonth, firstyear string1 = "" IF ( abbrev EQ 1 ) THEN BEGIN string1 = STRTRIM(firstmonth, 1) + "/" + STRTRIM(dayofmonth, 1) $ + "/" + STRTRIM(year, 1) ENDIF ELSE BEGIN string1 = months[firstmonth-1] + " " + STRTRIM(dayofmonth, 1) $ + ", " + STRTRIM(year, 1) ENDELSE jday2date, lastday, lastmonth, dayofmonth, lastyear string2 = "" IF ( abbrev EQ 1 ) THEN BEGIN string2 = STRTRIM(lastmonth, 1) + "/" + STRTRIM(dayofmonth, 1) $ + "/" + STRTRIM(lastyear, 1) ENDIF ELSE BEGIN string2 = months[lastmonth-1] + " " + STRTRIM(dayofmonth, 1) $ + ", " + STRTRIM(lastyear, 1) ENDELSE return, string1 + " - " + string2 END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : TICKVALUES ; ; Description: The zonal average plots contain a little picture of the world ; on the side, but it is too small to effectively use the ; routine used to write the map coordinates for the large ; plots. Therefore an additional customised version was written ; for the zonal average plots. ; Parameters: ; startlat - the starting latitude, closest to the south pole ; endlat - the ending latitude, closest to the north pole ; values - array to be updated by routine containing the integer values ; of each tickmark ; names - array to be updated by routine containing the printable string ; values of each tickmark ;***************************************************************************** PRO TICKVALUES, startlat, endlat, values, names numberofvalues = 0 ticklocation, startlat, endlat, startvalue, endvalue, latinterval values = INTARR( (endvalue - startvalue) / latinterval + 1 ) names = STRARR( (endvalue - startvalue) / latinterval + 1 ) FOR i = startvalue, endvalue, latinterval DO BEGIN CASE 1 OF (i EQ 0) : names[ numberofvalues ] = 'EQ' (i LT 0) : names[ numberofvalues ] = STRTRIM(-i, 1) + 'S' ELSE : names[ numberofvalues ] = STRTRIM(i, 1) + 'N' ENDCASE values[ numberofvalues ] = i numberofvalues = numberofvalues + 1 ENDFOR END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : INTERP ; ; Description: Resizes an array by a specified factor and linearly ; interpolates between values that are added. ; Parameters: ; passed - the array to be resized. ; original_spacing- spacing of the passed array. ; factor - factor by which array is to resized. ;***************************************************************************** FUNCTION INTERP, passed, original_spacing, factor original = REFORM( passed ) newarray = FLTARR( original_spacing * factor - factor + 1 ) FOR index = 0, original_spacing - 2 DO BEGIN difference = ( original[ index + 1 ] - original[ index ] ) / factor FOR step = 0, factor - 1 DO BEGIN newarray[ index * factor + step ] = original[ index ] + (difference * step) ENDFOR ENDFOR newarray[ (original_spacing - 1) * factor ] = original[ original_spacing - 1 ] return, newarray END ;***************************************************************************** ; Author : Josh Grant, COAPS ; Procedure Name : PLOTZONALAVG ; ; Description: Plots the zonal average of the swathed divergence, gridded ; divergence, and then the difference of the two methods. The ; longitudes of each latitude point is added and averaged to ; find the average at each latitude and then they are plotted. ; Parameters: ; data - a 3D array with the 3rd dimension having only 2 elements. ; The first element is the swathed divergence values and the ; second is the gridded divergences. ; area - area from the globe where the averages are to be found. ; miss - missing value of the datasets ; textcolor - color of all text printed to image. ; plotcolors - Each average will be plotted with its respective color in ; this 3 element array. ; landlevels - levels used to plot the topography on the continents. ; landcolors - colors used to plot the respective contour value. ; oceanblue - color used to fill the ocean on the globe. ; boxcolor - color of the box outlining the area that is being averaged ; on the globe. ; gif_name - file name that the image will be written to. ; mapcolor - color used for the outline of each map ; date - date printed at top of image depicting date of the data. ;***************************************************************************** PRO PLOTZONALAVG, data, area, miss, textcolor, plotcolors, $ landlevels, landcolors, oceanblue, boxcolor, $ gif_name, mapcolor, date xtitle = "Divergence (x10!U-6!Nsec!U-1!N)" ytitle = "Latitude" top_title = "Tropical Pacific Ocean" mid_title = "Wind Divergence Zonal Averages for" top_title_ypos = 0.96 mid_title_ypos = 0.95 date_title_ypos = 0.86 legends = ['Calculated from swaths', 'Calculated from gridded winds', $ 'Difference of the two methods'] legendx = 0.37 legendy = 0.28 mappos = [0.07, 0.39, 0.40, 0.68] plotos = [0.50, 0.15, 0.75, 0.95] diff = [0.80, 0.15, 0.97, 0.95] ; bottom_coord = [0.04, 0.04, 0.32, 0.28] ; divplot = FLTARR(4) xrange1 = [-10, 10] xrange2 = [-2, 2] interpfac = 100 lonlatratio = (mappos(2)-mappos(0))/(mappos(3)-mappos(1)) maplimit = [area(1), area(0), area(3), area(2)] globalarea = [-80, 0, 80, 359] xdimensions = area(2) - area(0) + 1 ydimensions = area(3) - area(1) + 1 latitude = FINDGEN( ydimensions ) + area(1) longitude = FINDGEN( xdimensions ) + area(0) dataavg = FLTARR( 3, ydimensions ) zonetotals = FLTARR( 3, ydimensions ) temp1 = data[0,*,*] temp2 = data[1,*,*] missing1 = WHERE(temp1 EQ miss) missing2 = WHERE(temp2 EQ miss) temp3 = temp2 - temp1 temp3[missing1] = miss temp3[missing2] = miss data[2,*,*] = temp3 XYOUTS, /NORMAL, 0.22, mid_title_ypos, mid_title, $ ALIGNMENT = 0.5, CHARSIZE = 1.2, CHARTHICK = 1.0, $ COLOR = textcolor XYOUTS, /NORMAL, 0.22, mid_title_ypos - 0.06, date, $ ALIGNMENT = 0.5, CHARSIZE = 1.2, CHARTHICK = 1.0, $ COLOR = textcolor coordinates = STRARR(4) FOR i = 0, 2, 2 DO BEGIN CASE 1 OF (area[i] EQ 0) OR ( area[i] EQ 180) : coordinates[i] = STRTRIM(area[i], 1) (area[i] LT 0) : coordinates[i] = STRTRIM(-(area[i]), 1) + 'W' (area[i] GT 180) : coordinates[i] = STRTRIM(360-area[i], 1) + 'W' ELSE : coordinates[i] = STRTRIM(area[i], 1) + 'E' ENDCASE ENDFOR FOR i = 1, 3, 2 DO BEGIN CASE 1 OF (area[i] EQ 0) : coordinates[i] = 'the EQ' (area[i] LT 0) : coordinates[i] = "Latitude " + $ STRTRIM(-(area[i]), 1) + "S" ELSE : coordinates[i] = STRTRIM(area[i], 1) + 'N' ENDCASE ENDFOR latstring = "From " + coordinates[1] + " to " + coordinates[3] lonstring = "Longitude " + coordinates[0] + " to " + coordinates[2] XYOUTS, /NORMAL, 0.22, mid_title_ypos - 0.13, latstring, $ ALIGNMENT = 0.5, CHARSIZE = 1.1, CHARTHICK = 1.0, $ COLOR = textcolor XYOUTS, /NORMAL, 0.22, mid_title_ypos - 0.17, "and", $ ALIGNMENT = 0.5, CHARSIZE = 1.1, CHARTHICK = 1.0, $ COLOR = textcolor XYOUTS, /NORMAL, 0.22, mid_title_ypos - 0.21, lonstring, $ ALIGNMENT = 0.5, CHARSIZE = 1.1, CHARTHICK = 1.0, $ COLOR = textcolor highest = 0.0 lowest = 0.0 highest_diff = 0.0 lowest_diff = 0.0 FOR index = 0, 2 DO BEGIN FOR y = 0, ydimensions - 1 DO BEGIN FOR x = 0, xdimensions - 1 DO BEGIN IF ( data[ index, x, y ] NE miss ) THEN BEGIN dataavg[index,y] = dataavg[index,y] + data[index,x,y] zonetotals[ index, y ] = zonetotals[ index, y ] + 1.0 ENDIF ENDFOR print, zonetotals[index, y] dataavg[index,y] = dataavg[index,y] / zonetotals[index,y] IF ( ( index EQ 0 OR index EQ 1 ) AND y EQ 0 ) THEN BEGIN highest = dataavg[index,y] lowest = dataavg[index,y] ENDIF ELSE BEGIN IF ( dataavg[index,y] GT highest ) THEN highest = dataavg[index,y] IF ( dataavg[index,y] LT lowest ) THEN lowest = dataavg[index,y] ENDELSE IF ( index EQ 2 AND y EQ 0 ) THEN BEGIN highest_diff = dataavg[index,y] lowest_diff = dataavg[index,y] ENDIF ELSE BEGIN IF ( dataavg[index,y] GT highest_diff ) THEN $ highest_diff = dataavg[index,y] IF ( dataavg[index,y] LT lowest_diff ) THEN $ lowest_diff = dataavg[index,y] ENDELSE ENDFOR ENDFOR IF ( lowest GT -10.0 AND highest LT 10.0 ) THEN BEGIN xrange = [-10.0, 10.0] ENDIF ELSE BEGIN xrange = [ lowest, highest ] ENDELSE TICKVALUES, area(1), area(3), values, names newlatitude = FINDGEN(ydimensions*interpfac) / interpfac + area(1) PLOT, /NOERASE, FLTARR(ydimensions*interpfac), newlatitude, $ POSITION = plotos, $ COLOR = textcolor, YRANGE = [area(1), area(3)], $ XRANGE = xrange, XTITLE = xtitle, YTITLE = ytitle FOR I = 0, 1 DO OPLOT, $ INTERP(dataavg[I,*], ydimensions, interpfac), $ newlatitude, LINE = 0, THICK = 2.0, COLOR = plotcolors(I) IF ( lowest_diff GT -3.0 AND highest_diff LT 3.0 ) THEN BEGIN xrange = [-3.0, 3.0] ENDIF ELSE BEGIN xrange = [ lowest_diff, highest_diff ] ENDELSE PLOT, /NOERASE, FLTARR(ydimensions*interpfac), newlatitude, $ POSITION = diff, COLOR = textcolor, YRANGE = [area(1), area(3)], $ XRANGE = xrange, XTITLE = xtitle OPLOT, INTERP(dataavg[2,*], ydimensions, interpfac), newlatitude, $ LINE = 0, THICK = 2.0, $ COLOR = plotcolors(2) FOR i = 0, 2 DO BEGIN XYOUTS, /NORMAL, legendx, legendy - 0.05*i, legends[i], $ ALIGNMENT = 1.0, CHARSIZE = 1.2, CHARTHICK = 1.0, $ COLOR = textcolor XYOUTS, /NORMAL, legendx + 0.01, legendy - 0.05*i - 0.015, "-", $ ALIGNMENT = 0.0, CHARSIZE = 3.0, CHARTHICK = 2.25, $ COLOR = plotcolors[i] ENDFOR !P.POSITION = mappos IF ( area(0) LT 0 ) THEN BEGIN globalarea[1] = globalarea[1] - 179 globalarea[3] = globalarea[3] - 180 ENDIF MAP_SET, /NOERASE, 0, (globalarea(1) + globalarea(3)) / 2.0, $ /CYLINDRICAL, LIMIT = globalarea, COLOR = mapcolor tempdata = FLTARR(globalarea(3) - globalarea(1) + 1, $ globalarea(2) - globalarea(0) + 1 ) templon = FINDGEN(globalarea(3)-globalarea(1) + 1) + globalarea(1) templat = FINDGEN(globalarea(2)-globalarea(0) + 1) + globalarea(0) CONTOUR, tempdata, templon, templat, /OVERPLOT, /CELL_FILL, $ LEVELS = 0, C_COLORS = oceanblue TOPOGRAPHY, globalarea, landlevels, landcolors MAP_CONTINENTS, COLOR = mapcolor, /COASTS, MLINETHICK = 0.5 MAPTICK, globalarea, textcolor PLOTS, [area(0), area(1)], COLOR = boxcolor PLOTS, [area(0), area(3)], COLOR = boxcolor, /CONTINUE PLOTS, [area(2), area(3)], COLOR = boxcolor, /CONTINUE PLOTS, [area(2), area(1)], COLOR = boxcolor, /CONTINUE PLOTS, [area(0), area(1)], COLOR = boxcolor, /CONTINUE ; latdiff = area[3] - area[1] ; londiff = area[2] - area[0] ; buffer = 0.0 ; lat_span = 0.0 ; IF ( latdiff / londiff GE 0.80 ) THEN BEGIN ; divplot[1] = bottom_coord[1] ; divplot[3] = bottom_coord[3] ; lon_span = londiff / (latdiff / (bottom_coord[3] - bottom_coord[1])) ; buffer = ( bottom_coord[2] - bottom_coord[0] - lon_span ) / 2 ; divplot[0] = bottom_coord[0] + buffer ; divplot[2] = bottom_coord[2] - buffer ; ENDIF ELSE BEGIN ; divplot[0] = bottom_coord[0] ; divplot[2] = bottom_coord[2] ; lat_span = latdiff / (londiff / (bottom_coord[2] - bottom_coord[0])) ; buffer = ( bottom_coord[3] - lat_span - bottom_coord[1] ) / 2 ; divplot[1] = bottom_coord[1] + buffer ; divplot[3] = bottom_coord[3] - buffer ; ENDELSE ; ; offset = [0.0, 0.0, 0.0, 0.0] ; FOR plot_number = 0, 2 DO BEGIN ; !P.POSITION = divplot + (offset * plot_number) ; MAP_SET, /NOERASE, 0, (maplimit(1) + maplimit(3)) / 2.0, $ ; /CYLINDRICAL, LIMIT = maplimit, COLOR = mapcolor ; TOPOGRAPHY, maplimit, landlevels, landcolors ; CONTOUR, data[plot_number, *, *], longitude, latitude, /OVERPLOT, $ ; /CELL_FILL, LEVELS = levels, C_COLORS = colors, MAX_VALUE = miss - 1 ; ; MAP_CONTINENTS, COLOR = mapcolor, /COASTS ; Write tick marks and label. ; MAPTICK, maplimit, textcolor, WIDENINTV = 1 ; offset = [0.333, 0.0, 0.333, 0.0] ; ENDFOR ; COLORBAR, labels, colors, unit, 0.10, 0.90, 0.13, $ ; COLOR = textcolor, YLABEL = 0.075, XUNIT = 0.87, $ ; BOXWIDTH = 6.8 XYOUTS, /NORMAL, 0.01, 0.01, "!17Grant", ALIGNMENT = 0.0, $ CHARSIZE = 0.9, CHARTHICk = 1.0, COLOR = textcolor XYOUTS, /NORMAL, 0.99, 0.01, "!17COAPS-FSU 1999", $ ALIGNMENT = 1.0, CHARSIZE = 0.9, CHARTHICk = 1.0, $ COLOR = textcolor FINISHIMAGE, TVRD(), gif_name print, "Wrote " + gif_name END