SURFEX v7.3
General documentation of Surfex
 All Classes Files Functions Variables Typedefs
/home/dasprezs/EXPORT_v7_3/src/LIB/FM/fm_writ.F90
Go to the documentation of this file.
00001 !     ######spl
00002       SUBROUTINE FM_WRIT(HFILEM,HRECFM,HFIPRI,KLENG,KFIELD,KGRID,&
00003                         KLENCH,HCOMMENT,KRESP)
00004       USE PARKIND1, ONLY : JPRB
00005       USE YOMHOOK , ONLY : LHOOK, DR_HOOK
00006 !     ###########################################################
00007 !
00008 !!****  *FM_WRIT* - routine to write a single data article into a "FM"-file
00009 !!
00010 !!    PURPOSE
00011 !!    -------
00012 !
00013 !       The purpose of FMWRIT is to write one article into a Meso-nh data file.
00014 !     This routine only holds for a LFI-file (not namelist).
00015 !
00016 !!**  METHOD
00017 !!    ------
00018 !!
00019 !!      The unformatted write operation is actually performed by the routine
00020 !!    LFIECR. You need to indicate the file name without the ".lfi"
00021 !!    suffix, the data array and the
00022 !!    length of this array. Furthermore, you have to give a name for the article
00023 !!    you are writing (string) which you better choose by convention.
00024 !!      FMWRIT also appends the grid-indicator (KGRID) at the beginning of
00025 !!    the LFI logical article (IWORK(1)) ; then the length of the comment
00026 !!    string (KLENCH) ; then the comment string itself which is first
00027 !!    converted into integer type using ICHAR.
00028 !!    Finally, it writes the data (integer or
00029 !!    real) itself (rest of array IWORK). We stress that the length KLENG
00030 !!    that the user has to indicate is the length of the real data array
00031 !!    WITHOUT taking the other fields into account.
00032 !!
00033 !!    EXTERNAL
00034 !!    --------
00035 !!
00036 !!      FMLOOK,LFIECR,ICHAR
00037 !!
00038 !!    IMPLICIT ARGUMENTS
00039 !!    ------------------
00040 !!
00041 !!      MODULE: MODD_FMDECLAR contains management parameters and
00042 !!              storage arrays to move information around at the
00043 !!              level of all "FM"-routines.
00044 !!
00045 !!    REFERENCE
00046 !!    ---------
00047 !!
00048 !!      see the Technical Specifications Report for the Meso-nh project
00049 !!      (in French)
00050 !!
00051 !!    AUTHOR
00052 !!    ------
00053 !!
00054 !!      C. FISCHER      *METEO-FRANCE*
00055 !!
00056 !!    MODIFICATIONS
00057 !!    -------------
00058 !!
00059 !!      original                                                        06/94
00060 !!      modified by V. Masson               16/09/96 (prints if error occurs)
00061 !----------------------------------------------------------------------------
00062 !
00063 !*      0.    DECLARATIONS
00064 !             ------------
00065 !
00066 USE MODD_FMDECLAR
00067 
00068 IMPLICIT NONE
00069 !
00070 !*      0.1   Declarations of arguments
00071 !
00072 CHARACTER(LEN=*)          ,INTENT(IN) ::HFILEM   ! file name
00073 CHARACTER(LEN=*)          ,INTENT(IN) ::HRECFM   ! name of the article to be written
00074 
00075 CHARACTER(LEN=*)          ,INTENT(IN) ::HFIPRI   ! file for prints in FM
00076 
00077 INTEGER,                   INTENT(IN) ::KLENG  ! length of the data field
00078 INTEGER(KIND=8),DIMENSION(1:KLENG),INTENT(IN) ::KFIELD ! array containing the data field
00079 INTEGER,                   INTENT(IN) ::KGRID  ! C-grid indicator (u,v,w,T)
00080 INTEGER,                   INTENT(IN) ::KLENCH ! length of comment string
00081 
00082 CHARACTER(LEN=KLENCH),     INTENT(IN) ::HCOMMENT ! comment string)
00083 
00084 INTEGER,                   INTENT(OUT)::KRESP  ! return-code if problems araised
00085 
00086 !
00087 !*      0.2   Declarations of local variables
00088 !
00089 INTEGER::IRESP,ITOTAL,INUMBR,J,IROW,IFMFNL,ILUPRI
00090 INTEGER(KIND=8),DIMENSION(:),ALLOCATABLE::IWORK
00091 INTEGER,DIMENSION(1:JPXKRK)::ICOMMENT
00092 CHARACTER(LEN=JPFINL)::YFNLFI
00093 CHARACTER(LEN=LEN(HFILEM))::YINTFN
00094 !
00095 !*      0.3   Taskcommon for logical units
00096 !
00097 COMMON/TASKWRIT/ILUPRI,INUMBR,IRESP
00098 !DIR$ TASKCOMMON TASKWRIT
00099 !
00100 !----------------------------------------------------------------------------
00101 !
00102 !*      1.1   THE NAME OF LFIFM
00103 !
00104 REAL(KIND=JPRB) :: ZHOOK_HANDLE
00105 IF (LHOOK) CALL DR_HOOK('FM_WRIT',0,ZHOOK_HANDLE)
00106 IRESP = 0 ; IROW = 0 ; ILUPRI = 6
00107 IFMFNL=JPFINL-4
00108 
00109 IROW=LEN(HFILEM)
00110 
00111 IF (IROW.EQ.0) THEN
00112    IRESP=-64
00113    GOTO 1000
00114 ELSEIF (IROW.GT.IFMFNL) THEN
00115    IRESP=-65
00116    GOTO 1000
00117 ENDIF
00118 YINTFN=ADJUSTR(HFILEM)
00119 YFNLFI=YINTFN//'.lfi'
00120 YFNLFI=ADJUSTL(YFNLFI)
00121 
00122 !
00123 !*      1.2   WE LOOK FOR THE FILE'S LOGICAL UNIT
00124 !
00125 CALL FMLOOK(YFNLFI,HFIPRI,INUMBR,IRESP)
00126 IF (IRESP.NE.0) GOTO 1000
00127 
00128 !
00129 !*      2.    GRID INDICATOR, COMMENT AND DATA ARE PUT TOGETHER
00130 !
00131 IF (KLENG.LE.0) THEN
00132     IRESP=-40
00133     GOTO 1000
00134 ELSEIF (KLENG.GT.JPXFIE) THEN
00135     IRESP=-43
00136     GOTO 1000
00137 ELSEIF ((KGRID.LT.0).OR.(KGRID.GT.8)) THEN
00138     IRESP=-46
00139     GOTO 1000
00140 ENDIF
00141 
00142 ITOTAL=KLENG+1+KLENCH+1
00143 IF(ALLOCATED(IWORK)) DEALLOCATE(IWORK)
00144 ALLOCATE(IWORK(ITOTAL))
00145 
00146 IWORK(1)=KGRID
00147 
00148 SELECT CASE (KLENCH)
00149 CASE(:-1)
00150     IRESP=-55
00151     GOTO 1000
00152 CASE(0)
00153     IWORK(2)=KLENCH
00154     IWORK(3:KLENG+2)=KFIELD(1:KLENG)
00155 CASE(1:JPXKRK)
00156     DO J=1,KLENCH
00157         ICOMMENT(J)=ICHAR(HCOMMENT(J:J))
00158     ENDDO
00159     IWORK(2)=KLENCH
00160     IWORK(3:KLENCH+2)=ICOMMENT(1:KLENCH)
00161     IWORK(KLENCH+3:ITOTAL)=KFIELD(1:KLENG)
00162 CASE(JPXKRK+1:)
00163     IRESP=-57
00164     GOTO 1000
00165 END SELECT
00166 
00167 !
00168 !  no compressing of any kind: the data is pure binary
00169 !
00170 !*      3.    UNFORMATTED, DIRECT ACCESS WRITE OPERATION
00171 !
00172 CALL LFIECR(IRESP,INUMBR,HRECFM,IWORK,ITOTAL)
00173 IF (IRESP.NE.0) GOTO 1000
00174 
00175 DEALLOCATE(IWORK)
00176 !
00177 !*      4.    MESSAGE PRINTING WHATEVER THE ISSUE WAS
00178 !
00179 1000    CONTINUE
00180 
00181 IF (IRESP.NE.0) THEN
00182 YFNLFI=ADJUSTL(HFIPRI)
00183 DO J=1,JPNXLU
00184     IF (CNAMFI(J).EQ.YFNLFI) THEN
00185        ILUPRI=J
00186        EXIT
00187     ENDIF
00188 ENDDO
00189 WRITE (ILUPRI,*) ' exit from FMWRIT with IRESP:',IRESP
00190 WRITE (ILUPRI,*) '   | HFILEM = ',HFILEM
00191 WRITE (ILUPRI,*) '   | HRECFM = ',HRECFM
00192 WRITE (ILUPRI,*) '   | KLENG  = ',KLENG
00193 WRITE (ILUPRI,*) '   | KGRID  = ',KGRID
00194 WRITE (ILUPRI,*) '   | KLENCH = ',KLENCH
00195 ENDIF
00196 KRESP=IRESP
00197 
00198 IF (LHOOK) CALL DR_HOOK('FM_WRIT',1,ZHOOK_HANDLE)
00199 RETURN
00200       IF (LHOOK) CALL DR_HOOK('FM_WRIT',1,ZHOOK_HANDLE)
00201       END SUBROUTINE FM_WRIT