
'                 *****ICE-EDT*******
' program to correct individual ICES records
' separate routines for master, hydro and chemistry
KEY OFF
DIM hp(4), hl(4), cp(15), cl(15), mp(12), ml(12)
ON ERROR GOTO handle
f$ = COMMAND$
IF f$ = "?" THEN GOSUB info
skp = 1
CLS
IF LEN(f$) < 2 THEN
LOCATE 5, 5: INPUT "Enter ICES file name "; aa$
ELSE
aa$ = f$
END IF
OPEN aa$ FOR RANDOM AS #1 LEN = 82
lnth = FIX(LOF(1) / 82)
FIELD #1, 82 AS a$
IF lnth = 0 THEN
 CLS
 LOCATE 3, 5
 PRINT "File "; aa$; " not available on current directory - run aborted"
 END
 ELSE
 CLS
LOCATE 3, 10: PRINT "File: "; aa$
LOCATE 3, 50: PRINT "No of records: "; lnth
END IF

j = INSTR(aa$, ".")

IF j = 0 THEN
bind$ = aa$
ELSE
bind$ = LEFT$(aa$, j - 1)
END IF

bout$ = bind$ + ".ERR"
bout = 1
OPEN "I", #2, bout$
DATA 28,4,32,4,36,5,58,3
 'field locations for hydro (03) record
FOR i = 1 TO 4
READ hp(i), hl(i)
NEXT i
DATA 28,4,32,4,36,4,40,3,43,3,46,3,49,3,52,3,55,3,58,3
DATA 61,3,64,3,67,3,70,4,74,3
'field locations for chemistry (76) recods

FOR i = 1 TO 15
READ cp(i), cl(i)
NEXT i

DATA 1,2,3,2,5,4,9,4,13,5,18,1,19,3,22,2,24,2,26,2,28,4,65,6
 'master
FOR i = 1 TO 12
READ mp(i), ml(i)
NEXT i
LOCATE 25, 25: PRINT "(Enter -ve record number to end session)";
rec:
LOCATE 9, 5: PRINT STRING$(50, 32);

LOCATE 9, 5: INPUT "Record number to be edited "; recno$
IF UCASE$(LEFT$(recno$, 1)) = "?" AND bout = 1 THEN
LOCATE 5, 1
IF EOF(2) THEN
bout = 10
ELSE
LINE INPUT #2, cor$

PRINT cor$
recno$ = MID$(cor$, 9, 6)
recno = VAL(recno$)
LOCATE 9, 33: PRINT recno
END IF
END IF

IF UCASE$(LEFT$(recno$, 1)) = "R" THEN
recno$ = "": skp = -skp
END IF

recno = VAL(recno$)
IF recno = 0 THEN
recno = recn1 + skp
IF recno = 0 THEN recno = 1
LOCATE 9, 33: PRINT recno
END IF
IF recno > lnth THEN
LOCATE 9, 5: PRINT STRING$(60, 32);
LOCATE 9, 5: PRINT "Not valid record number - press any key to procede "
s$ = INPUT$(1)
LOCATE 9, 5: PRINT STRING$(60, 32): GOTO rec
END IF
IF recno < 0 THEN
 LOCATE 9, 5: PRINT STRING$(60, 32);
 LOCATE 9, 5: PRINT "Editing session ended - goodbye"
 END

END IF

recn1 = recno

IF recno - 1 > 0 AND recno - 1 < lnth THEN
GET #1, recno - 1
 LOCATE 11, 1
 PRINT LEFT$(a$, 80);
END IF

IF recno + 1 <= lnth THEN
 GET #1, recno + 1
 LOCATE 14, 1: PRINT LEFT$(a$, 80);
END IF

IF recno + 2 <= lnth THEN
GET #1, recno + 2
 LOCATE 15, 1: PRINT LEFT$(a$, 80);
END IF
GET #1, recno
COLOR 0, 7: LOCATE 12, 1: PRINT LEFT$(a$, 80); : COLOR 7, 0
IF MID$(a$, 80, 1) = "3" THEN GOTO hyd
IF MID$(a$, 80, 1) = "6" THEN GOTO chem
IF MID$(a$, 80, 1) = "J" THEN GOTO mast

LOCATE 16, 1
PRINT "This is not a valid ICES record type - run aborted"
END

hyd:
LOCATE 17, 1:
COLOR 0, 7: PRINT "Hydro Record    ": COLOR 7, 0
PRINT "Enter <1> depth  <2> temperature  <3> salinity   <4> oxygen"
LOCATE , 30: INPUT s$
sn = VAL(s$)
IF sn <= 0 OR sn > 4 THEN GOTO jmphyd
fst = hp(sn): lst = hl(sn)
GOSUB ed
GET #1, recno
COLOR 0, 7: LOCATE 12, 1: PRINT a$: COLOR 7, 0
LOCATE 13, 1: PRINT STRING$(80, 32);
LOCATE 19, 30: PRINT "     ";
GOTO hyd

ed: ' to edit in change
LOCATE 13, fst, 1
COLOR 0, 7: PRINT STRING$(lst, 32)
LOCATE 13, fst
ss$ = ""
FOR i = 1 TO lst
s$ = INPUT$(1)
IF ASC(s$) > 31 THEN
 IF s$ = "-" OR s$ = "+" THEN
 op = 1: i = i - 1: GOTO OP1
 END IF
