Oasis3 4.0.2
parseblk.f90
Go to the documentation of this file.
00001 SUBROUTINE parseblk (cdone, cdtwo, knumb, klen, kleng)
00002 !****
00003 !               *****************************
00004 !               * OASIS ROUTINE  -  LEVEL T *
00005 !               * -------------     ------- *
00006 !               *****************************
00007 !
00008 !**** *parse*  - Parsing routine
00009 !
00010 !     Purpose:
00011 !     -------
00012 !     Get the rest of the line starting at the knumb'th string.
00013 !     A string is defined as a continuous set of non-blanks characters
00014 !
00015 !**   Interface:
00016 !     ---------
00017 !       *CALL*  *parseblk (cdone, cdtwo, knumb, klen, kleng)*
00018 !
00019 !     Input:
00020 !     -----
00021 !                cdone : line to be parsed (char string)
00022 !                knumb : rank within the line of the starting string (integer)
00023 !                klen  : length of the input line (integer)
00024 !
00025 !     Output:
00026 !     ------
00027 !                cdtwo : extracted rest of line, including blanks (char string)
00028 !                kleng : length of the extracted string (integer)
00029 !
00030 !     Workspace:
00031 !     ---------
00032 !     None
00033 !
00034 !     Externals:
00035 !     ---------
00036 !
00037 !     History:
00038 !     -------
00039 !       Version   Programmer     Date      Description
00040 !       -------   ----------     ----      -----------  
00041 !       2.5       S. Valcke      00/09/08  Adapted from parse.f
00042 !
00043 ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00044 !
00045 !* ---------------------------- Include files ---------------------------
00046 !
00047   USE mod_unit
00048 !
00049 !* ---------------------------- Argument declarations -------------------
00050 !
00051   INTEGER (kind=ip_intwp_p), INTENT ( in) :: knumb, klen
00052   CHARACTER (len=klen), INTENT ( inout) :: cdone
00053   CHARACTER (len=klen), INTENT ( out) :: cdtwo
00054   INTEGER (kind=ip_intwp_p), INTENT ( out) :: kleng
00055 !
00056 !* ---------------------------- Local declarations -------------------
00057 !
00058   INTEGER (kind=ip_intwp_p) :: il, kleng_aux
00059   CHARACTER (len=klen) :: clline
00060   CHARACTER (len=klen) :: clwork
00061   CHARACTER (len=1), SAVE :: clblank = ' ', clcmt = '#'
00062 !
00063 !* ---------------------------- Poema verses ----------------------------
00064 !
00065 ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00066 !
00067 !*    1. Skip line if it is a comment
00068 !        ----------------------------
00069 !
00070 100 IF (cdone(1:1) .NE. clcmt) GO TO 120
00071   READ (UNIT = nulin, FMT = 1001) clline 
00072   cdone(1:klen) = clline(1:klen)
00073   GO TO 100
00074 120 CONTINUE 
00075 1001 FORMAT(A80)
00076 !
00077 !
00078 !*    2. Do the extraction job
00079 !        ---------------------
00080 !
00081 !* - Fill cdtwo with blanks
00082 !
00083   cdtwo = clblank
00084 !
00085 !* Fill temporary string and remove leading blanks
00086 !
00087   il = INDEX ( cdone, clblank)
00088   kleng_aux = 1
00089   IF (INDEX ( cdone, clblank).EQ.1) THEN
00090       DO WHILE (cdone(il+1:il+1).EQ.clblank)
00091         kleng_aux = kleng_aux +1
00092         il = il+1
00093         IF (il+1.GT.klen) GO TO 130
00094       ENDDO
00095   ENDIF
00096 130 CONTINUE
00097   clwork = ADJUSTL ( cdone)
00098 !
00099 !* - If there are no more characters, kleng=-1
00100 !
00101   IF ( LEN_TRIM ( clwork) .LE. 0) THEN
00102       kleng = -1
00103       RETURN
00104   END IF
00105 !
00106 !* - If this is the one we're looking for, skip
00107 !    otherwise go knumb-1 more sets of characters
00108 !
00109   IF (knumb .GE. 2) THEN
00110       DO jl = 1, knumb-1
00111         ii = INDEX ( clwork, clblank) - 1
00112         il = ii + 1 
00113         DO WHILE (clwork(il:il).EQ.clblank)
00114           kleng_aux = kleng_aux +1
00115           il = il + 1
00116           IF (il.GT.klen) GO TO 140
00117         ENDDO
00118 140 CONTINUE
00119         kleng_aux = kleng_aux + ii
00120         clwork ( 1:ii) = clblank
00121         clwork = ADJUSTL ( clwork)
00122 !
00123 !* - If there are no more characters, kleng=-1
00124 !
00125         IF (LEN_TRIM ( clwork) .LE. 0) THEN
00126             kleng = -1
00127             RETURN
00128         END IF
00129       END DO
00130   END IF
00131 !
00132 !* - Find the length of the rest of the line
00133 !
00134   kleng = klen - kleng_aux
00135 !
00136 !* - Copy to cdtwo
00137 !
00138   cdtwo ( 1:kleng) = clwork ( 1: kleng)
00139 !
00140 !*    3. End of routine
00141 !        --------------
00142 !
00143   RETURN
00144 END SUBROUTINE parseblk
00145 
 All Data Structures Namespaces Files Functions Variables Defines