The maxdims argument is needed to specify the length of the array coords, usually is process_dimensions.
This routine does not actually perform a "shift" (more on this later). What it does do is return the correct ranks for a shift which can then be included directly as arguments to MPI_Send, MPI_Recv, MPI_Sendrecv, etc. to perform the actual shift.
The following virtual topology shows MPI_cart_shift called on process 20 with direction = 0 and disp = 2.
The following topology shows an MPI_Cart_shift also called on process 20 but direction = 1 and disp = -1. Note the effect of the periodic boundary condition.
Here is an example of two shifts. MPI_Sendrecv could be used for both.