C **********************************************************************      
C *                                                                    *      
C *  Read a SLA file and list the content of each record on the        *      
C *  standard output                                                   *      
C *                                                                    *      
C **********************************************************************      
C *                                                                    *      
C *  Date   : Dec 27, 1994                                             *      
C *  Author : P.Sicard   CLS Space Oceanography Group                  *      
C *                                                                    *      
C **********************************************************************      
                                                                              
                                                                              
      program read_sla                                                        
                                                                              
      implicit none                                                           
                                                                              
C +--------------------------------------------------------------------+      
C |     G L O B A L   C O N S T A N T S   A N D   V A R I A B L E S    |      
C +--------------------------------------------------------------------+      
                                                                              
C  Maximum number of cycles                                                   
C  ~~~~~~~~~~~~~~~~~~~~~~~~                                                   
      integer*2      ec_sla_maxCyc                                            
      parameter     (ec_sla_maxCyc = 200)                                     
                                                                              
C  Maximum number of measurements in a pass                                   
C  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                   
      integer*2      ec_sla_maxMes                                            
      parameter     (ec_sla_maxMes = 3400)                                   
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      character*80   tv_fileName         ! SLA file name to read              
      integer*4      jv_status           ! Status of called subroutines       
      logical        inside_box          ! function returns 1 is inside domain
      real f_lat
      real f_lon
                                                                              
      integer*2      ev_pass             ! Total number of passes             
      integer*2      ev_cyc              ! Total number of cycles             
      integer*2      ev_dat              ! Data records count                 
                                                                              
C     General header                                                          
      integer*2      ev_nbPass           ! Total number of passes             
      integer*2      ev_nbCycGen         ! Number of cycles                   
      integer*4      jv_repeat           ! Repetitivity                       
                                                                              
C     Pass header                                                             
      integer*2      ev_passNum          ! Passes number                      
      integer*2      ev_nbCyc            ! Number of cycles                   
      integer*2      ev_nbPts            ! Number of measurements             
      integer*4      jv_meanDay          ! Mean day                           
                                                                              
C     Cycles list                                                             
      integer*2      ew_cycList(ec_sla_maxCyc)                                
                                                                              
C     Data record                                                             
      integer*4      jv_lat              ! Latitude (10**-6 deg)              
      integer*4      jv_lon              ! Longitude (10**-6 deg)             
      integer*2      ew_sla(ec_sla_maxCyc)     
      real           meanday(ec_sla_maxCyc) ! day since 1-jan-92    
      integer        ref_day             !1-Jan-92 relative to 1-jan-50
      parameter      (ref_day = 15340)
      integer*2      DEFSLA
      parameter      (DEFSLA = 32767)
      integer        ival
      integer        isat         ! isat=1 (T/P), isat=15 (ERS) 
      character*64 fout 
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
                                                                              
C     Get the SLA file name on the standard input                             
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                             
      print *,'SLA file name ?'                                               
      read '(A)', tv_fileName
      print *,'output file name?'
      read *, fout
      ival=44
      open(unit=44,file=fout,form='formatted')                                               
      rewind(44)
      isat=1                                                                        
C     Opening file                                                            
C     ~~~~~~~~~~~~                                                            
      call opensla (tv_fileName, jv_status)                                   
      if (jv_status .ne. 0) goto 9999                                         
                                                                              
C     Reading general header                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
      call rdHeadGen (ev_nbPass   ,                                           
     &                ev_nbCycGen ,                                           
     &                jv_repeat   ,                                           
     &                jv_status   )                                           
      if (jv_status .ne. 0) goto 9999                                         
c                                                                              
c      print *,' '                                                             
c      print *,'Total number of passes   : ',ev_nbPass                         
c      print *,'Nb cycles used : ',ev_nbCycGen                                 
c      print *,'Repetitivity (1/100 day) : ',jv_repeat                         
c      print *,' '                                                             
                                                                              
