nc_rar.F 10.6 KB
*
* nc_rar.F
*
* James Caveen - UQAR
* Janvier 2007
*
* nc_rar.F: reconstruire les axes reduits
*           reduced axes reconstruction
* Decompresse un champ de points mouilles et
* reconstruit le champ 3D correspondant
*
* $Id: nc_rar.F,v 1.3 2007-02-14 14:43:34 caveenj Exp $
*
* $Log: not supported by cvs2svn $
*
*
*
* In this subroutine we provide information about
* the function.  The user configurable information 
* consists of the following:
*
* descr              Text description of the function
*
* num_args           Required number of arguments
*
* axis_inheritance   Type of axis for the result
*                       ( CUSTOM, IMPLIED_BY_ARGS, NORMAL, ABSTRACT )
*                       CUSTOM          - user defined axis
*                       IMPLIED_BY_ARGS - same axis as the incoming argument
*                       NORMAL          - the result is normal to this axis
*                       ABSTRACT        - an axis which only has index values
*
* piecemeal_ok       For memory optimization:
*                       axes where calculation may be performed piecemeal
*                       ( YES, NO )
* 
*
* For each argument we provide the following information:
*
* name               Text name for an argument
*
* unit               Text units for an argument
*
* desc               Text description of an argument
*
* axis_influence     Are this argument's axes the same as the result grid?
*                       ( YES, NO )
*
* axis_extend       How much does Ferret need to extend arg limits relative to result 
*


      SUBROUTINE nc_rar_init(id)

      INCLUDE 'ferret_cmn/EF_Util.cmn'

      INTEGER id, arg

************************************************************************
*                                            USER CONFIGURABLE PORTION |
*                                                                      |
*                                                                      V

      CALL ef_set_desc(id,'Reconstruire des axes reduits'//
     $     ' - reduced axes reconstruction' )

      CALL ef_set_num_args(id, 2)
      CALL ef_set_axis_inheritance(id, ABSTRACT, 
     .     ABSTRACT,IMPLIED_BY_ARGS, IMPLIED_BY_ARGS)
      CALL ef_set_piecemeal_ok(id, NO, NO, NO, NO)

      arg = 1
      CALL ef_set_arg_name(id, arg, 'A')
      CALL ef_set_arg_desc(id, arg,'Champ decrivant la grille de '//
     $      'sortie - Field describing output grid')
      CALL ef_set_axis_influence(id, arg, YES, YES, YES, YES)

      arg = 2
      CALL ef_set_arg_name(id, arg, 'B')
      call ef_set_arg_desc(id,arg,'Champ a reconstruire - ' //
     $     'Field to rebuild')
      CALL ef_set_axis_influence(id, arg, NO, NO, NO, YES)


      CALL ef_set_num_work_arrays(id, 1)

*                                                                      ^
*                                                                      |
*                                            USER CONFIGURABLE PORTION |
************************************************************************

      RETURN 
      END

      subroutine nc_rar_result_limits(id)

      implicit none

      INCLUDE 'ferret_cmn/EF_Util.cmn'
      INCLUDE 'ferret_cmn/EF_mem_subsc.cmn'

      INTEGER id

* **********************************************************************
*                                           USER CONFIGURABLE PORTION |
*                                                                     |
*                                                                     V
      INTEGER my_lo_x, my_hi_x, my_lo_y, my_hi_y
      integer nx,ny
      CHARACTER*100 errtxt

      INTEGER arg_lo_ss(4,EF_MAX_ARGS), arg_hi_ss(4,EF_MAX_ARGS),
     .     arg_incr(4,EF_MAX_ARGS)

*
*     Use utility functions to get context information about the arguments.
*     Set the abstract X Y.
*
*     les proprietes de l'axe Z sont heritees du premier champ passe en argument
*     lors de l'appel a la fonction nc_rar
*

      CALL ef_get_arg_subscripts(id, arg_lo_ss, arg_hi_ss, arg_incr)

      nx = arg_hi_ss(X_AXIS, ARG1) - arg_lo_ss(X_AXIS, ARG1) + 1
      ny = arg_hi_ss(Y_AXIS, ARG1) - arg_lo_ss(Y_AXIS, ARG1) + 1

