Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REPLACE TEXT

Status
Not open for further replies.

lazic67

Technical User
Feb 23, 2011
10
RS
Hello everyone,

I have one problem that I do not know how to solve.
I have a file called eph.txt, plain ASCII file.
How do I change my name, in fact I would like to translate the text.
For example instead of 'filename' in the same spot to put the 'Ime fajla'
data behind ':' To stay where they are.

I'm using CompaqVisualFortran.


Thanks for your help

P.S. below is a look eph.txt size

filename: Baji029H.11o
file format: RINEX
file size (bytes): 4524915
start date & time: 2011-01-29 06:00:00.000
final date & time: 2011-01-29 06:59:59.000
sample interval: 1.0000
possible missing epochs: 0
4-char station code: Baji
station name: Baji
station ID number:
antenna ID number:
antenna type: TRM41249.00 TZGD
antenna latitude (deg): 43.968457
antenna longitude (deg): 19.570591
antenna elevation (m): 306.728
antenna height (m): 0.0000
receiver ID number: 0220368043
receiver type: TRIMBLE 5700
receiver firmware: Nav 2.24 / Boot 2
RINEX version: 2.10
RINEX translator: GPSNet 2.70 3641
trans date & time: 2011-01-29 06:59:00.000
 
It is only a problem if you are trying to read and write the same file. It is a lot easier with 2 files. The basic algorithm is

1) Copy the file to another file (say eph.old)
2) Open eph.txt for writing, eph.old for reading
3) Read a line from eph.old
4) Find out where the colon is
5) Extract text before the colon - compare and get translation. You can do this with a lookup table
6) Write translation, colon and text after the colon to eph.txt
7) Repeat from 3 until end of file.
8) Close both files

Which part are you having problems with?
 
The problem is in step 4 and 5. I can not write code
for finding the column, Comparison and translation.

Thanks for your help
 
You can have some very simple minded translations: phrase for phrase substitution. You have to make sure the number of space in between words is exactly the same
Code:
!  --------------------------------------------------
!  Silverfrost FTN95 for Microsoft Visual Studio
!  Free Format FTN95 Source File
!  --------------------------------------------------
subroutine xlat (engtext, maltext)
   character*(*), intent(in):: engtext
   character*(*), intent(out):: maltext
   integer, parameter:: english = 1, malay = 2, max = 4
   character*16:: xlatphrase(2,max) &
      / 'open door', 'buka pintu', &
        'close door', 'tutop pintu', &
        'eat', 'makan', &
        'get married', 'bersanding' /
   character*16:: eng
   
   ! so we don't need to trim
   eng = engtext
   maltext = '??' // engtext
   do ii = 1, max
      if (eng .eq. xlatphrase(english,ii)) then
          maltext = xlatphrase(malay,ii)
          return
      endif
   enddo
end subroutine


program main
   character*16 malay
   
   call xlat ('eat', malay)
   print *, malay
   call xlat ('close door', malay)
   print *, malay
   ! this will fail - no such word
   call xlat ('play', malay)
   print *, malay
   ! this will fail - too many spaces
   call xlat ('close  door', malay)
   print *, malay
   stop
end
 
CIAO

I took silverfrost and tried to compile the code.

But we report a 572 error - String found where an operator was expected in the line of code 'get married', 'bersanding' /

Do you know what the problem was due to first use
silverfrost.

Greeting
 
Trying to compile it with gfortran I got these errors
Code:
$ gfortran translation.f95 -o translation
translation.f95:12.35:

   character*16:: xlatphrase(2,max) &
                                  1
Error: Syntax error in data declaration at (1)
translation.f95:23.10:

      if (eng .eq. xlatphrase(english,ii)) then
         1
Error: Operands of comparison operator '.eq.' at (1) are CHARACTER(1)/REAL(4)
translation.f95:24.20:

          maltext = xlatphrase(malay,ii)
                   1
Error: Can't convert REAL(4) to CHARACTER(1) at (1)
I changed the declaration of xlatphrase to
Code:
   character*16:: xlatphrase(2,max) = reshape( &
     (/ 'open door', 'buka pintu', &
        'close door', 'tutop pintu', &
        'eat', 'makan', &
        'get married', 'bersanding' /), (/2, max/))
Now it compiles with gfortran and runs
Code:
$ translation
 makan           
 tutop pintu     
 ??play          
 ??close  door
 
That's strange - I wrote it using silverfrost. Anyway mikrom has come to the rescue.
 
Btw, trying to compile the same source with g95 I got strange error:
Code:
$ g95 translation.f95 -o translation
In file translation.f95:13

     (/ 'open door', 'buka pintu', &
                     1
Error: Element in character array constructor at (1) has length 10 instead of 9
when I changed the array element to
Code:
     (/ 'open door', 'bukapintu', &
I got next error:
Code:
$ g95 translation.f95 -o translation
In file translation.f95:14

        'close door', 'tutop pintu', &
        1
Error: Element in character array constructor at (1) has length 10 instead of 9

Then I padded all array elements to the same length (i.e max length = 11)
Code:
   character*16:: xlatphrase(2,max) = reshape( &
     (/ 'open door  ', 'buka pintu ', &
        'close door ', 'tutop pintu', &
        'eat        ', 'makan      ', &
        'get married', 'bersanding ' /), (/2, max/))
...and the program compiled fine with g95.

I thought that it was bug of g95 compiler...

But, now I googled and found that:
"The F95 standard says that all of the elements in the array constructor have to be of the same length"
 
I get that when I use reshape on silverfrost.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top