Thread Subject: Need help to read file using fscanf or textscan

Subject: Need help to read file using fscanf or textscan

From: Brett

Date: 19 Apr, 2008 18:35:03

Message: 1 of 2

Hi all,

Really need an urgent help to read some mooring data. I
tried fscanf and textscan all didnt work. I want to pass
this module and help will be appreciated! Its about a
thousand column which starts like this:


 Location: 0N 23W 0000 14 Dec 2001 to 2300 31 Dec 2001

     432 times, 27 depths, 1 blocks, Gen. Date Jan 21 2008

 Units: Depth (Meters), ADCP Velocity (cm/s), -999.90 = missing

 Oceanographic Convention: (1,1) is NE at sqrt(2) cm/s

 Time: 0000 14 Dec 2001 to 2300 31 Dec 2001

 Time Index 1 to 432, 432 lines, 27 depths

 Depth Index: 1 2 3 4 5 6 7 8

                  9 10 11 12 13 14 15 16

                 17 18 19 20 21 22 23 24

                 25 26 27

 Depths: 5 10 15 20 25 30 35 40

                 45 50 55 60 65 70 75 80

                 85 90 95 100 105 110 115 120

                125 130 135

 YYYYMMDD HHMM ZONAL MERID ZONAL MERID ZONAL MERID ZONAL MERID

 20011214 0000-999.9-999.9-999.9-999.9 5.8 0.2 9.1 -2.9

                11.5 -5.2 13.2 -9.9 13.6 -14.6 10.9 -21.3

                10.0 -25.9 19.4 -21.3 33.3 -10.6 50.9 0.3

                68.3 5.8 78.8 5.4 81.4 5.9 76.7 8.5

                71.0 10.1 68.2 12.1 68.2 13.1 69.1 14.2

                68.8 12.8 65.5 10.8 59.7 9.8 51.5 10.1

                44.7 10.6 41.1 8.7-999.9-999.9

 20011214 0100-999.9-999.9-999.9-999.9 5.6 -3.1 8.8 -5.7

                11.6 -8.3 13.5 -11.1 15.2 -15.3 13.2 -21.3

                 9.1 -29.3 15.0 -29.5 27.7 -19.0 42.0 -7.8

                60.9 2.1 78.0 5.5 83.7 4.1 79.2 7.3

                72.0 8.8 68.5 11.6 69.4 13.6 70.8 13.9

                69.6 11.2 64.3 9.2 56.7 9.0 48.3 10.6

                43.9 10.0 41.4 8.1-999.9-999.9
 20011214 0200-999.9-999.9-999.9-999.9 12.8 -4.7 13.7 -5.5

                16.1 -7.7 17.6 -11.1 18.8 -15.6 17.1 -21.2

                13.5 -27.4 20.3 -25.4 34.6 -16.2 50.0 -5.9

                67.3 2.0 82.8 2.4 88.9 -0.8 85.7 2.6

                76.1 6.1 69.6 9.2 68.5 12.0 70.3 12.6

                68.7 11.7 64.1 9.9 57.2 9.8 48.2 11.0

                41.8 11.4 39.8 10.3-999.9-999.9

Thanks!!

Subject: Need help to read file using fscanf or textscan

From: Abel Brown

Date: 19 Apr, 2008 19:24:01

Message: 2 of 2

"Brett " <yellownoble400@yahoo.com> wrote in message
<fude0n$fhr$1@fred.mathworks.com>...
> Hi all,
>
> Really need an urgent help to read some mooring data. I
> tried fscanf and textscan all didnt work. I want to pass
> this module and help will be appreciated! Its about a
> thousand column which starts like this:
>
>
> Location: 0N 23W 0000 14 Dec 2001 to 2300 31 Dec 2001
>
> 432 times, 27 depths, 1 blocks, Gen. Date Jan 21 2008
>
> Units: Depth (Meters), ADCP Velocity (cm/s), -999.90 =
missing
>
> Oceanographic Convention: (1,1) is NE at sqrt(2) cm/s
>
> Time: 0000 14 Dec 2001 to 2300 31 Dec 2001
>
> Time Index 1 to 432, 432 lines, 27 depths
>
> Depth Index: 1 2 3 4 5 6 7 8
>
> 9 10 11 12 13 14 15 16
>
> 17 18 19 20 21 22 23 24
>
> 25 26 27
>
> Depths: 5 10 15 20 25 30 35 40
>
> 45 50 55 60 65 70 75 80
>
> 85 90 95 100 105 110 115 120
>
> 125 130 135
>
> YYYYMMDD HHMM ZONAL MERID ZONAL MERID ZONAL MERID ZONAL MERID
>
> 20011214 0000-999.9-999.9-999.9-999.9 5.8 0.2 9.1 -2.9
>
> 11.5 -5.2 13.2 -9.9 13.6 -14.6 10.9 -21.3
>
> 10.0 -25.9 19.4 -21.3 33.3 -10.6 50.9 0.3
>
> 68.3 5.8 78.8 5.4 81.4 5.9 76.7 8.5
>
> 71.0 10.1 68.2 12.1 68.2 13.1 69.1 14.2
>
> 68.8 12.8 65.5 10.8 59.7 9.8 51.5 10.1
>
> 44.7 10.6 41.1 8.7-999.9-999.9
>
> 20011214 0100-999.9-999.9-999.9-999.9 5.6 -3.1 8.8 -5.7
>
> 11.6 -8.3 13.5 -11.1 15.2 -15.3 13.2 -21.3
>
> 9.1 -29.3 15.0 -29.5 27.7 -19.0 42.0 -7.8
>
> 60.9 2.1 78.0 5.5 83.7 4.1 79.2 7.3
>
> 72.0 8.8 68.5 11.6 69.4 13.6 70.8 13.9
>
> 69.6 11.2 64.3 9.2 56.7 9.0 48.3 10.6
>
> 43.9 10.0 41.4 8.1-999.9-999.9
> 20011214 0200-999.9-999.9-999.9-999.9 12.8 -4.7 13.7 -5.5
>
> 16.1 -7.7 17.6 -11.1 18.8 -15.6 17.1 -21.2
>
> 13.5 -27.4 20.3 -25.4 34.6 -16.2 50.0 -5.9
>
> 67.3 2.0 82.8 2.4 88.9 -0.8 85.7 2.6
>
> 76.1 6.1 69.6 9.2 68.5 12.0 70.3 12.6
>
> 68.7 11.7 64.1 9.9 57.2 9.8 48.2 11.0
>
> 41.8 11.4 39.8 10.3-999.9-999.9
>
> Thanks!!

the only thing you need to do is open the file

fid = fopen('your_file.dat');

while(1)

  line = fgetl(fid);
  if ~isempty(line), break, end;
 
  %parse the line by white spaces
  parsed_line = textscan(line,'%s');
  
  % now do what you want with each line
  % typecast with str2num etc ...
  % or read in data lines with textscan(line,'%f')
  % which will save time ...


end

 file is not very hard. just spend some time playing around
and use some good'ol trial and error. Don't try to parse
the whole file while you're writing the code. just take
like the first 50-200 lines of the file and work with that.
 once you're confident that you can parse at least one
record properly then try your code on the whole file.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
fscanf Brett 19 Apr, 2008 14:35:06
textscan Brett 19 Apr, 2008 14:35:06
mooring Brett 19 Apr, 2008 14:35:06
rssFeed for this Thread

Contact us at files@mathworks.com