c$Header: /weru/cvs/weps/weps.src/manage/manage.for,v 1.5.2.1 2000-03-31 22:56:20 fredfox Exp $ c c subroutine manage i (sr, dd, mm, yyyy, syear, i lopdd, lopmm, lopyy) c c + + + PURPOSE + + + c This is the main routine of the MANAGEMENT submodel. The date passed c to this routine is checked with the next operation date in the c management file. If the dates match, then an operation is to be c performed today on the given subregion. c The date of last operation (op*) is also passed for output purposes.jt c C Edit History C 19-Feb-99 wjr rewrote C 20-Feb-99 wjr made date return C c + + + KEYWORDS + + + c tillage, management c c + + + PARAMETERS AND COMMON BLOCKS + + + *$noereference include 'p1werm.inc' include 'm1flag.inc' include 'manage/man.inc' include 'manage/asd.inc' include 'manage/oper.inc' C for debugging C *** include 's1layd.inc' C *** include 's1layr.inc' *$reference c c + + + ARGUMENT DECLARATIONS + + + integer sr, dd, mm, yyyy, syear, i lopdd, lopmm, lopyy c + + + ARGUMENT DEFINITIONS + + + c sr - the subregion number c dd - current simulation day c mm - current simulation month c yyyy - current simulation year c syear - starting year of the simulation run c lopdd - day of last operation c lopmm - month of last operation c lopyy - year of last operation c c + + + LOCAL VARIABLES + + + integer flag, myear, month, day, year character*80 line c c flag - denotes completion of the tllage routine when equal to 0 c myear - determines the "year offset" within a period of years c month - month from the management file c day - day from the management file c year - year from the management file c c + + + SUBROUTINES CALLED + + + c dooper - DO OPERation is called when dates match c dogroup - DO GROUP is called when G code encountered c doproc - DO PROCess is called when P code encountered c c + + + FUNCTION DECLARATIONS + + + integer difdat c c + + + DATA INITIALIZATIONS + + + flag=1 c c + + + OUTPUT FORMATS + + + 2015 format ('Op Date ', i2,1x,i2,1x,i4,' Rot yr ',i2,' sr #',i2) c2015 format ('Operation Date ',i2,1x,i2,1x,i4,', subregion #',i2) c c + + + END SPECIFICATIONS + + + c Don't do anything if the subregion isn't in the data file. c set the flag am0hrvfl to zero indicating no harvest has c been done. When manage does a harvest this flag will be set to c 1 or 2 depending on the type of harvest, and will remain 1 or 2 c until the next simulation day (next call to manage) This flag c replaces am0nkfl. ANH 12/7/95 am0hrvfl = 0 if (mbeg(sr).eq.mbeg(sr+1)) then write(*,*) 'Sub-region not in data file', sr return endif C line = mtbl(mcur(sr)) C C If we aren't pointing at a date, we have a problem C if (line(1:1).ne.'D') goto 901 C myear=mod (yyyy-syear, mperod(sr))+1 c Must be a space between 'D' and date in dd/mm/yyyy format read (line (3:12),'(i2,1x,i2,1x,i4)', err=902) day,month,year C C if not today then return C if (difdat (dd,mm,myear,day,month,year).ne.0) return if (am0tfl .eq. 1) then write (15,*) write (15,2015) dd,mm,yyyy,year,sr endif c pass date of operation to MAIN for output purposes lopdd = day lopmm = month lopyy = year C C Move the tbl ptr to the first operation after the date C 10 mcur(sr) = mcur(sr) + 1 line = mtbl(mcur(sr)) select case (line(1:1)) case ('O') opskip = 0 call dooper(sr) case ('G') if(opskip.eq.0) call dogroup(sr) case ('P') if(opskip.eq.0) call doProc(sr) case ('D') read (line (3:12),'(i2,1x,i2,1x,i4)', err=902) day,month,year if (difdat (dd,mm,myear,day,month,year).ne.0) return case ('*') mcount(sr) = mcount(sr) + 1 mcur(sr) = mbeg(sr) 101 mcur(sr) = mcur(sr) + 1 line = mtbl(mcur(sr)) if (line(1:1).ne.'D') goto 101 return case ('+') continue case default goto 903 end select goto 10 C C Error stops C 901 write(*,*) 'Enter manage not pointing at date' stop 1002 902 write(*, 9902) line, sr 9902 format('Bad date format ',a,' in region ',i2) stop 1002 903 write(*,*) 'Invalid management code -', line (1:1) stop 1002 end c c