C     ~~~~~~~~~~~~~~                                                          
C     Loop on Passes                                                          
C     ~~~~~~~~~~~~~~                                                        
      do ev_pass = 1 , ev_nbpass                                              
                                                                              
C          Reading current header pass                                        
C          ~~~~~~~~~~~~~~~~~~~~~~~~~~~                                        
           call rdHeadPass (ev_passNum ,                                      
     &                      ev_nbCyc   ,                                      
     &                      ev_nbPts   ,                                      
     &                      jv_meanDay ,                                      
     &                      jv_status  )                                      
           if (jv_status .ne. 0) goto 9999                                    
                                                                              
c           print *,' '                                                        
c           print *,'--------------- '                                         
c           print '(1X,A,I4.4,1X,A,I3,1X,A,I4,1X,A,I)',                        
c     &          'Pass No ',ev_passNum ,                                       
c     &          '* Cycles count : ', ev_nbCyc,                                
c     &          '* Data count   : ',ev_nbPts ,                                
c     &          '* Mean Day : ',jv_meanDay                                    
c           print *,'--------------- '                                         
c           print *,ev_passNum, ev_nbCyc

           call rdCycList (ew_cycList , jv_status)                            
           if (jv_status .ne. 0) goto 9999                                    
                                                                              

           do ev_cyc = 1 , ev_nbCyc                                           
           meanday(ev_cyc)=jv_meanday/100.+
     &      (ew_cycList(ev_cyc) -
     &      ew_cycList(1))*jv_repeat/10000.-float(ref_day)
           enddo                                                              

           
                                                                              
C          Reading data records of the current pass                           
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                           

           do ev_dat = 1 , ev_nbPts                                           
              call rdSLA (jv_lat , jv_lon, ew_sla , jv_status)              
              if (jv_status .ne. 0) goto 9999                                             
C              if (mod(ev_dat+2,3).eq.0) then
                 f_lat=jv_lat/1.0e+6
                 f_lon=jv_lon/1.0e+6
                 if (inside_box(f_lat,f_lon)) then
                    do ev_cyc = 1 , ev_nbCyc
                       if (ew_sla(ev_cyc).ne.DEFSLA) then
                          print '(f9.3,2x,f8.4,2x,f10.4,2x,I6)',
     &                         meanday(ev_cyc),
     &                         f_lat,
     &                         f_lon,
     &                         ew_sla(ev_cyc)
          write(ival,'(f9.3,2x,f8.4,2x,f10.4,2x,I6,I6)'),
     &                         meanday(ev_cyc),
     &                         f_lat,
     &                         f_lon-360,
     &                         ew_sla(ev_cyc),
     &                         isat    ! isat=1 (T/P), isat=15 (ERS2)

                       endif
                    enddo             
                endif
C              endif
           enddo                ! end loop on points in pass
        enddo                   ! end loop on passes              
 9999         continue
C     Closing SLA file                                                        
C     ~~~~~~~~~~~~~~~~                                                        
      call closeSLA                                                           
                                                                              
      end
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  OPENSLA                                                           |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Opening a SLA file                                              |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | tv_fileName   : SLA file name                                      |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine openSLA (tv_fileName,                                        
     &                    jv_status  )                                        
                                                                              
      include "readSLA.h"
                                                                              
C     Init private variables                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      character*(*)  tv_fileName         ! (I) Filename                       
      integer*4      jv_status           ! (O) Return status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4      jv_ios              ! Status I/O file                    
                                                                              
      integer*2      ev_spare            ! Spare                              
      integer*2      ev_nbCycGenVax      ! Cycles count of the General        
                                         ! Header record (VAX)                
      integer*2      ev_nbCycGen         ! Cycles count of the General        
                                         ! Header record (SUN)                
                                                                              
      integer*2      decod_i2            ! Decode function                    
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
      data lv_sla_open   /.false./                                            
                                                                              
      jv_status = 0                                                           
                                                                              
