示例#1
0
        private void ParseVeryLongStringRecord()
        {
            VeryLongStringRecord vlsr = this.SavFile.VeryLongStringRecord;

            foreach (var item in vlsr.StringLengths)
            {
                int variableIndex = 0;
                //int recordIndex = 0;
                this.VariableIndexByShortName.TryGetValue(item.Key.Trim(), out variableIndex);
                this.Variables[variableIndex].VeryLongStringWidth = Int32.Parse(item.Value.Trim());
            }
        }
示例#2
0
 internal void ReadKnownRecords(int variableCount)
 {
     foreach (var record in this.AllRecords)
     {
         switch (record.SubType)
         {
             case 3:
                 this.MachineIntegerInfo = new MachineIntegerInfoRecord(record);
                 break;
             case 4:
                 this.MachineFloatingPointInfoRecord = new MachineFloatingPointInfoRecord(record);
                 break;
             case 11:
                 this.VariableDisplayParameterRecord = new VariableDisplayParameterRecord(record, variableCount);
                 break;
             case 13:
                 this.LongVariableNamesRecord = new LongVariableNamesRecord(record);
                 break;
             case 14:
                 this.VeryLongStringRecord= new VeryLongStringRecord(record);
                 break;
         }
     }
 }
示例#3
0
        public void WriteFileHeader(SpssOptions options, IEnumerable <Variable> variables)
        {
            _options   = options;
            _compress  = options.Compressed;
            _bias      = options.Bias;
            _variables = variables.ToArray();

            // SPSS file header
            var headerRecords = new List <IRecord>
            {
                new HeaderRecord(options)
            };

            // Process all variable info
            var variableLongNames = new Dictionary <string, string>();
            var veryLongStrings   = new Dictionary <string, int>();
            var displayInfoList   = new List <VariableDisplayInfo>(_variables.Length);

            SetVariables(headerRecords, variableLongNames, veryLongStrings, displayInfoList);

            // Integer & encoding info
            var intInfoRecord = new MachineIntegerInfoRecord(_options.HeaderEncoding);

            headerRecords.Add(intInfoRecord);

            // Integer & encoding info
            var fltInfoRecord = new MachineFloatingPointInfoRecord();

            headerRecords.Add(fltInfoRecord);

            // Variable Display info, beware that the number of variables here must match the count of named variables
            // (exclude the string continuation, include VLS segments)
            var varDisplRecord = new VariableDisplayParameterRecord(displayInfoList.Count);

            for (int index = 0; index < displayInfoList.Count; index++)
            {
                varDisplRecord[index] = displayInfoList[index];
            }
            headerRecords.Add(varDisplRecord);

            // Variable Long names (as info record)
            if (variableLongNames.Any())
            {
                var longNameRecord = new LongVariableNamesRecord(variableLongNames, _options.HeaderEncoding);
                headerRecords.Add(longNameRecord);
            }

            if (veryLongStrings.Any())
            {
                var veryLongStringsRecord = new VeryLongStringRecord(veryLongStrings, _options.HeaderEncoding);
                headerRecords.Add(veryLongStringsRecord);
            }

            // Char encoding info record (for data)
            var charEncodingRecord = new CharacterEncodingRecord(_options.DataEncoding);

            headerRecords.Add(charEncodingRecord);

            // End of the info records
            headerRecords.Add(new DictionaryTerminationRecord());

            // Write all of header, variable and info records
            foreach (var headerRecord in headerRecords)
            {
                headerRecord.WriteRecord(_writer);
            }

            if (_compress)
            {
                _recordWriter = new CompressedRecordWriter(_writer, _bias, double.MinValue);
            }
            else
            {
                throw new NotImplementedException("Uncompressed SPSS data writing is not yet implemented. Please set compressed to true");
            }

            _stringWriter = new StringWriter(_options.DataEncoding, _recordWriter);
        }