Certainly! Here's a FORTRAN IV style program snippet demonstrating trilinear interpolation in the 3D Munsell data grid (Hue, Value, Chroma), using the 1943 renotation data stored as 4-digit BCD integers representing CIE XYZ (Illuminant C assumed). It includes detailed 1970s-style comments indicating how to adjust constants for other illuminants.
Assumptions / Setup:
- We have a discrete 3D table of Munsell data points for hues, values, chromas, each with XYZ stored as 4-digit BCD integers.
- Input: Munsell hue (H), value (V), chroma (C).
- Output: interpolated XYZ tristimulus.
- Uses trilinear interpolation between the 8 surrounding points.
- All arrays and sizes will be small for demonstration.
- Constants related to illuminant can be adjusted in data or coefficients.
PROGRAM MUNSELL_TRILINEAR
C**********************************************************************
C FORTRAN IV (circa 1970) program to perform trilinear interpolation
C of Munsell Renotation 1943 data in Hue, Value, Chroma space.
C
C Input: H, V, C (Hue [0..10), Value [1..9], Chroma [2..10])
C
C Output: interpolated CIE 1931 tristimulus values X, Y, Z
C
C The 1943 Renotation data is stored as 4-digit BCD integers, e.g., 4562 means 0.4562.
C
C Illuminant is assumed C by default; to change illum., update the XYZ dataset
C or apply chromatic adaptation factors here.
C
C**********************************************************************
IMPLICIT NONE
INTEGER NHUE, NVAL, NCHR
PARAMETER (NHUE=3, NVAL=3, NCHR=3)
REAL H, V, C
REAL X, Y, Z
INTEGER IERR
INTEGER XDATA(NHUE,NVAL,NCHR)
INTEGER YDATA(NHUE,NVAL,NCHR)
INTEGER ZDATA(NHUE,NVAL,NCHR)
REAL HUE_ARR(NHUE), VALUE_ARR(NVAL), CHR_ARR(NCHR)
REAL W_H(2), W_V(2), W_C(2)
INTEGER H1, H2, V1, V2, C1, C2
REAL X000, X001, X010, X011, X100, X101, X110, X111
REAL Y000, Y001, Y010, Y011, Y100, Y101, Y110, Y111
REAL Z000, Z001, Z010, Z011, Z100, Z101, Z110, Z111
C Sample Munsell Hue degrees corresponding to indices.
C Note: Typically, Munsell hue axis runs 0-10 per hue sector; here simplified.
DATA HUE_ARR /5.0, 15.0, 25.0/
DATA VALUE_ARR /2.0, 5.0, 8.0/
DATA CHR_ARR /2.0, 6.0, 10.0/
C Sample 4-digit BCD encoded CIE XYZ values for 8 corners of cube
C Values fictional and simplified for demonstration.
DATA XDATA / 4562,4620,4685, 4700,4750,4820, 4800,4850,4900 /
DATA YDATA / 5321,5387,5450, 5500,5600,5680, 5750,5800,5900 /
DATA ZDATA / 3210,3265,3320, 3350,3400,3500, 3550,3600,3650 /
C Assume input Munsell:
H = 10.0 ! Example: hue=10 (degrees)
V = 4.0 ! Value level chosen between 2 and 5
C = 4.0 ! Chroma level between 2 and 6
CALL INTERP_TRILINEAR(H, V, C, XDATA, YDATA, ZDATA, HUE_ARR, VALUE_ARR, CHR_ARR, NHUE, NVAL, NCHR, X, Y, Z, IERR)
IF (IERR .NE. 0) THEN
PRINT *, 'Input out of range or interpolation error.'
STOP
ENDIF
PRINT *, 'Input Munsell H=',H,' V=',V,' C=',C
PRINT '(A,F7.4)', 'Interpolated X=', X
PRINT '(A,F7.4)', 'Interpolated Y=', Y
PRINT '(A,F7.4)', 'Interpolated Z=', Z
STOP
END
C**********************************************************************
SUBROUTINE INTERP_TRILINEAR(H, V, C, XDATA, YDATA, ZDATA, HUE_ARR, VALUE_ARR, CHR_ARR,
& NH, NV, NC, X, Y, Z, IERR)
C
C Perform trilinear interpolation of XYZ in the grid defined
C by discrete arrays HUE_ARR, VALUE_ARR, CHR_ARR, and corresponding
C BCD-coded data arrays XDATA, YDATA, ZDATA.
C
C Assumes ordered arrays HUE_ARR(NH), VALUE_ARR(NV), CHR_ARR(NC).
C
C Input:
C H, V, C - target Munsell coordinates (Hue, Value, Chroma)
C XDATA, YDATA, ZDATA - integer BCD encoded XYZ data arrays
C HUE_ARR, VALUE_ARR, CHR_ARR - reference tables for axis points
C NH,NV,NC - sizes of each dimension
C
C Output:
C X, Y, Z - interpolated tristimulus values (floating point)
C IERR - error flag (0=success)
C
C Constants controlling illuminant can be edited by changing
C - The data tables for XDATA, YDATA, ZDATA (if Illuminant changes)
C - Or by applying chromatic adaptation to X,Y,Z after interpolation.
C**********************************************************************
IMPLICIT NONE
INTEGER NH, NV, NC
INTEGER XDATA(NH,NV,NC), YDATA(NH,NV,NC), ZDATA(NH,NV,NC)
REAL HUE_ARR(NH), VALUE_ARR(NV), CHR_ARR(NC)
REAL H, V, C
REAL X, Y, Z
INTEGER IERR
INTEGER H1,H2,V1,V2,C1,C2
REAL DH, DV, DC
REAL WX(2), WV(2), WC(2)
REAL XD(2,2,2), YD(2,2,2), ZD(2,2,2)
INTEGER I,J,K
REAL XC, YC, ZC
C Local variables for BCD decode
REAL FUNCTION BCD_DECODE(BCD)
INTEGER BCD
IERR = 0
C
C Find bracketing indices for H (Hue)
CALL FIND_BRACKET(H, HUE_ARR, NH, H1, H2, DH)
IF (H1 .LT. 1 .OR. H2 .GT. NH) THEN
IERR = 1
RETURN
ENDIF
C For V (Value)
CALL FIND_BRACKET(V, VALUE_ARR, NV, V1, V2, DV)
IF (V1 .LT. 1 .OR. V2 .GT. NV) THEN
IERR = 1
RETURN
ENDIF
C For C (Chroma)
CALL FIND_BRACKET(C, CHR_ARR, NC, C1, C2, DC)
IF (C1 .LT. 1 .OR. C2 .GT. NC) THEN
IERR = 1
RETURN
ENDIF
C
C Calculate interpolation weights (fraction along each axis)
WX(1) = 1.0 - DH
WX(2) = DH
WV(1) = 1.0 - DV
WV(2) = DV
WC(1) = 1.0 - DC
WC(2) = DC
C
C Fetch BCD data for the 8 corner points and decode to floats
DO I = 1, 2
DO J = 1, 2
DO K = 1, 2
XD(I,J,K) = BCD_DECODE( XDATA(H1+I-1, V1+J-1, C1+K-1) )
YD(I,J,K) = BCD_DECODE( YDATA(H1+I-1, V1+J-1, C1+K-1) )
ZD(I,J,K) = BCD_DECODE( ZDATA(H1+I-1, V1+J-1, C1+K-1) )
ENDDO
ENDDO
ENDDO
C
C Perform trilinear interpolation for X, Y, Z separately
XC = 0.0
YC = 0.0
ZC = 0.0
DO I = 1, 2
DO J = 1, 2
DO K = 1, 2
XC = XC + WX(I)*WV(J)*WC(K)*XD(I,J,K)
YC = YC + WX(I)*WV(J)*WC(k)*YD(I,J,K)
ZC = ZC + WX(I)*WV(J)*WC(k)*ZD(I,J,K)
ENDDO
ENDDO
ENDDO
X = XC
Y = YC
Z = ZC
RETURN
END
C**********************************************************************
SUBROUTINE FIND_BRACKET(VAL, ARRAY, N, IDX1, IDX2, FRAC)
C Find indices IDX1 and IDX2 in ARRAY bracketing VAL,
C and fraction FRAC of VAL between these two points.
C
REAL VAL
REAL ARRAY(*)
INTEGER N, IDX1, IDX2
REAL FRAC
INTEGER I
IF (VAL .LE. ARRAY(1)) THEN
IDX1 = 1
IDX2 = 1
FRAC = 0.0
RETURN
ENDIF
IF (VAL .GE. ARRAY(N)) THEN
IDX1 = N
IDX2 = N
FRAC = 0.0
RETURN
ENDIF
DO 20 I = 1, N-1
IF (VAL .GE. ARRAY(I) .AND. VAL .LE. ARRAY(I+1)) THEN
IDX1 = I
IDX2 = I + 1
FRAC = (VAL - ARRAY(I)) / (ARRAY(I+1) - ARRAY(I))
RETURN
ENDIF
20 CONTINUE
C Should never reach here
IDX1 = 1
IDX2 = 1
FRAC = 0.0
RETURN
END
C**********************************************************************
REAL FUNCTION BCD_DECODE(BCD)
C Decode 4-digit integer BCD into float with decimal assumed after 1st digit
C e.g. 4562 -> 0.4562
INTEGER BCD
INTEGER D1,D2,D3,D4
D1 = BCD / 1000
D2 = (BCD / 100) - D1 * 10
D3 = (BCD / 10) - (BCD/100)*10
D4 = BCD - (BCD / 10)*10
BCD_DECODE = D1*0.1 + D2*0.01 + D3*0.001 + D4*0.0001
RETURN
END
Explanation of the key parts:
-
Data Input: XDATA, YDATA, ZDATA are integer arrays holding 4-digit BCD versions of the renotation data, i.e., stored as integers like 4562 meaning 0.4562 floating.
-
Bracketing: The FIND_BRACKET subroutine finds the two discreet data points bounding the input along each axis and the fractional distance between them.
-
Weights: Computed as complement/fraction for all 3 axes for trilinear interpolation.
-
Interpolation: Standard trilinear interpolation combines the 8 corner values weighted by fractions.
-
BCD decoding: Each corner's BCD value is decoded into a floating-point number before interpolation.
Where to adapt for illuminant:
In the 1970s, data might only be available for a particular Illuminant (e.g. C). To adapt for other illuminants (e.g., Illuminant A, D65):
-
Replace the entire XDATA,YDATA,ZDATA with renotation data recalculated for the desired illuminant.
-
Chromatic adaptation transform: Apply a von Kries or Bradford chromatic adaptation to the interpolated XYZ values after computation, using constants derived from the source and target illuminants.
-
Scaling constants or white point normalization may be applied in post-processing.
Comments in code might say:
C To adapt for other illuminants than Illuminant C:
C - Use renotation tables generated/supported for the desired illuminant.
C - Alternatively, apply chromatic adaptation matrix to interpolated XYZ here.
C - White-point references and constants may be adjusted accordingly.
Summary
This code snippet demonstrates a core 1970 FORTRAN style trilinear interpolation method between discrete Munsell renotation samples stored in BCD integers, producing XYZ under Illuminant C by default.
You can build on this pattern for larger tables, different illuminants, or further color space conversions.
If you would like, I can draft the later steps, such as conversions from XYZ to xyY or RGB (using 1970-era formulas), or implement chromatic adaptation matrices in FORTRAN style too.