libsim  Versione8.0.0

◆ volgrid6d_transform()

subroutine volgrid6d_transform ( type(transform_def), intent(in)  this,
type(griddim_def), intent(in), optional  griddim,
type(volgrid6d), intent(inout)  volgrid6d_in,
type(volgrid6d), intent(out)  volgrid6d_out,
type(vol7d_level), dimension(:), intent(in), optional, target  lev_out,
type(volgrid6d), intent(in), optional  volgrid6d_coord_in,
real, dimension(:,:), intent(in), optional  maskgrid,
real, dimension(:), intent(in), optional  maskbounds,
logical, intent(in), optional  clone,
logical, intent(in), optional  decode,
character(len=*), intent(in), optional  categoryappend 
)

Performs the specified abstract transformation on the data provided.

The abstract transformation is specified by this parameter; the corresponding specifical transformation (grid_transform object) is created and destroyed internally. The output transformed object is created internally and it does not require preliminary initialisation.

Parametri
[in]thisobject specifying the abstract transformation
[in]griddimgriddim specifying the output grid (required by most transformation types)
[in,out]volgrid6d_inobject to be transformed, it is not modified, despite the INTENT(inout)
[out]volgrid6d_outtransformed object, it does not require initialisation
[in]lev_outvol7d_level object defining target vertical grid, for vertical interpolations
[in]volgrid6d_coord_inobject providing time constant input vertical coordinate for some kind of vertical interpolations
[in]maskgrid2D field to be used for defining subareas according to its values, it must have the same shape as the field to be interpolated (for transformation subtype 'maskfill')
[in]maskboundsarray of boundary values for defining a subset of valid points where the values of maskgrid are within the first and last value of maskbounds (for transformation type 'metamorphosis:maskfill')
[in]cloneif provided and .TRUE. , clone the gaid's from volgrid6d_in to volgrid6d_out
[in]decodedetermine whether the data in volgrid6d_out should be decoded or remain coded in gaid, if not provided, the decode status is taken from volgrid6d_in
[in]categoryappendappend this suffix to log4fortran namespace category

Definizione alla linea 1851 del file volgrid6d_class.F90.

