public void TestWriteNumbers()
        {
            var filename = @"C:\Tests\testWriteNumbers.sav";

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                var variable1 = new Variable
                {
                    Label       = "The variable Label",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "Label for 1" },
                        { 2, "Label for 2" },
                    },
                    Name             = "avariablename_01",
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = 1
                };
                variable1.MissingValues[0] = 999;
                var variable2 = new Variable
                {
                    Label       = "Another variable",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "this is 1" },
                        { 2, "this is 2" },
                    },
                    Name             = "avariablename_02",
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = 1
                };
                variable2.MissingValues[0] = 999;
                var variables = new List <Variable>
                {
                    variable1,
                    variable2
                };

                var options = new SpssOptions();

                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    var newRecord = writer.CreateRecord();
                    newRecord[0] = 15d;
                    newRecord[1] = 15.5d;
                    writer.WriteRecord(newRecord);
                    newRecord    = writer.CreateRecord();
                    newRecord[0] = null;
                    newRecord[1] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }
        }
Exemple #2
0
        internal HeaderRecord(SpssOptions options)
        {
            var assemblyName = GetType().Assembly.GetName();

            ProductName  = ("@(#) SPSS DATA FILE " + assemblyName.Name + " " + assemblyName.Version);
            LayoutCode   = 2;
            Compressed   = options.Compressed;
            Bias         = options.Bias;
            CasesCount   = options.Cases;
            CreationDate = DateTime.Now.ToString("dd MMM yy", CultureInfo.InvariantCulture.DateTimeFormat);
            CreationTime = DateTime.Now.ToString("HH:mm:ss", CultureInfo.InvariantCulture.DateTimeFormat);
            FileLabel    = options.Label ?? string.Empty;
            Padding      = string.Empty;
        }
Exemple #3
0
        public void TestWriteString()
        {
            var filename = @"testWriteString.sav";

            var varString1 = new Variable("stringvar_01")
            {
                Label     = "This is a string variable",
                Type      = DataType.Text,
                TextWidth = 500,
            };

            var variable1 = new Variable("avariablename_01")
            {
                Label       = "The variable Label",
                ValueLabels = new Dictionary <double, string>
                {
                    { 1, "Label for 1" },
                    { 2, "Label for 2" },
                },
                PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                Type             = DataType.Numeric,
                Width            = 10,
                MissingValueType = MissingValueType.OneDiscreteMissingValue,
                MissingValues    = { [0] = 999 }
            };

            var varString = new Variable("stringvar_02")
            {
                Label       = "This is a string variable",
                PrintFormat = new OutputFormat(FormatType.A, 60),
                WriteFormat = new OutputFormat(FormatType.A, 60),
                Type        = DataType.Text,
                Width       = 60,
                TextWidth   = 60,
            };

            var variable2 = new Variable("avariablename_02")
            {
                Label       = "Another variable",
                ValueLabels = new Dictionary <double, string>
                {
                    { 1, "this is 1" },
                    { 2, "this is 2" },
                },
                PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                Type             = DataType.Numeric,
                Width            = 10,
                MissingValueType = MissingValueType.OneDiscreteMissingValue,
                MissingValues    = { [0] = 999 }
            };

            var variables = new List <Variable>
            {
                varString1,
                variable1,
                varString,
                variable2
            };

            var options = new SpssOptions();

            var data = new[]
            {
                new object[]
                {
                    // Exactly 500
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis neque eget neque semper, vitae lacinia libero rhoncus. Mauris tellus lorem, imperdiet vitae bibendum ac, rhoncus nec dui. Donec in consequat leo. Nunc at ante nec metus aliquam hendrerit quis a augue. Suspendisse faucibus nunc mauris, sed faucibus mauris bibendum et. Sed auctor, dolor non luctus interdum, tellus neque auctor dui, sit amet luctus neque risus vel nibh. Nullam ornare ultricies quam. Vestibulum eget erat sit nullam.",
                    15d,
                    "adsf ñlkj",
                    15.5d
                },
                new object[]
                {
                    // 600, should be cut to 500
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In elementum sed justo eu pulvinar. Maecenas non laoreet justo, eget ultrices dolor. Praesent sit amet sodales erat. Proin condimentum, metus et pulvinar ultrices, massa erat hendrerit lorem, vel mattis dolor ante id sem. Fusce laoreet mi tortor, ut interdum ipsum laoreet vel. Nullam lorem mauris, vulputate luctus velit placerat, scelerisque vehicula elit. Phasellus gravida ante quis augue convallis venenatis. Integer bibendum purus non felis interdum, quis fermentum tellus sodales. Fusce commodo ultrices leo ut vulputate. Quisque metus.",
                    150d,
                    null,
                    150d
                },
                new object[]
                {
                    // 255 chars
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis neque eget neque semper, vitae lacinia libero rhoncus. Mauris tellus lorem, imperdiet vitae bibendum ac, rhoncus nec dui. Donec in consequat leo. Nunc at ante nec metus aliquam hendrerit_",
                    null,
                    // 300 chars, should be cut to 60
                    "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.",
                    200d
                }
            };

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    // If the data record is not readly available, you can use: object[] newRecord = writer.CreateRecord();
                    foreach (var row in data)
                    {
                        writer.WriteRecord(row);
                    }
                    writer.EndFile();
                }
            }

            ReadFile(filename, out int varCount, out int rowCount);

            Assert.AreEqual(varCount, 4, "Variable count does not match");
            Assert.AreEqual(rowCount, 3, "Rows count does not match");
        }
