[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 |
---|
[1169] | 23 | if [ -f mesh_mask.nc ] ; then |
---|
| 24 | IGCM_sys_Cp mesh_mask.nc ${config_UserChoices_JobName}_mesh_mask.nc |
---|
| 25 | elif [ -f ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc ] ; then |
---|
[590] | 26 | IGCM_sys_GetBuffer ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc . |
---|
[588] | 27 | elif [ -f ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc ] ; then |
---|
[584] | 28 | IGCM_sys_Get ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc . |
---|
[588] | 29 | else |
---|
| 30 | IGCM_debug_Exit "mesh_mask can not be found. Stop." |
---|
| 31 | IGCM_debug_Exit "neither here ${R_SAVE}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc" |
---|
| 32 | IGCM_debug_Exit "nor here ${R_BUFR}/OCE/Output/${config_UserChoices_JobName}_mesh_mask.nc" |
---|
[1206] | 33 | IGCM_debug_Verif_Exit |
---|
[584] | 34 | fi |
---|
| 35 | fi |
---|
[201] | 36 | |
---|
| 37 | filename=${1} |
---|
| 38 | |
---|
| 39 | chaineT=${filename%%'grid_T'*} |
---|
| 40 | chaineU=${filename%%'grid_U'*} |
---|
| 41 | chaineV=${filename%%'grid_V'*} |
---|
| 42 | chaineW=${filename%%'grid_W'*} |
---|
| 43 | chaineIce=${filename%%'icemod'*} |
---|
[242] | 44 | chaineTrc=${filename%%'ptrc_T'*} |
---|
| 45 | chaineDia=${filename%%'diad_T'*} |
---|
[703] | 46 | chaineBio=${filename%%'dbio_T'*} |
---|
[201] | 47 | |
---|
| 48 | if [ ${filename} != ${chaineT} ]; then |
---|
| 49 | mask='tmask' ; depth='deptht' |
---|
| 50 | elif [ ${filename} != ${chaineU} ]; then |
---|
| 51 | mask='umask' ; depth='depthu' |
---|
| 52 | elif [ ${filename} != ${chaineV} ]; then |
---|
| 53 | mask='vmask' ; depth='depthv' |
---|
| 54 | elif [ ${filename} != ${chaineW} ]; then |
---|
| 55 | mask='tmask' ; depth='depthw' |
---|
| 56 | elif [ ${filename} != ${chaineIce} ]; then |
---|
| 57 | mask='tmask' ; depth='deptht' |
---|
[242] | 58 | elif [ ${filename} != ${chaineTrc} ]; then |
---|
| 59 | mask='tmask' ; depth='deptht' |
---|
| 60 | elif [ ${filename} != ${chaineDia} ]; then |
---|
| 61 | mask='tmask' ; depth='deptht' |
---|
[703] | 62 | elif [ ${filename} != ${chaineBio} ]; then |
---|
| 63 | mask='tmask' ; depth='deptht' |
---|
[201] | 64 | fi |
---|
| 65 | |
---|
[257] | 66 | #============================================ |
---|
| 67 | # Remove nav_lon, nav_lat file |
---|
[201] | 68 | IGCM_sys_ncks -Oh -x -v nav_lon,nav_lat ${filename} file1.nc |
---|
| 69 | |
---|
[257] | 70 | #============================================ |
---|
| 71 | # Extract mask variable |
---|
[201] | 72 | IGCM_sys_ncks -Oh -v ${mask} ${config_UserChoices_JobName}_mesh_mask.nc mask3D.nc |
---|
| 73 | |
---|
[257] | 74 | #============================================ |
---|
| 75 | # Rename deptht dimension |
---|
[201] | 76 | IGCM_sys_ncrename -Oh -d z,${depth} mask3D.nc |
---|
| 77 | |
---|
[257] | 78 | #============================================ |
---|
| 79 | # Remove single dimension t |
---|
[201] | 80 | IGCM_sys_ncwa -Oh -a t mask3D.nc mask3D.nc |
---|
| 81 | |
---|
[257] | 82 | #============================================ |
---|
| 83 | # Create mask2D |
---|
[201] | 84 | IGCM_sys_ncks -Oh -d ${depth},0,0 mask3D.nc mask2D.nc |
---|
| 85 | IGCM_sys_ncwa -Oh -a ${depth} mask2D.nc mask2D.nc |
---|
[207] | 86 | IGCM_sys_ncrename -h -v ${mask},mask2D mask2D.nc |
---|
[201] | 87 | |
---|
[257] | 88 | #============================================ |
---|
| 89 | # Append mask (2D) to file1.nc |
---|
[201] | 90 | IGCM_sys_ncks -Ah -c -v mask2D mask2D.nc file1.nc |
---|
| 91 | |
---|
| 92 | if [ ${filename} = ${chaineIce} ]; then |
---|
| 93 | |
---|
[257] | 94 | #============================================ |
---|
| 95 | # Append mask (3D) only for oceanic files |
---|
[201] | 96 | IGCM_sys_ncks -Ah -v ${mask} mask3D.nc file1.nc |
---|
[207] | 97 | IGCM_sys_ncrename -h -v ${mask},mask3D file1.nc |
---|
[201] | 98 | |
---|
[257] | 99 | #============================================ |
---|
| 100 | # Add record dimension only for oceanic files |
---|
[201] | 101 | IGCM_sys_ncecat -Oh file1.nc file1.nc |
---|
| 102 | |
---|
[257] | 103 | #============================================ |
---|
| 104 | # Apply mask 3D only for oceanic files |
---|
[311] | 105 | IGCM_sys_ncwa -Oh -a record -B 'mask3D==1' file1.nc file2.nc |
---|
| 106 | IGCM_sys_Rm file1.nc |
---|
| 107 | IGCM_sys_Mv file2.nc file1.nc |
---|
[201] | 108 | |
---|
[311] | 109 | |
---|
[201] | 110 | fi |
---|
| 111 | |
---|
[257] | 112 | #============================================ |
---|
| 113 | # Add record dimension |
---|
[201] | 114 | IGCM_sys_ncecat -Oh file1.nc file1.nc |
---|
| 115 | |
---|
[257] | 116 | #============================================ |
---|
| 117 | # Apply mask 2D |
---|
[207] | 118 | IGCM_sys_ncwa -Oh -b -a record -B 'mask2D==1' file1.nc file1.nc |
---|
[201] | 119 | |
---|
[257] | 120 | #============================================ |
---|
| 121 | # Permute record dimension in time_counter dimension |
---|
[207] | 122 | IGCM_sys_ncpdq -Oh -a time_counter,record file1.nc file1.nc |
---|
| 123 | IGCM_sys_ncwa -Oh -a record file1.nc file1.nc |
---|
| 124 | |
---|
[257] | 125 | #============================================ |
---|
[990] | 126 | # Remove mask 2D and 3D for oceanic files, and mask 2D only for ice files |
---|
| 127 | |
---|
| 128 | if [ ${filename} = ${chaineIce} ]; then |
---|
| 129 | #============================================ |
---|
| 130 | # Remove mask 2D and mask 3D for oceanic files |
---|
| 131 | IGCM_sys_ncks -Oh -x -v mask2D,mask3D file1.nc file_mask.nc |
---|
| 132 | else |
---|
| 133 | #============================================ |
---|
| 134 | # Remove mask 2D for ice files |
---|
| 135 | IGCM_sys_ncks -Oh -x -v mask2D file1.nc file_mask.nc |
---|
| 136 | fi |
---|
[201] | 137 | |
---|
[257] | 138 | #============================================ |
---|
| 139 | # Add nav_lon nav_lat |
---|
[201] | 140 | IGCM_sys_ncks -Ah -v nav_lon,nav_lat ${filename} file_mask.nc |
---|
| 141 | |
---|
[1206] | 142 | # ------------------------------------------------------------------ |
---|
| 143 | # Test if all was right before proceeding further |
---|
| 144 | # ------------------------------------------------------------------ |
---|
| 145 | IGCM_debug_Verif_Exit |
---|
| 146 | |
---|
[257] | 147 | #============================================ |
---|
| 148 | # Cleaning |
---|
[201] | 149 | IGCM_sys_Mv file_mask.nc ${filename} |
---|
| 150 | IGCM_sys_Rm mask3D.nc mask2D.nc file1.nc |
---|
| 151 | |
---|
| 152 | IGCM_debug_PopStack "IGCM_Patch_mask" |
---|
| 153 | } |
---|