glen herrmannsfeldt <
g...@ugcs.caltech.edu> wrote:
> Jim <jim...@jmail.invalid> wrote:
>
> (snip, I wrote)
>
>>> Not really, but you can create an array of CHARACTER, and initialize
>>> it one constant per line, with continuations:
>
>>> character*80 :: str(4) = [ character(len=80) :: &
>>> 'this is one', &
>>> 'this is another', &
>>> 'this is the third one', &
>>> 'this is the last one' ]
>>> do i=1,size(str)
>>> print '(A)',str(i)
>>> enddo
>>> end
>
> (snip)
>
>> [...]
>
>> Anyway, is there a way to let a program "eat" a text file
>> at compile time as an input file and automatically use it
>> during run time?
>
> The file would have to have quotes around each line, and
> followed by ,&. That is, it would have to look like the lines
> above. You could then:
>
> character*80 :: str(4) = [ character(len=80) :: &
> #include "file.txt"
> "" ]
Ok this works!
But without "#". I've edited it as follow:
character(100) :: str(19) = [ character(len=100) ::&
include "config.txt"
]
Now we have:
1- a config text file template called config.txt.
formatted as needed:
==============
'line', &
'otherline', &
'lastline'
==========
2- we can use this at compile time and then we can
delete it when we have an executable created.
3- so we don't need that text file at run time.
No need to give it to user.
User is able to run executable without any other
file...
> It is easy in many languages to write a program to add the leading
> quote and trailing quote, comma, and (for Fortran) &.
>
> { print "\"" $0 "\",&"; }
Ok, that is the "weak point":
developer (me) as to edit config template file
in that "strange" unconfortable way using "apostrophe"
and apostrophe plus comma and "&".
As you truly explained there are automatic ways to do it:
developer can write a "human-friendly" config file, and then
edit it with a program like awk, sed or others...
So developer could write his config file template.
Then automatically edit it with sed or awk and
finally obtain a fortran-friendly config file to
include in source at compile time.
But... Just as a matter of curiosity...
I've written a few lines of fortran code to automatically
edit human-friendly text file so as it can be included in
a source code with include statement.
Look at following lines:
==================================
program hr2fortfriend
character(100) :: line, prevline
integer :: eof
open(101,file='hr.conf')
open(102,file='fortfriend.conf')
prevline = 'EMPTY'
do
read(101,'(a)',iostat=eof) line
if (eof/=0) then
write(102,*) "'",prevline,"'"
exit
else
if (prevline/='EMPTY') write(102,*) "'",prevline,"', &"
prevline = line
endif
enddo
close(101)
close(102)
end program
===========
Ok, it's quite bugged, anyway.. it seems work fine.
It take hr.conf lines and put them between apostrophes etc.
creating fortfiend.conf text file taht could be included in
a fortran source with include...
But I can't see any way to use this code as part of an other
source called "main".
I'd like to obtain this:
1- manual edit of text file (a config template) in a plain way:
line1
line2
etcc
2- compile main program and obtain
2.a- config template is translated in to fortran compatible
lines (by adding ' ', & etc.) and written in a new
temporary file.
2.b- above created temp file is included in main program.
2.c- an executable that no needs any other file to work
properly
The matter is that include statment workis at compile time
but hr2fortfriend is related to run time...
So I think there's no way to do '2.a' and '2.b' at the same
time.
Peraphs it's a preprocess related question...
I don't know a solution other than separete compile time
to template editing.
If you have any other ideas...