source: trunk/SRC/ToBeReviewed/UTILITAIRE/fitintobox.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:fitintobox
6;
7; PURPOSE: check that the input array has size and dimensions
8; compatible with the domain that was defined with the previous call
9; of domdef.
10;
11; CATEGORY: domain compatibility
12;
13; CALLING SEQUENCE:
14;     res = fitintobox(field[, nx, ny, nz, firstx, firsty, firstz
15;                                        ,  lastx,  lasty,  lastz])
16;
17; INPUTS:
18;     field: an array or a structure that can be read by the function
19;     litchamp.pro
20;
21;     nx, ny, nz, firstx, firsty, firstz,  lastx,  lasty,  lastz:
22;     optional parameters. If not given they will be define with a
23;     call to the procedure grille.pro
24;     
25; KEYWORD PARAMETERS: none
26;
27; OUTPUTS: an array with dimensions matching the domain
28;          or -1 if there is an error...
29;
30; COMMON BLOCKS: cm_4mesh and cm_4cal
31;
32; SIDE EFFECTS:
33;
34; RESTRICTIONS:
35;
36; EXAMPLE:
37;
38;   IDL> help, fitintobox(findgen(jpi,jpj))
39;   <Expression>    FLOAT     = Array[41, 3]
40;   IDL> help, fitintobox(findgen(jpi,jpj,78))
41;   Error:
42;   the array dimensions [180,148,78] are incompatible
43;   with the the domain dimensions
44;   [jpi/nx, jpj/ny, jpk/nz, jpt] = [180/41, 148/3, 31/31, 1]
45;   <Expression>    INT       =       -1
46;
47; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
48;                     10 juin 2000.
49; June 2005: S. Masson rewrite all.
50;-
51;------------------------------------------------------------
52;------------------------------------------------------------
53;------------------------------------------------------------
54FUNCTION err_mess, sz, jpi, nx, jpj, ny, jpk, nz, jpt
55;
56  compile_opt idl2, strictarrsubs
57;
58  IF n_elements(sz EQ 1) THEN $
59    RETURN, report(['Error: ' $
60                  , 'the vector size (' + tostr(sz) + ') is incompatible' $
61                  , 'with the the domain dimensions ' $
62                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
63                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
64                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
65                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
66                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
67  RETURN, report(['Error: ' $
68                  , 'the array dimensions ' + tostr(sz) + ' are incompatible' $
69                  , 'with the the domain dimensions ' $
70                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
71                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
72                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
73                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
74                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
75END
76;------------------------------------------------------------
77FUNCTION fitintobox, field, nx, ny, nz, firstx, firsty $
78                     , firstz, lastx, lasty, lastz, WDEPTH = wdepth
79;------------------------------------------------------------
80; include commons
81;
82  compile_opt idl2, strictarrsubs
83;
84@cm_4mesh
85@cm_4cal
86  IF NOT keyword_set(key_forgetold) THEN BEGIN
87@updatenew
88  ENDIF
89;---------------------
90  arr = litchamp(field)
91  IF n_params() EQ 1 THEN grille, -1, -1, -1, -1, nx, ny, nz $
92    , firstx, firsty, firstz, lastx, lasty, lastz, WDEPTH = wdepth
93;--------------------------------------------------------------
94;--------------------------------------------------------------
95; case according the number of dimensions of the array
96;--------------------------------------------------------------
97;--------------------------------------------------------------
98  sz = size(arr)
99  case sz[0] of
100;--------------------------------------------------------------
101    0:BEGIN                     ; scalar
102;--------------------------------------------------------------
103      return, report('Error: scalar value = ' + strtrim(arr, 1), /simple)
104    END
105;--------------------------------------------------------------
106    1:BEGIN                     ; 1D arrays
107;--------------------------------------------------------------
108      CASE 1 OF
109; x arrays
110        sz[1] EQ jpi                                                   :arr = (temporary(arr))[firstx:lastx                               ]
111        sz[1] EQ  nx                                                   :                                                     
112; y arrays
113        sz[1] EQ jpj                                                   :arr = (temporary(arr))[              firsty:lasty                 ]
114        sz[1] EQ  ny                                                   :                                                     
115; z arrays
116        sz[1] EQ jpk                                                   :arr = (temporary(arr))[                            firstz:lastz   ]
117        sz[1] EQ  nz                                                   :                                                     
118; t arrays
119        sz[1] EQ jpt                                                   :
120        ELSE:return, err_mess(sz[1], jpi, nx, jpj, ny, jpk, nz, jpt)
121      ENDCASE
122    END
123;--------------------------------------------------------------
124    2:BEGIN                     ; 2D arrays
125;--------------------------------------------------------------
126      CASE 1 OF
127; xy arrays
128        sz[1] EQ jpi AND sz[2] EQ jpj                                  :arr = (temporary(arr))[firstx:lastx, firsty:lasty                 ]
129        sz[1] EQ jpi AND sz[2] EQ  ny                                  :arr = (temporary(arr))[firstx:lastx,            *                 ]
130        sz[1] EQ  nx AND sz[2] EQ jpj                                  :arr = (temporary(arr))[           *, firsty:lasty                 ]
131        sz[1] EQ  nx AND sz[2] EQ  ny                                  :arr = (temporary(arr))[           *,            *                 ]
132; x(y)z arrays
133        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ jpk                 :arr = (temporary(arr))[firstx:lastx, firstz:lastz   ]
134        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ  nz                 :arr = (temporary(arr))[firstx:lastx,            *   ]
135        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ jpk                 :arr = (temporary(arr))[           *, firstz:lastz   ]
136        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ  nz                 :
137; (x)yz arrays
138        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ jpk                 :arr = (temporary(arr))[              firsty:lasty, firstz:lastz   ]
139        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ  nz                 :arr = (temporary(arr))[              firsty:lasty,            *   ]
140        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ jpk                 :arr = (temporary(arr))[                         *, firstz:lastz   ]
141        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ  nz                 :
142; xt arrays
143        sz[1] EQ jpi                                   AND sz[2] EQ jpt:arr = (temporary(arr))[firstx:lastx                            , *]
144        sz[1] EQ  nx                                   AND sz[2] EQ jpt:
145; yt arrays
146                         sz[1] EQ jpj                  AND sz[2] EQ jpt:arr = (temporary(arr))[              firsty:lasty              , *]
147                         sz[1] EQ  ny                  AND sz[2] EQ jpt:
148; zt arrays
149                                          sz[1] EQ jpk AND sz[2] EQ jpt:arr = (temporary(arr))[                            firstz:lastz, *]
150                                          sz[1] EQ  nz AND sz[2] EQ jpt:
151        ELSE:return, err_mess(sz[1:2], jpi, nx, jpj, ny, jpk, nz, jpt)
152      ENDCASE
153    END
154;--------------------------------------------------------------
155    3:BEGIN                     ; 3D arrays
156;--------------------------------------------------------------
157      CASE 1 OF
158; xyz arrays
159        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ jpk                 :arr = (temporary(arr))[firstx:lastx, firsty:lasty, firstz:lastz   ]
160        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ jpk                 :arr = (temporary(arr))[firstx:lastx,            *, firstz:lastz   ]
161        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ jpk                 :arr = (temporary(arr))[           *, firsty:lasty, firstz:lastz   ]
162        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ jpk                 :arr = (temporary(arr))[           *,            *, firstz:lastz   ]
163        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ  nz                 :arr = (temporary(arr))[firstx:lastx, firsty:lasty,            *   ]
164        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ  nz                 :arr = (temporary(arr))[firstx:lastx,            *,            *   ]
165        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ  nz                 :arr = (temporary(arr))[           *, firsty:lasty,            *   ]
166        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ  nz                 :
167; xyt arrays
168        sz[1] EQ jpi AND sz[2] EQ jpj                  AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx, firsty:lasty,               *]
169        sz[1] EQ jpi AND sz[2] EQ  ny                  AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx,            *,               *]
170        sz[1] EQ  nx AND sz[2] EQ jpj                  AND sz[3] EQ jpt:arr = (temporary(arr))[           *, firsty:lasty,               *]
171        sz[1] EQ  nx AND sz[2] EQ  ny                  AND sz[3] EQ jpt:
172; (x)yzt arrays
173        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[              firsty:lasty, firstz:lastz, *]
174        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ  nz AND sz[3] EQ jpt:arr = (temporary(arr))[              firsty:lasty,            *, *]
175        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[                         *, firstz:lastz, *]
176        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ  nz AND sz[3] EQ jpt:
177; x(y)zt arrays
178        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx,               firstz:lastz, *]
179        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ  nz AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx,                          *, *]
180        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[           *,               firstz:lastz, *]
181        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ  nz AND sz[3] EQ jpt:
182        ELSE:return, err_mess(sz[1:3], jpi, nx, jpj, ny, jpk, nz, jpt)
183      ENDCASE
184    END
185;--------------------------------------------------------------
186    4:BEGIN                     ; 4D arrays
187;--------------------------------------------------------------
188      CASE 1 OF
189; xyzt arrays
190        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ jpk AND sz[4] EQ jpt:arr = (temporary(arr))[firstx:lastx, firsty:lasty, firstz:lastz, *]
191        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ jpk AND sz[4] EQ jpt:arr = (temporary(arr))[firstx:lastx,            *, firstz:lastz, *]
192        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ jpk AND sz[4] EQ jpt:arr = (temporary(arr))[           *, firsty:lasty, firstz:lastz, *]
193        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ jpk AND sz[4] EQ jpt:arr = (temporary(arr))[           *,            *, firstz:lastz, *]
194        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ  nz AND sz[4] EQ jpt:arr = (temporary(arr))[firstx:lastx, firsty:lasty,            *, *]
195        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ  nz AND sz[4] EQ jpt:arr = (temporary(arr))[firstx:lastx,            *,            *, *]
196        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ  nz AND sz[4] EQ jpt:arr = (temporary(arr))[           *, firsty:lasty,            *, *]
197        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ  nz AND sz[4] EQ jpt:
198        ELSE:return, err_mess(sz[1:4], jpi, nx, jpj, ny, jpk, nz, jpt)
199      ENDCASE
200    END
201    ELSE:return, report('Error: fitintobox is managing arrays with a maximum of 4 dimensions', /simple)
202  ENDCASE
203
204  return, arr
205end
Note: See TracBrowser for help on using the repository browser.