!$Author$ !$Date$ !$Revision$ !$HeadURL$ subroutine stir_crop(isr, bc0nam, plant_harv) ! + + + ARGUMENT DECLARATIONS + + + integer isr character*(80) bc0nam integer plant_harv ! + + + ARGUMENT DEFINITIONS + + + ! isr - subregion index ! bc0nam - the crop name for this operation ! plant_harv - planting or harvest/termination flag ! 0 - unrelated operation ! 1 - planting operation ! 2 - harvest or termination operation ! + + + INCLUDE + + + include 'p1werm.inc' include 'command.inc' include 'm1flag.inc' include 'main/stir_report_val.inc' ! + + + PURPOSE + + + ! each time it is called, it assigns the last growing crop name to ! the stir crop name for reporting ! + + + LOCAL VARIABLES + + + integer idx, jdx, kdx ! only do if flag is set if( (soil_cond .eq. 0) .or. done_flg(isr) ) return ! start accounting for crops and harvests/terminations ! this relies on an initialization cycle and one regular cycle if( plant_harv .gt. 0 ) then ! this is either a planting or harvest/termination operation. if( phopidx(isr)+1 .gt. mxphops ) then ! maximum array size exceeded write(*,*) 'ERROR: too many planting and harvest Ops' write(*,*) ' increase mxphops in stir_report_val.inc' stop end if ! use temporary index to make shorter lines idx = phopidx(isr) phop_type(idx,isr) = plant_harv if( idx .eq. phoplastidx(isr) ) then ! stir_crop called multiple times in same operation ! reset crop number so it will be redone crop_num(idx,isr) = 0 end if if( plant_harv .eq. 1 ) then ! planting operation if( crop_num(idx,isr) .eq. 0 ) then ! crop number not yet assigned if( idx .gt. 1 ) then do jdx = idx-1, 1, -1 ! index back in op list if( phop_type(jdx,isr) .eq. 2 ) then ! found harvest/termination, this begins a new crop crop_num(idx,isr) = crop_num(jdx,isr) + 1 ! only want the last one exit else if( phop_type(jdx,isr) .eq. 1 ) then ! found planting without harvest/termination, this begins a new crop crop_num(idx,isr) = crop_num(jdx,isr) + 1 ! only want the last one exit else if( jdx .le. 1 ) then ! no harvest/termination found so first planting of file crop_num(idx,isr) = 1 end if end do else ! planting is first operation of file crop_num(idx,isr) = 1 end if end if else if( plant_harv .eq. 2 ) then ! harvest/termination operation if( crop_num(idx,isr) .eq. 0 ) then ! crop number not yet assigned if( idx .gt. 1 ) then do jdx = idx-1, 1, -1 ! index back in op list if( phop_type(jdx,isr) .eq. 1 ) then ! found planting, use to set crop number crop_num(idx,isr) = crop_num(jdx,isr) ! that is all exit else if( jdx .le. 1 ) then ! at start of file, no planting found, so continue at end do kdx = phopcnt(isr), idx+1, -1 if( phop_type(kdx,isr) .eq. 1 ) then ! found planting, use to set crop number crop_num(idx,isr) = crop_num(kdx,isr) ! that is all exit end if end do end if end do else ! at start of file, so search from end do kdx = phopcnt(isr), idx+1, -1 if( phop_type(kdx,isr) .eq. 1 ) then ! found planting, use to set crop number crop_num(idx,isr) = crop_num(kdx,isr) ! that is all exit end if end do end if end if if( report_loop .eqv. .true. ) then ! All harvest/termination ops should be present, check for last harvest/termination if( idx .lt. phopcnt(isr) ) then ! check operations to end of management file and wrap as needed do jdx = idx+1, phopcnt(isr) ! index forward looking for harvest/termination or planting op if( phop_type(jdx,isr) .eq. 1 ) then ! found planting, this is last harvest/termination last_harv(idx, isr) = 1 ! no more checking needed exit else if( phop_type(jdx,isr) .eq. 2 ) then ! found harvest/termination, this is not last harvest/termination ! no more checking needed exit end if if( jdx .eq. phopcnt(isr) ) then ! at end of file, restart at beginning do kdx = 1, idx-1 if( phop_type(kdx,isr) .eq. 1 ) then ! found planting, this is last harvest/termination last_harv(idx, isr) = 1 ! no more checking needed exit else if( phop_type(kdx,isr) .eq. 2 ) then ! found harvest/termination, this is not last harvest/termination ! no more checking needed exit end if end do end if end do else ! start checking operations at beginning of managment file, no wrapping required do jdx = 1, phopcnt(isr) ! index forward looking for harvest/termination or planting op if( phop_type(jdx,isr) .eq. 1 ) then ! found planting, this is last harvest/termination last_harv(idx, isr) = 1 ! no more checking needed exit else if( phop_type(jdx,isr) .eq. 2 ) then ! found harvest/termination, this is not last harvest/termination ! no more checking needed exit end if end do end if end if end if ! always reset phoplastidx(isr) = idx end if if( report_loop .neqv. .true. ) return ! register crop name for this event stir_cropname(phopidx(isr),isr) = bc0nam return end