IF op = 1 THEN op = 0: GOSUB opnch
PRINT s$;
ss$ = ss$ + s$
ELSE
i = i - 1
OP1:
END IF
NEXT i
COLOR 7, 0
MID$(a$, fst) = ss$
COLOR 0, 7: LOCATE 12, 1: PRINT LEFT$(a$, 80); : COLOR 7, 0
LSET a$ = a$
PUT #1, recno
delay 0.1
RETURN

jmphyd:
LOCATE 13, 1, 0: PRINT STRING$(80, 32);
FOR n = 11 TO 23
LOCATE n, 1: PRINT STRING$(80, 32);
NEXT n
LOCATE 5, 1: PRINT STRING$(80, 32);
GOTO rec

chem:
LOCATE 17, 1
COLOR 0, 7: PRINT "Chemistry Record": COLOR 7, 0
PRINT "Enter <1>  depth      <2>  temperature       <3> salinity   <4> oxygen"
PRINT "      <5>  phosphate  <6>  total phosphorus  <7> silicate   <8> nitrate"
PRINT "      <9>  nitrite    <10> ammonium          <11> total nitrogen"
PRINT "      <12> hydrogen sulphide                  <13> pH        <14> alkalinity"
PRINT "      <15> chlorophyll"
LOCATE , 30: INPUT s$
sn = VAL(s$)
IF sn <= 0 OR sn > 15 THEN GOTO jmphyd
fst = cp(sn): lst = cl(sn)
GOSUB ed
GET #1, recno
COLOR 0, 7: LOCATE 12, 1: PRINT a$: COLOR 7, 0
LOCATE 13, 1: PRINT STRING$(80, 32);
LOCATE 23, 30: PRINT "     ";

GOTO chem

mast:
LOCATE 17, 1
COLOR 0, 7: PRINT "Master Record  ": COLOR 7, 0
PRINT "Enter <1>  country      <2>  ship           <3> station no. <4> latitude"
PRINT "      <5>  longitude    <6>  quadrant       <7> year        <8> month"
PRINT "      <9>  day          <10> time           <11> sounding   <12> fractions"
LOCATE , 30: INPUT s$
sn = VAL(s$)
IF sn <= 0 OR sn > 12 THEN GOTO jmphyd
fst = mp(sn): lst = ml(sn)
GOSUB ed
IF sn < 11 THEN RECMOR = recno: GOSUB morot
GET #1, recno
COLOR 0, 7: LOCATE 12, 1: PRINT a$: COLOR 7, 0
LOCATE 13, 1: PRINT STRING$(80, 32);
LOCATE 21, 30: PRINT "     ";

GOTO mast

opnch: 'convert to opunch charatcter
IF s$ = "0" THEN s$ = "}": GOTO reop
s = ASC(s$): s = s + 25: s$ = CHR$(s)
reop:
RETURN

morot: 'output master corrections to data records

morot1:
RECMOR = RECMOR + 1
IF RECMOR > lnth THEN GOTO ret1
GET #1, RECMOR
IF MID$(a$, 80, 1) = "J" THEN GOTO ret1
MID$(a$, fst) = ss$
LSET a$ = a$
PUT #1, RECMOR
GOTO morot1
ret1:
RETURN

info:
CLS
PRINT "**********************************ICE-EDT**************************************"
PRINT
PRINT "1.     ICE-EDT edits ICES data records without the need of an editor."
PRINT
PRINT "2.     To operate you need to know the record number.  This can be obtained"
PRINT "       either from running TSLOOK (data records) or STASUM (master records)."
PRINT
PRINT "3.     Files of any size, to the limit of your disk space, are accommodated"
PRINT "       Program will abort if record type is not recognized."
PRINT
PRINT "4.     When making corrections to master records, corresponding corrections"
PRINT "       to data records are made automatically."
PRINT
PRINT "5.     If value you wish to enter to a field is larger than the field, this"
PRINT "       requires an 'overpunch' which is generated by a entering a '+' instead "
PRINT "       of the first number. For example 1232 in a field with a width of 3 will"
PRINT "       be entered +232 K32 will appear.  Note that if the + replaces anything"
PRINT "       but the number 1 then the value is too big for the field - R99 should be"
PRINT "       entered."
PRINT
PRINT "6.     Records may be stepped through one at a time by pressing ENTER at "
PRINT "       the record no. prompt.  Press `r' to reverse direction."
COLOR 0, 7
LOCATE , 30: PRINT "press any key to procede";
COLOR 7, 0
s$ = INPUT$(1)
CLS
LOCATE 10, 1
PRINT "7.     For more information contact:"
PRINT
PRINT "                               ICES"
PRINT "                             Pal‘gade 2-4"
PRINT "                          1261 Copenhagen K"
PRINT "                              Denmark"
PRINT "                       (telemail - ICES.DK/omnet)"
PRINT
COLOR 0, 7
LOCATE , 25: PRINT "press any key to procede";
COLOR 7, 0
s$ = INPUT$(1)
IF ASC(s$) = 27 THEN END
RETURN
handle:
IF ERR = 53 AND bout = 1 THEN
bout = 10
RESUME NEXT
END IF

CLS

PRINT "error "; ERR; " encountered"
END

