Recipe: Fortran program as OPeNDAP client: Difference between revisions
Line 20: | Line 20: | ||
==== Code ==== | ==== Code ==== | ||
<syntaxhighlight lang="fortran" line> | <syntaxhighlight lang="fortran" line> | ||
program g5nr_reader_dap | program g5nr_reader_dap | ||
Line 32: | Line 33: | ||
! 4D array: (lon,lat,lev,time) | ! 4D array: (lon,lat,lev,time) | ||
! ------------------------------------ | ! ------------------------------------ | ||
real, allocatable :: T(:,:,:,:) | real, allocatable :: T(:,:,:,:) | ||
! Miscellaneous | ! Miscellaneous | ||
Line 42: | Line 43: | ||
integer :: imin, imax, jmin, jmax | integer :: imin, imax, jmin, jmax | ||
real :: minlat, minlon, maxlat, maxlon | real :: minlat, minlon, maxlat, maxlon | ||
! We replace filename by opendal url | |||
! ---------------------------------- | |||
T_file = "http://opendap.nccs.nasa.gov:9090/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv" | |||
! file name and (subset) dimensions | ! file name and (subset) dimensions | ||
! bounding box: | ! bounding box: | ||
! lons = - | ! lons = -130:0.5:-65 | ||
! lats = | ! lats = 25:0.5:50 | ||
! --------------------------------- | ! --------------------------------- | ||
! array indices from the | |||
! | |||
! bounding lat/lon values | ! bounding lat/lon values | ||
imin = nint(( | imin = nint((-130. + 180.)/0.5) | ||
imax = nint(( | imax = nint(( -65. + 180.)/0.5) | ||
jmin = nint(( | jmin = nint(( 25 + 90.)/0.5) | ||
jmax = nint(( | jmax = nint(( 50 + 90.)/0.5) | ||
! | ! array sizes | ||
im = imax-imin+1 | im = imax-imin+1 | ||
jm = jmax-jmin+1 | jm = jmax-jmin+1 | ||
lm = 72 | lm = 72 | ||
! Open | ! Open url and get var id | ||
! | ! ----------------------- | ||
call check(nf90_open(T_file,NF90_NOWRITE,ncid), "opening T file") | call check(nf90_open(T_file,NF90_NOWRITE,ncid), "opening T file") | ||
call check(nf90_inq_varid(ncid,"t",varid), "getting T varid") | call check(nf90_inq_varid(ncid,"t",varid), "getting T varid") | ||
! Read | ! Read temperature data | ||
! | ! --------------------- | ||
allocate(T(im,jm,lm,1)) ! global 4D array with 1 time level | allocate(T(im,jm,lm,1)) ! global 4D array with 1 time level | ||
start = [imin, jmin, 1, 11772] | start = [imin, jmin, 1, 11772] ! time level 11772 corresponds to 2006/09/18, 9z | ||
count = [im, jm, lm, 1] ! 1 time level, 3D (lon,lat,lev) array | count = [im, jm, lm, 1] ! 1 time level, 3D (lon,lat,lev) array | ||
write(*,*) 'Reading T...' | write(*,*) 'Reading T...' |