*    Nos axes X et Y sont de type ABSTRACT, on les reindice donc a partir de 1
*    

      my_lo_x = 1
      my_hi_x = nx
      my_lo_y = 1
      my_hi_y = ny


      CALL ef_set_axis_limits(id, X_AXIS, my_lo_x, my_hi_x)
      CALL ef_set_axis_limits(id, Y_AXIS, my_lo_y, my_hi_y)


*                                                                     ^
*                                                                     |
*                                           USER CONFIGURABLE PORTION |
* **********************************************************************

      RETURN


 999   CONTINUE

       CALL EF_BAIL_OUT(id, errtxt)

      END


*
*
* Dans cette fonction on initialise un espace de travail
* qui contiendra les coordonnees reelles de l'axe wet
*
* Note:  les coordonnees sont de type real*8
*
      subroutine nc_rar_work_size(id)

      implicit none



      INCLUDE 'ferret_cmn/EF_Util.cmn'
      INCLUDE 'ferret_cmn/EF_mem_subsc.cmn'

      INTEGER id

      integer nxout

      character*100 errtxt


      INTEGER arg_lo_ss(4,EF_MAX_ARGS), arg_hi_ss(4,EF_MAX_ARGS),
     $          arg_incr(4,EF_MAX_ARGS)


      call ef_get_arg_subscripts(id,arg_lo_ss,arg_hi_ss,arg_incr)

      nxout = 1 + arg_hi_ss(X_AXIS,ARG2) -arg_lo_ss(X_AXIS,ARG2)

*
*Definition du tableau de travail XAX
*
*
* Les coordonnees qui seront contenues dans xax sont en real*8
* donc, on double l'espace requis
*
      nxout = nxout * 2
      call ef_set_work_array_dims(id,1,1,1,1,1,nxout,1,1,1)

      return
      end

*
* In this subroutine we compute the result
*
      SUBROUTINE nc_rar_compute(id, arg_1, arg_2, result,xax)

      implicit none

      INCLUDE 'ferret_cmn/EF_Util.cmn'
      INCLUDE 'ferret_cmn/EF_mem_subsc.cmn'

      INTEGER id

      REAL bad_flag(EF_MAX_ARGS), bad_flag_result

      REAL arg_1(mem1lox:mem1hix, mem1loy:mem1hiy, 
     .     mem1loz:mem1hiz, mem1lot:mem1hit)

      REAL arg_2(mem2lox:mem2hix, mem2loy:mem2hiy, 
     .     mem2loz:mem2hiz, mem2lot:mem2hit)

      REAL result(memreslox:memreshix, memresloy:memreshiy, 
     .     memresloz:memreshiz, memreslot:memreshit)

*
* Le tableau XAX est un tableau de travail qui contiendra
* les coordonnnes des points sur le vecteur comprime (pts mouilles)
* On divise la dimension wrk1hix par 2 car dans la fonction
* d'allocation d'espace de travail, on a alloue deux fois
* plus d'espace pour tenir compte du fait que xax est real*8
      real*8 xax(wrk1lox:wrk1hix/2,wrk1loy:wrk1hiy,wrk1loz:wrk1hiz,
     $     wrk1lot:wrk1hit)

* After initialization, the 'res_' arrays contain indexing information 
* for the result axes.  The 'arg_' arrays will contain the indexing 
* information for each variable's axes. 

      INTEGER res_lo_ss(4), res_hi_ss(4), res_incr(4)
      INTEGER arg_lo_ss(4,EF_MAX_ARGS), arg_hi_ss(4,EF_MAX_ARGS),
     $          arg_incr(4,EF_MAX_ARGS)


************************************************************************
*                                            USER CONFIGURABLE PORTION |
*                                                                      |
*                                                                      V

      INTEGER i,j,k,l
      INTEGER i2, j2, k2, l2

      integer arg
      character*100 errtxt

      integer dimxy,dimx,indx,indy,indz,indice


      CALL ef_get_res_subscripts(id, res_lo_ss, res_hi_ss, res_incr)
      CALL ef_get_arg_subscripts(id, arg_lo_ss, arg_hi_ss, arg_incr)
      CALL ef_get_bad_flags(id, bad_flag, bad_flag_result)
      
      arg = 2

