Changeset 965 for trunk/LMDZ.GENERIC/libf
- Timestamp:
- May 22, 2013, 9:10:28 AM (12 years ago)
- Location:
- trunk/LMDZ.GENERIC/libf/phystd
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.GENERIC/libf/phystd/hydrol.F90
r875 r965 110 110 111 111 112 ALLOCATE(runoff(ngrid))112 if (activerunoff) ALLOCATE(runoff(ngrid)) 113 113 114 114 ivap=igcm_h2o_vap … … 360 360 enddo 361 361 362 call writediagfi(ngrid,'runoff','Runoff amount',' ',2,runoff) 362 if (activerunoff) then 363 call writediagfi(ngrid,'runoff','Runoff amount',' ',2,runoff) 364 endif 363 365 364 366 return -
trunk/LMDZ.GENERIC/libf/phystd/inistats.F
r135 r965 1 1 subroutine inistats(ierr) 2 2 3 #ifdef CPP_PARA 4 use mod_phys_lmdz_para, only : is_master 5 #endif 3 6 implicit none 4 7 … … 11 14 #include "netcdf.inc" 12 15 16 #ifndef CPP_PARA 17 logical,parameter :: is_master=.true. 18 #endif 13 19 integer,intent(out) :: ierr 14 20 integer :: nid … … 47 53 pseudoalt(l)=-10.*log(presnivs(l)/preff) 48 54 enddo 55 56 if (is_master) then 57 ! only the master needs do this 49 58 50 59 ierr = NF_CREATE("stats.nc",NF_CLOBBER,nid) … … 115 124 ierr=NF_CLOSE(nid) 116 125 126 endif ! of if (is_master) 117 127 end -
trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specIR.F
r787 r965 1 SUBROUTINE iniwrite_specIR(nid,idayref ,phis)1 SUBROUTINE iniwrite_specIR(nid,idayref) 2 2 3 3 use radinc_h, only: L_NSPECTI 4 4 use radcommon_h, only: WNOI,DWNI 5 use comsoil_h5 ! use comsoil_h 6 6 7 7 implicit none … … 40 40 c ---------- 41 41 42 integer nid ! NetCDF file ID 43 INTEGER*4 idayref ! date (initial date for this run) 44 REAL phis(ip1jmp1) ! surface geopotential 42 integer,intent(in) :: nid ! NetCDF file ID 43 INTEGER*4,intent(in) :: idayref ! date (initial date for this run) 45 44 46 45 c Local: -
trunk/LMDZ.GENERIC/libf/phystd/iniwrite_specVI.F
r787 r965 1 SUBROUTINE iniwrite_specVI(nid,idayref ,phis)1 SUBROUTINE iniwrite_specVI(nid,idayref) 2 2 3 3 use radinc_h, only: L_NSPECTV … … 42 42 integer nid ! NetCDF file ID 43 43 INTEGER*4 idayref ! date (initial date for this run) 44 REAL phis(ip1jmp1) ! surface geopotential45 44 46 45 c Local: -
trunk/LMDZ.GENERIC/libf/phystd/iniwritesoil.F90
r787 r965 1 1 subroutine iniwritesoil(nid,ngrid) 2 2 3 use comsoil_h 3 use comsoil_h, only : inertiedat, mlayer 4 #ifdef CPP_PARA 5 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather 6 use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 7 #endif 4 8 5 9 ! initialization routine for 'writediagoil'. Here we create/define … … 34 38 integer :: i,j,l,ig0 35 39 40 #ifdef CPP_PARA 41 ! Added to work in parallel mode 42 real dx3_glop(klon_glo,nsoilmx) 43 real dx3_glo(iim,jjp1,nsoilmx) ! to store a global 3D data set 44 #else 45 logical,parameter :: is_master=.true. 46 logical,parameter :: is_mpi_root=.true. 47 #endif 48 36 49 ! 1. Define the dimensions 50 if (is_master) then 37 51 ! Switch to NetCDF define mode 38 52 ierr=NF_REDEF(nid) … … 183 197 ! Note no need to write time variable here; it is done in writediagsoil. 184 198 199 endif ! of if (is_master) 200 185 201 ! 3. Other variables to be included 186 202 187 203 ! 3.1 mesh area surrounding each horizontal point 204 if (is_master) then 188 205 ierr=NF_REDEF(nid) ! switch to NetCDF define mode 189 206 … … 219 236 endif 220 237 238 endif ! of if (is_master) 239 240 221 241 ! 3.2 Thermal inertia 242 if (is_master) then 222 243 ierr=NF_REDEF(nid) ! switch to NetCDF define mode 223 244 … … 241 262 ierr=NF_PUT_ATT_TEXT(nid,varid,"units",len_trim(text),text) 242 263 264 endif !of if (is_master) 265 243 266 ! Recast data along 'dynamics' grid 267 #ifdef CPP_PARA 268 ! gather field on a "global" (without redundant longitude) array 269 call Gather(inertiedat,dx3_glop) 270 !$OMP MASTER 271 if (is_mpi_root) then 272 call Grid1Dto2D_glo(dx3_glop,dx3_glo) 273 ! copy dx3_glo() to dx3(:) and add redundant longitude 274 data3(1:iim,:,:)=dx3_glo(1:iim,:,:) 275 data3(iip1,:,:)=data3(1,:,:) 276 endif 277 !$OMP END MASTER 278 !$OMP BARRIER 279 #else 244 280 ! Note: inertiedat is known from comsoil.h 245 246 281 do l=1,nsoilmx 247 282 ! handle the poles … … 250 285 data3(i,jjp1,l)=inertiedat(ngrid,l) 251 286 enddo 252 !!! THIS WILL NOT WORK IN PARALLEL !!!!253 287 ! rest of the grid 254 288 do j=2,jjm … … 260 294 enddo 261 295 enddo ! of do l=1,nsoilmx 262 263 ! Write data2 to file 264 ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode 265 ! Write 266 #ifdef NC_DOUBLE 267 ierr=NF_PUT_VAR_DOUBLE(nid,varid,data3) 268 #else 269 ierr=NF_PUT_VAR_REAL(nid,varid,data3) 270 #endif 271 if (ierr.ne.NF_NOERR) then 296 #endif 297 298 ! Write data3 to file 299 if (is_master) then 300 ierr=NF_ENDDEF(nid) ! switch out of NetCDF define mode 301 ! Write 302 #ifdef NC_DOUBLE 303 ierr=NF_PUT_VAR_DOUBLE(nid,varid,data3) 304 #else 305 ierr=NF_PUT_VAR_REAL(nid,varid,data3) 306 #endif 307 if (ierr.ne.NF_NOERR) then 272 308 write(*,*)"iniwritesoil: Error, could not write th_inertia variable" 273 endif 309 endif 310 endif ! of if (is_master) 274 311 275 312 end subroutine iniwritesoil -
trunk/LMDZ.GENERIC/libf/phystd/mkstat.F90
r135 r965 9 9 ! Yann W. july 2003 10 10 11 #ifdef CPP_PARA 12 use mod_phys_lmdz_para, only : is_master 13 #endif 11 14 12 15 implicit none … … 32 35 integer :: meanid,sdid 33 36 !integer, dimension(4) :: dimout 37 #ifndef CPP_PARA 38 logical,parameter :: is_master=.true. 39 #endif 34 40 35 41 ! Incrementation of count for the last step, which is not done in wstats 36 42 count(istime)=count(istime)+1 43 44 if (is_master) then 45 ! only the master needs do this 37 46 38 47 ierr = NF_OPEN("stats.nc",NF_WRITE,nid) … … 161 170 ierr= NF_CLOSE(nid) 162 171 172 endif ! of if (is_master) 173 163 174 end -
trunk/LMDZ.GENERIC/libf/phystd/physiq.F90
r961 r965 1686 1686 call writediagfi(ngrid,"p","Pressure","Pa",3,pplay) 1687 1687 1688 ! Subsurface temperatures 1689 call writediagsoil(ngrid,"tsurf","Surface temperature","K",2,tsurf) 1690 call writediagsoil(ngrid,"temp","temperature","K",3,tsoil) 1691 1688 1692 ! Total energy balance diagnostics 1689 1693 if(callrad.and.(.not.newtonian))then -
trunk/LMDZ.GENERIC/libf/phystd/writediagfi.F
r862 r965 41 41 42 42 USE surfdat_h 43 43 #ifdef CPP_PARA 44 USE mod_phys_lmdz_para, only : is_parallel, is_mpi_root, 45 & is_master, gather 46 USE mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 47 #endif 44 48 implicit none 45 49 … … 70 74 real*4,save :: date 71 75 72 REAL phis(ip1jmp1) 76 REAL phis(ip1jmp1) ! surface geopotential on extended lonxlat grid 73 77 74 78 integer irythme … … 99 103 integer dimvert 100 104 105 #ifdef CPP_PARA 106 ! Added to work in parallel mode 107 real dx3_glop(klon_glo,llm) 108 real dx3_glo(iim,jjp1,llm) ! to store a global 3D data set 109 real dx2_glop(klon_glo) 110 real dx2_glo(iim,jjp1) ! to store a global 2D (surface) data set 111 real px2(ngrid) 112 ! real dx1_glo(llm) ! to store a 1D (column) data set 113 ! real dx0_glo 114 real phisfi_glo(klon_glo) ! surface geopotential on global physics grid 115 #else 116 logical,parameter :: is_parallel=.false. 117 logical,parameter :: is_master=.true. 118 logical,parameter :: is_mpi_root=.true. 119 real phisfi_glo(ngrid) ! surface geopotential on global physics grid 120 #endif 101 121 !*************************************************************** 102 122 !Sortie des variables au rythme voulu … … 170 190 171 191 #ifdef CPP_PARA 192 ! Gather phisfi() geopotential on physics grid 193 call Gather(phisfi,phisfi_glo) 194 #else 195 phisfi_glo(:)=phisfi(:) 196 #endif 197 172 198 !! parallel: we cannot use the usual writediagfi method 173 call iophys_ini 174 #else 199 !! call iophys_ini 200 if (is_master) then 201 ! only the master is required to do this 202 175 203 ! Create the NetCDF file 176 204 ierr = NF_CREATE(fichnom, NF_CLOBBER, nid) … … 193 221 194 222 ! write "header" of file (longitudes, latitudes, geopotential, ...) 195 call gr_fi_dyn(1, ngrid,iip1,jjp1,phisfi,phis)223 call gr_fi_dyn(1,size(phisfi_glo),iip1,jjp1,phisfi_glo,phis) 196 224 call iniwrite(nid,day_ini,phis) 197 225 226 endif ! of if (is_master) 227 198 228 else 199 ! Open the NetCDF file 200 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 201 #endif 229 230 if (is_master) then 231 ! only the master is required to do this 232 233 ! Open the NetCDF file 234 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 235 endif ! of if (is_master) 236 202 237 endif ! if (firstnom.eq.'1234567890') 203 238 … … 223 258 if ( MOD(zitau+1,irythme) .eq.0.) then 224 259 225 #ifdef CPP_PARA226 !! parallel: we cannot use the usual writediagfi method227 if (dim .eq. 2) then228 dimvert = 1229 else if (dim == 3) then230 dimvert = llm231 endif232 call iophys_ecrit(nom,dimvert,titre,unite,px)233 #else260 !#ifdef CPP_PARA 261 ! !! parallel: we cannot use the usual writediagfi method 262 ! if (dim .eq. 2) then 263 ! dimvert = 1 264 ! else if (dim == 3) then 265 ! dimvert = llm 266 ! endif 267 ! call iophys_ecrit(nom,dimvert,titre,unite,px) 268 !#else 234 269 235 270 ! Compute/write/extend 'Time' coordinate (date given in days) … … 238 273 !-------------------------------------------------------- 239 274 275 if (is_master) then 276 ! only the master is required to do this 240 277 if (nom.eq.firstnom) then 241 278 ! We have identified a "first call" (at given date) … … 261 298 end if ! of if (nom.eq.firstnom) 262 299 300 endif ! of if (is_master) 301 263 302 !Case of a 3D variable 264 303 !--------------------- 265 304 if (dim.eq.3) then 266 305 306 #ifdef CPP_PARA 307 ! Gather field on a "global" (without redundant longitude) array 308 call Gather(px,dx3_glop) 309 !$OMP MASTER 310 if (is_mpi_root) then 311 call Grid1Dto2D_glo(dx3_glop,dx3_glo) 312 ! copy dx3_glo() to dx3(:) and add redundant longitude 313 dx3(1:iim,:,:)=dx3_glo(1:iim,:,:) 314 dx3(iip1,:,:)=dx3(1,:,:) 315 endif 316 !$OMP END MASTER 317 !$OMP BARRIER 318 #else 267 319 ! Passage variable physique --> variable dynamique 268 320 ! recast (copy) variable from physics grid to dynamics grid … … 280 332 ENDDO 281 333 ENDDO 282 334 #endif 283 335 ! Ecriture du champs 284 336 285 ! write (*,*) 'In writediagfi, on sauve: ' , nom 286 ! write (*,*) 'In writediagfi. Estimated date = ' ,date 337 if (is_master) then 338 ! only the master writes to output 287 339 ! name of the variable 288 340 ierr= NF_INQ_VARID(nid,nom,varid) … … 314 366 ! ierr= NF_PUT_VARA_DOUBLE(nid,varid,corner,edges,dx3) 315 367 !#else 368 ! write(*,*)"test: nid=",nid," varid=",varid 369 ! write(*,*)" corner()=",corner 370 ! write(*,*)" edges()=",edges 371 ! write(*,*)" dx3()=",dx3 316 372 ierr= NF_PUT_VARA_REAL(nid,varid,corner,edges,dx3) 317 373 !#endif … … 320 376 write(*,*) "***** PUT_VAR problem in writediagfi" 321 377 write(*,*) "***** with ",nom 322 write(*,*) 'ierr=', ierr 378 write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr) 323 379 c call abort 324 380 endif 325 381 382 endif !of if (is_master) 383 326 384 !Case of a 2D variable 327 385 !--------------------- 328 386 329 387 else if (dim.eq.2) then 388 389 #ifdef CPP_PARA 390 ! Gather field on a "global" (without redundant longitude) array 391 px2(:)=px(:,1) 392 call Gather(px2,dx2_glop) 393 !$OMP MASTER 394 if (is_mpi_root) then 395 call Grid1Dto2D_glo(dx2_glop,dx2_glo) 396 ! copy dx2_glo() to dx2(:) and add redundant longitude 397 dx2(1:iim,:)=dx2_glo(1:iim,:) 398 dx2(iip1,:)=dx2(1,:) 399 endif 400 !$OMP END MASTER 401 !$OMP BARRIER 402 #else 330 403 331 404 ! Passage variable physique --> physique dynamique … … 343 416 dx2(iip1,j)=dx2(1,j) 344 417 ENDDO 345 418 #endif 419 420 if (is_master) then 421 ! only the master writes to output 346 422 ! write (*,*) 'In writediagfi, on sauve: ' , nom 347 423 ! write (*,*) 'In writediagfi. Estimated date = ' ,date … … 379 455 write(*,*) "***** PUT_VAR matter in writediagfi" 380 456 write(*,*) "***** with ",nom 381 write(*,*) 'ierr=', ierr 457 write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr) 382 458 c call abort 383 459 endif 384 460 461 endif !of if (is_master) 462 385 463 !Case of a 1D variable (ie: a column) 386 464 !--------------------------------------------------- 387 465 388 466 else if (dim.eq.1) then 467 if (is_parallel) then 468 write(*,*) "writediagfi error: dim=1 not implemented ", 469 & "in parallel mode" 470 stop 471 endif 389 472 ! Passage variable physique --> physique dynamique 390 473 ! recast (copy) variable from physics grid to dynamics grid … … 430 513 431 514 else if (dim.eq.0) then 515 if (is_parallel) then 516 write(*,*) "writediagfi error: dim=0 not implemented ", 517 & "in parallel mode" 518 stop 519 endif 520 432 521 dx0 = px (1,1) 433 522 … … 462 551 463 552 endif ! of if (dim.eq.3) elseif(dim.eq.2)... 464 #endif465 553 466 554 endif ! of if ( MOD(zitau+1,irythme) .eq.0.) 467 555 468 #ifndef CPP_PARA 469 ierr= NF_CLOSE(nid)470 #endif556 if (is_master) then 557 ierr= NF_CLOSE(nid) 558 endif 471 559 472 560 end 561 -
trunk/LMDZ.GENERIC/libf/phystd/writediagsoil.F90
r787 r965 10 10 ! (yielding the sought time series of the variable) 11 11 12 use comsoil_h 12 #ifdef CPP_PARA 13 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather 14 use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 15 #endif 13 16 14 17 implicit none … … 31 34 32 35 ! Local variables: 33 real,dimension(iip1,jjp1,nsoilmx) :: data3 ! to store 3D data 36 real,dimension(iip1,jjp1,nsoilmx) :: data3 ! to store 3D data on extended lonxlat grid 34 37 ! Note iip1,jjp1 known from paramet.h; nsoilmx known from dimphys.h 35 real,dimension(iip1,jjp1) :: data2 ! to store 2D data 38 real,dimension(iip1,jjp1) :: data2 ! to store 2D data on extended lonxlat grid 36 39 real :: data0 ! to store 0D data 37 40 integer :: i,j,l ! for loops … … 53 56 integer,dimension(4) :: edges,corners 54 57 58 #ifdef CPP_PARA 59 ! Added to work in parallel mode 60 real dx3_glop(klon_glo,nsoilmx) 61 real dx3_glo(iim,jjp1,nsoilmx) ! to store a global 3D data set 62 real dx2_glop(klon_glo) 63 real dx2_glo(iim,jjp1) ! to store a global 2D (surface) data set 64 real px2(ngrid) 65 #else 66 logical,parameter :: is_master=.true. 67 logical,parameter :: is_mpi_root=.true. 68 #endif 69 55 70 ! 1. Initialization step 56 71 if (firstname.eq."1234567890") then … … 72 87 73 88 ! Create output NetCDF file 74 ierr=NF_CREATE(filename,NF_CLOBBER,nid) 75 if (ierr.ne.NF_NOERR) then 89 if (is_master) then 90 ierr=NF_CREATE(filename,NF_CLOBBER,nid) 91 if (ierr.ne.NF_NOERR) then 76 92 write(*,*)'writediagsoil: Error, failed creating file '//trim(filename) 77 93 stop 78 endif 79 94 endif 95 endif ! of if (is_master) 96 80 97 ! Define dimensions and axis attributes 81 98 call iniwritesoil(nid,ngrid) … … 86 103 else 87 104 ! If not an initialization call, simply open the NetCDF file 88 ierr=NF_OPEN(filename,NF_WRITE,nid) 105 if (is_master) then 106 ierr=NF_OPEN(filename,NF_WRITE,nid) 107 endif 89 108 endif ! of if (firstname.eq."1234567890") 90 109 … … 105 124 ! Note: day_step is known from control.h 106 125 107 ! Get NetCDF ID for "time" 108 ierr=NF_INQ_VARID(nid,"time",varid) 109 ! Add the current value of date to the "time" array 126 if (is_master) then 127 ! Get NetCDF ID for "time" 128 ierr=NF_INQ_VARID(nid,"time",varid) 129 ! Add the current value of date to the "time" array 110 130 #ifdef NC_DOUBLE 111 ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)112 #else 113 ierr=NF_PUT_VARA_REAL(nid,varid,ntime,1,date)114 #endif 115 if (ierr.ne.NF_NOERR) then131 ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date) 132 #else 133 ierr=NF_PUT_VARA_REAL(nid,varid,ntime,1,date) 134 #endif 135 if (ierr.ne.NF_NOERR) then 116 136 write(*,*)"writediagsoil: Failed writing date to time variable" 117 137 stop 118 endif 138 endif 139 endif ! of if (is_master) 119 140 endif ! of if (name.eq.firstname) 120 141 … … 122 143 if (dimpx.eq.3) then ! Case of a 3D variable 123 144 ! A. Recast data along 'dynamics' grid 145 #ifdef CPP_PARA 146 ! gather field on a "global" (without redundant longitude) array 147 call Gather(px,dx3_glop) 148 !$OMP MASTER 149 if (is_mpi_root) then 150 call Grid1Dto2D_glo(dx3_glop,dx3_glo) 151 ! copy dx3_glo() to dx3(:) and add redundant longitude 152 data3(1:iim,:,:)=dx3_glo(1:iim,:,:) 153 data3(iip1,:,:)=data3(1,:,:) 154 endif 155 !$OMP END MASTER 156 !$OMP BARRIER 157 #else 124 158 do l=1,nsoilmx 125 159 ! handle the poles … … 137 171 enddo 138 172 enddo 173 #endif 139 174 140 175 ! B. Write (append) the variable to the NetCDF file 176 if (is_master) then 141 177 ! B.1. Get the ID of the variable 142 178 ierr=NF_INQ_VARID(nid,name,varid) … … 176 212 " to file "//trim(filename)//" at time",date 177 213 endif 214 endif ! of if (is_master) 178 215 179 216 elseif (dimpx.eq.2) then ! Case of a 2D variable 217 180 218 ! A. Recast data along 'dynamics' grid 219 #ifdef CPP_PARA 220 ! gather field on a "global" (without redundant longitude) array 221 px2(:)=px(:,1) 222 call Gather(px2,dx2_glop) 223 !$OMP MASTER 224 if (is_mpi_root) then 225 call Grid1Dto2D_glo(dx2_glop,dx2_glo) 226 ! copy dx3_glo() to dx3(:) and add redundant longitude 227 data2(1:iim,:)=dx2_glo(1:iim,:) 228 data2(iip1,:)=data2(1,:) 229 endif 230 !$OMP END MASTER 231 !$OMP BARRIER 232 #else 181 233 ! handle the poles 182 234 do i=1,iip1 … … 192 244 data2(iip1,j)=data2(1,j) ! extra (modulo) longitude 193 245 enddo 246 #endif 194 247 195 248 ! B. Write (append) the variable to the NetCDF file 249 if (is_master) then 196 250 ! B.1. Get the ID of the variable 197 251 ierr=NF_INQ_VARID(nid,name,varid) … … 228 282 " to file "//trim(filename)//" at time",date 229 283 endif 284 endif ! of if (is_master) 230 285 231 286 elseif (dimpx.eq.0) then ! Case of a 0D variable 287 #ifdef CPP_PARA 288 write(*,*) "writediagsoil: dimps==0 case not implemented in // mode!!" 289 stop 290 #endif 232 291 ! A. Copy data value 233 292 data0=px(1,1) … … 267 326 268 327 ! 4. Close the NetCDF file 269 ierr=NF_CLOSE(nid) 328 if (is_master) then 329 ierr=NF_CLOSE(nid) 330 endif 270 331 271 332 end subroutine writediagsoil -
trunk/LMDZ.GENERIC/libf/phystd/writediagspecIR.F
r787 r965 1 subroutine writediagspecIR(ngrid,nom,titre,unite,dim ,px)1 subroutine writediagspecIR(ngrid,nom,titre,unite,dimpx,px) 2 2 3 3 ! Ecriture de variables diagnostiques au choix dans la physique … … 32 32 ! unite : unite de la variable (chaine de caracteres) 33 33 ! px : variable a sortir (real 0, 2, ou 3d) 34 ! dim : dimension de px : 0, 2, ou 3 dimensions34 ! dimpx : dimension de px : 0, 2, ou 3 dimensions 35 35 ! 36 36 !================================================================= … … 43 43 ! Addition by RW (2010) to allow OLR to be saved in .nc format 44 44 use radinc_h, only : L_NSPECTI 45 USE surfdat_h 45 ! USE surfdat_h, only : phisfi 46 #ifdef CPP_PARA 47 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather 48 use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 49 #endif 46 50 47 51 implicit none … … 60 64 61 65 ! Arguments on input: 62 integer ngrid63 character (len=*) :: nom,titre,unite64 integer dim65 real px(ngrid,L_NSPECTI)66 integer,intent(in) :: ngrid 67 character (len=*),intent(in) :: nom,titre,unite 68 integer,intent(in) :: dimpx 69 real,intent(in) :: px(ngrid,L_NSPECTI) 66 70 67 71 ! Local variables: … … 73 77 real date 74 78 75 REAL phis(ip1jmp1)79 ! REAL phis(ip1jmp1) 76 80 77 81 integer irythme … … 99 103 real dx3(iip1,jjp1,L_NSPECTI) ! to store the data set 100 104 105 #ifdef CPP_PARA 106 ! Added to work in parallel mode 107 real dx3_glop(klon_glo,L_NSPECTI) 108 real dx3_glo(iim,jjp1,L_NSPECTI) ! to store a global 3D data set 109 #else 110 logical,parameter :: is_master=.true. 111 logical,parameter :: is_mpi_root=.true. 112 #endif 101 113 102 114 !*************************************************************** … … 109 121 110 122 !*************************************************************** 111 112 ! The following test is here to enforce that writediagfi is not used with the113 ! 1D version of the GCM114 !not anymore (JL12)115 if (ngrid.eq.-1) return116 117 c nom=trim((nom))118 c unite=trim((unite))119 c titre=trim((titre))120 123 121 124 ! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file … … 130 133 ! just to be sure, check that firstnom is large enough to hold nom 131 134 if (len_trim(firstnom).lt.len_trim(nom)) then 132 write(*,*) "writediag fi: Error !!!"135 write(*,*) "writediagspecIR: Error !!!" 133 136 write(*,*) " firstnom string not long enough!!" 134 137 write(*,*) " increase its size to at least ",len_trim(nom) … … 137 140 138 141 ! Create the NetCDF file 142 if (is_master) then 139 143 ierr = NF_CREATE(fichnom, NF_CLOBBER, nid) 140 144 ! Define the 'Time' dimension … … 155 159 ierr = NF_ENDDEF(nid) 156 160 157 ! write "header" of file (longitudes, latitudes, geopotential, ...)158 call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)159 ! call iniwrite(nid,day_ini,phis)160 call iniwrite_specIR(nid,day_ini,phis)161 ! call gr_fi_dyn(1,size(phisfi_glo),iip1,jjp1,phisfi_glo,phis) 162 ! write "header" of file (longitudes, latitudes, area, ...) 163 call iniwrite_specIR(nid,day_ini) 164 endif ! of if (is_master) 161 165 162 166 zitau = -1 ! initialize zitau 163 167 else 164 ! Open the NetCDF file 165 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 168 if (is_master) then 169 ! Open the NetCDF file 170 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 171 endif 166 172 endif ! if (firstnom.eq.'1234567890') 167 173 … … 191 197 ! compute corresponding date (in days and fractions thereof) 192 198 date= float (zitau +1)/float (day_step) 193 ! Get NetCDF ID of 'Time' variable 194 i err= NF_INQ_VARID(nid,"Time",varid)195 196 !print*,'in writediagfi_spec.F, time=',varid197 198 ! Write (append) the new date to the 'Time' array199 200 if (is_master) then 201 ! Get NetCDF ID of 'Time' variable 202 ierr= NF_INQ_VARID(nid,"Time",varid) 203 204 ! Write (append) the new date to the 'Time' array 199 205 #ifdef NC_DOUBLE 200 ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)201 #else 202 ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)203 #endif 204 if (ierr.ne.NF_NOERR) then206 ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date) 207 #else 208 ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date) 209 #endif 210 if (ierr.ne.NF_NOERR) then 205 211 write(*,*) "***** PUT_VAR matter in writediagspec_nc" 206 212 write(*,*) "***** with time" 207 213 write(*,*) 'ierr=', ierr 208 214 c call abort 209 endif 210 211 write(6,*)'WRITEDIAGSPEC: date= ', date 215 endif 216 217 write(6,*)'WRITEDIAGSPEC: date= ', date 218 endif ! of if (is_master) 212 219 end if ! of if (nom.eq.firstnom) 213 220 … … 216 223 !Case of a 3D variable 217 224 !--------------------- 218 if (dim.eq.3) then 219 220 ! recast (copy) variable from physics grid to dynamics grid 225 if (dimpx.eq.3) then 226 227 ! A. Recast (copy) variable from physics grid to dynamics grid 228 #ifdef CPP_PARA 229 ! gather field on a "global" (without redundant longitude) array 230 call Gather(px,dx3_glop) 231 !$OMP MASTER 232 if (is_mpi_root) then 233 call Grid1Dto2D_glo(dx3_glop,dx3_glo) 234 ! copy dx3_glo() to dx3(:) and add redundant longitude 235 dx3(1:iim,:,:)=dx3_glo(1:iim,:,:) 236 dx3(iip1,:,:)=dx3(1,:,:) 237 endif 238 !$OMP END MASTER 239 !$OMP BARRIER 240 #else 221 241 DO l=1,L_NSPECTI 222 242 DO i=1,iip1 … … 232 252 ENDDO 233 253 ENDDO 254 #endif 255 256 ! B. Write (append) the variable to the NetCDF file 257 if (is_master) then 234 258 235 259 ! name of the variable … … 245 269 246 270 write (*,*) "==========================" 247 write (*,*) "DIAGSPEC : creating variable ",nom271 write (*,*) "DIAGSPECIR: creating variable ",nom 248 272 call def_var(nid,nom,titre,unite,4,id,varid,ierr) 249 273 … … 272 296 endif 273 297 274 endif ! of if (dim.eq.3) elseif(dim.eq.2)... 298 endif ! of if (is_master) 299 300 endif ! of if (dimpx.eq.3) 275 301 276 302 endif ! of if ( MOD(zitau+1,irythme) .eq.0.) 277 303 278 ierr= NF_CLOSE(nid) 304 ! Close the NetCDF file 305 if (is_master) then 306 ierr= NF_CLOSE(nid) 307 endif 279 308 280 309 end -
trunk/LMDZ.GENERIC/libf/phystd/writediagspecVI.F
r787 r965 1 subroutine writediagspecVI(ngrid,nom,titre,unite,dim ,px)1 subroutine writediagspecVI(ngrid,nom,titre,unite,dimpx,px) 2 2 3 3 ! Ecriture de variables diagnostiques au choix dans la physique … … 32 32 ! unite : unite de la variable (chaine de caracteres) 33 33 ! px : variable a sortir (real 0, 2, ou 3d) 34 ! dim : dimension de px : 0, 2, ou 3 dimensions34 ! dimpx : dimension de px : 0, 2, ou 3 dimensions 35 35 ! 36 36 !================================================================= … … 43 43 ! Addition by RW (2010) to allow OSR to be saved in .nc format 44 44 use radinc_h, only : L_NSPECTV 45 USE surfdat_h 45 ! USE surfdat_h 46 #ifdef CPP_PARA 47 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather 48 use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 49 #endif 46 50 47 51 implicit none … … 62 66 integer ngrid 63 67 character (len=*) :: nom,titre,unite 64 integer dim 68 integer dimpx 65 69 real px(ngrid,L_NSPECTV) 66 70 … … 73 77 real date 74 78 75 REAL phis(ip1jmp1)79 ! REAL phis(ip1jmp1) 76 80 77 81 integer irythme … … 99 103 real dx3(iip1,jjp1,L_NSPECTV) ! to store the data set 100 104 105 #ifdef CPP_PARA 106 ! Added to work in parallel mode 107 real dx3_glop(klon_glo,L_NSPECTV) 108 real dx3_glo(iim,jjp1,L_NSPECTV) ! to store a global 3D data set 109 #else 110 logical,parameter :: is_master=.true. 111 logical,parameter :: is_mpi_root=.true. 112 #endif 101 113 102 114 !*************************************************************** … … 108 120 109 121 !*************************************************************** 110 111 ! The following test is here to enforce that writediagfi is not used with the112 ! 1D version of the GCM113 !not anymore (JL12)114 if (ngrid.eq.-1) return115 116 c nom=trim((nom))117 c unite=trim((unite))118 c titre=trim((titre))119 122 120 123 ! Initialisation of 'firstnom' and create/open the "diagfi.nc" NetCDF file … … 136 139 137 140 ! Create the NetCDF file 141 if (is_master) then 138 142 ierr = NF_CREATE(fichnom, NF_CLOBBER, nid) 139 143 ! Define the 'Time' dimension … … 155 159 156 160 ! write "header" of file (longitudes, latitudes, geopotential, ...) 157 call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis)161 ! call gr_fi_dyn(1,ngrid,iip1,jjp1,phisfi,phis) 158 162 ! call iniwrite(nid,day_ini,phis) 159 call iniwrite_specVI(nid,day_ini,phis) 163 call iniwrite_specVI(nid,day_ini) 164 endif ! of if (is_master) 160 165 161 166 zitau = -1 ! initialize zitau 162 167 else 163 ! Open the NetCDF file 164 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 168 if (is_master) then 169 ! Open the NetCDF file 170 ierr = NF_OPEN(fichnom,NF_WRITE,nid) 171 endif 165 172 endif ! if (firstnom.eq.'1234567890') 166 173 … … 190 197 ! compute corresponding date (in days and fractions thereof) 191 198 date= float (zitau +1)/float (day_step) 192 ! Get NetCDF ID of 'Time' variable 193 i err= NF_INQ_VARID(nid,"Time",varid)194 195 !print*,'in writediagfi_spec.F, time=',varid196 197 ! Write (append) the new date to the 'Time' array199 200 if (is_master) then 201 ! Get NetCDF ID of 'Time' variable 202 ierr= NF_INQ_VARID(nid,"Time",varid) 203 204 ! Write (append) the new date to the 'Time' array 198 205 #ifdef NC_DOUBLE 199 ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)200 #else 201 ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date)202 #endif 203 if (ierr.ne.NF_NOERR) then206 ierr= NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date) 207 #else 208 ierr= NF_PUT_VARA_REAL(nid,varid,ntime,1,date) 209 #endif 210 if (ierr.ne.NF_NOERR) then 204 211 write(*,*) "***** PUT_VAR matter in writediagspec_nc" 205 212 write(*,*) "***** with time" 206 213 write(*,*) 'ierr=', ierr 207 214 c call abort 208 endif 209 210 write(6,*)'WRITEDIAGSPEC: date= ', date 215 endif 216 217 write(6,*)'WRITEDIAGSPEC: date= ', date 218 endif ! of if (is_master) 211 219 end if ! of if (nom.eq.firstnom) 212 220 … … 215 223 !Case of a 3D variable 216 224 !--------------------- 217 if (dim.eq.3) then 218 219 ! recast (copy) variable from physics grid to dynamics grid 225 if (dimpx.eq.3) then 226 227 ! A. Recast (copy) variable from physics grid to dynamics grid 228 #ifdef CPP_PARA 229 ! gather field on a "global" (without redundant longitude) array 230 call Gather(px,dx3_glop) 231 !$OMP MASTER 232 if (is_mpi_root) then 233 call Grid1Dto2D_glo(dx3_glop,dx3_glo) 234 ! copy dx3_glo() to dx3(:) and add redundant longitude 235 dx3(1:iim,:,:)=dx3_glo(1:iim,:,:) 236 dx3(iip1,:,:)=dx3(1,:,:) 237 endif 238 !$OMP END MASTER 239 !$OMP BARRIER 240 #else 220 241 DO l=1,L_NSPECTV 221 242 DO i=1,iip1 … … 231 252 ENDDO 232 253 ENDDO 254 #endif 255 256 ! B. Write (append) the variable to the NetCDF file 257 if (is_master) then 233 258 234 259 ! name of the variable … … 271 296 endif 272 297 273 endif ! of if (dim.eq.3) elseif(dim.eq.2)... 298 endif ! of if (is_master) 299 300 endif ! of if (dimpx.eq.3) 274 301 275 302 endif ! of if ( MOD(zitau+1,irythme) .eq.0.) 276 303 277 ierr= NF_CLOSE(nid) 304 ! Close the NetCDF file 305 if (is_master) then 306 ierr= NF_CLOSE(nid) 307 endif 278 308 279 309 end -
trunk/LMDZ.GENERIC/libf/phystd/wstats.F90
r135 r965 1 1 subroutine wstats(ngrid,nom,titre,unite,dim,px) 2 3 #ifdef CPP_PARA 4 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather, klon_mpi_begin 5 use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo 6 #endif 2 7 3 8 implicit none … … 5 10 #include "dimensions.h" 6 11 #include "dimphys.h" 12 #include "comconst.h" 7 13 #include "statto.h" 8 14 #include "netcdf.inc" 9 15 10 16 integer,intent(in) :: ngrid 11 character (len=*) :: nom,titre,unite17 character (len=*),intent(in) :: nom,titre,unite 12 18 integer,intent(in) :: dim 13 19 integer,parameter :: iip1=iim+1 14 20 integer,parameter :: jjp1=jjm+1 15 real, dimension(ngrid,llm) :: px21 real,intent(in) :: px(ngrid,llm) 16 22 real, dimension(iip1,jjp1,llm) :: mean3d,sd3d,dx3 17 23 real, dimension(iip1,jjp1) :: mean2d,sd2d,dx2 … … 20 26 integer :: ierr,varid,nbdim,nid 21 27 integer :: meanid,sdid 22 integer, dimension(4) :: id,start,size 28 integer, dimension(4) :: id,start,sizes 23 29 logical, save :: firstcall=.TRUE. 24 30 integer :: l,i,j,ig0 25 integer,save :: ind ex31 integer,save :: indx 26 32 27 33 integer, save :: step=0 28 34 29 35 ! Added to work in parallel mode 36 #ifdef CPP_PARA 37 real px3_glop(klon_glo,llm) ! to store a 3D data set on global physics grid 38 real px3_glo(iim,jjp1,llm) ! to store a global 3D data set on global lonxlat grid 39 real px2_glop(klon_glo) ! to store a 2D data set on global physics grid 40 real px2_glo(iim,jjp1) ! to store a 2D data set on global lonxlat grid 41 real px2(ngrid) 42 real px3(ngrid,llm) 43 #else 44 ! When not running in parallel mode: 45 real px3_glop(ngrid,llm) ! to store a 3D data set on global physics grid 46 real px3_glo(iim,jjp1,llm) ! to store a global 3D data set on global lonxlat grid 47 real px2_glop(ngrid) ! to store a 2D data set on global physics grid 48 real px2_glo(iim,jjp1) ! to store a 2D data set on global lonxlat grid 49 logical,parameter :: is_master=.true. 50 logical,parameter :: is_mpi_root=.true. 51 integer,parameter :: klon_mpi_begin=1 52 #endif 53 54 ! 1. Initialization (creation of stats.nc file) 30 55 if (firstcall) then 31 56 firstcall=.false. … … 34 59 endif 35 60 36 if (firstvar==nom) then ! If we're back to the first variable 61 if (firstvar==nom) then ! If we're back to the first variable, increment time counter 37 62 step = step + 1 38 63 endif 39 64 40 65 if (mod(step,istats).ne.0) then 66 ! if its not time to write to file, exit 41 67 RETURN 42 68 endif 43 69 70 ! collect fields on a global physics grid 71 #ifdef CPP_PARA 72 if (dim.eq.3) then 73 px3(1:ngrid,1:llm)=px(1:ngrid,1:llm) 74 ! Gather fieds on a "global" (without redundant longitude) array 75 call Gather(px3,px3_glop) 76 !$OMP MASTER 77 if (is_mpi_root) then 78 call Grid1Dto2D_glo(px3_glop,px3_glo) 79 ! copy dx3_glo() to dx3(:) and add redundant longitude 80 dx3(1:iim,:,:)=px3_glo(1:iim,:,:) 81 dx3(iip1,:,:)=dx3(1,:,:) 82 endif 83 !$OMP END MASTER 84 !$OMP BARRIER 85 else ! dim.eq.2 86 ! Gather fieds on a "global" (without redundant longitude) array 87 px2(:)=px(:,1) 88 call Gather(px2,px2_glop) 89 !$OMP MASTER 90 if (is_mpi_root) then 91 call Grid1Dto2D_glo(px2_glop,px2_glo) 92 ! copy px2_glo() to dx2(:) and add redundant longitude 93 dx2(1:iim,:)=px2_glo(1:iim,:) 94 dx2(iip1,:)=dx2(1,:) 95 endif 96 !$OMP END MASTER 97 !$OMP BARRIER 98 endif 99 #else 100 if (dim.eq.3) then 101 px3_glop(:,1:llm)=px(:,1:llm) 102 ! Passage variable physique --> variable dynamique 103 DO l=1,llm 104 DO i=1,iim 105 px3_glo(i,1,l)=px(1,l) 106 px3_glo(i,jjp1,l)=px(ngrid,l) 107 ENDDO 108 DO j=2,jjm 109 ig0= 1+(j-2)*iim 110 DO i=1,iim 111 px3_glo(i,j,l)=px(ig0+i,l) 112 ENDDO 113 ENDDO 114 ENDDO 115 else ! dim.eq.2 116 px2_glop(:)=px(:,1) 117 ! Passage variable physique --> physique dynamique 118 DO i=1,iim 119 px2_glo(i,1)=px(1,1) 120 px2_glo(i,jjp1)=px(ngrid,1) 121 ENDDO 122 DO j=2,jjm 123 ig0= 1+(j-2)*iim 124 DO i=1,iim 125 px2_glo(i,j)=px(ig0+i,1) 126 ENDDO 127 ENDDO 128 endif 129 #endif 130 131 ! 2. Write field to file 132 133 if (is_master) then 134 ! only master needs do this 135 44 136 ierr = NF_OPEN("stats.nc",NF_WRITE,nid) 45 137 46 138 namebis=trim(nom) 139 140 ! test: check if that variable already exists in file 47 141 ierr= NF_INQ_VARID(nid,namebis,meanid) 48 142 49 143 if (ierr.ne.NF_NOERR) then 50 144 ! variable not in file, create/define it 51 145 if (firstvar==nom) then 52 ind ex=153 count =0146 indx=1 147 count(:)=0 54 148 endif 55 149 … … 73 167 namebis=trim(nom) 74 168 call def_var(nid,namebis,titre,unite,nbdim,id,meanid,ierr) 75 call inivar(nid,meanid,ngrid,dim,index,px,ierr) 169 if (dim.eq.3) then 170 call inivar(nid,meanid,size(px3_glop,1),dim,indx,px3_glop,ierr) 171 else ! dim.eq.2 172 call inivar(nid,meanid,size(px2_glop,1),dim,indx,px2_glop,ierr) 173 endif 76 174 namebis=trim(nom)//"_sd" 77 175 call def_var(nid,namebis,trim(titre)//" total standard deviation over the season",unite,nbdim,id,sdid,ierr) 78 call inivar(nid,sdid,ngrid,dim,index,px,ierr) 176 if (dim.eq.3) then 177 call inivar(nid,sdid,size(px3_glop,1),dim,indx,px3_glop,ierr) 178 else ! dim.eq.2 179 call inivar(nid,sdid,size(px2_glop,1),dim,indx,px2_glop,ierr) 180 endif 79 181 80 182 ierr= NF_CLOSE(nid) … … 82 184 83 185 else 186 ! variable found in file 84 187 namebis=trim(nom)//"_sd" 85 188 ierr= NF_INQ_VARID(nid,namebis,sdid) … … 88 191 89 192 if (firstvar==nom) then 90 count(index)=count(int(index))+1 91 index=index+1 92 if (index>istime) then 93 index=1 94 endif 95 endif 96 97 if (count(index)==0) then 98 if (dim.eq.3) then 99 start=(/1,1,1,index/) 100 size=(/iip1,jjp1,llm,1/) 101 mean3d=0 102 sd3d=0 193 count(indx)=count(int(indx))+1 194 indx=indx+1 195 if (indx>istime) then 196 indx=1 197 endif 198 endif 199 200 if (count(indx)==0) then 201 ! very first time we write the variable to file 202 if (dim.eq.3) then 203 start=(/1,1,1,indx/) 204 sizes=(/iip1,jjp1,llm,1/) 205 mean3d(:,:,:)=0 206 sd3d(:,:,:)=0 103 207 else if (dim.eq.2) then 104 start=(/1,1,ind ex,0/)105 size =(/iip1,jjp1,1,0/)106 mean2d =0107 sd2d =0208 start=(/1,1,indx,0/) 209 sizes=(/iip1,jjp1,1,0/) 210 mean2d(:,:)=0 211 sd2d(:,:)=0 108 212 endif 109 213 else 110 if (dim.eq.3) then 111 start=(/1,1,1,index/) 112 size=(/iip1,jjp1,llm,1/) 113 #ifdef NC_DOUBLE 114 ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size,mean3d) 115 ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size,sd3d) 116 #else 117 ierr = NF_GET_VARA_REAL(nid,meanid,start,size,mean3d) 118 ierr = NF_GET_VARA_REAL(nid,sdid,start,size,sd3d) 214 ! load values from file 215 if (dim.eq.3) then 216 start=(/1,1,1,indx/) 217 sizes=(/iip1,jjp1,llm,1/) 218 #ifdef NC_DOUBLE 219 ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean3d) 220 ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,sizes,sd3d) 221 #else 222 ierr = NF_GET_VARA_REAL(nid,meanid,start,sizes,mean3d) 223 ierr = NF_GET_VARA_REAL(nid,sdid,start,sizes,sd3d) 119 224 #endif 120 225 if (ierr.ne.NF_NOERR) then … … 124 229 125 230 else if (dim.eq.2) then 126 start=(/1,1,ind ex,0/)127 size =(/iip1,jjp1,1,0/)128 #ifdef NC_DOUBLE 129 ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,size ,mean2d)130 ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,size ,sd2d)131 #else 132 ierr = NF_GET_VARA_REAL(nid,meanid,start,size ,mean2d)133 ierr = NF_GET_VARA_REAL(nid,sdid,start,size ,sd2d)231 start=(/1,1,indx,0/) 232 sizes=(/iip1,jjp1,1,0/) 233 #ifdef NC_DOUBLE 234 ierr = NF_GET_VARA_DOUBLE(nid,meanid,start,sizes,mean2d) 235 ierr = NF_GET_VARA_DOUBLE(nid,sdid,start,sizes,sd2d) 236 #else 237 ierr = NF_GET_VARA_REAL(nid,meanid,start,sizes,mean2d) 238 ierr = NF_GET_VARA_REAL(nid,sdid,start,sizes,sd2d) 134 239 #endif 135 240 if (ierr.ne.NF_NOERR) then … … 138 243 endif 139 244 endif 140 endif 245 endif ! of if (count(indx)==0) 246 247 248 ! 2.1. Build dx* (data on lon-lat grid, with redundant longitude) 141 249 142 250 if (dim.eq.3) then 251 dx3(1:iim,:,:)=px3_glo(:,:,:) 252 dx3(iip1,:,:)=dx3(1,:,:) 253 else ! dim.eq.2 254 dx2(1:iim,:)=px2_glo(:,:) 255 dx2(iip1,:)=dx2(1,:) 256 endif 257 258 259 ! 2.2. Add current values to previously stored sums 260 261 if (dim.eq.3) then 262 263 mean3d(:,:,:)=mean3d(:,:,:)+dx3(:,:,:) 264 sd3d(:,:,:)=sd3d(:,:,:)+dx3(:,:,:)**2 265 266 #ifdef NC_DOUBLE 267 ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,sizes,mean3d) 268 ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,sizes,sd3d) 269 #else 270 ierr = NF_PUT_VARA_REAL(nid,meanid,start,sizes,mean3d) 271 ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd3d) 272 #endif 273 274 else if (dim.eq.2) then 275 276 mean2d(:,:)= mean2d(:,:)+dx2(:,:) 277 sd2d(:,:)=sd2d(:,:)+dx2(:,:)**2 278 279 #ifdef NC_DOUBLE 280 ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,sizes,mean2d) 281 ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,sizes,sd2d) 282 #else 283 ierr = NF_PUT_VARA_REAL(nid,meanid,start,sizes,mean2d) 284 ierr = NF_PUT_VARA_REAL(nid,sdid,start,sizes,sd2d) 285 #endif 286 287 endif ! of if (dim.eq.3) elseif (dim.eq.2) 288 289 ierr= NF_CLOSE(nid) 290 endif ! of if (is_master) 291 292 end 293 294 !====================================================== 295 subroutine inivar(nid,varid,ngrid,dim,indx,px,ierr) 296 297 implicit none 298 299 include "dimensions.h" 300 include "dimphys.h" 301 include "netcdf.inc" 302 303 integer, intent(in) :: nid,varid,dim,indx,ngrid 304 real, dimension(ngrid,llm), intent(in) :: px 305 integer, intent(out) :: ierr 306 307 integer,parameter :: iip1=iim+1 308 integer,parameter :: jjp1=jjm+1 309 310 integer :: l,i,j,ig0 311 integer, dimension(4) :: start,sizes 312 real, dimension(iip1,jjp1,llm) :: dx3 313 real, dimension(iip1,jjp1) :: dx2 314 315 if (dim.eq.3) then 316 317 start=(/1,1,1,indx/) 318 sizes=(/iip1,jjp1,llm,1/) 143 319 144 320 ! Passage variable physique --> variable dynamique … … 158 334 ENDDO 159 335 160 mean3d= mean3d+dx3 161 sd3d= sd3d+dx3**2 162 163 #ifdef NC_DOUBLE 164 ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean3d) 165 ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd3d) 166 #else 167 ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean3d) 168 ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd3d) 336 #ifdef NC_DOUBLE 337 ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx3) 338 #else 339 ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx3) 169 340 #endif 170 341 171 342 else if (dim.eq.2) then 343 344 start=(/1,1,indx,0/) 345 sizes=(/iip1,jjp1,1,0/) 172 346 173 347 ! Passage variable physique --> physique dynamique … … 185 359 ENDDO 186 360 187 mean2d= mean2d+dx2 188 sd2d= sd2d+dx2**2 189 190 #ifdef NC_DOUBLE 191 ierr = NF_PUT_VARA_DOUBLE(nid,meanid,start,size,mean2d) 192 ierr = NF_PUT_VARA_DOUBLE(nid,sdid,start,size,sd2d) 193 #else 194 ierr = NF_PUT_VARA_REAL(nid,meanid,start,size,mean2d) 195 ierr = NF_PUT_VARA_REAL(nid,sdid,start,size,sd2d) 196 #endif 197 198 endif 199 200 ierr= NF_CLOSE(nid) 361 #ifdef NC_DOUBLE 362 ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,sizes,dx2) 363 #else 364 ierr = NF_PUT_VARA_REAL(nid,varid,start,sizes,dx2) 365 #endif 366 367 endif 201 368 202 369 end 203 204 !======================================================205 subroutine inivar(nid,varid,ngrid,dim,index,px,ierr)206 207 implicit none208 209 include "dimensions.h"210 include "dimphys.h"211 include "netcdf.inc"212 213 integer, intent(in) :: nid,varid,dim,index,ngrid214 real, dimension(ngrid,llm), intent(in) :: px215 integer, intent(out) :: ierr216 217 integer,parameter :: iip1=iim+1218 integer,parameter :: jjp1=jjm+1219 220 integer :: l,i,j,ig0221 integer, dimension(4) :: start,size222 real, dimension(iip1,jjp1,llm) :: dx3223 real, dimension(iip1,jjp1) :: dx2224 225 if (dim.eq.3) then226 227 start=(/1,1,1,index/)228 size=(/iip1,jjp1,llm,1/)229 230 ! Passage variable physique --> variable dynamique231 232 DO l=1,llm233 DO i=1,iip1234 dx3(i,1,l)=px(1,l)235 dx3(i,jjp1,l)=px(ngrid,l)236 ENDDO237 DO j=2,jjm238 ig0= 1+(j-2)*iim239 DO i=1,iim240 dx3(i,j,l)=px(ig0+i,l)241 ENDDO242 dx3(iip1,j,l)=dx3(1,j,l)243 ENDDO244 ENDDO245 246 #ifdef NC_DOUBLE247 ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx3)248 #else249 ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx3)250 #endif251 252 else if (dim.eq.2) then253 254 start=(/1,1,index,0/)255 size=(/iip1,jjp1,1,0/)256 257 ! Passage variable physique --> physique dynamique258 259 DO i=1,iip1260 dx2(i,1)=px(1,1)261 dx2(i,jjp1)=px(ngrid,1)262 ENDDO263 DO j=2,jjm264 ig0= 1+(j-2)*iim265 DO i=1,iim266 dx2(i,j)=px(ig0+i,1)267 ENDDO268 dx2(iip1,j)=dx2(1,j)269 ENDDO270 271 #ifdef NC_DOUBLE272 ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,size,dx2)273 #else274 ierr = NF_PUT_VARA_REAL(nid,varid,start,size,dx2)275 #endif276 277 endif278 279 end
Note: See TracChangeset
for help on using the changeset viewer.