[1799] | 1 | MODULE agrif_readwrite |
---|
| 2 | ! |
---|
| 3 | USE agrif_types |
---|
| 4 | !USE tools_brice |
---|
| 5 | ! |
---|
| 6 | IMPLICIT NONE |
---|
| 7 | ! |
---|
| 8 | !INTEGER :: nx_fine, ny_fine |
---|
| 9 | ! |
---|
| 10 | CONTAINS |
---|
| 11 | ! |
---|
| 12 | !***************************************************** |
---|
| 13 | ! function Read_Coordinates(name,Grid) |
---|
| 14 | !***************************************************** |
---|
| 15 | |
---|
| 16 | INTEGER FUNCTION Read_Coordinates(name,Grid,Pacifique) |
---|
| 17 | ! |
---|
| 18 | USE io_netcdf |
---|
| 19 | ! |
---|
| 20 | ! file name to open |
---|
| 21 | ! |
---|
| 22 | CHARACTER(*) name |
---|
| 23 | LOGICAL,OPTIONAL :: Pacifique |
---|
| 24 | ! |
---|
| 25 | TYPE(Coordinates) :: Grid |
---|
| 26 | ! |
---|
| 27 | CALL Read_Ncdf_var('glamt',name,Grid%glamt) |
---|
| 28 | CALL Read_Ncdf_var('glamu',name,Grid%glamu) |
---|
| 29 | CALL Read_Ncdf_var('glamv',name,Grid%glamv) |
---|
| 30 | CALL Read_Ncdf_var('glamf',name,Grid%glamf) |
---|
| 31 | CALL Read_Ncdf_var('gphit',name,Grid%gphit) |
---|
| 32 | CALL Read_Ncdf_var('gphiu',name,Grid%gphiu) |
---|
| 33 | CALL Read_Ncdf_var('gphiv',name,Grid%gphiv) |
---|
| 34 | CALL Read_Ncdf_var('gphif',name,Grid%gphif) |
---|
| 35 | CALL Read_Ncdf_var('e1t',name,Grid%e1t) |
---|
| 36 | CALL Read_Ncdf_var('e1u',name,Grid%e1u) |
---|
| 37 | CALL Read_Ncdf_var('e1v',name,Grid%e1v) |
---|
| 38 | CALL Read_Ncdf_var('e1f',name,Grid%e1f) |
---|
| 39 | CALL Read_Ncdf_var('e2t',name,Grid%e2t) |
---|
| 40 | CALL Read_Ncdf_var('e2u',name,Grid%e2u) |
---|
| 41 | CALL Read_Ncdf_var('e2v',name,Grid%e2v) |
---|
| 42 | CALL Read_Ncdf_var('e2f',name,Grid%e2f) |
---|
| 43 | CALL Read_Ncdf_var('nav_lon',name,Grid%nav_lon) |
---|
| 44 | CALL Read_Ncdf_var('nav_lat',name,Grid%nav_lat) |
---|
| 45 | ! |
---|
| 46 | IF( PRESENT(Pacifique) )THEN |
---|
| 47 | IF ( Grid%glamt(1,1) > Grid%glamt(nxfin,nyfin) ) THEN |
---|
| 48 | Pacifique = .TRUE. |
---|
| 49 | WHERE ( Grid%glamt < 0 ) |
---|
| 50 | Grid%glamt = Grid%glamt + 360. |
---|
| 51 | END WHERE |
---|
| 52 | WHERE ( Grid%glamf < 0 ) |
---|
| 53 | Grid%glamf = Grid%glamf + 360. |
---|
| 54 | END WHERE |
---|
| 55 | WHERE ( Grid%glamu < 0 ) |
---|
| 56 | Grid%glamu = Grid%glamu + 360. |
---|
| 57 | END WHERE |
---|
| 58 | WHERE ( Grid%glamv < 0 ) |
---|
| 59 | Grid%glamv = Grid%glamv + 360. |
---|
| 60 | END WHERE |
---|
| 61 | WHERE ( Grid%nav_lon < 0 ) |
---|
| 62 | Grid%nav_lon = Grid%nav_lon + 360. |
---|
| 63 | END WHERE |
---|
| 64 | ENDIF |
---|
| 65 | ENDIF |
---|
| 66 | ! |
---|
| 67 | WRITE(*,*) ' ' |
---|
| 68 | WRITE(*,*) 'Reading coordinates file: ',name |
---|
| 69 | WRITE(*,*) ' ' |
---|
| 70 | ! |
---|
| 71 | Read_Coordinates = 1 |
---|
| 72 | ! |
---|
| 73 | END FUNCTION Read_Coordinates |
---|
| 74 | |
---|
| 75 | !***************************************************** |
---|
| 76 | ! function Write_Coordinates(name,Grid) |
---|
| 77 | !***************************************************** |
---|
| 78 | |
---|
| 79 | INTEGER FUNCTION Write_Coordinates(name,Grid,nx_fine,ny_fine) |
---|
| 80 | ! |
---|
| 81 | USE io_netcdf |
---|
| 82 | CHARACTER(*) name |
---|
| 83 | TYPE(Coordinates) :: Grid |
---|
| 84 | INTEGER :: status,ncid,z |
---|
| 85 | REAL*8,DIMENSION(:),POINTER :: tabtemp |
---|
| 86 | INTEGER,DIMENSION(:),POINTER :: tabint |
---|
| 87 | CHARACTER(len=20),DIMENSION(4) :: dimnames |
---|
| 88 | INTEGER :: nx_fine, ny_fine |
---|
| 89 | ! |
---|
| 90 | status = nf90_create(name,NF90_WRITE,ncid) |
---|
| 91 | status = nf90_close(ncid) |
---|
| 92 | ! |
---|
| 93 | !CALL Write_Ncdf_dim('x',name,nxfin) |
---|
| 94 | !CALL Write_Ncdf_dim('y',name,nyfin) |
---|
| 95 | CALL Write_Ncdf_dim('x',name,nx_fine) |
---|
| 96 | CALL Write_Ncdf_dim('y',name,ny_fine) |
---|
| 97 | IF(.NOT. iom_activated) CALL Write_Ncdf_dim('z',name,1) |
---|
| 98 | CALL Write_Ncdf_dim('time',name,0) |
---|
| 99 | ! |
---|
| 100 | dimnames(1)='x' |
---|
| 101 | dimnames(2)='y' |
---|
| 102 | CALL Write_Ncdf_var('nav_lon',dimnames(1:2),name,Grid%nav_lon,'float') |
---|
| 103 | CALL Write_Ncdf_var('nav_lat',dimnames(1:2),name,Grid%nav_lat,'float') |
---|
| 104 | ! |
---|
| 105 | IF(.NOT. iom_activated) THEN |
---|
| 106 | ! copy nav_lev variable -> IOIPSL |
---|
| 107 | CALL Read_Ncdf_dim('z',parent_coordinate_file,z) |
---|
| 108 | ALLOCATE(tabtemp(z)) |
---|
| 109 | CALL Read_Ncdf_var('nav_lev',TRIM(parent_coordinate_file),tabtemp) |
---|
| 110 | CALL Write_Ncdf_var('nav_lev','z',name,tabtemp,'float') |
---|
| 111 | DEALLOCATE(tabtemp) |
---|
| 112 | ENDIF |
---|
| 113 | ! |
---|
| 114 | CALL Read_Ncdf_var('time',TRIM(parent_coordinate_file),tabtemp) |
---|
| 115 | CALL Write_Ncdf_var('time','time',name,tabtemp,'float') |
---|
| 116 | DEALLOCATE(tabtemp) |
---|
| 117 | CALL Read_Ncdf_var('time_steps',TRIM(parent_coordinate_file),tabint) |
---|
| 118 | CALL Write_Ncdf_var('time_steps','time',name,tabint) |
---|
| 119 | ! |
---|
| 120 | dimnames(1)='x' |
---|
| 121 | dimnames(2)='y' |
---|
| 122 | IF(iom_activated) THEN |
---|
| 123 | dimnames(3)='time' |
---|
| 124 | ELSE |
---|
| 125 | dimnames(3)='z' |
---|
| 126 | dimnames(4)='time' |
---|
| 127 | ENDIF |
---|
| 128 | |
---|
| 129 | CALL Write_Ncdf_var('glamt',dimnames,name,Grid%glamt,3,'double') |
---|
| 130 | CALL Write_Ncdf_var('glamu',dimnames,name,Grid%glamu,3,'double') |
---|
| 131 | CALL Write_Ncdf_var('glamv',dimnames,name,Grid%glamv,3,'double') |
---|
| 132 | CALL Write_Ncdf_var('glamf',dimnames,name,Grid%glamf,3,'double') |
---|
| 133 | CALL Write_Ncdf_var('gphit',dimnames,name,Grid%gphit,3,'double') |
---|
| 134 | CALL Write_Ncdf_var('gphiu',dimnames,name,Grid%gphiu,3,'double') |
---|
| 135 | CALL Write_Ncdf_var('gphiv',dimnames,name,Grid%gphiv,3,'double') |
---|
| 136 | CALL Write_Ncdf_var('gphif',dimnames,name,Grid%gphif,3,'double') |
---|
| 137 | CALL Write_Ncdf_var('e1t',dimnames,name,Grid%e1t,3,'double') |
---|
| 138 | CALL Write_Ncdf_var('e1u',dimnames,name,Grid%e1u,3,'double') |
---|
| 139 | CALL Write_Ncdf_var('e1v',dimnames,name,Grid%e1v,3,'double') |
---|
| 140 | CALL Write_Ncdf_var('e1f',dimnames,name,Grid%e1f,3,'double') |
---|
| 141 | CALL Write_Ncdf_var('e2t',dimnames,name,Grid%e2t,3,'double') |
---|
| 142 | CALL Write_Ncdf_var('e2u',dimnames,name,Grid%e2u,3,'double') |
---|
| 143 | CALL Write_Ncdf_var('e2v',dimnames,name,Grid%e2v,3,'double') |
---|
| 144 | CALL Write_Ncdf_var('e2f',dimnames,name,Grid%e2f,3,'double') |
---|
| 145 | ! |
---|
| 146 | CALL Copy_Ncdf_att('nav_lon',TRIM(parent_coordinate_file),name,& |
---|
| 147 | MINVAL(Grid%nav_lon),MAXVAL(Grid%nav_lon)) |
---|
| 148 | CALL Copy_Ncdf_att('nav_lat',TRIM(parent_coordinate_file),name,& |
---|
| 149 | MINVAL(Grid%nav_lat),MAXVAL(Grid%nav_lat)) |
---|
| 150 | CALL Copy_Ncdf_att('nav_lev',TRIM(parent_coordinate_file),name) |
---|
| 151 | CALL Copy_Ncdf_att('time',TRIM(parent_coordinate_file),name) |
---|
| 152 | CALL Copy_Ncdf_att('time_steps',TRIM(parent_coordinate_file),name) |
---|
| 153 | CALL Copy_Ncdf_att('glamt',TRIM(parent_coordinate_file),name) |
---|
| 154 | CALL Copy_Ncdf_att('glamu',TRIM(parent_coordinate_file),name) |
---|
| 155 | CALL Copy_Ncdf_att('glamv',TRIM(parent_coordinate_file),name) |
---|
| 156 | CALL Copy_Ncdf_att('glamf',TRIM(parent_coordinate_file),name) |
---|
| 157 | CALL Copy_Ncdf_att('gphit',TRIM(parent_coordinate_file),name) |
---|
| 158 | CALL Copy_Ncdf_att('gphiu',TRIM(parent_coordinate_file),name) |
---|
| 159 | CALL Copy_Ncdf_att('gphiv',TRIM(parent_coordinate_file),name) |
---|
| 160 | CALL Copy_Ncdf_att('gphif',TRIM(parent_coordinate_file),name) |
---|
| 161 | CALL Copy_Ncdf_att('e1t',TRIM(parent_coordinate_file),name) |
---|
| 162 | CALL Copy_Ncdf_att('e1u',TRIM(parent_coordinate_file),name) |
---|
| 163 | CALL Copy_Ncdf_att('e1v',TRIM(parent_coordinate_file),name) |
---|
| 164 | CALL Copy_Ncdf_att('e1f',TRIM(parent_coordinate_file),name) |
---|
| 165 | CALL Copy_Ncdf_att('e2t',TRIM(parent_coordinate_file),name) |
---|
| 166 | CALL Copy_Ncdf_att('e2u',TRIM(parent_coordinate_file),name) |
---|
| 167 | CALL Copy_Ncdf_att('e2v',TRIM(parent_coordinate_file),name) |
---|
| 168 | CALL Copy_Ncdf_att('e2f',TRIM(parent_coordinate_file),name) |
---|
| 169 | ! |
---|
| 170 | WRITE(*,*) ' ' |
---|
| 171 | WRITE(*,*) 'Writing coordinates file: ',name |
---|
| 172 | IF(.NOT. iom_activated) WRITE(*,*) 'IOISPL format' |
---|
| 173 | IF(iom_activated) WRITE(*,*) 'IOM format' |
---|
| 174 | WRITE(*,*) ' ' |
---|
| 175 | ! |
---|
| 176 | Write_Coordinates = 1 |
---|
| 177 | ! |
---|
| 178 | END FUNCTION Write_Coordinates |
---|
| 179 | ! |
---|
| 180 | ! |
---|
| 181 | !***************************************************** |
---|
| 182 | ! function set_child_name(Parentname,Childname) |
---|
| 183 | !***************************************************** |
---|
| 184 | ! |
---|
| 185 | SUBROUTINE set_child_name(Parentname,Childname) |
---|
| 186 | ! |
---|
| 187 | CHARACTER(*),INTENT(in) :: Parentname |
---|
| 188 | CHARACTER(*),INTENT(out) :: Childname |
---|
| 189 | CHARACTER(2) :: prefix |
---|
| 190 | INTEGER :: pos |
---|
| 191 | ! |
---|
| 192 | pos = INDEX(TRIM(Parentname),'/',back=.TRUE.) |
---|
| 193 | ! |
---|
| 194 | prefix=Parentname(pos+1:pos+2) |
---|
| 195 | IF (prefix == '1_') THEN |
---|
| 196 | Childname = '2_'//Parentname(pos+3:LEN(Parentname)) |
---|
| 197 | ELSEIF (prefix == '2_') THEN |
---|
| 198 | Childname = '3_'//Parentname(pos+3:LEN(Parentname)) |
---|
| 199 | ELSEIF (prefix == '3_') THEN |
---|
| 200 | Childname = '4_'//Parentname(pos+3:LEN(Parentname)) |
---|
| 201 | ELSEIF (prefix == '4_') THEN |
---|
| 202 | Childname = '5_'//Parentname(pos+3:LEN(Parentname)) |
---|
| 203 | ELSE |
---|
| 204 | Childname = '1_'//Parentname(pos+1:LEN(Parentname)) |
---|
| 205 | ENDIF |
---|
| 206 | ! |
---|
| 207 | END SUBROUTINE set_child_name |
---|
| 208 | ! |
---|
| 209 | |
---|
| 210 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 211 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 212 | END MODULE agrif_readwrite |
---|