*
* Obtenir la liste des indices des points mouilles sur la grille 3D
* 
      call ef_get_coordinates(id,arg,X_AXIS,arg_lo_ss(X_AXIS,
     $     ARG2),arg_hi_ss(X_AXIS,ARG2),xax)


#if defined DEBUG
      write(6,*)'res_lo_ss(X_AXIS), res_hi_ss(X_AXIS)',
     &     res_lo_ss(X_AXIS), res_hi_ss(X_AXIS)

      write(6,*)'res_lo_ss(Y_AXIS), res_hi_ss(Y_AXIS)',
     &     res_lo_ss(Y_AXIS), res_hi_ss(Y_AXIS)

      write(6,*)'res_lo_ss(Z_AXIS), res_hi_ss(Z_AXIS)',
     &     res_lo_ss(Z_AXIS), res_hi_ss(Z_AXIS)

      write(6,*)'res_lo_ss(T_AXIS), res_hi_ss(T_AXIS)',
     &     res_lo_ss(T_AXIS), res_hi_ss(T_AXIS)
#endif
C
C     Initialiser le champ de sortie a des manquants
C

      do  i=res_lo_ss(X_AXIS), res_hi_ss(X_AXIS)
         do  j=res_lo_ss(Y_AXIS), res_hi_ss(Y_AXIS)
            do  k=res_lo_ss(Z_AXIS), res_hi_ss(Z_AXIS)
               do  l=res_lo_ss(T_AXIS), res_hi_ss(T_AXIS)
                  result(i,j,k,l) = bad_flag_result
               enddo
            enddo
         enddo
      enddo




C
C    Reconstruction des axes de la grille 3D
C    et des valeurs du champ sur cette grille
C    
C



*
* Calcul des dimensions necessaires au calcul des coordonnees
*

        dimxy = res_hi_ss(X_AXIS)*res_hi_ss(Y_AXIS)
        dimx = res_hi_ss(X_AXIS)
 
*
*Calcul de l'indice de depart j et k du champ compresse
*cet indice demeure constant dans le calcul
* et est probablement = -111 ( i.e., non defini)
        j2 = arg_lo_ss(Y_AXIS,ARG2)
        k2 = arg_lo_ss(Z_AXIS,ARG2)


* Ici, on boucle sur les coordonnes des points mouilles
* et on recalcule les coordonnes i,j,k du champ 3D
* a partir de la coordonnee 1D 
* puis on assigne a result(i,j,k) la valeur
* correspondante dans le champ qui avait ete cree lors  
* de la compression des axes (arg_2)
*

        do i2 = arg_lo_ss(X_AXIS,ARG2),arg_hi_ss(X_AXIS,ARG2)
           indice = int(xax(i2,1,1,1))
           indz = (indice - 1)/dimxy
           indice = indice - indz*dimxy
           indy = (indice - 1)/dimx
           indx = indice - indy*dimx
           indz = indz + 1 
           indy = indy + 1

*
*          On s'assure que les indices calcules sont a
*          l'interieur du domaine demande 
*
           if( (indx .ge. res_lo_ss(X_AXIS) .and. 
     &          indx .le. res_hi_ss(X_AXIS)) .and.
     &          (indy .ge. res_lo_ss(Y_AXIS) .and. 
     &          indy .le. res_hi_ss(Y_AXIS)) .and.
     &          (indz .ge. res_lo_ss(Z_AXIS) .and. 
     &          indz .le. res_hi_ss(Z_AXIS))) then

              
*
* On repete l'operation pour chaque pas de temps demande
*
              l2 = arg_lo_ss(T_AXIS,ARG2) 

              do l = res_lo_ss(T_AXIS),res_hi_ss(T_AXIS)
                 result(indx,indy,indz,l) = arg_2(i2,j2,k2,l2)
                 l2 = l2 + arg_incr(T_AXIS,ARG2)
              enddo
           endif
        enddo


      
*                                                                      ^
*                                                                      |
*                                            USER CONFIGURABLE PORTION |
************************************************************************

      RETURN 
      END