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