source: codes/icosagcm/trunk/src/disvert_apbp.f90 @ 210

Last change on this file since 210 was 210, checked in by ymipsl, 10 years ago

Find automatically a free unit when trying to open a file.
Unit 42 has a big chance to be connected to an other file....

YM

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1MODULE disvert_apbp_mod
2  USE icosa
3  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: ap(:)
4!$OMP THREADPRIVATE(ap)
5  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: bp(:)
6!$OMP THREADPRIVATE(bp)
7  REAL(rstd), SAVE, ALLOCATABLE,TARGET :: presnivs(:)
8!$OMP THREADPRIVATE(presnivs)
9
10CONTAINS
11
12  SUBROUTINE init_disvert
13!  USE icosa
14  IMPLICIT NONE
15 
16    ALLOCATE(ap(llm+1))
17    ALLOCATE(bp(llm+1))
18    ALLOCATE(presnivs(llm))
19
20    CALL disvert(ap,bp,presnivs)   
21
22  END SUBROUTINE init_disvert 
23
24
25  SUBROUTINE disvert(ap,bp,presnivs)
26!  USE icosa
27  USE mpipara, ONLY: is_mpi_root
28  USE omp_para, ONLY: omp_in_parallel
29  USE transfert_omp_mod, ONLY: bcast_omp
30  USE free_unit_mod, ONLY : free_unit
31  IMPLICIT NONE
32  REAL(rstd),INTENT(OUT) :: ap(:)
33  REAL(rstd),INTENT(OUT) :: bp(:)
34  REAL(rstd),INTENT(OUT) :: presnivs(:)
35  INTEGER :: unit
36  CHARACTER(len=255) :: filename
37  INTEGER :: l,ok
38 
39    filename="apbp.txt" !file to read
40    ! but users may want to use some other file name
41    CALL getin('read_apbp_file',filename)
42   
43!$OMP MASTER
44    unit=free_unit()
45    OPEN(unit,file=filename,status="old",action="read",iostat=ok)
46    IF (ok/=0) THEN
47      WRITE(*,*) "disvert_ap_bp error: input file ",trim(filename)," not found!"
48      CALL ABORT
49    ENDIF
50    ! read in ap() and b() line by line, starting from surface up
51    ! to model top
52    DO l=1,llm+1
53      READ(unit,fmt=*,iostat=ok) ap(l),bp(l)
54      IF (ok/=0) THEN
55        WRITE(*,*) "disvert_ap_bp error: failed reading ap(l) and bp(l) for l=",l
56        CALL ABORT
57      ENDIF
58    ENDDO
59!$OMP END MASTER
60    IF (omp_in_parallel()) THEN
61      CALL bcast_omp(ap)
62      CALL bcast_omp(bp)
63    ENDIF
64   
65    ! build presnivs(), approximative mid-layer pressures
66    DO l=1,llm
67      presnivs(l)=0.5*(ap(l)+bp(l)*preff+ap(l+1)+bp(l+1)*preff)
68    ENDDO
69   
70    ! tell the world about it
71    IF (is_mpi_root) THEN
72!$OMP MASTER
73      WRITE(*,*) "ap()=",ap
74      WRITE(*,*) "bp()=",bp
75      WRITE(*,*) "Approximative mid-layer pressure, assuming a surface pressure preff=",preff," Pa"
76      WRITE(*,*) "and approximative mid-layer height, assuming an atmospheric scale height of ",scaleheight/1000," (km)"
77      DO l=1,llm
78        WRITE(*,*) 'PRESNIVS(',l,')=',presnivs(l),'  Z ~ ',log(preff/presnivs(l))*scaleheight/1000,       &
79                   ' DZ ~ ',scaleheight/1000*log((ap(l)+bp(l)*preff)/ max(ap(l+1)+bp(l+1)*preff,1.e-10))
80      ENDDO
81!$OMP END MASTER
82    ENDIF
83 
84  END SUBROUTINE disvert
85 
86END MODULE disvert_apbp_mod
Note: See TracBrowser for help on using the repository browser.