use 
  else if (P_unit=="GPa")
here.

Also, what if the unit given is neither kbar nor GPa? It would be good to have some error checking here, rather than siilently treat every other text as Pa.