C     Opening file in direct mode to get the number of cycles used            
C     in the General Header record  (record length = 4)                       
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            
      open (unit = jc_sla_lun      ,                                          
     &      file = tv_fileName     ,                                          
     &      status = 'old'         ,                                          
     &      access = 'direct'      ,                                          
     &      form   = 'unformatted' ,                                          
     &      recl   = 4             ,                                          
     &      iostat = jv_ios        )                                          
      if (jv_ios .ne. 0) then                                                 
           print *,' '                                                        
           print *,'Subroutine : OPENSLA'                                     
           print *,'Error opening file : ',tv_fileName                        
           print *,'Status = ',jv_ios                                         
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
C     Reading General Header record                                           
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                           
      read (unit   = jc_sla_lun ,                                             
     &      rec    = 1          ,                                             
     &      iostat = jv_ios     ) ev_spare , ev_nbCycGenVax                   
      if (jv_ios .ne. 0) then                                                 
           print *,' '                                                        
           print *,'Subroutine : OPENSLA'                                     
           print *,'Error during read General Header record'                  
           print *,'Status = ',jv_ios                                         
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
C     decode Number of cycles                                                 
C     ~~~~~~~~~~~~~~~~~~~~~~~                                                 
      ev_nbCycGen = decod_i2 (ev_nbCycGenVax)                                 
                                                                              
C     Close SLA file                                                          
C     ~~~~~~~~~~~~~~                                                          
      close (unit = jc_sla_lun, iostat = jv_ios)                              
                                                                              
C     Computing record length in bytes                                        
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                        
      jv_sla_recl = 8 + (ev_nbCycGen * 2) + (MOD(ev_nbCycGen,2) *2)           
                                                                              
C     Opening SLA file in  direct access mode                                 
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                 
      open (unit = jc_sla_lun      ,                                          
     &      file = tv_fileName     ,                                          
     &      status = 'old'         ,                                          
     &      access = 'direct'      ,                                          
     &      recl   = jv_sla_recl   ,                                          
     &      iostat = jv_ios        )                                          
      if (jv_ios .ne. 0) then                                                 
           print *,' '                                                        
           print *,'Subroutine : OPENSLA'                                     
           print *,'Error opening file : ',tv_fileName                        
           print *,'Status = ',jv_ios                                         
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
      lv_sla_open   = .true.                                                  
      jv_sla_recNum = 0                                                       
                                                                              
 9999 continue                                                                
                                                                              
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  RDHEADGEN                                                         |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Reading the General Header Record                               |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C |                                                                    |      
C | ev_nbPass     : Total number of passes                             |      
C | ev_nbCycGen   : Number of cycles used to generate SLA file         |      
C | jv_repeat     : repetitivity (1/100 Day) (e.g T/P=991)             |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine rdHeadGen (ev_nbPass   ,                                     
     &                      ev_nbCycGen ,                                     
     &                      jv_repeat   ,                                     
     &                      jv_status   )                                     
                                                                              
      include "readSLA.h"
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      ev_nbPass           ! (O) Total number of passes         
      integer*2      ev_nbCycGen         ! (O) Number of cycles               
      integer*4      jv_repeat           ! (O) Repetitivity                   
      integer*4      jv_status           ! (O) Return status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      decod_i2            ! Decode function i2                 
      integer*4      decod_i4            ! Decode function i4                 
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_status = 0                                                           
                                                                              
C     Reading current record (must be the number 1)                           
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                           
      if (jv_sla_recNum .ne. 0) then                                          
           print *,' '                                                        
           print *,'Subroutine rdHeadGen'                                     
           print *,'Current record is not the General Header record'          
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
      call rdRecord(jv_status)                                                
      if (jv_status .ne. 0) goto 9999                                         
                                                                              