1851 
1852  CALL init(volgrid6d_out, griddim=volgrid6d_in%griddim, &
1853  time_definition=volgrid6d_in%time_definition, categoryappend=categoryappend)
1854  IF (c_e(var_coord_in)) THEN
1855  CALL init(grid_trans, this, lev_in=volgrid6d_in%level, lev_out=lev_out, &
1856  coord_3d_in=coord_3d_in, categoryappend=categoryappend)
1857  ELSE
1858  CALL init(grid_trans, this, lev_in=volgrid6d_in%level, lev_out=lev_out, &
1859  categoryappend=categoryappend)
1860  ENDIF
1861 
1862  CALL get_val(grid_trans, output_level_auto=llev_out) ! get levels if auto-generated
1863  IF (.NOT.ASSOCIATED(llev_out)) llev_out => lev_out
1864  nlevel = SIZE(llev_out)
1865  ELSE
1866  CALL l4f_category_log(volgrid6d_in%category, l4f_error, &
1867  'volgrid6d_transform: vertint requested but lev_out not provided')
1868  CALL init(volgrid6d_out) ! initialize to empty
1869  CALL raise_error()
1870  RETURN
1871  ENDIF
1872 
1873 ELSE
1874  CALL init(volgrid6d_out, griddim=griddim, &
1875  time_definition=volgrid6d_in%time_definition, categoryappend=categoryappend)
1876  CALL init(grid_trans, this, in=volgrid6d_in%griddim, out=volgrid6d_out%griddim, &
1877  maskgrid=maskgrid, maskbounds=maskbounds, categoryappend=categoryappend)
1878 ENDIF
1879 
1880 
1881 IF (c_e(grid_trans)) THEN ! transformation is valid
1882 
1883  CALL volgrid6d_alloc(volgrid6d_out, ntime=ntime, nlevel=nlevel, &
1884  ntimerange=ntimerange, nvar=nvar)
1885 
1886  IF (PRESENT(decode)) THEN ! explicitly set decode status
1887  ldecode = decode
1888  ELSE ! take it from input
1889  ldecode = ASSOCIATED(volgrid6d_in%voldati)
1890  ENDIF
1891 ! force decode if gaid is readonly
1892  decode_loop: DO i6 = 1,nvar
1893  DO i5 = 1, ntimerange
1894  DO i4 = 1, ntime
1895  DO i3 = 1, nlevel
1896  IF (c_e(volgrid6d_in%gaid(i3,i4,i5,i6))) THEN
1897  ldecode = ldecode .OR. grid_id_readonly(volgrid6d_in%gaid(i3,i4,i5,i6))
1898  EXIT decode_loop
1899  ENDIF
1900  ENDDO
1901  ENDDO
1902  ENDDO
1903  ENDDO decode_loop
1904 
1905  IF (PRESENT(decode)) THEN
1906  IF (ldecode.NEQV.decode) THEN
1907  CALL l4f_category_log(volgrid6d_in%category, l4f_warn, &
1908  'volgrid6d_transform: decode status forced to .TRUE. because driver does not allow copy')
1909  ENDIF
1910  ENDIF
1911 
1912  CALL volgrid6d_alloc_vol(volgrid6d_out, decode=ldecode)
1913 
1914 !ensure unproj was called
1915 !call griddim_unproj(volgrid6d_out%griddim)
1916 
1917  IF (trans_type == 'vertint') THEN
1918 #ifdef DEBUG
1919  CALL l4f_category_log(volgrid6d_in%category, l4f_debug, &
1920  "volgrid6d_transform: vertint to "//t2c(nlevel)//" levels")
1921 #endif
1922  CALL compute(grid_trans, volgrid6d_in, volgrid6d_out, lev_out=llev_out, &
1923  var_coord_vol=var_coord_vol, clone=clone)
1924  ELSE
1925  CALL compute(grid_trans, volgrid6d_in, volgrid6d_out, clone=clone)
1926  ENDIF
1927 
1928  IF (cf_out == 0) THEN ! unrotated components are desired
1929  CALL wind_unrot(volgrid6d_out) ! unrotate if necessary
1930  ELSE IF (cf_out == 1) THEN ! rotated components are desired
1931  CALL wind_rot(volgrid6d_out) ! rotate if necessary
1932  ENDIF
1933 
1934 ELSE
1935 ! should log with grid_trans%category, but it is private
1936  CALL l4f_category_log(volgrid6d_in%category, l4f_error, &
1937  'volgrid6d_transform: transformation not valid')
1938  CALL raise_error()
1939 ENDIF
1940 
1941 CALL delete (grid_trans)
1942 
1943 END SUBROUTINE volgrid6d_transform
1944 
1945 
1954 SUBROUTINE volgrid6dv_transform(this, griddim, volgrid6d_in, volgrid6d_out, &
1955  lev_out, volgrid6d_coord_in, maskgrid, maskbounds, clone, decode, categoryappend)
1956 TYPE(transform_def),INTENT(in) :: this
1957 TYPE(griddim_def),INTENT(in),OPTIONAL :: griddim
1958 TYPE(volgrid6d),INTENT(inout) :: volgrid6d_in(:)
1959 TYPE(volgrid6d),POINTER :: volgrid6d_out(:)
1960 TYPE(vol7d_level),INTENT(in),OPTIONAL :: lev_out(:)
1961 TYPE(volgrid6d),INTENT(in),OPTIONAL :: volgrid6d_coord_in
1962 REAL,INTENT(in),OPTIONAL :: maskgrid(:,:)
1963 REAL,INTENT(in),OPTIONAL :: maskbounds(:)
1964 LOGICAL,INTENT(in),OPTIONAL :: clone
1965 LOGICAL,INTENT(in),OPTIONAL :: decode
1966 CHARACTER(len=*),INTENT(in),OPTIONAL :: categoryappend
1967 
1968 INTEGER :: i, stallo
1969 
1970 
1971 allocate(volgrid6d_out(size(volgrid6d_in)),stat=stallo)
1972 if (stallo /= 0)then
1973  call l4f_log(l4f_fatal,"allocating memory")
1974  call raise_fatal_error()
1975 end if
1976 
1977 do i=1,size(volgrid6d_in)
1978  call transform(this, griddim, volgrid6d_in(i), volgrid6d_out(i), &
1979  lev_out=lev_out, volgrid6d_coord_in=volgrid6d_coord_in, &
1980  maskgrid=maskgrid, maskbounds=maskbounds, &
1981  clone=clone, decode=decode, categoryappend=categoryappend)
1982 end do
1983 
1984 END SUBROUTINE volgrid6dv_transform
1985 
1986 
1987 ! Internal method for performing grid to sparse point computations
1988 SUBROUTINE volgrid6d_v7d_transform_compute(this, volgrid6d_in, vol7d_out, &
1989  networkname, noconvert)
1990 TYPE(grid_transform),INTENT(in) :: this ! oggetto di trasformazione per grigliato
1991 type(volgrid6d), INTENT(in) :: volgrid6d_in ! oggetto da trasformare
1992 type(vol7d), INTENT(inout) :: vol7d_out ! oggetto trasformato
1993 CHARACTER(len=*),OPTIONAL,INTENT(in) :: networkname ! imposta il network in vol7d_out (default='generic')
1994 LOGICAL,OPTIONAL,INTENT(in) :: noconvert
1995 
1996 INTEGER :: nntime, nana, ntime, ntimerange, nlevel, nvar, stallo
1997 INTEGER :: itime, itimerange, ivar, inetwork
1998 REAL,ALLOCATABLE :: voldatir_out(:,:,:)
1999 TYPE(conv_func),POINTER :: c_func(:)
2000 TYPE(datetime),ALLOCATABLE :: validitytime(:,:)
2001 REAL,POINTER :: voldatiin(:,:,:)
2002 
2003 #ifdef DEBUG
2004 call l4f_category_log(volgrid6d_in%category,l4f_debug,"start volgrid6d_v7d_transform_compute")
2005 #endif
2006 
2007 ntime=0
2008 ntimerange=0
2009 nlevel=0
2010 nvar=0
2011 NULLIFY(c_func)
2012 
2013 if (present(networkname))then
2014  call init(vol7d_out%network(1),name=networkname)
2015 else
2016  call init(vol7d_out%network(1),name='generic')
2017 end if
2018 
2019 if (associated(volgrid6d_in%timerange))then
2020  ntimerange=size(volgrid6d_in%timerange)
2021  vol7d_out%timerange=volgrid6d_in%timerange
2022 end if
2023 
2024 if (associated(volgrid6d_in%time))then
2025  ntime=size(volgrid6d_in%time)
2026 
2027  if (vol7d_out%time_definition == volgrid6d_in%time_definition) then
2028 
2029  ! i time sono definiti uguali: assegno
2030  vol7d_out%time=volgrid6d_in%time
2031 
2032  else
2033  ! converto reference in validity
2034  allocate (validitytime(ntime,ntimerange),stat=stallo)
2035  if (stallo /=0)then
2036  call l4f_category_log(volgrid6d_in%category,l4f_fatal,"allocating memory")
2037  call raise_fatal_error()
2038  end if
2039 
2040  do itime=1,ntime
2041  do itimerange=1,ntimerange
2042  if (vol7d_out%time_definition > volgrid6d_in%time_definition) then
2043  validitytime(itime,itimerange) = &
2044  volgrid6d_in%time(itime) + timedelta_new(sec=volgrid6d_in%timerange(itimerange)%p1)
2045  else
2046  validitytime(itime,itimerange) = &
2047  volgrid6d_in%time(itime) - timedelta_new(sec=volgrid6d_in%timerange(itimerange)%p1)
2048  end if
2049  end do
2050  end do
2051 
2052  nntime = count_distinct(reshape(validitytime,(/ntime*ntimerange/)), back=.true.)
2053  vol7d_out%time=pack_distinct(reshape(validitytime,(/ntime*ntimerange/)), nntime,back=.true.)
2054 
2055  end if
2056 end if
2057 
2058 IF (ASSOCIATED(volgrid6d_in%level)) THEN
2059  nlevel = SIZE(volgrid6d_in%level)
2060  vol7d_out%level=volgrid6d_in%level
2061 ENDIF
2062 
2063 IF (ASSOCIATED(volgrid6d_in%var)) THEN
2064  nvar = SIZE(volgrid6d_in%var)
2065  IF (.NOT. optio_log(noconvert)) THEN
2066  CALL vargrib2varbufr(volgrid6d_in%var, vol7d_out%dativar%r, c_func)
2067  ENDIF
2068 ENDIF
2069 
2070 nana = SIZE(vol7d_out%ana)
2071 
2072 ! allocate once for speed
2073 IF (.NOT.ASSOCIATED(volgrid6d_in%voldati)) THEN
2074  ALLOCATE(voldatiin(volgrid6d_in%griddim%dim%nx, volgrid6d_in%griddim%dim%ny, &
2075  nlevel))
2076 ENDIF
2077 
2078 ALLOCATE(voldatir_out(nana,1,nlevel),stat=stallo)
2079 IF (stallo /= 0) THEN
2080  CALL l4f_category_log(volgrid6d_in%category,l4f_fatal,"allocating memory")
2081  CALL raise_fatal_error()
2082 ENDIF
2083 
2084 inetwork=1
2085 do itime=1,ntime
2086  do itimerange=1,ntimerange
2087 ! do ilevel=1,nlevel
2088  do ivar=1,nvar
2089 
2090  !non è chiaro se questa sezione è utile o no
2091  !ossia il compute sotto sembra prevedere voldatir_out solo in out
2092 !!$ if (vol7d_out%time_definition == volgrid6d_in%time_definition) then
2093 !!$ voldatir_out=reshape(vol7d_out%voldatir(:,itime,ilevel,itimerange,ivar,inetwork),(/nana,1/))
2094 !!$ else
2095 !!$ voldatir_out=reshape(vol7d_out%voldatir(:,index(vol7d_out%time,validitytime(itime,ilevel)),ilevel,itimerange,ivar,inetwork),(/nana,1/))
2096 !!$ end if
2097 
2098  CALL volgrid_get_vol_3d(volgrid6d_in, itime, itimerange, ivar, &
2099  voldatiin)
2100 
2101  CALL compute(this, voldatiin, voldatir_out, vol7d_out%dativar%r(ivar))
2102 
2103  if (vol7d_out%time_definition == volgrid6d_in%time_definition) then
2104  vol7d_out%voldatir(:,itime,:,itimerange,ivar,inetwork) = &
2105  voldatir_out(:,1,:)
2106  else
2107  vol7d_out%voldatir(:,index(vol7d_out%time,validitytime(itime,itimerange)),:,itimerange,ivar,inetwork)=&
2108  reshape(voldatir_out,(/nana,nlevel/))
2109  end if
2110 
2111 ! 1 indice della dimensione "anagrafica"
2112 ! 2 indice della dimensione "tempo"
2113 ! 3 indice della dimensione "livello verticale"
2114 ! 4 indice della dimensione "intervallo temporale"
2115 ! 5 indice della dimensione "variabile"
2116 ! 6 indice della dimensione "rete"
2117 
2118  end do
2119 ! end do
2120  end do
2121 end do
2122 
2123 deallocate(voldatir_out)
2124 IF (.NOT.ASSOCIATED(volgrid6d_in%voldati)) THEN
2125  DEALLOCATE(voldatiin)
2126 ENDIF
2127 if (allocated(validitytime)) deallocate(validitytime)
2128 
2129 ! Rescale valid data according to variable conversion table
2130 IF (ASSOCIATED(c_func)) THEN
2131  DO ivar = 1, nvar
2132  CALL compute(c_func(ivar), vol7d_out%voldatir(:,:,:,:,ivar,:))
2133  ENDDO
2134  DEALLOCATE(c_func)
2135 ENDIF
2136 
2137 end SUBROUTINE volgrid6d_v7d_transform_compute
2138 
2139 
Index method.

Generated with Doxygen.