[135] | 1 | subroutine setspi |
---|
| 2 | |
---|
| 3 | !================================================================== |
---|
| 4 | ! |
---|
| 5 | ! Purpose |
---|
| 6 | ! ------- |
---|
| 7 | ! Set up spectral intervals and Planck function in the longwave. |
---|
| 8 | ! |
---|
| 9 | ! Authors |
---|
| 10 | ! ------- |
---|
| 11 | ! Adapted from setspi in the NASA Ames radiative code by |
---|
| 12 | ! Robin Wordsworth (2009). |
---|
| 13 | ! |
---|
| 14 | ! Called by |
---|
| 15 | ! --------- |
---|
| 16 | ! callcorrk.F |
---|
| 17 | ! |
---|
| 18 | ! Calls |
---|
| 19 | ! ----- |
---|
| 20 | ! none |
---|
| 21 | ! |
---|
| 22 | !================================================================== |
---|
| 23 | |
---|
[2283] | 24 | use radinc_h, only: L_NSPECTI,corrkdir,banddir,NTstart,NTstop,NTfac |
---|
[135] | 25 | use radcommon_h, only: BWNI,BLAMI,WNOI,DWNI,WAVEI,planckir,sigma |
---|
[374] | 26 | use datafile_mod, only: datadir |
---|
[1384] | 27 | use comcstfi_mod, only: pi |
---|
[135] | 28 | |
---|
| 29 | implicit none |
---|
| 30 | |
---|
| 31 | logical file_ok |
---|
| 32 | integer nw, nt, m, mm, file_entries |
---|
[989] | 33 | real*8 a, b, ans, y, bpa, bma, T, dummy |
---|
[135] | 34 | |
---|
| 35 | character(len=30) :: temp1 |
---|
[716] | 36 | character(len=200) :: file_id |
---|
| 37 | character(len=200) :: file_path |
---|
[135] | 38 | |
---|
| 39 | ! C1 and C2 values from Goody and Yung (2nd edition) MKS units |
---|
| 40 | ! These values lead to a "sigma" (sigma*T^4) of 5.67032E-8 W m^-2 K^-4 |
---|
| 41 | |
---|
| 42 | real*8 :: c1 = 3.741832D-16 ! W m^-2 |
---|
| 43 | real*8 :: c2 = 1.438786D-2 ! m K |
---|
| 44 | |
---|
| 45 | real*8 :: lastband(2), plancksum |
---|
| 46 | |
---|
[789] | 47 | !! used to count lines |
---|
[997] | 48 | integer :: nb |
---|
| 49 | integer :: ierr |
---|
[789] | 50 | |
---|
[135] | 51 | logical forceEC, planckcheck |
---|
| 52 | |
---|
| 53 | real*8 :: x(12) = [ -0.981560634246719D0, -0.904117256370475D0, & |
---|
| 54 | -0.769902674194305D0, -0.587317954286617D0, & |
---|
| 55 | -0.367831498998180D0, -0.125233408511469D0, & |
---|
| 56 | 0.125233408511469D0, 0.367831498998180D0, & |
---|
| 57 | 0.587317954286617D0, 0.769902674194305D0, & |
---|
| 58 | 0.904117256370475D0, 0.981560634246719D0 ] |
---|
| 59 | |
---|
| 60 | real*8 :: w(12) = [ 0.047175336386512D0, 0.106939325995318D0, & |
---|
| 61 | 0.160078328543346D0, 0.203167426723066D0, & |
---|
| 62 | 0.233492536538355D0, 0.249147045813403D0, & |
---|
| 63 | 0.249147045813403D0, 0.233492536538355D0, & |
---|
| 64 | 0.203167426723066D0, 0.160078328543346D0, & |
---|
| 65 | 0.106939325995318D0, 0.047175336386512D0 ] |
---|
| 66 | mm=0 |
---|
| 67 | |
---|
[959] | 68 | forceEC=.true. |
---|
[135] | 69 | planckcheck=.true. |
---|
| 70 | |
---|
| 71 | !======================================================================= |
---|
| 72 | ! Set up spectral bands - wavenumber [cm^(-1)]. Go from smaller to |
---|
| 73 | ! larger wavenumbers. |
---|
| 74 | |
---|
| 75 | write(temp1,'(i2.2)') L_NSPECTI |
---|
| 76 | !file_id='/corrk_data/' // corrkdir(1:LEN_TRIM(corrkdir)) // '/narrowbands_IR.in' |
---|
| 77 | file_id='/corrk_data/'//trim(adjustl(banddir))//'/narrowbands_IR.in' |
---|
[374] | 78 | file_path=TRIM(datadir)//TRIM(file_id) |
---|
[135] | 79 | |
---|
| 80 | ! check that the file exists |
---|
| 81 | inquire(FILE=file_path,EXIST=file_ok) |
---|
| 82 | if(.not.file_ok) then |
---|
[374] | 83 | write(*,*)'The file ',TRIM(file_path) |
---|
[135] | 84 | write(*,*)'was not found by setspi.F90, exiting.' |
---|
[374] | 85 | write(*,*)'Check that your path to datagcm:',trim(datadir) |
---|
| 86 | write(*,*)' is correct. You can change it in callphys.def with:' |
---|
| 87 | write(*,*)' datadir = /absolute/path/to/datagcm' |
---|
| 88 | write(*,*)'Also check that the corrkdir you chose in callphys.def exists.' |
---|
[135] | 89 | call abort |
---|
| 90 | endif |
---|
[789] | 91 | |
---|
[1315] | 92 | !$OMP MASTER |
---|
[997] | 93 | nb=0 |
---|
| 94 | ierr=0 |
---|
[789] | 95 | ! check that the file contains the right number of bands |
---|
| 96 | open(131,file=file_path,form='formatted') |
---|
[989] | 97 | read(131,*,iostat=ierr) file_entries |
---|
[789] | 98 | do while (ierr==0) |
---|
[989] | 99 | read(131,*,iostat=ierr) dummy |
---|
| 100 | ! write(*,*) 'setspi: file_entries:',dummy,'ierr=',ierr |
---|
[789] | 101 | if (ierr==0) nb=nb+1 |
---|
| 102 | enddo |
---|
[135] | 103 | close(131) |
---|
[989] | 104 | |
---|
[789] | 105 | write(*,*) 'setspi: L_NSPECTI = ',L_NSPECTI, 'in the model ' |
---|
| 106 | write(*,*) ' there are ',nb, 'entries in ',TRIM(file_path) |
---|
| 107 | if(nb.ne.L_NSPECTI) then |
---|
| 108 | write(*,*) 'MISMATCH !! I stop here' |
---|
[135] | 109 | call abort |
---|
| 110 | endif |
---|
| 111 | |
---|
| 112 | ! load and display the data |
---|
| 113 | open(111,file=file_path,form='formatted') |
---|
| 114 | read(111,*) |
---|
| 115 | do M=1,L_NSPECTI-1 |
---|
| 116 | read(111,*) BWNI(M) |
---|
| 117 | end do |
---|
| 118 | read(111,*) lastband |
---|
| 119 | close(111) |
---|
| 120 | BWNI(L_NSPECTI) =lastband(1) |
---|
| 121 | BWNI(L_NSPECTI+1)=lastband(2) |
---|
[1315] | 122 | !$OMP END MASTER |
---|
| 123 | !$OMP BARRIER |
---|
[135] | 124 | |
---|
| 125 | print*,'' |
---|
[374] | 126 | print*,'setspi: IR band limits:' |
---|
[135] | 127 | do M=1,L_NSPECTI+1 |
---|
| 128 | print*,m,'-->',BWNI(M),' cm^-1' |
---|
| 129 | end do |
---|
| 130 | |
---|
| 131 | ! Set up mean wavenumbers and wavenumber deltas. Units of |
---|
| 132 | ! wavenumbers is cm^(-1); units of wavelengths is microns. |
---|
| 133 | |
---|
| 134 | do M=1,L_NSPECTI |
---|
[961] | 135 | WNOI(M) = 0.5D0*(BWNI(M+1)+BWNI(M)) |
---|
[135] | 136 | DWNI(M) = BWNI(M+1)-BWNI(M) |
---|
[961] | 137 | WAVEI(M) = 1.0D+4/WNOI(M) |
---|
| 138 | BLAMI(M) = 0.01D0/BWNI(M) |
---|
[135] | 139 | end do |
---|
[961] | 140 | BLAMI(M) = 0.01D0/BWNI(M) |
---|
[135] | 141 | ! note M=L_NSPECTI+1 after loop due to Fortran bizarreness |
---|
| 142 | |
---|
| 143 | !======================================================================= |
---|
| 144 | ! For each IR wavelength interval, compute the integral of B(T), the |
---|
| 145 | ! Planck function, divided by the wavelength interval, in cm-1. The |
---|
| 146 | ! integration is in MKS units, the final answer is the same as the |
---|
| 147 | ! original planck.f; W m^-2 wavenumber^-1, where wavenumber is in CM^-1. |
---|
| 148 | |
---|
| 149 | print*,'' |
---|
[374] | 150 | print*,'setspi: Current Planck integration range:' |
---|
[2283] | 151 | print*,'T = ',dble(NTstart)/NTfac, ' to ',dble(NTstop)/NTfac,' K.' |
---|
[135] | 152 | |
---|
[2283] | 153 | IF(.NOT.ALLOCATED(planckir)) ALLOCATE(planckir(L_NSPECTI,NTstop-NTstart+1)) |
---|
| 154 | |
---|
[135] | 155 | do NW=1,L_NSPECTI |
---|
| 156 | a = 1.0D-2/BWNI(NW+1) |
---|
| 157 | b = 1.0D-2/BWNI(NW) |
---|
[961] | 158 | bpa = (b+a)/2.0D0 |
---|
| 159 | bma = (b-a)/2.0D0 |
---|
[2668] | 160 | ! if (nw .eq. 25) then !LT debug |
---|
| 161 | ! print*, "a = ",a |
---|
| 162 | ! print*, "b= ",b |
---|
| 163 | ! print*,"bpa = ",bpa |
---|
| 164 | ! print*, "bma = ",bma |
---|
| 165 | ! endif |
---|
[2283] | 166 | do nt=NTstart,NTstop |
---|
[543] | 167 | T = dble(NT)/NTfac |
---|
[135] | 168 | ans = 0.0D0 |
---|
| 169 | do mm=1,12 |
---|
| 170 | y = bma*x(mm)+bpa |
---|
[2668] | 171 | !to avoid floating overflow when T is low and optical wavelength |
---|
| 172 | if ((c2/(y*T)) .lt. 700.0D0) then |
---|
| 173 | ans = ans + w(mm)*c1/(y**5*(exp(c2/(y*T))-1.0D0)) |
---|
| 174 | else |
---|
| 175 | ans = ans +0.0D0 |
---|
| 176 | endif |
---|
[135] | 177 | end do |
---|
[2283] | 178 | planckir(NW,nt-NTstart+1) = ans*bma/(PI*DWNI(NW)) |
---|
[135] | 179 | end do |
---|
| 180 | end do |
---|
| 181 | |
---|
| 182 | ! force planck=sigma*eps*T^4 for each temperature in array |
---|
| 183 | if(forceEC)then |
---|
[374] | 184 | print*,'setspi: Force F=sigma*eps*T^4 for all values of T!' |
---|
[2283] | 185 | do nt=NTstart,NTstop |
---|
[961] | 186 | plancksum=0.0D0 |
---|
[543] | 187 | T=dble(NT)/NTfac |
---|
[135] | 188 | |
---|
| 189 | do NW=1,L_NSPECTI |
---|
| 190 | plancksum=plancksum+ & |
---|
[2283] | 191 | planckir(NW,nt-NTstart+1)*DWNI(NW)*pi |
---|
[135] | 192 | end do |
---|
| 193 | |
---|
| 194 | do NW=1,L_NSPECTI |
---|
[2283] | 195 | planckir(NW,nt-NTstart+1)= & |
---|
| 196 | planckir(NW,nt-NTstart+1)* & |
---|
[543] | 197 | sigma*(dble(nt)/NTfac)**4/plancksum |
---|
[135] | 198 | end do |
---|
| 199 | end do |
---|
| 200 | endif |
---|
| 201 | |
---|
| 202 | if(planckcheck)then |
---|
| 203 | ! check energy conservation at lower temperature boundary |
---|
[961] | 204 | plancksum=0.0D0 |
---|
[2283] | 205 | nt=NTstart |
---|
[135] | 206 | do NW=1,L_NSPECTI |
---|
[2283] | 207 | plancksum=plancksum+planckir(NW,nt-NTstart+1)*DWNI(NW)*pi |
---|
[135] | 208 | end do |
---|
[374] | 209 | print*,'setspi: At lower limit:' |
---|
[135] | 210 | print*,'in model sig*T^4 = ',plancksum,' W m^-2' |
---|
[543] | 211 | print*,'actual sig*T^4 = ',sigma*(dble(nt)/NTfac)**4,' W m^-2' |
---|
[135] | 212 | |
---|
| 213 | ! check energy conservation at upper temperature boundary |
---|
[961] | 214 | plancksum=0.0D0 |
---|
[135] | 215 | nt=NTstop |
---|
| 216 | do NW=1,L_NSPECTI |
---|
[2283] | 217 | plancksum=plancksum+planckir(NW,nt-NTstart+1)*DWNI(NW)*pi |
---|
[135] | 218 | end do |
---|
[374] | 219 | print*,'setspi: At upper limit:' |
---|
[135] | 220 | print*,'in model sig*T^4 = ',plancksum,' W m^-2' |
---|
[543] | 221 | print*,'actual sig*T^4 = ',sigma*(dble(nt)/NTfac)**4,' W m^-2' |
---|
[135] | 222 | print*,'' |
---|
| 223 | endif |
---|
| 224 | |
---|
| 225 | return |
---|
| 226 | end subroutine setspi |
---|