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 

Read binary file with Fortran

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



Joined: 07 Jun 2013
Posts: 9

PostPosted: Fri Jan 16, 2015 6:09 am    Post subject: Read binary file with Fortran Reply with quote

Hello,
I have a question about reading binary files with Fortran.

I have a file with logged GPS observations.
File and format for first several data fields are attached:

https://yadi.sk/i/R5vTA80Je2CTg
https://yadi.sk/d/cM9NiQaCe2CTN

Could anybody write several words about how to correctly open and start read this file?
Unfortunately I have never dealt with binary. I'm not a programmer.

Thanks in advance!

[/img]
Back to top
View user's profile Send private message
wahorger



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

PostPosted: Sat Jan 24, 2015 12:18 am    Post subject: Reply with quote

The links you have included do not appear to work.

The effort required to read the data is relatively small once the file formats are fully understood. Some knowledge of the machine used to create the data is extremely helpful, as well as the floating point system used (if not one of the standards).

Also, it is not uncommon for some GPS devices to store the data in an arcane system (like only seconds of arc, not DD:MM:SS.SSSS or DDMMSS.ssss or decimal degrees, etc.).

Without the internal format, it is impossible to write the code!
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sat Jan 24, 2015 11:33 am    Post subject: Reply with quote

Are you sure the GPS output is binary ?
I would expect it is text although the records may not be terminated as DOS format <cr><lf>.

I would open the file using access='TRANSPARENT' and review all characters in the file.
The following gives some idea of an approach:
Code:
      open (unit   = 11,               &
            file   = file_name,        &
            status = 'OLD',            &
            form   = 'UNFORMATTED',    &
            access = 'TRANSPARENT',    &
            iostat = iostat)
      write (*,2000) 'Opening file ',trim(file_name),' iostat = ',iostat
2000  format (a,a,a,i0)
!
!  Read all characters and lines
!
      do
!
!      Get next character from file
         lastc = ic
         read (unit=11, iostat=iostat) c
          if (iostat /= 0) exit
!
         n  = n + one      ! number of characters read
         ic = ichar(c)
         count_ic(ic) = count_ic(ic) + one
!
!      respond to this character
         select case (ic)
!
            case (10)      ! <lf>  appears in both Unix and DOS format files
               num_lf = num_lf + one             ! line control characters ; 10:LF indicates end of line
!
!            report last line
               max_len  = max (max_len, line_len)
               call Write_line (line_content, line_index, num_line, line_len, next_char, max_lines, options)
!
               if (lastc /= 13) then
                  write (*,*) '<LF>', lastc, ic
                  probably_unix = probably_unix + 1
               else
                  probably_dos  = probably_dos  + 1
               end if
!
            case (13)       ! <CR>
               num_cr = num_cr + one             ! line control characters ; 13:CR indicates new line
!
            case (9)
               num_control = num_control + one   ! control characters
               line_content(next_char) = ' '
               if (next_char < max_file_size) next_char = next_char + 1
               line_len    = line_len  + 1
!
            case (0:8,11,12,14:31)
               num_control = num_control + one   ! control characters
               line_len    = line_len  + 1
!
            case (32:126)
               num_alfa = num_alfa + one         ! normal character
               line_content(next_char) = c
               if (next_char < max_file_size) next_char = next_char + 1
               line_len = line_len  + 1
!
            case (127:256)
               num_other = num_other + one       ! other character
!
            case default
               write (*,*) 'Unrecognised character : ichar =',ic
!
         end select
      end do
Back to top
View user's profile Send private message
brucebowler
Guest





PostPosted: Mon Jan 26, 2015 7:18 pm    Post subject: Reply with quote

What GPS unit? It certainly looks binary to me, but with knowing which brand of GPS it would be impossible to decode the file. Note that MOST GPS units that spit out binary spit out the data in a proprietary format. If you can get the GPS to spit out its data in NMEA format, it'll be a human readable text that is well documented.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General 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