Changeset 4258 for palm/trunk/SOURCE/netcdf_data_input_mod.f90
- Timestamp:
- Oct 7, 2019 1:29:08 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SOURCE/netcdf_data_input_mod.f90
r4247 r4258 25 25 ! ----------------- 26 26 ! $Id$ 27 ! - Migrate input of soil temperature and moisture to land-surface model. 28 ! - Remove interpolate routines and move the only required subroutine to 29 ! land-surface model. 30 ! 31 ! 4247 2019-09-30 10:18:24Z pavelkrc 27 32 ! Add reading and processing of building_surface_pars 28 33 ! … … 608 613 PRIVATE 609 614 610 INTERFACE netcdf_data_input_interpolate611 MODULE PROCEDURE netcdf_data_input_interpolate_1d612 MODULE PROCEDURE netcdf_data_input_interpolate_1d_soil613 MODULE PROCEDURE netcdf_data_input_interpolate_2d614 MODULE PROCEDURE netcdf_data_input_interpolate_3d615 END INTERFACE netcdf_data_input_interpolate616 617 615 INTERFACE netcdf_data_input_check_dynamic 618 616 MODULE PROCEDURE netcdf_data_input_check_dynamic … … 650 648 END INTERFACE netcdf_data_input_init_3d 651 649 652 INTERFACE netcdf_data_input_init_lsm653 MODULE PROCEDURE netcdf_data_input_init_lsm654 END INTERFACE netcdf_data_input_init_lsm655 656 650 INTERFACE netcdf_data_input_surface_data 657 651 MODULE PROCEDURE netcdf_data_input_surface_data … … 733 727 ! 734 728 !-- Public subroutines 735 PUBLIC netcdf_data_input_check_dynamic, netcdf_data_input_check_static, & 729 PUBLIC netcdf_data_input_check_dynamic, & 730 netcdf_data_input_check_static, & 736 731 netcdf_data_input_chemistry_data, & 737 732 get_dimension_length, & 738 733 netcdf_data_input_inquire_file, & 739 netcdf_data_input_init, netcdf_data_input_init_lsm, & 740 netcdf_data_input_init_3d, netcdf_data_input_att, & 741 netcdf_data_input_interpolate, & 742 netcdf_data_input_surface_data, netcdf_data_input_topo, & 734 netcdf_data_input_init, & 735 netcdf_data_input_init_3d, & 736 netcdf_data_input_att, & 737 netcdf_data_input_surface_data, & 738 netcdf_data_input_topo, & 743 739 netcdf_data_input_var, & 744 740 get_attribute, & … … 2914 2910 IF ( init_3d%nx-1 /= nx .OR. init_3d%nxu-1 /= nx - 1 .OR. & 2915 2911 init_3d%ny-1 /= ny .OR. init_3d%nyv-1 /= ny - 1 ) THEN 2916 message_string = 'Number of inifor horizontal grid points '//&2917 'd oes not match the number of numeric grid '//&2918 ' points.'2912 message_string = 'Number of horizontal grid points in '// & 2913 'dynamic input file does not match ' // & 2914 'the number of numeric grid points.' 2919 2915 CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 ) 2920 2916 ENDIF 2921 2917 2922 2918 IF ( init_3d%nzu /= nz ) THEN 2923 message_string = 'Number of inifor vertical grid points ' //&2924 'd oes not match the number of numeric grid '//&2925 ' points.'2919 message_string = 'Number of vertical grid points in '// & 2920 'dynamic input file does not match ' // & 2921 'the number of numeric grid points.' 2926 2922 CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 ) 2927 2923 ENDIF … … 3353 3349 3354 3350 END SUBROUTINE netcdf_data_input_init_3d 3355 3356 !------------------------------------------------------------------------------!3357 ! Description:3358 ! ------------3359 !> Reads initialization data of u, v, w, pt, q, geostrophic wind components,3360 !> as well as soil moisture and soil temperature, derived from larger-scale3361 !> model (COSMO) by Inifor.3362 !------------------------------------------------------------------------------!3363 SUBROUTINE netcdf_data_input_init_lsm3364 3365 USE control_parameters, &3366 ONLY: message_string3367 3368 USE indices, &3369 ONLY: nx, nxl, nxr, ny, nyn, nys3370 3371 IMPLICIT NONE3372 3373 CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE :: var_names !< string containing all variables on file3374 3375 INTEGER(iwp) :: id_dynamic !< NetCDF id of dynamic input file3376 INTEGER(iwp) :: num_vars !< number of variables in netcdf input file3377 3378 !3379 !-- Skip routine if no input file with dynamic input data is available.3380 IF ( .NOT. input_pids_dynamic ) RETURN3381 !3382 !-- CPU measurement3383 CALL cpu_log( log_point_s(85), 'NetCDF input init', 'start' )3384 3385 #if defined ( __netcdf )3386 !3387 !-- Open file in read-only mode3388 CALL open_read_file( TRIM( input_file_dynamic ) // &3389 TRIM( coupling_char ), id_dynamic )3390 3391 !3392 !-- At first, inquire all variable names.3393 CALL inquire_num_variables( id_dynamic, num_vars )3394 !3395 !-- Allocate memory to store variable names.3396 ALLOCATE( var_names(1:num_vars) )3397 CALL inquire_variable_names( id_dynamic, var_names )3398 !3399 !-- Read vertical dimension for soil depth.3400 IF ( check_existence( var_names, 'zsoil' ) ) &3401 CALL get_dimension_length( id_dynamic, init_3d%nzs, 'zsoil' )3402 !3403 !-- Read also the horizontal dimensions required for soil initialization.3404 !-- Please note, in case of non-nested runs or in case of root domain,3405 !-- these data is already available, but will be read again for the sake3406 !-- of clearness.3407 CALL get_dimension_length( id_dynamic, init_3d%nx, 'x' )3408 CALL get_dimension_length( id_dynamic, init_3d%ny, 'y' )3409 !3410 !-- Check for correct horizontal and vertical dimension. Please note,3411 !-- in case of non-nested runs or in case of root domain, these checks3412 !-- are already performed3413 IF ( init_3d%nx-1 /= nx .OR. init_3d%ny-1 /= ny ) THEN3414 message_string = 'Number of inifor horizontal grid points '// &3415 'does not match the number of numeric grid points.'3416 CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )3417 ENDIF3418 !3419 !-- Read vertical dimensions. Later, these are required for eventual3420 !-- inter- and extrapolations of the initialization data.3421 IF ( check_existence( var_names, 'zsoil' ) ) THEN3422 ALLOCATE( init_3d%z_soil(1:init_3d%nzs) )3423 CALL get_variable( id_dynamic, 'zsoil', init_3d%z_soil )3424 ENDIF3425 !3426 !-- Read initial data for soil moisture3427 IF ( check_existence( var_names, 'init_soil_m' ) ) THEN3428 !3429 !-- Read attributes for the fill value and level-of-detail3430 CALL get_attribute( id_dynamic, char_fill, &3431 init_3d%fill_msoil, &3432 .FALSE., 'init_soil_m' )3433 CALL get_attribute( id_dynamic, char_lod, &3434 init_3d%lod_msoil, &3435 .FALSE., 'init_soil_m' )3436 !3437 !-- level-of-detail 1 - read initialization profile3438 IF ( init_3d%lod_msoil == 1 ) THEN3439 ALLOCATE( init_3d%msoil_1d(0:init_3d%nzs-1) )3440 3441 CALL get_variable( id_dynamic, 'init_soil_m', &3442 init_3d%msoil_1d(0:init_3d%nzs-1) )3443 !3444 !-- level-of-detail 2 - read 3D initialization data3445 ELSEIF ( init_3d%lod_msoil == 2 ) THEN3446 ALLOCATE ( init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )3447 3448 CALL get_variable( id_dynamic, 'init_soil_m', &3449 init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&3450 nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )3451 3452 ENDIF3453 init_3d%from_file_msoil = .TRUE.3454 ENDIF3455 !3456 !-- Read soil temperature3457 IF ( check_existence( var_names, 'init_soil_t' ) ) THEN3458 !3459 !-- Read attributes for the fill value and level-of-detail3460 CALL get_attribute( id_dynamic, char_fill, &3461 init_3d%fill_tsoil, &3462 .FALSE., 'init_soil_t' )3463 CALL get_attribute( id_dynamic, char_lod, &3464 init_3d%lod_tsoil, &3465 .FALSE., 'init_soil_t' )3466 !3467 !-- level-of-detail 1 - read initialization profile3468 IF ( init_3d%lod_tsoil == 1 ) THEN3469 ALLOCATE( init_3d%tsoil_1d(0:init_3d%nzs-1) )3470 3471 CALL get_variable( id_dynamic, 'init_soil_t', &3472 init_3d%tsoil_1d(0:init_3d%nzs-1) )3473 3474 !3475 !-- level-of-detail 2 - read 3D initialization data3476 ELSEIF ( init_3d%lod_tsoil == 2 ) THEN3477 ALLOCATE ( init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )3478 3479 CALL get_variable( id_dynamic, 'init_soil_t', &3480 init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&3481 nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )3482 ENDIF3483 init_3d%from_file_tsoil = .TRUE.3484 ENDIF3485 !3486 !-- Close input file3487 CALL close_input_file( id_dynamic )3488 #endif3489 !3490 !-- End of CPU measurement3491 CALL cpu_log( log_point_s(85), 'NetCDF input init', 'stop' )3492 3493 END SUBROUTINE netcdf_data_input_init_lsm3494 3351 3495 3352 !------------------------------------------------------------------------------! … … 3584 3441 message_string = 'Reading 3D building data - vertical ' // & 3585 3442 'coordinate do not match numeric grid.' 3586 CALL message( 'netcdf_data_input_mod', 'PA0553', 2, 2, myid, 6, 0 )3443 CALL message( 'netcdf_data_input_mod', 'PA0553', 2, 2, 0, 6, 0 ) 3587 3444 ENDIF 3588 3445 ENDIF … … 4227 4084 4228 4085 END SUBROUTINE resize_array_4d_real 4229 4230 !------------------------------------------------------------------------------!4231 ! Description:4232 ! ------------4233 !> Vertical interpolation and extrapolation of 1D variables.4234 !------------------------------------------------------------------------------!4235 SUBROUTINE netcdf_data_input_interpolate_1d( var, z_grid, z_file)4236 4237 IMPLICIT NONE4238 4239 INTEGER(iwp) :: k !< running index z-direction file4240 INTEGER(iwp) :: kk !< running index z-direction stretched model grid4241 INTEGER(iwp) :: kl !< lower index bound along z-direction4242 INTEGER(iwp) :: ku !< upper index bound along z-direction4243 4244 REAL(wp), DIMENSION(:) :: z_grid !< grid levels on numeric grid4245 REAL(wp), DIMENSION(:) :: z_file !< grid levels on file grid4246 REAL(wp), DIMENSION(:), INTENT(INOUT) :: var !< treated variable4247 REAL(wp), DIMENSION(:), ALLOCATABLE :: var_tmp !< temporary variable4248 4249 4250 kl = LBOUND(var,1)4251 ku = UBOUND(var,1)4252 ALLOCATE( var_tmp(kl:ku) )4253 4254 DO k = kl, ku4255 4256 kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )4257 4258 IF ( kk < ku ) THEN4259 IF ( z_file(kk) - z_grid(k) <= 0.0_wp ) THEN4260 var_tmp(k) = var(kk) + &4261 ( var(kk+1) - var(kk) ) / &4262 ( z_file(kk+1) - z_file(kk) ) * &4263 ( z_grid(k) - z_file(kk) )4264 4265 ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp ) THEN4266 var_tmp(k) = var(kk-1) + &4267 ( var(kk) - var(kk-1) ) / &4268 ( z_file(kk) - z_file(kk-1) ) * &4269 ( z_grid(k) - z_file(kk-1) )4270 ENDIF4271 !4272 !-- Extrapolate4273 ELSE4274 4275 var_tmp(k) = var(ku) + ( var(ku) - var(ku-1) ) / &4276 ( z_file(ku) - z_file(ku-1) ) * &4277 ( z_grid(k) - z_file(ku) )4278 4279 ENDIF4280 4281 ENDDO4282 var(:) = var_tmp(:)4283 4284 DEALLOCATE( var_tmp )4285 4286 4287 END SUBROUTINE netcdf_data_input_interpolate_1d4288 4289 4290 !------------------------------------------------------------------------------!4291 ! Description:4292 ! ------------4293 !> Vertical interpolation and extrapolation of 1D variables from Inifor grid4294 !> onto Palm grid, where both have same dimension. Please note, the passed4295 !> paramter list in 1D version is different compared to 2D version.4296 !------------------------------------------------------------------------------!4297 SUBROUTINE netcdf_data_input_interpolate_1d_soil( var, var_file, &4298 z_grid, z_file, &4299 nzb_var, nzt_var, &4300 nzb_file, nzt_file )4301 4302 IMPLICIT NONE4303 4304 INTEGER(iwp) :: k !< running index z-direction file4305 INTEGER(iwp) :: kk !< running index z-direction stretched model grid4306 INTEGER(iwp) :: ku !< upper index bound along z-direction for varialbe from file4307 INTEGER(iwp) :: nzb_var !< lower bound of final array4308 INTEGER(iwp) :: nzt_var !< upper bound of final array4309 INTEGER(iwp) :: nzb_file !< lower bound of file array4310 INTEGER(iwp) :: nzt_file !< upper bound of file array4311 4312 ! LOGICAL, OPTIONAL :: zsoil !< flag indicating reverse z-axis, i.e. zsoil instead of height, e.g. in case of ocean or soil4313 4314 REAL(wp), DIMENSION(nzb_var:nzt_var) :: z_grid !< grid levels on numeric grid4315 REAL(wp), DIMENSION(nzb_file:nzt_file) :: z_file !< grid levels on file grid4316 REAL(wp), DIMENSION(nzb_var:nzt_var) :: var !< treated variable4317 REAL(wp), DIMENSION(nzb_file:nzt_file) :: var_file !< temporary variable4318 4319 ku = nzt_file4320 4321 DO k = nzb_var, nzt_var4322 !4323 !-- Determine index on Inifor grid which is closest to the actual height4324 kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )4325 !4326 !-- If closest index on Inifor grid is smaller than top index,4327 !-- interpolate the data4328 IF ( kk < nzt_file ) THEN4329 IF ( z_file(kk) - z_grid(k) <= 0.0_wp ) THEN4330 var(k) = var_file(kk) + ( var_file(kk+1) - var_file(kk) ) / &4331 ( z_file(kk+1) - z_file(kk) ) * &4332 ( z_grid(k) - z_file(kk) )4333 4334 ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp ) THEN4335 var(k) = var_file(kk-1) + ( var_file(kk) - var_file(kk-1) ) / &4336 ( z_file(kk) - z_file(kk-1) ) * &4337 ( z_grid(k) - z_file(kk-1) )4338 ENDIF4339 !4340 !-- Extrapolate if actual height is above the highest Inifor level by the last value4341 ELSE4342 var(k) = var_file(ku)4343 ENDIF4344 4345 ENDDO4346 4347 END SUBROUTINE netcdf_data_input_interpolate_1d_soil4348 4349 !------------------------------------------------------------------------------!4350 ! Description:4351 ! ------------4352 !> Vertical interpolation and extrapolation of 2D variables at lateral boundaries.4353 !------------------------------------------------------------------------------!4354 SUBROUTINE netcdf_data_input_interpolate_2d( var, z_grid, z_file)4355 4356 IMPLICIT NONE4357 4358 INTEGER(iwp) :: i !< running index x- or y -direction4359 INTEGER(iwp) :: il !< lower index bound along x- or y-direction4360 INTEGER(iwp) :: iu !< upper index bound along x- or y-direction4361 INTEGER(iwp) :: k !< running index z-direction file4362 INTEGER(iwp) :: kk !< running index z-direction stretched model grid4363 INTEGER(iwp) :: kl !< lower index bound along z-direction4364 INTEGER(iwp) :: ku !< upper index bound along z-direction4365 4366 REAL(wp), DIMENSION(:) :: z_grid !< grid levels on numeric grid4367 REAL(wp), DIMENSION(:) :: z_file !< grid levels on file grid4368 REAL(wp), DIMENSION(:,:), INTENT(INOUT) :: var !< treated variable4369 REAL(wp), DIMENSION(:), ALLOCATABLE :: var_tmp !< temporary variable4370 4371 4372 il = LBOUND(var,2)4373 iu = UBOUND(var,2)4374 kl = LBOUND(var,1)4375 ku = UBOUND(var,1)4376 ALLOCATE( var_tmp(kl:ku) )4377 4378 DO i = il, iu4379 DO k = kl, ku4380 4381 kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )4382 4383 IF ( kk < ku ) THEN4384 IF ( z_file(kk) - z_grid(k) <= 0.0_wp ) THEN4385 var_tmp(k) = var(kk,i) + &4386 ( var(kk+1,i) - var(kk,i) ) / &4387 ( z_file(kk+1) - z_file(kk) ) * &4388 ( z_grid(k) - z_file(kk) )4389 4390 ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp ) THEN4391 var_tmp(k) = var(kk-1,i) + &4392 ( var(kk,i) - var(kk-1,i) ) / &4393 ( z_file(kk) - z_file(kk-1) ) * &4394 ( z_grid(k) - z_file(kk-1) )4395 ENDIF4396 !4397 !-- Extrapolate4398 ELSE4399 4400 var_tmp(k) = var(ku,i) + ( var(ku,i) - var(ku-1,i) ) / &4401 ( z_file(ku) - z_file(ku-1) ) * &4402 ( z_grid(k) - z_file(ku) )4403 4404 ENDIF4405 4406 ENDDO4407 var(:,i) = var_tmp(:)4408 4409 ENDDO4410 4411 DEALLOCATE( var_tmp )4412 4413 4414 END SUBROUTINE netcdf_data_input_interpolate_2d4415 4416 !------------------------------------------------------------------------------!4417 ! Description:4418 ! ------------4419 !> Vertical interpolation and extrapolation of 3D variables.4420 !------------------------------------------------------------------------------!4421 SUBROUTINE netcdf_data_input_interpolate_3d( var, z_grid, z_file )4422 4423 IMPLICIT NONE4424 4425 INTEGER(iwp) :: i !< running index x-direction4426 INTEGER(iwp) :: il !< lower index bound along x-direction4427 INTEGER(iwp) :: iu !< upper index bound along x-direction4428 INTEGER(iwp) :: j !< running index y-direction4429 INTEGER(iwp) :: jl !< lower index bound along x-direction4430 INTEGER(iwp) :: ju !< upper index bound along x-direction4431 INTEGER(iwp) :: k !< running index z-direction file4432 INTEGER(iwp) :: kk !< running index z-direction stretched model grid4433 INTEGER(iwp) :: kl !< lower index bound along z-direction4434 INTEGER(iwp) :: ku !< upper index bound along z-direction4435 4436 REAL(wp), DIMENSION(:) :: z_grid !< grid levels on numeric grid4437 REAL(wp), DIMENSION(:) :: z_file !< grid levels on file grid4438 REAL(wp), DIMENSION(:,:,:), INTENT(INOUT) :: var !< treated variable4439 REAL(wp), DIMENSION(:), ALLOCATABLE :: var_tmp !< temporary variable4440 4441 il = LBOUND(var,3)4442 iu = UBOUND(var,3)4443 jl = LBOUND(var,2)4444 ju = UBOUND(var,2)4445 kl = LBOUND(var,1)4446 ku = UBOUND(var,1)4447 4448 ALLOCATE( var_tmp(kl:ku) )4449 4450 DO i = il, iu4451 DO j = jl, ju4452 DO k = kl, ku4453 4454 kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )4455 4456 IF ( kk < ku ) THEN4457 IF ( z_file(kk) - z_grid(k) <= 0.0_wp ) THEN4458 var_tmp(k) = var(kk,j,i) + &4459 ( var(kk+1,j,i) - var(kk,j,i) ) / &4460 ( z_file(kk+1) - z_file(kk) ) * &4461 ( z_grid(k) - z_file(kk) )4462 4463 ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp ) THEN4464 var_tmp(k) = var(kk-1,j,i) + &4465 ( var(kk,j,i) - var(kk-1,j,i) ) / &4466 ( z_file(kk) - z_file(kk-1) ) * &4467 ( z_grid(k) - z_file(kk-1) )4468 ENDIF4469 !4470 !-- Extrapolate4471 ELSE4472 var_tmp(k) = var(ku,j,i) + &4473 ( var(ku,j,i) - var(ku-1,j,i) ) / &4474 ( z_file(ku) - z_file(ku-1) ) * &4475 ( z_grid(k) - z_file(ku) )4476 4477 ENDIF4478 ENDDO4479 var(:,j,i) = var_tmp(:)4480 ENDDO4481 ENDDO4482 4483 DEALLOCATE( var_tmp )4484 4485 4486 END SUBROUTINE netcdf_data_input_interpolate_3d4487 4086 4488 4087 !------------------------------------------------------------------------------!
Note: See TracChangeset
for help on using the changeset viewer.