fixed or variable character length 
Author Message
 fixed or variable character length

Hello all,
     I am currently using HP fortran 90 compiler and I have a quick
question that has been bugging me for a bit.

I am trying to create a file name the following way...

c80 = char_var//'.plt'

I konw that works but what the problem is that my char_var's length
changes depending on the word entered by the user, so it could be 4 or
6 or 8 or whatever, so I have to declare it as 20 character length

character*20 char_var

the problem with this is when user enters char_var that has length
less than 20, the compiler adds spaces so it kind of looks like this..

char_var='filename'

write(*,*)c80
--------
output...

filename                 .plt

how can i fix that so it looks like "filename.plt"?



Sun, 20 Dec 2009 02:28:18 GMT  
 fixed or variable character length
...

Quote:
> I am trying to create a file name the following way...

> c80 = char_var//'.plt'

...

use

c80 = TRIM(char_var)//'.plt'

instead.

Of course, you may want to check that the user didn't add the "dot"
already before you add another one...

--



Sun, 20 Dec 2009 02:34:25 GMT  
 fixed or variable character length
Use the TRIM function.  For example,

c80 = TRIM(char_var)//'.plt'



Sun, 20 Dec 2009 02:37:15 GMT  
 fixed or variable character length
Thank you dpb and mposh a lot. it saved me a lot of time from writing
a subroutine to take care of that haha


Sun, 20 Dec 2009 03:06:28 GMT  
 fixed or variable character length

Quote:

> Thank you dpb and mposh a lot. it saved me a lot of time from writing
> a subroutine to take care of that haha

If you're unfamiliar or new enough to Fortran to not know TRIM(),
looking through the manual section on intrinsic functions can be
enlightening...

--



Sun, 20 Dec 2009 03:27:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. fixed length character array passed as a real argument

2. Problem when formating a variable delimited file to fixed length

3. Variable vs. fixed-length records performance

4. Variable vs. fixed length - tuning question

5. variable-length character array.

6. maximum length of a character variable

7. Variable length character functions

8. Reading variable length character strings

9. Maximum length of character variable

10. assumed-length character variable

11. Getting true length of a variable length record - IBM Mainframe

12. Finding Variable-Length Record Length

 

 
Powered by phpBB® Forum Software