#!/usr/bin/perl # This script is meant to first read in a list of station # names and codes that have been pulled out of the WMO # precipitation inventory file: # # ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/v2/v2.prcp.inv # # and then use this list to pull the actual monthly rainfall # data from the file: # # ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/v2/v2.prcp # $StationListFile = "junkdat/PrcpInvEriRegion.txt"; open(STNLIST,"<$StationListFile"); while(){ chop; # Here I want to pull out the station name and # first three letters of the country name. $StnName = substr $_,12,19; # We pull out the fixed length station name $StnName =~ s/\s*$//; # We delete trailing spaces $StnName =~ s/\s/\_/g; # Internal spaces replaced w/underscore $CntryCode = substr $_,32,3; # Take country code as 1st 3 letters of name $StnCode = substr $_,0,11; # Get the station code $FileName=$CntryCode."-".$StnName."\.prcp"; # Set the data file name print $FileName,"\n"; # Print file name so I can watch processing # grep datafile for station code open(PRCPDAT,"grep \^$StnCode junkdat/v2.prcp |"); open(DATOUT,">prcp/$FileName"); # Open the output file # Print the station data header print DATOUT "STN CODE STATION NAME COUNTRY LAT LON ELEV(meters)\n"; # Print station info print DATOUT $_,"\n"; # Put in a note describing data print DATOUT "Note: This file contains monthly rain in tenths of a millimeter.\n"; # Put in note acknowledging source... print DATOUT "Source: ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/v2/v2.prcp\n"; # Print column headers for data print DATOUT "STATIONCODE YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC\n"; # Now read and print the data to the data file while(){ print DATOUT; } close(PRCPDAT); close(DATOUT); } close(STNLIST); exit 0;