For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > missing values from files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author missing values from files
Irenta

2007-07-29, 9:58 pm

Hello all!

I wrote a script that reads data from different files and put it all
together in one new file in columns. Once I open the new file, I
noticed that all data from all files is read, but it starts putting
zeros in the last rows from the last two columns from the files it
reads. (Example below). I checked the files and they both have the
whole list of numbers. Somehow the script stops reading the data from
the files. Has anyone experienced this? Is there a command that could
help me? I would really appreciate any suggestions.

04 040913. 29.8 67.1 15.0 -25.9 2.6
04 040913. 29.8 67.9 19.0 -25.2 4.5
04 040913. 29.8 70.7 22.0 -23.0 3.2
04 040913. 29.8 72.7 23.0 -21.2 3.1
04 040913. 29.8 74.7 25.0 -18.9 2.3
04 040913 29.8 71.8 28.0 -20.8 4.1
04 040913. 29.8 66.7 30.0 -23.7 6.3
04 040913. 29.8 68.4 32.0 -2.0 7.3
04 040913. 29.8 69.8 34.0 0.0 7.6
04 040913. 29.8 72.6 35.0 0.0 6.2
04 040913. 29.8 73.9 36.0 0.0 5.2
04 040913. 29.8 74.4 38.0 0.0 5.0
04 040913. 29.8 70.1 40.0 0.0 7.2
04 040913. 29.8 67.0 41.0 0.0 8.7
04 040913. 29.8 70.9 44.0 0.0 8.7
04 040913. 25.3 90.1 45.0 0.0 0.2
04 040913. 24.4 77.9 45.0 0.0 5.4
04 040913. 25.2 83.2 47.0 0.0 1.9
04 040913. 24.7 78.9 50.0 0.0 4.0
04 040913. 25.1 84.1 54.0 0.0 2.4
04 040913. 24.7 80.8 56.0 0.0 4.1
04 040913. 24.7 82.1 58.0 0.0 4.5
04 040913. 24.6 79.8 60.0 0.0 4.5
04 040913. 29.4 74.2 45.0 0.0 0.0
04 040913. 29.4 75.4 44.0 0.0 0.0
04 040913. 29.5 76.3 42.0 0.0 0.0
04 040913. 29.5 75.6 40.0 0.0 0.0
04 040913. 29.5 77.1 38.0 0.0 0.0
04 040913. 29.5 76.7 36.0 0.0 0.0
04 040913. 29.5 76.7 34.0 0.0 0.0
04 040913 29.5 76.5 32.0 0.0 0.0
04 040913. 29.5 76.2 31.0 0.0 0.0
04 040913. 29.5 76.1 30.0 0.0 0.0
04 040913. 29.5 75.8 29.0 0.0 0.0
04 040913. 29.5 75.5 28.0 0.0 0.0
04 040913. 29.5 74.4 28.0 0.0 0.0

Thanks,
Isha

Jeff Pang

2007-07-29, 9:58 pm


--- Irenta <isha.renta@gmail.com> wrote:

> Hello all!
>
> I wrote a script that reads data from different
> files and put it all
> together in one new file in columns. Once I open the
> new file, I
> noticed that all data from all files is read, but it
> starts putting
> zeros in the last rows from the last two columns
> from the files it
> reads. (Example below). I checked the files and they
> both have the
> whole list of numbers. Somehow the script stops
> reading the data from
> the files. Has anyone experienced this? Is there a
> command that could
> help me? I would really appreciate any suggestions.


What's the original data and what's the script piece?
We may need those to see it more clearly.

--
http://home.arcor.de/jeffpang/
http://home.earthlink.net/~pangj/



________________________________________
________________________________________
____
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc...monopolyherenow
Paul Lalli

2007-07-29, 9:58 pm

On Jul 29, 7:08 pm, isha.re...@gmail.com (Irenta) wrote:
> Hello all!
>
> I wrote a script that reads data from different files and put it all
> together in one new file in columns. Once I open the new file, I
> noticed that all data from all files is read, but it starts putting
> zeros in the last rows from the last two columns from the files it
> reads. (Example below). I checked the files and they both have the
> whole list of numbers. Somehow the script stops reading the data from
> the files. Has anyone experienced this? Is there a command that could
> help me? I would really appreciate any suggestions.


