source: trunk/ToBeReviewed/UTILITAIRE/fitintobox.pro @ 11

Last change on this file since 11 was 11, checked in by pinsard, 18 years ago

upgrade of UTILITAIRE/Utilities according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 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  IF n_elements(sz EQ 1) THEN $
56    RETURN, report(['Error: ' $
57                  , 'the vector size (' + tostr(sz) + ') is incompatible' $
58                  , 'with the the domain dimensions ' $
59                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
60                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
61                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
62                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
63                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
64  RETURN, report(['Error: ' $
65                  , 'the array dimensions ' + tostr(sz) + ' are incompatible' $
66                  , 'with the the domain dimensions ' $
67                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
68                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
69                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
70                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
71                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
72END
73;------------------------------------------------------------
74FUNCTION fitintobox, field, nx, ny, nz, firstx, firsty $
75                     , firstz, lastx, lasty, lastz, WDEPTH = wdepth
76;------------------------------------------------------------
77; include commons
78@cm_4mesh
79@cm_4cal
80  IF NOT keyword_set(key_forgetold) THEN BEGIN
81@updatenew
82  ENDIF
83;---------------------
84  arr = litchamp(field)
85  IF n_params() EQ 1 THEN grille, -1, -1, -1, -1, nx, ny, nz $
86    , firstx, firsty, firstz, lastx, lasty, lastz, WDEPTH = wdepth
87;--------------------------------------------------------------
88;--------------------------------------------------------------
89; case according the number of dimensions of the array
90;--------------------------------------------------------------
91;--------------------------------------------------------------
92  sz = size(arr)
93  case sz[0] of
94;--------------------------------------------------------------
95    0:BEGIN                     ; scalar
96;--------------------------------------------------------------
97      return, report('Error: scalar value = ' + strtrim(arr, 1), /simple)
98    END
99;--------------------------------------------------------------
100    1:BEGIN                     ; 1D arrays
101;--------------------------------------------------------------
102      CASE 1 OF
103; x arrays
104        sz[1] EQ jpi                                                   :arr = (temporary(arr))[firstx:lastx                               ]
105        sz[1] EQ  nx                                                   :                                                     
106; y arrays
107        sz[1] EQ jpj                                                   :arr = (temporary(arr))[              firsty:lasty                 ]
108        sz[1] EQ  ny                                                   :                                                     
109; z arrays
110        sz[1] EQ jpk                                                   :arr = (temporary(arr))[                            firstz:lastz   ]
111        sz[1] EQ  nz                                                   :                                                     
112; t arrays
113        sz[1] EQ jpt                                                   :
114        ELSE:return, err_mess(sz[1], jpi, nx, jpj, ny, jpk, nz, jpt)
115      ENDCASE
116    END
117;--------------------------------------------------------------
118    2:BEGIN                     ; 2D arrays
119;--------------------------------------------------------------
120      CASE 1 OF
121; xy arrays
122        sz[1] EQ jpi AND sz[2] EQ jpj                                  :arr = (temporary(arr))[firstx:lastx, firsty:lasty                 ]
123        sz[1] EQ jpi AND sz[2] EQ  ny                                  :arr = (temporary(arr))[firstx:lastx,            *                 ]
124        sz[1] EQ  nx AND sz[2] EQ jpj                                  :arr = (temporary(arr))[           *, firsty:lasty                 ]
125        sz[1] EQ  nx AND sz[2] EQ  ny                                  :arr = (temporary(arr))[           *,            *                 ]
126; x(y)z arrays
127        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ jpk                 :arr = (temporary(arr))[firstx:lastx, firstz:lastz   ]
128        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ  nz                 :arr = (temporary(arr))[firstx:lastx,            *   ]
129        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ jpk                 :arr = (temporary(arr))[           *, firstz:lastz   ]
130        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ  nz                 :
131; (x)yz arrays
132        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ jpk                 :arr = (temporary(arr))[              firsty:lasty, firstz:lastz   ]
133        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ  nz                 :arr = (temporary(arr))[              firsty:lasty,            *   ]
134        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ jpk                 :arr = (temporary(arr))[                         *, firstz:lastz   ]
135        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ  nz                 :
136; xt arrays
137        sz[1] EQ jpi                                   AND sz[2] EQ jpt:arr = (temporary(arr))[firstx:lastx                            , *]
138        sz[1] EQ  nx                                   AND sz[2] EQ jpt:
139; yt arrays
140                         sz[1] EQ jpj                  AND sz[2] EQ jpt:arr = (temporary(arr))[              firsty:lasty              , *]
141                         sz[1] EQ  ny                  AND sz[2] EQ jpt:
142; zt arrays
143                                          sz[1] EQ jpk AND sz[2] EQ jpt:arr = (temporary(arr))[                            firstz:lastz, *]
144                                          sz[1] EQ  nz AND sz[2] EQ jpt:
145        ELSE:return, err_mess(sz[1:2], jpi, nx, jpj, ny, jpk, nz, jpt)
146      ENDCASE
147    END
148;--------------------------------------------------------------
149    3:BEGIN                     ; 3D arrays
150;--------------------------------------------------------------
151      CASE 1 OF
152; xyz arrays
153        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ jpk                 :arr = (temporary(arr))[firstx:lastx, firsty:lasty, firstz:lastz   ]
154        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ jpk                 :arr = (temporary(arr))[firstx:lastx,            *, firstz:lastz   ]
155        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ jpk                 :arr = (temporary(arr))[           *, firsty:lasty, firstz:lastz   ]
156        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ jpk                 :arr = (temporary(arr))[           *,            *, firstz:lastz   ]
157        sz[1] EQ jpi AND sz[2] EQ jpj AND sz[3] EQ  nz                 :arr = (temporary(arr))[firstx:lastx, firsty:lasty,            *   ]
158        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ  nz                 :arr = (temporary(arr))[firstx:lastx,            *,            *   ]
159        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ  nz                 :arr = (temporary(arr))[           *, firsty:lasty,            *   ]
160        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ  nz                 :
161; xyt arrays
162        sz[1] EQ jpi AND sz[2] EQ jpj                  AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx, firsty:lasty,               *]
163        sz[1] EQ jpi AND sz[2] EQ  ny                  AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx,            *,               *]
164        sz[1] EQ  nx AND sz[2] EQ jpj                  AND sz[3] EQ jpt:arr = (temporary(arr))[           *, firsty:lasty,               *]
165        sz[1] EQ  nx AND sz[2] EQ  ny                  AND sz[3] EQ jpt:
166; (x)yzt arrays
167        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, *]
168        nx EQ 1      AND sz[1] EQ jpj AND sz[2] EQ  nz AND sz[3] EQ jpt:arr = (temporary(arr))[              firsty:lasty,            *, *]
169        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[                         *, firstz:lastz, *]
170        nx EQ 1      AND sz[1] EQ  ny AND sz[2] EQ  nz AND sz[3] EQ jpt:
171; x(y)zt arrays
172        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, *]
173        sz[1] EQ jpi AND ny EQ 1      AND sz[2] EQ  nz AND sz[3] EQ jpt:arr = (temporary(arr))[firstx:lastx,                          *, *]
174        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ jpk AND sz[3] EQ jpt:arr = (temporary(arr))[           *,               firstz:lastz, *]
175        sz[1] EQ  nx AND ny EQ 1      AND sz[2] EQ  nz AND sz[3] EQ jpt:
176        ELSE:return, err_mess(sz[1:3], jpi, nx, jpj, ny, jpk, nz, jpt)
177      ENDCASE
178    END
179;--------------------------------------------------------------
180    4:BEGIN                     ; 4D arrays
181;--------------------------------------------------------------
182      CASE 1 OF
183; xyzt arrays
184        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, *]
185        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, *]
186        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, *]
187        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ jpk AND sz[4] EQ jpt:arr = (temporary(arr))[           *,            *, firstz:lastz, *]
188        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,            *, *]
189        sz[1] EQ jpi AND sz[2] EQ  ny AND sz[3] EQ  nz AND sz[4] EQ jpt:arr = (temporary(arr))[firstx:lastx,            *,            *, *]
190        sz[1] EQ  nx AND sz[2] EQ jpj AND sz[3] EQ  nz AND sz[4] EQ jpt:arr = (temporary(arr))[           *, firsty:lasty,            *, *]
191        sz[1] EQ  nx AND sz[2] EQ  ny AND sz[3] EQ  nz AND sz[4] EQ jpt:
192        ELSE:return, err_mess(sz[1:4], jpi, nx, jpj, ny, jpk, nz, jpt)
193      ENDCASE
194    END
195    ELSE:return, report('Error: fitintobox is managing arrays with a maximum of 4 dimensions', /simple)
196  ENDCASE
197
198  return, arr
199end
Note: See TracBrowser for help on using the repository browser.