run Subroutine

subroutine run(im, lm, n_fields, output_filename)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: im
integer, intent(in) :: lm
integer, intent(in) :: n_fields
character(len=*), intent(in) :: output_filename

Calls

proc~~run~17~~CallsGraph proc~run~17 run mpi_comm_rank mpi_comm_rank proc~run~17->mpi_comm_rank mpi_comm_size mpi_comm_size proc~run~17->mpi_comm_size none~add_dimension FileMetadata%add_dimension proc~run~17->none~add_dimension none~add_variable FileMetadata%add_variable proc~run~17->none~add_variable none~create_par NetCDF4_FileFormatter%create_par proc~run~17->none~create_par none~put_var~21 NetCDF4_FileFormatter%put_var proc~run~17->none~put_var~21 proc~mapl_verify MAPL_Verify proc~run~17->proc~mapl_verify insert insert none~add_dimension->insert proc~mapl_return MAPL_Return none~add_dimension->proc~mapl_return at at none~add_variable->at begin begin none~add_variable->begin get get none~add_variable->get interface~mapl_assert MAPL_Assert none~add_variable->interface~mapl_assert next next none~add_variable->next none~get_const_value Variable%get_const_value none~add_variable->none~get_const_value none~get_dimensions Variable%get_dimensions none~add_variable->none~get_dimensions none~get_shape UnlimitedEntity%get_shape none~add_variable->none~get_shape none~insert~104 StringVariableMap%insert none~add_variable->none~insert~104 none~is_empty UnlimitedEntity%is_empty none~add_variable->none~is_empty none~add_variable->proc~mapl_return push_back push_back none~add_variable->push_back none~create_par->proc~mapl_verify nf90_create nf90_create none~create_par->nf90_create none~create_par->proc~mapl_return none~put_var_real64_4 NetCDF4_FileFormatter%put_var_real64_4 none~put_var~21->none~put_var_real64_4 proc~mapl_throw_exception MAPL_throw_exception proc~mapl_verify->proc~mapl_throw_exception none~get_shape->proc~mapl_return none~insert_pair~11 StringVariableMap%insert_pair none~insert~104->none~insert_pair~11 none~is_empty->proc~mapl_return none~get_value UnlimitedEntity%get_value none~is_empty->none~get_value none~put_var_real64_4->proc~mapl_verify none~put_var_real64_4->proc~mapl_return nf90_inq_varid nf90_inq_varid none~put_var_real64_4->nf90_inq_varid nf90_put_var nf90_put_var none~put_var_real64_4->nf90_put_var proc~mapl_return->at proc~mapl_return->insert proc~mapl_return->proc~mapl_throw_exception none~get_value->proc~mapl_return

Called by

proc~~run~17~~CalledByGraph proc~run~17 run program~main~16 main program~main~16->proc~run~17

Source Code

   subroutine run(im, lm, n_fields, output_filename)
      integer, intent(in) :: im
      integer, intent(in) :: lm
      integer, intent(in) :: n_fields
      character(*), intent(in) :: output_filename

      type (Netcdf4_Fileformatter) :: formatter
      type (FileMetadata) :: metadata
      real, allocatable :: field(:,:,:)

      integer :: jm
      integer :: j0, j1
      integer :: nj_local
      integer :: rank, npes, ierror
      integer :: j, n
      character(:), allocatable :: field_name
      character(3) :: field_idx_str

      call mpi_comm_size(MPI_COMM_WORLD, npes, ierror)
      _VERIFY(ierror)
      call mpi_comm_rank(MPI_COMM_WORLD, rank, ierror)
      _VERIFY(ierror)

      jm = im*6 ! pseudo cubed sphere
      call metadata%add_dimension('IM_WORLD', im)
      call metadata%add_dimension('JM_WORLD', jm)
      call metadata%add_dimension('LM', lm)

      do n = 1, n_fields
         write(field_idx_str,'(i3.3)') n
         field_name = 'field_' // field_idx_str
         call metadata%add_variable(field_name, Variable(pFIO_REAL32, dimensions='IM_WORLD,JM_WORLD,LM'))
      end do

      call formatter%create_par(output_filename, comm=MPI_COMM_WORLD)
      call formatter%write(metadata)

      j0 = 1 + rank*jm/npes
      j1 = (rank+1)*jm/npes
      nj_local = (j1 - j0) + 1
      allocate(field(im, nj_local, lm))

      do j = j0, j1
         field(:,j-j0+1,:) = j
      end do

      do n = 1, n_fields
         write(field_idx_str,'(i3.3)') n
         field_name = 'field_' // field_idx_str
         call formatter%put_var(field_name, field, start=[1,j0,1], count=[im,nj_local,lm])
      end do

      call formatter%close()
   end subroutine run