write_pedestrian_wind_metadata_nc Subroutine

public subroutine write_pedestrian_wind_metadata_nc(ncid, receptor_height)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ncid
real, intent(in) :: receptor_height

Calls

proc~~write_pedestrian_wind_metadata_nc~~CallsGraph proc~write_pedestrian_wind_metadata_nc write_pedestrian_wind_metadata_nc nf90_def_var nf90_def_var proc~write_pedestrian_wind_metadata_nc->nf90_def_var nf90_enddef nf90_enddef proc~write_pedestrian_wind_metadata_nc->nf90_enddef nf90_get_var nf90_get_var proc~write_pedestrian_wind_metadata_nc->nf90_get_var nf90_inq_varid nf90_inq_varid proc~write_pedestrian_wind_metadata_nc->nf90_inq_varid nf90_inquire_variable nf90_inquire_variable proc~write_pedestrian_wind_metadata_nc->nf90_inquire_variable nf90_put_att nf90_put_att proc~write_pedestrian_wind_metadata_nc->nf90_put_att nf90_put_var nf90_put_var proc~write_pedestrian_wind_metadata_nc->nf90_put_var nf90_redef nf90_redef proc~write_pedestrian_wind_metadata_nc->nf90_redef nf90_sync nf90_sync proc~write_pedestrian_wind_metadata_nc->nf90_sync proc~nchandle_error nchandle_error proc~write_pedestrian_wind_metadata_nc->proc~nchandle_error nf90_strerror nf90_strerror proc~nchandle_error->nf90_strerror

Called by

proc~~write_pedestrian_wind_metadata_nc~~CalledByGraph proc~write_pedestrian_wind_metadata_nc write_pedestrian_wind_metadata_nc proc~stats_define_pedestrian_wind stats_define_pedestrian_wind proc~stats_define_pedestrian_wind->proc~write_pedestrian_wind_metadata_nc proc~stats_createnc_tavg stats_createnc_tavg proc~stats_createnc_tavg->proc~stats_define_pedestrian_wind proc~stats_createnc_tkslice stats_createnc_tkslice proc~stats_createnc_tkslice->proc~stats_define_pedestrian_wind proc~stats_prepare stats_prepare proc~stats_prepare->proc~stats_createnc_tavg proc~stats_prepare->proc~stats_createnc_tkslice proc~stats_main stats_main proc~stats_main->proc~stats_prepare program~udales uDALES program~udales->proc~stats_main

Source Code

  subroutine write_pedestrian_wind_metadata_nc(ncid, receptor_height)
    implicit none

    integer, intent(in) :: ncid
    real, intent(in) :: receptor_height

    integer :: status, height_varid, wind_varid, ndims
    integer :: no_dims(0)
    real :: stored_height, tolerance
    logical :: height_exists

    status = nf90_inq_varid(ncid, 'receptor_height', height_varid)
    height_exists = status == NF90_NOERR
    if (height_exists) then
      status = nf90_inquire_variable(ncid, height_varid, ndims=ndims)
      call nchandle_error(status)
      if (ndims /= 0) then
        write(0,*) 'ERROR: Existing receptor_height is an array; cannot use a single height.'
        stop 1
      end if
      status = nf90_get_var(ncid, height_varid, stored_height)
      call nchandle_error(status)
      tolerance = 100.*epsilon(1.)*max(1., abs(stored_height), abs(receptor_height))
      if (abs(stored_height-receptor_height) > tolerance) then
        write(0,'(a,f10.3,a,f10.3,a)') 'ERROR: Existing receptor_height=', stored_height, &
                                       ' m differs from configured value ', receptor_height, ' m.'
        stop 1
      end if
    else if (status /= NF90_ENOTVAR) then
      call nchandle_error(status)
    end if

    status = nf90_redef(ncid)
    call nchandle_error(status)

    if (.not. height_exists) then
      status = nf90_def_var(ncid, 'receptor_height', NF90_FLOAT, no_dims, height_varid)
      call nchandle_error(status)
    end if

    status = nf90_put_att(ncid, height_varid, 'longname', &
                          'Height above model ground used for ws_local')
    call nchandle_error(status)
    status = nf90_put_att(ncid, height_varid, 'standard_name', 'height')
    call nchandle_error(status)
    status = nf90_put_att(ncid, height_varid, 'units', 'm')
    call nchandle_error(status)
    status = nf90_put_att(ncid, height_varid, 'positive', 'up')
    call nchandle_error(status)

    status = nf90_inq_varid(ncid, 'ws_local', wind_varid)
    call nchandle_error(status)
    status = nf90_inquire_variable(ncid, wind_varid, ndims=ndims)
    call nchandle_error(status)
    if (ndims /= 3) then
      write(0,*) 'ERROR: Existing ws_local has incompatible dimensions for a single height.'
      stop 1
    end if
    status = nf90_put_att(ncid, wind_varid, 'coordinates', 'receptor_height')
    call nchandle_error(status)

    status = nf90_enddef(ncid)
    call nchandle_error(status)
    status = nf90_put_var(ncid, height_varid, receptor_height)
    call nchandle_error(status)
    status = nf90_sync(ncid)
    call nchandle_error(status)
  end subroutine write_pedestrian_wind_metadata_nc