-
Notifications
You must be signed in to change notification settings - Fork 1
/
IPSLIN.FOR
412 lines (352 loc) · 13.2 KB
/
IPSLIN.FOR
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
C=======================================================================
C IPSLIN, Subroutine
C
C Reads soil initial conditions from FILEX file
C Read initial values of rapidly changing soil variables,
C and convert values to standard soil depths
C-----------------------------------------------------------------------
C Revision history
C
C 06/21/1991 JWJ Written
C 05/28/1993 PWW Header revision and minor changes
C 12/01/1993 WTB Modifed to read soil test P
C 08/19/2002 GH Modified for Y2K
C 02/07/2007 GH Add path to FileX
! 08/15/2011 Improve the handling of INH4 and INO3
C-----------------------------------------------------------------------
C INPUT : FILEX,LNIC,NLAYR,DUL,SWINIT,PEDON,SLNO
C
C LOCAL : LN,NLAYRI,NLAYR,DS,DLAYRI,LINEXP,ISECT,CHARTEST,LUNEXP
C
C OUTPUT : YRIC,PRCROP,WRESR,WRESND,EFINOC,EFNFIX,INO3,INH4,SWINIT
C-----------------------------------------------------------------------
C Called : SESOIL INPUT
C
C Calls : FIND IGNORE ERROR
C-----------------------------------------------------------------------
C DEFINITIONS
C
C HDLAY :
C=======================================================================
SUBROUTINE IPSLIN (FILEX,FILEX_P,LNIC,NLAYR,DUL,YRIC,PRCROP,WRESR,
& WRESND,EFINOC,EFNFIX,PEDON,SLNO,DS,SWINIT,INH4,INO3,
& ISWITCH,ICWD,ICRES,ICREN,ICREP,ICRIP,ICRID,YRSIM)
! & SOM1I, SOM2I, SOM3I)
USE ModuleDefs
IMPLICIT NONE
CHARACTER*2 PRCROP
CHARACTER*6 ERRKEY,FINDCH
CHARACTER*10 PEDON,SLNO
CHARACTER*12 FILEX
CHARACTER*80 CHARTEST
CHARACTER*92 FILEX_P
INTEGER L,LN,LUNEXP,NLAYRI,NLAYR,LINEXP,ISECT,LNIC,
& YRIC,ERRNUM,IFIND,YRSIM
REAL DS(NL),DLAYRI(NL),SWINIT(NL)
REAL DUL(NL),WRESR,WRESND,EFINOC,EFNFIX,INO3(NL),INH4(NL)
REAL ICWD,ICRES,ICREN,ICREP,ICRIP,ICRID !, TOTSOM
! REAL, DIMENSION(NL) :: SOM1I, SOM2I, SOM3I
TYPE (SwitchType) ISWITCH
PARAMETER (LUNEXP = 16)
PARAMETER (ERRKEY = 'IPSLIN')
FINDCH = '*INITI'
C
C Set default initial conditions in case they are missing
C
YRIC = 0
PRCROP = ' '
WRESR = 0.0
C-GH WRESR = 1.0
WRESND = 0.0
EFINOC = 1.0
EFNFIX = 1.0
ICWD = 0.0
ICRES = 0.0
ICREN = 0.0
ICREP = 0.0
ICRIP = 100.0
ICRID = 0.0
C-GH ICRID = 15.0
C
SWINIT = -99.
INO3 = -99.
INH4 = -99.
IF (PEDON .NE. SLNO) RETURN
IF (LNIC .LE. 0) RETURN
OPEN (LUNEXP,FILE = FILEX_P,STATUS = 'OLD',IOSTAT=ERRNUM)
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,0)
CALL FIND (LUNEXP,FINDCH,LINEXP,IFIND)
IF (IFIND .EQ. 0) CALL ERROR (ERRKEY,1,FILEX,LINEXP)
50 CONTINUE
CALL IGNORE (LUNEXP,LINEXP,ISECT,CHARTEST)
IF (ISECT .EQ. 1) THEN
READ (CHARTEST,55,IOSTAT=ERRNUM) LN
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
IF (LN .NE. LNIC) GO TO 50
READ (CHARTEST,55,IOSTAT=ERRNUM) LN,PRCROP,YRIC,WRESR,
& WRESND,EFINOC,EFNFIX,ICWD,ICRES,ICREN,ICREP,ICRIP,ICRID
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
ELSE
CALL ERROR (ERRKEY,2,FILEX,LINEXP)
ENDIF
IF (YRIC .LT. 0) THEN
YRIC = YRSIM
ENDIF
CALL Y2K_DOY (YRIC)
IF (ISWITCH%ISWNIT .EQ. 'Y') THEN
WRESR = MAX(WRESR,0.0)
C-GH IF (WRESR .LT. 1.0) WRESR = 1.0
IF (WRESND .LT. 0.0) WRESND = 0.0
IF (EFINOC .LT. 0.0) EFINOC = 1.0
IF (EFNFIX .LT. 0.0) EFNFIX = 1.0
ICWD = MAX(ICWD,0.0)
C-PW ICRES = MAX(ICRES,10.0)
ICRES = MAX(ICRES,0.0)
ICREN = MAX(ICREN,0.0)
ICREP = MAX(ICREP,0.0)
ICRID = MAX(ICRID,0.0)
C-GH ICRID = MAX(ICRID,15.0)
IF (ICRIP .LT. 0.0) ICRIP = 100.0
ENDIF
NLAYRI = 1
C
C Read layer information for the correct IC level number
C
70 CONTINUE
CALL IGNORE (LUNEXP,LINEXP,ISECT,CHARTEST)
IF (ISECT .EQ. 1) THEN
READ (CHARTEST,60,IOSTAT=ERRNUM) LN
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
IF (LN .NE. LNIC) GO TO 70
READ (CHARTEST,60,IOSTAT=ERRNUM) LN,DLAYRI(NLAYRI),
& SWINIT(NLAYRI),INH4(NLAYRI),INO3(NLAYRI)
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
INH4(NLAYRI) = MAX(INH4(NLAYRI), 0.0)
INO3(NLAYRI) = MAX(INO3(NLAYRI), 0.0)
NLAYRI = NLAYRI + 1
GO TO 70
ENDIF
CLOSE (LUNEXP)
!Force input depths to go to bottom of profile
IF (DLAYRI(NLAYRI) < DS(NLAYR)) THEN
NLAYRI = NLAYRI + 1
DLAYRI(NLAYRI) = DS(NLAYR)
INH4(NLAYRI) = 0.0
INO3(NLAYRI) = 0.0
ENDIF
NLAYRI = NLAYRI - 1
! Match layers first!
CALL LMATCH (NLAYRI,DLAYRI,SWINIT,NLAYR,DS)
CALL LMATCH (NLAYRI,DLAYRI,INH4, NLAYR,DS)
CALL LMATCH (NLAYRI,DLAYRI,INO3, NLAYR,DS)
! Then check for bounds
DO L = 1, NLAYR
IF (ISWITCH%ISWWAT .NE. 'N') THEN
IF (SWINIT(L) .GT. 0.75) THEN
CALL ERROR (ERRKEY,10,FILEX,LINEXP)
ENDIF
IF (SWINIT(L) .LT. 0.00) THEN
SWINIT(L) = DUL(L)
ENDIF
ENDIF
IF (ISWITCH%ISWNIT .EQ. 'Y') THEN
IF (INH4(L) .LT. 0.0) THEN
INH4(L) = 0.01
ENDIF
IF (INH4(L) .GT. 100.0) THEN
CALL ERROR (ERRKEY,11,FILEX,LINEXP)
ENDIF
IF (INO3(L) .LT. 0.0) THEN
INO3(L) = 0.01
ENDIF
IF (INO3(L) .GT. 100.0) THEN
CALL ERROR (ERRKEY,12,FILEX,LINEXP)
ENDIF
ENDIF
ENDDO
! CALL LMATCH (NLAYRI,DLAYRI,SOM1I, NLAYR,DS)
! CALL LMATCH (NLAYRI,DLAYRI,SOM2I, NLAYR,DS)
! CALL LMATCH (NLAYRI,DLAYRI,SOM3I, NLAYR,DS)
RETURN
C-----------------------------------------------------------------------
C Format Strings
C-----------------------------------------------------------------------
55 FORMAT (I3,3X,A2,1X,I5,10(1X,F5.0))
60 FORMAT (I3,F5.0,3(1X,F5.0))
65 FORMAT (26X,3F6.0)
END SUBROUTINE IPSLIN
C=======================================================================
C IPSLAN, Subroutine
C
C Reads soil analysis data from FILEX file
C Read initial values of soil variables, such as fertility,
C that change at a medium rate, adjust soil depths to standard
C Created 01-JUL-91, J. Jones to read new IBSNAT formats
C-----------------------------------------------------------------------
C Revision history
C
C 07/01/1991 JWJ Written
C 11/18/1992 WDB Modifed to read soil test P
C 05/28/1993 PWW Header revision and minor changes
! 03/31/2005 CHP Return method of P extraction (SMPX) if any P values
! (SAPX) are read.
C 02/07/2007 GH Add path to File_X
C-----------------------------------------------------------------------
C INPUT : FILEX,LNSA,PEDON,SLNO,BD,OC,PH
C
C LOCAL : LUNEXP,LN,NLAYRI,NLAYR,DS,SABL,LINEXP,ISECT,CHARTEST,
C SADM,SAOC,SANI,SAPHW,SAPHB,SAPX,SAKE,
C SADAT,SMDM,SMOC,SMNI,SMHW,SMHB,SMPX,SMKE
C
C OUTPUT : BD,OC,PH,EXTP
C-----------------------------------------------------------------------
C Called : SESOIL INPUT
C
C Calls : FIND IGNORE ERROR
C-----------------------------------------------------------------------
C DEFINITIONS
C
C HDLAY :
C=======================================================================
SUBROUTINE IPSLAN (FILEX, FILEX_P,LNSA, BD, DS, EXK, EXTP, OC,
& PEDON, PH, PHKCL, SLNO, SMHB, SMKE, SMPX, TOTN,
& SASC, NLAYR)
USE ModuleDefs
IMPLICIT NONE
CHARACTER*5 SMHB, SMKE, SMPX, SMHBtemp, SMKEtemp, SMPXtemp
CHARACTER*6 ERRKEY, FINDCH
CHARACTER*10 SLNO, PEDON
CHARACTER*12 FILEX
CHARACTER*80 CHARTEST*80
CHARACTER*92 FILEX_P
INTEGER LN,LUNEXP,NLAYRI,NLAYR,LINEXP,ISECT,LNSA
INTEGER ERRNUM,SADAT,IFIND,L
REAL SABL(NL),SADM(NL),SAOC(NL),SANI(NL),SAPHW(NL)
REAL SAPX(NL),SAKE(NL),BD(NL),OC(NL),DS(NL),SAPHB(NL)
REAL PH(NL),PHKCL(NL),EXK(NL), EXTP(NL),TOTN(NL), SASC(NL)
PARAMETER (LUNEXP = 16)
PARAMETER (ERRKEY = 'IPSLAN')
FINDCH = '*SOIL '
IF (LNSA .LE. 0) RETURN
IF (PEDON .NE. SLNO) RETURN
SADM = -99.
SAOC = -99.
SANI = -99.
SAPHW = -99.
SAPHB = -99.
SAPX = -99.
SASC = -99.
OPEN (LUNEXP,FILE = FILEX_P,STATUS = 'OLD',IOSTAT=ERRNUM)
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,0)
CALL FIND (LUNEXP,FINDCH,LINEXP,IFIND)
IF (IFIND .EQ. 0) CALL ERROR (ERRKEY,1,FILEX,LINEXP)
50 CONTINUE
CALL IGNORE (LUNEXP,LINEXP,ISECT,CHARTEST)
IF (ISECT .EQ. 1) THEN
READ (CHARTEST,55,IOSTAT=ERRNUM) LN
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
IF (LN .NE. LNSA) GO TO 50
!chp 3/31/05 READ (CHARTEST,55,IOSTAT=ERRNUM) LN,SADAT,SMHB,SMPX,SMKE
READ (CHARTEST,55,IOSTAT=ERRNUM) LN, SADAT,
& SMHBtemp, SMPXtemp, SMKEtemp
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
ELSE
CALL ERROR (ERRKEY,2,FILEX,LINEXP)
ENDIF
CALL Y2K_DOY (SADAT)
C
C Read layer information for the correct soil analysis number
C
NLAYRI = 1
70 CONTINUE
CALL IGNORE (LUNEXP,LINEXP,ISECT,CHARTEST)
IF (ISECT .EQ. 1) THEN
READ (CHARTEST,60,IOSTAT=ERRNUM) LN
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
IF (LN .NE. LNSA) GO TO 70
READ (CHARTEST,60,IOSTAT=ERRNUM) LN,SABL(NLAYRI),
& SADM (NLAYRI),SAOC(NLAYRI),SANI(NLAYRI),SAPHW(NLAYRI),
& SAPHB(NLAYRI),SAPX(NLAYRI),SAKE(NLAYRI)
IF (ERRNUM .NE. 0) CALL ERROR (ERRKEY,ERRNUM,FILEX,LINEXP)
! chp added 4/21/2008 - stable organic C in %
READ (CHARTEST,'(51X,F6.0)',IOSTAT=ERRNUM) SASC(NLAYRI)
IF (ERRNUM .NE. 0) SASC(NLAYRI) = -99.
IF (SADM(NLAYRI) .GT. 10.0) THEN
CALL ERROR (ERRKEY,10,FILEX,LINEXP)
ENDIF
IF (SAOC(NLAYRI) .GT. 100.0) THEN
CALL ERROR (ERRKEY,11,FILEX,LINEXP)
ENDIF
IF (SANI(NLAYRI) .GT. 10.0) THEN
CALL ERROR (ERRKEY,12,FILEX,LINEXP)
ENDIF
NLAYRI = NLAYRI + 1
GO TO 70
ENDIF
CLOSE (LUNEXP)
NLAYRI = NLAYRI - 1
C Use soil analysis values for NLAYR layers for which data were
C in the experimental field; for other layers the values from
C the soil profile will be retained and used. Only replace
C those values if data were available (i.e., not < 0.)
IF (SADM(1) .GT. 0.0 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SADM, NLAYR, DS)
DO L = 1, NLAYR
IF (SADM(L) .GT. 0.0) BD(L) = SADM(L)
ENDDO
ENDIF
IF (SAOC(1) .GT. -1.E-6 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SAOC, NLAYR, DS)
DO L = 1, NLAYR
! OC in %, SAOC in % (despite what v3.5-Vol2 says)
IF (SAOC(L) .GT. -1.E-6) OC(L) = SAOC(L)
ENDDO
ENDIF
IF (SANI(1) .GT. -1.E-6 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SANI, NLAYR, DS)
DO L = 1, NLAYR
! TOTN in %, SANI in % (despite what v3.5-Vol2 says)
IF (SANI(L) .GT. -1.E-6) TOTN(L) = SANI(L)
ENDDO
ENDIF
IF (SAPHW(1) .GT. 0.0 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SAPHW, NLAYR, DS)
DO L = 1, NLAYR
IF (SAPHW(L).GT. 0.0) PH(L) = SAPHW(L)
ENDDO
ENDIF
IF (SAPHB(1) .GT. 0.0 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SAPHB, NLAYR, DS)
SMHB = SMHBtemp
DO L = 1, NLAYR
IF (SAPHB(L).GT. 0.0) PHKCL(L) = SAPHB(L)
ENDDO
ENDIF
IF (SAPX(1) .GT. -1.E-6 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SAPX, NLAYR, DS)
SMPX = SMPXtemp !CHP 3/31/2005
DO L = 1, NLAYR
IF (SAPX(L) .GT. -1.E-6) THEN
EXTP(L) = SAPX(L)
ENDIF
ENDDO
ENDIF
IF (SAKE(1) .GT. -1.E-6 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SAKE, NLAYR, DS)
SMKE = SMKEtemp !CHP 3/31/2005
DO L = 1, NLAYR
IF (SAKE(L) .GT. -1.E-6) EXK(L) = SAKE(L)
ENDDO
ENDIF
! Stable organic C has no counterpart in the soil profile data
IF (SASC(1) .GT. -1.E-6 .AND. NLAYRI > 0) THEN
CALL LMATCH (NLAYRI, SABL, SASC, NLAYR, DS)
ENDIF
RETURN
C-----------------------------------------------------------------------
C Format Strings
C-----------------------------------------------------------------------
55 FORMAT (I3,2X,I3,3(1X,A5))
60 FORMAT (I3,F5.0,8(1X,F5.0))
END SUBROUTINE IPSLAN
!