Don't forget that Excel comma separated files require a full stop decimal point and a comma between variables, if your Windows International settings specify the British/american method. For continental Europe, the decimal point is a comma and the comma separator becomes a semi-colon.
FTN95 always uses a full stop as the decimal, unless someone wants to tell me otherwise. The alternate method is to use a tab delimited text file, but you will probably still have to make the conversion for the decimal point.
Typically, you could use the following for tab delimited:
character*1 separator,from_decimal_point, to_decimal_point
character*20 format_string
character*2000 big_output_buffer
separator = char(9)
from_decimal_point = '.'
to_decimal_point = ','
big_output_buffer = ' '
format_string='(f12.3,a)'
write(big_output_buffer,format_string)(frct(i),separator,i=1,siz)
ilen=leng(big_output_buffer)
do i=1,ilen
if(big_output_buffer(i:i) .eq. from_decimal_point )then
big_output_buffer(i:i) = to_decimal_point
endif
enddo
write(1000)trim(big_output_buffer)
1000 format(a)
end
If you wish to make this a bit more general, then a translation subroutine would do the trick, i.e.
subroutine translate_specific_characters(string,from,to)
character*(*) string,from,to
! 'from' and 'to' must be the same length and have a one to one
! translation relationship
if(from .eq. to)return
ilen = leng(string)
do i=1,ilen
iposition = index(from,string(i:i))
if(iposition .gt. 0)then
string(i:i) = to(iposition:iposition)
endif
enddo
end
and the main program would become:
character*1 separator
character*2 translate_from, translate_to
character*20 format_string
character*2000 big_output_buffer
translate_from = '.,'
translate_to = ',;'
big_output_buffer = ' '
format_string='(f12.3,a)'
write(big_output_buffer,format_string)(frct(i),separator,i=1,siz)
call translate_specific_characters(big_output_buffer,translate_from,translate_to)
write(1000)trim(big_output_buffer)
1000 format(a)
end
The above program starts with the default British/american setup and translates to the European style. The translate_from and translate_to strings could be set at program start-up. If they are identical, then no translation is carried out. Note this suggestion leaves an extra separator on the right hand end of the string, which will probably not matter, but is easily removed before translation with:
ilen=leng(big_output_buffer)
big_output_buffer(ilen:) = ' '
Note if you are mixing text and numerics, then in a CSV file, if the text includes the separator, then the string is surrounded in quotes, and a slightly more complicated translation routine is required that determines whether you are within quotes or not, e.g. the translation routine becomes:
subroutine translate_specific_characters(string,from,to)
character*(*) string,from,to
! 'from' and 'to' must be the same length and have a one to one
! translation relationship
if(from .eq. to)return
ilen = leng(string)
in_quote = 0
do i=1,ilen
!toggle quotation status
if(string(i:i) .eq. ''')in_quote = 1 - in_quote
if(in_quote .eq. 0)then
iposition = index(from,string(i:i))
if(iposition .gt. 0)then
string(i:i) = to(iposition:iposition)
endif
endif
enddo
end
Regards
Ian