[201] | 1 | #!/bin/ksh |
---|
| 2 | |
---|
[257] | 3 | #************************************************************** |
---|
| 4 | # Author: Arnaud Caubel |
---|
[373] | 5 | # Contact: Arnaud.Caubel__at__lsce.ipsl.fr |
---|
| 6 | # $Revision:: $ Revision of last commit |
---|
| 7 | # $Author:: $ Author of last commit |
---|
| 8 | # $Date:: $ Date of last commit |
---|
[257] | 9 | # IPSL (2009) |
---|
| 10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 11 | # |
---|
| 12 | #************************************************************** |
---|
| 13 | |
---|
[201] | 14 | #------------------------------------------------------------ |
---|
| 15 | # Add mask from meshmask file to oceanic variables |
---|
| 16 | #------------------------------------------------------------ |
---|
| 17 | |
---|
| 18 | function IGCM_Patch_20091118_mask { |
---|
| 19 | |
---|
| 20 | IGCM_debug_PushStack "IGCM_Patch_mask" $@ |
---|
| 21 | |
---|
[590] | 22 | if [ ! -f ${config_UserChoices_JobName}_mesh_mask.nc ] ; then |
---|
[588] | 23 | if [ -f ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc ] ; then |
---|
[590] | 24 | IGCM_sys_GetBuffer ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc . |
---|
[588] | 25 | elif [ -f ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc ] ; then |
---|
[584] | 26 | IGCM_sys_Get ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc . |
---|
[588] | 27 | else |
---|
| 28 | IGCM_debug_Exit "mesh_mask can not be found. Stop." |
---|
| 29 | IGCM_debug_Exit "neither here ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc" |
---|
| 30 | IGCM_debug_Exit "nor here ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc" |
---|
| 31 | IGCM_debug_Verif_Exit_Post |
---|
[584] | 32 | fi |
---|
| 33 | fi |
---|
[201] | 34 | |
---|
| 35 | filename=${1} |
---|
| 36 | |
---|
| 37 | chaineT=${filename%%'grid_T'*} |
---|
| 38 | chaineU=${filename%%'grid_U'*} |
---|
| 39 | chaineV=${filename%%'grid_V'*} |
---|
| 40 | chaineW=${filename%%'grid_W'*} |
---|
| 41 | chaineIce=${filename%%'icemod'*} |
---|
[242] | 42 | chaineTrc=${filename%%'ptrc_T'*} |
---|
| 43 | chaineDia=${filename%%'diad_T'*} |
---|
[703] | 44 | chaineBio=${filename%%'dbio_T'*} |
---|
[201] | 45 | |
---|
| 46 | if [ ${filename} != ${chaineT} ]; then |
---|
| 47 | mask='tmask' ; depth='deptht' |
---|
| 48 | elif [ ${filename} != ${chaineU} ]; then |
---|
| 49 | mask='umask' ; depth='depthu' |
---|
| 50 | elif [ ${filename} != ${chaineV} ]; then |
---|
| 51 | mask='vmask' ; depth='depthv' |
---|
| 52 | elif [ ${filename} != ${chaineW} ]; then |
---|
| 53 | mask='tmask' ; depth='depthw' |
---|
| 54 | elif [ ${filename} != ${chaineIce} ]; then |
---|
| 55 | mask='tmask' ; depth='deptht' |
---|
[242] | 56 | elif [ ${filename} != ${chaineTrc} ]; then |
---|
| 57 | mask='tmask' ; depth='deptht' |
---|
| 58 | elif [ ${filename} != ${chaineDia} ]; then |
---|
| 59 | mask='tmask' ; depth='deptht' |
---|
[703] | 60 | elif [ ${filename} != ${chaineBio} ]; then |
---|
| 61 | mask='tmask' ; depth='deptht' |
---|
[201] | 62 | fi |
---|
| 63 | |
---|
[257] | 64 | #============================================ |
---|
| 65 | # Remove nav_lon, nav_lat file |
---|
[201] | 66 | IGCM_sys_ncks -Oh -x -v nav_lon,nav_lat ${filename} file1.nc |
---|
| 67 | |
---|
[257] | 68 | #============================================ |
---|
| 69 | # Extract mask variable |
---|
[201] | 70 | IGCM_sys_ncks -Oh -v ${mask} ${config_UserChoices_JobName}_mesh_mask.nc mask3D.nc |
---|
| 71 | |
---|
[257] | 72 | #============================================ |
---|
| 73 | # Rename deptht dimension |
---|
[201] | 74 | IGCM_sys_ncrename -Oh -d z,${depth} mask3D.nc |
---|
| 75 | |
---|
[257] | 76 | #============================================ |
---|
| 77 | # Remove single dimension t |
---|
[201] | 78 | IGCM_sys_ncwa -Oh -a t mask3D.nc mask3D.nc |
---|
| 79 | |
---|
[257] | 80 | #============================================ |
---|
| 81 | # Create mask2D |
---|
[201] | 82 | IGCM_sys_ncks -Oh -d ${depth},0,0 mask3D.nc mask2D.nc |
---|
| 83 | IGCM_sys_ncwa -Oh -a ${depth} mask2D.nc mask2D.nc |
---|
[207] | 84 | IGCM_sys_ncrename -h -v ${mask},mask2D mask2D.nc |
---|
[201] | 85 | |
---|
[257] | 86 | #============================================ |
---|
| 87 | # Append mask (2D) to file1.nc |
---|
[201] | 88 | IGCM_sys_ncks -Ah -c -v mask2D mask2D.nc file1.nc |
---|
| 89 | |
---|
| 90 | if [ ${filename} = ${chaineIce} ]; then |
---|
| 91 | |
---|
[257] | 92 | #============================================ |
---|
| 93 | # Append mask (3D) only for oceanic files |
---|
[201] | 94 | IGCM_sys_ncks -Ah -v ${mask} mask3D.nc file1.nc |
---|
[207] | 95 | IGCM_sys_ncrename -h -v ${mask},mask3D file1.nc |
---|
[201] | 96 | |
---|
[257] | 97 | #============================================ |
---|
| 98 | # Add record dimension only for oceanic files |
---|
[201] | 99 | IGCM_sys_ncecat -Oh file1.nc file1.nc |
---|
| 100 | |
---|
[257] | 101 | #============================================ |
---|
| 102 | # Apply mask 3D only for oceanic files |
---|
[311] | 103 | IGCM_sys_ncwa -Oh -a record -B 'mask3D==1' file1.nc file2.nc |
---|
| 104 | IGCM_sys_Rm file1.nc |
---|
| 105 | IGCM_sys_Mv file2.nc file1.nc |
---|
[201] | 106 | |
---|
[311] | 107 | |
---|
[201] | 108 | fi |
---|
| 109 | |
---|
[257] | 110 | #============================================ |
---|
| 111 | # Add record dimension |
---|
[201] | 112 | IGCM_sys_ncecat -Oh file1.nc file1.nc |
---|
| 113 | |
---|
[257] | 114 | #============================================ |
---|
| 115 | # Apply mask 2D |
---|
[207] | 116 | IGCM_sys_ncwa -Oh -b -a record -B 'mask2D==1' file1.nc file1.nc |
---|
[201] | 117 | |
---|
[257] | 118 | #============================================ |
---|
| 119 | # Permute record dimension in time_counter dimension |
---|
[207] | 120 | IGCM_sys_ncpdq -Oh -a time_counter,record file1.nc file1.nc |
---|
| 121 | IGCM_sys_ncwa -Oh -a record file1.nc file1.nc |
---|
| 122 | |
---|
[257] | 123 | #============================================ |
---|
[990] | 124 | # Remove mask 2D and 3D for oceanic files, and mask 2D only for ice files |
---|
| 125 | |
---|
| 126 | if [ ${filename} = ${chaineIce} ]; then |
---|
| 127 | #============================================ |
---|
| 128 | # Remove mask 2D and mask 3D for oceanic files |
---|
| 129 | IGCM_sys_ncks -Oh -x -v mask2D,mask3D file1.nc file_mask.nc |
---|
| 130 | else |
---|
| 131 | #============================================ |
---|
| 132 | # Remove mask 2D for ice files |
---|
| 133 | IGCM_sys_ncks -Oh -x -v mask2D file1.nc file_mask.nc |
---|
| 134 | fi |
---|
[201] | 135 | |
---|
[257] | 136 | #============================================ |
---|
| 137 | # Add nav_lon nav_lat |
---|
[201] | 138 | IGCM_sys_ncks -Ah -v nav_lon,nav_lat ${filename} file_mask.nc |
---|
| 139 | |
---|
[257] | 140 | #============================================ |
---|
| 141 | # Cleaning |
---|
[201] | 142 | IGCM_debug_Verif_Exit_Post |
---|
| 143 | IGCM_sys_Mv file_mask.nc ${filename} |
---|
| 144 | IGCM_sys_Rm mask3D.nc mask2D.nc file1.nc |
---|
| 145 | |
---|
| 146 | IGCM_debug_PopStack "IGCM_Patch_mask" |
---|
| 147 | } |
---|