The chances that Perl is somehow not doing what it's supposed to are
very very small.

The chances that you did something wrong in your script are very very
large.

No one can tell you what you did wrong without you showing the code
that contains the wrong part.

Please pare your problem down to the shortest complete piece of code
that still demonstrates the failure, and then post that.

Paul Lalli

Irenta

2007-07-30, 3:59 am

On Jul 29, 7:08 pm, isha.re...@gmail.com (Irenta) wrote:
> Hello all!
>
> I wrote a script that reads data from different files and put it all
> together in one new file in columns. Once I open the new file, I
> noticed that all data from all files is read, but it starts putting
> zeros in the last rows from the last two columns from the files it
> reads. (Example below). I checked the files and they both have the
> whole list of numbers. Somehow the script stops reading the data from
> the files. Has anyone experienced this? Is there a command that could
> help me? I would really appreciate any suggestions.
>
> 04 040913. 29.8 67.1 15.0 -25.9 2.6
> 04 040913. 29.8 67.9 19.0 -25.2 4.5
> 04 040913. 29.8 70.7 22.0 -23.0 3.2
> 04 040913. 29.8 72.7 23.0 -21.2 3.1
> 04 040913. 29.8 74.7 25.0 -18.9 2.3
> 04 040913 29.8 71.8 28.0 -20.8 4.1
> 04 040913. 29.8 66.7 30.0 -23.7 6.3
> 04 040913. 29.8 68.4 32.0 -2.0 7.3
> 04 040913. 29.8 69.8 34.0 0.0 7.6
> 04 040913. 29.8 72.6 35.0 0.0 6.2
> 04 040913. 29.8 73.9 36.0 0.0 5.2
> 04 040913. 29.8 74.4 38.0 0.0 5.0
> 04 040913. 29.8 70.1 40.0 0.0 7.2
> 04 040913. 29.8 67.0 41.0 0.0 8.7
> 04 040913. 29.8 70.9 44.0 0.0 8.7
> 04 040913. 25.3 90.1 45.0 0.0 0.2
> 04 040913. 24.4 77.9 45.0 0.0 5.4
> 04 040913. 25.2 83.2 47.0 0.0 1.9
> 04 040913. 24.7 78.9 50.0 0.0 4.0
> 04 040913. 25.1 84.1 54.0 0.0 2.4
> 04 040913. 24.7 80.8 56.0 0.0 4.1
> 04 040913. 24.7 82.1 58.0 0.0 4.5
> 04 040913. 24.6 79.8 60.0 0.0 4.5
> 04 040913. 29.4 74.2 45.0 0.0 0.0
> 04 040913. 29.4 75.4 44.0 0.0 0.0
> 04 040913. 29.5 76.3 42.0 0.0 0.0
> 04 040913. 29.5 75.6 40.0 0.0 0.0
> 04 040913. 29.5 77.1 38.0 0.0 0.0
> 04 040913. 29.5 76.7 36.0 0.0 0.0
> 04 040913. 29.5 76.7 34.0 0.0 0.0
> 04 040913 29.5 76.5 32.0 0.0 0.0
> 04 040913. 29.5 76.2 31.0 0.0 0.0
> 04 040913. 29.5 76.1 30.0 0.0 0.0
> 04 040913. 29.5 75.8 29.0 0.0 0.0
> 04 040913. 29.5 75.5 28.0 0.0 0.0
> 04 040913. 29.5 74.4 28.0 0.0 0.0
>
> Thanks,
> Isha


The part of the script that output to the <ALLF> file is the
following:

select(ALLF);

@inittime=(10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
13);

