-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSREA045.FOR
4531 lines (3806 loc) · 131 KB
/
CSREA045.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
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! Generic read routines
! File contains utilities for generic reading of standard files
! NOTE: Need to get array sizes with: ASIZE=UBOUND(ARRAYOUT,1)
! XREADD - Subroutine to find number of components, options, etc..
! XREADT - Subroutine to read line of text from X-file
! XREADC - Subroutine to read character from X-file
! XREADR - Subroutine to read real value from X-file
! XREADI - Subroutine to read integer value from X-file
! XREADCA - Subroutine to read array of characters from X-file
! XREADRA - Subroutine to read array of real values from X-file
! XREADIA - Subroutine to read array of integer values from X-file
! AREADT - Subroutine to read line of text from summary file
! AREADC - Subroutine to read character from summary file
! AREADR - Subroutine to read real value from summary file
! AREADI - Subroutine to read integer value from summary file
! CUREADT - Subroutine to read line of text from cultivar file
! CUREADC - Subroutine to read character from cultivar file
! CUREADR - Subroutine to read real value from cultivar file
! ECREADT - Subroutine to read line(s) of text from ecotype file
! ECREADC - Subroutine to read character from ecotype file
! ECREADR - Subroutine to read real value from ecotype file
! ECREADRA - Subroutine to read real array from eco file (String<25)
! SPREADT - Subroutine to read line of text from species file
! SPREADC - Subroutine to read character from species file
! SPREADR - Subroutine to read real value from species file
! SPREADRA - Subroutine to read array of real value from species file
! SPREADIA - Subroutine to read array of integers from species file
! SPREADCA - Subroutine to read array of characters from species file
! SLREADT - Subroutine to read line of text from soil file
! SLREADC - Subroutine to read character from soil file
! SLREADR - Subroutine to read real value from soil file
! SLREADCA - Subroutine to read array of characters from soil file
! SLREADRA - Subroutine to read array of real values from soil file
! SMREADT - Subroutine to read line of text from SOM file
! SMREADC - Subroutine to read character from SOM file
! SMREADR - Subroutine to read real value from SOM file
! SMREADRA - Subroutine to read array of real value from SOM file
! SMREADR2 - Subroutine to read 2 dim array,real value from SOM file
! AMAKEABV - Subroutine to make array of abbreviations with synonyms
! AMAKE1 - Subroutine to make array when data in columns,1 level
! AMAKER0 - Subroutine to make array when data in rows and 0 levels
! AMAKE5 - Subroutine to make array when data in columns,5 levels
! ARAYREAD - Subroutine to read internal array and return string
! Following no longer used but retained for possible later use
! E1READT - Subroutine to read line of text from 'soils' type eco file
! E1READC - Subroutine to read character from 'soils' type eco file
! E1READR - Subroutine to read real value from 'soils' type eco file
! S1READT - Subroutine to read line of text from old species file
! S1READC - Subroutine to read character from old species file
! S1READR - Subroutine to read real value from old species file
! S1READRA - Subroutine to read array of real value from old species file
! S1READIA - Subroutine to read array of integers from old species file
! S1READCA - Subroutine to read array of characters from old species file
!-----------------------------------------------------------------------
SUBROUTINE XREADD(FILENAME,TN,RN,snnum,onnum,cnnum)
IMPLICIT NONE
INTEGER snx
PARAMETER (snx=10)
INTEGER onx
PARAMETER (onx=3)
CHARACTER (LEN=1000) DATASTD
CHARACTER (LEN=600) DATATMP
CHARACTER (LEN=254) TL2541, DATALINE
CHARACTER (LEN=80) Tl0801
CHARACTER (LEN=30) TL30
CHARACTER (LEN=20) GROUP, LEVELSTD
CHARACTER (LEN=10) LEVEL, TL10FROMI
CHARACTER (LEN=1) TL1UPCASE, FTYPE
CHARACTER (LEN=*) FILENAME
INTEGER FILENUM, GROUPLEN, TVILENT
INTEGER LEVELLEN, FILELEN, LENSTD
INTEGER FNUMERR, I, L
INTEGER CNNUM(SNX,ONX), SNNUM, ONNUM(SNX)
INTEGER SN, ON(SNX), CN(SNX,ONX), TN, RN, COLRN
INTEGER RNCOL, SNCOL, ONCOL, CNCOL, TVICOLNM
INTRINSIC MAX
SAVE
CALL GETLUN('FILETMP',FILENUM)
FTYPE='*' ! Default file type
GROUP='*TREATMENTS'
LENSTD=12
FILELEN=TVILENT(FILENAME)
GROUPLEN=TVILENT(GROUP)
OPEN(filenum,FILE=filename(1:FILELEN),STATUS='OLD')
LEVEL=TL10FROMI(TN)
LEVELLEN=TVILENT(LEVEL)
IF(LEVELLEN.GT.LENSTD)LEVELLEN=LENSTD
LEVELSTD=' '
LEVELSTD(1:LEVELLEN)=LEVEL(1:LEVELLEN)
SNNUM=1
DO I=1,SNX
onnum(i)=1
ENDDO
DO I=1,SNX
DO L=1,ONX
CNNUM(I,L)=1
ENDDO
ENDDO
tl0801=' '
DO WHILE(tl0801(1:GROUPLEN).NE.GROUP(1:GROUPLEN))
READ(filenum,'(A80)',END=9996,ERR=9999)tl0801
CALL Ltrim(tl0801)
tl0801(1:1)=Tl1upcase(tl0801(1:1))
tl0801(2:2)=Tl1upcase(tl0801(2:2))
IF(tl0801(1:1).EQ.'$')ftype='$'
END DO
DO WHILE (TL0801(1:1).NE.'@')
READ (FILENUM,'(A80)') TL0801
ENDDO
RNCOL=Tvicolnm(TL0801,'RN ')
SNCOL=Tvicolnm(TL0801,'SN ')
ONCOL=Tvicolnm(TL0801,'ON ')
CNCOL=Tvicolnm(TL0801,'CN ')
tl2541=' '
DO
DO WHILE(tl30(1:levellen).NE.levelstd(1:levellen))
READ(filenum,'(A254)',END=9996,ERR=9999)tl2541
IF(tl2541(1:1).EQ.'*')GOTO 999
TL30=TL2541(1:30)
CALL Ltrim(tl30)
IF(tl30(1:1).EQ.'0'.AND.tl30(2:2).NE.' ')THEN
tl30(1:1)=' '
IF(tl30(2:2).EQ.'0'.AND.tl30(3:3).NE.' ')THEN
tl30(2:2)=' '
IF(tl30(3:3).EQ.'0'.AND.tl30(4:4).NE.' ')THEN
tl30(3:3)=' '
ENDIF
ENDIF
ENDIF
CALL Ltrim(tl30)
tl30(1:1)=Tl1upcase(tl30(1:1))
tl30(2:2)=Tl1upcase(tl30(2:2))
END DO
DATALINE=tl2541(1:20)//' '
CALL Standard(dataline,datatmp,'6')
IF(ftype.EQ.'*')THEN
DATASTD(1:48)=DATATMP(1:48)
ELSEIF(ftype.EQ.'$'.AND.rncol.GT.0)THEN
IF (rncol.GT.0)THEN
READ(DATATMP,'(6X,I6)')COLRN
IF (COLRN.NE.RN) GOTO 998
ENDIF
DATASTD(1:48)=DATATMP(7:54)
ENDIF
IF (SNCOL.GT.0) THEN
READ(DATASTD,'(6X,I6)')sn
ELSE
SN = 1
ENDIF
IF(SN.LE.0)SN=1
IF (SN.GT.0)THEN
IF (SNCOL.GT.0) THEN
READ(DATASTD,'(12X,I6)')on(sn)
IF(ON(SN).LE.0)ON(SN)=1
IF(ON(SN).GT.0)THEN
READ(DATASTD,'(18X,I6)')cn(sn,on(sn))
IF(CN(SN,ON(SN)).LE.0)cn(sn,on(sn))=1
ENDIF
ENDIF
ENDIF
IF (sn.LT.1) sn = 1
snnum=MAX(snnum,sn)
IF (on(sn).LT.1) on(sn) = 1
onnum(sn)=MAX(onnum(sn),on(sn))
cnnum(sn,on(sn))=MAX(cnnum(sn,on(sn)),cn(sn,on(sn)))
998 CONTINUE
READ(filenum,'(A254)',END=9996,ERR=9999)tl2541
IF(tl2541(1:1).EQ.'*')GOTO 999
TL30=TL2541(1:30)
CALL Ltrim(tl30)
IF(tl30(1:1).EQ.'0'.AND.tl30(2:2).NE.' ')THEN
tl30(1:1)=' '
IF(tl30(2:2).EQ.'0'.AND.tl30(3:3).NE.' ')THEN
tl30(2:2)=' '
IF(tl30(3:3).EQ.'0'.AND.tl30(4:4).NE.' ')THEN
tl30(3:3)=' '
ENDIF
ENDIF
ENDIF
CALL Ltrim(tl30)
tl30(1:1)=Tl1upcase(tl30(1:1))
tl30(2:2)=Tl1upcase(tl30(2:2))
ENDDO
999 CONTINUE
9996 CONTINUE
9999 CONTINUE
CLOSE(filenum)
IF (SN .LE. 0)THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE (fnumerr,*) ' Problem in XREADD (ie.treatment details)!'
WRITE (fnumerr,*) ' Sequence number <=0 in ',filename(1:60)
WRITE (fnumerr,*) ' Check READS.OUT for details of reads'
WRITE (*,*) ' Problem in XREADD (ie.treatment details)!'
WRITE (*,*) ' Could not read: ',filename(1:60)
WRITE (*,*) ' Sequence number <=0 in ',filename(1:60)
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
RETURN
END
!-----------------------------------------------------------------------
SUBROUTINE XREADT(FILENAME,COL1,COL1R,COL2,COL3,COL4,CODE,TXTO)
USE CRSIMDEF
IMPLICIT NONE
CHARACTER (LEN=1000) DATASTD, ABVSTD
CHARACTER (LEN=254) FILENEW, FILEOLD, ABVLINE, DATALINE
CHARACTER (LEN=254) TL2541, DATARRAY(500), ABVARRAY(1000)
CHARACTER (LEN=128) ARG
CHARACTER (LEN=100) DATAROC
CHARACTER (LEN=132) ABVFILE
CHARACTER (LEN=64) CTRDIRFL
CHARACTER (LEN=60) ENAME
CHARACTER (LEN=52) TEXTSTD
CHARACTER (LEN=30) TL30
CHARACTER (LEN=30) LEVELTMP, LEVELSTD, LE
CHARACTER (LEN=12) COEFFC, ABVC, COEFFCTM
CHARACTER (LEN=10) EXPER, TL10FROMI, LEVEL, TL10
CHARACTER (LEN=4) COEFFCHK
CHARACTER (LEN=3) CU,FL,SA,IC,MP,MI,MF,MR,MC,MT,ME,MH,SM,AM,FI
CHARACTER (LEN=3) DI
CHARACTER (LEN=1) TL1UPCASE, TR, CTR, FTYPE, COLON, HEADLINE
CHARACTER (LEN=1) FNUMFLAG, CTRFLAG
CHARACTER (LEN=*) FILENAME, CODE, TXTO
INTEGER COL2TMP, COL3TMP, COL4TMP, COL1, COL1R, L
INTEGER COL2, COL3, COL4, COLRN, STARNUM, STARTRE
INTEGER COL1P, COL1RP, COL2P, COL3P, COL4P, XREADNUM
INTEGER TVILENT, TVI1, TVI2, TVI3, TVI4
INTEGER STARTCOL, LEVELLEN, FILELEN, LINE, LENTMP
INTEGER TVINSTR, ABVNUM, DATANUM, LENSTD, ABVLEN, DN
INTEGER DATANUMS, RETURNUM, ARGLEN, ABVSYN, FNUMREA
INTEGER FILENUM, FNUMERR
INTEGER RNCOL, SNCOL, ONCOL, CNCOL, TVICOLNM
LOGICAL FFLAG, FOPEN
PARAMETER (LENSTD=13)
INTRINSIC LEN,MIN,TRIM !,EOF
SAVE
IF (FNUMFLAG.NE.'Y')THEN
CALL Getlun('READS.OUT',fnumrea)
CALL GETLUN('FILETMP',FILENUM)
INQUIRE (FILE='READS.OUT',OPENED=fopen)
IF (.NOT.fopen) OPEN(UNIT=fnumrea,FILE='READS.OUT')
FNUMFLAG = 'Y'
ENDIF
CALL LTRIM2(FILENAME,filenew)
FILELEN=TVILENT(FILENEW)
FILELEN=MIN(254,FILELEN)
FILENEW=' '
FILENEW(1:FILELEN)=FILENAME(1:FILELEN)
IF (FILENEW(1:FILELEN) .EQ. FILEOLD(1:FILELEN)) THEN
IF(COL1.EQ.COL1P)THEN
IF(COL1R.EQ.COL1RP)THEN
IF(COL2.EQ.COL2P)THEN
IF(COL3.EQ.COL3P)THEN
IF(COL4.EQ.COL4P)THEN
GO TO 5555
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
TVI1 = TVILENT(FILENEW)
! Pre-processor
OPEN(filenum,FILE=filenew,STATUS='OLD')
DO WHILE (TL10(1:6).NE.'*TREAT')
READ (FILENUM,'(A10)') TL10
ENDDO
IF (FILENEW(TVI1-2:TVI1).EQ.'INH') THEN
! Find TN and SN if not provided (DS4 files)
READ (FILENUM,'(A10)') TL10
READ (FILENUM,'(A10)') TL10
READ (TL10,'(I3)') COL1
READ (TL10,'(3X,I3)') COL2
COL1R = 0
COL3 = 1
COL4 =1
ELSE
! Find if RN,SN,ON,CN present (X-files)
READ (FILENUM,'(A10)') TL10
DO WHILE (TL10(1:1).NE.'@')
READ (FILENUM,'(A30)') TL30
ENDDO
RNCOL=Tvicolnm(TL30,'RN ')
SNCOL=Tvicolnm(TL30,'SN ')
ONCOL=Tvicolnm(TL30,'ON ')
CNCOL=Tvicolnm(TL30,'CN ')
ENDIF
CLOSE (filenum)
IF (COL1.LT.0) THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE(fnumerr,*) ' Treatment # <0 !'
WRITE(fnumerr,*) ' Check READS.OUT for details'
WRITE(*,*) ' Treatment # <0 !'
WRITE(*,*) ' Program will have to stop!'
WRITE(*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
IF (COL1R.LT.0) COL1R=0
WRITE(fnumrea,*)' '
WRITE(fnumrea,*)'FILE ',FILENAME(1:FILELEN)
WRITE(fnumrea,*)' TREATMENT: ',COL1
WRITE(fnumrea,*)' REPLICATE: ',COL1R
WRITE(fnumrea,*)' SN,ON,CN (as provided): ',COL2,COL3,COL4
IF (COL2.LE.0) COL2=1
IF (COL3.LE.0) COL3=1
IF (COL4.LE.0) COL4=1
WRITE(fnumrea,*)' SN,ON,CN (as used) : ',COL2,COL3,COL4
LEVEL=TL10FROMI(COL1)
LEVELLEN=TVILENT(LEVEL)
IF(LEVELLEN.GT.LENSTD)LEVELLEN=LENSTD
LEVELSTD=' '
LEVELSTD(1:LEVELLEN)=LEVEL(1:LEVELLEN)
FTYPE='*'
OPEN(filenum,FILE=filename(1:FILELEN),STATUS='OLD')
DATANUM=0
LINE=0
RETURNUM=0
TR='N'
CTR='N'
STARTCOL=1
ABVLINE=' '
XREADNUM=0
4444 CONTINUE
STARTRE=0
STARNUM=0
8888 CONTINUE
XREADNUM=XREADNUM + 1
DO
tl2541=' '
READ(filenum,'(A254)',END=9996,ERR=9999)tl2541
IF(tl2541(1:1).EQ.'$')ftype='$'
IF(TVILENT(tl2541).LT.3)GOTO 999
IF(TL2541(1:1).EQ.'!')GOTO 999
! Controls to be taken from CTR file (lower case x)
IF (FILENEW(FILELEN:FILELEN).EQ.'x') THEN
IF(TL2541(1:11).EQ.'*SIMULATION'.AND.CTR.EQ.'N') THEN
READ(filenum,'(A254)',END=9996,ERR=9999)TL2541
DO
!IF (EOF(filenum)) GOTO 9996 !chp portability to g95
READ(filenum,'(A254)',END=9996,ERR=9999)TL2541
IF(TL2541(1:1).EQ.'*') THEN
IF(TL2541(1:3).NE.'*SI') EXIT
ENDIF
ENDDO
ENDIF
ENDIF
COLON='N'
HEADLINE = 'N'
IF(tl2541(1:4).EQ.'*EXP')HEADLINE = 'Y'
IF(tl2541(1:1).EQ.'$')THEN
IF(tl2541(2:4).EQ.'EXP')HEADLINE='Y'
IF(tl2541(8:10).EQ.'EXP')HEADLINE='Y'
IF(tl2541(8:10).EQ.'DET')HEADLINE='Y'
ENDIF
IF(HEADLINE.EQ.'Y')THEN
DO TVI1=1,30
IF(COLON.EQ.'Y'.AND.TL2541(TVI1:TVI1).NE.' ')EXIT
IF(TL2541(TVI1:TVI1).EQ.':')COLON='Y'
TL2541(TVI1:TVI1)=' '
ENDDO
CALL LTRIM(TL2541)
READ (TL2541,'(A10,A60)')EXPER,ENAME
CALL Ltrim(ENAME)
DATANUM=DATANUM+1
DATARRAY(DATANUM)='EXPER '//' '//exper
IF(FTYPE.EQ.'*') THEN
DATANUM=DATANUM+1
DATARRAY(DATANUM)='ENAME '//' '//ename
ENDIF
GO TO 999
ENDIF
IF(tl2541(1:1).EQ.'$')GOTO 999
IF(tl2541(1:3).EQ.'*EX')GOTO 999
IF(TR.EQ.'Y')THEN
RETURNUM=RETURNUM+1
IF (RETURNUM .GT. 250) THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE(fnumerr,*)' Problem reading treatment ',COL1
WRITE(fnumerr,*)' Component,option,species ',COL2,COL3,COL4
WRITE(fnumerr,*)' Check READS.OUT for details'
WRITE (*,*) ' Problem reading treatment ',COL1
WRITE (*,*) ' Component,option,species: ',COL2,COL3,COL4
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
ENDIF
tl30=' '
TL30=TL2541(1:30)
CALL Ltrim(tl30)
tl30(1:1)=Tl1upcase(tl30(1:1))
tl30(2:2)=Tl1upcase(tl30(2:2))
IF (TL30(2:2).EQ.' ') TL30(3:3)=' '
IF (tl2541(1:1).EQ.'*') THEN
IF (tl2541(1:8).NE.'*CONTROL') THEN
IF (TL2541(2:4).EQ.'EXP') GO TO 999
IF (TL2541(2:8).NE.'GENERAL') STARNUM=STARNUM + 1
! Following is to accomodate files with treatment group
! low in file
IF (STARNUM .EQ. STARTRE+1 .AND. STARNUM .GT. 2) THEN
! Following is necessary to stop entering
! when treatments at end of file
IF (XREADNUM .EQ. 1) THEN
CLOSE (FILENUM)
OPEN (filenum,FILE=filename(1:FILELEN),STATUS='OLD')
DATANUM=0
LINE=0
RETURNUM=0
TR='N'
CTR='N'
STARTCOL=1
ABVLINE=' '
GO TO 8888
ENDIF
ENDIF
IF(TL2541(2:4).EQ.'TRE')THEN
TR='Y'
STARTCOL=5
IF (RNCOL.LE.0) STARTCOL = STARTCOL - 1
IF (SNCOL.LE.0) STARTCOL = STARTCOL - 1
IF (ONCOL.LE.0) STARTCOL = STARTCOL - 1
IF (CNCOL.LE.0) STARTCOL = STARTCOL - 1
IF (STARTRE.EQ.0) STARTRE=STARNUM
ELSEIF(TL2541(2:5).EQ.'GENE')THEN
TR='N'
STARTCOL=1
ELSE
TR='N'
STARTCOL=2
ENDIF
LE=' '
IF(TL2541(2:5).EQ.'GENE')LE(1:3)='000'
IF(TL2541(2:4).EQ.'TRE')LE(1:LEVELLEN)=LEVELSTD(1:LEVELLEN)
IF(TL2541(2:4).EQ.'CUL')LE(1:3)=CU
IF(TL2541(2:5).EQ.'GENO')LE(1:3)=CU
IF(TL2541(2:4).EQ.'FIE')LE(1:3)=FL
IF(TL2541(2:4).EQ.'SOI')LE(1:3)=SA
IF(TL2541(2:4).EQ.'INI')LE(1:3)=IC
IF(TL2541(2:4).EQ.'PLA')LE(1:3)=MP
IF(TL2541(2:4).EQ.'IRR')LE(1:3)=MI
IF(TL2541(2:4).EQ.'FER')LE(1:3)=MF
IF(TL2541(2:4).EQ.'RES')LE(1:3)=MR
IF(TL2541(2:4).EQ.'CHE')LE(1:3)=MC
IF(TL2541(2:4).EQ.'TIL')LE(1:3)=MT
IF(TL2541(2:4).EQ.'ENV')LE(1:3)=ME
IF(TL2541(2:4).EQ.'HAR')LE(1:3)=MH
IF(TL2541(2:4).EQ.'FIL')LE(1:3)=FI
IF(TL2541(2:4).EQ.'DIS')LE(1:3)=DI
IF(TL2541(2:4).EQ.'SIM')THEN
LE(1:3)=SM
IF(SM(1:1).NE.'0')THEN
IF(CTR.EQ.'N')THEN
IF(Ctrflag.NE.'Y') THEN
WRITE(fnumrea,*)' CONTROLS FROM: ',filenew(1:60)
Ctrflag = "Y"
ENDIF
ENDIF
CTR='Y'
ENDIF
ENDIF
IF(TL2541(2:4).EQ.'AUT')LE(1:3)=AM
ENDIF
GO TO 999
ENDIF
IF(tl2541(1:1).EQ.'@')THEN
! Strip off leading @
tl2541(1:1)=' '
! Following code introduced to move header across.
! Maybe necessary in case first column is character field
! eg General section, but not for data fields where
! first column must be numeric!!!
TVI2=0
TVI3=0
DO tvi1=1,30
IF(tl2541(tvi1:tvi1).EQ.' ' .AND. TVI2.GT.0)THEN
TVI3=MIN(10,TVI1-1)
EXIT
ENDIF
IF(tl2541(tvi1:tvi1).NE.' '.AND. TVI2.EQ.0)TVI2=TVI1
ENDDO
TL10(1:(TVI3-TVI2+1))=TL2541(TVI2:TVI3)
DO TVI1=1,TVI3
TL2541(TVI1:TVI1)=' '
ENDDO
TL2541(1:(TVI3-TVI2+1))=TL10(1:(TVI3-TVI2+1))
! Strip out leading periods
ABVLEN=TVILENT(TL2541)
DO TVI1=1,ABVLEN-1
IF(TL2541(TVI1:TVI1+1).EQ.' .')TL2541(TVI1:TVI1+1)=' '
! NEW JULY 05
IF(TL2541(TVI1:TVI1).EQ.'!')TL2541(TVI1:ABVLEN)=' '
ENDDO
IF (ABVLINE(2:30).NE.TL2541(2:30))THEN
ABVLINE(1:1)=' '
ABVLINE=tl2541
ABVSTD=' '
CALL STANDARD(ABVLINE,ABVSTD,'13')
ABVNUM=TVINSTR(ABVSTD)
! NB MAXIMUM NUMBER OF VARIABLES ALONG LINE=40
IF(ABVNUM.GT.40)ABVNUM=40
LINE=1
GO TO 999
ENDIF
ENDIF
DATALINE=tl2541
IF(ABVNUM.EQ.1)THEN
IF(line.EQ.1)THEN
datanum=datanum+1
CALL LTRIM(abvline)
CALL LTRIM(dataline)
DATARRAY(datanum)=abvline(1:6)//' '//dataline(1:247)
LINE=LINE+1
ELSE
CALL LTRIM(dataline)
tvi1=TVILENT(DATARRAY(datanum))
tvi2=TVILENT(dataline)
IF(tvi1+tvi2.GT.241)tvi2=254-tvi1
dn=datanum
DATARRAY(dn)=DATARRAY(dn)(1:tvi1)//' '//dataline(1:tvi2)
ENDIF
GO TO 999
ENDIF
DATASTD=' '
TEXTSTD=' '
IF(TVILENT(abvline).LT.3)THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE(fnumerr,*)' Header line not found! '
WRITE(fnumerr,*)' Possibly wrong file type!'
WRITE(fnumerr,*)' Header line: ',abvline(1:60)
WRITE(fnumerr,*)' Data line : ',dataline(1:60)
WRITE(fnumerr,*)' Text : ',textstd
WRITE(fnumerr,*)' Check READS.OUT for details'
WRITE (*,*) ' Header line not found! '
WRITE (*,*) ' Possibly wrong file type!'
WRITE (*,*) ' Header line: ',abvline(1:60)
WRITE (*,*) ' Data line : ',dataline(1:60)
WRITE (*,*) ' Text : ',textstd
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
IF(MP(1:1).EQ.'0' .AND. MH(1:1).EQ.'0')THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE(fnumerr,*)' Both planting and harvest levels = 0!'
WRITE(fnumerr,*)' Hence no crop nor fallow specified!'
WRITE(fnumerr,*)' Check READS.OUT for details of reads'
WRITE(*,*)' Both planting and harvest levels = 0!'
WRITE(*,*)' Hence no crop nor fallow specified!'
WRITE(*,*)' Program will have to stop'
WRITE(*,*)' Check READS.OUT for details of reads'
CLOSE (fnumerr)
STOP ' '
ENDIF
IF (TVILENT(DATALINE).LT.5) GO TO 999
CALL STANDC(ABVLINE,DATALINE,DATASTD,TEXTSTD,'13')
! Below is for debugging purposes only
! WRITE(fnumrea,*)' ABVLINE ',abvline(1:60)
! WRITE(fnumrea,*)' ABVSTD ',abvstd(1:60)
! WRITE(fnumrea,*)' DATALINE ',dataline(1:60)
! WRITE(fnumrea,*)' DATASTD ',datastd(1:60)
IF(le(1:3).NE.'000')THEN
leveltmp=' '
READ(DATASTD,'(A13)',ERR=7777)leveltmp(1:13)
CALL Ltrim(leveltmp)
IF(leveltmp(1:1).EQ.'0')THEN
leveltmp(1:1)=' '
IF(leveltmp(2:2).EQ.'0')THEN
leveltmp(2:2)=' '
IF(leveltmp(3:3).EQ.'0')THEN
leveltmp(3:3)=' '
ENDIF
ENDIF
ENDIF
CALL Ltrim(leveltmp)
ENDIF
IF(TR.EQ.'Y')THEN
DATAROC=' '
IF(ftype.EQ.'*')THEN
DATAROC(1:52)=DATASTD(1:52)
ELSEIF(ftype.EQ.'$')THEN
IF (RNCOL.GT.0) THEN
READ(DATASTD,'(13X,I13)',ERR=7777)COLRN
IF (COLRN.NE.COL1R)GO TO 999
DATAROC(1:13)=DATASTD(1:13)
DATAROC(14:52)=DATASTD(26:64)
ENDIF
ENDIF
IF (SNCOL.GT.0.AND.COL2.GT.0) THEN
READ(DATAROC,'(13X,I13)',ERR=7777)COL2TMP
IF (COL2TMP.EQ.0)COL2TMP=COL2
IF (COL2TMP.NE.COL2)GO TO 999
ENDIF
IF (ONCOL.GT.0.AND.COL3.GT.0) THEN
READ(DATAROC,'(26X,I13)',ERR=7777)COL3TMP
IF (COL3TMP.EQ.0)COL3TMP=COL3
IF (COL3TMP.NE.COL3)GO TO 999
ENDIF
IF (CNCOL.GT.0.AND.COL4.GT.0) THEN
READ(DATAROC,'(39X,I13)',ERR=7777)COL4TMP
IF (COL4TMP.EQ.0)COL4TMP=COL4
IF (COL4TMP.NE.COL4)GO TO 999
ENDIF
ENDIF
IF (LE .NE. '00') THEN
IF (LE(1:1).EQ.'0') THEN
LE(1:1)=' '
IF (LE(2:2).EQ.'0') LE(2:2)=' ' ! NEW JUL 06
ENDIF
CALL Ltrim(le)
LENTMP=TVILENT(LE)
! Below is for debugging
! Write (fnumrea,*)' Leveltmp ie what read ',leveltmp
! Write (fnumrea,*)' Le ie what needed ',le
IF(LEVELTMP(1:LENTMP).NE.LE(1:LENTMP))GO TO 999
IF(LEVELTMP(LENTMP+1:LENTMP+1).NE.' ')GO TO 999
ENDIF
DO TVI1=1,ABVNUM-(STARTCOL-1)
IF(TVI1.EQ.1)THEN
IF(LINE.EQ.1)THEN
datanums=datanum
ELSE
datanum=datanums
ENDIF
ENDIF
datanum=datanum+1
TVI2=1 + ((STARTCOL-1)*LENSTD) + (TVI1-1)*LENSTD
TVI4=TVI2 + (LENSTD-1)
COEFFC=DATASTD(TVI2:TVI4)
ABVC=ABVSTD(TVI2:TVI4)
! Below are for debugging
! Write(fnumrea,*)' abvnum ',abvnum
! Write(fnumrea,*)' lenstd ',lenstd
! Write(fnumrea,*)' startcol ',startcol
! Write(fnumrea,*)' abvc ',abvc
! Write(fnumrea,*)' tvi2,tvi4 ',tvi2,tvi4
! Write(fnumrea,*)' coeffc ',coeffc
COEFFCTM=COEFFC
CALL LTRIM(COEFFCTM)
IF (TVILENT(COEFFCTM).LT.1)COEFFC='-99 '
CALL LTRIM(TEXTSTD)
IF (TVILENT(TEXTSTD).LT.1)TEXTSTD(1:3)='-99'
COEFFCHK=COEFFCTM(1:4)
IF (LINE.EQ.1) THEN
IF(COEFFCHK.EQ.'TEXT')THEN
DATARRAY(datanum)=abvc//' '//TEXTSTD
ELSE
DATARRAY(datanum)=abvc//' '//coeffc
ENDIF
IF(TVI1.EQ.(ABVNUM-(STARTCOL-1)))LINE=LINE+1
ELSE
LENTMP=TVILENT(DATARRAY(datanum))
IF(COEFFCHK.EQ.'TEXT')THEN
TL2541=DATARRAY(datanum)(1:LENTMP)//' '//TEXTSTD
DATARRAY(datanum)=TL2541
ELSE
TL2541=DATARRAY(datanum)(1:LENTMP)//' '//coeffc
DATARRAY(datanum)=TL2541
ENDIF
ENDIF
IF(ABVC(1:3).EQ.'CU '.OR.ABVC(1:3).EQ.'GE ') CU=COEFFC(1:3)
IF(ABVC(1:3).EQ.'FL ')FL=COEFFC(1:3)
IF(ABVC(1:3).EQ.'SA ')SA=COEFFC(1:3)
IF(ABVC(1:3).EQ.'IC ')IC=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MP '.OR.ABVC(1:3).EQ.'PL ')MP=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MI '.OR.ABVC(1:3).EQ.'IR ')MI=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MF '.OR.ABVC(1:3).EQ.'FE ')MF=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MR '.OR.ABVC(1:3).EQ.'RE ')MR=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MC '.OR.ABVC(1:3).EQ.'CH ')MC=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MT '.OR.ABVC(1:3).EQ.'TI ')MT=COEFFC(1:3)
IF(ABVC(1:3).EQ.'ME '.OR.ABVC(1:3).EQ.'EN ')ME=COEFFC(1:3)
IF(ABVC(1:3).EQ.'ME '.OR.ABVC(1:3).EQ.'EM ')ME=COEFFC(1:3)
IF(ABVC(1:3).EQ.'MH '.OR.ABVC(1:3).EQ.'HA ')MH=COEFFC(1:3)
IF(ABVC(1:3).EQ.'DI '.OR.ABVC(1:3).EQ.'DI ')DI=COEFFC(1:3)
IF(ABVC(1:3).EQ.'SM ')THEN
SM=COEFFC(1:3)
FI=COEFFC(1:3)
ENDIF
IF(ABVC(1:3).EQ.'AM ')AM=COEFFC(1:3)
IF(ABVC(1:3).EQ.'FI ')FI=COEFFC(1:3)
ENDDO
999 CONTINUE
END DO
9996 CONTINUE
! Following is to accomodate files with treatment group
! at the end of the file
IF (STARNUM.EQ.STARTRE .AND. XREADNUM.EQ.1) THEN
CLOSE (FILENUM)
OPEN (filenum,FILE=filename(1:FILELEN),STATUS='OLD')
DATANUM=0
LINE=0
RETURNUM=0
TR='N'
CTR='N'
STARTCOL=1
ABVLINE=' '
GO TO 8888
ENDIF
9999 CONTINUE
CLOSE(filenum)
IF (CTR.EQ.'N')THEN
arg=' '
tvi2=0
tvi3=0
! CALL GETARG (0,arg,arglen)
!portability
CALL GETARG (0,arg)
arglen = len_trim(arg)
DO tvi1=1,arglen
IF (arg(tvi1:tvi1).EQ.SLASH) tvi2=tvi1
IF (arg(tvi1:tvi1).EQ.'.') tvi3=tvi1-1
ENDDO
IF (tvi3.EQ.0) THEN
tvi3=arglen
ENDIF
ctrdirfl=ARG(1:TVI3)//'.CTR'
ctrdirfl = TRIM(ctrdirfl)
! Change control file name from module specific to general
DO L=LEN(CTRDIRFL),1,-1
IF (CTRDIRFL(L:L).EQ.SLASH) EXIT
ENDDO
IF (L.GT.1) THEN
ctrdirfl=CTRDIRFL(1:L-1)//SLASH//'CROPSIM.CTR'
ELSE
ctrdirfl(1:12)='CROPSIM.CTR '
ENDIF
INQUIRE(FILE=ctrdirfl,EXIST=fflag)
IF(.NOT.fflag)THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE (fnumerr,*) ' No control file: ',ctrdirfl(1:60)
WRITE (fnumerr,*) ' Check READS.OUT for details'
WRITE (*,*) ' No control file: ',ctrdirfl(1:60)
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
OPEN(filenum,FILE=ctrdirfl,STATUS='OLD')
IF(Ctrflag.NE.'Y') THEN
WRITE(fnumrea,*)' CONTROLS FROM: ',filenew(1:60)
Ctrflag = "Y"
ENDIF
STARTCOL=2
CTR='Y'
TR='N'
LE='1 '
GO TO 4444
ENDIF
CLOSE(filenum)
IF (DATANUM.LE.0.0)THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE (fnumerr,*) ' Problem reading: ',filename(1:55)
WRITE (fnumerr,*) ' No elements in array!',datarray(1)(1:50)
WRITE (fnumerr,*) ' Check READS.OUT for details'
WRITE (*,*) ' Problem reading: ',filename(1:55)
WRITE (*,*) ' No elements in array!',datarray(1)(1:50)
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
IF (DATANUM.GT.0.AND.DATARRAY(1)(1:6) .EQ. ' ')THEN
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE (fnumerr,*) ' Problem reading: ',filename(1:55)
WRITE (fnumerr,*) ' First array element: ',datarray(1)(1:50)
WRITE (fnumerr,*) ' 2nd array element: ',datarray(2)(1:50)
WRITE (fnumerr,*) ' Number in array: ',datanum
WRITE (fnumerr,*) ' Check READS.OUT for details'
WRITE (*,*) ' Problem reading: ',filename(1:55)
WRITE (*,*) ' First array element: ',datarray(1)(1:50)
WRITE (*,*) ' 2nd array element: ',datarray(2)(1:50)
WRITE (*,*) ' Number in array: ',datanum
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
ENDIF
WRITE(fnumrea,'(A13)')' Data array:'
DO TVI3=1,DATANUM
WRITE(fnumrea,'(I6,A2,A60)')tvi3,' ',datarray(TVI3)(1:60)
ENDDO
abvfile=' '
abvfile(1:10)='DETAIL.CDE'
INQUIRE(FILE=abvfile,EXIST=fflag)
IF(.NOT.fflag)THEN
! CALL GETARG (0,arg,arglen)
!portability
CALL GETARG (0,arg)
arglen = len_trim(arg)
DO tvi1=1,arglen
IF(arg(tvi1:tvi1).EQ.SLASH)tvi2=tvi1
ENDDO
abvfile=ARG(1:TVI2)//'DETAIL.CDE'
INQUIRE(FILE=abvfile,EXIST=fflag)
ENDIF
IF(fflag)THEN
! Read abbreviation file
WRITE(fnumrea,*)' '
WRITE(fnumrea,*)' Reading abbrev file: ',abvfile(1:55)
CALL AMAKEABV(ABVFILE,abvarray,abvsyn)
ELSE
WRITE(fnumrea,*)' '
abvsyn=0
ENDIF
5555 CONTINUE
FILEOLD=' '
FILEOLD=' '
FILEOLD(1:FILELEN)=FILENEW(1:FILELEN)
COL1P=COL1
COL1RP=COL1R
COL2P=COL2
COL3P=COL3
COL4P=COL4
CALL ARAYREAD(CODE,DATARRAY,DATANUM,ABVARRAY,ABVSYN,TXTO)
!WRITE(FNUMREA,*) 'CODE,TXTO ',CODE,TXTO
RETURN
7777 CONTINUE
CALL Getlun('ERROR.OUT',fnumerr)
OPEN(UNIT=fnumerr,FILE='ERROR.OUT')
WRITE(fnumerr,*)' Problem in reading treatments in X-file file!'
WRITE(fnumerr,*)' Original line was: ',dataline(1:50)
WRITE(fnumerr,*)' Standard line was: ',datastd(1:50)
WRITE(fnumerr,*)' Text was: ',textstd
WRITE(fnumerr,*)' Maybe that numbers run together!'
WRITE(fnumerr,*)' Or dots in header line over numeric fields!'
WRITE(fnumerr,*)' Check READS.OUT for details'
WRITE (*,*) ' Problem in reading treatments in X-file file!'
WRITE (*,*) ' Original line was: ',dataline(1:50)
WRITE (*,*) ' Standard line was: ',datastd(1:50)
WRITE (*,*) ' Text was: ',textstd
WRITE (*,*) ' Maybe that numbers run together!'
WRITE (*,*) ' Or dots in header line over numeric fields!'
WRITE (*,*) ' Program will have to stop'
WRITE (*,*) ' Check READS.OUT for details'
CLOSE (fnumerr)
STOP ' '
END
!-----------------------------------------------------------------------
SUBROUTINE XREADC(FILENAME,COL1,COL1R,COL2,COL3,COL4,CODE,charout)
! Returns one character string for particular code
IMPLICIT NONE
CHARACTER (LEN=*) FILENAME, CODE, CHAROUT
CHARACTER (LEN=254) TL2541, TXTO
CHARACTER (LEN=100) CODENEW
!chp 2/23/07 CHARACTER (LEN=20) COEFF
CHARACTER (LEN=50) COEFF
CHARACTER (LEN=1) FOUND
INTEGER TVI1, STARTPOS, ENDPOS
INTEGER LENGTH, TVI3, CODECLEN
INTEGER COL1, COL1R, COL2, COL3, COL4
INTRINSIC LEN
SAVE
CALL XREADT (FILENAME,COL1,COL1R,COL2,COL3,COL4,CODE,TXTO)
CALL LTRIM2(CODE,codenew)
CODECLEN=LEN(CHAROUT)
DO TVI1=1,CODECLEN
CHAROUT(TVI1:TVI1)=' '
ENDDO
DO TVI1=1,20