Silverfrost Forums

Welcome to our forums

Reading and writing compass azimuth.

3 Nov 2011 11:27 #9183

How would you structure a READ and WRITE statement for compass azimuths in the following format:

N45.00E or N45.00W S45.00E or S45.00W

It has to be generic since the azimuth will be in 1 or 4 quadrants. N or S is always first and E or W follows the degrees of rotation. Degrees of rotation is 0 - 90 degrees.

Thanks,

😃

4 Nov 2011 8:04 #9185

May be like this?

      WINAPP
      OPTIONS(INTL)

      PROGRAM TEST

      IMPLICIT NONE

      real*8         alfa
      character*1    A,B
      character*7    string

c     read data. alfa is converted to 0 ... 360 degrees

      open(10,err=200,file='input.dat',status='old')
      read(10,'(A)',err=200,end=200)string
      call upcase@(string)
      A = string(1:1)
      B = string(7:7)
      read(string(2:6),*,err=200)alfa
      if (A .eq. 'S' .and. B .eq. 'E') then
        alfa = alfa+90.D0
      else if (A .eq. 'S' .and. B .eq. 'W') then
        alfa = alfa+180.D0
      else if (A .eq. 'N' .and. B .eq. 'W') then
        alfa = alfa+270.D0
      end if
      print*,alfa
200   close(10)

c     write data. example:

      alfa = 127.D0

      open(20,err=400,file='output.dat',status='unknown')
      if (alfa .gt. 0.D0 .and. alfa .le. 90.D0) then
        A = 'N'
        B = 'E'
      else if (alfa .gt. 90.D0 .and. alfa .le. 180.D0) then
        A = 'S'
        B = 'E'
        alfa = alfa-90.D0
      else if (alfa .gt. 180.D0 .and. alfa .le. 270.D0) then
        A = 'S'
        B = 'W'
        alfa = alfa-180.D0
      else
        A = 'N'
        B = 'W'
        alfa = alfa-270.D0
      end if
      string(1:1) = A
      string(7:7) = B
      write(string(2:6),'(F5.2)',err=400)alfa
      write(20,'(A)',err=400)string
      print*,string
400   close(20)

      end

Regards - Wilfried

Please login to reply.