Automatically infer variables' measurement level from format and data.
[pspp] / tests / data / pc+-file-reader.at
index 1d89d0dbf6e79a432cb89847a83a72820fae911a..115b2f953f26f1c8ebb72c9e6c67d74d6b37e826 100644 (file)
@@ -1,3 +1,19 @@
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl
 AT_BANNER([SPSS/PC+ file reader - positive])
 
 AT_SETUP([variable labels and missing values])
@@ -89,32 +105,25 @@ LIST.
 ])
 AT_CHECK([pspp -o pspp.csv pc+-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-File label: PSPP synthetic test file
-
-Variable,Description,Position
-NUM1,Format: F8.0,1
-NUM2,"Label: Numeric variable 2's label
-Format: F8.0",2
-NUM3,"Format: F8.0
-Missing Values: 1",3
-NUM4,"Label: Another numeric variable label
-Format: F8.0
-Missing Values: 2",4
-STR1,Format: A8,5
-STR2,"Label: STR2's variable label
-Format: A4",6
-STR3,"Format: A5
-Missing Values: ""MISS """,7
-STR4,"Label: STR4's variable label
-Format: A1
-Missing Values: ""O""",8
-STR5,Format: A11,9
-STR6,"Label: Another string variable's label
-Format: A11",10
+Table: File Label
+Label,PSPP synthetic test file
+
+Table: Variables
+Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
+NUM1,1,,Unknown,Input,8,Right,F8.0,F8.0,
+NUM2,2,Numeric variable 2's label,Unknown,Input,8,Right,F8.0,F8.0,
+NUM3,3,,Unknown,Input,8,Right,F8.0,F8.0,1
+NUM4,4,Another numeric variable label,Unknown,Input,8,Right,F8.0,F8.0,2
+STR1,5,,Nominal,Input,8,Left,A8,A8,
+STR2,6,STR2's variable label,Nominal,Input,4,Left,A4,A4,
+STR3,7,,Nominal,Input,5,Left,A5,A5,"""MISS """
+STR4,8,STR4's variable label,Nominal,Input,1,Left,A1,A1,"""O"""
+STR5,9,,Nominal,Input,11,Left,A11,A11,
+STR6,10,Another string variable's label,Nominal,Input,11,Left,A11,A11,
 
 Table: Data List
 NUM1,NUM2,NUM3,NUM4,STR1,STR2,STR3,STR4,STR5,STR6
-0,1,2,.,abcdefgh,ijkl,mnopq,r,stuvwxyzAB ,CDEFGHIJKLM
+0,1,2,.,abcdefgh,ijkl,mnopq,r,stuvwxyzAB,CDEFGHIJKLM
 ])
 AT_CLEANUP
 
