source: trunk/SRC/Computation/bsf.pro @ 445

Last change on this file since 445 was 445, checked in by smasson, 13 years ago

improve the implementation of the partial steps + bugfix in bsf

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1;+
2;
3; @file_comments
4; compute the barotropic (along the model grid) stream function in Sv using
5; the following equation: total(total(e2u*e3u*un),3), 2, /cumulative)/1.e6
6;
7; @categories
8; diagnostics
9;
10; @param z3d {in} {type=3D xyz array}
11; zonal velocity
12;
13; @keyword NOSTRUCTURE {default=0}{type=scalar: 0 or 1}
14; activate if you do not want that msf returns a structure
15; but only the array referring to the field.
16;
17; @keyword REFPOINT {type=2 element vector}
18; a 2 element vector [x,y] giving the (approximative) position of the
19; point that should be taken as a reference. This position should be
20; given with the same coordinates system as the one used in
21; glam/gphi. see example
22;
23; @keyword REFVALUE {type=scalar} {default=0.}
24; the bsf value that we want to speficy at the position defined by refpoint
25;
26; @returns {type=2D xy array}
27; barotropic stream function in Sv
28;
29; @uses
30; <pro>cm_4mesh</pro>
31; <pro>cm_4data</pro>
32; <pro>grille</pro>
33; <pro>litchamp</pro>
34; <pro>fitintobox</pro>
35;
36; @restrictions
37; - T and U boxzoom parameters must be the same
38; - to be valid, mask must be equal to 0 at the bottom and on each
39;   side of the domain along x direction
40; - define the common variables (of cm_4data)
41;       varname = 'BSF'
42;       varunit = 'Sv'
43;       vargrid = 'F'
44;
45; @examples
46;
47;   IDL> initorca05
48;   IDL> file = '/Volumes/pim/F31/oce/1y/F31_1y_0040_0040_grid_U.nc'
49;   IDL> un = read_ncdf('vozocrtx', 0, 0, /timestep, file = file)
50;   IDL> bar = bsf(un, refvalue = 0., refpoint = [0, 20])
51;   IDL> plt, bar, -150, 150, int = 10, style = 'so0so', format = '(i4)', lct = 64
52;
53; @history
54; Gurvan Madec, Christian Ethe, Claude Talandier and Sebastien Masson, Dec 2008
55;
56; @version
57; $Id$
58;
59;-
60;
61FUNCTION bsf, z3d, NOSTRUCTURE = nostructure, REFPOINT = refpoint, REFVALUE = refvalue
62;
63  compile_opt idl2, strictarrsubs
64;
65@cm_4mesh
66@cm_4data
67;
68  CASE 1 OF
69    firstxt NE firstxu OR lastxt NE lastxu: return, report('T and U box must be defined over the same x indexes, use /memeindices when calling domdef')
70    firstyt NE firstyu OR lastyt NE lastyu: return, report('T and U box must be defined over the same y indexes, use /memeindices when calling domdef')
71    ELSE:
72  ENDCASE
73;
74  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz, grid = 'T'
75  umsk = (umask())[firstx:lastx, firsty:lasty, firstz:lastz]
76  IF total(umsk[*, *, nz-1]) NE 0 THEN return, report('The bottom of the box (defined by lastzt) must be set to land value (=0)')
77  IF total(umsk[*, 0, *]) NE 0 THEN return, report('southern boudary must be land point if you want to compute the bsf with this function')
78;
79  un = litchamp(z3d)
80  IF size(un, /n_dimensions) NE 3 THEN return, report('input data must be a 3D array')
81  un = fitintobox(temporary(un))
82;
83  e23 = e3u_3d(/e2)
84;
85; mask the array
86  un = temporary(umsk) * temporary(un)
87; compute the bsf
88  bsf = 1.e-6 * total(total(temporary(un) * temporary(e23), 3), 2, /cumulative)
89; set bsf to 0 in the largest continent... no done...
90  IF keyword_set(refpoint) THEN BEGIN
91    refind = neighbor(refpoint[0], refpoint[1], glamf[firstx:lastx, firsty:lasty], gphif[firstx:lastx, firsty:lasty], SPHERE = key_onearth)
92    IF n_elements(refvalue) EQ 0 THEN refval = - bsf[refind[0]] ELSE refval = refvalue - bsf[refind[0]]
93    bsf = temporary(bsf) + refval
94  ENDIF
95  IF keyword_set(flagdata) THEN bsf[nx-1, *] = !values.f_nan
96;
97; update data informations
98  varname = 'BSF'
99  varunit = 'Sv'
100  vargrid = 'F'
101;
102  IF keyword_set(nostructure) THEN return, bsf
103
104  IF keyword_set(key_forgetold) THEN BEGIN
105    return, {arr:temporary(bsf), grid:vargrid, unit:varunit, experiment:varexp, name:varname}
106  ENDIF ELSE BEGIN
107    return, {tab:temporary(bsf), grille:vargrid, unite:varunit, experience:varexp, nom:varname}
108  ENDELSE
109
110END
Note: See TracBrowser for help on using the repository browser.