Beispiel #1
0
 public object this[Variable variable]
 {
     get
     {
         return this[variable.Index];
     }
 }
Beispiel #2
0
        protected List <SpssLib.SpssDataset.Variable> SpssVars(DataTable dt_dict)
        {
            List <SpssLib.SpssDataset.Variable> vars = new List <SpssLib.SpssDataset.Variable>();

            foreach (DataRow row in dt_dict.Rows)
            {
                string   varname  = row["varname"].ToString();
                string   varlabel = row["FieldLabel"].ToString();
                DataType datatype = GetSPSSDataType(row["FieldDataType"].ToString());

                SpssLib.SpssDataset.Variable var = SpssVar(varname, varlabel, datatype, null);
            }

            return(vars);
        }
Beispiel #3
0
        protected SpssLib.SpssDataset.Variable SpssVar(string fldname, string label, DataType datatype, Dictionary <double, string> vallabels)
        {
            DataType dtype = new DataType();


            SpssLib.SpssDataset.Variable var = new SpssLib.SpssDataset.Variable(fldname);

            var.PrintFormat      = new OutputFormat(FormatType.F, 8, 2);
            var.WriteFormat      = new OutputFormat(FormatType.F, 8, 2);
            var.Type             = datatype;
            var.Width            = 10;
            var.MissingValueType = MissingValueType.NoMissingValues;
            var.Label            = label;
            if (vallabels != null)
            {
                var.ValueLabels = vallabels;
            }

            return(var);
        }
        private Variable GetVariable(int variableIndex, int dictionaryIndex, FileParser.MetaData metaData)
        {
            var variable = new Variable();
            variable.Index = variableIndex;

            // Get variable record data:
            var variableRecord = metaData.VariableRecords[dictionaryIndex];
            variable.ShortName = variableRecord.Name;
            variable.Label = variableRecord.HasVariableLabel ? variable.Label = variableRecord.Label : null;
            foreach (var missing in variableRecord.MissingValues)
            {
                variable.MissingValues.Add(missing);
            }
            variable.PrintFormat = variableRecord.PrintFormat;
            variable.WriteFormat = variableRecord.WriteFormat;
            variable.Type = variableRecord.Type == 0 ? DataType.Numeric : DataType.Text;
            if (variable.Type == DataType.Text)
            {
                variable.TextWidth = variableRecord.Type;
            }

            // Get value labels:
            // ここってdictionaryIndexで検索していたけど、1から始まるindexなので+1した(ずれていた)。
            var valueLabelRecord = (from record in metaData.ValueLabelRecords where record.Variables.Contains(dictionaryIndex + 1) select record).FirstOrDefault();

            if (valueLabelRecord != null)
            {
                foreach (var label in valueLabelRecord.Labels)
                {
                    variable.ValueLabels.Add(BitConverter.ToDouble(label.Key, 0), label.Value);
                }
            }

            // Get display info:
            //ここのヌルチェックがなくて落ちていた。
            if (metaData.InfoRecords.VariableDisplayParameterRecord != null)
            {
                var displayInfo = metaData.InfoRecords.VariableDisplayParameterRecord.VariableDisplayEntries[variableIndex];
                variable.Alignment = displayInfo.Alignment;
                variable.MeasurementType = displayInfo.MeasurementType;
                variable.Width = displayInfo.Width;
            }
            // Get (optional) long variable name:
            if (metaData.InfoRecords.LongVariableNamesRecord != null)
            {
                var longNameDictionary = metaData.InfoRecords.LongVariableNamesRecord.LongNameDictionary;
                if (longNameDictionary.ContainsKey(variable.ShortName))
                {
                    variable.Name = longNameDictionary[variable.ShortName].Trim();
                }
                else
                {
                    variable.Name = variable.ShortName.Trim();
                }
            }
            else
            {
                variable.Name = variable.ShortName.Trim();
            }
            return variable;
        }