210 subroutine gas_init( mpicomm, mpirank, mpiroot, co2usr_file,
211 & co2cyc_file, ico2flg,
212 & ictmflg, con_pi, errflg, errmsg)
254 type(mpi_comm),
intent(in) :: mpicomm
255 integer,
intent(in) :: mpirank, mpiroot
256 integer,
intent(in) :: ictmflg, ico2flg
257 character(len=26),
intent(in) :: co2usr_file,co2cyc_file
258 real(kind=kind_phys),
intent(in) :: con_pi
261 character(len=*),
intent(out) :: errmsg
262 integer,
intent(out) :: errflg
265 real (kind=kind_phys),
dimension(IMXCO2,JMXCO2) :: co2dat
266 real (kind=kind_phys) :: co2g1, co2g2
268 integer :: i, j, k, iyr, imo
269 logical :: file_exist, lextpl
270 character :: cline*100, cform*8
271 data cform /
'(24f7.2)' /
282 raddeg = 180.0/con_pi
285 if ( mpirank==mpiroot ) print *, vtaggas
294 lab_ico2 :
if ( ico2flg == 0 )
then
296 if ( mpirank==mpiroot )
then
297 print *,
' - Using prescribed co2 global mean value=',
303 lab_ictm :
if ( ictmflg == -1 )
then
305 read_and_broadcast_co2_v1:
if ( mpirank==mpiroot )
then
306 inquire (file=co2usr_file, exist=file_exist)
307 if ( .not. file_exist )
then
308 print *,
' Can not find user CO2 data file: ',co2usr_file
310 errmsg =
'ERROR(gas_init): Cannot find user CO2 data file'
314 open(nico2cn,file=co2usr_file,form=
'formatted',
317 read (nico2cn, 25) iyr, cline, co2g1, co2g2
318 25
format(i4,a94,f7.2,16x,f5.2)
319 co2_glb = co2g1 * 1.0e-6
321 if ( ico2flg == 1 )
then
322 print *,
' - Using co2 global annual mean value from',
323 &
' user provided data set:',co2usr_file
324 print *, iyr,cline(1:94),co2g1,
' GROWTH RATE =', co2g2
325 elseif ( ico2flg == 2 )
then
326 allocate ( co2vmr_sav(imxco2,jmxco2,12) )
329 read (nico2cn,cform) co2dat
334 co2vmr_sav(i,j,imo) = co2dat(i,j) * 1.0e-6
339 print *,
' - Using co2 monthly 2-d data from user',
340 &
' provided data set:',co2usr_file
341 print *, iyr,cline(1:94),co2g1,
' GROWTH RATE =', co2g2
343 print *,
' CHECK: Sample of selected months of CO2 data'
345 print *,
' Month =',imo
346 print *, (co2vmr_sav(1,j,imo),j=1,jmxco2)
349 print *,
' ICO2=',ico2flg,
' is not a valid selection'
351 errmsg =
'ERROR(gas_init): ICO2 is not valid'
358 if ( ico2flg == 2 )
then
359 allocate ( co2vmr_sav(imxco2,jmxco2,12) )
361 endif read_and_broadcast_co2_v1
365 if ( ico2flg == 1 )
then
366 if ( mpirank==mpiroot )
then
367 print *,
' - Using observed co2 global annual mean value'
369 elseif ( ico2flg == 2 )
then
370 allocate ( co2vmr_sav(imxco2,jmxco2,12) )
371 if ( mpirank==mpiroot )
then
372 print *,
' - Using observed co2 monthly 2-d data'
375 print *,
' ICO2=',ico2flg,
' is not a valid selection'
377 errmsg =
'ERROR(gas_init): ICO2 is not a valid selection'
381 if ( ictmflg == -2 )
then
382 read_and_broadcast_co2_v2:
if ( mpirank==mpiroot )
then
383 inquire (file=co2cyc_file, exist=file_exist)
384 if ( .not. file_exist )
then
385 print *,
' Can not find seasonal cycle CO2 data: ',
388 errmsg =
'ERROR(gas_init): Can not find seasonal cycle '
392 allocate( co2cyc_sav(imxco2,jmxco2,12) )
396 open (nico2cn,file=co2cyc_file,form=
'formatted',
399 read (nico2cn, 35) cline, co2g1, co2g2
400 35
format(a98,f7.2,16x,f5.2)
401 read (nico2cn,cform) co2dat
403 print *,
' - Superimpose seasonal cycle to mean CO2 data'
404 print *,
' Opened CO2 climatology seasonal cycle data',
405 &
' file: ',co2cyc_file
409 read (nico2cn,45) cline, gco2cyc(imo)
412 gco2cyc(imo) = gco2cyc(imo) * 1.0e-6
414 read (nico2cn,cform) co2dat
418 co2cyc_sav(i,j,imo) = co2dat(i,j) * 1.0e-6
426 allocate( co2cyc_sav(imxco2,jmxco2,12) )
427 endif read_and_broadcast_co2_v2
434 call ccpp_bcast(co2_glb, mpiroot, mpicomm, ierr)
435 call ccpp_bcast(gco2cyc, mpiroot, mpicomm, ierr)
436 if (
allocated(co2vmr_sav))
then
437 call ccpp_bcast(co2vmr_sav, mpiroot, mpicomm, ierr)
439 if (
allocated(co2cyc_sav))
then
440 call ccpp_bcast(co2cyc_sav, mpiroot, mpicomm, ierr)
464 & mpicomm, mpirank, mpiroot, co2dat_file, co2gbl_file,
465 & ictmflg, ico2flg, errflg, errmsg )
519 integer,
intent(in) :: iyear, imon, iday, ihour
520 type(mpi_comm),
intent(in) :: mpicomm
521 integer,
intent(in) :: mpirank, mpiroot
522 integer,
intent(in) :: ictmflg,ico2flg
523 character(len=26),
intent(in) :: co2dat_file, co2gbl_file
524 logical,
intent(in) :: ldoco2
527 character(len=*),
intent(out) :: errmsg
528 integer,
intent(out) :: errflg
531 real (kind=kind_phys),
dimension(IMXCO2,JMXCO2) :: co2dat, co2ann
532 real (kind=kind_phys) :: co2g1, co2g2, rate
534 integer :: i, id, j, l, iyr, imo, iyr1, iyr2, jyr, idyr
535 integer,
save :: mdays(13), midmon=15, midm=15, midp=45
537 data mdays / 31,28,31,30,31,30,31,31,30,31,30,31,30 /
539 logical :: file_exist, lextpl, change
540 character :: cline*100, cform*8, cfile1*26
541 data cform /
'(24f7.2)' /
552 if ( ico2flg == 0 )
return
553 if ( ictmflg ==-1 )
return
554 if ( .not. ldoco2 )
return
556 if ( ictmflg < 0 )
then
560 lextpl = ( mod(ictmflg,10) == 1 )
562 if ( idyr == 0 ) idyr = iyear
568 if ( kyrsav == iyear )
return
576 lab_if_idyr :
if ( idyr < minyear .and. ictmflg > 0 )
then
578 read_and_broadcast_co2_v1:
if ( mpirank==mpiroot )
then
579 print *,
' Requested CO2 data year',iyear,
' earlier than',
581 print *,
' Which is the earliest monthly observation',
583 print *,
' Thus, historical global mean data is used'
587 inquire (file=co2gbl_file, exist=file_exist)
588 if ( .not. file_exist )
then
589 print *,
' Requested co2 data file "',co2gbl_file,
592 errmsg =
'ERROR(gas_update): Requested co2 data file not '//
597 open(nico2cn,file=co2gbl_file,form=
'formatted',status=
'old')
600 read (nico2cn, 24) iyr1, iyr2, cline
601 24
format(i4,4x,i4,a48)
603 print *,
' Opened co2 data file: ',co2gbl_file
606 if ( idyr < iyr1 )
then
614 lab_dowhile1 :
do while ( i >= iyr1 )
617 read (nico2cn, *) jyr, co2g1, co2g2
619 if ( i == iyr .and. iyr == jyr )
then
620 co2_glb = (co2g1+co2g2) * 0.5e-6
621 if ( ico2flg == 2 )
then
624 co2vmr_sav(i,j,1:6) = co2g1 * 1.0e-6
625 co2vmr_sav(i,j,7:12) = co2g2 * 1.0e-6
630 print *,
' Co2 data for year',iyear, co2_glb
640 endif read_and_broadcast_co2_v1
647 write(cfile1(19:22),34) idyr
651 read_and_broadcast_co2_v2:
if ( mpirank==mpiroot )
then
652 inquire (file=cfile1, exist=file_exist)
653 if ( .not. file_exist )
then
655 lab_if_ictm :
if ( ictmflg > 10 )
then
656 print *,
' Specified co2 data for year',idyr,
657 &
' not found !! Need to change namelist ICTM !!'
659 errmsg =
'ERROR(gas_update): Specified co2 data for year '
663 print *,
' Requested co2 data for year',idyr,
664 &
' not found, check for other available data set'
666 lab_dowhile2 :
do while ( iyr >= minyear )
668 write(cfile1(19:22),34) iyr
670 inquire (file=cfile1, exist=file_exist)
671 print *,
' Looking for CO2 file ',cfile1
673 if ( file_exist )
then
678 if ( .not. file_exist )
then
679 print *,
' Can not find co2 data source file'
681 errmsg =
'ERROR(gas_update): Can not find co2 data '//
691 open (nico2cn,file=cfile1,form=
'formatted',status=
'old')
693 read (nico2cn, 36) iyr, cline, co2g1, co2g2
694 36
format(i4,a94,f7.2,16x,f5.2)
696 print *,
' Opened co2 data file: ',cfile1
697 print *, iyr, cline(1:94), co2g1,
' GROWTH RATE =', co2g2
703 rate = 2.00 * (iyear - iyr)
708 co2_glb = (co2g1 + rate) * 1.0e-6
709 print *,
' Global annual mean CO2 data for year',
712 if ( ictmflg == -2 )
then
714 if ( ico2flg == 1 )
then
715 print *,
' CHECK: Monthly deviations of climatology ',
716 &
'to be superimposed on global annual mean'
718 elseif ( ico2flg == 2 )
then
722 read (nico2cn,cform) co2dat
727 co2ann(i,j) = co2ann(i,j) + co2dat(i,j)
734 co2ann(i,j) = co2ann(i,j) * 1.0e-6 / float(12)
741 co2vmr_sav(i,j,imo) = co2ann(i,j)+co2cyc_sav(i,j,imo)
746 print *,
' CHECK: Sample of 2-d annual mean of CO2 ',
747 &
'data used for year:',iyear
749 print *,
' CHECK: AFTER adding seasonal cycle, Sample ',
750 &
'of selected months of CO2 data for year:',iyear
752 print *,
' Month =',imo
753 print *, co2vmr_sav(1,:,imo)
759 if ( ico2flg == 2 )
then
761 read (nico2cn,cform) co2dat
766 co2vmr_sav(i,j,imo) = (co2dat(i,j) + rate) * 1.0e-6
771 print *,
' CHECK: Sample of selected months of CO2 ',
772 &
'data used for year:',iyear
774 print *,
' Month =',imo
775 print *, co2vmr_sav(1,:,imo)
784 endif read_and_broadcast_co2_v2
788 call ccpp_bcast(co2_glb, mpiroot, mpicomm, ierr)
789 call ccpp_bcast(gco2cyc, mpiroot, mpicomm, ierr)
790 if (
allocated(co2vmr_sav))
then
791 call ccpp_bcast(co2vmr_sav, mpiroot, mpicomm, ierr)
793 if (
allocated(co2cyc_sav))
then
794 call ccpp_bcast(co2cyc_sav, mpiroot, mpicomm, ierr)
834 subroutine getgases( plvl, xlon, xlat, IMAX, LMAX, ico2flg,
835 & top_at_1, con_pi, gasdat)
885 integer,
intent(in) :: imax, lmax, ico2flg
886 real (kind=kind_phys),
intent(in) :: plvl(:,:), xlon(:), xlat(:)
887 logical,
intent(in) :: top_at_1
888 real(kind=kind_phys),
intent(in) :: con_pi
891 real (kind=kind_phys),
intent(out) :: gasdat(:,:,:)
894 integer :: i, k, ilat, ilon
896 real (kind=kind_phys) :: xlon1, xlat1, tmp
904 gasdat(i,k,1) = co2vmr_def
905 gasdat(i,k,2) = n2ovmr_def
906 gasdat(i,k,3) = ch4vmr_def
907 gasdat(i,k,4) = o2vmr_def
908 gasdat(i,k,5) = covmr_def
909 gasdat(i,k,6) = f11vmr_def
910 gasdat(i,k,7) = f12vmr_def
911 gasdat(i,k,8) = f22vmr_def
912 gasdat(i,k,9) = cl4vmr_def
913 gasdat(i,k,10)= f113vmr_def
919 if ( ico2flg == 1 )
then
924 gasdat(i,k,1) = co2_glb + gco2cyc(kmonsav)
928 elseif ( ico2flg == 2 )
then
932 tmp = raddeg / resco2
936 if ( xlon1 < 0.0 ) xlon1 = xlon1 + con_pi
937 xlat1 = hfpi - xlat(i)
940 ilon = min( imxco2, int( xlon1*tmp + 1 ))
941 ilat = min( jmxco2, int( xlat1*tmp + 1 ))
945 if ( plvl(i,k) >= prsco2 )
then
946 gasdat(i,k,1) = co2vmr_sav(ilon,ilat,kmonsav)
948 gasdat(i,k,1) = co2_glb + gco2cyc(kmonsav)
953 if ( plvl(i,k+1) >= prsco2 )
then
954 gasdat(i,k,1) = co2vmr_sav(ilon,ilat,kmonsav)
956 gasdat(i,k,1) = co2_glb + gco2cyc(kmonsav)