Changeset 1669 for LMDZ5/branches/testing/libf/bibio
- Timestamp:
- Oct 16, 2012, 2:41:50 PM (12 years ago)
- Location:
- LMDZ5/branches/testing
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
LMDZ5/branches/testing
- Property svn:mergeinfo changed
/LMDZ5/trunk merged: 1629-1633,1635,1637-1659,1666-1668
- Property svn:mergeinfo changed
-
LMDZ5/branches/testing/libf/bibio/netcdf95.F90
r1279 r1669 3 3 4 4 ! Author: Lionel GUEZ 5 6 ! Three criticisms may be made about the Fortran 90 NetCDF interface: 7 8 ! -- NetCDF procedures are usually functions with side effects. 9 ! First, they have "intent(out)" arguments. 10 ! Furthermore, there is obviously data transfer inside the procedures. 11 ! Any data transfer inside a function is considered as a side effect. 12 13 ! -- The caller of a NetCDF procedure usually has to handle the error 14 ! status. NetCDF procedures would be much friendlier if they behaved 15 ! like the Fortran input/output statements. That is, the error status 16 ! should be an optional output argument. 17 ! If the caller does not request the error status and there is an 18 ! error then the NetCDF procedure should produce an error message 19 ! and stop the program. 20 21 ! -- Some procedures use array arguments with assumed size. 22 ! It would be better to use the pointer attribute. 23 24 ! This module produces a NetCDF interface that answers those three 25 ! criticisms for some (not all) procedures. 26 27 ! "nf95_get_att" is more secure than "nf90_get_att" because it 28 ! checks that the "values" argument is long enough and removes the 29 ! null terminator, if any. 30 31 ! This module replaces some of the official NetCDF procedures. 32 ! This module also provides the procedures "handle_err" and "nf95_gw_var". 33 34 ! This module provides only a partial replacement for some generic 35 ! procedures such as "nf90_def_var". 5 ! See: 6 ! http://www.lmd.jussieu.fr/~lglmd/NetCDF95 36 7 37 8 use nf95_def_var_m 38 9 use nf95_put_var_m 10 use nf95_get_var_m 39 11 use nf95_gw_var_m 40 12 use nf95_put_att_m -
LMDZ5/branches/testing/libf/bibio/nf95_get_att_m.F90
r1279 r1669 1 1 ! $Id$ 2 2 module nf95_get_att_m 3 4 use handle_err_m, only: handle_err 5 use netcdf, only: nf90_get_att, nf90_noerr 6 use simple, only: nf95_inquire_attribute 3 7 4 8 implicit none 5 9 6 10 interface nf95_get_att 7 module procedure nf95_get_att_text 11 module procedure nf95_get_att_text, nf95_get_att_one_FourByteInt 12 13 ! The difference between the specific procedures is the type of 14 ! argument "values". 8 15 end interface 9 16 … … 15 22 subroutine nf95_get_att_text(ncid, varid, name, values, ncerr) 16 23 17 use netcdf, only: nf90_get_att, nf90_inquire_attribute, nf90_noerr18 use handle_err_m, only: handle_err19 20 24 integer, intent( in) :: ncid, varid 21 25 character(len = *), intent( in) :: name … … 23 27 integer, intent(out), optional:: ncerr 24 28 25 ! Variable local to the procedure:29 ! Variables local to the procedure: 26 30 integer ncerr_not_opt 27 31 integer att_len … … 30 34 31 35 ! Check that the length of "values" is large enough: 32 ncerr_not_opt = nf90_inquire_attribute(ncid, varid, name, len=att_len) 33 call handle_err("nf95_get_att_text nf90_inquire_attribute " & 34 // trim(name), ncerr_not_opt, ncid, varid) 35 if (len(values) < att_len) then 36 print *, "nf95_get_att_text" 37 print *, "varid = ", varid 38 print *, "attribute name: ", name 39 print *, 'length of "values" is not large enough' 40 print *, "len(values) = ", len(values) 41 print *, "number of characters in attribute: ", att_len 42 stop 1 36 call nf95_inquire_attribute(ncid, varid, name, nclen=att_len, & 37 ncerr=ncerr_not_opt) 38 if (ncerr_not_opt == nf90_noerr) then 39 if (len(values) < att_len) then 40 print *, "nf95_get_att_text" 41 print *, "varid = ", varid 42 print *, "attribute name: ", name 43 print *, 'length of "values" is not large enough' 44 print *, "len(values) = ", len(values) 45 print *, "number of characters in attribute: ", att_len 46 stop 1 47 end if 43 48 end if 44 49 … … 48 53 ncerr = ncerr_not_opt 49 54 else 50 call handle_err("nf95_get_att_text", ncerr_not_opt, ncid, varid) 55 call handle_err("nf95_get_att_text " // trim(name), ncerr_not_opt, & 56 ncid, varid) 51 57 end if 52 58 … … 58 64 end subroutine nf95_get_att_text 59 65 66 !*********************** 67 68 subroutine nf95_get_att_one_FourByteInt(ncid, varid, name, values, ncerr) 69 70 integer, intent( in) :: ncid, varid 71 character(len = *), intent( in) :: name 72 integer , intent(out) :: values 73 integer, intent(out), optional:: ncerr 74 75 ! Variables local to the procedure: 76 integer ncerr_not_opt 77 integer att_len 78 79 !------------------- 80 81 ! Check that the attribute contains a single value: 82 call nf95_inquire_attribute(ncid, varid, name, nclen=att_len, & 83 ncerr=ncerr_not_opt) 84 if (ncerr_not_opt == nf90_noerr) then 85 if (att_len /= 1) then 86 print *, "nf95_get_att_one_FourByteInt" 87 print *, "varid = ", varid 88 print *, "attribute name: ", name 89 print *, 'the attribute does not contain a single value' 90 print *, "number of values in attribute: ", att_len 91 stop 1 92 end if 93 end if 94 95 ncerr_not_opt = nf90_get_att(ncid, varid, name, values) 96 if (present(ncerr)) then 97 ncerr = ncerr_not_opt 98 else 99 call handle_err("nf95_get_att_one_FourByteInt " // trim(name), & 100 ncerr_not_opt, ncid, varid) 101 end if 102 103 end subroutine nf95_get_att_one_FourByteInt 104 60 105 end module nf95_get_att_m -
LMDZ5/branches/testing/libf/bibio/nf95_gw_var_m.F90
r1279 r1669 1 1 ! $Id$ 2 2 module nf95_gw_var_m 3 4 use nf95_get_var_m, only: NF95_GET_VAR 5 use simple, only: nf95_inquire_variable, nf95_inquire_dimension 3 6 4 7 implicit none … … 8 11 ! These procedures read a whole NetCDF variable (coordinate or 9 12 ! primary) into an array. 10 ! The difference between the procedures is the rank of the array11 ! a nd the type of Fortran values.13 ! The difference between the procedures is the rank and type of 14 ! argument "values". 12 15 ! The procedures do not check the type of the NetCDF variable. 13 16 14 !!$ module procedure nf95_gw_var_real_1d, nf95_gw_var_real_2d, & 15 !!$ nf95_gw_var_real_3d, nf95_gw_var_real_4d, nf95_gw_var_dble_1d, & 16 !!$ nf95_gw_var_dble_3d, nf95_gw_var_int_1d, nf95_gw_var_int_3d 17 ! Not including double precision procedures in the generic 18 ! interface because we use a compilation option that changes default 19 ! real precision. 17 20 module procedure nf95_gw_var_real_1d, nf95_gw_var_real_2d, & 18 nf95_gw_var_real_3d, nf95_gw_var_real_4d, nf95_gw_var_ int_1d, &19 nf95_gw_var_int_ 3d21 nf95_gw_var_real_3d, nf95_gw_var_real_4d, nf95_gw_var_real_5d, & 22 nf95_gw_var_int_1d, nf95_gw_var_int_3d 20 23 end interface 21 24 … … 29 32 ! Real type, the array has rank 1. 30 33 31 use netcdf, only: NF90_GET_VAR32 use simple, only: nf95_inquire_variable, nf95_inquire_dimension33 use handle_err_m, only: handle_err34 35 34 integer, intent(in):: ncid 36 35 integer, intent(in):: varid … … 38 37 39 38 ! Variables local to the procedure: 40 integer ierr,len41 integer, pointer 39 integer nclen 40 integer, pointer:: dimids(:) 42 41 43 42 !--------------------- … … 46 45 47 46 if (size(dimids) /= 1) then 48 print *, "nf95_gw_var_real_1d: NetCDF variable is not of rank 1" 49 stop 1 50 end if 51 52 call nf95_inquire_dimension(ncid, dimids(1), len=len) 53 deallocate(dimids) ! pointer 54 55 allocate(values(len)) 56 if (len /= 0) then 57 ierr = NF90_GET_VAR(ncid, varid, values) 58 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 59 end if 47 print *, "nf95_gw_var_real_1d:" 48 print *, "varid = ", varid 49 print *, "rank of NetCDF variable is ", size(dimids), ", not 1" 50 stop 1 51 end if 52 53 call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen) 54 deallocate(dimids) ! pointer 55 56 allocate(values(nclen)) 57 if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values) 60 58 61 59 end subroutine nf95_gw_var_real_1d … … 67 65 ! Real type, the array has rank 2. 68 66 69 use netcdf, only: NF90_GET_VAR70 use simple, only: nf95_inquire_variable, nf95_inquire_dimension71 use handle_err_m, only: handle_err72 73 67 integer, intent(in):: ncid 74 68 integer, intent(in):: varid … … 76 70 77 71 ! Variables local to the procedure: 78 integer ierr, len1,len279 integer, pointer 72 integer nclen1, nclen2 73 integer, pointer:: dimids(:) 80 74 81 75 !--------------------- … … 84 78 85 79 if (size(dimids) /= 2) then 86 print *, "nf95_gw_var_real_2d: NetCDF variable is not of rank 2" 87 stop 1 88 end if 89 90 call nf95_inquire_dimension(ncid, dimids(1), len=len1) 91 call nf95_inquire_dimension(ncid, dimids(2), len=len2) 92 deallocate(dimids) ! pointer 93 94 allocate(values(len1, len2)) 95 if (len1 /= 0 .and. len2 /= 0) then 96 ierr = NF90_GET_VAR(ncid, varid, values) 97 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 98 end if 80 print *, "nf95_gw_var_real_2d:" 81 print *, "varid = ", varid 82 print *, "rank of NetCDF variable is ", size(dimids), ", not 2" 83 stop 1 84 end if 85 86 call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1) 87 call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2) 88 deallocate(dimids) ! pointer 89 90 allocate(values(nclen1, nclen2)) 91 if (nclen1 /= 0 .and. nclen2 /= 0) call NF95_GET_VAR(ncid, varid, values) 99 92 100 93 end subroutine nf95_gw_var_real_2d … … 106 99 ! Real type, the array has rank 3. 107 100 108 use netcdf, only: NF90_GET_VAR109 use simple, only: nf95_inquire_variable, nf95_inquire_dimension110 use handle_err_m, only: handle_err111 112 101 integer, intent(in):: ncid 113 102 integer, intent(in):: varid … … 115 104 116 105 ! Variables local to the procedure: 117 integer ierr, len1, len2,len3118 integer, pointer 106 integer nclen1, nclen2, nclen3 107 integer, pointer:: dimids(:) 119 108 120 109 !--------------------- … … 123 112 124 113 if (size(dimids) /= 3) then 125 print *, "nf95_gw_var_real_3d: NetCDF variable is not of rank 3" 126 stop 1 127 end if 128 129 call nf95_inquire_dimension(ncid, dimids(1), len=len1) 130 call nf95_inquire_dimension(ncid, dimids(2), len=len2) 131 call nf95_inquire_dimension(ncid, dimids(3), len=len3) 132 deallocate(dimids) ! pointer 133 134 allocate(values(len1, len2, len3)) 135 if (len1 * len2 * len3 /= 0) then 136 ierr = NF90_GET_VAR(ncid, varid, values) 137 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 138 end if 114 print *, "nf95_gw_var_real_3d:" 115 print *, "varid = ", varid 116 print *, "rank of NetCDF variable is ", size(dimids), ", not 3" 117 stop 1 118 end if 119 120 call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1) 121 call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2) 122 call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3) 123 deallocate(dimids) ! pointer 124 125 allocate(values(nclen1, nclen2, nclen3)) 126 if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values) 139 127 140 128 end subroutine nf95_gw_var_real_3d … … 146 134 ! Real type, the array has rank 4. 147 135 148 use netcdf, only: NF90_GET_VAR149 use simple, only: nf95_inquire_variable, nf95_inquire_dimension150 use handle_err_m, only: handle_err151 152 136 integer, intent(in):: ncid 153 137 integer, intent(in):: varid … … 155 139 156 140 ! Variables local to the procedure: 157 integer ierr,len_dim(4), i158 integer, pointer 141 integer len_dim(4), i 142 integer, pointer:: dimids(:) 159 143 160 144 !--------------------- … … 163 147 164 148 if (size(dimids) /= 4) then 165 print *, "nf95_gw_var_real_4d: NetCDF variable is not of rank 4" 149 print *, "nf95_gw_var_real_4d:" 150 print *, "varid = ", varid 151 print *, "rank of NetCDF variable is ", size(dimids), ", not 4" 166 152 stop 1 167 153 end if 168 154 169 155 do i = 1, 4 170 call nf95_inquire_dimension(ncid, dimids(i), len=len_dim(i))156 call nf95_inquire_dimension(ncid, dimids(i), nclen=len_dim(i)) 171 157 end do 172 158 deallocate(dimids) ! pointer 173 159 174 160 allocate(values(len_dim(1), len_dim(2), len_dim(3), len_dim(4))) 175 if (all(len_dim /= 0)) then 176 ierr = NF90_GET_VAR(ncid, varid, values) 177 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 178 end if 161 if (all(len_dim /= 0)) call NF95_GET_VAR(ncid, varid, values) 179 162 180 163 end subroutine nf95_gw_var_real_4d … … 182 165 !************************************ 183 166 167 subroutine nf95_gw_var_real_5d(ncid, varid, values) 168 169 ! Real type, the array has rank 5. 170 171 integer, intent(in):: ncid 172 integer, intent(in):: varid 173 real, pointer:: values(:, :, :, :, :) 174 175 ! Variables local to the procedure: 176 integer len_dim(5), i 177 integer, pointer:: dimids(:) 178 179 !--------------------- 180 181 call nf95_inquire_variable(ncid, varid, dimids=dimids) 182 183 if (size(dimids) /= 5) then 184 print *, "nf95_gw_var_real_5d:" 185 print *, "varid = ", varid 186 print *, "rank of NetCDF variable is ", size(dimids), ", not 5" 187 stop 1 188 end if 189 190 do i = 1, 5 191 call nf95_inquire_dimension(ncid, dimids(i), nclen=len_dim(i)) 192 end do 193 deallocate(dimids) ! pointer 194 195 allocate(values(len_dim(1), len_dim(2), len_dim(3), len_dim(4), len_dim(5))) 196 if (all(len_dim /= 0)) call NF95_GET_VAR(ncid, varid, values) 197 198 end subroutine nf95_gw_var_real_5d 199 200 !************************************ 201 184 202 !!$ subroutine nf95_gw_var_dble_1d(ncid, varid, values) 185 203 !!$ 186 204 !!$ ! Double precision, the array has rank 1. 187 !!$188 !!$ use netcdf, only: NF90_GET_VAR189 !!$ use simple, only: nf95_inquire_variable, nf95_inquire_dimension190 !!$ use handle_err_m, only: handle_err191 205 !!$ 192 206 !!$ integer, intent(in):: ncid … … 195 209 !!$ 196 210 !!$ ! Variables local to the procedure: 197 !!$ integer ierr,len198 !!$ integer, pointer 211 !!$ integer nclen 212 !!$ integer, pointer:: dimids(:) 199 213 !!$ 200 214 !!$ !--------------------- … … 203 217 !!$ 204 218 !!$ if (size(dimids) /= 1) then 205 !!$ print *, "nf95_gw_var_dble_1d: NetCDF variable is not of rank 1" 206 !!$ stop 1 219 !!$ print *, "nf95_gw_var_dble_1d:" 220 !!$ print *, "varid = ", varid 221 !!$ print *, "rank of NetCDF variable is ", size(dimids), ", not 1" 222 !!$ stop 1 207 223 !!$ end if 208 224 !!$ 209 !!$ call nf95_inquire_dimension(ncid, dimids(1), len=len)225 !!$ call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen) 210 226 !!$ deallocate(dimids) ! pointer 211 227 !!$ 212 !!$ allocate(values(len)) 213 !!$ if (len /= 0) then 214 !!$ ierr = NF90_GET_VAR(ncid, varid, values) 215 !!$ call handle_err("NF90_GET_VAR", ierr, ncid, varid) 216 !!$ end if 228 !!$ allocate(values(nclen)) 229 !!$ if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values) 217 230 !!$ 218 231 !!$ end subroutine nf95_gw_var_dble_1d … … 223 236 !!$ 224 237 !!$ ! Double precision, the array has rank 3. 225 !!$226 !!$ use netcdf, only: NF90_GET_VAR227 !!$ use simple, only: nf95_inquire_variable, nf95_inquire_dimension228 !!$ use handle_err_m, only: handle_err229 238 !!$ 230 239 !!$ integer, intent(in):: ncid … … 233 242 !!$ 234 243 !!$ ! Variables local to the procedure: 235 !!$ integer ierr, len1, len2,len3236 !!$ integer, pointer 244 !!$ integer nclen1, nclen2, nclen3 245 !!$ integer, pointer:: dimids(:) 237 246 !!$ 238 247 !!$ !--------------------- … … 241 250 !!$ 242 251 !!$ if (size(dimids) /= 3) then 243 !!$ print *, "nf95_gw_var_dble_3d: NetCDF variable is not of rank 3" 252 !!$ print *, "nf95_gw_var_dble_3d:" 253 !!$ print *, "varid = ", varid 254 !!$ print *, "rank of NetCDF variable is ", size(dimids), ", not 3" 244 255 !!$ stop 1 245 256 !!$ end if 246 257 !!$ 247 !!$ call nf95_inquire_dimension(ncid, dimids(1), len=len1)248 !!$ call nf95_inquire_dimension(ncid, dimids(2), len=len2)249 !!$ call nf95_inquire_dimension(ncid, dimids(3), len=len3)258 !!$ call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1) 259 !!$ call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2) 260 !!$ call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3) 250 261 !!$ deallocate(dimids) ! pointer 251 262 !!$ 252 !!$ allocate(values(len1, len2, len3)) 253 !!$ if (len1 * len2 * len3 /= 0) then 254 !!$ ierr = NF90_GET_VAR(ncid, varid, values) 255 !!$ call handle_err("NF90_GET_VAR", ierr, ncid, varid) 256 !!$ end if 263 !!$ allocate(values(nclen1, nclen2, nclen3)) 264 !!$ if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values) 257 265 !!$ 258 266 !!$ end subroutine nf95_gw_var_dble_3d 259 267 !!$ 260 268 !************************************ 261 269 … … 264 272 ! Integer type, the array has rank 1. 265 273 266 use netcdf, only: NF90_GET_VAR267 use simple, only: nf95_inquire_variable, nf95_inquire_dimension268 use handle_err_m, only: handle_err269 270 274 integer, intent(in):: ncid 271 275 integer, intent(in):: varid … … 273 277 274 278 ! Variables local to the procedure: 275 integer ierr,len276 integer, pointer 279 integer nclen 280 integer, pointer:: dimids(:) 277 281 278 282 !--------------------- … … 281 285 282 286 if (size(dimids) /= 1) then 283 print *, "nf95_gw_var_int_1d: NetCDF variable is not of rank 1" 284 stop 1 285 end if 286 287 call nf95_inquire_dimension(ncid, dimids(1), len=len) 288 deallocate(dimids) ! pointer 289 290 allocate(values(len)) 291 if (len /= 0) then 292 ierr = NF90_GET_VAR(ncid, varid, values) 293 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 294 end if 287 print *, "nf95_gw_var_int_1d:" 288 print *, "varid = ", varid 289 print *, "rank of NetCDF variable is ", size(dimids), ", not 1" 290 stop 1 291 end if 292 293 call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen) 294 deallocate(dimids) ! pointer 295 296 allocate(values(nclen)) 297 if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values) 295 298 296 299 end subroutine nf95_gw_var_int_1d … … 302 305 ! Integer type, the array has rank 3. 303 306 304 use netcdf, only: NF90_GET_VAR305 use simple, only: nf95_inquire_variable, nf95_inquire_dimension306 use handle_err_m, only: handle_err307 308 307 integer, intent(in):: ncid 309 308 integer, intent(in):: varid … … 311 310 312 311 ! Variables local to the procedure: 313 integer ierr, len1, len2,len3314 integer, pointer 312 integer nclen1, nclen2, nclen3 313 integer, pointer:: dimids(:) 315 314 316 315 !--------------------- … … 319 318 320 319 if (size(dimids) /= 3) then 321 print *, "nf95_gw_var_int_3d: NetCDF variable is not of rank 3" 322 stop 1 323 end if 324 325 call nf95_inquire_dimension(ncid, dimids(1), len=len1) 326 call nf95_inquire_dimension(ncid, dimids(2), len=len2) 327 call nf95_inquire_dimension(ncid, dimids(3), len=len3) 328 deallocate(dimids) ! pointer 329 330 allocate(values(len1, len2, len3)) 331 if (len1 * len2 * len3 /= 0) then 332 ierr = NF90_GET_VAR(ncid, varid, values) 333 call handle_err("NF90_GET_VAR", ierr, ncid, varid) 334 end if 320 print *, "nf95_gw_var_int_3d:" 321 print *, "varid = ", varid 322 print *, "rank of NetCDF variable is ", size(dimids), ", not 3" 323 stop 1 324 end if 325 326 call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1) 327 call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2) 328 call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3) 329 deallocate(dimids) ! pointer 330 331 allocate(values(nclen1, nclen2, nclen3)) 332 if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values) 335 333 336 334 end subroutine nf95_gw_var_int_3d -
LMDZ5/branches/testing/libf/bibio/nf95_put_var_m.F90
r1279 r1669 9 9 nf95_put_var_2D_FourByteReal, nf95_put_var_3D_FourByteReal, & 10 10 nf95_put_var_4D_FourByteReal 11 !!$ module procedure nf95_put_var_1D_FourByteReal, &12 !!$ nf95_put_var_2D_FourByteReal, nf95_put_var_3D_FourByteReal, &13 !!$ nf95_put_var_4D_FourByteReal, nf90_put_var_1D_EightByteReal, &14 !!$ nf90_put_var_3D_EightByteReal15 11 end interface 16 12 … … 25 21 use handle_err_m, only: handle_err 26 22 27 integer, intent( 28 real, intent( 29 integer, dimension(:), optional, intent( 23 integer, intent(in) :: ncid, varid 24 real, intent(in) :: values 25 integer, dimension(:), optional, intent(in) :: start 30 26 integer, intent(out), optional:: ncerr 31 27 … … 52 48 use handle_err_m, only: handle_err 53 49 54 integer, intent( 55 integer, intent( 56 integer, dimension(:), optional, intent( 50 integer, intent(in) :: ncid, varid 51 integer, intent(in) :: values 52 integer, dimension(:), optional, intent(in) :: start 57 53 integer, intent(out), optional:: ncerr 58 54 … … 74 70 !*********************** 75 71 76 subroutine nf95_put_var_1D_FourByteReal(ncid, varid, values, start, count,&77 stride, map, ncerr)72 subroutine nf95_put_var_1D_FourByteReal(ncid, varid, values, start, & 73 count_nc, stride, map, ncerr) 78 74 79 75 use netcdf, only: nf90_put_var … … 82 78 integer, intent(in) :: ncid, varid 83 79 real, intent(in) :: values(:) 84 integer, dimension(:), optional, intent(in) :: start, count , stride, map85 integer, intent(out), optional:: ncerr 86 87 ! Variable local to the procedure: 88 integer ncerr_not_opt 89 90 !------------------- 91 92 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count , stride, &93 map)80 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 81 integer, intent(out), optional:: ncerr 82 83 ! Variable local to the procedure: 84 integer ncerr_not_opt 85 86 !------------------- 87 88 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 89 stride, map) 94 90 if (present(ncerr)) then 95 91 ncerr = ncerr_not_opt … … 103 99 !*********************** 104 100 105 subroutine nf95_put_var_1D_FourByteInt(ncid, varid, values, start, count,&106 stride, map, ncerr)101 subroutine nf95_put_var_1D_FourByteInt(ncid, varid, values, start, & 102 count_nc, stride, map, ncerr) 107 103 108 104 use netcdf, only: nf90_put_var … … 111 107 integer, intent(in) :: ncid, varid 112 108 integer, intent(in) :: values(:) 113 integer, dimension(:), optional, intent(in) :: start, count , stride, map114 integer, intent(out), optional:: ncerr 115 116 ! Variable local to the procedure: 117 integer ncerr_not_opt 118 119 !------------------- 120 121 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count , stride, &122 map)109 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 110 integer, intent(out), optional:: ncerr 111 112 ! Variable local to the procedure: 113 integer ncerr_not_opt 114 115 !------------------- 116 117 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 118 stride, map) 123 119 if (present(ncerr)) then 124 120 ncerr = ncerr_not_opt … … 132 128 !*********************** 133 129 134 subroutine nf95_put_var_2D_FourByteReal(ncid, varid, values, start, count, & 135 stride, map, ncerr) 136 137 use netcdf, only: nf90_put_var 138 use handle_err_m, only: handle_err 139 140 integer, intent( in) :: ncid, varid 141 real, intent( in) :: values(:, :) 142 integer, dimension(:), optional, intent( in) :: start, count, stride, map 143 integer, intent(out), optional:: ncerr 144 145 ! Variable local to the procedure: 146 integer ncerr_not_opt 147 148 !------------------- 149 150 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count, stride, & 151 map) 130 subroutine nf95_put_var_1D_EightByteReal(ncid, varid, values, start, & 131 count_nc, stride, map, ncerr) 132 133 use typesizes, only: eightByteReal 134 use netcdf, only: nf90_put_var 135 use handle_err_m, only: handle_err 136 137 integer, intent(in) :: ncid, varid 138 real (kind = EightByteReal), intent(in) :: values(:) 139 integer, dimension(:), optional, intent(in):: start, count_nc, stride, map 140 integer, intent(out), optional:: ncerr 141 142 ! Variable local to the procedure: 143 integer ncerr_not_opt 144 145 !------------------- 146 147 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 148 stride, map) 149 if (present(ncerr)) then 150 ncerr = ncerr_not_opt 151 else 152 call handle_err("nf95_put_var_1D_eightByteReal", ncerr_not_opt, ncid, & 153 varid) 154 end if 155 156 end subroutine nf95_put_var_1D_EightByteReal 157 158 !*********************** 159 160 subroutine nf95_put_var_2D_FourByteReal(ncid, varid, values, start, & 161 count_nc, stride, map, ncerr) 162 163 use netcdf, only: nf90_put_var 164 use handle_err_m, only: handle_err 165 166 integer, intent(in) :: ncid, varid 167 real, intent(in) :: values(:, :) 168 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 169 integer, intent(out), optional:: ncerr 170 171 ! Variable local to the procedure: 172 integer ncerr_not_opt 173 174 !------------------- 175 176 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 177 stride, map) 152 178 if (present(ncerr)) then 153 179 ncerr = ncerr_not_opt … … 161 187 !*********************** 162 188 163 subroutine nf95_put_var_3D_FourByteReal(ncid, varid, values, start, count, & 164 stride, map, ncerr) 165 166 use netcdf, only: nf90_put_var 167 use handle_err_m, only: handle_err 168 169 integer, intent( in) :: ncid, varid 170 real, intent( in) :: values(:, :, :) 171 integer, dimension(:), optional, intent( in) :: start, count, stride, map 172 integer, intent(out), optional:: ncerr 173 174 ! Variable local to the procedure: 175 integer ncerr_not_opt 176 177 !------------------- 178 179 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count, stride, & 180 map) 189 subroutine nf95_put_var_2D_EightByteReal(ncid, varid, values, start, & 190 count_nc, stride, map, ncerr) 191 192 use typesizes, only: EightByteReal 193 use netcdf, only: nf90_put_var 194 use handle_err_m, only: handle_err 195 196 integer, intent(in) :: ncid, varid 197 real (kind = EightByteReal), intent(in) :: values(:, :) 198 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 199 integer, intent(out), optional:: ncerr 200 201 ! Variable local to the procedure: 202 integer ncerr_not_opt 203 204 !------------------- 205 206 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 207 stride, map) 208 if (present(ncerr)) then 209 ncerr = ncerr_not_opt 210 else 211 call handle_err("nf95_put_var_2D_EightByteReal", ncerr_not_opt, ncid, & 212 varid) 213 end if 214 215 end subroutine nf95_put_var_2D_EightByteReal 216 217 !*********************** 218 219 subroutine nf95_put_var_3D_FourByteReal(ncid, varid, values, start, & 220 count_nc, stride, map, ncerr) 221 222 use netcdf, only: nf90_put_var 223 use handle_err_m, only: handle_err 224 225 integer, intent(in) :: ncid, varid 226 real, intent(in) :: values(:, :, :) 227 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 228 integer, intent(out), optional:: ncerr 229 230 ! Variable local to the procedure: 231 integer ncerr_not_opt 232 233 !------------------- 234 235 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 236 stride, map) 181 237 if (present(ncerr)) then 182 238 ncerr = ncerr_not_opt … … 190 246 !*********************** 191 247 192 subroutine nf95_put_var_4D_FourByteReal(ncid, varid, values, start, count, & 193 stride, map, ncerr) 194 195 use netcdf, only: nf90_put_var 196 use handle_err_m, only: handle_err 197 198 integer, intent( in) :: ncid, varid 199 real, intent( in) :: values(:, :, :, :) 200 integer, dimension(:), optional, intent( in) :: start, count, stride, map 201 integer, intent(out), optional:: ncerr 202 203 ! Variable local to the procedure: 204 integer ncerr_not_opt 205 206 !------------------- 207 208 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count, stride, & 209 map) 248 subroutine nf95_put_var_3D_EightByteReal(ncid, varid, values, start, & 249 count_nc, stride, map, ncerr) 250 251 use typesizes, only: eightByteReal 252 use netcdf, only: nf90_put_var 253 use handle_err_m, only: handle_err 254 255 integer, intent(in) :: ncid, varid 256 real (kind = EightByteReal), intent(in) :: values(:, :, :) 257 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 258 integer, intent(out), optional:: ncerr 259 260 ! Variable local to the procedure: 261 integer ncerr_not_opt 262 263 !------------------- 264 265 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 266 stride, map) 267 if (present(ncerr)) then 268 ncerr = ncerr_not_opt 269 else 270 call handle_err("nf95_put_var_3D_eightByteReal", ncerr_not_opt, ncid, & 271 varid) 272 end if 273 274 end subroutine nf95_put_var_3D_EightByteReal 275 276 !*********************** 277 278 subroutine nf95_put_var_4D_FourByteReal(ncid, varid, values, start, & 279 count_nc, stride, map, ncerr) 280 281 use netcdf, only: nf90_put_var 282 use handle_err_m, only: handle_err 283 284 integer, intent(in) :: ncid, varid 285 real, intent(in) :: values(:, :, :, :) 286 integer, dimension(:), optional, intent(in) :: start, count_nc, stride, map 287 integer, intent(out), optional:: ncerr 288 289 ! Variable local to the procedure: 290 integer ncerr_not_opt 291 292 !------------------- 293 294 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 295 stride, map) 210 296 if (present(ncerr)) then 211 297 ncerr = ncerr_not_opt … … 219 305 !*********************** 220 306 221 !!$ subroutine nf90_put_var_1D_EightByteReal(ncid, varid, values, start, count, & 222 !!$ stride, map, ncerr) 223 !!$ 224 !!$ use typesizes, only: eightByteReal 225 !!$ use netcdf, only: nf90_put_var 226 !!$ use handle_err_m, only: handle_err 227 !!$ 228 !!$ integer, intent( in) :: ncid, varid 229 !!$ real (kind = EightByteReal), intent( in) :: values(:) 230 !!$ integer, dimension(:), optional, intent( in) :: start, count, stride, map 231 !!$ integer, intent(out), optional:: ncerr 232 !!$ 233 !!$ ! Variable local to the procedure: 234 !!$ integer ncerr_not_opt 235 !!$ 236 !!$ !------------------- 237 !!$ 238 !!$ ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count, stride, & 239 !!$ map) 240 !!$ if (present(ncerr)) then 241 !!$ ncerr = ncerr_not_opt 242 !!$ else 243 !!$ call handle_err("nf95_put_var_1D_eightByteReal", ncerr_not_opt, ncid, & 244 !!$ varid) 245 !!$ end if 246 !!$ 247 !!$ end subroutine nf90_put_var_1D_EightByteReal 248 !!$ 249 !!$ !*********************** 250 !!$ 251 !!$ subroutine nf90_put_var_3D_EightByteReal(ncid, varid, values, start, count, & 252 !!$ stride, map, ncerr) 253 !!$ 254 !!$ use typesizes, only: eightByteReal 255 !!$ use netcdf, only: nf90_put_var 256 !!$ use handle_err_m, only: handle_err 257 !!$ 258 !!$ integer, intent( in) :: ncid, varid 259 !!$ real (kind = EightByteReal), intent( in) :: values(:, :, :) 260 !!$ integer, dimension(:), optional, intent( in) :: start, count, stride, map 261 !!$ integer, intent(out), optional:: ncerr 262 !!$ 263 !!$ ! Variable local to the procedure: 264 !!$ integer ncerr_not_opt 265 !!$ 266 !!$ !------------------- 267 !!$ 268 !!$ ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count, stride, & 269 !!$ map) 270 !!$ if (present(ncerr)) then 271 !!$ ncerr = ncerr_not_opt 272 !!$ else 273 !!$ call handle_err("nf95_put_var_3D_eightByteReal", ncerr_not_opt, ncid, & 274 !!$ varid) 275 !!$ end if 276 !!$ 277 !!$ end subroutine nf90_put_var_3D_EightByteReal 307 subroutine nf95_put_var_4D_EightByteReal(ncid, varid, values, start, & 308 count_nc, stride, map, ncerr) 309 310 use typesizes, only: EightByteReal 311 use netcdf, only: nf90_put_var 312 use handle_err_m, only: handle_err 313 314 integer, intent(in):: ncid, varid 315 real(kind = EightByteReal), intent(in):: values(:, :, :, :) 316 integer, dimension(:), optional, intent(in):: start, count_nc, stride, map 317 integer, intent(out), optional:: ncerr 318 319 ! Variable local to the procedure: 320 integer ncerr_not_opt 321 322 !------------------- 323 324 ncerr_not_opt = nf90_put_var(ncid, varid, values, start, count_nc, & 325 stride, map) 326 if (present(ncerr)) then 327 ncerr = ncerr_not_opt 328 else 329 call handle_err("nf95_put_var_4D_EightByteReal", ncerr_not_opt, ncid, & 330 varid) 331 end if 332 333 end subroutine nf95_put_var_4D_EightByteReal 278 334 279 335 end module nf95_put_var_m -
LMDZ5/branches/testing/libf/bibio/simple.F90
r1279 r1669 2 2 module simple 3 3 4 use handle_err_m, only: handle_err 5 4 6 implicit none 5 7 8 private handle_err 9 6 10 contains 7 11 … … 9 13 10 14 use netcdf, only: nf90_open 11 use handle_err_m, only: handle_err12 15 13 16 character(len=*), intent(in):: path … … 36 39 37 40 use netcdf, only: nf90_inq_dimid 38 use handle_err_m, only: handle_err 39 40 integer, intent( in) :: ncid 41 character (len = *), intent( in) :: name 41 42 integer, intent(in) :: ncid 43 character (len = *), intent(in) :: name 42 44 integer, intent(out) :: dimid 43 45 integer, intent(out), optional:: ncerr … … 52 54 ncerr = ncerr_not_opt 53 55 else 54 call handle_err("nf95_inq_dimid ", ncerr_not_opt, ncid)56 call handle_err("nf95_inq_dimid " // name, ncerr_not_opt, ncid) 55 57 end if 56 58 … … 59 61 !************************ 60 62 61 subroutine nf95_inquire_dimension(ncid, dimid, name, len, ncerr)63 subroutine nf95_inquire_dimension(ncid, dimid, name, nclen, ncerr) 62 64 63 65 use netcdf, only: nf90_inquire_dimension 64 use handle_err_m, only: handle_err65 66 66 67 integer, intent( in) :: ncid, dimid 67 68 character (len = *), optional, intent(out) :: name 68 integer, optional, intent(out) :: len69 integer, intent(out), optional:: ncerr 70 71 ! Variable local to the procedure: 72 integer ncerr_not_opt 73 74 !------------------- 75 76 ncerr_not_opt = nf90_inquire_dimension(ncid, dimid, name, len)69 integer, optional, intent(out) :: nclen 70 integer, intent(out), optional:: ncerr 71 72 ! Variable local to the procedure: 73 integer ncerr_not_opt 74 75 !------------------- 76 77 ncerr_not_opt = nf90_inquire_dimension(ncid, dimid, name, nclen) 77 78 if (present(ncerr)) then 78 79 ncerr = ncerr_not_opt … … 88 89 89 90 use netcdf, only: nf90_inq_varid 90 use handle_err_m, only: handle_err91 91 92 92 integer, intent(in) :: ncid 93 character (len = *), intent(in):: name93 character(len=*), intent(in):: name 94 94 integer, intent(out) :: varid 95 95 integer, intent(out), optional:: ncerr … … 115 115 116 116 ! In "nf90_inquire_variable", "dimids" is an assumed-size array. 117 ! This is the classical case of an array the size of which is 117 ! This is not optimal. 118 ! We are in the classical case of an array the size of which is 118 119 ! unknown in the calling procedure, before the call. 119 120 ! Here we use a better solution: a pointer argument array. … … 121 122 122 123 use netcdf, only: nf90_inquire_variable, nf90_max_var_dims 123 use handle_err_m, only: handle_err124 124 125 125 integer, intent(in):: ncid, varid … … 151 151 ncerr = ncerr_not_opt 152 152 else 153 call handle_err("nf95_inquire_variable", ncerr_not_opt, ncid )153 call handle_err("nf95_inquire_variable", ncerr_not_opt, ncid, varid) 154 154 end if 155 155 … … 161 161 162 162 use netcdf, only: nf90_create 163 use handle_err_m, only: handle_err164 163 165 164 character (len = *), intent(in ) :: path … … 186 185 !************************ 187 186 188 subroutine nf95_def_dim(ncid, name, len, dimid, ncerr)187 subroutine nf95_def_dim(ncid, name, nclen, dimid, ncerr) 189 188 190 189 use netcdf, only: nf90_def_dim 191 use handle_err_m, only: handle_err192 190 193 191 integer, intent( in) :: ncid 194 192 character (len = *), intent( in) :: name 195 integer, intent( in) :: len193 integer, intent( in) :: nclen 196 194 integer, intent(out) :: dimid 197 195 integer, intent(out), optional :: ncerr … … 202 200 !------------------- 203 201 204 ncerr_not_opt = nf90_def_dim(ncid, name, len, dimid)205 if (present(ncerr)) then 206 ncerr = ncerr_not_opt 207 else 208 call handle_err("nf95_def_dim ", ncerr_not_opt, ncid)202 ncerr_not_opt = nf90_def_dim(ncid, name, nclen, dimid) 203 if (present(ncerr)) then 204 ncerr = ncerr_not_opt 205 else 206 call handle_err("nf95_def_dim " // name, ncerr_not_opt, ncid) 209 207 end if 210 208 … … 216 214 217 215 use netcdf, only: nf90_redef 218 use handle_err_m, only: handle_err219 216 220 217 integer, intent( in) :: ncid … … 240 237 241 238 use netcdf, only: nf90_enddef 242 use handle_err_m, only: handle_err243 239 244 240 integer, intent( in) :: ncid … … 265 261 266 262 use netcdf, only: nf90_close 267 use handle_err_m, only: handle_err268 263 269 264 integer, intent( in) :: ncid … … 289 284 290 285 use netcdf, only: nf90_copy_att 291 use handle_err_m, only: handle_err292 286 293 287 integer, intent( in):: ncid_in, varid_in … … 305 299 ncerr = ncerr_not_opt 306 300 else 307 call handle_err("nf95_copy_att ", ncerr_not_opt, ncid_out)301 call handle_err("nf95_copy_att " // name, ncerr_not_opt, ncid_out) 308 302 end if 309 303 310 304 end subroutine nf95_copy_att 311 305 306 !*********************** 307 308 subroutine nf95_inquire_attribute(ncid, varid, name, xtype, nclen, attnum, & 309 ncerr) 310 311 use netcdf, only: nf90_inquire_attribute 312 313 integer, intent( in) :: ncid, varid 314 character (len = *), intent( in) :: name 315 integer, intent(out), optional :: xtype, nclen, attnum 316 integer, intent(out), optional:: ncerr 317 318 ! Variable local to the procedure: 319 integer ncerr_not_opt 320 321 !------------------- 322 323 ncerr_not_opt = nf90_inquire_attribute(ncid, varid, name, xtype, nclen, & 324 attnum) 325 if (present(ncerr)) then 326 ncerr = ncerr_not_opt 327 else 328 call handle_err("nf95_inquire_attribute " // name, ncerr_not_opt, & 329 ncid, varid) 330 end if 331 332 end subroutine nf95_inquire_attribute 333 334 !*********************** 335 336 subroutine nf95_inquire(ncid, nDimensions, nVariables, nAttributes, & 337 unlimitedDimId, formatNum, ncerr) 338 339 use netcdf, only: nf90_inquire 340 341 integer, intent( in) :: ncid 342 integer, optional, intent(out) :: nDimensions, nVariables, nAttributes 343 integer, optional, intent(out) :: unlimitedDimId, formatNum 344 integer, intent(out), optional:: ncerr 345 346 ! Variable local to the procedure: 347 integer ncerr_not_opt 348 349 !------------------- 350 351 ncerr_not_opt = nf90_inquire(ncid, nDimensions, nVariables, nAttributes, & 352 unlimitedDimId, formatNum) 353 if (present(ncerr)) then 354 ncerr = ncerr_not_opt 355 else 356 call handle_err("nf95_inquire", ncerr_not_opt, ncid) 357 end if 358 359 end subroutine nf95_inquire 360 312 361 end module simple
Note: See TracChangeset
for help on using the changeset viewer.