Ignore:
Timestamp:
Oct 30, 2018 2:51:23 PM (3 years ago)
Author:
kanani
Message:

Reintegrated fixes/changes from branch chemistry

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/date_and_time_mod.f90

    r3298 r3458  
    1919!
    2020! Current revisions:
    21 ! -----------------
     21! ------------------
    2222!
    2323!
     
    2525! -----------------
    2626! $Id$
     27! from chemistry branch r3443, banzhafs:
     28! Added initial hour_of_day, hour_of_year, day_of_year and month_of_year to
     29! init_date_and_time
     30!
     31! 3298 2018-10-02 12:21:11Z kanani
    2732! - Minor formatting (kanani)
    2833! - Added Routines for DEFAULT mode of chemistry emissions (Russo)
     
    6166!>       already implemented changes for calculating it from date_init in
    6267!>       calc_date_and_time
     68!> @todo time_utc during spin-up 
    6369!------------------------------------------------------------------------------!
    6470 MODULE date_and_time_mod
     
    9197    INTEGER(iwp)        ::  index_mm                                !< index months of the default emission mode
    9298    INTEGER(iwp)        ::  index_dd                                !< index days of the default emission mode
    93     INTEGER(iwp)        ::  index_hh                                !< index hours of the default emission mode
     99    INTEGER(iwp)        ::  index_hh                                !< index hours of the emission mode
     100    INTEGER(iwp)        ::  hours_since_reference_point             !< hours of current simulation
    94101
    95102    REAL(wp)            ::  time_utc                     !< current model time in UTC
     
    102109    REAL(wp), PARAMETER ::  d_seconds_year = 1.0_wp / 31536000.0_wp !< inverse of the seconds per year (1/(365*86400))
    103110   
    104     CHARACTER(len=8)    ::  date_init = "31122018"                  !< Starting date of simulation: We selected this because it was a monday
     111    CHARACTER(len=8)    ::  date_init = "21062017"                  !< Starting date of simulation: We selected this because it was a monday
    105112 
    106113    !> --- Parameters
     
    121128    END INTERFACE time_default_indices
    122129
     130    !-- Get hour index in the PRE-PROCESSED case of chemistry emissions :
     131    INTERFACE time_preprocessed_indices
     132       MODULE PROCEDURE time_preprocessed_indices
     133    END INTERFACE time_preprocessed_indices
     134
     135
    123136    !-- Calculate current date and time
    124137    INTERFACE calc_date_and_time
     
    128141
    129142    !-- Public Interfaces
    130     PUBLIC calc_date_and_time, time_default_indices, init_date_and_time
     143    PUBLIC calc_date_and_time, time_default_indices, init_date_and_time, time_preprocessed_indices
    131144
    132145    !-- Public Variables
     
    147160       IMPLICIT NONE
    148161
     162       !--    Variables Definition
     163       INTEGER ::  i_mon       !< Index for going through the different months
     164
    149165       IF  (day_of_year_init == 0) THEN
    150166          ! Day of the month at starting time
     
    159175       ENDIF
    160176
    161     END SUBROUTINE init_date_and_time
    162 
    163 !------------------------------------------------------------------------------!
    164 ! Description:
    165 ! ------------
    166 !> Calculate current date and time of the simulation
    167 !------------------------------------------------------------------------------!
    168  
    169     SUBROUTINE calc_date_and_time
    170 
    171        IMPLICIT NONE
    172 
    173 !--    Variables Definition
    174        INTEGER                          :: i_mon       !< Index for going through the different months
    175 
    176        !> Update simulation time in seconds
    177        time_update = simulated_time-coupling_start_time
    178 
    179 !--    Calculate current day of the simulated time
    180        days_since_reference_point=INT(FLOOR( (time_utc_init + time_update) &
    181                                / 86400.0_wp ) )
    182 
    183 !--    Calculate actual UTC time                       
    184        time_utc = MOD((time_utc_init + time_since_reference_point), 86400.0_wp)
    185        
    186 !sB    PRILIMINARY workaround for time_utc bug concerning time_since_reference_point:
    187        time_utc_emis = MOD((time_utc_init + time_update), 86400.0_wp)     
    188 
    189 !--    Calculate initial day of the year: it is calculated only once. In fact, day_of_year_init is initialized to 0 and then a positive value is passed. This condition is also called only when day_of_year_init is not given in the namelist.
    190 
     177
     178       !-- Calculate initial hour of the day: the first hour of the day is from 00:00:00 to 00:59:59.
     179
     180       hour_of_day = INT( FLOOR( time_utc_init/3600.0_wp ) ) + 1
     181
     182       !-- Calculate initial day day_of_year_init in case date_init is given or day_of_year_init is given
    191183       IF ( day_of_year_init == 0 ) THEN
    192184
     
    214206       ENDIF
    215207
     208       
     209       !-- Initial day of the year
     210       day_of_year = day_of_year_init
     211
     212       !-- Initial hour of the year
     213       hour_of_year = ( (day_of_year-1) * 24 ) + hour_of_day
     214
     215       !--Initial day of the month and month of the year
     216       !> --------------------------------------------------------------------------------
     217       !> The first case is when date_init is not provided: we only know day_of_year_init     
     218       IF ( month_of_year == 0 .AND. day_of_month == 0) THEN
     219
     220         
     221          IF ( day_of_year .LE. 31 ) THEN
     222
     223             month_of_year=1
     224             day_of_month=day_of_year
     225
     226          ELSE
     227
     228             DO i_mon=2,12   !january is considered in the first case
     229                IF ( day_of_year .LE. SUM(days(1:i_mon)) .AND. day_of_year .GT. SUM(days(1:(i_mon-1))) ) THEN
     230           
     231                   month_of_year=i_mon
     232
     233                   day_of_month=INT(MOD(day_of_year, SUM(days(1:(i_mon-1)))))
     234
     235                   GOTO 38
     236
     237                ENDIF
     238
     239             38 ENDDO
     240          ENDIF
     241       !> --------------------------------------------------------------------------------
     242       !> in the second condition both day of month and month_of_year are either given in input (passed to date_init) or we are in some day successive to the initial one, so that day_of_month has already be computed in previous step
     243       !>TBD: something to calculate the current year is missing
     244       ELSEIF ( day_of_month .GT. 0 .AND. day_of_month .LE. 31 .AND. month_of_year .GT. 0 .AND. month_of_year .LE. 12) THEN
     245 
     246          !> calculate month_of_year. TBD: test the condition when day_of_year==31
     247 
     248          IF (day_of_year==1) THEN  !> this allows to turn from december to January when passing from a year to another
     249 
     250             month_of_year = 1
     251       
     252          ELSE IF (day_of_year .GT. 1 .AND. day_of_year .GT. SUM(days(1:month_of_year))) THEN
     253
     254             month_of_year = month_of_year + 1
     255
     256          ENDIF
     257
     258          !> calculate day_of_month
     259          IF ( month_of_year == 1 ) THEN
     260           
     261            day_of_month=day_of_year
     262
     263          ELSE
     264
     265            day_of_month=INT(MOD(day_of_year, SUM(days(1:(month_of_year-1)))))
     266
     267          ENDIF
     268
     269
     270       ELSE
     271
     272          !> Condition when date_init is provided but it is given in the wrong format
     273          message_string = 'date_init not provided in the namelist or'            //          &
     274                              ' given in the wrong format: MUST BE DDMMYYYY'                 
     275          CALL message( 'init_date_and_time', 'DT0102', 2, 2, 0, 6, 0 )
     276
     277       ENDIF
     278
     279
     280    END SUBROUTINE init_date_and_time
     281
     282!------------------------------------------------------------------------------!
     283! Description:
     284! ------------
     285!> Calculate current date and time of the simulation
     286!------------------------------------------------------------------------------!
     287 
     288    SUBROUTINE calc_date_and_time
     289
     290       IMPLICIT NONE
     291
     292!--    Variables Definition
     293       INTEGER                          :: i_mon       !< Index for going through the different months
     294
     295       !> Update simulation time in seconds
     296       time_update = simulated_time-coupling_start_time
     297
     298!--    Calculate current day of the simulated time
     299       days_since_reference_point=INT(FLOOR( (time_utc_init + time_update) &
     300                               / 86400.0_wp ) )
     301
     302!--    Calculate actual UTC time                       
     303       time_utc = MOD((time_utc_init + time_since_reference_point), 86400.0_wp)
     304       
     305!sB    PRILIMINARY workaround for time_utc changes due to changes in time_since_reference_point in
     306!sB    radiation_model_mod during runtime:
     307       time_utc_emis = MOD((time_utc_init + time_update), 86400.0_wp)     
     308
     309!--    Calculate initial day of the year: it is calculated only once. In fact, day_of_year_init is initialized to 0 and then a positive value is passed. This condition is also called only when day_of_year_init is not given in the namelist.
     310
     311       IF ( day_of_year_init == 0 ) THEN
     312
     313          !> Condition for printing an error when date_init is not provided when day_of_year_init is not given in the namelist or when the format of the date is not the one required by PALM.
     314          IF ( day_of_month .GT. 0 .AND. day_of_month .LE. 31 .AND. month_of_year .GT. 0 .AND. month_of_year .LE. 12) THEN
     315       
     316             IF ( month_of_year == 1 ) THEN  !!month of year is read in input
     317
     318                day_of_year_init = day_of_month
     319
     320             ELSE
     321
     322                day_of_year_init= SUM(days( 1:(month_of_year-1) )) + day_of_month  !day_of_month is read in input in this case
     323
     324             ENDIF
     325!kanani: Revise, we cannot force users to provide date_init, maybe set a default value?
     326!           ELSE
     327!
     328!              message_string = 'date_init not provided in the namelist or'             //          &
     329!                               ' given in the wrong format: MUST BE DDMMYYYY'                       
     330!              CALL message( 'calc_date_and_time', 'DT0100', 2, 2, 0, 6, 0 )
     331     
     332          ENDIF
     333
     334       ENDIF
     335
    216336      !-- Calculate actual hour of the day: the first hour of the day is from 00:00:00 to 00:59:59.
    217337
     
    302422
    303423      ENDIF       
    304      
     424
    305425    END SUBROUTINE calc_date_and_time
    306426
    307 !TBD: check the routines used for update of emission indices in the DEFAULT MODE
     427
     428!------------------------------------------------------------------------------!
     429! Description:
     430! ------------
     431!> This routine determines the time factor index in the PRE-PROCESSED emissions mode.
     432!------------------------------------------------------------------------------!
     433
     434 SUBROUTINE time_preprocessed_indices(index_hh)
     435
     436    USE indices
     437
     438    IMPLICIT NONE
     439
     440!
     441!-- In/output
     442    INTEGER, INTENT(INOUT) ::  index_hh    !> Index Hour
     443!
     444!-- Additional Variables for calculateing indices
     445!-- Constants
     446    INTEGER, PARAMETER ::  nhour = 24
     447
     448    IF (days_since_reference_point == 0) THEN
     449
     450       index_hh=hour_of_day
     451
     452    ELSE
     453
     454       index_hh=(days_since_reference_point*nhour)+(hour_of_day)
     455
     456    ENDIF
     457
     458
     459 END SUBROUTINE time_preprocessed_indices
     460
     461
    308462!------------------------------------------------------------------------------!
    309463! Description:
Note: See TracChangeset for help on using the changeset viewer.