@@ -209,73 +218,52 @@ LIST.
 ])
 AT_CHECK([pspp -o pspp.csv pc+-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-File label: PSPP synthetic test file
-
-Variable,Description,Position
-NUM1,"Format: F8.0
-
-Value,Label
-1,one",1
-NUM2,"Format: F8.0
-
-Value,Label
-2,two
-3,three",2
-NUM3,"Format: F8.0
-
-Value,Label
-3,three
-4,four",3
-NUM4,"Format: F8.0
-
-Value,Label
-4,four",4
-NUM5,"Format: F8.0
-
-Value,Label
-4,four
-5,five",5
-STR1,"Format: A1
-
-Value,Label
-a,value label for `a'",6
-STR2,"Format: A2
-
-Value,Label
-ab,value label for `ab'",7
-STR3,"Format: A3
-
-Value,Label
-abc,value label for `abc'",8
-STR4,"Format: A4
-
-Value,Label
-abcd,value label for abcdefgh",9
-STR5,"Format: A5
-
-Value,Label
-abcde,value label for abcdefgh
-ijklm,value label for ijklmnop",10
-STR6,"Format: A6
-
-Value,Label
-abcdef,value label for abcdefgh
-ijklmn,value label for ijklmnop
-qrstuv,value label for qrstuvwx",11
-STR7,"Format: A7
-
-Value,Label
-abcdefg,value label for abcdefgh
-ijklmno,value label for ijklmnop
-qrstuvw,value label for qrstuvwx
-yzABCDE,value label for yzABCDEF",12
-STR8,"Format: A8
-
-Value,Label
-GHIJKLMN,value label for GHIJKLMN
-ijklmnop,value label for ijklmnop
-qrstuvwx,value label for qrstuvwx
-yzABCDEF,value label for yzABCDEF",13
+Table: File Label
+Label,PSPP synthetic test file
+
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+NUM3,3,Unknown,Input,8,Right,F8.0,F8.0
+NUM4,4,Unknown,Input,8,Right,F8.0,F8.0
+NUM5,5,Unknown,Input,8,Right,F8.0,F8.0
+STR1,6,Nominal,Input,1,Left,A1,A1
+STR2,7,Nominal,Input,2,Left,A2,A2
+STR3,8,Nominal,Input,3,Left,A3,A3
+STR4,9,Nominal,Input,4,Left,A4,A4
+STR5,10,Nominal,Input,5,Left,A5,A5
+STR6,11,Nominal,Input,6,Left,A6,A6
+STR7,12,Nominal,Input,7,Left,A7,A7
+STR8,13,Nominal,Input,8,Left,A8,A8
+
+Table: Value Labels
+Variable Value,,Label
+NUM1,1,one
+NUM2,2,two
+,3,three
+NUM3,3,three
+,4,four
+NUM4,4,four
+NUM5,4,four
+,5,five
+STR1,a,value label for `a'
+STR2,ab,value label for `ab'
+STR3,abc,value label for `abc'
+STR4,abcd,value label for abcdefgh
+STR5,abcde,value label for abcdefgh
+,ijklm,value label for ijklmnop
+STR6,abcdef,value label for abcdefgh
+,ijklmn,value label for ijklmnop
+,qrstuv,value label for qrstuvwx
+STR7,abcdefg,value label for abcdefgh
+,ijklmno,value label for ijklmnop
+,qrstuvw,value label for qrstuvwx
+,yzABCDE,value label for yzABCDEF
+STR8,GHIJKLMN,value label for GHIJKLMN
+,ijklmnop,value label for ijklmnop
+,qrstuvwx,value label for qrstuvwx
+,yzABCDEF,value label for yzABCDEF
 
 Table: Data List
 NUM1,NUM2,NUM3,NUM4,NUM5,STR1,STR2,STR3,STR4,STR5,STR6,STR7,STR8
@@ -344,21 +332,93 @@ LIST.
 ])
 AT_CHECK([pspp -o pspp.csv pc+-file.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-File label: PSPP synthetic test file
+Table: File Label
+Label,PSPP synthetic test file
 
-Variable,Description,Position
-NUM1,Format: F8.0,1
-NUM2,Format: F8.0,2
-STR4,Format: A4,3
-STR8,Format: A8,4
-STR15,Format: A15,5
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+STR4,3,Nominal,Input,4,Left,A4,A4
+STR8,4,Nominal,Input,8,Left,A8,A8
+STR15,5,Nominal,Input,15,Left,A15,A15
 
 Table: Data List
 NUM1,NUM2,STR4,STR8,STR15
--5,150,abcd,efghj   ,efghijklABCDEFG
+-5,150,abcd,efghj,efghijklABCDEFG
 1000,.,PQRS,TUVWXYZa,bcdefghijklmnop
 ])
 AT_CLEANUP
+
+AT_SETUP([weighted])
+AT_KEYWORDS([sack synthetic PC+ file negative])
+AT_DATA([pc+-file.sack], [dnl
+dnl File header.
+2; 0;
+@MAIN; @MAIN_END - @MAIN;
+@VARS; @VARS_END - @VARS;
+0; 0;
+@DATA; @DATA_END - @DATA;
+(0; 0) * 11;
+i8 0 * 128;
+
+MAIN:
+    i16 1;         dnl Fixed.
+    s62 "PCSPSS PSPP synthetic test product";
+    PCSYSMIS;
+    0; 0; i16 1;   dnl Fixed.
+    i16 0;
+    i16 7;
+    i16 1; i16 6;
+    i16 0;         dnl Fixed.
+    i16 1; i16 0;
+    s8 "11/28/14";
+    s8 "15:11:00";
+    s64 "PSPP synthetic test file";
+MAIN_END:
+
+VARS:
+    0; 0; 0; 0x050800; s8 "$CASENUM"; PCSYSMIS;
+    0; 0; 0; 0x010800; s8 "$DATE"; PCSYSMIS;
+    0; 0; 0; 0x050802; s8 "$WEIGHT"; PCSYSMIS;
+
+    dnl Numeric variables.
+    0; 0; 0; 0x050800; s8 "NUM1"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM2"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM3"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM4"; PCSYSMIS;
+VARS_END:
+
+DATA:
+    0.0; "11/28/14"; 1.0; 2.0; 3.0; 4.0; 5.0;
+DATA_END:
+])
+AT_CHECK([sack --le pc+-file.sack > pc+-file.sav])
+AT_DATA([pc+-file.sps], [dnl
+SYSFILE INFO FILE='pc+-file.sav' ENCODING='us-ascii'.
+])
+AT_CHECK([pspp -O format=csv pc+-file.sps], [0], [dnl
+Table: File Information
+File,pc+-file.sav
+Label,PSPP synthetic test file
+Created,11/28/14 15:11:00 by PCSPSS PSPP synthetic test product
+Integer Format,Little Endian
+Real Format,IEEE 754 LE.
+Variables,4
+Cases,1
+Type,SPSS/PC+ System File
+Weight,NUM3
+Compression,None
+Encoding,us-ascii
+
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+NUM3,3,Unknown,Input,8,Right,F8.0,F8.0
+NUM4,4,Unknown,Input,8,Right,F8.0,F8.0
+])
+AT_CLEANUP
 \f
 AT_BANNER([SPSS/PC+ file reader - negative])
 