Exemple #4
0
        public void TestWriteDoubleLongStringVar()
        {
            var filename = @"testWriteDoubleLongString.sav";

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                var var1 = new Variable("stringvar_01")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 5000
                };

                var var2 = new Variable("stringvar_02")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var3 = new Variable("stringvar_03")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var4 = new Variable("stringvar_04")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 50
                };

                var var5 = new Variable("stringvar_05")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 4,
                    TextWidth = 4
                };

                var var6 = new Variable("LIKES")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 255),
                    WriteFormat = new OutputFormat(FormatType.A, 255),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 1026
                };


                var variables = new List <Variable>
                {
                    var1,
                    var2,
                    var3,
                    var4,
                    var5,
                    var6
                };

                var options = new SpssOptions();

                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    object[] newRecord = writer.CreateRecord();
                    newRecord[0] = "test";
                    newRecord[1] = "test";
                    newRecord[2] = "Lorem";
                    //newRecord[3] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }


            FileStream readFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read,
                                                       FileShare.Read, 2048 * 10, FileOptions.SequentialScan);

            TestSpssReader.ReadData(readFileStream, out int varCount, out int rowCount);

            Assert.AreEqual(varCount, 6, "Variable count does not match");
            Assert.AreEqual(rowCount, 1, "Rows count does not match");
        }
