#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------

#read data frame and meta data
F1 = read($F1, data_type="frame", format="csv"); #new data
M = read($M, data_type="frame", format="csv"); #existing recode maps
specJson1 = $TRANSFORM_SPEC1
specJson2 = $TRANSFORM_SPEC2

#frame indexing
F11 = F1[,1:2];
F12 = F1[,3];
M1 = M[,1:2];
M2 = M[,3];

X1 = transformapply(target=F11, meta=M1, spec=specJson1);
X2 = transformapply(target=F12, meta=M2, spec=specJson2);

X1 = X1 * (X1!=77.7);
X2 = X2 * (X2!=77.7);

F21 = transformdecode(target=X1, meta=M1, spec=specJson1);
F22 = transformdecode(target=X2, meta=M2, spec=specJson2);

#frame cbind
F2 = cbind(F21, F22);

write(F2, $F2);
