source: trunk/LMDZ.GENERIC/libf/phystd/setspv.F90 @ 3990

Last change on this file since 3990 was 3990, checked in by emillour, 5 days ago

Generic PCM:
OpenMP bug fix in ave_stelspec.F90 (line counting strategy should only be done
by the master thread). While at it turned ave_stelspec and setspv into modules.
EM

File size: 4.2 KB
RevLine 
[3990]1      module setspv_mod
2     
3      implicit none
4     
5      contains
6     
[135]7      subroutine setspv
8
9!==================================================================
10!     
11!     Purpose
12!     -------
[3654]13!     Set up spectral intervals and stellar spectrum in the shortwave.
[135]14!     
15!     Authors
16!     -------
17!     Adapted from setspv in the NASA Ames radiative code by
18!     Robin Wordsworth (2009).
19!
20!     Called by
21!     ---------
22!     callcorrk.F
23!     
24!     Calls
25!     -----
26!     ave_stelspec.F
27!     
28!==================================================================
29
30      use radinc_h,    only: L_NSPECTV, corrkdir, banddir
31      use radcommon_h, only: BWNV,BLAMV,WNOV,DWNV,WAVEV, &
[3654]32                             STELLARF
[374]33      use datafile_mod, only: datadir
[3654]34      use callkeys_mod, only: Fat1AU
[3990]35      use ave_stelspec_mod, only: ave_stelspec
[135]36
37      implicit none
38
39      logical file_ok
40
41      integer N, M, file_entries
42
43      character(len=30)  :: temp1
[716]44      character(len=200) :: file_id
45      character(len=200) :: file_path
[135]46
47      real*8 :: lastband(2)
48
49      real*8 STELLAR(L_NSPECTV)
[989]50      real*8 sum, dummy
[135]51
[789]52      !! used to count lines
[997]53      integer :: nb
54      integer :: ierr
[789]55
[135]56!=======================================================================
57!     Set up spectral bands - wavenumber [cm^(-1)]. Go from smaller to
58!     larger wavenumbers, the same as in the IR.
59
60      write(temp1,'(i2.2)') L_NSPECTV
61      file_id='/corrk_data/'//trim(adjustl(banddir))//'/narrowbands_VI.in'
[374]62      file_path=TRIM(datadir)//TRIM(file_id)
[135]63
64      ! check that the file exists
65      inquire(FILE=file_path,EXIST=file_ok)
66      if(.not.file_ok) then
[374]67         write(*,*)'The file ',TRIM(file_path)
[135]68         write(*,*)'was not found by setspv.F90, exiting.'
[374]69         write(*,*)'Check that your path to datagcm:',trim(datadir)
70         write(*,*)' is correct. You can change it in callphys.def with:'
71         write(*,*)' datadir = /absolute/path/to/datagcm'
72         write(*,*)'Also check that the corrkdir you chose in callphys.def exists.'
[3893]73         call abort_physic("setspv", "Unable to read file",1)
[135]74      endif
[1315]75       
76!$OMP MASTER       
[997]77      nb=0
78      ierr=0
[789]79      ! check that the file contains the right number of bands
80      open(131,file=file_path,form='formatted')
[989]81      read(131,*,iostat=ierr) file_entries
[789]82      do while (ierr==0)
[989]83        read(131,*,iostat=ierr) dummy
[789]84        if (ierr==0) nb=nb+1
85      enddo
[135]86      close(131)
[989]87
[789]88      write(*,*) 'setspv: L_NSPECTV = ',L_NSPECTV, 'in the model '
89      write(*,*) '        there are   ',nb, 'entries in ',TRIM(file_path)
90      if(nb.ne.L_NSPECTV) then
91         write(*,*) 'MISMATCH !! I stop here'
[3893]92         call abort_physic("setspv","The number of entries in narrowbands_VI.in does not match with L_NSPECTV",1)
[135]93      endif
94
95      ! load and display the data
96      open(111,file=file_path,form='formatted')
97      read(111,*)
98       do M=1,L_NSPECTV-1
99         read(111,*) BWNV(M)
100      end do
101      read(111,*) lastband
102      close(111)
103      BWNV(L_NSPECTV)  =lastband(1)
104      BWNV(L_NSPECTV+1)=lastband(2)
[1315]105!$OMP END MASTER
106!$OMP BARRIER
[135]107
[374]108      print*,'setspv: VI band limits:'
[135]109      do M=1,L_NSPECTV+1
110         print*,m,'-->',BWNV(M),' cm^-1'
111      end do
112      print*,' '
113
114!     Set up mean wavenumbers and wavenumber deltas.  Units of
115!     wavenumbers is cm^(-1); units of wavelengths is microns.
116
117      do M=1,L_NSPECTV
118         WNOV(M)  = 0.5*(BWNV(M+1)+BWNV(M))
119         DWNV(M)  = BWNV(M+1)-BWNV(M)
120         WAVEV(M) = 1.0E+4/WNOV(M)
121         BLAMV(M) = 0.01/BWNV(M)
122      end do
123      BLAMV(M) = 0.01/BWNV(M) ! wavelength in METERS for aerosol stuff
124!     note M=L_NSPECTV+1 after loop due to Fortran bizarreness
125
126!=======================================================================
127!     Set up stellar spectrum
128
[374]129      write(*,*)'setspv: Interpolating stellar spectrum from the hires data...'
[253]130      call ave_stelspec(STELLAR)
[135]131
132!     Sum the stellar flux, and write out the result. 
133      sum = 0.0 
134      do N=1,L_NSPECTV
135         STELLARF(N) = STELLAR(N) * Fat1AU
136         sum         = sum+STELLARF(N)
137      end do
[2831]138      write(6,'("setspv: Stellar flux at 1 AU = ",f9.2," W m-2")') sum
[135]139      print*,' '
140
141    END subroutine setspv
[3990]142   
143    end module setspv_mod
144   
Note: See TracBrowser for help on using the repository browser.