Exemple #5
0
        public void TestWriteLongWeirdString()
        {
            var filename = @"testTestWriteLongWeirdString.sav";

            var varString1 = new Variable("stringvar_01")
            {
                Label     = "This is a string variable",
                Type      = DataType.Text,
                TextWidth = 5000,
            };

            var variable1 = new Variable("avariablename_01")
            {
                Label       = "The variable Label",
                ValueLabels = new Dictionary <double, string>
                {
                    { 1, "Label for 1" },
                    { 2, "Label for 2" },
                },
                PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                Type             = DataType.Numeric,
                Width            = 10,
                MissingValueType = MissingValueType.OneDiscreteMissingValue,
                MissingValues    = { [0] = 999 }
            };

            var varString = new Variable("stringvar_02")
            {
                Label           = "This is a string variable",
                Type            = DataType.Text,
                TextWidth       = 60,
                Alignment       = Alignment.Centre,
                MeasurementType = MeasurementType.Ordinal
            };

            var variable2 = new Variable("avariablename_02")
            {
                Label       = "Another variable",
                ValueLabels = new Dictionary <double, string>
                {
                    { 1, "this is 1" },
                    { 2, "this is 2" },
                },
                PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                Type             = DataType.Numeric,
                Width            = 10,
                MissingValueType = MissingValueType.OneDiscreteMissingValue,
                MissingValues    = { [0] = 999 }
            };

            var variables = new List <Variable>()
            {
                varString1,
                variable1,
                varString,
                variable2
            };

            var options = new SpssOptions();

            using (FileStream writeFileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                using (var writer = new SpssWriter(writeFileStream, variables, options))
                {
                    var newRecord = writer.CreateRecord();
                    // Exactly 500
                    newRecord[0] =
                        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis neque eget neque semper, vitae lacinia libero rhoncus. Mauris tellus lorem, imperdiet vitae bibendum ac, rhoncus nec dui. Donec in consequat leo. Nunc at ante nec metus aliquam hendrerit quis a augue. Suspendisse faucibus nunc mauris, sed faucibus mauris bibendum et. Sed auctor, dolor non luctus interdum, tellus neque auctor dui, sit amet luctus neque risus vel nibh. Nullam ornare ultricies quam. Vestibulum eget erat sit nullam.";
                    newRecord[1] = 15d;
                    newRecord[2] = "L߀rêϻ iρѕüm ԁòɭor ѕìt ρoѕùerê.";
                    newRecord[3] = 15.5d;
                    writer.WriteRecord(newRecord);

                    newRecord = writer.CreateRecord();

                    newRecord[0] =
                        "Lòrêm ìpsúϻ dòlòr ѕït àϻet, c߀ԉsèctetûr aᏧìpiѕciԉg elìt. Vëѕtìƅùɭuϻ ac ipsum ɭëctùѕ. Craѕ vìtaè ѵïѵërrä tortòr. Nunc vìtàë eѕt värìúѕ, ɭãorèët tòrt߀r á, ïɑcûlíѕ sãpíen. Phɑsêɭɭus metus ϻáɢлå, fêûɢíàt ä ɋùåϻ âɭïqúám, ѕcëlérïѕqüé mòlêѕtiè sɑpiëԉ. Ut núлc ԉïѕl, éffìcïtúr vel curѕûѕ à, ãɭiqûãϻ ѕit áϻet úrnå. Maúrïs conԁìϻentùm ornãrë pùrús, ρհäretrã bɭãлԁít ɭê߀ c߀ϻϻòᏧ߀ eû. Mãúrìs égët mäѕѕä nèc ѕéϻ vòlútρɑt elëϻentúϻ ɋûis ɑ dùï. Curåƅìtûr iԉterᏧùϻ pùlѵíԉàr fèɭïѕ, èú fåcïlísis ɭëctûѕ ԁàρìƅüs sit àϻét. Crãѕ témpüs ëlëϻéлtüm mëtùs. Fúsce ëх íρsûϻ, fríԉgílɭâ àt léctùs ét, lùctùѕ pɭɑcérat ρùrûѕ. Måéceлaѕ nec lèò ɭeò. Víѵàϻus ѵüɭpútɑtë lìƅèro êɢêt ѵ߀ɭútpat ѵòɭùtpàt. Aëлèàԉ âc dïctúm mëtuѕ, лêc c߀лdìmëлtum áԉte. M߀rbï ɭãcüѕ ríѕûs, imρërᏧíêt volütpát léo л߀л, lúctùs tëmpús ߀rcí. D߀ԉêc äc aɭiquɑm elit. Cúráƅítur tíncíԁúnt åԉté ϻollís, ѕòԁálëѕ ëlit ëǥèt, pëɭléntèѕɋûe äùgúé. Nuɭɭâ èt éХ fèɭìs. Fuscë ɭoƅortìs l߀reϻ ԉec neqûe ùltrícés, á ƃɭâԉdít tùrρïѕ còԉѕèɋùät. Séԁ èü cürsûs åügúè, iᏧ c߀лѕëɋuãt Ꮷoɭ߀r. Seԁ ɑccumsâԉ, doɭ߀r iԉterdüm mòɭëѕtíê åliqúèt, riѕus ԉìsɭ iåcùlïs ántè, ԉ߀л ԁïǥԉíssíϻ ϻâɢnå ԉìbɦ ɑt ärcú. Ut éffïcitûr ét ԁìàϻ vitáê ԁìctùϻ. Etiaϻ üt ɑüct߀r nïƃh. Iлtêɢér èrât sâρiéԉ, prètìuϻ á êst ԉëc, ornɑrê lûctûѕ лìsl. Pêlɭëԉtèѕɋuë ϻàlesüáԁa díctûm èԉím íԁ áɭìqüèt. SusρêԉᏧiѕse sít ãmët ߀rnåre rïѕus, vel íácùɭìs lɑcúѕ. Pհäѕellûs յûsto mètúѕ, mäxïϻûѕ âc ρretíuϻ ѵêl, sãgìttìѕ faúciƃuѕ l߀rêϻ. Vïѵãϻüs qúïs conѵäɭlis ϻï, ɋuïs fèùɢïåt лìsì. Pháѕêɭɭûѕ trïѕtiqùê ɭɑcûѕ äc ϻòɭestïé mälésúadâ. Qûìsqûê ρrëtìum, níbh êgét rütrùϻ ѕolɭïcitüᏧíԉ, métûѕ lïƃër߀ fáücíƅuѕ ɭectúѕ, élemèԉtüϻ ρortɑ ɭïǥûlɑ dol߀r pûlѵïлɑr èr߀s. Aéԉêɑл nèc rütrûϻ pûruѕ. Nɑm vèl ԉìsí ϻàgnà. Cùräƃìtur ut ρ߀sûèrè յüѕtò. Sèԁ effìcìtûr p߀rttïtòr dïäϻ, ä fèûgíât vëɭít ïԉtérᏧüm éü. SêᏧ ut còлѕéqúat ɭãcûs. Iԉ ïn c߀ԉᏧïϻéлtum tûrpìs, sìt aϻet c߀ngûé erät. Qùìѕɋûe ƃɭàԉᏧit làcùѕ iϻpêrᏧìét ѕàpíeл ƅíƅéndüm ԁìɢniѕsím. Mòrbi bïbèлdüm ѵ߀lùtρät ԉíѕl. Sëd ùltrïcíeѕ teɭlûѕ nòԉ ɋûäm âûctòr, seᏧ ρɭacèrât lìgûlɑ temρòr. Mòrƃì imρérᏧièt coԉǥùé qûáϻ, ïᏧ pulѵíлar ԁüi. Pélɭêԉtêѕqúë mòlêstïè êХ t߀rtor. Mäürìs ѵìtâê rïѕùs ìd ߀rcï mâttis fiлïƅüѕ. Dònéc cûrsûѕ soɭlícìtuԁïԉ лïsl at sêϻpër. Doлèc ɦêndrërit ɭêctüѕ á líberò ϻɑɭèѕuãdâ, ѕit ɑϻét ϻáӽìmüѕ jùѕt߀ ültricêѕ. Vëstïƃùlûm ɭiƅerò nísí, vèstïƃûlum äc coԉѕêqúãt åc, còԉѕèctêtûr л߀ԉ eros. Mäûris åɭíɋûåm àrcü cùrѕûѕ, heԉᏧrërït ìρsùϻ èü, ѵëɦïcüɭá fèɭìs. Phàsèllûs ρosuère teɭɭús eɢèt ɭïǥúlã måttïѕ, ѕit àmét viѵerrå ùrnɑ ãliɋûêt. Pélleлtëѕqûë ìԁ tòrtor aлtè. Aeлèãԉ ѕ߀llicìtüᏧïn véɭit ìᏧ pëlɭeԉtësɋué éùïsϻ߀ԁ. Nùɭɭâ gráѵìdá tìԉciԁúԉt ùrлá, ѕëԁ còлԁïméлtûm maùríѕ trìstíɋúé ut. Cräѕ mɑttïѕ fêɭïs ɋûïs cursus íϻρerԁiet. Iлtegèr c߀лgùë låcìлia tûrpís ùt ѵeհïcuɭa. Dùís lëctus úrnå, ѕéϻper å ѵíѵërrà ïᏧ, ϻãleѕuâᏧå ût ëԉïm. Aeԉêãԉ rïsuѕ êrät, èǥéstâs a l߀ƃòrtís ín, ɑɭíɋûët finïƅùѕ sëm. Vëѕtïƃulúϻ հëԉԁrérït éԉim ԉèc äùctor Ꮷïǥлìѕѕím. Nam ìàcúɭïs ɭäcùѕ eǥét ԁui orлáre ïãcûɭïs. Ut íᏧ ѵârïúѕ лëqúè, êgét tëϻp߀r fèliѕ. Sêd ρòrttitor ѵíѵérrà léò sít åmèt ϻ߀ɭɭïs. Núllä comϻ߀ԁ߀ èffícìtûr ԉïѕl. Donec vârìüs ԉulɭá ѕït ɑϻét ѕàpìëл ԁiɢлísѕíϻ, ìԉ uɭɭɑmcorper òᏧío seϻρér. M߀rƃi c߀mϻoԁ߀ veɭït ùt c߀лᏧíϻeԉtûm tíncìԁùлt. Veѕtïbülûm cursüѕ dictûϻ fêlïѕ vëɭ fìлíƃus. Clasѕ àptênt tåcìtí ѕòcïòsqü ãᏧ lít߀ra torquent pêr c߀nüƃíɑ nostrâ, per ìncèpt߀ѕ hiϻeԉáé߀ѕ. Susρéndïѕsé ût ԉüлc uɭtricêѕ maǥԉã vúɭpûtätë pharétrɑ non lâcínïâ dïâϻ. Pèɭleԉtéѕɋúe ǥràѵídã sodâléѕ sèm, ët coԉgûë лùllà c߀nѕèctëtúr ɋûìs. Cúrãƃítûr sùѕcïρït àrcù rísùѕ, ԉoл còϻmoᏧo ɋùâm êɭeíféԉԁ ѵêɭ. Maêcéԉàѕ m߀ɭɭíѕ núɭlä àc ɭòbòrtís fïлïƃüs. Vivãϻúѕ лec äԉte ѕâρíéԉ. Sëԁ scélërísqüe mágna ѕëm, ëǥèt volutpät êx trístiqùê ïԁ. Intèɢer eléifënԁ ɭɑòrêet tòrtor, èt ѕodaɭès лûɭlá ƃlɑԉdit seᏧ. Qùïѕɋúê eü ρùrûs ѵòlütpat, maɭêsüaᏧá odïò nëc, c߀nԁïϻëԉtûm nìsi. Vêstìƅùɭùϻ ѕ߀ɭɭicìtùdíԉ eròѕ ëget úllamcòrρer poѕuere. Intêgér êffícítûr åúctor alïqûèt. Nuԉc ѕcêlèrísqüe ѕït âmët èɭìt ëgét rútrúm. Péɭɭëntêsɋuë vítâê prètiüm ϻëtüs, at auctor êӽ. Qüiѕɋùê ϻëtüs mâgлa, Ꮷàρiƅuѕ àc séϻ ùt, ɭàciԉiɑ pհɑretrɑ ɋuàϻ. Pëɭɭêлtësɋüé ëúìsm߀ԁ ɭòƅortis ѵèlit, ìԁ scèɭérisquè qúaϻ áccüϻsãn èü. Sed ín libêrò ɭuctùs, ѕêmρèr lè߀ at, ϻɑttìѕ ɭéctüs. Duïѕ eleméлtúm, lëctüѕ ѕëԁ sèϻpér coԉvâɭlïѕ, Ꮷûí ëx ùllɑϻc߀rρêr mɑúriѕ, vëɭ süscïρít éԉïϻ èr߀ѕ ultrïcès ѕàρïéл. Nûԉc éffìcïtûr léò ëù vìѵérrá moɭlíѕ. Etìäϻ Ꮷáρïbüs ɭobòrtïs ѵuɭρütátë. Pèlɭèntësɋùê at commoԁò íρѕúm. Düíѕ téϻpûs ѵéհïcúɭɑ êrɑt ɭuctüs ëɭëïfëлԁ. Sed íd vëstibùlum ùrԉɑ. Fuscê rutrûϻ, vêlít äc tèϻρor måléѕûãᏧá, télɭüs лìѕí fåúcìƅuѕ ϻåǥԉa, ѵìtaé ϻãttìѕ Ꮷíɑm ɭêctuѕ vïtàê ߀rcï. Péllentesqûè ãliqúam consèctetûr ëɢeѕtãѕ. Dòԉec ïԁ ïåcûlís dúi. Nûɭláϻ ɭoƅ߀rtìs nìѕï ëǥèt Ꮷüi ëuïsmòԁ pɭacërát. Fûscë bìbéԉԁúm, ɭìɢûlá ѵël ѵêɦïcùɭå p߀ѕùëre, лuɭɭa ϻãѕѕå ɭacínía ɭïǥula, ïԉ s߀llícìtüdín erat tùrpís éü ìpsûϻ. Nüԉc conԁimeлtûϻ mäɭésúáԁå làcúѕ. Doԉéc ãc mälêѕüäᏧã âüǥùe, ìԉ ɭäcìлiá ɭigüɭâ. Núɭɭɑϻ ëѕt ãntè, úlláϻcòrρêr c߀лsêɋúåt diám лòn, ëɢêѕtàs ãɭïɋuâϻ ԉuлc. Pèɭɭëлtesɋúê háƃïtänt ϻorbì trïstíqùé ѕèԉectus êt лetuѕ ët maléѕûaᏧä fɑmës åc tùrρïѕ êɢêѕtãѕ. Nülɭä fɑcìɭiѕï. Måüris tìлcìdúnt ipѕúϻ ɭ߀rém, ѕëᏧ ѵiѵërrã èлím ѕeϻpêr ût. Aêлëäԉ coлváɭɭis ρèɭɭéԉtèѕqúê qûàm, ѕéԁ ƅɭɑԉԁit Ꮷïâϻ véɦïcuɭa métuѕ.";
                    newRecord[1] = 150d;
                    newRecord[2] = null;
                    newRecord[3] = 150d;
                    writer.WriteRecord(newRecord);

                    newRecord = writer.CreateRecord();

                    newRecord[0] =
                        "Lòrèm ipѕüϻ Ꮷòlor ѕít ámet, coԉѕéctëtùr ãԁiρìscíлǥ êlìt. Iл ïacûlis ԉêqûë êgét nèɋùé ѕêmpër, vítɑe läcïлíâ ɭíbèr߀ rhoncüѕ. Mâûríѕ tèllus lorém, ìmρérԁiët ѵìtɑe ƃïƅèԉdúm ác, rɦòncûs ԉéc dùi. D߀nëc ïn c߀лséɋûãt lèo. Núлc àt änte ԉec ϻêtüѕ åɭïqûåm henԁrérít qüís á âüǥûe. SûsρëԉᏧísѕê fåúcïbüs лunc mäûriѕ, ѕeᏧ fàùcíƅüѕ mâúríѕ ƅïbêndúm èt. SêᏧ ãûctor, Ꮷòɭor n߀n lüctuѕ ïлterdùm, téllus néqúë àûct߀r ԁuì, ѕìt ámët ɭùctuѕ ԉeɋùé ríѕûs veɭ niƃɦ. Nüllaϻ ߀rԉåré üɭtrícìës qùãm. Vèѕtïbulum ëɢet erɑt ѕït ԉúɭɭãm.";
                    newRecord[1] = null;
                    newRecord[2] = "Lorem ipsum dolor sit posuere.";
                    newRecord[3] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }

            ReadFile(filename, out int varCount, out int rowCount);

            Assert.AreEqual(varCount, 4, "Variable count does not match");
            Assert.AreEqual(rowCount, 3, "Rows count does not match");
        }
Exemple #6
0
        public void TestWriteNumbers()
        {
            var filename = @"testWriteNumbers.sav";

            var variables = new List <Variable>
            {
                new Variable("avariablename_01")
                {
                    Label       = "The variable Label",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "Label for 1" },
                        { 2, "Label for 2" },
                    },
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = MissingValueType.OneDiscreteMissingValue
                },
                new Variable("avariablename_02")
                {
                    Label       = "Another variable",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "this is 1" },
                        { 2, "this is 2" },
                    },
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = MissingValueType.OneDiscreteMissingValue
                }
            };

            variables[0].MissingValues[0] = 999;
            variables[1].MissingValues[0] = 999;

            var options = new SpssOptions();

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    var newRecord = writer.CreateRecord();
                    newRecord[0] = 15d;
                    newRecord[1] = 15.5d;
                    writer.WriteRecord(newRecord);
                    newRecord    = writer.CreateRecord();
                    newRecord[0] = null;
                    newRecord[1] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }

            ReadFile(filename, out int varCount, out int rowCount);

            Assert.AreEqual(varCount, 2, "Variable count does not match");
            Assert.AreEqual(rowCount, 2, "Rows count does not match");
        }
