source: trunk/procs/maskread.pro @ 205

Last change on this file since 205 was 205, checked in by pinsard, 14 years ago

homegenize THEN BEGIN ... ENDIF

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1;+
2;
3; lit un fichier bathymetry ORCA ou un mask atmos
4;
5; @categories
6; lecture de fichier
7;
8; @param BATHY {in}{required}{type=string}
9; part of bathymetry file
10;
11; @param MODEL {in}{required}{type=string}
12; part of bathymetry file ++ or grid type ?
13;
14; @keyword D3
15;
16; @returns
17; -1 in case of error
18;
19; @examples
20;
21; To read bathymetry of pacific for ORCA (model/grid?) file :
22; IDL> bathy='pacific'
23; IDL> model='orca'
24; IDL> result=maskread(bathy, model)
25; IDL> print, result
26; ++
27;    Reading orca.pacific mask
28;
29; % Subscript range values of the form low:high must be >= 0, < size, with low <= high: ZBAT.
30;
31;
32; To check good errors handling : ++
33; IDL> bathy='ginette'
34; IDL> model='arthur'
35; IDL> result=maskread(bathy, model)
36; IDL> print, result
37;
38; @uses
39; <pro>common</pro>
40; <propost_it>com_eg</propost_it>
41;
42; <propost_it>mask_z</propost_it>
43;
44; @todo
45; error handling
46;
47; make realistic example work !
48;
49; @history
50;
51; - fplod 20091210T103244Z aedon.locean-ipsl.upmc.fr (Darwin)
52;
53;   * check parameters
54;
55; - Maurice Imbard (mimlod\@ipsl.jussieu.fr) 12/05/99
56;
57; @version
58; $Id$
59;
60;-
61FUNCTION maskread, bathy, model $
62         , D3=d3
63;
64  compile_opt idl2, strictarrsubs
65;
66@common
67@com_eg
68;
69; Return to caller if errors
70 ON_ERROR, 2
71;
72 usage='result=maskread( bathy, model, D3=d3)'
73;
74 nparam = N_PARAMS()
75 IF (nparam LT 2) THEN BEGIN
76    ras = report(['Incorrect number of arguments.' $
77          + '!C' $
78          + 'Usage : ' + usage])
79    return, -1
80 ENDIF
81
82 arg_type = size(bathy,/type)
83 IF (arg_type NE 7) THEN BEGIN
84   ras = report(['Incorrect arg type bathy' $
85          + '!C' $
86          + 'Usage : ' + usage])
87    return, -1
88 ENDIF
89
90 arg_type = size(model,/type)
91 IF (arg_type NE 7) THEN BEGIN
92   ras = report(['Incorrect arg type model' $
93          + '!C' $
94          + 'Usage : ' + usage])
95    return, -1
96 ENDIF
97
98   IF n_elements(nbathys) EQ 0 THEN BEGIN
99      read_bathy = 'yes'
100   ENDIF ELSE BEGIN
101      i = 0
102      WHILE i LE nbathys-1 DO BEGIN
103         IF bathy_read[i].name EQ bathy THEN BEGIN
104            zbat = bathy_read[i].mask
105            IF keyword_set(D3) THEN BEGIN
106               zbat = 0 > zbat
107               ; Build 3D from pseudo 3D
108               zbat=reform(zbat[*]#(1./(indgen(jpkglo)+1)),(size(zbat))[1],(size(zbat))[2],jpkglo)
109               zbat=floor(zbat)<1
110            ENDIF ELSE BEGIN
111               zbat = zbat <  1
112            ENDELSE
113            return, zbat
114         ENDIF ELSE BEGIN
115            read_bathy = 'yes'
116         ENDELSE
117         i = i+1
118      ENDWHILE
119   ENDELSE
120
121   IF read_bathy EQ 'yes' THEN BEGIN
122      z = -1
123;;
124;---------------------------------------------------------------------
125; definition de la taille du fichier a aller chercher: jpidta,jpjdta,jpkdta...
126;---------------------------------------------------------------------
127      if n_elements(jpidta) EQ 0 THEN BEGIN
128         if n_elements(ixmindta) EQ 0 OR n_elements(ixmaxdta) EQ 0 THEN BEGIN
129          jpidta = jpiglo
130         ENDIF ELSE BEGIN
131          jpidta = ixmaxdta-ixmindta+1
132         ENDELSE
133      endif
134      if n_elements(jpjdta) EQ 0 THEN BEGIN
135         if n_elements(iymindta) EQ 0 OR n_elements(iymaxdta) EQ 0 THEN BEGIN
136          jpjdta = jpjgloo
137         ENDIF ELSE BEGIN
138          jpjdta = iymaxdta-iymindta+1
139         ENDELSE
140      endif
141      if n_elements(jpkdta) EQ 0 THEN BEGIN
142         if n_elements(izmindta) EQ 0 OR n_elements(izmaxdta) EQ 0 THEN BEGIN
143          jpkdta = jpkglo
144         ENDIF ELSE BEGIN
145          jpkdta = izmaxdta-izmindta+1
146         ENDELSE
147      endif
148;--------------------------------------------------------------------
149; ouverture du fichier a l'adresse s_fichier
150;--------------------------------------------------------------------
151;;
152      iname = bathy
153      iname_file = hom_idl+'grids/'+model+'.'+iname
154      openr, iunit, /get_lun,iname_file
155      print, '    Reading ', model+'.'+iname, ' mask '
156      print, ' '
157;---------------------------------------------------------------------
158; lecture des champs directement vers le champ
159;---------------------------------------------------------------------
160      ifreq = 40
161      ifin = jpiglo/ifreq+1
162      irest = jpiglo-(ifin-1)*ifreq
163      zbati = intarr(ifreq)
164      zbati2 = intarr(irest)
165      ;;
166      zbat = intarr(jpiglo,jpjglo)
167;
168      readf, iunit, FORMAT = '(16x,2i8)', iim, ijm
169      readf, iunit, FORMAT = '(/)'
170      readf, iunit, FORMAT = '(/)'
171      il1 = 0
172      FOR jn = 1, ifin-1 DO BEGIN
173         readf, iunit, FORMAT = '(/)'
174         readf, iunit, FORMAT = '(/)'
175         il2 = min([ jpiglo-1, il1+ifreq-1] )
176         readf, iunit, FORMAT = '(/)'
177         readf, iunit, FORMAT = '(/)'
178         readf, iunit, FORMAT = '(/)'
179         il3 = il2-(jn-1)*ifreq
180         iformat = string('(', il3+2, 'i3)')
181         FOR jj = jpjglo-1, 0, -1  DO BEGIN
182            zbati[0:ifreq-1] = 0
183            readf, iunit, FORMAT = iformat, ij, zbati
184            zbat[il1:il2, jj] = zbati[0:il3]
185         END
186         il1 = il1 + ifreq
187      END
188      readf, iunit, FORMAT = '(/)'
189      readf, iunit, FORMAT = '(/)'
190      il2 = min([ jpiglo-1, il1+ifreq-1] )
191      readf, iunit, FORMAT = '(/)'
192      readf, iunit, FORMAT = '(/)'
193      readf, iunit, FORMAT = '(/)'
194      il3 = il2-(ifin-1)*ifreq
195      iformat = string('(', il3+2, 'i3)')
196      FOR jj = jpjglo-1, 0, -1  DO BEGIN
197         zbati2[0:irest-1] = 0
198         readf, iunit, FORMAT = iformat, ij, zbati2
199         zbat[il1:il2, jj] = zbati2[0:il3]
200      END
201      ;;
202;---------------------------------------------------------------------
203; on initialise les ixmindta, iymindta  au besoin
204;---------------------------------------------------------------------
205;;
206      ixmindta = 0
207      ixmaxdta = jpiglo-1
208      iymindta = 0
209      iymaxdta = jpjglo-1
210      izmindta = 0
211      izmaxdta = jpkglo-1
212;---------------------------------------------------------------------
213; on reduit z selon les valeurs de ixmindta, iymindta, ...+ shift
214;---------------------------------------------------------------------
215      z = zbat[ixminmesh-ixmindta:ixmaxmesh-ixmindta $
216               ,iyminmesh-iymindta:iymaxmesh-iymindta ]
217      z = shift(z,key_shift, 0)
218;---------------------------------------------------------------------
219      IF n_elements(nbathys) EQ 0 THEN BEGIN
220         nbathys = 1
221         a = z*0
222         bathy_read = {name: '', mask:a}
223         bathy_read = replicate(bathy_read, 4)
224         bathy_read[0].name = bathy
225         bathy_read[0].mask = z
226      ENDIF ELSE BEGIN
227         IF nbathys LE 3 THEN BEGIN
228            nbathys = nbathys + 1
229         ENDIF ELSE BEGIN
230            nbathys = 1
231         ENDELSE
232         bathy_read[nbathys-1].name = bathy
233         bathy_read[nbathys-1].mask = z
234      ENDELSE
235
236;---------------------------------------------------------------------
237fini:
238      free_lun,iunit
239      close, iunit
240;---------------------------------------------------------------------
241sortie:
242      zbat = z
243      IF keyword_set(D3) THEN BEGIN
244         zbat = 0 > zbat
245         ; Build 3D from pseudo 3D
246         zbat=reform(zbat[*]#(1./(indgen(jpkglo)+1)),(size(zbat))[1],(size(zbat))[2], jpkglo)
247         zbat=floor(zbat)<1
248      ENDIF ELSE BEGIN
249         zbat = zbat <  1
250      ENDELSE
251      return, zbat
252   ENDIF
253END
Note: See TracBrowser for help on using the repository browser.