
/*      FUNCTION PRESS ( Z )                                                     *
C-------------------------------------------------------------------------------
C
C                            Function = PRESS
C
C     This computes pressure in decibars, given the depth in meters.           *
C     Formula is from the GEOSECS operation group (See computer routine
C     listings in the El Nino Watch Data Reports).
C
C-------------------------------------------------------------------------------
*/
#include "common.h"
#include "ocean.h"

/*      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
*/

#define    C1  2.398599584e05
#define    C2  5.753279964e10
#define    C3  4.833657881e05

#if PROTOTYPE_ALLOWED
double PRESS(double Z)
#else
double PRESS(Z)
double Z;
#endif
{
     double ARG, press;
     ARG = C2 -  C3 * Z;
     if (ARG < 0.0)
     {
          printf(" Depth Z = %e meters: too large for function PRESS", Z);
          exit(-1);
     }
     press = C1 - sqrt( ARG );
     return(press);
}
#undef   C1
#undef   C2
#undef   C3

#ifdef EXE
#if PROTOTYPE_ALLOWED
void main(int argc, char *argv[])
#else
void main(argc, argv)
int argc;
char *argv[];
#endif
{
   double Z = 0.0;

   if (argc != 2)
   {
      printf("\n USAGE: press <depth>");
      printf("\n EXAMPLE: press 0.0\n");
   }
   else
   {
      Z = atof(argv[1]);
   }
   printf("\n pressure = %f dbar at depth = %g m\n\n", PRESS(Z), Z);
}
#endif