Exemple #7
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);
        }
Exemple #8
0
        public void TestWriteDoubleLongStringVar()
        {
            var filename = @"c:\temp\testWriteDoubleLongString.sav";

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                var var1 = new Variable("stringvar_01")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 5000
                };

                var var2 = new Variable("stringvar_02")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var3 = new Variable("stringvar_03")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 70),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 5000
                };

                var var4 = new Variable("stringvar_04")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 50,
                    TextWidth = 50
                };

                var var5 = new Variable("stringvar_05")
                {
                    Label     = "This is a string variable",
                    Type      = DataType.Text,
                    Width     = 4,
                    TextWidth = 4
                };

                var var6 = new Variable("LIKES")
                {
                    Label       = "This is a string variable",
                    PrintFormat = new OutputFormat(FormatType.A, 255),
                    WriteFormat = new OutputFormat(FormatType.A, 255),
                    Type        = DataType.Text,
                    Width       = 50,
                    TextWidth   = 1026
                };


                var variables = new List <Variable>
                {
                    var1,
                    var2,
                    var3,
                    var4,
                    var5,
                    var6
                };

                var options = new SpssOptions();

                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    object[] newRecord = writer.CreateRecord();
                    newRecord[0] = "test";
                    newRecord[1] = "test";
                    newRecord[2] = "Lorem";
                    //newRecord[3] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }
        }
        public void TestWriteString()
        {
            var filename = @"C:\Tests\testWriteString.sav";

            using (FileStream fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                var varString1 = new Variable
                {
                    Label     = "This is a string variable",
                    Name      = "stringvar_01",
                    Type      = DataType.Text,
                    TextWidth = 500,
                };

                var variable1 = new Variable
                {
                    Label       = "The variable Label",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "Label for 1" },
                        { 2, "Label for 2" },
                    },
                    Name             = "avariablename_01",
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = 1
                };
                variable1.MissingValues[0] = 999;

                var varString = new Variable
                {
                    Label       = "This is a string variable",
                    Name        = "stringvar_02",
                    PrintFormat = new OutputFormat(FormatType.A, 60),
                    WriteFormat = new OutputFormat(FormatType.A, 60),
                    Type        = DataType.Text,
                    Width       = 60,
                    TextWidth   = 60,
                };

                var variable2 = new Variable
                {
                    Label       = "Another variable",
                    ValueLabels = new Dictionary <double, string>
                    {
                        { 1, "this is 1" },
                        { 2, "this is 2" },
                    },
                    Name             = "avariablename_02",
                    PrintFormat      = new OutputFormat(FormatType.F, 8, 2),
                    WriteFormat      = new OutputFormat(FormatType.F, 8, 2),
                    Type             = DataType.Numeric,
                    Width            = 10,
                    MissingValueType = 1
                };
                variable2.MissingValues[0] = 999;

                var variables = new List <Variable>
                {
                    varString1,
                    variable1,
                    varString,
                    variable2
                };

                var options = new SpssOptions();

                using (var writer = new SpssWriter(fileStream, variables, options))
                {
                    var newRecord = writer.CreateRecord();
                    // Exactly 500
                    newRecord[0] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis neque eget neque semper, vitae lacinia libero rhoncus. Mauris tellus lorem, imperdiet vitae bibendum ac, rhoncus nec dui. Donec in consequat leo. Nunc at ante nec metus aliquam hendrerit quis a augue. Suspendisse faucibus nunc mauris, sed faucibus mauris bibendum et. Sed auctor, dolor non luctus interdum, tellus neque auctor dui, sit amet luctus neque risus vel nibh. Nullam ornare ultricies quam. Vestibulum eget erat sit nullam.";
                    newRecord[1] = 15d;
                    newRecord[2] = "adsf ñlkj";
                    newRecord[3] = 15.5d;
                    writer.WriteRecord(newRecord);

                    newRecord = writer.CreateRecord();
                    // 600, should be cut to 500
                    newRecord[0] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In elementum sed justo eu pulvinar. Maecenas non laoreet justo, eget ultrices dolor. Praesent sit amet sodales erat. Proin condimentum, metus et pulvinar ultrices, massa erat hendrerit lorem, vel mattis dolor ante id sem. Fusce laoreet mi tortor, ut interdum ipsum laoreet vel. Nullam lorem mauris, vulputate luctus velit placerat, scelerisque vehicula elit. Phasellus gravida ante quis augue convallis venenatis. Integer bibendum purus non felis interdum, quis fermentum tellus sodales. Fusce commodo ultrices leo ut vulputate. Quisque metus.";
                    newRecord[1] = 150d;
                    newRecord[2] = null;
                    newRecord[3] = 150d;
                    writer.WriteRecord(newRecord);

                    newRecord = writer.CreateRecord();
                    // 255 chars
                    newRecord[0] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis neque eget neque semper, vitae lacinia libero rhoncus. Mauris tellus lorem, imperdiet vitae bibendum ac, rhoncus nec dui. Donec in consequat leo. Nunc at ante nec metus aliquam hendrerit_";
                    newRecord[1] = null;
                    // 300 chars, should be cut to 60
                    newRecord[2] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.";
                    newRecord[3] = 200d;
                    writer.WriteRecord(newRecord);
                    writer.EndFile();
                }
            }
        }