for($j=0;$j<=13,$j++)
{
for($i=0;$i<3600;$i++)
{
#100
printf "04 0409$inittime[$j].";
printf (" %6.1f",$fcontentt);
$fcontentr=$lgfdlr[$i];
printf (" %6.1f",$fcontentr);
$fcontenth=$lgfdlh[$i];
printf (" %6.1f",$fcontenth);
$U10m=$U10m2[$i];
printf ("%6.1f",$U10m);
$V10m=$V10m2[$i];
printf (" %6.1f",$V10m);
}

The original data looks like this for both columns (its not the same
as avobe, but it all looks alike):

-22.8751843486893
-22.531242615231
-22.1875255329602
-22.2744658806832
-22.6195836363245
-22.9655908311773
-23.3110765545002
-23.4838263614896
-24.858017538158
-24.514857460528
-22.7110916594702
-22.0232953789172
-22.0233266610968
-21.3351587053353
-20.9047771219217
-20.9905719397528
-20.8178432089233
-20.7301997181004
-20.7273862607902
-21.5824094727958
-20.9768502847344
-20.5461012947858
-20.715219488662
-20.5393661302302
-20.2780510559188
-19.0718863341354
-18.1242289849413
-18.5508189553684
-18.8900288435228
-18.6302041364828
-18.5424609104989
-18.1095881063968

Hope this help you help me :)

Isha

Prabu Ayyappan

2007-07-30, 3:59 am

Hi Isha,


This may not help you. But some sort of debugging in your logic.

for($j=0;$j<=13,$j++)
for($i=0;$i<3600;$i++)

What is this 13 and 3600 ? is this the no of lines in the file ?.

Print and see the $#inittime $#lgfdlr $#U10m2 $#V10m2.

So that they all have the same number of lines.


Thanks,
Prabu


Irenta <isha.renta@gmail.com> wrote:
On Jul 29, 7:08 pm, isha.re...@gmail.com (Irenta) wrote:
> Hello all!
>
> I wrote a script that reads data from different files and put it all
> together in one new file in columns. Once I open the new file, I
> noticed that all data from all files is read, but it starts putting
> zeros in the last rows from the last two columns from the files it
> reads. (Example below). I checked the files and they both have the
> whole list of numbers. Somehow the script stops reading the data from
> the files. Has anyone experienced this? Is there a command that could
> help me? I would really appreciate any suggestions.
>
> 04 040913. 29.8 67.1 15.0 -25.9 2.6
> 04 040913. 29.8 67.9 19.0 -25.2 4.5
> 04 040913. 29.8 70.7 22.0 -23.0 3.2
> 04 040913. 29.8 72.7 23.0 -21.2 3.1
> 04 040913. 29.8 74.7 25.0 -18.9 2.3
> 04 040913 29.8 71.8 28.0 -20.8 4.1
> 04 040913. 29.8 66.7 30.0 -23.7 6.3
> 04 040913. 29.8 68.4 32.0 -2.0 7.3
> 04 040913. 29.8 69.8 34.0 0.0 7.6
> 04 040913. 29.8 72.6 35.0 0.0 6.2
> 04 040913. 29.8 73.9 36.0 0.0 5.2
> 04 040913. 29.8 74.4 38.0 0.0 5.0
> 04 040913. 29.8 70.1 40.0 0.0 7.2
> 04 040913. 29.8 67.0 41.0 0.0 8.7
> 04 040913. 29.8 70.9 44.0 0.0 8.7
> 04 040913. 25.3 90.1 45.0 0.0 0.2
> 04 040913. 24.4 77.9 45.0 0.0 5.4
> 04 040913. 25.2 83.2 47.0 0.0 1.9
> 04 040913. 24.7 78.9 50.0 0.0 4.0
> 04 040913. 25.1 84.1 54.0 0.0 2.4
> 04 040913. 24.7 80.8 56.0 0.0 4.1
> 04 040913. 24.7 82.1 58.0 0.0 4.5
> 04 040913. 24.6 79.8 60.0 0.0 4.5
> 04 040913. 29.4 74.2 45.0 0.0 0.0
> 04 040913. 29.4 75.4 44.0 0.0 0.0
> 04 040913. 29.5 76.3 42.0 0.0 0.0
> 04 040913. 29.5 75.6 40.0 0.0 0.0
> 04 040913. 29.5 77.1 38.0 0.0 0.0
> 04 040913. 29.5 76.7 36.0 0.0 0.0
> 04 040913. 29.5 76.7 34.0 0.0 0.0
> 04 040913 29.5 76.5 32.0 0.0 0.0
> 04 040913. 29.5 76.2 31.0 0.0 0.0
> 04 040913. 29.5 76.1 30.0 0.0 0.0
> 04 040913. 29.5 75.8 29.0 0.0 0.0
> 04 040913. 29.5 75.5 28.0 0.0 0.0
> 04 040913. 29.5 74.4 28.0 0.0 0.0
>
> Thanks,
> Isha


