replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Bug report
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug report

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Wed Apr 18, 2012 11:47 am    Post subject: Bug report Reply with quote

Just a small bug:

Code:
      program test

      logical*2      L
      character*3    ext
      character*120  ifile

      ext   = 'jpg'
      ifile = 'test_image.tiff'
      call set_suffix@(ifile,ext,L)
      print*,ifile

      end


The suffix is not 'jpg' but 'jpgf' - so the old suffix should be deleted completely before adding the new one.

Regards - Wilfried
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Wed Apr 18, 2012 9:00 pm    Post subject: Reply with quote

I have now fixed this bug for the next release.
Back to top
View user's profile Send private message AIM Address
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Thu May 03, 2012 10:06 am    Post subject: Reply with quote

Sorry, here's the next:

Code:
      program test

      character*10 string

      string = '  abcdefgh'
      call upcase@(adjustl(string))
      print*,string

      end


upcase@ didn't work together with adjustl.

Regards - Wilfried
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Thu May 03, 2012 10:27 am    Post subject: Reply with quote

My understanding is that this behaves correctly.

adjustl is a function returning a character string. It does not change the argument. Hence the upper case is applied to the returned value which is then discarded. The character variable called string is left unchanged.
Back to top
View user's profile Send private message AIM Address
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Thu May 03, 2012 11:01 am    Post subject: Reply with quote

Hmmm... My understanding was - according to the bracket rules - that first the string is adjusted to the left:

'__abcdefgh' --> 'abcdefgh__'

after that, this result is transformed to 'ABCDEFGH__'.

Thanks and regards - Wilfried
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Thu May 03, 2012 5:38 pm    Post subject: Reply with quote

Paul is correct, upcase@ is applied to a temporary variable which is discarded. You need to write it like this

Code:

    program test

      character*10 string

      string = '  abcdefgh'
      string = adjustl(string)
      call upcase@(string)
      print*,string

      end

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Fri May 04, 2012 7:49 am    Post subject: Reply with quote

OK, I see. But it is not nice, and I don't understand why in this case it is impossible to "work with brackets" like here:

Code:
      program test

      character*10 string,string2
      character*20 string3

      string  = '  abcdefgh'
      string2 = '    ABCD  '
      string3 = trim(adjustl(string2))//adjustl(string)
      print*,string3

      end


In this example, the term trim(adjustl(string2)) is handled in the usual way "from inner to outer brackets": First, string2 is adjusted to the left, then the result is trimmed. That is the way I was expecting when I use upcase@(adjustl(string)).

Regards - Wilfried
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Fri May 04, 2012 8:06 am    Post subject: Reply with quote

Here's the result, I wrote my own function doing that what i want:

Code:
      program test

      character*20  string
      character*120 ucase

      string  = '            abcdefgh'
      string  =  ucase(adjustl(string))
      print*,string
      end

      character function ucase(string)

      integer*4      i,ic
      character*120  string

      do i = 1,len_trim(string)
        ic = ichar(string(i:i))
        if (ic >= 97 .and. ic < 122) string(i:i) = char(ic-32)
        ucase(i:i) = string(i:i)
      end do
      end


Regards - Wilfried
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri May 04, 2012 4:02 pm    Post subject: Reply with quote

The reason TRIM(ADJUSTL(string)) works is because ADJUSTL and TRIM are functions. This sort of nesting functions as arguments inside another works because TRIM acts on the function result from ADJUSTL.

But UPCASE@ is a subroutine which expects a variable argument, so it can change it. If you write the following, the argument is not a variable.

CALL UPCASE@(ADJUSTL(STRING))

The solution, as you have discovered is to write your own function. But you didn't need to write your own case conversion, you could have just produced a "function wrapper" for the UPCASE@ subroutine, e.g.

Code:

FUNCTION UPCASE(STRING)
   CHARACTER(LEN=*), INTENT(IN) :: STRING
   CHARACTER(LEN=LEN(STRING)) :: UPCASE
   UPCASE = STRING             ! Copy the string
   CALL UPCASE@(UPCASE)   ! Change it to uppercase
END FUNCTION


Note that this version automatically returns a string of the same length as STRING, whereas, your function always returns a string of 120 characters

Once you have this, you can write, for example,

Code:

S = "     hello" !< contains leading spaces
print *, UPCASE(ADJUSTL(S)) !< prints "HELLO     "
print *, ADJUSTL(UPCASE(S)) !< prints "HELLO     "
print *, TRIM(ADJUSTL(UPCASE(S))) !< prints "HELLO"


Hope this helps, it might be useful to wrap other @ subroutines as well.

Regards
David.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Tue May 08, 2012 10:13 am    Post subject: Reply with quote

David, just now I see your advise. Thanks a lot! It is a good idea to "wrap" subroutines in the way you wrote.

Regards - Wilfried
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group