! ------------------------------------------------------------------------- ! Bernese GPS Software Version 5.0 ! ------------------------------------------------------------------------- SUBROUTINE exit_men(irCode) ! ------------------------------------------------------------------------- ! Purpose: Prints the return code to keyword "MENUAUX_IRCODE" ! ! Author: R. Dach ! ! Created: 05-Nov-2003 ! Last mod.: 17-Nov-2003 ! ! Changes: 17-Nov-2003 RD: Prevent "PANIC LOOP" ! ! SRs called: opnfil ! ! Copyright: Astronomical Institute ! University of Berne ! Switzerland ! ------------------------------------------------------------------------- ! Modules ! ------- USE m_bern USE p_menaux, ONLY: inpFileName IMPLICIT NONE ! List of Parameters ! ------------------ ! input: INTEGER(i4b) :: irCode ! Program return code ! output ! Functions ! --------- ! Local types ! ----------- ! Local parameters ! ---------------- CHARACTER(LEN=8), PARAMETER :: srName = 'exit_men' ! Local Variables ! --------------- CHARACTER(LEN=lineLength) :: dummy CHARACTER(LEN=keyValueLength),DIMENSION(:),ALLOCATABLE :: buffer CHARACTER(LEN=keyValueLength) :: line INTEGER(i4b) :: nLine,blanklines,totline INTEGER(i4b) :: ii INTEGER(i4b) :: ios INTEGER(i4b) :: iac ! Write the return code for MENUAUX ! --------------------------------- IF (program_Name /= 'MENUAUX') RETURN ! Try to open the input file ! -------------------------- CALL opnfil(lfnloc, inpFileName, 'OLD', 'FORMATTED',' ', ' ', ios) IF (ios /= 0) RETURN ! Get the number of lines ! ----------------------- nLine = 0 blanklines=0 DO WHILE(ios == 0) READ(lfnloc,'(A)',iostat=ios) line IF (ios == 0) nLine = nLine + 1 dummy=adjustl(line) if(dummy == '') then blanklines=blanklines+1 else blanklines=0 endif if(blanklines == 20) then nLine=nLine-20 exit endif ENDDO ! Allocate a buffer ! ----------------- ALLOCATE(buffer(nLine),stat=iac) IF (iac == 0) THEN ! Rewind file, read file into the buffer ! -------------------------------------- REWIND(lfnloc) totline=nline nLine = 0 ios = 0 DO WHILE(ios == 0 .and. nline < totline) READ(lfnloc,'(A)',iostat=ios) line IF (ios == 0) THEN nLine = nLine + 1 IF (index(line,'MENUAUX_IRCODE') /= 1) THEN buffer(nLine) = line ELSE IF (irCode == 0) THEN buffer(nLine) = 'MENUAUX_IRCODE 1 "0"' ELSE buffer(nLine) = 'MENUAUX_IRCODE 1 "2"' ENDIF ENDIF ENDDO CLOSE(lfnloc) ! Write buffer back to the file ! ----------------------------- CALL opnfil(lfnloc, inpFileName, 'OLD', 'FORMATTED',' ', ' ', ios) IF (ios /= 0) THEN DEALLOCATE(buffer,stat=iac) RETURN ENDIF DO ii = 1,nLine WRITE(lfnloc,'(A)') TRIM(buffer(ii)) ENDDO ! Close file, deallocate buffer ! ----------------------------- CLOSE(lfnloc) DEALLOCATE(buffer,stat=iac) ! "buffer" could not be allocated ! -------------------------------- ELSE WRITE(lfnerr,'(/,A,/)') & ' *** SR EXIT_MEN: Variable "buffer" could not be allocated' ENDIF RETURN END SUBROUTINE exit_men