home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  1.2 KB  |  56 lines

  1. /* Formats a floating point value in one of the following formats   */
  2. /* (i)  If mode == 0, use floating point format with "precision"    */
  3. /*      places after the decimal point.                             */
  4. /* (ii) If mode == 1, use scientific notation with one place before */
  5. /*      the decimal point and "precision" places after.             */
  6.  
  7. #include "plplot.h"
  8. #include <stdio.h>
  9. #ifdef PLSTDC
  10. #include <string.h>
  11. #else
  12. extern char *strcpy();
  13. extern char *strcat();
  14. #endif
  15.  
  16. static PLINT setpre, precis;
  17.  
  18. /* Set the number of points written after the decimal point in labels */
  19.  
  20. void plprec(setp,prec)
  21. PLINT setp, prec;
  22. {
  23.    setpre = setp;
  24.    precis = prec;
  25. }
  26.  
  27. void plform(value,mode,prec,result)
  28. PLFLT value;
  29. PLINT mode, prec;
  30. char *result;
  31. {
  32.    PLINT j, expon;
  33.    char form[10];
  34.    char temp[30];
  35.  
  36.    if(setpre)
  37.       prec = precis;
  38.  
  39.    if (mode == 0) {
  40.      sprintf(form,"%%-.%df",prec);
  41.      sprintf(temp,form,value);
  42.      strcpy(result,temp);
  43.    }
  44.    else {
  45.      sprintf(form,"%%-.%dE",prec);
  46.      sprintf(temp,form,value);
  47.      j = strpos(temp,'E') + 1;
  48.      sscanf(&temp[j],"%d",&expon);
  49.      sprintf(form,"%-d",expon);
  50.      strcpy(&temp[j-1],"x10#u");
  51.      strcat(temp,form);
  52.      strcpy(result,temp);
  53.    }
  54. }
  55.  
  56.