-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiny_extract_all.py
586 lines (488 loc) · 19.7 KB
/
shiny_extract_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#Right now, this needs to be run in the directory with the data
# and it will write output to the current working directory
import f90nml
import os
import sys
import subprocess
#sets the paths for outputs, debug, and year
from setvars import *
iargs = len(sys.argv)
if iargs < 1:
sys.exit("Usage: python shiny_extract.py which_node")
else:
which_node = sys.argv[1]
suffix = "_*.nc"
#Directory with original SCHISM nc output
schismdir = OUTPUTS
#Directory to output timeseries files
#will go to a .git-ignored directory in the current working directory
thisdir = os.getcwd()
outdir = os.path.join(thisdir,"outputs")
#Check that output directory exists
if not os.path.exists(schismdir):
sys.exit("SCHISM output directory " + schismdir + " does not exist. Exiting.")
#Create a directory for output if one doesn't exist.
#Note, existing files will be overwritten
if not os.path.exists(outdir):
os.makedirs(outdir)
#Which year
which_year = iYr0
#to make the files
basename = "GEN_"
#read nml used by schism
cgem = f90nml.read('cgem.nml')
#number of phytoplankton groups
nospA = cgem.get('nosp').get('nospa')
#number of zooplankton groups
nospZ = cgem.get('nosp').get('nospz')
if debug:
print(nospA,nospZ,"\n")
#Number of state vars, A/Qn/Qp(nospa), Z(nospz), and the rest(25)
nf = 3*nospA + nospZ + 25
if debug:
print('nf',nf,"\n")
#Initialize list of variable names
names = []
descriptions = []
units = []
#This script defines all variables
#['A','Qn','Qp','Z','NO3','NH4','PO4','DIC','O2','OM1CA','OM1NA','OM1PA','OM2CA','OM2NA','OM2PA','OM1CZ','OM1NZ','OM1PZ','OM2CZ','OM2NZ','OM2PZ','OM1R','OM2R','CDOM','Si','OM1BC','OM2BC','Alk']
#but skips extraction for variables not listed in cgem_vars.
#skip_var is True or False
skip_var = []
#!-A; Phytoplankton number density (cells/m3);
for i in range(nospA):
names.append("A" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " number density")
units.append("cells/m3")
skip_var.append(False) if 'A' in cgem_vars else skip_var.append(True)
#!-Qn: Phytoplankton Nitrogen Quota (mmol-N/cell)
for i in range(nospA):
names.append("Qn" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " nitrogen quota.")
units.append("mmol-N/cell")
skip_var.append(False) if 'Qn' in cgem_vars else skip_var.append(True)
#!-Qp: Phytoplankton Phosphorus Quota (mmol-P/cell)
for i in range(nospA):
names.append("Qp" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " phosphorus quota.")
units.append("mmol-P/cell")
skip_var.append(False) if 'Qp' in cgem_vars else skip_var.append(True)
#!-Z: Zooplankton number density (individuals/m3);
for i in range(nospZ):
names.append("Z" + str(i+1))
descriptions.append("Zooplankton group " + str(i+1) + " number density.")
units.append("organisms/m3")
skip_var.append(False) if 'Z' in cgem_vars else skip_var.append(True)
#!-NO3; Nitrate (mmol-N/m3)
names.append("NO3")
descriptions.append("Nitrate")
units.append("mmol-N/m3")
skip_var.append(False) if 'NO3' in cgem_vars else skip_var.append(True)
#!-NH4; Ammonium (mmol-N/m3)
names.append("NH4")
descriptions.append("Ammonium")
units.append("mmol-N/m3")
skip_var.append(False) if 'NH4' in cgem_vars else skip_var.append(True)
#!-PO4: Phosphate (mmol-P/m3)
names.append("PO4")
descriptions.append("Phosphate")
units.append("mmol-P/m3")
skip_var.append(False) if 'PO4' in cgem_vars else skip_var.append(True)
#!-DIC: Dissolved Inorganic Carbon (mmol-C/m3)
names.append("DIC")
descriptions.append("Dissolved Inorganic Carbon")
units.append("mmol-C/m3")
skip_var.append(False) if 'DIC' in cgem_vars else skip_var.append(True)
#!-O2: Molecular Oxygen (mmol-O2/m3)
names.append("O2")
descriptions.append("Molecular Oxygen")
units.append("mmol-O2/m3")
skip_var.append(False) if 'O2' in cgem_vars else skip_var.append(True)
#!-OM1CA: (mmol-C/m3--particulate)
#! -- Particulate Organic Matter from dead Phytoplankton
names.append("OM1CA")
descriptions.append("Carbon Particulate Organic Matter from dead Phytoplankton")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1CA' in cgem_vars else skip_var.append(True)
#!-OM1NA: (mmol-N/m3--particulate)
#! -- Particulate Organic Matter from dead Phytoplankton
names.append("OM1NA")
descriptions.append("Nitrogen Particulate Organic Matter from dead Phytoplankton")
units.append("mmol-N/m3")
skip_var.append(False) if 'OM1NA' in cgem_vars else skip_var.append(True)
#!-OM1PA: (mmol-PC/m3--particulate)
#! -- Particulate Organic Matter from dead Phytoplankton
names.append("OM1PA")
descriptions.append("Phosporus Particulate Organic Matter from dead Phytoplankton")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1PA' in cgem_vars else skip_var.append(True)
#!-OM2CA: (mmol-C/m3--dissolved)
#! -- Dissolved Organic Matter from dead Phytoplankton
names.append("OM2CA")
descriptions.append("Carbon Dissolved Organic Matter from dead Phytoplankton")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2CA' in cgem_vars else skip_var.append(True)
#!-OM2NA: (mmol-NC/m3--dissolved)
#! -- Dissolved Organic Matter from dead Phytoplankton
names.append("OM2NA")
descriptions.append("Nitrogen Dissolved Organic Matter from dead Phytoplankton")
units.append("mmol-N/m3")
skip_var.append(False) if 'OM2NA' in cgem_vars else skip_var.append(True)
#!-OM2PA: (mmol-P/m3--dissolved)
#! -- Dissolved Organic Matter from dead Phytoplankton
names.append("OM2PA")
descriptions.append("Phosphorus Dissolved Organic Matter from dead Phytoplankton")
units.append("mmol-P/m3")
skip_var.append(False) if 'OM2PA' in cgem_vars else skip_var.append(True)
#!-OM1Z:(mmol-C/m3--particulate)
#! -- Particulate Organic Matter from Zooplankton fecal pellets.
names.append("OM1CZ")
descriptions.append("Carbon Particulate Organic Matter from Zooplankton fecal pellets")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1CZ' in cgem_vars else skip_var.append(True)
#!-OM1NZ:(mmol-N/m3--particulate)
#! -- Particulate Organic Matter from Zooplankton fecal pellets.
names.append("OM1NZ")
descriptions.append("Nitrogen Particulate Organic Matter from Zooplankton fecal pellets")
units.append("mmol-N/m3")
skip_var.append(False) if 'OM1NZ' in cgem_vars else skip_var.append(True)
#!-OM1PZ:(mmol-P/m3--particulate)
#! -- Particulate Organic Matter from Zooplankton fecal pellets.
names.append("OM1PZ")
descriptions.append("Phosphorus Particulate Organic Matter from Zooplankton fecal pellets")
units.append("mmol-P/m3")
skip_var.append(False) if 'OM1PZ' in cgem_vars else skip_var.append(True)
#!-OM2CZ:(mmol-C/m3--dissolved)
#! -- Dissolved Organic Matter from Zooplankton fecal pellets.
names.append("OM2CZ")
descriptions.append("Carbon Dissolved Organic Matter from Zooplankton fecal pellets")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2CZ' in cgem_vars else skip_var.append(True)
#!-OM2NZ:(mmol-C/m3--dissolved)
#! -- Dissolved Organic Matter from Zooplankton fecal pellets.
names.append("OM2NZ")
descriptions.append("Nitrogen Dissolved Organic Matter from Zooplankton fecal pellets")
units.append("mmol-N/m3")
skip_var.append(False) if 'OM2NZ' in cgem_vars else skip_var.append(True)
#!-OM2PZ:(mmol-P/m3--dissolved)
#! -- Dissolved Organic Matter from Zooplankton fecal pellets.
names.append("OM2PZ")
descriptions.append("Phosphorus Dissolved Organic Matter from Zooplankton fecal pellets")
units.append("mmol-P/m3")
skip_var.append(False) if 'OM2PZ' in cgem_vars else skip_var.append(True)
#!-OM1R: (mmol-C/m3--particulate)
#!-- Particulate Organic Matter from river outflow
names.append("OM1R")
descriptions.append("Particulate Organic Matter from river outflow")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1R' in cgem_vars else skip_var.append(True)
#!-OM2R: (mmol-C/m3--dissolved)
#!-- Dissolved Organic Matter from river outflow
names.append("OM2R")
descriptions.append("Dissolved Organic Matter from river outflow")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2R' in cgem_vars else skip_var.append(True)
#!-CDOM: (ppb)
#!-- Colored Dissolved Organic Matter
names.append("CDOM")
descriptions.append("Colored Dissolved Organic Matter")
units.append("ppb")
skip_var.append(False) if 'CDOM' in cgem_vars else skip_var.append(True)
#!-Si: (mmol-Si/m3) -- Silica
names.append("Si")
descriptions.append("Silica")
units.append("mmol-Si/m3")
skip_var.append(False) if 'Si' in cgem_vars else skip_var.append(True)
#!-OM1BC: (mmol-C/m3--particulate)
#!-- Particulate Organic Matter in initial and boundary conditions
names.append("OM1BC")
descriptions.append("Particulate Organic Matter in initial and boundary conditions")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1BC' in cgem_vars else skip_var.append(True)
#!-OM2BC: (mmol-C/m3--dissolved)
#!-- Dissolved Organic Matter in initial and boundary conditions
names.append("OM2BC")
descriptions.append("Dissolved Organic Matter in initial and boundary conditions")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2BC' in cgem_vars else skip_var.append(True)
#!-Alk: (mmol-HCO3/m3) -- Alkalinity
names.append("Alk")
descriptions.append("Alkalinity")
units.append("mmol-N/m3")
skip_var.append(False) if 'Alk' in cgem_vars else skip_var.append(True)
#!-Tr: Tracer
names.append("Tr")
descriptions.append("Tracer")
units.append("1/m3")
skip_var.append(False) if 'Tr' in cgem_vars else skip_var.append(True)
if debug:
print(len(names),'names:',names)
print(len(descriptions),'descriptions:',descriptions)
print(len(units),'units:',units,"\n")
print(len(skip_var),'skip_var:',skip_var,"\n")
#Start a list for output file names
outputfiles = []
#For all the state variables
for i in range(nf):
if skip_var[i]:
if debug: print("skipping",names[i])
continue
base = basename + str(i+1)
inputfile = os.path.join(schismdir,base + suffix)
if debug : print('inputfile',inputfile,"\n")
outputfile = names[i] + ".nc"
outputfile = os.path.join(outdir,outputfile)
#Extract a time series to a file, which will be overwritten if it exists
command = 'ncks -O -d nSCHISM_hgrid_node,' + str(which_node) + ' ' + inputfile + ' ' + outputfile
print(command)
#Add description attribute
command = 'ncatted -O -a description,' + base + ',c,c,\"' + descriptions[i] + '\" ' + outputfile
print(command)
#Add units attribute
command = 'ncatted -O -a units,' + base + ',c,c,' + units[i] + ' ' + outputfile
print(command)
#Rename the variable
command = 'ncrename -v ' + base + ',' + names[i] + ' ' + outputfile
print(command)
sys.exit()
#Right now, this needs to be run in the directory with the data
# and it will write output to the current working directory
import f90nml
import os
import sys
import subprocess
#sets the paths for outputs, debug, and year
from setvars import *
iargs = len(sys.argv)
if iargs < 1:
sys.exit("Usage: python shiny_extract.py which_node")
else:
which_node = sys.argv[1]
suffix = "_*.nc"
#Directory with original SCHISM nc output
schismdir = OUTPUTS
#Directory to output timeseries files
#will go to a .git-ignored directory in the current working directory
thisdir = os.getcwd()
outdir = os.path.join(thisdir,"outputs")
#Check that output directory exists
if not os.path.exists(schismdir):
sys.exit("SCHISM output directory " + schismdir + " does not exist. Exiting.")
#Create a directory for output if one doesn't exist.
#Note, existing files will be overwritten
if not os.path.exists(outdir):
os.makedirs(outdir)
#Which year
which_year = iYr0
#to make the files
basename = "GEN_"
#read nml used by schism
cgem = f90nml.read('cgem.nml')
#number of phytoplankton groups
nospA = cgem.get('nosp').get('nospa')
#number of zooplankton groups
nospZ = cgem.get('nosp').get('nospz')
if debug:
print(nospA,nospZ,"\n")
#Number of state vars, A/Qn/Qp(nospa), Z(nospz), and the rest(17) + stoich(8)
nf = 3*nospA + nospZ + 17 + 8
if debug:
print('nf',nf,"\n")
#Initialize list of variable names
names = []
descriptions = []
units = []
#This script defines all variables
#['A','Qn','Qp','Z','NO3','NH4','PO4','DIC','O2','OM1A','OM2A','OM1Z','OM2Z','OM1R','OM2R','CDOM','Si','OM1BC','OM2BC','Alk','Tr','sx1A','sy1A','sx2A','sy2A','sx1Z','sy1Z','sx2Z','sy2Z']
#but skips extraction for variables not listed in cgem_vars.
#skip_var is True or False
skip_var = []
#!-A; Phytoplankton number density (cells/m3);
for i in range(nospA):
names.append("A" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " number density")
units.append("cells/m3")
skip_var.append(False) if 'A' in cgem_vars else skip_var.append(True)
#!-Qn: Phytoplankton Nitrogen Quota (mmol-N/cell)
for i in range(nospA):
names.append("Qn" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " nitrogen quota.")
units.append("mmol-N/cell")
skip_var.append(False) if 'Qn' in cgem_vars else skip_var.append(True)
#!-Qp: Phytoplankton Phosphorus Quota (mmol-P/cell)
for i in range(nospA):
names.append("Qp" + str(i+1))
descriptions.append("Phytoplankton group " + str(i+1) + " phosphorus quota.")
units.append("mmol-P/cell")
skip_var.append(False) if 'Qp' in cgem_vars else skip_var.append(True)
#!-Z: Zooplankton number density (individuals/m3);
for i in range(nospZ):
names.append("Z" + str(i+1))
descriptions.append("Zooplankton group " + str(i+1) + " number density.")
units.append("organisms/m3")
skip_var.append(False) if 'Z' in cgem_vars else skip_var.append(True)
#!-NO3; Nitrate (mmol-N/m3)
names.append("NO3")
descriptions.append("Nitrate")
units.append("mmol-N/m3")
skip_var.append(False) if 'NO3' in cgem_vars else skip_var.append(True)
#!-NH4; Ammonium (mmol-N/m3)
names.append("NH4")
descriptions.append("Ammonium")
units.append("mmol-N/m3")
skip_var.append(False) if 'NH4' in cgem_vars else skip_var.append(True)
#!-PO4: Phosphate (mmol-P/m3)
names.append("PO4")
descriptions.append("Phosphate")
units.append("mmol-P/m3")
skip_var.append(False) if 'PO4' in cgem_vars else skip_var.append(True)
#!-DIC: Dissolved Inorganic Carbon (mmol-C/m3)
names.append("DIC")
descriptions.append("Dissolved Inorganic Carbon")
units.append("mmol-C/m3")
skip_var.append(False) if 'DIC' in cgem_vars else skip_var.append(True)
#!-O2: Molecular Oxygen (mmol-O2/m3)
names.append("O2")
descriptions.append("Molecular Oxygen")
units.append("mmol-O2/m3")
skip_var.append(False) if 'O2' in cgem_vars else skip_var.append(True)
#!-OM1A: (mmol-C/m3--particulate)
#! -- Particulate Organic Matter from dead Phytoplankton
names.append("OM1A")
descriptions.append("Particulate Organic Matter from dead Phytoplankton")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1A' in cgem_vars else skip_var.append(True)
#!-OM2A: (mmol-C/m3--dissolved)
#! -- Dissolved Organic Matter from dead Phytoplankton
names.append("OM2A")
descriptions.append("Dissolved Organic Matter from dead Phytoplankton")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2A' in cgem_vars else skip_var.append(True)
#!-OM1Z:(mmol-C/m3--particulate)
#! -- Particulate Organic Matter from Zooplankton fecal pellets.
names.append("OM1Z")
descriptions.append("Particulate Organic Matter from Zooplankton fecal pellets")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1Z' in cgem_vars else skip_var.append(True)
#!-OM2Z:(mmol-C/m3--dissolved)
#! -- Dissolved Organic Matter from Zooplankton fecal pellets.
names.append("OM2Z")
descriptions.append("Dissolved Organic Matter from Zooplankton fecal pellets")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2Z' in cgem_vars else skip_var.append(True)
#!-OM1R: (mmol-C/m3--particulate)
#!-- Particulate Organic Matter from river outflow
names.append("OM1R")
descriptions.append("Particulate Organic Matter from river outflow")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1R' in cgem_vars else skip_var.append(True)
#!-OM2R: (mmol-C/m3--dissolved)
#!-- Dissolved Organic Matter from river outflow
names.append("OM2R")
descriptions.append("Dissolved Organic Matter from river outflow")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2R' in cgem_vars else skip_var.append(True)
#!-CDOM: (ppb)
#!-- Colored Dissolved Organic Matter
names.append("CDOM")
descriptions.append("Colored Dissolved Organic Matter")
units.append("ppb")
skip_var.append(False) if 'CDOM' in cgem_vars else skip_var.append(True)
#!-Si: (mmol-Si/m3) -- Silica
names.append("Si")
descriptions.append("Silica")
units.append("mmol-Si/m3")
skip_var.append(False) if 'Si' in cgem_vars else skip_var.append(True)
#!-OM1BC: (mmol-C/m3--particulate)
#!-- Particulate Organic Matter in initial and boundary conditions
names.append("OM1BC")
descriptions.append("Particulate Organic Matter in initial and boundary conditions")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM1BC' in cgem_vars else skip_var.append(True)
#!-OM2BC: (mmol-C/m3--dissolved)
#!-- Dissolved Organic Matter in initial and boundary conditions
names.append("OM2BC")
descriptions.append("Dissolved Organic Matter in initial and boundary conditions")
units.append("mmol-C/m3")
skip_var.append(False) if 'OM2BC' in cgem_vars else skip_var.append(True)
#!-Alk: (mmol-HCO3/m3) -- Alkalinity
names.append("Alk")
descriptions.append("Alkalinity")
units.append("mmol-N/m3")
skip_var.append(False) if 'Alk' in cgem_vars else skip_var.append(True)
#!Tracer
names.append("Tr")
descriptions.append("Tracer")
units.append("NONE")
skip_var.append(False) if 'Tr' in cgem_vars else skip_var.append(True)
#!sx1A
names.append("sx1A")
descriptions.append("C/P from OM1A")
units.append("C/P")
skip_var.append(False) if 'sx1A' in cgem_vars else skip_var.append(True)
#!sy1A
names.append("sy1A")
descriptions.append("N/P from OM1A")
units.append("N/P")
skip_var.append(False) if 'sy1A' in cgem_vars else skip_var.append(True)
#!sx2A
names.append("sx2A")
descriptions.append("C/P from OM2A")
units.append("C/P")
skip_var.append(False) if 'sx2A' in cgem_vars else skip_var.append(True)
#!sy2A
names.append("sy2A")
descriptions.append("N/P from OM2A")
units.append("N/P")
skip_var.append(False) if 'sy2A' in cgem_vars else skip_var.append(True)
#!sx1Z,sy1Z,sx2Z,sy2Z
names.append("sx1Z")
descriptions.append("C/P from OM1Z")
units.append("C/P")
skip_var.append(False) if 'sx1Z' in cgem_vars else skip_var.append(True)
#!sy1Z
names.append("sy1Z")
descriptions.append("N/P from OM1Z")
units.append("N/P")
skip_var.append(False) if 'sy1Z' in cgem_vars else skip_var.append(True)
#!sx2Z
names.append("sx2Z")
descriptions.append("C/P from OM2Z")
units.append("C/P")
skip_var.append(False) if 'sx2Z' in cgem_vars else skip_var.append(True)
#!sy2Z
names.append("sy2Z")
descriptions.append("N/P from OM2Z")
units.append("N/P")
skip_var.append(False) if 'sy2Z' in cgem_vars else skip_var.append(True)
if debug:
print(len(names),'names:',names)
print(len(descriptions),'descriptions:',descriptions)
print(len(units),'units:',units,"\n")
print(len(skip_var),'skip_var:',skip_var,"\n")
#Start a list for output file names
outputfiles = []
#For all the state variables
for i in range(nf):
if skip_var[i]:
if debug: print("skipping",names[i])
continue
base = basename + str(i+1)
inputfile = os.path.join(schismdir,base + suffix)
if debug : print('inputfile',inputfile,"\n")
outputfile = names[i] + "_" + str(which_node) + ".nc"
outputfile = os.path.join(outdir,outputfile)
#Extract a time series to a file, which will be overwritten if it exists
command = 'ncrcat -O -d nSCHISM_hgrid_node,' + str(which_node) + ' ' + inputfile + ' ' + outputfile
print(command)
#Add description attribute
command = 'ncatted -O -a description,' + base + ',c,c,\"' + descriptions[i] + '\" ' + outputfile
print(command)
#Add units attribute
command = 'ncatted -O -a units,' + base + ',c,c,' + units[i] + ' ' + outputfile
print(command)
#Rename the variable
command = 'ncrename -v ' + base + ',' + names[i] + ' ' + outputfile
print(command)
sys.exit()