The part of the script that output to the file is the
following:

select(ALLF);

@inittime=(10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
13);

for($j=0;$j<=13,$j++)
{
for($i=0;$i<3600;$i++)
{
#100
printf "04 0409$inittime[$j].";
printf (" %6.1f",$fcontentt);
$fcontentr=$lgfdlr[$i];
printf (" %6.1f",$fcontentr);
$fcontenth=$lgfdlh[$i];
printf (" %6.1f",$fcontenth);
$U10m=$U10m2[$i];
printf ("%6.1f",$U10m);
$V10m=$V10m2[$i];
printf (" %6.1f",$V10m);
}

The original data looks like this for both columns (its not the same
as avobe, but it all looks alike):

-22.8751843486893
-22.531242615231
-22.1875255329602
-22.2744658806832
-22.6195836363245
-22.9655908311773
-23.3110765545002
-23.4838263614896
-24.858017538158
-24.514857460528
-22.7110916594702
-22.0232953789172
-22.0233266610968
-21.3351587053353
-20.9047771219217
-20.9905719397528
-20.8178432089233
-20.7301997181004
-20.7273862607902
-21.5824094727958
-20.9768502847344
-20.5461012947858
-20.715219488662
-20.5393661302302
-20.2780510559188
-19.0718863341354
-18.1242289849413
-18.5508189553684
-18.8900288435228
-18.6302041364828
-18.5424609104989
-18.1095881063968

Hope this help you help me :)

Isha


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/





---------------------------------
Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV.
Isha M. Renta

2007-07-30, 3:59 am

The 13 is the counter for the $inittime array (which actually have 13
numbers and not 15 as it seems) and the 3600 is the number of lines in all
the files. All the files have 3600 lines.

Isha

On 7/30/07, Prabu Ayyappan <prabu.ayyappan@yahoo.com> wrote:
>
> Hi Isha,
>
>
> This may not help you. But some sort of debugging in your logic.
>
> for($j=0;$j<=13,$j++)
> for($i=0;$i<3600;$i++)
>
> What is this 13 and 3600 ? is this the no of lines in the file ?.
>
> Print and see the $#inittime $#lgfdlr $#U10m2 $#V10m2.
>
> So that they all have the same number of lines.
>
>
> Thanks,
> Prabu
>
>
> *
> *
>
> On Jul 29, 7:08 pm,(Irenta) wrote:
>
> The part of the script that output to the file is the
> following:
>
> select(ALLF);
>
> @inittime=(10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
> 13);
>
> for($j=0;$j<=13,$j++)
> {
> for($i=0;$i<3600;$i++)
> {
> #100
> printf "04 0409$inittime[$j].";
> printf (" %6.1f",$fcontentt);
> $fcontentr=$lgfdlr[$i];
> printf (" %6.1f",$fcontentr);
> $fcontenth=$lgfdlh[$i];
> printf (" %6.1f",$fcontenth);
> $U10m=$U10m2[$i];
> printf ("%6.1f",$U10m);
> $V10m=$V10m2[$i];
> printf (" %6.1f",$V10m);
> }
>
> The original data looks like this for both columns (its not the same
> as avobe, but it all looks alike):
>
> -22.8751843486893
> -22.531242615231
> -22.1875255329602
> -22.2744658806832
> -22.6195836363245
> -22.9655908311773
> -23.3110765545002
> -23.4838263614896
> -24.858017538158
> -24.514857460528
> -22.7110916594702
> -22.0232953789172
> -22.0233266610968
> -21.3351587053353
> -20.9047771219217
> -20.9905719397528
> -20.8178432089233
> -20.7301997181004
> -20.7273862607902
> -21.5824094727958
> -20.9768502847344
> -20.5461012947858
> -20.715219488662
> -20.5393661302302
> -20.2780510559188
> -19.0718863341354
> -18.1242289849413
> -18.5508189553684
> -18.8900288435228
> -18.6302041364828
> -18.5424609104989
> -18.1095881063968
>
> Hope this help you help me :)
>
> Isha
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
> ------------------------------
> Ready for the edge of your seat? Check out tonight's top picks<http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/>on Yahoo! TV.
>
>


