Changeset 432 for trunk/SRC/ToBeReviewed
- Timestamp:
- 05/14/10 12:11:28 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/PLOTS/VECTEUR/vecteur.pro
r370 r432 134 134 ; The color of the arrow. Black by default (color 0) 135 135 ; 136 ; @keyword VECTNORMCOLOR 137 ; a 2 elements vector used to specify the color of the vector according to 138 ; its norm. Vector norm will be scaled to color numbers (1 to 254) by using 139 ; the following rule: VECTNORMCOLOR[0] corresponds to 1 and VECTNORMCOLOR[1] to 254 140 ; 136 141 ; @keyword VECTTHICK {default=1} 137 142 ; The thick of the arrow. … … 169 174 ;- 170 175 PRO vecteur, composanteu, composantev, normevecteur, indice2d, reduitindice2d $ 171 , CMREF=cmref, MISSING=missing, NORMEREF=normeref $172 , VECTCOLOR=vectcolor, VECTTHICK=vectthick $173 , VECTREFPOS=vectrefpos$174 , VECTREFFORMAT=vectrefformat, NOVECTREF=novectref $175 , _EXTRA=extra176 , CMREF = cmref, MISSING = missing, NORMEREF = normeref $ 177 , VECTCOLOR = vectcolor, VECTTHICK = vectthick $ 178 , VECTREFPOS = vectrefpos, VECTNORMCOLOR = vectnormcolor $ 179 , VECTREFFORMAT = vectrefformat, NOVECTREF = novectref $ 180 , _EXTRA = extra 176 181 ; 177 182 compile_opt idl2, strictarrsubs 178 183 ; 179 184 @common 180 tempsun = systime(1); For key_performance181 ; 182 ; 183 184 185 186 187 188 189 190 191 192 193 ; 194 195 196 197 198 199 200 201 185 tempsun = systime(1) ; For key_performance 186 ; 187 ; 188 taille = size(composanteu) 189 nx = taille[1] 190 ny = taille[2] 191 if n_elements(reduitindice2d) EQ 0 then reduitindice2d = lindgen(nx, ny) 192 zu = composanteu 193 zv = composantev 194 norme = normevecteur 195 taille = size(indice2d) 196 nxgd = taille[1] 197 nygd = taille[2] 198 ; 199 msk = replicate(1, nx, ny) 200 if keyword_set(missing) then terre = where(abs(zu) GE missing/10) ELSE terre = -1 201 if terre[0] NE -1 then BEGIN 202 msk[terre] = 0 203 zu[terre] = 0 204 zv[terre] = 0 205 norme[terre] = 0 206 ENDIF 202 207 ; 203 208 ; Stage 1: … … 246 251 ; 247 252 ; coordinates of the point T (beginning of the arrow) in spherical coordinates. 248 249 253 glam = glamt[indice2d[reduitindice2d]] 254 gphi = gphit[indice2d[reduitindice2d]] 250 255 ; 251 256 ; Coordinates of the point T (beginning of the arrow) in the cartesian reference. 252 257 ; For the sphere, we use a sphere with a radius of 1. 253 258 ; 254 radius = replicate(1,nx*ny)255 256 r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)257 ; 258 259 260 259 radius = replicate(1, nx*ny) 260 coord_sphe = transpose([ [glam[*]], [gphi[*]], [radius[*]] ]) 261 r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 262 ; 263 x0 = reform(r[0, *], nx, ny) 264 y0 = reform(r[1, *], nx, ny) 265 z0 = reform(r[2, *], nx, ny) 261 266 ; 262 267 ; Stage 1, b) … … 270 275 ; 271 276 ; definition of nu 272 radius = replicate(1,nxgd*nygd)273 277 radius = replicate(1, nxgd*nygd) 278 IF finite(glamu[0]*gphiu[0]) NE 0 THEN $ 274 279 coord_sphe = transpose([ [(glamu[indice2d])[*]], [(gphiu[indice2d])[*]], [radius[*]] ]) $ 275 276 r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)280 ELSE coord_sphe = transpose([ [(glamf[indice2d])[*]], [(gphit[indice2d])[*]], [radius[*]] ]) 281 r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 277 282 ; coordinates of points of the grid u in cartesian. 278 279 280 283 ux = reform(r[0, *], nxgd, nygd) 284 uy = reform(r[1, *], nxgd, nygd) 285 uz = reform(r[2, *], nxgd, nygd) 281 286 ; calculation of nu 282 283 284 287 nux = ux-shift(ux, 1, 0) 288 nuy = uy-shift(uy, 1, 0) 289 nuz = uz-shift(uz, 1, 0) 285 290 ; conditions at extremities. 286 287 288 289 290 291 if NOT keyword_set(key_periodic) OR nxgd NE jpi then begin 292 nux[0, *] = nux[1, *] 293 nuy[0, *] = nuy[1, *] 294 nuz[0, *] = nuz[1, *] 295 ENDIF 291 296 ; reduction of the grid 292 293 294 297 nux = nux[reduitindice2d] 298 nuy = nuy[reduitindice2d] 299 nuz = nuz[reduitindice2d] 295 300 ; definition of nv 296 297 coord_sphe = transpose([ [(glamv[indice2d])[*]], [(gphiv[indice2d])[*]], [radius[*]] ]) $298 299 r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)301 IF finite(glamv[0]*gphiv[0]) NE 0 THEN $ 302 coord_sphe = transpose([ [(glamv[indice2d])[*]], [(gphiv[indice2d])[*]], [radius[*]] ]) $ 303 ELSE coord_sphe = transpose([ [(glamt[indice2d])[*]], [(gphif[indice2d])[*]], [radius[*]] ]) 304 r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 300 305 ; coordinates of points of the grid in cartesian. 301 302 303 306 vx = reform(r[0, *], nxgd, nygd) 307 vy = reform(r[1, *], nxgd, nygd) 308 vz = reform(r[2, *], nxgd, nygd) 304 309 ; calcul of nv 305 306 307 310 nvx = vx-shift(vx, 0, 1) 311 nvy = vy-shift(vy, 0, 1) 312 nvz = vz-shift(vz, 0, 1) 308 313 ; conditions at extremities 309 310 311 314 nvx[*, 0] = nvx[*, 1] 315 nvy[*, 0] = nvy[*, 1] 316 nvz[*, 0] = nvz[*, 1] 312 317 ; reduction of the grid 313 314 315 318 nvx = nvx[reduitindice2d] 319 nvy = nvy[reduitindice2d] 320 nvz = nvz[reduitindice2d] 316 321 ; 317 322 ; normalization 318 323 ; 319 320 324 normalise, nux, nuy, nuz 325 normalise, nvx, nvy, nvz 321 326 ; 322 327 ; Stage 1, c) … … 324 329 ; coordinates of the vector V in the cartesian reference 325 330 ; 326 327 328 331 direcx = zu*nux + zv*nvx 332 direcy = zu*nuy + zv*nvy 333 direcz = zu*nuz + zv*nvz 329 334 ; normalization of the vector V 330 335 normalise, direcx, direcy, direcz 331 336 ; on divide by 100 332 333 334 337 direcx = direcx/100. 338 direcy = direcy/100. 339 direcz = direcz/100. 335 340 ; 336 341 ; Stage 1, d) 337 342 ; coordinates of the point of the arrow in the cartesian reference. 338 343 339 340 341 344 x1 = x0 + direcx 345 y1 = y0 + direcy 346 z1 = z0 + direcz 342 347 343 348 ; coordinates of the point of the arrow in spherical coordinates. 344 349 345 346 r = cv_coord(from_rect=coord_rect,/to_sphere,/degrees)347 348 350 coord_rect = transpose([ [x1[*]], [y1[*]], [z1[*]] ]) 351 r = cv_coord(from_rect = coord_rect, /to_sphere, /degrees) 352 glam1 = reform(r[0, *], nx, ny) 353 gphi1 = reform(r[1, *], nx, ny) 349 354 350 355 ; … … 355 360 ; we modify it 356 361 ; 357 358 359 360 361 362 363 364 365 362 ind = where(glam1 LT !x.range[0] AND glam1+360. LE !x.range[1]) 363 if ind[0] NE -1 then glam1[ind] = glam1[ind]+360. 364 ind = where(glam1 GT !x.range[1] AND glam1-360. GE !x.range[0]) 365 if ind[0] NE -1 then glam1[ind] = glam1[ind]-360. 366 367 ind = where(glam LT !x.range[0] AND glam+360. LE !x.range[1]) 368 if ind[0] NE -1 then glam[ind] = glam[ind]+360. 369 ind = where(glam GT !x.range[1] AND glam-360. GE !x.range[0]) 370 if ind[0] NE -1 then glam[ind] = glam[ind]-360. 366 371 ; 367 372 ; 368 373 ; Stage 1, e) 369 374 ; 370 r = convert_coord(glam,gphi,/data,/to_normal)371 x0 = r[0, *]; normal coordinates of the beginning of the array.372 y0 = r[1, *];373 374 r = convert_coord(glam1,gphi1,/data,/to_normal)375 x1 = r[0, *]; normal coordinates of the ending of the array (Before scaling).376 y1 = r[1, *];375 r = convert_coord(glam, gphi, /data, /to_normal) 376 x0 = r[0, *] ; normal coordinates of the beginning of the array. 377 y0 = r[1, *] ; 378 379 r = convert_coord(glam1, gphi1, /data, /to_normal) 380 x1 = r[0, *] ; normal coordinates of the ending of the array (Before scaling). 381 y1 = r[1, *] ; 377 382 ; 378 383 ; tests to avoid that arrows be drawing out of the domain. 379 384 ; 380 381 382 385 out = where(x0 LT !p.position[0] OR x0 GT !p.position[2] $ 386 OR y0 LT !p.position[1] OR y0 GT !p.position[3]) 387 if out[0] NE -1 THEN x0[out] = !values.f_nan 383 388 ; 384 389 ; Following projections, there may are points at NaN when we pass in normal coordinates. 385 390 ; We delete these points. 386 391 ; 387 nan = finite(x0*y0*x1*y1) 388 number = where(nan EQ 1) 389 x0 = x0[number] & x1 = x1[number] 390 y0 = y0[number] & y1 = y1[number] 391 msk = msk[number] 392 norme = norme[number] 393 ; 392 nan = finite(x0*y0*x1*y1) 393 number = where(nan EQ 1) 394 x0 = x0[number] & x1 = x1[number] 395 y0 = y0[number] & y1 = y1[number] 396 msk = msk[number] 397 norme = norme[number] 398 ; 399 points = where(msk EQ 1) 400 IF points[0] NE -1 THEN BEGIN 401 402 x0 = x0[points] & x1 = x1[points] 403 y0 = y0[points] & y1 = y1[points] 404 msk = msk[points] 405 norme = norme[points] 406 394 407 ; We define the vector direction in the normalize reference. 395 408 ; 396 dirx = x1-x0397 diry = y1-y0409 dirx = x1-x0 410 diry = y1-y0 398 411 ; 399 412 ;We pass in polar coordinates to recuperate the angle which wasb the goal of all the first stage!!! 400 413 ; 401 402 dirpol = cv_coord(from_rect = transpose([ [dirx[*]], [diry[*]] ]), /to_polar) 403 dirpol = msk*dirpol[0, *] 414 dirpol = cv_coord(from_rect = transpose([ [dirx[*]], [diry[*]] ]), /to_polar) 415 dirpol = msk*dirpol[0, *] 404 416 ; 405 417 ; Stage 2 … … 409 421 ; Automatic putting at the scale 410 422 ; 411 if NOT keyword_set(cmref) then BEGIN423 if NOT keyword_set(cmref) then BEGIN 412 424 mipgsz = min(page_size, max = mapgsz) 413 425 sizexfeuille = mipgsz*key_portrait+mapgsz*(1-key_portrait) … … 415 427 cmref = 5 > floor(sizexfeuille/10.) < 15 416 428 cmref = cmref/10. 417 ENDIF418 if NOT keyword_set(normeref) then BEGIN429 ENDIF 430 if NOT keyword_set(normeref) then BEGIN 419 431 value = max(norme) 420 432 puissance10 = 10.^floor(alog10(value)) 421 433 normeref = puissance10*floor(value/puissance10) 422 endif423 cm = 1.*normeref/cmref434 endif 435 cm = 1.*normeref/cmref 424 436 ; 425 437 ; We modify the array norme to an element having the value cm be represented 426 ; by a trait of lenght 1 cm on the paper. Norme contain the normeof vectors438 ; by a line of lenght 1 cm on the paper. Norme contains the norm of vectors 427 439 ; we want to draw. 428 440 ; 429 norme = 1/(1.*cm)*norme*cv_cm2normal(dirpol) 430 ; 441 ; define colors before norme is changed... 442 IF NOT KEYWORD_SET(vectcolor) THEN vectcolor = 0 443 IF keyword_set(vectnormcolor) THEN BEGIN 444 mp = projsegment([vectnormcolor], [1, 254], /mp) 445 colors = byte(round(mp[0] * norme + mp[1] )) 446 ENDIF ELSE colors = byte(vectcolor) 447 ; 448 norme = 1/(1.*cm)*norme*cv_cm2normal(dirpol) 431 449 ; 432 450 ; Stage 3 433 ; Now that we have the angle and the norm e, we recuperate coordinates in451 ; Now that we have the angle and the norm, we recuperate coordinates in 434 452 ; rectangular and we draw arrows. 435 453 ; 436 r = cv_coord(from_polar = transpose([ [dirpol[*]], [norme[*]] ]), /to_rect)437 composantex = r[0, *]438 composantey = r[1, *]439 ; 440 x1 = x0+composantex441 y1 = y0+composantey454 r = cv_coord(from_polar = transpose([ [dirpol[*]], [norme[*]] ]), /to_rect) 455 composantex = r[0, *] 456 composantey = r[1, *] 457 ; 458 x1 = x0+composantex 459 y1 = y0+composantey 442 460 ; 443 461 ; Drawing 444 462 ; 445 if NOT KEYWORD_SET(vectcolor) then vectcolor = 0 446 447 points = where(msk EQ 1) 448 IF points[0] NE -1 THEN arrow, x0[points], y0[points], x1[points], y1[points], /norm $ 449 , hsize = -.2, COLOR = vectcolor, THICK = vectthick 463 points = where(msk EQ 1) 464 IF n_elements(colors) GT 1 THEN BEGIN 465 FOR i = 0, n_elements(colors)-1 DO arrow, x0[i], y0[i], x1[i], y1[i], /norm, hsize = -.2, COLOR = colors[i], THICK = vectthick 466 ENDIF ELSE arrow, x0, y0, x1, y1, /norm, hsize = -.2, COLOR = colors, THICK = vectthick 450 467 ; 451 468 ; Draw an arrow at the right bottom of the drawing as a caption. 452 469 ; 453 if NOT keyword_set(novectref) then BEGIN470 if NOT keyword_set(novectref) then BEGIN 454 471 dx = cmref*cv_cm2normal(0) ; Length of the vector of reference in normalized coordinates. 455 472 if keyword_set(vectrefformat) then $ 456 normelegende = strtrim(string(normeref, format = vectrefformat), 1)+' ' $473 normelegende = strtrim(string(normeref, format = vectrefformat), 1)+' ' $ 457 474 ELSE normelegende = strtrim(normeref, 1)+' ' 458 475 ; 459 476 if keyword_set(vectrefpos) then begin 460 r = convert_coord(vectrefpos,/data, /to_normal)461 462 477 r = convert_coord(vectrefpos, /data, /to_normal) 478 x0 = r[0] 479 y0 = r[1] 463 480 ENDIF ELSE BEGIN 464 465 466 467 481 x0 = !x.window[1]-dx 482 r = convert_coord(!d.x_ch_size, !d.y_ch_size, /device, /to_normal) 483 dy = 3*r[1]*!p.charsize 484 y0 = !y.window[0]-dy 468 485 ENDELSE 469 486 … … 471 488 xyouts, x0, y0, normelegende, /norm, align = 1, charsize = !p.charsize, color = 0 472 489 473 endif 474 ; 475 ; 476 477 if keyword_set(key_performance) NE 0 THEN print, 'temps vecteur', systime(1)-tempsun 490 endif 491 endif 492 ; 493 ; 494 495 if keyword_set(key_performance) NE 0 THEN print, 'temps vecteur', systime(1)-tempsun 478 496 ;------------------------------------------------------------ 479 497 ;------------------------------------------------------------ 480 498 return 481 499 END 482 500
Note: See TracChangeset
for help on using the changeset viewer.