C     Get fields in record                                                    
C     ~~~~~~~~~~~~~~~~~~~~                                                    
      ev_nbPass   = decod_i2(eq_sla_nbPass)                                   
      ev_nbCycGen = decod_i2(eq_sla_nbCycGen)                                 
      jv_repeat   = decod_i4(jq_sla_repeat)                                   
                                                                              
 9999 continue                                                                
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  RDHEADPASS                                                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Reading a Pass Header Record                                    |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C |                                                                    |      
C | ev_passNum    : Pass number                                        |      
C | ev_nbCyc      : Number of cycles in the current pass               |      
C | ev_nbPts      : Number of data records for the current pass        |      
C | jv_meanDay    : Mean day of the 1st cycle 1/100 Day)               |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine rdHeadPass (ev_passNum   ,                                   
     &                       ev_nbCyc     ,                                   
     &                       ev_nbPts     ,                                   
     &                       jv_meanDay   ,                                   
     &                       jv_status    )                                   
                                                                              
      include "readSLA.h"
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      ev_passNum          ! (O) Pass number                    
      integer*2      ev_nbCyc            ! (O) Number of cycles               
      integer*2      ev_nbPts            ! (O) Number of measurements         
      integer*4      jv_meanDay          ! (O) Mean day                       
      integer*4      jv_status           ! (O) Return Status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      decod_i2            ! Decode function i2                 
      integer*4      decod_i4            ! Decode function i4                 
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_status = 0                                                           
                                                                              
C     Reading current record                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
      call rdRecord(jv_status)                                                
      if (jv_status .ne. 0) goto 9999                                         
                                                                              
C     Get fields in record                                                    
C     ~~~~~~~~~~~~~~~~~~~~                                                    
      ev_passNum   = decod_i2(eq_sla_passNum)                                 
      ev_nbCyc     = decod_i2(eq_sla_nbCyc)                                   
      ev_nbPts     = decod_i2(eq_sla_nbPts)                                   
      jv_meanDay   = decod_i4(jq_sla_meanDay)                                 
                                                                              
C     Save the number of cycles in the current pass                           
C     ---------------------------------------------                           
      ev_sla_nbCyc = ev_nbCyc                                                 
                                                                              
 9999 continue                                                                
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  RDCYCLIST                                                         |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Reading a Cycles List Record                                    |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C |                                                                    |      
C | ew_cycList    : Cycles list (1 ... nbCyc in the pass)              |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine rdCycList  (ew_cycList   ,                                   
     &                       jv_status    )                                   
                                                                              
      include "readSLA.h"
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      ew_cycList(*)       ! (O) Cycles list                    
      integer*4      jv_status           ! (O) Return Status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      ev_cyc              ! Cycle count                        
      integer*2      decod_i2            ! Decode function i2                 
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_status = 0                                                           
                                                                              
C     Reading current record                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
      call rdRecord(jv_status)                                                
      if (jv_status .ne. 0) goto 9999                                         
                                                                              
C     Get fields in record                                                    
C     ~~~~~~~~~~~~~~~~~~~~                                                    
      do ev_cyc = 1 , ev_sla_nbCyc                                            
           ew_cycList(ev_cyc) = decod_i2(ep_sla_CycList(ev_cyc))              
      enddo                                                                   
                                                                              
 9999 continue                                                                
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  RDSLA                                                             |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Reading a Data (SLA) record                                     |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C |                                                                    |      
C | jv_lat        : Latitude of the measurement  (10**-6 deg)          |      
C | jv_lon        : Longitude of the measurement (10**-6 deg)          |      
C | ew_sla        : Sea level Anomaly for each cycle of the pass       |      
C |                 (1 ... nbCyc)  unit = millimeters                  |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine rdSLA  (jv_lat     ,                                         
     &                   jv_lon     ,                                         
     &                   ew_sla     ,                                         
     &                   jv_status  )                                         

      include "readSLA.h"
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4      jv_lat              ! (O) Latitude                       
      integer*4      jv_lon              ! (O) Longitude                      
      integer*2      ew_sla(*)           ! (O) SLA list                       
      integer*4      jv_status           ! (O) Return Status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*2      ev_s                ! SLA count                          
      integer*2      decod_i2            ! Decode function i2                 
      integer*4      decod_i4            ! Decode function i4                 
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_status = 0                                                           
                                                                              