@@ -418,51 +478,39 @@ AT_CHECK([pspp -O format=csv pc+-file.sps], [0], [stdout], [])
 AT_CHECK([sed 's/default encoding.*For/default encoding.  For/' stdout], [0], [dnl
 "warning: `pc+-file.sav': Using default encoding.  For best results, specify an encoding explicitly.  Use SYSFILE INFO with ENCODING=""DETECT"" to analyze the possible encodings."
 
-File label: PSPP synthetic test file
+Table: File Label
+Label,PSPP synthetic test file
 
-Variable,Description,Position
-NUM1,Format: F8.0,1
-NUM2,Format: F8.0,2
-NUM3,Format: F8.0,3
-NUM4,Format: F8.0,4
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+NUM3,3,Unknown,Input,8,Right,F8.0,F8.0
+NUM4,4,Unknown,Input,8,Right,F8.0,F8.0
 
 Table: Data List
 NUM1,NUM2,NUM3,NUM4
 2,3,4,5
 
-File:,pc+-file.sav
-Label:,PSPP synthetic test file
-Created:,11/28/14 15:11:00 by PCSPSS PSPP synthetic test product
-Integer Format:,Little Endian
-Real Format:,IEEE 754 LE.
-Variables:,4
-Cases:,1
-Type:,SPSS/PC+ System File
-Weight:,Not weighted.
-Compression:,None
-Encoding:,us-ascii
-
-Variable,Description,Position
-NUM1,"Format: F8.0
-Measure: Scale
-Role: Input
-Display Alignment: Right
-Display Width: 8",1
-NUM2,"Format: F8.0
-Measure: Scale
-Role: Input
-Display Alignment: Right
-Display Width: 8",2
-NUM3,"Format: F8.0
-Measure: Scale
-Role: Input
-Display Alignment: Right
-Display Width: 8",3
-NUM4,"Format: F8.0
-Measure: Scale
-Role: Input
-Display Alignment: Right
-Display Width: 8",4
+Table: File Information
+File,pc+-file.sav
+Label,PSPP synthetic test file
+Created,11/28/14 15:11:00 by PCSPSS PSPP synthetic test product
+Integer Format,Little Endian
+Real Format,IEEE 754 LE.
+Variables,4
+Cases,1
+Type,SPSS/PC+ System File
+Weight,Not weighted
+Compression,None
+Encoding,us-ascii
+
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+NUM3,3,Unknown,Input,8,Right,F8.0,F8.0
+NUM4,4,Unknown,Input,8,Right,F8.0,F8.0
 ])
 AT_CLEANUP
 
@@ -518,7 +566,7 @@ AT_CHECK([pspp -O format=csv pc+-file.sps], [0], [dnl
 
 warning: `pc+-file.sav' near offset 0x100: Record 0 specifies unexpected system missing value 1 (0x1p+0).
 
-"warning: `pc+-file.sav' near offset 0x100: Record 0 reserved fields have unexpected values (1,1,0,2,0)."
+"warning: `pc+-file.sav' near offset 0x100: Record 0 reserved fields have unexpected values (1,1,0,2,0,0)."
 
 warning: `pc+-file.sav' near offset 0x100: Record 0 case counts differ (1 versus 3).
 ])
@@ -844,6 +892,8 @@ GET FILE='pc+-file.sav' ENCODING='us-ascii'.
 ])
 AT_CHECK([pspp -O format=csv pc+-file.sps], [1], [dnl
 error: `pc+-file.sav' near offset 0x1b0: Record 1 has length 192 (expected 224).
+
+pc+-file.sps:1: error: GET: `pc+-file.sav': Data file dictionary has no variables.
 ])
 AT_CLEANUP
 
@@ -1196,20 +1246,126 @@ DISPLAY DICTIONARY.
 LIST.
 ])
 AT_CHECK([pspp -O format=csv pc+-file.sps], [0], [dnl
-File label: PSPP synthetic test file
+Table: File Label
+Label,PSPP synthetic test file
 
-Variable,Description,Position
-NUM1,Format: F8.0,1
-NUM2,Format: F8.0,2
-STR4,Format: A4,3
-STR8,Format: A8,4
-STR15,Format: A15,5
+Table: Variables
+Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
+NUM1,1,Unknown,Input,8,Right,F8.0,F8.0
+NUM2,2,Unknown,Input,8,Right,F8.0,F8.0
+STR4,3,Nominal,Input,4,Left,A4,A4
+STR8,4,Nominal,Input,8,Left,A8,A8
+STR15,5,Nominal,Input,15,Left,A15,A15
 
 warning: `pc+-file.sav' near offset 0x308: Possible compressed data corruption: string contains compressed integer (opcode 101).
 
 Table: Data List
 NUM1,NUM2,STR4,STR8,STR15
--5,150,abcd,efghj   ,efghijklABCDEFG
+-5,150,abcd,efghj,efghijklABCDEFG
 1000,.,PQRS,TUVWXYZa,bcdefghijklmnop
 ])
 AT_CLEANUP
