***************************************************************** * PROGRAM: cmap_pen_rt_def_anom_v0712.lnx.f * * LANGUAGE: Fortran77 * * MACHINE: Any LINUX BOX *----------------------------------------------------------------* * PURPOSE: to define anomaly fields for the real-time pentad CMAP *----------------------------------------------------------------* * USAGE: *----------------------------------------------------------------* * INPUT FILES: Unit 10 == current pentad identification * 20 == pentad climatology * 30 == yearly file of pentad CMAP *----------------------------------------------------------------* * OUTPUT FILES: Unit 50 == yearly file of pentad CMAP anomaly *----------------------------------------------------------------* * SUBROUTINES USED: NONE * * FUNCTIONS USED: (all Standard Fortran 77 functions) * *----------------------------------------------------------------* * INPUT VARIABLES: kyy == year of the target date * kmm == month of the target date * kdd == day of the target date * kjj == Julian Day * * LOCAL VARIABLES: * rain == pentad rainfall * clim == pentad climatology * anom == pentad anomaly * *----------------------------------------------------------------* * DATE 2007-12-09 *----------------------------------------------------------------* * MODIFICATIONS: *----------------------------------------------------------------* c=====|==|=========|=========|=========|=========|=========|=========|== c program CMAP_def_anom_2_5deg implicit none integer NX, NY parameter( NX=144, NY=72 ) character yyyymmdd*8, f_clim*45, f_cmap*57, f_anom*61 integer yyyy, mm, dd, days(12), leap, m, jjj, ddd, pen, ii, jj real clim(NX,NY), rain(NX,NY), anom(NX,NY) data days / 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 / c----------------------------------------------------------------------- c check parameter c----------------------------------------------------------------------- if( iargc().lt.1 ) then write(*, *) write(*, *) '#################################' write(*, *) '# #' write(*, *) '# parameter needed #' write(*, *) '# #' write(*, *) '#################################' write(*, *) stop endif c----------------------------------------------------------------------- c get target date c----------------------------------------------------------------------- call getarg(1, yyyymmdd) read(yyyymmdd, '(i4.4,2i2.2)') yyyy, mm, dd c----------------------------------------------------------------------- c adjust for leap-year c----------------------------------------------------------------------- if( mod(yyyy,4).eq.0 ) days(2)=29 if( mod(yyyy,100).eq.0 ) days(2)=28 if( mod(yyyy,400).eq.0 ) days(2)=29 if( days(2).eq.29 ) then leap=1 else leap=0 endif c----------------------------------------------------------------------- c calculate Julian day of target date c----------------------------------------------------------------------- jjj=dd do m=1, mm-1 jjj=jjj+days(m) enddo c----------------------------------------------------------------------- c determine the pentad c----------------------------------------------------------------------- if( jjj.le.59 ) then ddd=jjj else ddd=jjj-leap endif if( mod(ddd,5).ne.0 ) then write(*, *) '## NOT end of pentad: ', yyyy, mm, dd, jjj stop endif pen=ddd/5 write(*, *) yyyy, mm, dd, jjj, ' pentad: ', pen c----------------------------------------------------------------------- c construct file names c----------------------------------------------------------------------- c------------>123456789|123456789|123456789|1234<-- c f_clim='../library/cmap_pen_clim_79-98.lnx' c-------------------------------------------- c switch to 1991-2020 climo --2021.05.27 S.Wu c-------------------------------------------- c------------>123456789|123456789|123456789|123456789|12345<-- f_clim='../library/cmapo_pen_v2104_clim_1991-2020.lnx' c------------>123456789|123456789|123456789|123456789|123456789|1234567<-- f_cmap='../output/CMAP_PEN_RT/yyyy/cmap_pen_rt_v0011_out.lnx.yyyy' write(f_cmap(23:26), '(i4.4)') yyyy write(f_cmap(54:57), '(i4.4)') yyyy c------------------->123456789|123456789|123456789|123456789|<-- f_anom( 1:40)='../output/CMAP_PEN_RT/yyyy/cmap_pen_rt_v' f_anom(41:61)='0011_out_ano.lnx.yyyy' write(f_anom(23:26), '(i4.4)') yyyy write(f_anom(58:61), '(i4.4)') yyyy c----------------------------------------------------------------------- c read in CMAP and climatology c----------------------------------------------------------------------- open(10, file=f_clim, status='old', 1 access='direct', recl=NX*NY*4) open(11, file=f_cmap, status='old', 1 access='direct', recl=NX*NY*4) read(10, rec=pen) clim read(11, rec=pen) rain close(10) close(11) write(*, *) ' <-- ', f_clim, clim(72,36) write(*, *) ' <-- ', f_cmap, rain(72,36) c----------------------------------------------------------------------- c define anomaly c----------------------------------------------------------------------- do jj=1, NY do ii=1, NX if( clim(ii,jj).ge.0.0.and. 1 rain(ii,jj).ge.0.0 ) then anom(ii,jj)=rain(ii,jj)-clim(ii,jj) else anom(ii,jj)=-999.0 endif enddo enddo c----------------------------------------------------------------------- c output c----------------------------------------------------------------------- open(20, file=f_anom, access='direct', recl=NX*NY*4) write(20, rec=pen) anom close(20) write(*, *) ' ==> ', f_anom, anom(72,36) stop end c c=====|==|=========|=========|=========|=========|=========|=========|==