C     Reading current record                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
      call rdRecord(jv_status)                                                
      if (jv_status .ne. 0) goto 9999                                         
                                                                              
C     Get fields in record                                                    
C     ~~~~~~~~~~~~~~~~~~~~                                                    
      jv_lat = decod_i4(jq_sla_lat)                                           
      jv_lon = decod_i4(jq_sla_lon)                                           
                                                                              
      do ev_s = 1 , ev_sla_nbCyc                                              
           ew_sla(ev_s) = decod_i2(ep_sla_data(ev_s))                         
      enddo                                                                   
                                                                              
 9999 continue                                                                
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  CLOSESLA                                                          |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Closing SLA file                                                |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C | <none>                                                             |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine closeSLA                                                     

      include "readSLA.h"
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4       jv_ios                ! status I/O file                 
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      if (lv_sla_open) then                                                   
           close(unit=jc_sla_lun , iostat=jv_ios)                             
           lv_sla_open   = .false.                                            
           jv_sla_recNum = 0                                                  
      endif                                                                   
                                                                              
                                                                              
      return                                                                  
      end                                                                     
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  RDRECORD      (internal)                                          |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Reading current record                                          |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | <none>                                                             |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C | jv_status     : Status   0 -> OK ; 1 -> NOK                        |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine rdRecord (jv_status)                                         
      
      include "readSLA.h"
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4      jv_status           ! (O) Return Status                  
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4       jv_ios                ! status I/O file                 
      integer*4       jv_b                  ! bytes count                     
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_status = 0                                                           
                                                                              