Chas Owens

2007-07-30, 7:00 pm

On 7/30/07, Isha M. Renta <isha.renta@gmail.com> wrote:
> The 13 is the counter for the $inittime array (which actually have 13
> numbers and not 15 as it seems) and the 3600 is the number of lines in all
> the files. All the files have 3600 lines.
>
> Isha

snip

Then you have an off-by-one error. You are saying

for($j=0;$j<=13,$j++) {

This will loop 14 times, not 13 times. This is why C-style for loops
are bad. Don't use them. If you want to loop over an array use the
iterating version of for:

for my $element (@array) {}

If you want to loop over a range you still should use the iterating
version of for:

for my $j (1 .. 13) {}
John W. Krahn

2007-07-30, 7:00 pm

Chas Owens wrote:
> On 7/30/07, Isha M. Renta <isha.renta@gmail.com> wrote:
> snip
>
> Then you have an off-by-one error. You are saying
>
> for($j=0;$j<=13,$j++) {
>
> This will loop 14 times, not 13 times. This is why C-style for loops
> are bad. Don't use them. If you want to loop over an array use the
> iterating version of for:
>
> for my $element (@array) {}
>
> If you want to loop over a range you still should use the iterating
> version of for:
>
> for my $j (1 .. 13) {}


It would probably be better to use:

for my $j ( 0 .. $#array ) {}




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Chas Owens

2007-07-30, 7:00 pm

On 7/30/07, John W. Krahn <krahnj@telus.net> wrote:
> Chas Owens wrote:
>
> It would probably be better to use:
>
> for my $j ( 0 .. $#array ) {}

snip

No, that is almost always better written as

for my $element (@array) {}

You should only use a range if you want to iterate a specific number
of times or you want to iterate over that range. Using the position
of last the last element in an array is a big clue that you really
want to iterate over an array, not a range.
Mr. Shawn H. Corey

2007-07-30, 7:00 pm

Chas Owens wrote:
> No, that is almost always better written as
>
> for my $element (@array) {}
>
> You should only use a range if you want to iterate a specific number
> of times or you want to iterate over that range. Using the position
> of last the last element in an array is a big clue that you really
> want to iterate over an array, not a range.
>


Sometimes you want the index to the array:

sub shuffle {
my $deck = shift @_;

for my $i ( 0 .. $#{ $deck } ){
my $j = int( rand( scalar( @{ $deck } )));
( $deck->[$i], $deck->[$j] ) = ( $deck->[$j], $deck->[$i] );
}
}


--
Just my 0.00000002 million dollars worth,
Shawn

"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
Irenta

2007-07-30, 7:00 pm

Thanks it worked! YAY!


On Jul 30, 12:11 pm, chas.ow...@gmail.com (Chas Owens) wrote:
> On 7/30/07, Isha M. Renta <isha.re...@gmail.com> wrote:> The 13 is the counter for the $inittime array (which actually have 13
>
>
> snip
>
> Then you have an off-by-one error. You are saying
>
> for($j=0;$j<=13,$j++) {
>
> This will loop 14 times, not 13 times. This is why C-style for loops
> are bad. Don't use them. If you want to loop over an array use the
> iterating version of for:
>
> for my $element (@array) {}
>
> If you want to loop over a range you still should use the iterating
> version of for:
>
> for my $j (1 .. 13) {}



Rob Dixon

2007-07-30, 7:00 pm

Chas Owens wrote:
> On 7/30/07, John W. Krahn <krahnj@telus.net> wrote:
> snip
>
> No, that is almost always better written as
>
> for my $element (@array) {}


That is a completely different loop. And I think John's point was that
it would be better to use $#array than to hard-code 13.

Rob
Irenta

2007-07-31, 6:59 pm

On Jul 30, 3:27 pm, rob.di...@350.com (Rob Dixon) wrote:
> Chas Owens wrote:
>
>
>
>
>
>
>
>
>
>
>
> That is a completely different loop. And I think John's point was that
> it would be better to use $#array than to hard-code 13.
>
> Rob


ok it started working and now that I run it in another computer is
doing the same thing. I added -w at the top and it is giving me the
following errors:

Use of uninitialized value in division (/) at ./filegroupfix1_1000.txt
line 133, <V10> line 61410.
Use of uninitialized value in printf at ./filegroupfix1_1000.txt line
136, <V10> line 61410.
Error opening file. at ./filegroupfix1_1000.txt line 15, <V10> line
136506.
Useless use of a constant in void context at ./filegroupfix1_1000.txt
line 149.

The script is below.***

Can anyone tell me what am I missing?
I'll appreciate your help.
Thanks,
Isha
***
----------------
#!/usr/bin/perl -w

#open the data files

@fcsttime=( '00', '06', 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72);

@inittime=('10. 00', '10. 06', '10. 12', '10. 18', '11. 00', '11. 06',
'11. 12', '11. 18', '12. 00', '12. 06', '12. 12', '12. 18', '13. 00');
#@dayntime=( '0000', '0600', '1200', '1800');

for($j=0;$j<=13;$j++)
{
open (GFDLU,'<',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].UGRD.txt") || die "Error opening file.";
open (GFDLV,'<',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].VGRD.txt") || die "Error opening file.";
open (GFDLP,'<',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].PRMSL.txt") || die "Error opening file.";
open (GFDLT,'<',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].TMPsfc.txt") || die "Error opening file.";
open (GFDLR,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].RH.txt")
|| die "Error opening file.";
open (GFDLH,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt")
|| die "Error opening file.";


#assign the data files to a list
@lgfdlp=<GFDLP>;
@lgfdlu=<GFDLU>;
@lgfdlv=<GFDLV>;
#20
@lgfdlt=<GFDLT>;
@lgfdlr=<GFDLR>;
@lgfdlh=<GFDLH>;

#removes the first line from the list
splice(@lgfdlp,0,1,());
splice(@lgfdlu,0,1,());
splice(@lgfdlv,0,1,());
splice(@lgfdlt,0,1,());
splice(@lgfdlr,0,1,());
splice(@lgfdlh,0,1,());


open (U10M,'>>',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].U10M.txt") || die "Error opening file.";
open (V10M,'>>',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].V10M.txt") || die "Error opening file.";

#creates lists
@z0=();
#40
@W35m=();
@Ust=();
$kconst=0.4;
@W10=();
@theta10=();
@U10=();
@V10=();

for($d=0;$d<3600;$d++)
{
$W35m[$d]=sqrt($lgfdlu[$d]**2+$lgfdlv[$d
]**2); #magnitude of 35m
winds

if($W35m[$d]<=12.5)
{
#35 to 10m wind reduction equation for W35 less than 12.5 m/s
$z0[$d]=1000*0.0185/9.8*(0.00053*$W35m[$d]**2+0.0286*
$W35m[$d]-0.0137)**2;
}
else
{
#35 to 10m wind reduction equation for W5 greater than 12.5 m/s
$z0[$d]=0.0739*$W35m[$d]-0.58;
#60
}
$z0[$d]=$z0[$d]*0.001; #changes z0 from mm to m
$Ust[$d]=($W35m[$d]*$kconst)/(log(35/$z0[$d])); #Calculates U* -
Powell et al. 2003 eq. (1)
$W10[$d]=($Ust[$d]/$kconst)*log(10/$z0[$d]); #Calculates 10 m wind
magnitude
$theta10[$d]=atan2($lgfdlu[$d],$lgfdlv[$
d]); #calculates 35m wind
direction. Assumed wdir35=wdir10
$U10[$d]=$W10[$d]*sin($theta10[$d]); #Calculates the U10 component
$V10[$d]=$W10[$d]*cos($theta10[$d]); #Calculates the V10 component
printf U10M "$U10[$d]\n";
printf V10M "$V10[$d]\n";
}


#creates lat/lon files
#open (LAT,'>>',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].lat.txt")
|| die "Error opening file.";
#open (LON,'>>',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].lon.txt")
|| die "Error opening file.";

#@initposx=(75.291,76.291,77.458,78.291,78.958,79.625,80.125,80.625,81.458,81.958,82.458,83.125,83.625,83.958,84.291,84.291,84.291,84.291,84.125,83.958,83.625);

#@initposy=(12.708,13.374,13.874,14.208,14.541,14.874,15.208,15.708,16.208,16.708,17.374,18.041,18.874,19.541,20.374,21.208,22.208,23.041,23.875,24.875,25.541);


#calculates the lat/long and puts is in a file

#$xbeg=$initposx[$j];
#$ybeg=$initposy[$j];

#for($m=0;$m<60;$m++)
##80
# {
# for($k=0;$k<60;$k++)
# {
# $lon=($xbeg-($k*(0.08333333)));
# $lat=($ybeg+($m*(0.08333333)));
# printf LAT "$lat\n";
# printf LON "$lon\n";
# }
# }

open (LATI,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].lat.txt")
|| die "Error opening file.";
open (LONI,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].lon.txt")
|| die "Error opening file.";
open (U10,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].U10M.txt")
|| die "Error opening file.";
open (V10,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].V10M.txt")
|| die "Error opening file.";
open (ALLF,'>>',"26Uivan09l.2004091000.gribn3.f
$fcsttime[$j].ALLF.txt") || die "Error opening file.";

#assigns lat/lon and U10 and V10 files to lists
@lgfdllat=<LATI>;
@lgfdllon=<LONI>;
@U10m2=<U10>;
@V10m2=<V10>;

#organizes the data files in one file

select(ALLF);


for($i=0;$i<3600;$i++)
{
#100
printf "04 0409$inittime[$j]00";
$fcontentlat=$lgfdllat[$i];
printf (" %7.3f",$fcontentlat);
$fcontentlon=$lgfdllon[$i];
printf ("%8.3f",$fcontentlon);
$pressv=$lgfdlp[$i]/100;
printf (" %6.1f",$pressv);
$fcontentt=$lgfdlt[$i];
printf (" %6.1f",$fcontentt);
$fcontentr=$lgfdlr[$i];
printf (" %6.1f",$fcontentr);
$fcontenth=$lgfdlh[$i];
printf (" %6.1f",$fcontenth);
$U10m=$U10m2[$i];
printf ("%6.1f",$U10m);
$V10m=$V10m2[$i];
printf (" %6.1f",$V10m);
print " GFDL\n";
}
#120
close(GFDLU,GFDLV,GFDLH,GFDLR,GFDLT,GFDL
P,LATI,LONI,U10M,V10M,ALLF)
}

John W. Krahn

2007-07-31, 6:59 pm

Irenta wrote:
>
> ok it started working and now that I run it in another computer is
> doing the same thing. I added -w at the top and it is giving me the
> following errors:


-w will give you warnings not errors.


> Use of uninitialized value in division (/) at ./filegroupfix1_1000.txt
> line 133, <V10> line 61410.
> Use of uninitialized value in printf at ./filegroupfix1_1000.txt line
> 136, <V10> line 61410.
> Error opening file. at ./filegroupfix1_1000.txt line 15, <V10> line
> 136506.
> Useless use of a constant in void context at ./filegroupfix1_1000.txt
> line 149.
>
> The script is below.***


It is hard to tell from the program where lines 15, 133, 136 and 149 are
because the email program wraps long lines.


> Can anyone tell me what am I missing?
> I'll appreciate your help.
> Thanks,
> Isha
> ***
> ----------------
> #!/usr/bin/perl -w
>
> #open the data files
>
> @fcsttime=( '00', '06', 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72);
>
> @inittime=('10. 00', '10. 06', '10. 12', '10. 18', '11. 00', '11. 06',
> '11. 12', '11. 18', '12. 00', '12. 06', '12. 12', '12. 18', '13. 00');
> #@dayntime=( '0000', '0600', '1200', '1800');
>
> for($j=0;$j<=13;$j++)
> {
> open (GFDLU,'<',"26Uivan09l.2004091000.gribn3.f
> $fcsttime[$j].UGRD.txt") || die "Error opening file.";
> open (GFDLV,'<',"26Uivan09l.2004091000.gribn3.f
> $fcsttime[$j].VGRD.txt") || die "Error opening file.";
> open (GFDLP,'<',"26Uivan09l.2004091000.gribn3.f
> $fcsttime[$j].PRMSL.txt") || die "Error opening file.";
> open (GFDLT,'<',"26Uivan09l.2004091000.gribn3.f
> $fcsttime[$j].TMPsfc.txt") || die "Error opening file.";
> open (GFDLR,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].RH.txt")
> || die "Error opening file.";
> open (GFDLH,'<',"26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt")
> || die "Error opening file.";


Your error message "Error opening file." makes it difficult to tell which file
couldn't be opened and the reason that it couldn't be opened. You should
include the file name and the $! variable in the error message.

open GFDLH, '<', "26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt" or die
"Error opening '26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt' $!";


> #assign the data files to a list
> @lgfdlp=<GFDLP>;
> @lgfdlu=<GFDLU>;
> @lgfdlv=<GFDLV>;
> #20
> @lgfdlt=<GFDLT>;
> @lgfdlr=<GFDLR>;
> @lgfdlh=<GFDLH>;


[ SNIP ]

> for($i=0;$i<3600;$i++)
> {
> #100
> printf "04 0409$inittime[$j]00";
> $fcontentlat=$lgfdllat[$i];
> printf (" %7.3f",$fcontentlat);
> $fcontentlon=$lgfdllon[$i];
> printf ("%8.3f",$fcontentlon);
> $pressv=$lgfdlp[$i]/100;


"Use of uninitialized value in division" means that the value of $lgfdlp[$i]
is undef.

> printf (" %6.1f",$pressv);
> $fcontentt=$lgfdlt[$i];
> printf (" %6.1f",$fcontentt);


"Use of uninitialized value in printf" means that the value of $fcontentt is
undef.


> $fcontentr=$lgfdlr[$i];
> printf (" %6.1f",$fcontentr);
> $fcontenth=$lgfdlh[$i];
> printf (" %6.1f",$fcontenth);
> $U10m=$U10m2[$i];
> printf ("%6.1f",$U10m);
> $V10m=$V10m2[$i];
> printf (" %6.1f",$V10m);
> print " GFDL\n";
> }
> #120
> close(GFDLU,GFDLV,GFDLH,GFDLR,GFDLT,GFDL
P,LATI,LONI,U10M,V10M,ALLF)


close() can only close *one* filehandle so you get the warning "Useless use of
a constant in void context" for all the other filehandles.


> }



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Irenta

2007-08-02, 7:00 pm

On 31 jul, 18:36, kra...@telus.net (John W. Krahn) wrote:
> Irenta wrote:
>
>
> -w will give you warnings not errors.
>
>
>
> It is hard to tell from the program where lines 15, 133, 136 and 149 are
> because the email program wraps long lines.
>
>
>
>
>
>
>
>
> Your error message "Error opening file." makes it difficult to tell which file
> couldn't be opened and the reason that it couldn't be opened. You should
> include the file name and the $! variable in the error message.
>
> open GFDLH, '<', "26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt" or die
> "Error opening '26Uivan09l.2004091000.gribn3.f$fcsttime[$j].HGT.txt' $!";
>
>
> [ SNIP ]
>
>
> "Use of uninitialized value in division" means that the value of $lgfdlp[$i]
> is undef.
>
>
> "Use of uninitialized value in printf" means that the value of $fcontentt is
> undef.
>
>
> close() can only close *one* filehandle so you get the warning "Useless use of
> a constant in void context" for all the other filehandles.
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall


those "unitialized values" are assigned to the handle of the files
before the loop... does't that initialize them?

Isha

Chas Owens

2007-08-02, 7:00 pm

On 8/1/07, Irenta <isha.renta@gmail.com> wrote:
snip

snip
close(GFDLU,GFDLV,GFDLH,GFDLR,GFDLT,GFDL
P,LATI,LONI,U10M,V10M,ALLF)[color=darkre
d]
snip[color=darkred]
> those "unitialized values" are assigned to the handle of the files
> before the loop... does't that initialize them?

snip

Yes, they are initialized, but they are triggering the "Useless use
of a constant in void context" warning because close only takes one
file handle; the others are useless. The "Use of uninitialized value"
warning is coming from your calls to printf. Some of your variables
have undefined values and Perl is warning you in case that isn't what
you wanted (it usually isn't).
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com