Last active
August 29, 2015 14:08
-
-
Save Eastonium/3c9d0114c574e623e947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
#This scrip is for modifying RAW 915rwp files, in this case I was modifying the wind angle and have a bit more code to accomidate that. | |
path = '/data/home/gervais/prod/jobs/0389/collection/nim/nim915rwpM1.00' | |
os.chdir(path) | |
for filename in glob.glob(os.path.join(path, '*.cnw')): | |
print filename; | |
with open(filename,'r') as file: | |
editcolumn = 2;#Column 3 is for the DIR variable, so I defined it here to be easy to change later | |
data = file.readlines(); | |
length = int(len(data)); | |
for i in range(length): | |
explode = data[i].split(); | |
if (len(explode) == 18) and (explode[editcolumn] != "DIR"):#The data-containing lines have 18 lines, the != "DIR" is so it doesn't try to modify the header | |
if (int(explode[editcolumn]) != 999999) and (int(explode[editcolumn]) != -9999):#A test to ensure that I'm not editing fill values | |
#print explode[editcolumn]; | |
explode[editcolumn] = str(int(explode[editcolumn])+90);#Adding to the degree value | |
#print explode[editcolumn]; | |
if int(explode[editcolumn]) >= 360:#ensuring the number is between 0 and 360 | |
explode[editcolumn] = str(int(explode[editcolumn])-360); | |
#print explode[editcolumn]; | |
#print; | |
data[i] = '{:>6}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}{:>9}\n'.format(*explode[:]);#This is the format used for 915rwp data lines | |
#print data[i]; | |
with open(filename,'w') as file: | |
file.writelines(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment