trohling@uceng.UC.EDU (tom rohling) (02/24/90)
Does anybody have a real good real*8 or real*4 to character converter subroutine (maybe) that can do the following, (or something like it): 1) Send it a real number to be converted to a character variable that can be forwarded to a graphics lib call like 'fmprstr'. 2) Specify how many decimals you would like to retain. For example, if I have a real*8, I don't want to have all 16 digits in the character variable, but say only keep two. Here's the application: we've got some CFD visualization software we wrote ourselves and the routine (above) we wrote eons ago in the days of F66 is lately doing some weird voodoo on our code. I figured that there's got to be a more elegent way to accomplish it. Any donations/suggestions would be welcomed. =========================================================================== Tom Rohling "Infinity is where things happen trohling@uceng.uc.edu that don't" -Anonymous or rohling@afiris.ase.uc.edu ===========================================================================
jra@BRL.MIL ("John R. Anderson", VLD/ASB) (02/24/90)
From Tom Rohling: > Does anybody have a real good real*8 or real*4 to character converter >subroutine (maybe) that can do the following, (or something like it): > > 1) Send it a real number to be converted to a character variable > that can be forwarded to a graphics lib call like 'fmprstr'. > > 2) Specify how many decimals you would like to retain. For example, > if I have a real*8, I don't want to have all 16 digits in the > character variable, but say only keep two. How about something like: character*24 strg real*8 number integer length write( strg , 100 ) number 100 format( 'f10.2' ) c Use a function that returns the index of the last c non-blank character in the string c I'm not sure of the name of the routine length = lnblank( strg ) call fmprstr( ..., strg(1:length) , ... )
seibel@cgl.ucsf.edu (George Seibel) (02/25/90)
In article <3743@uceng.UC.EDU> trohling@uceng.UC.EDU (tom rohling) writes: > > Does anybody have a real good real*8 or real*4 to character converter >subroutine (maybe) that can do the following, (or something like it): > > 1) Send it a real number to be converted to a character variable > that can be forwarded to a graphics lib call like 'fmprstr'. Use an internal write: (it's ANSI f77, not an extension) subroutine RtoCh(rvar,cvar) real rvar character*(*) cvar write(cvar,'(f8.3)') rvar return end > 2) Specify how many decimals you would like to retain. For example, > if I have a real*8, I don't want to have all 16 digits in the > character variable, but say only keep two. For this just use a different format, like f8.2. George Seibel, UCSF seibel@cgl.ucsf.edu
blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS294 x42854") (02/26/90)
I don't know of any way to do it in FORTRAN, however, I noticed some C routines that might do what you want: ecvt,fcvt,gcvt. Check section 3 of your UNIX manuals. -- Brent L. Bates NASA-Langley Research Center M.S. 294 Hampton, Virginia 23665-5225 (804) 864-2854 E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov
blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS294 x42854") (02/27/90)
Please disregard first part of my original reply. I completely forgot about using a character variable inplace of an unit number in a FORTRAN write statement. I tried to make a simple problem more complex than it was. Got to remember KISS (keep it simple and stupid). -- Brent L. Bates NASA-Langley Research Center M.S. 294 Hampton, Virginia 23665-5225 (804) 864-2854 E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov
merritt@iris613.gsfc.nasa.gov (John H Merritt) (02/27/90)
In article <9002261609.AA20841@aero4.larc.nasa.gov> blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS294 x42854") writes: > > I don't know of any way to do it in FORTRAN, however, I noticed >some C routines that might do what you want: ecvt,fcvt,gcvt. Check >section 3 of your UNIX manuals. Use an internal write! character *80 cnum x = 1.2345 write(cnum,'(f10.3)') x and for C use sprintf. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ John H. Merritt # Yesterday I knew nothing, Applied Research Corporation # Today I know that. merritt@iris613.gsfc.nasa.gov #