- Timestamp:
- 03/28/08 17:05:12 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ReadWrite/ncdf_getmask.pro
r327 r341 27 27 ; 28 28 ; @keyword MISSING_VALUE {type=scalar} 29 ; To define (or redefine if the attribute is 30 ; already existing) the missing values used with USEASMASK31 ; keyword29 ; To define (or redefine if the attribute is already existing) the 30 ; missing values used with USEASMASK keyword. Note that this value is 31 ; not used if TESTOP keyword is given and contains 2 words. 32 32 ; 33 33 ; @keyword USEASMASK {type=scalar string} … … 35 35 ; that will be used to build the land/sea mask. In this case the 36 36 ; mask is based on the first record (if record dimension 37 ; exists). The mask is build according to : 38 ; 1 the keyword missing_value if existing 39 ; 2 the attribute 'missing_value' if existing 40 ; 3 NaN values if existing 37 ; exists). The mask is build according to operator defined by TESTOP 38 ; keyword (default NE) and the testing values defined as 39 ; 1) the second word of TESTOP if existing 40 ; 2) MISSING_VALUE keyword 41 ; 3) attribute missing_value or _fillvalue of the variable USEASMASK 42 ; 4) !Values.f_nan (can be used only with NE and EQ operators) 43 ; 44 ; @keyword TESTOP {default='NE'} {type=scalar string, for example 'GT 0.5'} 45 ; a string describing the type of test that will be done to define the 46 ; mask. The test is performed on the variable specified by USEASMASK 47 ; keyword. 48 ; TESTOP can contain 1 or 2 words. The first word is the operator 49 ; definition: "EQ" "NE" "GE" "GT" "LE" "LT" (default is NE). The 50 ; second word define the testing value. If TESTOP contains only 1 51 ; word, then the test value is denifed by 52 ; 1) MISSING_VALUE keyword 53 ; 2) attribute missing_value or _fillvalue of the variable USEASMASK 54 ; 3) !Values.f_nan (can be used only with NE and EQ operators) 41 55 ; 42 56 ; @keyword … … 52 66 ; IDL> mask = ncdf_getmask('meshmaskORCA2.nc', maskname = 'tmask') 53 67 ; 68 ; IDL> mask = ncdf_getmask('t106.nc', useasmask = 'SLM', testop = 'le 0.5') 69 ; 54 70 ; @history 55 71 ; August 2007: Sebastien Masson (smasson\@lodyc.jussieu.fr) … … 59 75 ; 60 76 ;- 61 FUNCTION ncdf_getmask, fileid, ADDSCL_BEFORE =addscl_before $62 , MASKNAME=maskname, USEASMASK=useasmask $63 , MISSING_VALUE=missing_value, INVMASK=invmask $64 , _EXTRA=ex77 FUNCTION ncdf_getmask, fileid, ADDSCL_BEFORE = addscl_before $ 78 , MASKNAME = maskname, USEASMASK = useasmask $ 79 , MISSING_VALUE = missing_value, INVMASK = invmask $ 80 , TESTOP = testop, _EXTRA = ex 65 81 ; 66 82 compile_opt idl2, strictarrsubs … … 102 118 ncdf_varget, cdfid, mskid, mask, count = count 103 119 ENDIF ELSE ncdf_varget, cdfid, mskid, mask 104 ; check if we need to applay add_offset and scale factor 120 121 ; get add_offset, scale factor and missing value attributes 105 122 ncdf_getatt, cdfid, mskid, add_offset = add, scale_factor = scl, missing_value = miss 106 IF n_elements(missing_value) NE 0 THEN miss = missing_value 107 123 ; do we apply add_offset and scale factor ? 108 124 IF keyword_set(addscl_before) THEN BEGIN 109 125 IF scl NE 1 THEN mask = mask * scl … … 112 128 113 129 IF keyword_set(useasmask) THEN BEGIN 114 IF n_elements(miss) NE 0 THEN BEGIN 130 131 IF n_elements(missing_value) NE 0 THEN miss = missing_value 132 IF size(miss, /type) EQ 7 THEN miss = !values.f_nan 133 134 IF NOT keyword_set(testop) THEN testop = 'NE' 135 tmp = strsplit(testop, ' ', /extract) 136 op = strupcase(tmp[0]) 137 IF op EQ 'EQ' THEN BEGIN 138 op = 'NE' 139 invmask = 1b - keyword_set(invmask) 140 ENDIF 141 IF n_elements(tmp) EQ 1 THEN testval = miss ELSE testval = float(tmp[1]) 142 IF finite(testval) EQ 0 THEN BEGIN 143 IF op NE 'NE' THEN mask = report('NaN test value can be used only with EQ or NE operator') ELSE mask = finite(mask) 144 ENDIF ELSE BEGIN 145 CASE op OF 146 'GE':mask = mask GE testval 147 'GT':mask = mask GT testval 148 'LE':mask = mask LE testval 149 'LT':mask = mask LT testval 150 'NE':BEGIN 115 151 ; we have to take care of the float accuracy 116 CASE 1 OF 117 miss GE 1.e6:mask = mask LT (miss-10) 118 miss LE -1.e6:mask = mask GT (miss+10) 119 abs(miss) LE 1.e-6:mask = abs(mask) GT 1.e-6 120 ELSE:mask = mask NE miss 152 CASE 1 OF 153 testval GE 1.e6:mask = mask LT (testval - 10) 154 testval LE -1.e6:mask = mask GT (testval + 10) 155 abs(testval) LE 1.e-6:mask = abs(mask) GT 1.e-6 156 ELSE:mask = mask NE testval 157 ENDCASE 158 END 121 159 ENDCASE 122 ENDIF ELSE BEGIN123 mask = finite(mask)124 IF min(mask) EQ 1 THEN BEGIN125 ras = report( 'missing or nan values not found...')126 mask = -1127 ENDIF128 160 ENDELSE 161 162 IF mask[0] NE -1 THEN BEGIN 163 mask = byte(round(mask)) 164 if keyword_set(invmask) then mask = 1b-mask 165 ENDIF 166 129 167 ENDIF 130 131 mask = byte(round(mask))132 if keyword_set(invmask) then mask = 1b-mask133 134 168 ENDIF ELSE mask = -1 135 169
Note: See TracChangeset
for help on using the changeset viewer.