[152] | 1 | ;+ |
---|
[231] | 2 | ; |
---|
[152] | 3 | ; @file_comments |
---|
| 4 | ; Draw 2d plots with TV procedure |
---|
| 5 | ; |
---|
| 6 | ; @categories find a file |
---|
| 7 | ; graphic |
---|
| 8 | ; |
---|
[231] | 9 | ; @param DATA {in}{required} |
---|
[152] | 10 | ; The field we want to display can be: |
---|
| 11 | ; 1) an array. If the array is not a 2D array, its mean along |
---|
| 12 | ; the z and t direction will be automatically performed |
---|
| 13 | ; (as it is done in plt). |
---|
| 14 | ; 2) a structure respecting all criterions specified by |
---|
[231] | 15 | ; <pro>litchamp</pro> cf. IDL> xhelp,'litchamp' |
---|
[152] | 16 | ; |
---|
[231] | 17 | ; @param MIN {in}{optional}{default=min of DATA (on non-masked points)} |
---|
[152] | 18 | ; |
---|
[231] | 19 | ; @param MAX {in}{optional}{default=max of DATA (on non-masked points)} |
---|
[152] | 20 | ; |
---|
| 21 | ; @keyword BOTTOM {default=0} |
---|
| 22 | ; The lowest color index of the colors to be used |
---|
| 23 | ; |
---|
[231] | 24 | ; @keyword BOXZOOM |
---|
| 25 | ; Vector indicating the geographic zone on which we want to cut the map. |
---|
[152] | 26 | ; If BOXZOOM has : |
---|
| 27 | ; 1 element : The extraction is made on [lon1, lon2, lat1, lat2, 0.,boxzoom[0]] |
---|
| 28 | ; 2 elements: The extraction is made on [lon1, lon2, lat1, lat2, boxzoom[0],boxzoom[1]] |
---|
| 29 | ; 4 elements: The extraction is made on [Boxzoom, 0, max([gdept, gdepw])] |
---|
| 30 | ; 5 elements: The extraction is made on [Boxzoom[0:3], 0, Boxzoom[4]] |
---|
| 31 | ; 6 elements: The extraction is made on Boxzoom |
---|
| 32 | ; |
---|
[254] | 33 | ; Where lon1, lon2, lat1, lat2 are global variables defined at the last |
---|
| 34 | ; <pro>domdef</pro> ! |
---|
[152] | 35 | ; |
---|
| 36 | ; @keyword C_NAN {default=!d.n_colors < 255} |
---|
| 37 | ; The color number that should be used for the NaN values. |
---|
| 38 | ; |
---|
| 39 | ; @keyword C_MASK {default=0} |
---|
| 40 | ; The color number that should be used for the mask values. |
---|
| 41 | ; |
---|
| 42 | ; @keyword MASKVAL {default=1.e+20} |
---|
| 43 | ; The mask value. Note that if abs(mask) < 1.e6, then the |
---|
| 44 | ; exact value of the mask is used to find the maskwd point. |
---|
| 45 | ; if abs(mask) > 1.e6, the test to find the masked value is ge |
---|
| 46 | ; abs(mask)/10. This is necessary to avoid the rounding errors |
---|
| 47 | ; |
---|
| 48 | ; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - BOTTOM} |
---|
| 49 | ; number of colors to be used. |
---|
| 50 | ; |
---|
| 51 | ; @keyword NOINTERP |
---|
[163] | 52 | ; Used this keyword if you don't want that the values |
---|
[152] | 53 | ; are interpolated from BOTTOM using NCOLORS colors. |
---|
[163] | 54 | ; This can be for example useful when working on byte type arrays. |
---|
[152] | 55 | ; |
---|
| 56 | ; @keyword _EXTRA |
---|
[260] | 57 | ; Used to pass keywords to <pro>placedessin</pro>, <proidl>TV</proidl>, |
---|
[259] | 58 | ; <pro>axe</pro>, <pro>legende</pro>, <pro>barrecouleur</pro>, |
---|
| 59 | ; <pro>terminedessin</pro> |
---|
[231] | 60 | ; |
---|
[152] | 61 | ; @examples |
---|
| 62 | ; IDL> tvplus, dist(100) |
---|
| 63 | ; |
---|
| 64 | ; @history |
---|
| 65 | ; Aug 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
| 66 | ; |
---|
| 67 | ; @version |
---|
| 68 | ; $Id$ |
---|
| 69 | ; |
---|
| 70 | ;- |
---|
[231] | 71 | ; |
---|
[152] | 72 | PRO pltv, data, min, max, BOTTOM = bottom, BOXZOOM = boxzoom $ |
---|
| 73 | , C_MASK = c_mask, C_NAN = c_nan, MININ = minin, MAXIN = maxin $ |
---|
| 74 | , MASKVAL = maskval, NCOLORS = ncolors, NOINTERP = nointerp $ |
---|
| 75 | , _EXTRA = ex |
---|
| 76 | ; |
---|
| 77 | compile_opt idl2, strictarrsubs |
---|
| 78 | ; |
---|
| 79 | @cm_general ; for key_performance |
---|
| 80 | ;-------------------------------------------------------------- |
---|
| 81 | tempsun = systime(1) ; for key_performance |
---|
| 82 | ;-------------------------------------------------------------- |
---|
| 83 | ;-------------------------------------------------------------- |
---|
| 84 | ; I2) Reading of the field and checkup. |
---|
| 85 | ;-------------------------------------------------------------- |
---|
[231] | 86 | IF n_elements(minin) NE 0 THEN min = minin |
---|
[152] | 87 | IF n_elements(maxin) NE 0 THEN max = maxin |
---|
| 88 | IF size(data, /type) NE 8 THEN z2d = reform(float(data)) ELSE z2d = data |
---|
| 89 | IF size(z2d, /n_dimensions) NE 2 then BEGIN |
---|
| 90 | if keyword_set(boxzoom) then BEGIN |
---|
| 91 | savedbox = 1b |
---|
| 92 | saveboxparam, 'boxparam4pltv.dat' |
---|
| 93 | ENDIF |
---|
[231] | 94 | z2d = checkfield(temporary(z2d), 'plt', TYPE = 'xy', direc = direc, BOXZOOM = boxzoom) |
---|
[251] | 95 | if n_elements(z2d) EQ 1 AND z2d[0] EQ -1 then BEGIN |
---|
[152] | 96 | IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat' |
---|
| 97 | return |
---|
| 98 | ENDIF |
---|
| 99 | ENDIF |
---|
| 100 | dtasize = size(z2d, /dimensions) |
---|
| 101 | ;------------------------------------------------------------ |
---|
| 102 | ; def of ncolmax, bottom, topcol et ncolors |
---|
| 103 | ;------------------------------------------------------------ |
---|
| 104 | ncolmax = !d.n_colors < 256 |
---|
| 105 | IF n_elements(bottom) EQ 0 THEN bottom = 1 |
---|
| 106 | IF NOT keyword_set(ncolors) then ncolors = ncolmax - 1 - bottom |
---|
| 107 | topcol = (bottom + ncolors - 1) < (ncolmax - 1) |
---|
| 108 | ;------------------------------------------------------------ |
---|
| 109 | ; Do we have NaN values in z2d??? |
---|
| 110 | ;------------------------------------------------------------ |
---|
| 111 | msknan = finite(z2d, /nan) |
---|
| 112 | nan = total(msknan) |
---|
| 113 | IF keyword_set(nan) THEN nanind = where(temporary(msknan) EQ 1) |
---|
| 114 | ;------------------------------------------------------------ |
---|
| 115 | ; get the mask |
---|
| 116 | ;------------------------------------------------------------ |
---|
| 117 | IF n_elements(maskval) EQ 0 THEN maskval = 1.e20 |
---|
[231] | 118 | IF abs(maskval) LT 1e6 THEN BEGIN |
---|
[152] | 119 | IF keyword_set(nan) THEN z2d[nanind] = 1.e20 |
---|
[231] | 120 | msk = z2d NE maskval |
---|
| 121 | ENDIF ELSE BEGIN |
---|
[152] | 122 | IF keyword_set(nan) THEN z2d[nanind] = 0 |
---|
| 123 | msk = abs(z2d) LT abs(maskval)/10. |
---|
| 124 | ENDELSE |
---|
| 125 | maskind = where(msk EQ 0, masked) |
---|
| 126 | IF keyword_set(nan) THEN z2d[nanind] = !values.f_nan |
---|
| 127 | ;------------------------------------------------------------ |
---|
| 128 | ; get the real min/max and the user defined min/max of the array |
---|
| 129 | ;------------------------------------------------------------ |
---|
| 130 | determineminmax, z2d, msk, truemin, truemax, MININ = min, MAXIN = max, NAN = nan |
---|
[263] | 131 | if n_elements(z2d) EQ 1 AND z2d[0] EQ -1 then BEGIN |
---|
| 132 | IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat' |
---|
| 133 | return |
---|
| 134 | ENDIF |
---|
[181] | 135 | z2d = min > temporary(z2d) < max |
---|
[152] | 136 | ;------------------------------------------------------------ |
---|
[231] | 137 | ; apply other keywords (nointerp, c_nan, c_mask) |
---|
[152] | 138 | ;------------------------------------------------------------ |
---|
| 139 | IF NOT keyword_set(nointerp) THEN BEGIN |
---|
| 140 | ; interpolation between bottom and bottom+ncolors-1 |
---|
[181] | 141 | m = 1.*(ncolors-1)/(max-min) |
---|
| 142 | p = bottom - 1.*min*m |
---|
[152] | 143 | z2d = m * temporary(z2d) + p |
---|
| 144 | ENDIF |
---|
[231] | 145 | ; set c_nan for NaN values |
---|
[152] | 146 | IF keyword_set(nan) THEN BEGIN |
---|
| 147 | IF n_elements(c_nan) NE 0 THEN cnan = 0 > c_nan < (ncolmax -1) ELSE cnan = (ncolmax -1) |
---|
| 148 | z2d[nanind] = cnan |
---|
| 149 | ENDIF |
---|
| 150 | ; c_mask for masked values |
---|
[231] | 151 | IF keyword_set(masked) THEN BEGIN |
---|
[152] | 152 | IF n_elements(c_mask) NE 0 THEN cmask = 0 > c_mask < (ncolmax - 1) ELSE cmask = (ncolmax -1) |
---|
| 153 | z2d[maskind] = cmask |
---|
[231] | 154 | ENDIF |
---|
| 155 | z2d = round(temporary(z2d)) |
---|
[152] | 156 | ; use byte type to save memory |
---|
| 157 | z2d = byte(temporary(z2d)) |
---|
| 158 | ;-------------------------------------------------------------- |
---|
| 159 | ; . |
---|
| 160 | ;-------------------------------------------------------------- |
---|
| 161 | if NOT keyword_set(overplot) then reinitplt, /z, /invert |
---|
[256] | 162 | placedessin, 'pltv', posplot, posbar, dtasize, _extra = ex |
---|
[152] | 163 | ;-------------------------------------------------------------- |
---|
| 164 | ; 3) Drawing |
---|
| 165 | ;-------------------------------------------------------------- |
---|
| 166 | |
---|
| 167 | xsize = !p.position[2] - !p.position[0] |
---|
| 168 | ysize = !p.position[3] - !p.position[1] |
---|
[231] | 169 | IF !d.name EQ 'X' THEN BEGIN |
---|
[152] | 170 | xsize = ceil(xsize * !d.x_size) |
---|
| 171 | ysize = ceil(ysize * !d.y_size) |
---|
| 172 | z2d = congrid(z2d, xsize, ysize) |
---|
| 173 | ENDIF |
---|
[231] | 174 | |
---|
[152] | 175 | tv, z2d, !p.position[0], !p.position[1] $ |
---|
| 176 | , xsize = xsize, ysize = ysize $ |
---|
| 177 | , /normal, _EXTRA = ex |
---|
| 178 | |
---|
| 179 | ;------------------------------------------------------------ |
---|
| 180 | ; caption + display of these. |
---|
| 181 | ;------------------------------------------------------------ |
---|
| 182 | axe, 'pltv', dtasize, _EXTRA = ex |
---|
| 183 | legende, truemin, truemax, 'plt', DIREC = direc $ |
---|
| 184 | , INTERVALLE = float(max-min)/(topcol-bottom) $ |
---|
| 185 | , _extra = ex |
---|
| 186 | plot, [0], [0], /noerase, /nodata, xstyle = 1, ystyle = 1 |
---|
| 187 | |
---|
| 188 | IF keyword_set(masked) THEN tracemask, msk, indgen(dtasize[0]), indgen(dtasize[1]) |
---|
| 189 | ;------------------------------------------------------------ |
---|
| 190 | ; color bar |
---|
| 191 | ;------------------------------------------------------------ |
---|
| 192 | barrecouleur, 0, min, max, 10, bottom = bottom, position = posbar, ncolors = (topcol-bottom+1), _extra = ex |
---|
[231] | 193 | ; 4) End of drawing |
---|
| 194 | terminedessin, _extra=ex |
---|
[152] | 195 | ; |
---|
| 196 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat' |
---|
[231] | 197 | if keyword_set(key_performance) NE 0 THEN print, 'time pltv', systime(1)-tempsun |
---|
[152] | 198 | ; |
---|
| 199 | return |
---|
| 200 | end |
---|