C     Test if SLA file open                                                   
C     ~~~~~~~~~~~~~~~~~~~~~                                                   
      if (.not. lv_sla_open) then                                             
           print *,' '                                                        
           print *,'Subroutine : RDSLA'                                       
           print *,'SLA file not opened'                                      
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
C     Reading current record                                                  
C     ~~~~~~~~~~~~~~~~~~~~~~                                                  
      jv_sla_recNum = jv_sla_recNum + 1                                       
                                                                              
      read (unit = jc_sla_lun    ,                                            
     &      rec  = jv_sla_recNum ,                                            
     &      iostat = jv_ios)                                                  
     &     (yw_sla_rec(jv_b) , jv_b = 1 , jv_sla_recl)                        
                                                                              
      if (jv_ios .ne. 0) then                                                 
           print *,' '                                                        
           print *,'Subroutine : RDSLA'                                       
           print *,'Error during read'                                        
           print *,'Record number : ',jv_sla_recNum                           
           print *,'Status        : ',jv_ios                                  
           print *,' '                                                        
           jv_status = 1                                                      
           goto 9999                                                          
      endif                                                                   
                                                                              
 9999 continue                                                                
      return                                                                  
      end                                                                     
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C | DECOD_I2 (internal)                                                |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C | Change a Vax two-byte integer into a Sun two-byte integer          |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | yw_i2     : Vax two-byte integer                                   |      
C |                   +--------+--------+                              |      
C |                   |    A   |    B   |                              |      
C |                   +--------+--------+                              |      
C |                     yw_i2(1) (yw_i(2)                              |      
C |                                                                    |      
C | Output                                                             |      
C | ------                                                             |      
C |                   +--------+--------+                              |      
C |                   |s   B   |    A   |  s: sign bit                 |      
C |                   +--------+--------+                              |      
C |                        decod_i2                                    |      
C +--------------------------------------------------------------------+      
                                                                              
                                                                              
	Integer*2 Function decod_i2(yw_i2)                                           
                                                                              
      implicit none                                                           
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      byte      yw_i2(2)            ! (I) Vax integer 2                       
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
	decod_i2 = yw_i2(2)                                                          
	decod_i2 = decod_i2 * 256                                                    
	if (yw_i2(1) .LT. 0) then                                                    
		decod_i2 = decod_i2 + 256+ yw_i2(1)                                         
	else                                                                         
		decod_i2 = decod_i2 + yw_i2(1)                                              
	endif                                                                        
                                                                              
	return                                                                       
	end                                                                          
                                                                              
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C | DECOD_I4 (internal)                                                |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C | Change a Vax four-byte integer into a Sun four-byte integer        |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | yw_i4     : Vax four-byte integer                                  |      
C |             +--------+--------+--------+--------+                  |      
C |             |    A   |    B   |   C    |    D   |                  |      
C |             +--------+--------+--------+--------+                  |      
C |               yw_i4(1) yw_i4(2) yw_i4(3) yw_i4(4)                  |      
C |                                                                    |      
C | Output                                                             |      
C | ------                                                             |      
C |             +--------+--------+--------+--------+                  |      
C |             |    D   |    C   |   B    |    A   |                  |      
C |             +--------+--------+--------+--------+                  |      
C |                           decod_i4                                 |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
	integer*4 function decod_i4(yw_i4)                                           
                                                                              
      implicit none                                                           
                                                                              
C +--------------------------------------------------------------------+      
C |                        P A R A M E T E R S                         |      
C +--------------------------------------------------------------------+      
                                                                              
      byte      yw_i4(4)            ! (I) Vax integer 4                       
                                                                              
C +--------------------------------------------------------------------+      
C |                     L O C A L   V A R I A B L E S                  |      
C +--------------------------------------------------------------------+      
                                                                              
      integer*4 jv_temp             ! Temporary variable                      
                                                                              
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
	decod_i4 = yw_i4(1)                                                          
	if (decod_i4 .LT. 0) then                                                    
		decod_i4 = 256 + decod_i4                                                   
	endif                                                                        
                                                                              
	jv_temp = yw_i4(2)                                                           
	if (jv_temp .LT. 0) then                                                     
		jv_temp = 256 + jv_temp                                                     
	endif                                                                        
	decod_i4 = decod_i4 + jv_temp * 256                                          
                                                                              
	jv_temp = yw_i4(3)                                                           
	if (jv_temp .LT. 0) then                                                     
		jv_temp = 256 + jv_temp                                                     
	endif                                                                        
	decod_i4 = decod_i4 + jv_temp * 65536                                        
                                                                              
        jv_temp  = yw_i4(4)                                                   
	decod_i4 = decod_i4 + jv_temp * 16777216                                     
                                                                              
	return                                                                       
	end                                                                          
                                                                              
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  SKIPREC                                                          |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
C |                                                                    |      
C |  - Skip n records of an SLA file                                   |      
C |                                                                    |      
C | Input parameters                                                   |      
C | ----------------                                                   |      
C | nbRec         :number of records to skip                           |      
C |                                                                    |      
C | Output parameters                                                  |      
C | -----------------                                                  |      
C | <none>                                                             |      
C |                                                                    |      
C +--------------------------------------------------------------------+      
                                                                              
      subroutine skipRec(nbRec)                                               

      include "readSLA.h"
      integer*2 nbRec
C +--------------------------------------------------------------------+      
C |                              C O D E                               |      
C +--------------------------------------------------------------------+      
                                                                              
      jv_sla_recNum=jv_sla_recNum+nbRec
      return
      end

      logical function inside_box(xlat,xlon)
      real xlat
      real xlon
      real maxLat
      real maxLon
      real minLat
      real minLon
      parameter (minLat = 28.250)
      parameter (maxLat = 36.250)
      parameter (minLon = 290.000)
      parameter (maxLon = 300.000)

      inside_box=(xlat.ge.minLat).and.(xlat.le.maxLat).and.
     &     (xlon.ge.minLon).and.(xlon.le.maxLon) 
      return
      end
