Changeset 2696 for palm/trunk/SOURCE/netcdf_interface_mod.f90
- Timestamp:
- Dec 14, 2017 5:12:51 PM (6 years ago)
- Location:
- palm/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk
-
palm/trunk/SOURCE
-
palm/trunk/SOURCE/netcdf_interface_mod.f90
r2512 r2696 1 1 !> @file netcdf_interface_mod.f90 2 2 !------------------------------------------------------------------------------! 3 ! This file is part of PALM.3 ! This file is part of the PALM model system. 4 4 ! 5 5 ! PALM is free software: you can redistribute it and/or modify it under the … … 25 25 ! ----------------- 26 26 ! $Id$ 27 ! Implementation of uv exposure model (FK) 28 ! Implemented checks for turbulence_closure_mod (TG) 29 ! Implementation of chemistry module (FK) 30 ! Bugfix in setting netcdf grids for LSM variables 31 ! Enable setting of _FillValue attribute in output files (MS) 32 ! 33 ! 2512 2017-10-04 08:26:59Z raasch 27 34 ! upper bounds of cross section and 3d output changed from nx+1,ny+1 to nx,ny 28 35 ! no output of ghost layer data any more … … 410 417 INTEGER(iwp), DIMENSION(1:max_masks,0:1,100) :: id_var_domask 411 418 419 REAL(wp) :: fill_value = -999.0_wp !< value for the _FillValue attribute 420 412 421 413 422 PUBLIC dofl_dim_label_x, dofl_dim_label_y, dofl_dim_label_z, dofl_label, & 414 423 dofl_time_count, dofl_unit, domask_unit, dopr_unit, dopts_num, & 415 424 dots_label, dots_max, dots_num, dots_rad, dots_soil, dots_unit, & 416 do2d_unit, do3d_unit, id_set_fl, id_set_mask, id_set_pr, & 425 do2d_unit, do3d_unit, fill_value, & 426 id_set_fl, id_set_mask, id_set_pr, & 417 427 id_set_prt, id_set_pts, id_set_sp, id_set_ts, id_set_xy, id_set_xz,& 418 428 id_set_yz, id_set_3d, id_var_domask, id_var_dofl, id_var_dopr, & … … 432 442 END INTERFACE netcdf_create_dim 433 443 434 INTERFACE netcdf_close_file435 MODULE PROCEDURE netcdf_close_file436 END INTERFACE netcdf_close_file437 438 444 INTERFACE netcdf_create_file 439 445 MODULE PROCEDURE netcdf_create_file … … 448 454 END INTERFACE netcdf_define_header 449 455 450 INTERFACE netcdf_get_attribute451 MODULE PROCEDURE netcdf_get_attribute452 END INTERFACE netcdf_get_attribute453 454 INTERFACE netcdf_get_variable455 MODULE PROCEDURE netcdf_get_variable_2d456 MODULE PROCEDURE netcdf_get_variable_3d457 END INTERFACE netcdf_get_variable458 459 456 INTERFACE netcdf_handle_error 460 457 MODULE PROCEDURE netcdf_handle_error 461 458 END INTERFACE netcdf_handle_error 462 459 463 INTERFACE netcdf_open_read_file464 MODULE PROCEDURE netcdf_open_read_file465 END INTERFACE netcdf_open_read_file466 467 460 INTERFACE netcdf_open_write_file 468 461 MODULE PROCEDURE netcdf_open_write_file 469 462 END INTERFACE netcdf_open_write_file 470 463 471 PUBLIC netcdf_create_file, netcdf_close_file, netcdf_define_header, & 472 netcdf_handle_error, netcdf_get_attribute, netcdf_get_variable, & 473 netcdf_open_read_file, netcdf_open_write_file 464 PUBLIC netcdf_create_file, netcdf_define_header, & 465 netcdf_handle_error, netcdf_open_write_file 474 466 475 467 CONTAINS … … 482 474 ONLY: zu, zw 483 475 476 #if defined( __chem ) 477 USE chemistry_model_mod, & 478 ONLY: chem_define_netcdf_grid 479 #endif 480 484 481 USE constants, & 485 482 ONLY: pi 486 483 487 484 USE control_parameters, & 488 ONLY: a veraging_interval, averaging_interval_pr,&485 ONLY: air_chemistry, averaging_interval, averaging_interval_pr, & 489 486 data_output_pr, domask, dopr_n, & 490 487 dopr_time_count, dopts_time_count, dots_time_count, & … … 493 490 dt_do2d_yz, dt_do3d, mask_size, do2d_xy_time_count, & 494 491 do3d_time_count, domask_time_count, end_time, land_surface, & 495 lod, mask_size_l, mask_i, mask_i_global, mask_j, mask_j_global,&492 mask_size_l, mask_i, mask_i_global, mask_j, mask_j_global, & 496 493 mask_k_global, message_string, mid, ntdim_2d_xy, & 497 494 ntdim_2d_xz, ntdim_2d_yz, ntdim_3d, nz_do3d, prt_time_count, & … … 500 497 skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz, & 501 498 skip_time_do3d, topography, num_leg, num_var_fl, & 502 urban_surface 499 urban_surface, uv_exposure 503 500 504 501 USE grid_variables, & … … 533 530 ONLY: hom, statistic_regions 534 531 532 USE turbulence_closure_mod, & 533 ONLY: tcm_define_netcdf_grid 534 535 535 USE urban_surface_mod, & 536 536 ONLY: usm_define_netcdf_grid 537 538 USE uv_exposure_model_mod, & 539 ONLY: uvem_define_netcdf_grid 537 540 538 541 … … 894 897 CASE DEFAULT 895 898 899 CALL tcm_define_netcdf_grid( domask(mid,av,i), found, & 900 grid_x, grid_y, grid_z ) 901 896 902 ! 897 903 !-- Check for land surface quantities … … 900 906 grid_x, grid_y, grid_z ) 901 907 ENDIF 902 903 908 ! 904 909 !-- Check for plant canopy quantities 905 IF ( plant_canopy ) THEN910 IF ( .NOT. found .AND. plant_canopy ) THEN 906 911 CALL pcm_define_netcdf_grid( domask(mid,av,i), found, & 907 912 grid_x, grid_y, grid_z ) … … 915 920 grid_z ) 916 921 ENDIF 922 923 ! 924 !-- Check for chemistry quantities 925 #if defined( __chem ) 926 IF ( .NOT. found .AND. air_chemistry ) THEN 927 CALL chem_define_netcdf_grid( domask(mid,av,i), & 928 found, grid_x, grid_y, & 929 grid_z ) 930 ENDIF 931 #endif 917 932 918 933 ! … … 961 976 id_var_domask(mid,av,i), & 962 977 TRIM( domask_unit(mid,av,i) ), & 963 domask(mid,av,i), 494, 495, 496 )978 domask(mid,av,i), 494, 495, 496, .TRUE. ) 964 979 965 980 var_list = TRIM( var_list ) // TRIM( domask(mid,av,i) ) // ';' … … 1425 1440 CASE DEFAULT 1426 1441 1442 CALL tcm_define_netcdf_grid( do3d(av,i), found, & 1443 grid_x, grid_y, grid_z ) 1444 1427 1445 ! 1428 1446 !-- Check for land surface quantities … … 1434 1452 ! 1435 1453 !-- Check for plant canopy quantities 1436 IF ( plant_canopy ) THEN1454 IF ( .NOT. found .AND. plant_canopy ) THEN 1437 1455 CALL pcm_define_netcdf_grid( do3d(av,i), found, grid_x, & 1438 1456 grid_y, grid_z ) … … 1446 1464 grid_z ) 1447 1465 ENDIF 1448 1466 1467 ! 1468 !-- Check for chemistry quantities 1469 #if defined( __chem ) 1470 IF ( .NOT. found .AND. air_chemistry ) THEN 1471 CALL chem_define_netcdf_grid( do3d(av,i), found, & 1472 grid_x, grid_y, grid_z ) 1473 ENDIF 1474 #endif 1475 1449 1476 !-- Check for user-defined quantities 1450 1477 IF ( .NOT. found ) THEN … … 1490 1517 nc_precision(4), id_var_do3d(av,i), & 1491 1518 TRIM( do3d_unit(av,i) ), do3d(av,i), 79, & 1492 80, 357 )1519 80, 357, .TRUE. ) 1493 1520 #if defined( __netcdf4_parallel ) 1494 1521 IF ( netcdf_data_format > 4 ) THEN … … 2029 2056 nc_precision(1), id_var_do2d(av,i), & 2030 2057 TRIM( do2d_unit(av,i) ), & 2031 do2d(av,i), 119, 120, 354 )2058 do2d(av,i), 119, 120, 354, .TRUE. ) 2032 2059 2033 2060 ELSE … … 2079 2106 ENDIF 2080 2107 2108 IF ( .NOT. found ) THEN 2109 CALL tcm_define_netcdf_grid( do2d(av,i), found, & 2110 grid_x, grid_y, & 2111 grid_z ) 2112 ENDIF 2113 2081 2114 ! 2082 2115 !-- Check for radiation quantities … … 2085 2118 found, grid_x, grid_y,& 2086 2119 grid_z ) 2120 ENDIF 2121 2122 ! 2123 !-- Check for chemistry quantities 2124 #if defined( __chem ) 2125 IF ( .NOT. found .AND. air_chemistry ) THEN 2126 CALL chem_define_netcdf_grid( do2d(av,i), found, & 2127 grid_x, grid_y, & 2128 grid_z ) 2129 ENDIF 2130 #endif 2131 2132 ! 2133 !-- Check for UV exposure quantities 2134 IF ( .NOT. found .AND. uv_exposure ) THEN 2135 CALL uvem_define_netcdf_grid( do2d(av,i), found, & 2136 grid_x, grid_y, grid_z ) 2087 2137 ENDIF 2088 2138 … … 2132 2182 nc_precision(1), id_var_do2d(av,i), & 2133 2183 TRIM( do2d_unit(av,i) ), & 2134 do2d(av,i), 119, 120, 354 )2184 do2d(av,i), 119, 120, 354, .TRUE. ) 2135 2185 2136 2186 ENDIF … … 2777 2827 ENDIF 2778 2828 2829 IF ( .NOT. found ) THEN 2830 CALL tcm_define_netcdf_grid( do2d(av,i), found, & 2831 grid_x, grid_y, grid_z ) 2832 ENDIF 2833 2779 2834 ! 2780 2835 !-- Check for radiation quantities … … 2784 2839 grid_z ) 2785 2840 ENDIF 2841 2842 ! 2843 !-- Check for chemistry quantities 2844 #if defined( __chem ) 2845 IF ( .NOT. found .AND. air_chemistry ) THEN 2846 CALL chem_define_netcdf_grid( do2d(av,i), found, & 2847 grid_x, grid_y, & 2848 grid_z ) 2849 ENDIF 2850 #endif 2786 2851 2787 2852 ! … … 2829 2894 nc_precision(2), id_var_do2d(av,i), & 2830 2895 TRIM( do2d_unit(av,i) ), do2d(av,i), & 2831 159, 160, 355 )2896 159, 160, 355, .TRUE. ) 2832 2897 2833 2898 #if defined( __netcdf4_parallel ) … … 3431 3496 ENDIF 3432 3497 3498 IF ( .NOT. found ) THEN 3499 CALL tcm_define_netcdf_grid( do2d(av,i), found, & 3500 grid_x, grid_y, grid_z ) 3501 ENDIF 3502 3433 3503 ! 3434 3504 !-- Check for radiation quantities … … 3439 3509 ENDIF 3440 3510 3511 ! 3512 !-- Check for chemistry quantities 3513 #if defined( __chem ) 3514 IF ( .NOT. found .AND. air_chemistry ) THEN 3515 CALL chem_define_netcdf_grid( do2d(av,i), found, & 3516 grid_x, grid_y, & 3517 grid_z ) 3518 ENDIF 3519 #endif 3441 3520 ! 3442 3521 !-- Check for user-defined quantities … … 3483 3562 nc_precision(3), id_var_do2d(av,i), & 3484 3563 TRIM( do2d_unit(av,i) ), do2d(av,i), & 3485 198, 199, 356 )3564 198, 199, 356, .TRUE. ) 3486 3565 3487 3566 #if defined( __netcdf4_parallel ) … … 5453 5532 END SUBROUTINE netcdf_create_file 5454 5533 5455 5456 !------------------------------------------------------------------------------!5457 ! Description:5458 ! ------------5459 !> Closes an existing netCDF file.5460 !------------------------------------------------------------------------------!5461 5462 SUBROUTINE netcdf_close_file( id, errno )5463 #if defined( __netcdf )5464 5465 USE pegrid5466 5467 IMPLICIT NONE5468 5469 INTEGER(iwp), INTENT(IN) :: errno !< error number5470 INTEGER(iwp), INTENT(INOUT) :: id !< file id5471 5472 nc_stat = NF90_CLOSE( id )5473 CALL netcdf_handle_error( 'netcdf_close', errno )5474 #endif5475 END SUBROUTINE netcdf_close_file5476 5477 !------------------------------------------------------------------------------!5478 ! Description:5479 ! ------------5480 !> Opens an existing netCDF file for reading only and gives back the id.5481 !------------------------------------------------------------------------------!5482 5483 SUBROUTINE netcdf_open_read_file( filename, id, errno )5484 #if defined( __netcdf )5485 5486 USE pegrid5487 5488 IMPLICIT NONE5489 5490 CHARACTER (LEN=*), INTENT(IN) :: filename !< filename5491 INTEGER(iwp), INTENT(IN) :: errno !< error number5492 INTEGER(iwp), INTENT(INOUT) :: id !< file id5493 LOGICAL :: file_open = .FALSE.5494 5495 nc_stat = NF90_OPEN( filename, NF90_NOWRITE, id )5496 5497 CALL netcdf_handle_error( 'netcdf_open_read_file', errno )5498 5499 #endif5500 END SUBROUTINE netcdf_open_read_file5501 5502 !------------------------------------------------------------------------------!5503 ! Description:5504 ! ------------5505 !> Reads the global attributes of a file5506 !------------------------------------------------------------------------------!5507 5508 SUBROUTINE netcdf_get_attribute( id, attribute_name, value, global, errno, variable_name )5509 #if defined( __netcdf )5510 5511 USE pegrid5512 5513 IMPLICIT NONE5514 5515 CHARACTER(LEN=*) :: attribute_name !< attribute name5516 CHARACTER(LEN=*), OPTIONAL :: variable_name !< variable name5517 5518 INTEGER(iwp), INTENT(IN) :: errno !< error number5519 INTEGER(iwp), INTENT(INOUT) :: id !< file id5520 INTEGER(iwp), INTENT(INOUT) :: value !< read value5521 5522 INTEGER(iwp) :: id_var !< variable id5523 5524 LOGICAL, INTENT(IN) :: global !< flag indicating global attributes5525 5526 !5527 !-- Read global attribute5528 IF ( global ) THEN5529 nc_stat = NF90_GET_ATT( id, NF90_GLOBAL, TRIM( attribute_name ), value )5530 CALL netcdf_handle_error( 'netcdf_get_attribute global', errno )5531 !5532 !-- Read attributes referring to a single variable. Therefore, first inquire5533 !-- variable id5534 ELSE5535 nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )5536 CALL netcdf_handle_error( 'netcdf_get_attribute', errno )5537 nc_stat = NF90_GET_ATT( id, id_var, TRIM( attribute_name ), value )5538 CALL netcdf_handle_error( 'netcdf_get_attribute', errno )5539 ENDIF5540 #endif5541 END SUBROUTINE netcdf_get_attribute5542 5543 !------------------------------------------------------------------------------!5544 ! Description:5545 ! ------------5546 !> Reads a 2D REAL variable of a file. Reading is done processor-wise,5547 !> i.e. each core reads its own domain, as well as in slices along x.5548 !------------------------------------------------------------------------------!5549 5550 SUBROUTINE netcdf_get_variable_2d( id, variable_name, i, var, errno )5551 #if defined( __netcdf )5552 5553 USE indices5554 USE pegrid5555 5556 IMPLICIT NONE5557 5558 CHARACTER(LEN=*) :: variable_name !< attribute name5559 INTEGER(iwp), INTENT(IN) :: errno !< error number5560 INTEGER(iwp), INTENT(IN) :: i !< index along x direction5561 5562 INTEGER(iwp), INTENT(INOUT) :: id !< file id5563 5564 INTEGER(iwp) :: id_var !< variable id5565 5566 REAL(wp), DIMENSION(nys:nyn), INTENT(INOUT) :: var !< variable to be read5567 REAL(wp) :: var_dum5568 !5569 !-- Inquire variable id5570 nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )5571 !5572 !-- Get variable5573 nc_stat = NF90_GET_VAR( id, id_var, var(nys:nyn), &5574 start = (/ i+1, nys+1 /), &5575 count = (/ 1, nyn - nys + 1 /) )5576 5577 CALL netcdf_handle_error( 'netcdf_get_variable', errno )5578 #endif5579 END SUBROUTINE netcdf_get_variable_2d5580 5581 !------------------------------------------------------------------------------!5582 ! Description:5583 ! ------------5584 !> Reads a 3D INTEGER variable of a file. Reading is done processor-wise,5585 !> i.e. each core reads its own domain, as well as in slices along x.5586 !------------------------------------------------------------------------------!5587 5588 SUBROUTINE netcdf_get_variable_3d( id, variable_name, i, j, var, errno )5589 #if defined( __netcdf )5590 5591 USE indices5592 USE pegrid5593 5594 IMPLICIT NONE5595 5596 CHARACTER(LEN=*) :: variable_name !< attribute name5597 INTEGER(iwp), INTENT(IN) :: errno !< error number5598 INTEGER(iwp), INTENT(IN) :: i !< index along x direction5599 INTEGER(iwp), INTENT(IN) :: j !< index along y direction5600 5601 INTEGER(iwp), INTENT(INOUT) :: id !< file id5602 5603 INTEGER(iwp) :: id_var !< variable id5604 INTEGER(iwp) :: id_z !< id of z-dimension5605 INTEGER(iwp) :: nz_file !< number of grid-points in file5606 5607 INTEGER( KIND = 1 ), DIMENSION(nzb:nzt+1), INTENT(INOUT) :: var !< variable to be read5608 !5609 !-- Get dimension of z-axis5610 nc_stat = NF90_INQ_DIMID( id, "z", id_z )5611 nc_stat = NF90_INQUIRE_DIMENSION( id, id_z, len = nz_file )5612 !5613 !-- Inquire variable id5614 nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )5615 !5616 !-- Get variable5617 nc_stat = NF90_GET_VAR( id, id_var, var(0:nz_file-1), &5618 start = (/ i+1, j+1, 1 /), &5619 count = (/ 1, 1, nz_file /) )5620 5621 CALL netcdf_handle_error( 'netcdf_get_variable', errno )5622 #endif5623 END SUBROUTINE netcdf_get_variable_3d5624 5625 5534 !------------------------------------------------------------------------------! 5626 5535 ! Description: … … 5629 5538 !> The parallel flag has to be TRUE for parallel netCDF output support. 5630 5539 !------------------------------------------------------------------------------! 5631 5632 5540 SUBROUTINE netcdf_open_write_file( filename, id, parallel, errno ) 5633 5541 #if defined( __netcdf ) … … 5731 5639 SUBROUTINE netcdf_create_var( ncid, dim_id, var_name, var_type, var_id, & 5732 5640 unit_name, long_name, error_no1, error_no2, & 5733 error_no3 )5641 error_no3, fill ) 5734 5642 5735 5643 #if defined( __netcdf ) … … 5739 5647 CHARACTER(LEN=*), INTENT(IN) :: unit_name 5740 5648 CHARACTER(LEN=*), INTENT(IN) :: var_name 5649 5650 LOGICAL, OPTIONAL :: fill !< indicates setting of _FillValue attribute 5741 5651 5742 5652 INTEGER, INTENT(IN) :: error_no1 … … 5777 5687 ENDIF 5778 5688 5689 ! 5690 !-- Set _FillValue for all variables, except for dimension variables. 5691 !-- Set the fill values accordingly to the corresponding output precision. 5692 IF ( PRESENT( fill ) ) THEN 5693 IF ( var_type == NF90_REAL4 ) THEN 5694 nc_stat = NF90_PUT_ATT( ncid, var_id, '_FillValue', & 5695 REAL( fill_value, KIND = 4 ) ) 5696 CALL netcdf_handle_error( 'netcdf_create_var', 0 ) 5697 ELSE 5698 nc_stat = NF90_PUT_ATT( ncid, var_id, '_FillValue', & 5699 REAL( fill_value, KIND = 8 ) ) 5700 CALL netcdf_handle_error( 'netcdf_create_var', 0 ) 5701 ENDIF 5702 ENDIF 5703 5779 5704 #endif 5780 5705 END SUBROUTINE netcdf_create_var
Note: See TracChangeset
for help on using the changeset viewer.