Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:38:16 UTC

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
6d54cf9ca1 Ed H*0001 #include "CAL_OPTIONS.h"
a63ed37559 Patr*0002 
                0003       subroutine cal_MonthsForYear(
                0004      I                              iyear,
                0005      O                              firstmonth,
                0006      O                              lastmonth,
                0007      O                              nmonths,
                0008      I                              mythid
                0009      &                            )
                0010 
                0011 c     ==================================================================
                0012 c     SUBROUTINE cal_MonthsForYear
                0013 c     ==================================================================
                0014 c
                0015 c     o Given the current year of integration this routine returns
                0016 c       the number of months affected by the integration as well as the
                0017 c       first month and the last month in the sequence of the total
                0018 c       number of months that are to be integrated.
                0019 c
                0020 c       This routine also checks consistency of variables quite
                0021 c       extensively.
                0022 c
                0023 c     started: Christian Eckert eckert@mit.edu  06-Apr-2000
                0024 c
                0025 c     changed: 
                0026 c
                0027 c     ==================================================================
                0028 c     SUBROUTINE cal_MonthsForYear
                0029 c     ==================================================================
                0030 
                0031       implicit none
                0032 
                0033 c     == global variables ==
                0034 
                0035 #include "cal.h"
                0036 
                0037 c     == routine arguments ==
                0038 
                0039       integer iyear
                0040       integer firstmonth
                0041       integer lastmonth
                0042       integer nmonths
                0043       integer mythid
                0044 
                0045 c     == local variables ==
                0046 
                0047       integer ierr
                0048       integer numyears
                0049       integer firstyear
                0050       integer firstmon
                0051       integer lastyear
                0052       integer lastmon
                0053       integer lastday
                0054       integer lastsecs
                0055 
                0056 c     == external ==
                0057 
                0058       integer  cal_IntYears
                0059       external cal_IntYears
                0060 
                0061 c     == end of interface ==
                0062 
                0063       numyears = cal_IntYears( mythid )
                0064 
                0065       firstyear = modelstartdate(1)/10000
                0066       firstmon  = mod(modelstartdate(1)/100,100)
                0067       lastyear  = modelenddate(1)/10000
                0068       lastmon   = mod(modelenddate(1)/100,100)
                0069       lastday   = mod(modelenddate(1),100)
                0070       lastsecs  = modelenddate(2)/10000*secondsperhour +
                0071      &            mod(modelenddate(2)/100,100)*secondsperminute +
                0072      &            mod(modelenddate(2),100)
                0073 
                0074       if ( numyears .eq. 1 ) then
                0075 c--     Only one calendar year affected by the integration.
                0076         if ( iyear .eq. 1 ) then
                0077           if ( firstyear .eq. lastyear ) then
                0078             if ( (lastday .eq. 1) .and. (lastsecs .eq. 0) ) then
                0079 c--           Not really next month yet.
                0080               lastmonth  = lastmon - firstmon
                0081             else
                0082 c--           The most frequent case.
                0083               lastmonth  = lastmon - firstmon + 1
                0084             endif
                0085             firstmonth = 1
                0086           else if ( firstyear+1 .eq. lastyear ) then
                0087 c--         This is only the case if we end at midnight of 01-Jan
                0088 c--         of the next year.
                0089             if ( ( modelenddate(2) .eq. 0) .and.
                0090      &         ( mod(modelenddate(1),100) .eq. 1 ) .and.
                0091      &           mod(modelenddate(1)/100,100) .eq. 1 ) then
                0092               firstmonth = 1
                0093               lastmonth  = nmonthyear - firstmon + 1
                0094             else
                0095 c--           Inconsistent modelenddate; check cal_IntYears.
                0096               ierr = 2804
                0097               call cal_PrintError( ierr, mythid )
                0098               stop ' stopped in cal_MonthsForYear.'
                0099             endif
                0100           else
                0101 c--         The specification of lastyear is wrong.
                0102             ierr = 2803
                0103             call cal_PrintError( ierr, mythid )
                0104             stop ' stopped in cal_MonthsForYear.'
                0105           endif
                0106         else
                0107 c--       The variables numyears and iyear are inconsistent;
                0108 c--       ( iyear .gt. numyears ).
                0109           ierr = 2802
                0110           call cal_PrintError( ierr, mythid )
                0111           stop ' stopped in cal_MonthsForYear.'
                0112         endif
                0113 
                0114       else if ( numyears .gt. 1 ) then
                0115 c--     More than one year of integration.
                0116         if ( iyear .eq. 1 ) then
                0117           firstmonth = 1
                0118           lastmonth  = nmonthyear - firstmon + 1
                0119         else if ( ( iyear .gt. 1 )        .and.
                0120      &            ( iyear .lt. numyears )       ) then
                0121 c--       Somewhere between first and last year.
                0122           firstmonth = (nmonthyear - firstmon + 1) +
                0123      &                 (iyear - 2)*nmonthyear + 1
                0124           lastmonth  = (nmonthyear - firstmon + 1) +
                0125      &                 (iyear - 2)*nmonthyear + nmonthyear
                0126         else if ( iyear .eq. numyears ) then
                0127 c--       The last year of the integration.
                0128           if ( lastyear .eq. (firstyear + numyears - 1) ) then
                0129             if ( (lastday .eq. 1) .and. (lastsecs .eq. 0) ) then
                0130 c--           Not really next month yet.
                0131               lastmonth  = (nmonthyear - firstmon + 1) +
                0132      &                     (numyears - 2)*nmonthyear + lastmon - 1
                0133             else
                0134 c--           The most frequent case.
                0135               lastmonth  = (nmonthyear - firstmon + 1) +
                0136      &                     (numyears - 2)*nmonthyear + lastmon
                0137             endif
                0138             firstmonth = (nmonthyear - firstmon + 1) +
                0139      &                   (numyears - 2)*nmonthyear + 1
                0140           else if ( lastyear .eq. (firstyear + numyears) ) then
                0141 c--         This is only the case if we end at midnight of 01-Jan.
                0142             if ( ( modelenddate(2) .eq. 0) .and.
                0143      &         ( mod(modelenddate(1),100) .eq. 1 ) .and.
                0144      &           mod(modelenddate(1)/100,100) .eq. 1 ) then
                0145               firstmonth = (nmonthyear - firstmon) +
                0146      &                     (numyears - 2)*nmonthyear + 1
                0147               lastmonth  = (nmonthyear - firstmon) +
                0148      &                     (numyears - 2)*nmonthyear + nmonthyear
                0149             else
                0150 c--           Inconsistent modelenddate; check cal_IntYears.
                0151               ierr = 2807
                0152               call cal_PrintError( ierr, mythid )
                0153               stop ' stopped in cal_MonthsForYear.'
                0154             endif
                0155           else
                0156 c--         The variables lastyear and numyears are inconsistent.
                0157             ierr = 2806
                0158             call cal_PrintError( ierr, mythid )
                0159             stop ' stopped in cal_MonthsForYear.'
                0160           endif
                0161         else
                0162 c--       The variables iyear and numyears are inconsistent.
                0163           ierr = 2805
                0164           call cal_PrintError( ierr, mythid )
                0165           stop ' stopped in cal_MonthsForYear.'
                0166         endif
                0167 
                0168       else
                0169 c--     The number of years to integrate is wrong; check cal_IntYears.
                0170         ierr = 2801
                0171         call cal_PrintError( ierr, mythid )
                0172         stop ' stopped in cal_MonthsForYear.'
                0173       endif
                0174 
                0175 c--   The number of months to integrate in the given year.
                0176       nmonths = lastmonth - firstmonth + 1
                0177 
                0178       return
                0179       end
                0180