+
+AT_SETUP([invalid weight index])
+AT_KEYWORDS([sack synthetic PC+ file negative])
+AT_DATA([pc+-file.sack], [dnl
+dnl File header.
+2; 0;
+@MAIN; @MAIN_END - @MAIN;
+@VARS; @VARS_END - @VARS;
+0; 0;
+@DATA; @DATA_END - @DATA;
+(0; 0) * 11;
+i8 0 * 128;
+
+MAIN:
+    i16 1;         dnl Fixed.
+    s62 "PCSPSS PSPP synthetic test product";
+    PCSYSMIS;
+    0; 0; i16 1;   dnl Fixed.
+    i16 0;
+    i16 7;
+    i16 1; i16 10;
+    i16 0;         dnl Fixed.
+    i16 1; i16 0;
+    s8 "11/28/14";
+    s8 "15:11:00";
+    s64 "PSPP synthetic test file";
+MAIN_END:
+
+VARS:
+    0; 0; 0; 0x050800; s8 "$CASENUM"; PCSYSMIS;
+    0; 0; 0; 0x010800; s8 "$DATE"; PCSYSMIS;
+    0; 0; 0; 0x050802; s8 "$WEIGHT"; PCSYSMIS;
+
+    dnl Numeric variables.
+    0; 0; 0; 0x050800; s8 "NUM1"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM2"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM3"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM4"; PCSYSMIS;
+VARS_END:
+
+DATA:
+    0.0; "11/28/14"; 1.0; 2.0; 3.0; 4.0; 5.0;
+DATA_END:
+])
+AT_CHECK([sack --le pc+-file.sack > pc+-file.sav])
+AT_DATA([pc+-file.sps], [dnl
+GET FILE='pc+-file.sav' ENCODING='us-ascii'.
+])
+AT_CHECK([pspp -O format=csv pc+-file.sps], [0],
+  [warning: `pc+-file.sav': Invalid weight index 10.
+])
+AT_CLEANUP
+
+AT_SETUP([string weight])
+AT_KEYWORDS([sack synthetic PC+ file negative])
+AT_DATA([pc+-file.sack], [dnl
+dnl File header.
+2; 0;
+@MAIN; @MAIN_END - @MAIN;
+@VARS; @VARS_END - @VARS;
+0; 0;
+@DATA; @DATA_END - @DATA;
+(0; 0) * 11;
+i8 0 * 128;
+
+MAIN:
+    i16 1;         dnl Fixed.
+    s62 "PCSPSS PSPP synthetic test product";
+    PCSYSMIS;
+    0; 0; i16 1;   dnl Fixed.
+    i16 0;
+    i16 7;
+    i16 1; i16 6;
+    i16 0;         dnl Fixed.
+    i16 1; i16 0;
+    s8 "11/28/14";
+    s8 "15:11:00";
+    s64 "PSPP synthetic test file";
+MAIN_END:
+
+VARS:
+    0; 0; 0; 0x050800; s8 "$CASENUM"; PCSYSMIS;
+    0; 0; 0; 0x010800; s8 "$DATE"; PCSYSMIS;
+    0; 0; 0; 0x050802; s8 "$WEIGHT"; PCSYSMIS;
+
+    dnl Variables.
+    0; 0; 0; 0x050800; s8 "NUM1"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM2"; PCSYSMIS;
+    0; 0; 0; 0x010800; s8 "STR1"; PCSYSMIS;
+    0; 0; 0; 0x050800; s8 "NUM4"; PCSYSMIS;
+VARS_END:
+
+DATA:
+    0.0; "11/28/14"; 1.0; s8 "acbdefgh"; 3.0; 4.0; 5.0;
+DATA_END:
+])
+AT_CHECK([sack --le pc+-file.sack > pc+-file.sav])
+AT_DATA([pc+-file.sps], [dnl
+GET FILE='pc+-file.sav' ENCODING='us-ascii'.
+])
+AT_CHECK([pspp -O format=csv pc+-file.sps], [0],
+  [warning: `pc+-file.sav' near offset 0x250: Cannot weight by string variable `STR1'.
+])
+AT_CLEANUP