On Jul 30, 3:27 pm, [EMAIL PROTECTED] (Rob Dixon) wrote:
> Chas Owens wrote:
> > On 7/30/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
> >> Chas Owens wrote:
> >>> On 7/30/07, Isha M. Renta <[EMAIL PROTECTED]> 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) {}
> >> 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) {}
>
> 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');
[EMAIL PROTECTED]( '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.";

[EMAIL 
PROTECTED](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);

[EMAIL 
PROTECTED](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,GFDLP,LATI,LONI,U10M,V10M,ALLF)
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to