-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create_Final_Run_Files.r
439 lines (423 loc) · 15.1 KB
/
Create_Final_Run_Files.r
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
rm(list=ls())
library(MASS)
#library(fields)
#library(maps)
#library(hydroGOF)
#library(plotrix)
#library(rworldmap)
#library(RColorBrewer)
#library(humidity)
esmap.dir = "/scratch/summit/roab9675/SMAP/Gridded_ESMAP/"
smap.points.file = "/projects/roab9675/SMAP/Point_Check/Good_Points"
smap.points = read.table(smap.points.file)
smap.points = as.matrix(smap.points)
smap.lat = smap.points[,1]
smap.lon = smap.points[,2]
npoints = length(smap.lon)
bad.file = "/projects/roab9675/SMAP/Point_Check/TMP_BAD_Points2"
if(file.exists(bad.file)==TRUE) file.remove(bad.file)
good.file = "/projects/roab9675/SMAP/Point_Check/TMP_GOOD_Points2"
if(file.exists(good.file)==TRUE) file.remove(good.file)
#npoints
for(p in 1:npoints){
old.dir = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/Hydrus_SpinUp/",sep='')
new.dir = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/Hydrus_FINAL/",sep='')
if(dir.exists(new.dir)==TRUE) unlink(new.dir,recursive=TRUE)
dir.create(new.dir,recursive=TRUE)
print(new.dir)
#Open NOD_INF and get new SM
nod.file = paste(old.dir,"NOD_INF.OUT", sep='')
opt1 = grep('Time: 35064',readLines(nod.file))
opt2 = grep('Time: 8802.7600',readLines(nod.file))
opt3 = grep('Time: 8727.7300',readLines(nod.file))
starts = grep('1 -0.0000',readLines(nod.file))
ends = grep('101 -100.0000',readLines(nod.file))
opt = c(opt1,opt2,opt3)[which(c(opt1,opt2,opt3) >= 1000)[1]]
if(is.na(opt) == TRUE){
write(paste(smap.lat[p]," ",smap.lon[p],sep=''),bad.file,append=TRUE)
#Make Selector.in file
soil.file = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/Soil_raw",sep='')
soil.raw = read.table(soil.file)
smap.file = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/SMAP_raw",sep='')
smap.raw = read.table(smap.file)
ndays = dim(smap.raw)[1]
nhours = ndays*24
sel.file = paste(old.dir,"SELECTOR.IN",sep='')
if(file.exists(sel.file)==TRUE) file.remove(sel.file)
write("Pcp_File_Version=4",sel.file,append=TRUE)
write("*** BLOCK A: BASIC INFORMATION *****************************************",sel.file,append=TRUE)
write("Heading",sel.file,append=TRUE)
write("dry to wet",sel.file,append=TRUE)
write("LUnit TUnit MUnit (indicated units are obligatory for all input data)",sel.file,append=TRUE)
write("cm",sel.file,append=TRUE)
write("hours",sel.file,append=TRUE)
write("mmol",sel.file,append=TRUE)
write("lWat lChem lTemp lSink lRoot lShort lWDep lScreen lVariabBC lEquil lInverse",sel.file,append=TRUE)
write(" t f f t f f f t t t f",sel.file,append=TRUE)
write("lSnow lHP1 lMeteo lVapor lActiveU lFluxes lIrrig lDummy lDummy lDummy",sel.file,append=TRUE)
write(" f f f f f t f f f f",sel.file,append=TRUE)
write("NMat NLay CosAlpha",sel.file,append=TRUE)
write(" 1 1 1",sel.file,append=TRUE)
write("*** BLOCK B: WATER FLOW INFORMATION ************************************",sel.file,append=TRUE)
write("MaxIt TolTh TolH (maximum number of iterations and tolerances)",sel.file,append=TRUE)
write(" 300 0.001 1",sel.file,append=TRUE)
write("TopInf WLayer KodTop InitCond",sel.file,append=TRUE)
write(" t t -1 t",sel.file,append=TRUE)
write("BotInf qGWLF FreeD SeepF KodBot DrainF hSeep",sel.file,append=TRUE)
write(" f f t f -1 f 0",sel.file,append=TRUE)
write(" hTab1 hTabN",sel.file,append=TRUE)
write(" 0 0",sel.file,append=TRUE)
write(" Model Hysteresis",sel.file,append=TRUE)
write(" 0 0",sel.file,append=TRUE)
write(" thr ths Alfa n Ks l",sel.file,append=TRUE)
if(soil.raw == 1){ # Sand - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000107 * 360000
l = 0.5
}
if(soil.raw == 2){ # Loamy sand - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.0000141 * 360000
l = 0.5
}
if(soil.raw == 3){ # Sandy loam - medium
thr = 0.010
ths = 0.439
alfa = 0.0314
n = 1.1804
Ks = 0.00000523 * 360000
l = 0.5
}
if(soil.raw == 4){ # Silt loam - medium
thr = 0.010
ths = 0.439
alfa = 0.0314
n = 1.1804
Ks = 0.00000281 * 360000
l = 0.5
}
if(soil.raw == 5){ # Silt - medium fine
thr = 0.010
ths = 0.430
alfa = 0.0083
n = 1.2539
Ks = 0.00000281 * 360000
l = 0.5
}
if(soil.raw == 6){ # Loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000338 * 360000
l = 0.5
}
if(soil.raw == 7){ # Sandy clay loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000445 * 360000
l = 0.5
}
if(soil.raw == 8){ # Silty clay loam - medium fine
thr = 0.010
ths = 0.430
alfa = 0.0083
n = 1.2539
Ks = 0.00000204 * 360000
l = 0.5
}
if(soil.raw == 9){ # Clay loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000245 * 360000
l = 0.5
}
if(soil.raw == 10){ # Sandy clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000722 * 360000
l = 0.5
}
if(soil.raw == 11){ # Silty clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000134 * 360000
l = 0.5
}
if(soil.raw == 12){ # Clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.000000974 * 360000
l = 0.5
}
if(soil.raw == 13){ # Organic materials
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000338 * 360000
l = 0.5
}
if(soil.raw == 15){ # Bedrock
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.0000000974 * 360000
l = 0.5
}
if(soil.raw == 16){ # Other
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000134 * 360000
l = 0.5
}
write(paste(" ",round(thr,digits=5)," ",round(ths,digits=5)," ",round(alfa,digits=5)," ",round(n,digits=5)," ",round(Ks,digits=5)," ",round(l,digits=5)),sel.file,append=TRUE)
write("*** BLOCK C: TIME INFORMATION ******************************************",sel.file,append=TRUE)
write(" dt dtMin dtMax DMul DMul2 ItMin ItMax MPL",sel.file,append=TRUE)
nouts = 468
write(paste(" 0.024 0.00024 0.96 1.3 0.7 3 7 ",round(nouts,digits=0),sep=''),sel.file,append=TRUE)
write(" tInit tMax",sel.file,append=TRUE)
write(paste(" 0 ",nhours,sep=''),sel.file,append=TRUE)
write(" lPrintD nPrintSteps tPrintInterval lEnter",sel.file,append=TRUE)
write(" t 1 1 t",sel.file,append=TRUE)
write("TPrint(1),TPrint(2),...,TPrint(MPL)",sel.file,append=TRUE)
time = seq(24,nhours,length.out=nouts)
for(k in 1:(nouts/6)){
write(paste(" ",round(time[(k*6-5)],digits=2)," ",round(time[(k*6-4)],digits=2)," ",round(time[(k*6-3)],digits=2)," ",round(time[(k*6-2)],digits=2)," ",round(time[(k*6-1)],digits=2)," ",round(time[(k*6-0)],digits=2),sep=''),sel.file,append=TRUE)
}
write("*** BLOCK G: ROOT WATER UPTAKE INFORMATION *****************************",sel.file,append=TRUE)
write(" Model (0 - Feddes, 1 - S shape) cRootMax OmegaC",sel.file,append=TRUE)
write(" 0 1",sel.file,append=TRUE)
write(" P0 P2H P2L P3 r2H r2L",sel.file,append=TRUE)
write(" -1 -8000 -12000 -24000 0.0208333 0.00416667",sel.file,append=TRUE)
write("POptm(1),POptm(2),...,POptm(NMat)",sel.file,append=TRUE)
write(" -25 ",sel.file,append=TRUE)
write("*** END OF INPUT FILE 'SELECTOR.IN' ************************************",sel.file,append=TRUE)
write(" ",sel.file,append=TRUE)
}
if(is.na(opt) == FALSE){
write(paste(smap.lat[p]," ",smap.lon[p],sep=''),good.file,append=TRUE)
lstart = starts[which(starts > opt)[1]]
lend = ends[which(ends > opt)[1]]
nod.raw = readLines(nod.file)
nod.chosen = nod.raw[lstart:lend]
newsm = array(NA, c(101))
for(i in 1:101){
tmp = nod.chosen[i]
newsm[i] = as.numeric(strsplit(tmp," ")[[1]][which(strsplit(tmp," ")[[1]] != "")[4]])
}
#Create new PROFILE.DAT file
pro.file = paste(old.dir,"PROFILE.DAT", sep='')
pro.raw = readLines(pro.file)
for(i in 1:101){
tmp = pro.raw[(i+5)]
value = strsplit(tmp," ")[[1]][which(strsplit(tmp," ")[[1]] != "")[3]]
new = gsub(value, format(newsm[i], scientific=TRUE), tmp)
pro.raw[(i+5)] = new
}
new.file = paste(new.dir,"PROFILE.DAT", sep='')
write(pro.raw, new.file)
#Make Selector.in file
soil.file = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/Soil_raw",sep='')
soil.raw = read.table(soil.file)
smap.file = paste(esmap.dir,smap.lat[p],"/",smap.lon[p],"/SMAP_raw",sep='')
smap.raw = read.table(smap.file)
ndays = dim(smap.raw)[1]
nhours = ndays*24
sel.file = paste(new.dir,"SELECTOR.IN",sep='')
if(file.exists(sel.file)==TRUE) file.remove(sel.file)
write("Pcp_File_Version=4",sel.file,append=TRUE)
write("*** BLOCK A: BASIC INFORMATION *****************************************",sel.file,append=TRUE)
write("Heading",sel.file,append=TRUE)
write("dry to wet",sel.file,append=TRUE)
write("LUnit TUnit MUnit (indicated units are obligatory for all input data)",sel.file,append=TRUE)
write("cm",sel.file,append=TRUE)
write("hours",sel.file,append=TRUE)
write("mmol",sel.file,append=TRUE)
write("lWat lChem lTemp lSink lRoot lShort lWDep lScreen lVariabBC lEquil lInverse",sel.file,append=TRUE)
write(" t f f t f f f t t t f",sel.file,append=TRUE)
write("lSnow lHP1 lMeteo lVapor lActiveU lFluxes lIrrig lDummy lDummy lDummy",sel.file,append=TRUE)
write(" f f f f f t f f f f",sel.file,append=TRUE)
write("NMat NLay CosAlpha",sel.file,append=TRUE)
write(" 1 1 1",sel.file,append=TRUE)
write("*** BLOCK B: WATER FLOW INFORMATION ************************************",sel.file,append=TRUE)
write("MaxIt TolTh TolH (maximum number of iterations and tolerances)",sel.file,append=TRUE)
write(" 10 0.001 1",sel.file,append=TRUE)
write("TopInf WLayer KodTop InitCond",sel.file,append=TRUE)
write(" t t -1 t",sel.file,append=TRUE)
write("BotInf qGWLF FreeD SeepF KodBot DrainF hSeep",sel.file,append=TRUE)
write(" f f t f -1 f 0",sel.file,append=TRUE)
write(" hTab1 hTabN",sel.file,append=TRUE)
write(" 0 0",sel.file,append=TRUE)
write(" Model Hysteresis",sel.file,append=TRUE)
write(" 0 0",sel.file,append=TRUE)
write(" thr ths Alfa n Ks l",sel.file,append=TRUE)
if(soil.raw == 1){ # Sand - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000107 * 360000
l = 0.5
}
if(soil.raw == 2){ # Loamy sand - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.0000141 * 360000
l = 0.5
}
if(soil.raw == 3){ # Sandy loam - medium
thr = 0.010
ths = 0.439
alfa = 0.0314
n = 1.1804
Ks = 0.00000523 * 360000
l = 0.5
}
if(soil.raw == 4){ # Silt loam - medium
thr = 0.010
ths = 0.439
alfa = 0.0314
n = 1.1804
Ks = 0.00000281 * 360000
l = 0.5
}
if(soil.raw == 5){ # Silt - medium fine
thr = 0.010
ths = 0.430
alfa = 0.0083
n = 1.2539
Ks = 0.00000281 * 360000
l = 0.5
}
if(soil.raw == 6){ # Loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000338 * 360000
l = 0.5
}
if(soil.raw == 7){ # Sandy clay loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000445 * 360000
l = 0.5
}
if(soil.raw == 8){ # Silty clay loam - medium fine
thr = 0.010
ths = 0.430
alfa = 0.0083
n = 1.2539
Ks = 0.00000204 * 360000
l = 0.5
}
if(soil.raw == 9){ # Clay loam - coarse
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000245 * 360000
l = 0.5
}
if(soil.raw == 10){ # Sandy clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000722 * 360000
l = 0.5
}
if(soil.raw == 11){ # Silty clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000134 * 360000
l = 0.5
}
if(soil.raw == 12){ # Clay - fine
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.000000974 * 360000
l = 0.5
}
if(soil.raw == 13){ # Organic materials
thr = 0.025
ths = 0.403
alfa = 0.0383
n = 1.3774
Ks = 0.00000338 * 360000
l = 0.5
}
if(soil.raw == 15){ # Bedrock
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.0000000974 * 360000
l = 0.5
}
if(soil.raw == 16){ # Other
thr = 0.010
ths = 0.614
alfa = 0.0265
n = 1.1033
Ks = 0.00000134 * 360000
l = 0.5
}
write(paste(" ",round(thr,digits=5)," ",round(ths,digits=5)," ",round(alfa,digits=5)," ",round(n,digits=5)," ",round(Ks,digits=5)," ",round(l,digits=5)),sel.file,append=TRUE)
write("*** BLOCK C: TIME INFORMATION ******************************************",sel.file,append=TRUE)
write(" dt dtMin dtMax DMul DMul2 ItMin ItMax MPL",sel.file,append=TRUE)
nouts = 468
write(paste(" 0.024 0.00024 0.96 1.3 0.7 3 7 ",round(nouts,digits=0),sep=''),sel.file,append=TRUE)
write(" tInit tMax",sel.file,append=TRUE)
write(paste(" 0 ",nhours,sep=''),sel.file,append=TRUE)
write(" lPrintD nPrintSteps tPrintInterval lEnter",sel.file,append=TRUE)
write(" t 1 1 t",sel.file,append=TRUE)
write("TPrint(1),TPrint(2),...,TPrint(MPL)",sel.file,append=TRUE)
time = seq(24,nhours,length.out=nouts)
for(k in 1:(nouts/6)){
write(paste(" ",round(time[(k*6-5)],digits=2)," ",round(time[(k*6-4)],digits=2)," ",round(time[(k*6-3)],digits=2)," ",round(time[(k*6-2)],digits=2)," ",round(time[(k*6-1)],digits=2)," ",round(time[(k*6-0)],digits=2),sep=''),sel.file,append=TRUE)
}
write("*** BLOCK G: ROOT WATER UPTAKE INFORMATION *****************************",sel.file,append=TRUE)
write(" Model (0 - Feddes, 1 - S shape) cRootMax OmegaC",sel.file,append=TRUE)
write(" 0 1",sel.file,append=TRUE)
write(" P0 P2H P2L P3 r2H r2L",sel.file,append=TRUE)
write(" -1 -8000 -12000 -24000 0.0208333 0.00416667",sel.file,append=TRUE)
write("POptm(1),POptm(2),...,POptm(NMat)",sel.file,append=TRUE)
write(" -25 ",sel.file,append=TRUE)
write("*** END OF INPUT FILE 'SELECTOR.IN' ************************************",sel.file,append=TRUE)
write(" ",sel.file,append=TRUE)
#Copy Descript and Hydrus1D.Dat
file.copy(paste(old.dir,"DESCRIPT.TXT",sep=''),paste(new.dir,"DESCRIPT.TXT",sep=''))
file.copy(paste(old.dir,"HYDRUS1D.DAT",sep=''),paste(new.dir,"HYDRUS1D.DAT",sep=''))
file.copy(paste(old.dir,"ATMOSPH.IN",sep=''),paste(new.dir,"ATMOSPH.IN",sep=''))
}
print(new.dir)
}