replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Namelist and user defined types
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 

Namelist and user defined types

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
wahorger



Joined: 13 Oct 2014
Posts: 1238
Location: Morrison, CO, USA

PostPosted: Mon Nov 11, 2024 6:29 am    Post subject: Namelist and user defined types Reply with quote

Has anyone had an issue with placing a TYPE in a namelist? I can write it out, and all the data are there, but I get an error when I try to read it.

I'll gen up an example if no one has ever had this problem.
Back to top
View user's profile Send private message Visit poster's website
Kenneth_Smith



Joined: 18 May 2012
Posts: 730
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Nov 11, 2024 1:26 pm    Post subject: Reply with quote

Bill,

This works for me with the 32 bit compiler:

Code:
module my_mod
use ISO_FORTRAN_ENV
implicit none
type :: something
      real :: a
      real :: b
      integer :: i
end type something

type(something) :: thing1
NAMELIST /group/ thing1

contains
  integer function run()
  print*, Compiler_version()
  thing1   = something(1.0,2.0,999)
  print*, 'Thing1 before file write'
  print*, thing1%a, thing1%b, thing1%i
  ! Write thing1 to scratch
  open(unit=10,status='scratch')
  rewind 10
  write(10,group)
  ! Change thing1
  thing1   = something(10.0,20.0,-999)
  print*, 'New Thing1'
  print*, thing1%a, thing1%b, thing1%i
  ! Recover original value from scratch
  rewind 10
  read(10,group)
  print*, 'Old thing1 read from file via namelist'
  print*, thing1%a, thing1%b, thing1%i
  rewind 10
  close(10)
  run = 1
  end function run
end module my_mod

program main
use my_mod
i = run()
end program main


Code:
 FTN95 v9.03.0
 Thing1 before file write
      1.00000         2.00000             999
 New Thing1
      10.0000         20.0000            -999
 Old thing1 read from file via namelist
      1.00000         2.00000             999

Press RETURN to close window...


There does appear to be a problem with the 64 bit compiler:

Code:
FreeFormat1.F95(14) : error 1205 - amd_fill_namelist_block is not available in FTN95/64


Note I am a little behind the times using FTN95 v9.03.0.

Also see http://forums.silverfrost.com/viewtopic.php?t=4363&highlight=namelist
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Mon Nov 11, 2024 2:36 pm    Post subject: Reply with quote

Thank you for the feedback. I have noted this omission.
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1238
Location: Morrison, CO, USA

PostPosted: Mon Nov 11, 2024 2:39 pm    Post subject: Reply with quote

Ken, thanks for this.

I was not having trouble until I introduced a TYPE that also contained a character variable. Looking at the file, it appears that the numeric variables are adjacent to the character, with no intervening space or new_line. For all my character variables (arrays), there is a space between elements. Apparently, not so for TYPE.

I'll try moving the character variable to the "middle" of the numeric types and see what happens in the actual file.
Back to top
View user's profile Send private message Visit poster's website
wahorger



Joined: 13 Oct 2014
Posts: 1238
Location: Morrison, CO, USA

PostPosted: Mon Nov 11, 2024 3:12 pm    Post subject: Reply with quote

The TYPE is defined as:
Code:
   type ::rules
   sequence
   integer::   from_acct
   character*16::   trans_name
   integer::   to_acct
   end type

The variable is declared as:
Code:
type (rules):: pledges(20)

In the created file, PLEDGES, after initialization and writing the file, the file looks like this:
Code:

PLEDGES =         4025'Invoice         '           0        4031
'Invoice         '           0        4082'Invoice         '
           0        4025'Credit Memo     '           0
        4031'Credit Memo     '           0        4082
'Credit Memo     '           0           0'                '
           0           0'                '           0
           0'                '           0           0
'                '           0           0'                '
           0           0'                '           0
           0'                '           0           0
'                '           0           0'                '
           0           0'                '           0
           0'                '           0           0
'                '           0           0'                '
           0           0'                '           0

