gengrid subroutine

Generates grids from user-defined coordinates and resolution.

How to use

subroutine gengrid(idata, Xmin, Ymin, Xmax, Ymax, res)
Parameters:
  • idata :: map to be created [FPL defined type structure] [1]
  • Xmin :: westernmost longitude [double or float] [1]
  • Ymin :: southernmost latitude [double or float] [1]
  • Xmax :: easternmost longitude [double or float] [1]
  • Ymax :: northernmost latitude [double or float] [1]
  • res :: map resolution [double or float] [1]
Return:

idata :: map structure with defined longitudes, latitudes and resolution. See Structure Fields [1]

Call :

gengrid(idata,Xmin,Ymin,Xmax,Ymax,res)

[1](1, 2, 3, 4, 5, 6, 7) Defined by user

[Code example] Create grided data

Create a 3d netCDF from map extent -74.73715442059999, -34.343706397220295, -34.73715458059378, 5.6562934427799965, 10 times and 1.0 degree resolution.

program main
  use fpl
  implicit none

  !Definition of dataset structures
  type(nc3d_int_llf_ti) :: grid3d
 
  !Auxiliary variables
  integer(kind=intgr) :: i, j, k, l

  character(200) :: opath3d

  !Output files
  opath3d = "database/grid3d.nc"


  !Grid 3d definitions
  grid3d%long_name = "My Grid 1 degree"
  
  grid3d%varname = "grid"
  grid3d%lonname = "lon"
  grid3d%latname = "lat"
  grid3d%timename = "time"

  grid3d%varunits = "dimensionless"
  grid3d%lonunits = "degrees_east"
  grid3d%latunits = "degrees_north"
  grid3d%timeunits = "hour"

  grid3d%ntimes = 10

  grid3d%FillValue = -9999

  !   Latitude|                                  Xmin: westernmost longitude   
  !           |                                  Ymin: southernmost latitude
  !           |       Ymax                       Xmax: easternmost longitude
  !           |_________________                 Ymax: northernmost latitude
  !           |__|__|__|__|__|__|                i, j: initial position of the matrix on the x-axis and y-axis (i=0,j=0).
  !           |__|__|__|__|__|__|                
  !      Xmin |__|__|__|__|__|__| Xmax           
  !           |__|__|__|__|__|__|
  !          j|__|__|__|__|__|__|_____________ 
  !           i                      Longitude 
  !                   Ymin

  !Generates a 3d grid
  call gengrid(grid3d, -74.73715442059999, -34.343706397220295, -34.73715458059378, 5.6562934427799965, 1.0)

  !Fills the array data
  do i = 1, grid3d%ntimes
    do j = 1, grid3d%nlons
      do k = 1, grid3d%nlats
        grid3d%ncdata(j,k,i) = int(i*(cos(real(j))*grid3d%longitudes(j) + k*grid3d%latitudes(k)))
      end do
    end do
  end do

  !Write 3d data on file
  call writegrid(opath3d, grid3d)

end program main
#RedHat based systems
gfortran -o gengrid.out gengrid.f90 -I/usr/lib64/gfortran/modules/ -lFPL

#Debian based systems
gfortran -o gengrid.out gengrid.f90 -I/usr/include/ -lFPL

Important

-I<dir> This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to Influencing the linking step. See the GNU Fortran Compiler Documentation .

<dir> is defined in Makefile as $(FPL_moddir). See Build Library.

After compilation run the program ./gengrid.out