c$Header: /weru/cvs/weps/weps.src/manage/mfinit.for,v 1.9 2000-06-07 16:23:13 fredfox Exp $ c c subroutine mfinit (sr, fname, maxper) c c + + + PURPOSE + + + c Mfinit should be called during the initialization stage of the the c main weps program. Mfinit searches the management data file; marking c the start sections of each subregion, while storing the number of c years in each subregion's management cycle. c C C Edit History C 19-Feb-99 wjr rewrote C c + + + KEYWORDS + + + c tillage, management file, initialization c c + + + PARAMETERS AND COMMON BLOCKS + + + *$noereference include 'p1werm.inc' include 'wpath.inc' include 'm1dbug.inc' include 'm1flag.inc' include 'manage/man.inc' include 'manage/asd.inc' include 'manage/tcrop.inc' include 'file.fi' *$reference c c + + + ARGUMENT DECLARATIONS + + + integer sr character fname*(*) integer maxper c c + + + ARGUMENT DEFINITIONS + + + c sr - current subregion c fname - management file name c c + + + LOCAL VARIABLES + + + integer linidx, eofidx, endidx character*80 line integer i,j c c + + + SUBROUTINES CALLED + + + c c + + + FUNCTION DECLARATONS + + + integer lentrm c + + + DATA INITIALIZATIONS + + + linidx=1 mbeg(1)=1 if (sr.ne.1) linidx = mbeg(sr) mcur(sr) = 0 mcount(sr) = 0 ! initialize the manage/tcrop.inc variables do 100 i=1,mnsub tczht(i) = 0.0 tczrtd(i) = 0.0 tcmst(i) = 0.0 tcmf(i) = 0.0 tcmbg(i) = 0.0 tcmrt(i) = 0.0 tcmyld(i) = 0.0 tcdstm(i) = 0.0 tcxstm(i) = 0.0 do 50 j=1,mnsz tcmbgz(j,i) = 0.0 tcmrtz(j,i) = 0.0 50 continue 100 continue c + + + END SPECIFICATIONS + + + c c Open management debug file (tdbug.out) and manage.out file c if flags are set. c ! These have been moved to "inprun.for" C if (am0tdb .eq. 1) call fopenk(29, rootp(1:lentrm(rootp)) // C * 'tdbug.out', 'unknown') C if (am0tfl .eq. 1) call fopenk(15, rootp(1:lentrm(rootp)) // C * 'manage.out', 'unknown') ! LEW - 8/18/99 c C read in management file C call fopenk(lui1, fname(1:lentrm(fname)), 'old') 10 read(lui1, '(a)', end=20) line if (line(1:1).eq.'#') goto 10 mtbl(linidx) = line linidx = linidx + 1 C *** write (*,*) ' man fil: ',linidx, line if (linidx.le.mxtbln) goto 10 write (*,*) 'Management table too long - ', fname stop 1001 20 mbeg(sr+1) = linidx close(lui1) C *** C debugging code to dump table C C *** write(*,*) 'start dump of management file ', fname C *** do 111 linidx = mbeg(sr), mbeg(sr+1) C *** write(*,*) linidx, mtbl(linidx) C *** 111 continue C *** write(*,*) 'end of dump' C *** C c First need to find the version of the management file we are c going to read. All files should now have a version #. ANH line = mtbl(mbeg(sr)) if (line (1:8).eq.'Version: ') then c We have found the version # of the management file c Lets see what it is if (line(10:13).ne.'1.10') then print*, 'Version 1.10 is needed for this release.' print*, 'You need to convert ', fname print*, ' to the correct format.' stop 1002 endif else print*, 'Version not found in management file ', fname stop 1002 endif C line = mtbl(mbeg(sr) + 1) c "*START" position found? if (line (1:6).eq.'*START') then c Obtain the number of years for the subregion's management cycle read (line (8:10), '(i3)', err=901) mperod(sr) else print*, '*START not second non-comment line in ', fname stop 1002 endif C C Find end and eof statements C eofidx = 0 endidx = 0 do 30 linidx=mbeg(sr),mbeg(sr+1)-1 line = mtbl(linidx) if (line (1:4).eq.'*END') then if (endidx.ne.0) goto 902 endidx = linidx endif if (line (1:4).eq.'*EOF') then if (eofidx.ne.0) goto 903 eofidx = linidx endif 30 continue C C Make sure that eof is last & end next to last C mbeg(sr+1) = eofidx+1 line = mtbl(mbeg(sr+1) - 2) c "*END" position found? if (line (1:4).ne.'*END') goto 904 line = mtbl(mbeg(sr+1) - 1) c "*EOF" position found? if (line (1:4).ne.'*EOF') goto 905 C C Leave current pointer for region at first date C do 40 linidx = mbeg(sr), mbeg(sr+1) - 1 line = mtbl(linidx) if (line(1:1).eq.'D') goto 41 40 continue goto 906 41 mcur(sr) = linidx C C Used for debugging purposes C Output info about each subregion's management cycle C print *, 'Management filename is: ', fname C print *, 'Management cycle is ', mperod(sr), C & ' years for Subregion ', sr C print *, 'The *START line is: ', start(sr) C & ' first operation line is: ', curnt(sr) C *** return before dump if (mperod(sr) .gt. maxper) maxper = mperod(sr) return C debugging code to dump table C c write(*,*) 'start dump of management file ', fname c do 111 linidx = mbeg(sr), mbeg(sr+1) c write(*,*) linidx, mtbl(linidx) c 111 continue c write(*,*) 'end of dump' c write(*,*) 'leaving mfinit' return C C Error stops C 901 write(*,*) 'Error reading start param ', line(8:10) stop 1002 902 write(*,*) 'Duplicate *END statements in ', fname stop 1002 903 write(*,*) 'Duplicate *EOF statements in ', fname stop 1002 904 write(*,*) '*END not penultimate line in ', fname stop 1002 905 write(*,*) '*EOF not last line in ', fname stop 1002 906 write(*,*) 'No starting date specified in ', fname stop 1002 C end c c