You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Main #17033/HEAD / v10
Tags:  not added yet

MAIN.for

C**************************************************************************
C*************************************************************************
C   DRIVER for the  MODEL TO SIMULATE CROP GROWTH SUBJECTED TO             
C   DAILY VARIATIONS OF WEATHER AND SOIL WATER CONDITIONS      
C   Written in Microsoft FORTRAN for PC-compatible machines              
C   Authors: RICARDO BRAGA and JADIR ROSA                                
C   Obs: This program is an assignment of the course AGE 5646-Agricultural
C      and Biological Systems Simulation.
C   Date: 03/31/1997
C   Modified 7/99 CHP - modified modular format, revised output format, 
C         modified soil water routines, added water balance 
C   
C*************************************************************************
C
C     LIST OF VARIABLES
C
C     DOY    = Julian day 
C     DOYP   = date of planting (Julian day)
C     endsim = code signifying physiological maturity (end of simulation)
C     FROP   = frequency of printout (days)
C     IPRINT = code for printout (=0 for printout)
C     LAI    = canopy leaf area index (m2 m-2)
C     PAR    = photosynthetically active radiation (MJ/m2/d)
C     RAIN   = daily rainfall (mm)
C     SRAD   = daily solar radiation (MJ/m2/d)
C     SWFAC1 = soil water deficit stress factor
C     SWFAC2 = soil water excess stress factor
C     TAIRHR = hourly average temperature (Celsius)
C     TMAX   = daily maximum temperature (Celsius)
C     TMIN   = daily minimum temperature (Celsius)
C
C**********************************************************************

      PROGRAM MAIN

!-----------------------------------------------------------------------
      USE DFLIB
      IMPLICIT NONE
      SAVE

      REAL LAI, SWFAC1, SWFAC2
      REAL SRAD, TMAX, TMIN, PAR, RAIN
      INTEGER DOY,DOYP, endsim
      INTEGER FROP, IPRINT

!************************************************************************
!************************************************************************
!     INITIALIZATION AND INPUT OF DATA
!************************************************************************
      CALL OPENF(DOYP, FROP)
      
      CALL WEATHR(SRAD,TMAX,TMIN,RAIN,PAR,'INIT')

      CALL SW(
     &    DOY, LAI, RAIN, SRAD, TMAX, TMIN,               !Input
     &    SWFAC1, SWFAC2,                                 !Output
     &    'INIT ')                                        !Control

      CALL PLANT(DOY, endsim, TMAX, TMIN,                 !Input
     &    PAR, SWFAC1, SWFAC2,                            !Input
     &    LAI,                                            !Output
     &    'INIT ')                                        !Control

!-----------------------------------------------------------------------
!     DAILY TIME LOOP 
!-----------------------------------------------------------------------
      DO 500 DOY = 0,1000
        IF (DOY .NE. 0) THEN

          CALL WEATHR(SRAD,TMAX,TMIN,RAIN,PAR,'RATE ')

!************************************************************************
!************************************************************************
!     RATE CALCULATIONS
!************************************************************************
          CALL SW(
     &      DOY, LAI, RAIN, SRAD, TMAX, TMIN,             !Input
     &      SWFAC1, SWFAC2,                               !Output
     &      'RATE ')                                      !Control

          IF (DOY .GT. DOYP) THEN
            CALL PLANT(DOY, endsim,TMAX,TMIN,             !Input
     &        PAR, SWFAC1, SWFAC2,                        !Input
     &        LAI,                                        !Output
     &        'RATE ')                                    !Control
          ENDIF

!************************************************************************
!************************************************************************
!     INTEGRATION OF STATE VARIABLES
!************************************************************************
          CALL SW(
     &      DOY, LAI, RAIN, SRAD, TMAX, TMIN,             !Input
     &      SWFAC1, SWFAC2,                               !Output
     &      'INTEG')                                      !Control

          IF (DOY .GT. DOYP) THEN
            CALL PLANT(DOY, endsim, TMAX,TMIN,            !Input
     &        PAR, SWFAC1, SWFAC2,                        !Input
     &        LAI,                                        !Output
     &        'INTEG')                                    !Control
          ENDIF

        ENDIF

!************************************************************************
!************************************************************************
!     WRITE DAILY OUTPUT
!************************************************************************

        IPRINT = MOD(DOY, FROP)
        IF ((IPRINT .EQ. 0) .OR. (endsim .EQ. 1) .OR. 
     &        (DOY .EQ. DOYP)) THEN

          CALL SW(
     &      DOY, LAI, RAIN, SRAD, TMAX, TMIN,             !Input
     &      SWFAC1, SWFAC2,                               !Output
     &      'OUTPT')                                      !Control

          IF (DOY .GE. DOYP) THEN
            CALL PLANT(DOY, endsim, TMAX,TMIN,            !Input
     &        PAR, SWFAC1, SWFAC2,                        !Input
     &        LAI,                                        !Output
     &        'OUTPT')                                    !Control
          ENDIF

        ENDIF

        IF (ENDSIM .EQ. 1) EXIT

!-----------------------------------------------------------------------
!     END OF DAILY TIME LOOP 
!-----------------------------------------------------------------------
  500 ENDDO

!************************************************************************
!************************************************************************
!     CLOSE FILES AND WRITE SUMMARY REPORTS
!************************************************************************
      CALL WEATHR(SRAD,TMAX,TMIN,RAIN,PAR,'CLOSE') 

      CALL SW(
     &  DOY, LAI, RAIN, SRAD, TMAX, TMIN,                 !Input
     &  SWFAC1, SWFAC2,                                   !Output
     &  'CLOSE')                                          !Control
      
      CALL PLANT(DOY, endsim, TMAX,TMIN,                  !Input    
     &    PAR, SWFAC1, SWFAC2,                            !Input
     &    LAI,                                            !Output
     &    'CLOSE') 

      PAUSE 'End of Program - hit enter key to end'

!-----------------------------------------------------------------------  
      STOP
      END PROGRAM MAIN
****************************************************************************



************************************************************************
*     SUBROUTINE OPENF(DOYP)
*     This subroutine opens the simulation control file, and reads date of
*     planting (DOYP)
*
*     SIMCTRL.INP => date of planting, frequency of printout
************************************************************************

      SUBROUTINE OPENF(DOYP, FROP)

      IMPLICIT NONE
      INTEGER DOYP, FROP

      OPEN (UNIT=8, FILE='SIMCTRL.INP',STATUS='UNKNOWN')
      READ(8,5) DOYP, FROP
      IF (FROP .LE. 0) FROP = 1
    5 FORMAT(2I6)
      CLOSE(8)

!-----------------------------------------------------------------------  
      RETURN
      END SUBROUTINE OPENF
************************************************************************
************************************************************************