There is no intervening space between the numeric and character elements of RULES. This yields the run-time error of:
Quote:
*** Error 204, Invalid identifier in a namelist name group


Thinking there needs to be a space between the numeric value and the first quote for the character variable, I manually placed them.
Code:
PLEDGES =         4025 'Invoice         '           0        4031
'Invoice         '           0        4082 'Invoice         '
           0        4025 'Credit Memo     '           0
        4031 'Credit Memo     '           0        4082
'Credit Memo     '           0           0 '                '
           0           0 '                '           0
           0 '                '           0           0
'                '           0           0 '                '
           0           0 '                '           0
           0 '                '           0           0
'                '           0           0 '                '
           0           0 '                '           0
           0 '                '           0           0
'                '           0           0 '                '
           0           0 '                '           0

Now, the file works to READ.

Moving the variables in the TYPE simply moves the data in the file, but the space that must be between the first quote on the character data and other data is missing. If I move the character variable to the end of the type, I'll get (shorter display):
Code:
PLEDGES =         4025           0'Invoice         '        4031
           0'Invoice         '        4082           0
'Invoice         '        4025           0'Credit Memo     '
        4031           0'Credit Memo     '        4082
           0'Credit Memo     '           0           0
Back to top
View user's profile Send private message Visit poster's website
Kenneth_Smith



Joined: 18 May 2012
Posts: 730
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Tue Nov 12, 2024 12:22 am    Post subject: Reply with quote

Bill, This is a very interesting problem.

Of the three compilers I have on my lap top, only one runs and gives sensible output for the following code.

Code:
program test
use ISO_FORTRAN_ENV
type pets
  character(20) :: animal
  character(20) :: name
  integer       :: age
  character(30) :: breed
end type pets

type(pets) :: mypets(2)

NAMELIST /PETLIST/ mypets

print*, COMPILER_VERSION()
mypets(1)%animal = 'dog'
mypets(1)%name   = 'Casper'
mypets(1)%age    = 4
mypets(1)%breed  = 'Jack Russell Terrier'

mypets(2)%animal = 'dog'
mypets(2)%name   = 'Patch'
mypets(2)%age    = 12
mypets(2)%breed  = 'Parson Russell Terrier'

print*, 'Before write to NAMELIST'
print*, mypets(1)
print*, mypets(2)

open(unit=10,file='list.txt',status='unknown')
write(10,PETLIST)
close(unit=10,status='keep')

open(unit=10,file='list.txt',status='unknown')
read(10,PETLIST) 
print*, 'After read from NAMELIST'
print*, mypets(1)
print*, mypets(2)

end program test


Code:
 GCC version 11.3.0
 Before write to NAMELIST
 dog                 Casper                         4 Jack Russell Terrier
 dog                 Patch                         12 Parson Russell Terrier
 After read from NAMELIST
 dog                 Casper                         4 Jack Russell Terrier
 dog                 Patch                         12 Parson Russell Terrier

Press RETURN to close window...
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Tue Nov 12, 2024 4:13 pm    Post subject: Reply with quote

The missing code in FTN95 for x64 and NAMELIST has now been added for the next release. There was also an /64 internal compiler error for NAMELISTs and user TYPEs containing character variables.

There remains a fault in the external IO library (when reading NAMELISTs with a user TYPE and CHARACTER members). This causes the data to be read from the wrong point leading to a false runtime error "Invalid character in field".

This remaining fault is non-trivial and may take a while to fix.
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1238
Location: Morrison, CO, USA

PostPosted: Wed Nov 13, 2024 4:43 am    Post subject: Reply with quote

In the interim, I have gone with a different (more pedestrian) solution, which will work just fine.

That said, my ultimate goal would be to use NAMELIST. And I am in no hurry.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Wed Nov 13, 2024 9:50 am    Post subject: Reply with quote

The remaining fault (when reading a NAMELIST with CHARACTER variables in a user TYPE) has now been fixed for the next release of the DLLs.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support 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