0

I have various years and months of data for numerous site locations. I have computed the average for all months for each needed year. Each Month/Year has its own its own file. Not all sites have data for a given month so no file exists in that case. What I am attempting to do is take each file Month/Year to build a new file for each site. The file structure I am attempting to build would be

Year Jan Feb
2002 xxx xxx
2003 xxx xxx
2019 xxx xxx

the naming conventions of the files are County071-O3-5001-2002.out-APR.csv.tmp.ext-avg.dat with the Bold text which would change depending on the year and the month. Since there are missing "Months" and Years" data at times I am unsure how to build table to account for missing months of data. Any suggestions how to automate this would be great given I have over 100 sites to do for a 17 year period of time.

Thanks

1
  • 2
    Build table unconditionally first, then fill with data later on as appropriate?
    – Panki
    Jul 13 at 18:31
0

without writing the code, I would use perl to write something to iterate across all of the possible months and years; plug those values into something that will be a file name and stat the file; if the file isn't found, assume that the data are zero for that month/year and move on to the next month/year.

Pseudo code:

foreach $year (2001 2002 2003 2004)
  foreach $month (Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec)
     if (-3 County071-O3-5001-$year).out-$month.csv.tmp.ext-avg.dat) /* test if it exists */
        then open it, read it, print it
     else  /* assume it's zero */
         print 0 
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.