PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/Spss/SpssSafeWrapper.cs

#
C# | 1990 lines | 483 code | 35 blank | 1472 comment | 49 complexity | 64713a1d4b30e9c4fc1db0fe322ff097 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Spss
  4. {
  5. /// <summary>
  6. /// Very thin SpssSafeWrapper class for functions exposed by spssio32.dll.
  7. /// </summary>
  8. [CLSCompliant(false)]
  9. public class SpssSafeWrapper : SpssThinWrapper
  10. {
  11. /// <summary>
  12. /// Creates an instance of the <see cref="SpssSafeWrapper"/> class.
  13. /// </summary>
  14. protected SpssSafeWrapper()
  15. {
  16. }
  17. // These lengths were extracted from the SPSS documentation
  18. // rather than any header file.
  19. public const int SPSS_GUID_LENGTH = 256;
  20. public const int SPSS_SYSTEM_STRING_LENGTH = 41;
  21. public const int SPSS_MAX_TEXTINFO = 255;
  22. public const int SPSS_DATESTAMP_LENGTH = 9;
  23. public const int SPSS_TIMESTAMP_LENGTH = 8;
  24. #region veg
  25. public static Int32 SPSS_STRING(Int32 size)
  26. {
  27. return size;
  28. }
  29. public const Int32 SPSS_NUMERIC = 0;
  30. #endregion veg
  31. /// <summary>
  32. /// Opens an SPSS file for reading.
  33. /// </summary>
  34. /// <param name="fileName">
  35. /// Name of the file.
  36. /// </param>
  37. /// <param name="handle">
  38. /// The handle to the opened file.
  39. /// </param>
  40. /// <returns>
  41. /// <see cref="ReturnCode.SPSS_OK"/>,
  42. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  43. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  44. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  45. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  46. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  47. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>, or
  48. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>.
  49. /// </returns>
  50. /// <remarks>
  51. /// This function opens an SPSS data file for reading and returns a handle that should be
  52. /// used for subsequent operations on the file.
  53. /// Files opened with spssOpenRead should be closed with <see cref="SpssThinWrapper.spssCloseReadDelegate"/>.
  54. /// </remarks>
  55. public static ReturnCode spssOpenRead(string fileName, out int handle)
  56. {
  57. return SpssThinWrapper.spssOpenReadImpl(ref fileName, out handle);
  58. }
  59. /// <summary>
  60. /// Creates an empty SPSS file.
  61. /// </summary>
  62. /// <param name="fileName">
  63. /// Name of the file.
  64. /// </param>
  65. /// <param name="handle">
  66. /// The handle to the new file.
  67. /// </param>
  68. /// <returns>
  69. /// <see cref="ReturnCode.SPSS_OK"/>,
  70. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  71. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  72. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  73. /// </returns>
  74. /// <remarks>
  75. /// This function opens a file in preparation for creating a new SPSS data file and returns a
  76. /// handle that should be used for subsequent operations on the file.
  77. /// Files opened with spssOpenWrite should be closed with <see cref="SpssThinWrapper.spssCloseWriteDelegate"/>.
  78. /// </remarks>
  79. public static ReturnCode spssOpenWrite(string fileName, out int handle)
  80. {
  81. return SpssThinWrapper.spssOpenWriteImpl(ref fileName, out handle);
  82. }
  83. /// <summary>
  84. /// Reports the name of the case weight variable.
  85. /// </summary>
  86. /// <param name="handle">
  87. /// Handle to the data file.
  88. /// </param>
  89. /// <param name="varName">
  90. /// The name of the case weight variable.
  91. /// </param>
  92. /// <returns>
  93. /// <see cref="ReturnCode.SPSS_OK"/>,
  94. /// <see cref="ReturnCode.SPSS_NO_CASEWGT"/>,
  95. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  96. /// <see cref="ReturnCode.SPSS_INVALID_CASEWGT"/>.
  97. /// </returns>
  98. /// <remarks>
  99. /// This function reports the name of the case weight variable.
  100. /// </remarks>
  101. public static ReturnCode spssGetCaseWeightVar(int handle, out string varName)
  102. {
  103. varName = new string(' ', SPSS_MAX_VARNAME + 1);
  104. ReturnCode result = SpssThinWrapper.spssGetCaseWeightVarImpl(handle, ref varName);
  105. varName = (result == ReturnCode.SPSS_OK) ? varName.Substring(0, varName.IndexOf('\0')) : null;
  106. return result;
  107. }
  108. /// <summary>
  109. /// Retrieves the first block of SPSS Data Entry information from a data file.
  110. /// </summary>
  111. /// <param name="handle">
  112. /// Handle to the data file.
  113. /// </param>
  114. /// <param name="data">
  115. /// Data from the file.
  116. /// </param>
  117. /// <param name="maxData">
  118. /// Maximum bytes to return.
  119. /// </param>
  120. /// <returns>
  121. /// <see cref="ReturnCode.SPSS_OK"/>,
  122. /// <see cref="ReturnCode.SPSS_NO_DEW"/>,
  123. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  124. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  125. /// </returns>
  126. /// <remarks>
  127. /// The client can retrieve DEW information (file information that is private to the SPSS
  128. /// Data Entry product) from a file in whatever increments are convenient. The first such
  129. /// increment is retrieved by calling spssGetDEWFirst, and subsequent segments are
  130. /// retrieved by calling spssGetDEWNext as many times as necessary. As with
  131. /// spssGetDEWInfo, spssGetDEWFirst will return SPSS_NO_DEW if the file was written
  132. /// with a byte order that is the reverse of that of the host.
  133. /// </remarks>
  134. public static ReturnCode spssGetDEWFirst(int handle, out string data, int maxData)
  135. {
  136. data = new string(' ', maxData);
  137. int len;
  138. ReturnCode result = SpssThinWrapper.spssGetDEWFirstImpl(handle, ref data, data.Length, out len);
  139. data = (result == ReturnCode.SPSS_OK) ? data.Substring(0, len) : null;
  140. return result;
  141. }
  142. /// <summary>
  143. /// Gets the Data Entry GUID from a data file.
  144. /// </summary>
  145. /// <param name="handle">
  146. /// Handle to the data file.
  147. /// </param>
  148. /// <param name="asciiGUID">
  149. /// The file's GUID in character form or a null string if the
  150. /// file contains no GUID.
  151. /// </param>
  152. /// <returns>
  153. /// <see cref="ReturnCode.SPSS_OK"/> or
  154. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  155. /// </returns>
  156. /// <remarks>
  157. /// Data Entry for Windows maintains a GUID in character form as a uniqueness indicator.
  158. /// Two files have identical dictionaries and DEW information if they have the same
  159. /// GUID. Note that the spssOpenWriteCopy function will not copy the source file’s
  160. /// GUID. spssGetDEWGUID allows the client to read a file’s GUID, if any.
  161. /// </remarks>
  162. public static ReturnCode spssGetDEWGUID(int handle, out string asciiGUID)
  163. {
  164. asciiGUID = new string(' ', SPSS_GUID_LENGTH + 1);
  165. ReturnCode result = SpssThinWrapper.spssGetDEWGUIDImpl(handle, ref asciiGUID);
  166. // Although we search for a null terminator, the documentation
  167. // tells us that the GUID is always SPSS_GUID_LENGTH, so we COULD
  168. // just terminate the string there to trim off the null terminator that is
  169. // artificially put there.
  170. asciiGUID = (result == ReturnCode.SPSS_OK) ? asciiGUID.Substring(0, asciiGUID.IndexOf('\0')) : null;
  171. return result;
  172. }
  173. /// <summary>
  174. /// Retrieves the next block of SPSS Data Entry information from a data file.
  175. /// </summary>
  176. /// <param name="handle">
  177. /// Handle to the data file.
  178. /// </param>
  179. /// <param name="data">
  180. /// Data from the file.
  181. /// </param>
  182. /// <param name="maxData">
  183. /// Maximum bytes to return.
  184. /// </param>
  185. /// <returns>
  186. /// <see cref="ReturnCode.SPSS_OK"/>,
  187. /// <see cref="ReturnCode.SPSS_DEW_NOFIRST"/>,
  188. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  189. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  190. /// </returns>
  191. /// <remarks>
  192. /// The client can retrieve DEW information (file information that is private to the SPSS
  193. /// Data Entry product) from a file in whatever increments are convenient. The first such
  194. /// increment is retrieved by calling <see cref="spssGetDEWFirst"/>, and subsequent segments are
  195. /// retrieved by calling spssGetDEWNext as many times as necessary. As with
  196. /// <see cref="SpssThinWrapper.spssGetDEWInfoDelegate"/>, <see cref="spssGetDEWFirst"/> will return SPSS_NO_DEW if the file was written
  197. /// with a byte order that is the reverse of that of the host.
  198. /// </remarks>
  199. public static ReturnCode spssGetDEWNext(int handle, out string data, int maxData)
  200. {
  201. data = new string(' ', maxData);
  202. int len;
  203. ReturnCode result = SpssThinWrapper.spssGetDEWNextImpl(handle, ref data, data.Length, out len);
  204. data = (result == ReturnCode.SPSS_OK) ? data.Substring(0, len) : null;
  205. return result;
  206. }
  207. /// <summary>
  208. /// Gets the file label of a data file.
  209. /// </summary>
  210. /// <param name="handle">
  211. /// Handle to the data file.
  212. /// </param>
  213. /// <param name="id">
  214. /// File label.
  215. /// </param>
  216. /// <returns>
  217. /// <see cref="ReturnCode.SPSS_OK"/> or
  218. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  219. /// </returns>
  220. /// <remarks>
  221. /// This function retrieves the file label of the SPSS data file associated with
  222. /// <paramref>handle</paramref> into the <paramref>id</paramref> parameter.
  223. /// </remarks>
  224. public static ReturnCode spssGetIdString(int handle, out string id)
  225. {
  226. id = new string(' ', SPSS_MAX_IDSTRING + 1); // leave room for null terminator
  227. ReturnCode result = SpssThinWrapper.spssGetIdStringImpl(handle, ref id);
  228. id = (result == ReturnCode.SPSS_OK) ? id.Substring(0, id.IndexOf('\0')) : null;
  229. return result;
  230. }
  231. /// <summary>
  232. /// Gets information on the running version of SPSS, and the hosting computer.
  233. /// </summary>
  234. /// <param name="handle">
  235. /// Handle to the data file.
  236. /// </param>
  237. /// <param name="relInfo">
  238. /// Array of <see cref="int"/> in which release- and machine-specific data will be
  239. /// stored.
  240. /// </param>
  241. /// <returns>
  242. /// <see cref="ReturnCode.SPSS_OK"/>,
  243. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  244. /// <see cref="ReturnCode.SPSS_NO_TYPE73"/>.
  245. /// </returns>
  246. /// <remarks>
  247. /// This function reports release- and machine-specific information about the file
  248. /// associated with handle. The information consists of an array of eight int values copied
  249. /// from record type 7, subtype 3 of the file, and is useful primarily for debugging. The
  250. /// array elements are, in order, release number (index 0), release subnumber (1), special
  251. /// release identifier number (2), machine code (3), floating-point representation code (4),
  252. /// compression scheme code (5), big/little-endian code (6), and character representation
  253. /// code (7).
  254. /// </remarks>
  255. public static ReturnCode spssGetReleaseInfo(int handle, out int[] relInfo)
  256. {
  257. relInfo = new int[8];
  258. ReturnCode result = SpssThinWrapper.spssGetReleaseInfoImpl(handle, relInfo);
  259. return result;
  260. }
  261. /// <summary>
  262. /// Gets the name of the system that created a data file.
  263. /// </summary>
  264. /// <param name="handle">
  265. /// Handle to the data file.
  266. /// </param>
  267. /// <param name="sysName">
  268. /// The originating system name.
  269. /// </param>
  270. /// <returns>
  271. /// <see cref="ReturnCode.SPSS_OK"/> or
  272. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  273. /// </returns>
  274. /// <remarks>
  275. /// This function returns the name of the system under which the file was created.
  276. /// </remarks>
  277. public static ReturnCode spssGetSystemString(int handle, out string sysName)
  278. {
  279. sysName = new string(' ', SPSS_SYSTEM_STRING_LENGTH + 1); // leave room for null terminator
  280. ReturnCode result = SpssThinWrapper.spssGetSystemStringImpl(handle, ref sysName);
  281. sysName = (result == ReturnCode.SPSS_OK) ? sysName.Substring(0, sysName.IndexOf('\0')) : null;
  282. return result;
  283. }
  284. /// <summary>
  285. /// Gets the data created by TextSmart.
  286. /// </summary>
  287. /// <param name="handle">
  288. /// Handle to the data file.
  289. /// </param>
  290. /// <param name="textInfo">
  291. /// Text data.
  292. /// </param>
  293. /// <returns>
  294. /// <see cref="ReturnCode.SPSS_OK"/> or
  295. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  296. /// </returns>
  297. /// <remarks>
  298. /// This function retrieves the text data created by TextSmart.
  299. /// </remarks>
  300. public static ReturnCode spssGetTextInfo(int handle, out string textInfo)
  301. {
  302. textInfo = new string(' ', SPSS_MAX_TEXTINFO + 1);
  303. ReturnCode result = SpssThinWrapper.spssGetTextInfoImpl(handle, ref textInfo);
  304. textInfo = (result == ReturnCode.SPSS_OK) ? textInfo.Substring(0, textInfo.IndexOf('\0')) : null;
  305. return result;
  306. }
  307. /// <summary>
  308. /// Gets the creation date of a data file, as recorded in the file itself.
  309. /// </summary>
  310. /// <param name="handle">
  311. /// Handle to the data file.
  312. /// </param>
  313. /// <param name="fileDate">
  314. /// File creation date.
  315. /// </param>
  316. /// <param name="fileTime">
  317. /// File creation time.
  318. /// </param>
  319. /// <returns>
  320. /// <see cref="ReturnCode.SPSS_OK"/> or
  321. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>.
  322. /// </returns>
  323. /// <remarks>
  324. /// This function returns the creation date of the file as recorded in the file itself. The creation
  325. /// date is a 9-byte string in dd mmm yy format (27 Feb 96). The creation time is a
  326. /// 8-byte oypcbi in hh:mm:ss format (13:12:15).
  327. /// </remarks>
  328. public static ReturnCode spssGetTimeStamp(int handle, out string fileDate, out string fileTime)
  329. {
  330. fileDate = new string(' ', SPSS_DATESTAMP_LENGTH + 1);
  331. fileTime = new string(' ', SPSS_TIMESTAMP_LENGTH + 1);
  332. ReturnCode result = SpssThinWrapper.spssGetTimeStampImpl(handle, ref fileDate, ref fileTime);
  333. fileDate = (result == ReturnCode.SPSS_OK) ? fileDate.Substring(0, fileDate.IndexOf('\0')) : null;
  334. fileTime = (result == ReturnCode.SPSS_OK) ? fileTime.Substring(0, fileTime.IndexOf('\0')) : null;
  335. return result;
  336. }
  337. /// <summary>
  338. /// Gets the string value of a variable.
  339. /// </summary>
  340. /// <param name="handle">
  341. /// Handle to the data file.
  342. /// </param>
  343. /// <param name="varHandle">
  344. /// Handle of the variable.
  345. /// </param>
  346. /// <param name="value">
  347. /// Value of the string variable.
  348. /// </param>
  349. /// <returns>
  350. /// <see cref="ReturnCode.SPSS_OK"/>,
  351. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  352. /// <see cref="ReturnCode.SPSS_OPEN_WRMODE"/>,
  353. /// <see cref="ReturnCode.SPSS_INVALID_CASE"/>,
  354. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  355. /// <see cref="ReturnCode.SPSS_BUFFER_SHORT"/>.
  356. /// </returns>
  357. /// <remarks>
  358. /// This function gets the value of a string variable for the current case, which is the case
  359. /// read by the most recent call to <see cref="SpssThinWrapper.spssReadCaseRecordDelegate"/>.
  360. /// </remarks>
  361. public static ReturnCode spssGetValueChar(int handle, double varHandle, out string value)
  362. {
  363. value = new string(' ', SPSS_MAX_LONGSTRING + 1); // leave room for null terminator
  364. ReturnCode result = SpssThinWrapper.spssGetValueCharImpl(handle, varHandle, ref value, value.Length);
  365. if (result == ReturnCode.SPSS_BUFFER_SHORT)
  366. {
  367. value = new string(' ', SPSS_MAX_VERYLONGSTRING + 1);
  368. result = SpssThinWrapper.spssGetValueCharImpl(handle, varHandle, ref value, value.Length);
  369. }
  370. value = (result == ReturnCode.SPSS_OK) ? value.Substring(0, value.IndexOf('\0')) : null;
  371. return result;
  372. }
  373. /// <summary>
  374. /// Gets the alignment of a variable.
  375. /// </summary>
  376. /// <param name="handle">
  377. /// Handle to the data file.
  378. /// </param>
  379. /// <param name="varName">
  380. /// Variable name.
  381. /// </param>
  382. /// <param name="alignment">
  383. /// Alignment of the variable.
  384. /// </param>
  385. /// <returns>
  386. /// <see cref="ReturnCode.SPSS_OK"/>,
  387. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  388. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  389. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  390. /// </returns>
  391. /// <remarks>
  392. /// This function reports the value of the alignment attribute of a variable.
  393. /// </remarks>
  394. public static ReturnCode spssGetVarAlignment(int handle, string varName, out AlignmentCode alignment)
  395. {
  396. return SpssThinWrapper.spssGetVarAlignmentImpl(handle, ref varName, out alignment);
  397. }
  398. /// <summary>
  399. /// Gets the missing values of a short string variable.
  400. /// </summary>
  401. /// <param name="handle">
  402. /// Handle to the data file.
  403. /// </param>
  404. /// <param name="varName">
  405. /// Variable name.
  406. /// </param>
  407. /// <param name="missingFormat">
  408. /// Missing value format code.
  409. /// </param>
  410. /// <param name="missingVal1">
  411. /// First missing value.
  412. /// </param>
  413. /// <param name="missingVal2">
  414. /// Second missing value.
  415. /// </param>
  416. /// <param name="missingVal3">
  417. /// Third missing value.
  418. /// </param>
  419. /// <returns>
  420. /// <see cref="ReturnCode.SPSS_OK"/>,
  421. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  422. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  423. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  424. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  425. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>.
  426. /// </returns>
  427. /// <remarks>
  428. /// This function reports the missing values of a short string variable. The value of
  429. /// <paramref>missingFormat</paramref> will indicate
  430. /// the number of missing values. The
  431. /// appropriate number of missing values is copied to the <paramref>missingVal1</paramref>,
  432. /// <paramref>missingVal2</paramref>, and <paramref>missingVal3</paramref> parameters.
  433. /// </remarks>
  434. public static ReturnCode spssGetVarCMissingValues(int handle, string varName, out MissingValueFormatCode missingFormat, out string missingVal1, out string missingVal2, out string missingVal3)
  435. {
  436. missingVal1 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  437. missingVal2 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  438. missingVal3 = new string(' ', SPSS_MAX_SHORTSTRING + 1);
  439. ReturnCode result = SpssThinWrapper.spssGetVarCMissingValuesImpl(handle, ref varName, out missingFormat,
  440. ref missingVal1, ref missingVal2, ref missingVal3);
  441. if (missingFormat < MissingValueFormatCode.SPSS_THREE_MISSVAL)
  442. missingVal3 = null;
  443. else
  444. missingVal3 = (result == ReturnCode.SPSS_OK) ? missingVal3.Substring(0, missingVal3.IndexOf('\0')) : null;
  445. if (missingFormat < MissingValueFormatCode.SPSS_TWO_MISSVAL)
  446. missingVal2 = null;
  447. else
  448. missingVal2 = (result == ReturnCode.SPSS_OK) ? missingVal2.Substring(0, missingVal2.IndexOf('\0')) : null;
  449. if (missingFormat < MissingValueFormatCode.SPSS_ONE_MISSVAL)
  450. missingVal1 = null;
  451. else
  452. missingVal1 = (result == ReturnCode.SPSS_OK) ? missingVal1.Substring(0, missingVal1.IndexOf('\0')) : null;
  453. return result;
  454. }
  455. /// <summary>
  456. /// Gets the width of a variable.
  457. /// </summary>
  458. /// <param name="handle">
  459. /// Handle to the data file.
  460. /// </param>
  461. /// <param name="varName">
  462. /// Variable name.
  463. /// </param>
  464. /// <param name="columnWidth">
  465. /// Column width.
  466. /// </param>
  467. /// <returns>
  468. /// <see cref="ReturnCode.SPSS_OK"/>,
  469. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  470. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  471. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  472. /// </returns>
  473. /// <remarks>
  474. /// This function reports the value of the column width attribute of a variable. A value of
  475. /// zero is special and means that the SPSS Data Editor, which is the primary user of this
  476. /// attribute, will set an appropriate width using its own algorithm.
  477. /// </remarks>
  478. public static ReturnCode spssGetVarColumnWidth(int handle, string varName, out int columnWidth)
  479. {
  480. return SpssThinWrapper.spssGetVarColumnWidthImpl(handle, ref varName, out columnWidth);
  481. }
  482. /// <summary>
  483. /// Gets the name and type of a variable.
  484. /// </summary>
  485. /// <param name="handle">
  486. /// Handle to the data file.
  487. /// </param>
  488. /// <param name="iVar">
  489. /// Zero origin variable number.
  490. /// </param>
  491. /// <param name="varName">
  492. /// Variable name.
  493. /// </param>
  494. /// <param name="varType">
  495. /// Variable type.
  496. /// </param>
  497. /// <returns>
  498. /// <see cref="ReturnCode.SPSS_OK"/>,
  499. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  500. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  501. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  502. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  503. /// </returns>
  504. /// <remarks>
  505. /// This function gets the name and type of one of the variables present in a data file. It
  506. /// serves the same purpose as <see cref="spssGetVarNames"/> but returns the information one variable
  507. /// at a time and, therefore, can be passed to a Visual Basic program.
  508. /// The type code is an integer in the range 0–255, 0 indicating a numeric
  509. /// variable and a positive value indicating a string variable of that size.
  510. /// </remarks>
  511. public static ReturnCode spssGetVarInfo(int handle, int iVar, out string varName, out int varType)
  512. {
  513. varName = new string(' ', SpssSafeWrapper.SPSS_MAX_VARNAME + 1);
  514. ReturnCode result = SpssThinWrapper.spssGetVarInfoImpl(handle, iVar, ref varName, out varType);
  515. varName = (result == ReturnCode.SPSS_OK) ? varName.Substring(0, varName.IndexOf('\0')) : null;
  516. return result;
  517. }
  518. /// <summary>
  519. /// Gets the handle for a named variable.
  520. /// </summary>
  521. /// <param name="handle">
  522. /// Handle to the data file.
  523. /// </param>
  524. /// <param name="varName">
  525. /// Variable name.
  526. /// </param>
  527. /// <param name="varHandle">
  528. /// Handle for the variable.
  529. /// </param>
  530. /// <returns>
  531. /// <see cref="ReturnCode.SPSS_OK"/>,
  532. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  533. /// <see cref="ReturnCode.SPSS_DICT_NOTCOMMIT"/>,
  534. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  535. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  536. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  537. /// </returns>
  538. /// <remarks>
  539. /// This function returns a handle for a variable, which can then be used to read or write
  540. /// (depending on how the file was opened) values of the variable. If handle is associated
  541. /// with an output file, the dictionary must be written with <see cref="SpssThinWrapper.spssCommitHeaderDelegate"/>
  542. /// before variable handles can be obtained via spssGetVarHandle.
  543. /// </remarks>
  544. public static ReturnCode spssGetVarHandle(int handle, string varName, out double varHandle)
  545. {
  546. return SpssThinWrapper.spssGetVarHandleImpl(handle, ref varName, out varHandle);
  547. }
  548. /// <summary>
  549. /// Gets the variable label for some named variable.
  550. /// </summary>
  551. /// <param name="handle">
  552. /// Handle to the data file.
  553. /// </param>
  554. /// <param name="varName">
  555. /// Variable name.
  556. /// </param>
  557. /// <param name="varLabel">
  558. /// Variable label.
  559. /// </param>
  560. /// <returns>
  561. /// <see cref="ReturnCode.SPSS_OK"/>,
  562. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  563. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  564. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  565. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  566. /// </returns>
  567. /// <remarks>
  568. /// This function copies the label of variable <paramref>varName</paramref> into
  569. /// <paramref>varLabel</paramref>. To get labels more than 120 characters long, use
  570. /// the spssGetVarLabelLong function.
  571. /// </remarks>
  572. public static ReturnCode spssGetVarLabel(int handle, string varName, out string varLabel)
  573. {
  574. int len;
  575. varLabel = new string(' ', SPSS_MAX_LONGSTRING + 1); // leave room for null terminator
  576. ReturnCode result = spssGetVarLabelLongImpl(handle, ref varName, ref varLabel, varLabel.Length, out len);
  577. varLabel = (result == ReturnCode.SPSS_OK) ? varLabel.Substring(0, len) : varLabel = null;
  578. return result;
  579. }
  580. /// <summary>
  581. /// Gets the measurement level of a variable.
  582. /// </summary>
  583. /// <param name="handle">
  584. /// Handle to the data file.
  585. /// </param>
  586. /// <param name="varName">
  587. /// Variable name.
  588. /// </param>
  589. /// <param name="measureLevel">
  590. /// Measurement level.
  591. /// </param>
  592. /// <returns>
  593. /// <see cref="ReturnCode.SPSS_OK"/>,
  594. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  595. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  596. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  597. /// </returns>
  598. /// <remarks>
  599. /// This function reports the value of the measurement level attribute of a variable.
  600. /// </remarks>
  601. public static ReturnCode spssGetVarMeasureLevel(int handle, string varName, out MeasurementLevelCode measureLevel)
  602. {
  603. int measureLevelInt;
  604. ReturnCode status = SpssThinWrapper.spssGetVarMeasureLevelImpl(handle, ref varName, out measureLevelInt);
  605. measureLevel = (MeasurementLevelCode)measureLevelInt;
  606. return status;
  607. }
  608. /// <summary>
  609. /// Gets the missing values of a numeric variable.
  610. /// </summary>
  611. /// <param name="handle">
  612. /// Handle to the data file.
  613. /// </param>
  614. /// <param name="varName">
  615. /// Variable name.
  616. /// </param>
  617. /// <param name="missingFormat">
  618. /// Missing value format code.
  619. /// </param>
  620. /// <param name="missingVal1">
  621. /// First missing value.
  622. /// </param>
  623. /// <param name="missingVal2">
  624. /// Second missing value.
  625. /// </param>
  626. /// <param name="missingVal3">
  627. /// Third missing value.
  628. /// </param>
  629. /// <returns>
  630. /// <see cref="ReturnCode.SPSS_OK"/>,
  631. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  632. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  633. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  634. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>.
  635. /// </returns>
  636. /// <remarks>
  637. /// This function reports the missing values of a numeric variable. The value of
  638. /// <paramref>missingFormat</paramref> determines the interpretation of
  639. /// <paramref>missingVal1</paramref>, <paramref>missingVal2</paramref>, and
  640. /// <paramref>missingVal3</paramref>. If missingFormat is SPSS_MISS_RANGE,
  641. /// <paramref>missingVal1</paramref> and <paramref>missingVal2</paramref>
  642. /// represent the upper and lower limits, respectively, of the range, and
  643. /// <paramref>missingVal3</paramref> is not used. If missingFormat is
  644. /// SPSS_MISS_RANGEANDVAL, <paramref>missingVal1</paramref> and
  645. /// <paramref>missingVal2</paramref> represent the range and
  646. /// <paramref>missingVal3</paramref> is the discrete missing value.
  647. /// If missingFormat is neither of the above, it will be in the range
  648. /// 0–3, indicating the number of discrete missing
  649. /// values present. (The macros SPSS_NO_MISSVAL, SPSS_ONE_MISSVAL,
  650. /// SPSS_TWO_MISSVAL, and SPSS_THREE_MISSVAL may be used as synonyms for 0–3.)
  651. /// </remarks>
  652. public static ReturnCode spssGetVarNMissingValues(int handle, string varName, out MissingValueFormatCode missingFormat, out double missingVal1, out double missingVal2, out double missingVal3)
  653. {
  654. return SpssThinWrapper.spssGetVarNMissingValuesImpl(handle, ref varName, out missingFormat, out missingVal1, out missingVal2, out missingVal3);
  655. }
  656. /// <summary>
  657. /// Gets the value label for a variable.
  658. /// </summary>
  659. /// <param name="handle">
  660. /// Handle to the data file.
  661. /// </param>
  662. /// <param name="varName">
  663. /// Variable name.
  664. /// </param>
  665. /// <param name="value">
  666. /// Short string value for which the label is wanted.
  667. /// </param>
  668. /// <param name="label">
  669. /// Label for the value.
  670. /// </param>
  671. /// <returns>
  672. /// <see cref="ReturnCode.SPSS_OK"/>,
  673. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  674. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  675. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  676. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  677. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  678. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  679. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>, or
  680. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>.
  681. /// </returns>
  682. /// <remarks>
  683. /// This function gets the value label for a given value of a short string variable.
  684. /// </remarks>
  685. public static ReturnCode spssGetVarCValueLabel(int handle, string varName, string value, out string label)
  686. {
  687. int len;
  688. label = new string(' ', SPSS_MAX_VALLABEL + 1);
  689. ReturnCode result = spssGetVarCValueLabelLongImpl(handle, ref varName, ref value, ref label, label.Length, out len);
  690. label = (result == ReturnCode.SPSS_OK) ? label.Substring(0, len) : null;
  691. return result;
  692. }
  693. /// <summary>
  694. /// Gets the value label for a given value of a numeric variable.
  695. /// </summary>
  696. /// <param name="handle">
  697. /// Handle to the data file.
  698. /// </param>
  699. /// <param name="varName">
  700. /// Variable name.
  701. /// </param>
  702. /// <param name="value">
  703. /// Numeric value for which the label is wanted.
  704. /// </param>
  705. /// <param name="label">
  706. /// Label for the value.
  707. /// </param>
  708. /// <returns>
  709. /// <see cref="ReturnCode.SPSS_OK"/>,
  710. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  711. /// <see cref="ReturnCode.SPSS_NO_LABEL"/>,
  712. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  713. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  714. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  715. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>.
  716. /// </returns>
  717. /// <remarks>
  718. /// This function gets the value label for a given value of a numeric variable.
  719. /// </remarks>
  720. public static ReturnCode spssGetVarNValueLabel(int handle, string varName, double value, out string label)
  721. {
  722. int len;
  723. label = new string(' ', SPSS_MAX_VALLABEL + 1); // leave room for null terminator
  724. ReturnCode result = spssGetVarNValueLabelLong(handle, ref varName, value, ref label, label.Length, out len);
  725. if (result == ReturnCode.SPSS_OK)
  726. label = label.Substring(0, len);
  727. else
  728. label = null;
  729. return result;
  730. }
  731. /// <summary>
  732. /// Gets print formatting information for a variable.
  733. /// </summary>
  734. /// <param name="handle">
  735. /// Handle to the data file.
  736. /// </param>
  737. /// <param name="varName">
  738. /// Variable name.
  739. /// </param>
  740. /// <param name="printType">
  741. /// Print format type code (file spssdio.h defines macros of
  742. /// the form <see cref="FormatTypeCode">SPSS_FMT_...</see> for all valid format type codes)
  743. /// </param>
  744. /// <param name="printDec">
  745. /// Number of digits after the decimal.
  746. /// </param>
  747. /// <param name="printWidth">
  748. /// Print format width.
  749. /// </param>
  750. /// <returns>
  751. /// <see cref="ReturnCode.SPSS_OK"/>,
  752. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  753. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  754. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  755. /// </returns>
  756. /// <remarks>
  757. /// This function reports the print format of a variable. Format type, number of decimal
  758. /// places, and field width are returned as <paramref>printType</paramref>,
  759. /// <paramref>printDec</paramref>, and <paramref>printWid</paramref>, respectively.
  760. /// </remarks>
  761. public static ReturnCode spssGetVarPrintFormat(int handle, string varName, out FormatTypeCode printType, out int printDec, out int printWidth)
  762. {
  763. return SpssThinWrapper.spssGetVarPrintFormatImpl(handle, ref varName, out printType, out printDec, out printWidth);
  764. }
  765. /// <summary>
  766. /// Gets the write format of a variable.
  767. /// </summary>
  768. /// <param name="handle">
  769. /// Handle to the data file
  770. /// </param>
  771. /// <param name="varName">
  772. /// Variable name
  773. /// </param>
  774. /// <param name="writeType">
  775. /// Pointer to write format type code (file spssdio.h defines macros of
  776. /// the form <see cref="FormatTypeCode">SPSS_FMT_...</see> for all valid format type codes)
  777. /// </param>
  778. /// <param name="writeDec">
  779. /// Pointer to number of digits after the decimal
  780. /// </param>
  781. /// <param name="writeWidth">
  782. /// Pointer to write format width
  783. /// </param>
  784. /// <returns>
  785. /// <see cref="ReturnCode.SPSS_OK"/>,
  786. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  787. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  788. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  789. /// </returns>
  790. /// <remarks>
  791. /// This function reports the write format of a variable. Format type, number of decimal
  792. /// places, and field width are returned as writeType, writeDec, and writeWid,
  793. /// respectively.
  794. /// </remarks>
  795. public static ReturnCode spssGetVarWriteFormat(int handle, string varName, out FormatTypeCode writeType, out int writeDec, out int writeWidth)
  796. {
  797. return SpssThinWrapper.spssGetVarWriteFormatImpl(handle, ref varName, out writeType, out writeDec, out writeWidth);
  798. }
  799. /// <summary>
  800. /// Opens an SPSS file for appending cases.
  801. /// </summary>
  802. /// <param name="fileName">
  803. /// Name of the file.
  804. /// </param>
  805. /// <param name="handle">
  806. /// Handle to the opened file.
  807. /// </param>
  808. /// <returns>
  809. /// <see cref="ReturnCode.SPSS_OK"/>,
  810. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  811. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  812. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  813. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  814. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  815. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>,
  816. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>, or
  817. /// <see cref="ReturnCode.SPSS_INCOMPAT_APPEND"/>.
  818. /// </returns>
  819. /// <remarks>
  820. /// This function opens an SPSS data file for appending cases and returns a handle that
  821. /// should be used for subsequent operations on the file.
  822. /// </remarks>
  823. public static ReturnCode spssOpenAppend(string fileName, out int handle)
  824. {
  825. return SpssThinWrapper.spssOpenAppendImpl(ref fileName, out handle);
  826. }
  827. /// <summary>
  828. /// Creates a new SPSS data file, with a dictionary copied from an existing file.
  829. /// </summary>
  830. /// <param name="fileName">
  831. /// Name of the new file.
  832. /// </param>
  833. /// <param name="dictFileName">
  834. /// Name of existing file.
  835. /// </param>
  836. /// <param name="handle">
  837. /// Handle of the new file.
  838. /// </param>
  839. /// <returns>
  840. /// <see cref="ReturnCode.SPSS_OK"/>,
  841. /// <see cref="ReturnCode.SPSS_FITAB_FULL"/>,
  842. /// <see cref="ReturnCode.SPSS_FILE_OERROR"/>,
  843. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>,
  844. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>,
  845. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>,
  846. /// <see cref="ReturnCode.SPSS_NO_TYPE2"/>, or
  847. /// <see cref="ReturnCode.SPSS_NO_TYPE999"/>.
  848. /// </returns>
  849. /// <remarks>
  850. /// This function opens a file in preparation for creating a new SPSS data file and initializes
  851. /// its dictionary from that of an existing SPSS data file. It is useful when you want to modify
  852. /// the dictionary or data of an existing file or replace all of its data. The typical sequence
  853. /// of operations is to call <see cref="spssOpenWriteCopy"/> (newFileName, oldFileName, ...) to open a
  854. /// new file initialized with a copy of the old file’s dictionary, then <see cref="spssOpenRead"/> (oldFile-
  855. /// Name, ...) to open the old file to access its data.
  856. /// </remarks>
  857. public static ReturnCode spssOpenWriteCopy(string fileName, string dictFileName, out int handle)
  858. {
  859. return SpssThinWrapper.spssOpenWriteCopyImpl(ref fileName, ref dictFileName, out handle);
  860. }
  861. /// <summary>
  862. /// Sets the case weight variable in a data file.
  863. /// </summary>
  864. /// <param name="handle">
  865. /// Handle to the data file.
  866. /// </param>
  867. /// <param name="varName">
  868. /// The name of the case weight variable.
  869. /// </param>
  870. /// <returns>
  871. /// <see cref="ReturnCode.SPSS_OK"/>,
  872. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  873. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  874. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  875. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  876. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  877. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>, or
  878. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  879. /// </returns>
  880. /// <remarks>
  881. /// This function defines variable varName as the case weight variable for the data file
  882. /// specified by the handle.
  883. /// </remarks>
  884. public static ReturnCode spssSetCaseWeightVar(int handle, string varName)
  885. {
  886. return SpssThinWrapper.spssSetCaseWeightVarImpl(handle, ref varName);
  887. }
  888. /// <summary>
  889. /// Sets the Trends date variable information.
  890. /// </summary>
  891. /// <param name="handle">
  892. /// Handle to the data file.
  893. /// </param>
  894. /// <param name="dateInfo">
  895. /// Array containing date variables information.
  896. /// </param>
  897. /// <returns>
  898. /// <see cref="ReturnCode.SPSS_OK"/>,
  899. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  900. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  901. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  902. /// <see cref="ReturnCode.SPSS_INVALID_DATEINFO"/>, or
  903. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  904. /// </returns>
  905. /// <remarks>
  906. /// This function sets the Trends date variable information. The array at dateInfo is
  907. /// assumed to have numofElements elements that correspond to the data array portion of
  908. /// record 7, subtype 3. Its first six elements comprise the “fixed” information, followed
  909. /// by a sequence of one or more three-element groups. Since very little validity checking
  910. /// is done on the input array, this function should be used with caution and is
  911. /// recommended only for copying Trends information from one file to another.
  912. /// </remarks>
  913. unsafe public static ReturnCode spssSetDateVariables(int handle, int[] dateInfo)
  914. {
  915. return SpssThinWrapper.spssSetDateVariablesImpl(handle, dateInfo.Length, (int*)Marshal.UnsafeAddrOfPinnedArrayElement(dateInfo, 0));
  916. }
  917. /// <summary>
  918. /// Sets the first block of Data Entry information.
  919. /// </summary>
  920. /// <param name="handle">
  921. /// Handle to the data file.
  922. /// </param>
  923. /// <param name="data">
  924. /// Data to be written.
  925. /// </param>
  926. /// <returns>
  927. /// <see cref="ReturnCode.SPSS_OK"/>,
  928. /// <see cref="ReturnCode.SPSS_EMPTY_DEW"/>,
  929. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  930. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  931. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  932. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  933. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  934. /// </returns>
  935. /// <remarks>
  936. /// DEW information (file information which is private to the SPSS Data Entry product)
  937. /// can be delivered to the I/O DLL in whatever segments are convenient for the client.
  938. /// The spssSetDEWFirst function is called to deliver the first such segment, and
  939. /// subsequent segments are delivered by calling spssSetDEWNext as many times as
  940. /// necessary.
  941. /// </remarks>
  942. public static ReturnCode spssSetDEWFirst(int handle, string data)
  943. {
  944. return SpssThinWrapper.spssSetDEWFirstImpl(handle, ref data, data.Length);
  945. }
  946. /// <summary>
  947. /// Sets the unique Data Entry uniqueness GUID.
  948. /// </summary>
  949. /// <param name="handle">
  950. /// Handle to the data file.
  951. /// </param>
  952. /// <param name="asciiGUID">
  953. /// The GUID to be stored on the file.
  954. /// </param>
  955. /// <returns>
  956. /// <see cref="ReturnCode.SPSS_OK"/>,
  957. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  958. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  959. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  960. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  961. /// </returns>
  962. /// <remarks>
  963. /// This function stores the Data Entry for Windows uniqueness indicator on the data file.
  964. /// It should only be used by the DEW product.
  965. /// </remarks>
  966. public static ReturnCode spssSetDEWGUID(int handle, string asciiGUID)
  967. {
  968. return SpssThinWrapper.spssSetDEWGUIDImpl(handle, ref asciiGUID);
  969. }
  970. /// <summary>
  971. /// Sets the next block of information for Data Entry.
  972. /// </summary>
  973. /// <param name="handle">
  974. /// Handle to the data file.
  975. /// </param>
  976. /// <param name="data">
  977. /// Data to be written.
  978. /// </param>
  979. /// <returns>
  980. /// <see cref="ReturnCode.SPSS_OK"/>,
  981. /// <see cref="ReturnCode.SPSS_DEW_NOFIRST"/>,
  982. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  983. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  984. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  985. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  986. /// <see cref="ReturnCode.SPSS_FILE_BADTEMP"/>.
  987. /// </returns>
  988. /// <remarks>
  989. /// The DEW information (file information that is private to the SPSS Data Entry product)
  990. /// can be delivered to the I/O DLL in whatever segments are convenient for the client.
  991. /// The spssSetDEWFirst function is called to deliver the first such segment, and
  992. /// subsequent segments are delivered by calling spssSetDEWNext as many times as
  993. /// necessary.
  994. /// </remarks>
  995. public static ReturnCode spssSetDEWNext(int handle, string data)
  996. {
  997. return SpssThinWrapper.spssSetDEWNextImpl(handle, ref data, data.Length);
  998. }
  999. /// <summary>
  1000. /// Sets the file label of a data file.
  1001. /// </summary>
  1002. /// <param name="handle">
  1003. /// Handle to the data file.
  1004. /// </param>
  1005. /// <param name="id">
  1006. /// File label. The length of the string should not exceed
  1007. /// <see cref="SpssThinWrapper.SPSS_MAX_IDSTRING"/> characters.
  1008. /// </param>
  1009. /// <returns>
  1010. /// <see cref="ReturnCode.SPSS_OK"/>,
  1011. /// <see cref="ReturnCode.SPSS_EXC_LEN64"/>
  1012. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1013. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>, or
  1014. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>.
  1015. /// </returns>
  1016. /// <remarks>
  1017. /// This function sets the file label of the output SPSS data file associated with handle to
  1018. /// the given string id.
  1019. /// </remarks>
  1020. public static ReturnCode spssSetIdString(int handle, string id)
  1021. {
  1022. return SpssThinWrapper.spssSetIdStringImpl(handle, ref id);
  1023. }
  1024. /// <summary>
  1025. /// Sets multiple response definitions to a data file.
  1026. /// </summary>
  1027. /// <param name="handle">
  1028. /// Handle to the data file.
  1029. /// </param>
  1030. /// <param name="mrespDefs">
  1031. /// ASCII string containing definitions.
  1032. /// </param>
  1033. /// <returns>
  1034. /// <see cref="ReturnCode.SPSS_OK"/>,
  1035. /// <see cref="ReturnCode.SPSS_EMPTY_MULTRESP"/>
  1036. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1037. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1038. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  1039. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1040. /// </returns>
  1041. /// <remarks>
  1042. /// This function is used to write multiple response definitions to the file. The definitions
  1043. /// consist of a single null-terminated ASCII string which is similar to that containing the
  1044. /// variable set definitions.
  1045. /// </remarks>
  1046. public static ReturnCode spssSetMultRespDefs(int handle, string mrespDefs)
  1047. {
  1048. return SpssThinWrapper.spssSetMultRespDefsImpl(handle, ref mrespDefs);
  1049. }
  1050. /// <summary>
  1051. /// Sets the text data from the string in textInfo.
  1052. /// </summary>
  1053. /// <param name="handle">
  1054. /// Handle to the data file
  1055. /// </param>
  1056. /// <param name="textInfo">
  1057. /// Text data
  1058. /// </param>
  1059. /// <returns>
  1060. /// <see cref="ReturnCode.SPSS_OK"/>,
  1061. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1062. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1063. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  1064. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1065. /// </returns>
  1066. /// <remarks>
  1067. /// This function sets the text data from the null-terminated string in textInfo. If the string is
  1068. /// longer than 255 characters, only the first 255 are (quietly) used. If textInfo contains the
  1069. /// empty string, existing text data, if any, is deleted.
  1070. /// </remarks>
  1071. public static ReturnCode spssSetTextInfo(int handle, string textInfo)
  1072. {
  1073. return SpssThinWrapper.spssSetTextInfoImpl(handle, ref textInfo);
  1074. }
  1075. /// <summary>
  1076. /// Sets the value of a string variable.
  1077. /// </summary>
  1078. /// <param name="handle">
  1079. /// Handle to the data file.
  1080. /// </param>
  1081. /// <param name="varHandle">
  1082. /// Handle to the variable.
  1083. /// </param>
  1084. /// <param name="value">
  1085. /// Value of the variable. The length of the
  1086. /// string (ignoring trailing blanks, if any) should be less than or equal
  1087. /// to the length of the variable.
  1088. /// </param>
  1089. /// <returns>
  1090. /// <see cref="ReturnCode.SPSS_OK"/>,
  1091. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1092. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1093. /// <see cref="ReturnCode.SPSS_DICT_NOTCOMMIT"/>,
  1094. /// <see cref="ReturnCode.SPSS_STR_EXP"/>, or
  1095. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>.
  1096. /// </returns>
  1097. /// <remarks>
  1098. /// This function sets the value of a string variable for the current case. The current case is
  1099. /// not written out to the data file until <see cref="SpssThinWrapper.spssCommitCaseRecordDelegate"/> is called.
  1100. /// </remarks>
  1101. public static ReturnCode spssSetValueChar(int handle, double varHandle, string value)
  1102. {
  1103. return SpssThinWrapper.spssSetValueCharImpl(handle, varHandle, ref value);
  1104. }
  1105. /// <summary>
  1106. /// Sets the alignment of a variable.
  1107. /// </summary>
  1108. /// <param name="handle">
  1109. /// Handle to the data file.
  1110. /// </param>
  1111. /// <param name="varName">
  1112. /// Variable name.
  1113. /// </param>
  1114. /// <param name="alignment">
  1115. /// Alignment. If not a legal
  1116. /// value, alignment is set to a type-appropriate default.
  1117. /// </param>
  1118. /// <returns>
  1119. /// <see cref="ReturnCode.SPSS_OK"/>,
  1120. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1121. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1122. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1123. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  1124. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  1125. /// </returns>
  1126. /// <remarks>
  1127. /// This function sets the value of the alignment attribute of a variable.
  1128. /// </remarks>
  1129. public static ReturnCode spssSetVarAlignment(int handle, string varName, AlignmentCode alignment)
  1130. {
  1131. return SpssThinWrapper.spssSetVarAlignmentImpl(handle, ref varName, alignment);
  1132. }
  1133. /// <summary>
  1134. /// Sets missing values for a short string variable.
  1135. /// </summary>
  1136. /// <param name="handle">
  1137. /// Handle to the data file.
  1138. /// </param>
  1139. /// <param name="varName">
  1140. /// Variable name.
  1141. /// </param>
  1142. /// <param name="missingFormat">
  1143. /// The number of missing values (0-3) actually supplied.
  1144. /// </param>
  1145. /// <param name="missingVal1">
  1146. /// First missing value.
  1147. /// </param>
  1148. /// <param name="missingVal2">
  1149. /// Second missing value.
  1150. /// </param>
  1151. /// <param name="missingVal3">
  1152. /// Third missing value.
  1153. /// </param>
  1154. /// <returns>
  1155. /// <see cref="ReturnCode.SPSS_OK"/>,
  1156. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1157. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1158. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1159. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1160. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1161. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  1162. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>,
  1163. /// <see cref="ReturnCode.SPSS_INVALID_MISSFOR"/>,
  1164. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>, or
  1165. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1166. /// </returns>
  1167. /// <remarks>
  1168. /// This function sets missing values for a short string variable. The argument
  1169. /// missingFormat must be set to a value in the range 0–3 to indicate the number of missing
  1170. /// values supplied. When fewer than three missing values are to be defined, the redundant
  1171. /// arguments must still be present, although their values are not inspected. For example,
  1172. /// if missingFormat is 2, missingVal3 is unused. The supplied missing values must be nullterminated
  1173. /// and not longer than the length of the variable unless the excess length is
  1174. /// made up of blanks, which are ignored. If the missing value is shorter than the length of
  1175. /// the variable, trailing blanks are assumed.
  1176. /// </remarks>
  1177. public static ReturnCode spssSetVarCMissingValues(int handle, string varName, MissingValueFormatCode missingFormat, string missingVal1, string missingVal2, string missingVal3)
  1178. {
  1179. return SpssThinWrapper.spssSetVarCMissingValuesImpl(handle, ref varName, missingFormat,
  1180. ref missingVal1, ref missingVal2, ref missingVal3);
  1181. }
  1182. /// <summary>
  1183. /// Sets the column width of a variable.
  1184. /// </summary>
  1185. /// <param name="handle">
  1186. /// Handle to the data file.
  1187. /// </param>
  1188. /// <param name="varName">
  1189. /// Variable name.
  1190. /// </param>
  1191. /// <param name="columnWidth">
  1192. /// Column width. If negative, a value of zero is (quietly) used instead.
  1193. /// </param>
  1194. /// <returns>
  1195. /// <see cref="ReturnCode.SPSS_OK"/>,
  1196. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1197. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1198. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1199. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>, or
  1200. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>.
  1201. /// </returns>
  1202. /// <remarks>
  1203. /// This function sets the value of the column width attribute of a variable. A value of zero
  1204. /// is special and means that the SPSS Data Editor, which is the primary user of this
  1205. /// attribute, is to set an appropriate width using its own algorithm.
  1206. /// </remarks>
  1207. public static ReturnCode spssSetVarColumnWidth(int handle, string varName, int columnWidth)
  1208. {
  1209. return SpssThinWrapper.spssSetVarColumnWidthImpl(handle, ref varName, columnWidth);
  1210. }
  1211. /// <summary>
  1212. /// Sets the label of a variable.
  1213. /// </summary>
  1214. /// <param name="handle">
  1215. /// Handle to the data file.
  1216. /// </param>
  1217. /// <param name="varName">
  1218. /// Variable name.
  1219. /// </param>
  1220. /// <param name="varLabel">
  1221. /// Variable label. The length of the string should not exceed
  1222. /// <see cref="SpssThinWrapper.SPSS_MAX_VARLABEL"/> characters.
  1223. /// If varLabel is the empty string, the existing label, if any, is deleted.
  1224. /// </param>
  1225. /// <returns>
  1226. /// <see cref="ReturnCode.SPSS_OK"/>,
  1227. /// <see cref="ReturnCode.SPSS_EXC_LEN120"/>,
  1228. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1229. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1230. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1231. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1232. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  1233. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1234. /// </returns>
  1235. /// <remarks>
  1236. /// This function sets the label of a variable.
  1237. /// </remarks>
  1238. public static ReturnCode spssSetVarLabel(int handle, string varName, string varLabel)
  1239. {
  1240. return SpssThinWrapper.spssSetVarLabelImpl(handle, ref varName, ref varLabel);
  1241. }
  1242. /// <summary>
  1243. /// Creates a new variable with a given name.
  1244. /// </summary>
  1245. /// <param name="handle">
  1246. /// Handle to the data file.
  1247. /// </param>
  1248. /// <param name="varName">
  1249. /// Variable name.
  1250. /// </param>
  1251. /// <param name="varType">
  1252. /// Type and size of the variable.
  1253. /// </param>
  1254. /// <returns>
  1255. /// <list type="table">
  1256. /// <listheader>
  1257. /// <term>Error code</term>
  1258. /// <description>Description</description>
  1259. /// </listheader>
  1260. /// <item>
  1261. /// <term><see cref="ReturnCode.SPSS_OK"/></term>
  1262. /// <description>No error</description>
  1263. /// </item>
  1264. /// <item>
  1265. /// <term><see cref="ReturnCode.SPSS_INVALID_HANDLE"/></term>
  1266. /// <description>The file handle is not valid</description>
  1267. /// </item>
  1268. /// <item>
  1269. /// <term><see cref="ReturnCode.SPSS_OPEN_RDMODE"/></term>
  1270. /// <description>File is open for reading, not writing</description>
  1271. /// </item>
  1272. /// <item>
  1273. /// <term><see cref="ReturnCode.SPSS_DICT_COMMIT"/></term>
  1274. /// <description>Dictionary has already been written with <see cref="SpssThinWrapper.spssCommitHeaderDelegate"/></description>
  1275. /// </item>
  1276. /// <item>
  1277. /// <term><see cref="ReturnCode.SPSS_INVALID_VARTYPE"/></term>
  1278. /// <description>Invalid length code ( varLength is negative or exceeds 255)</description>
  1279. /// </item>
  1280. /// <item>
  1281. /// <term><see cref="ReturnCode.SPSS_INVALID_VARNAME"/></term>
  1282. /// <description>Variable name is invalid</description>
  1283. /// </item>
  1284. /// <item>
  1285. /// <term><see cref="ReturnCode.SPSS_DUP_VAR"/></term>
  1286. /// <description>There is already a variable with the same name</description>
  1287. /// </item>
  1288. /// <item>
  1289. /// <term><see cref="ReturnCode.SPSS_NO_MEMORY"/></term>
  1290. /// <description>Insufficient memory</description>
  1291. /// </item>
  1292. /// </list>
  1293. /// </returns>
  1294. /// <remarks>
  1295. /// This function creates a new variable named varName, which will be either numeric or
  1296. /// string based on varLength. If the latter is zero, a numeric variable with a default format
  1297. /// of F8.2 will be created; if it is greater than 0 and less than or equal to 255, a string variable
  1298. /// with length varLength will be created; any other value will be rejected as invalid.
  1299. /// For better readability, macros SPSS_NUMERIC and SPSS_STRING( length) may be
  1300. /// used as values for varLength.
  1301. /// </remarks>
  1302. public static ReturnCode spssSetVarName(int handle, string varName, int varType)
  1303. {
  1304. return SpssThinWrapper.spssSetVarNameImpl(handle, ref varName, varType);
  1305. }
  1306. /// <summary>
  1307. /// Changes or adds a value label for a short string variable.
  1308. /// </summary>
  1309. /// <param name="handle">
  1310. /// Handle to the data file.
  1311. /// </param>
  1312. /// <param name="varName">
  1313. /// Variable name.
  1314. /// </param>
  1315. /// <param name="value">
  1316. /// Value to be labeled.
  1317. /// </param>
  1318. /// <param name="label">
  1319. /// Label.
  1320. /// </param>
  1321. /// <returns>
  1322. /// <see cref="ReturnCode.SPSS_OK"/>,
  1323. /// <see cref="ReturnCode.SPSS_EXC_LEN60"/>,
  1324. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1325. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1326. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1327. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1328. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1329. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  1330. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>,
  1331. /// <see cref="ReturnCode.SPSS_EXC_STRVALUE"/>,
  1332. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  1333. /// <see cref="ReturnCode.SPSS_INTERNAL_VLABS"/>.
  1334. /// </returns>
  1335. /// <remarks>
  1336. /// This function changes or adds a value label for the specified value of a short string
  1337. /// variable. The label should not exceed 60 characters in length.
  1338. /// </remarks>
  1339. public static ReturnCode spssSetVarCValueLabel(int handle, string varName, string value, string label)
  1340. {
  1341. return SpssThinWrapper.spssSetVarCValueLabelImpl(handle, ref varName, ref value, ref label);
  1342. }
  1343. /// <summary>
  1344. /// Sets the variable sets information in a data file.
  1345. /// </summary>
  1346. /// <param name="handle">
  1347. /// Handle to the data file.
  1348. /// </param>
  1349. /// <param name="varSets">
  1350. /// Variable sets information.
  1351. /// </param>
  1352. /// <returns>
  1353. /// <see cref="ReturnCode.SPSS_OK"/>,
  1354. /// <see cref="ReturnCode.SPSS_EMPTY_VARSETS"/>,
  1355. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1356. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1357. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>, or
  1358. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1359. /// </returns>
  1360. /// <remarks>
  1361. /// This function sets the variable sets information in the data file. The information must
  1362. /// be provided in the form of a string. No validity checks are performed
  1363. /// on the supplied string beyond ensuring that its length is not 0. Any existing variable
  1364. /// sets information is discarded.
  1365. /// </remarks>
  1366. public static ReturnCode spssSetVariableSets(int handle, string varSets)
  1367. {
  1368. return SpssThinWrapper.spssSetVariableSetsImpl(handle, ref varSets);
  1369. }
  1370. /// <summary>
  1371. /// Sets the measurement level of a variable.
  1372. /// </summary>
  1373. /// <param name="handle">
  1374. /// Handle to the data file.
  1375. /// </param>
  1376. /// <param name="varName">
  1377. /// Variable name.
  1378. /// </param>
  1379. /// <param name="measureLevel">
  1380. /// Measurement level.
  1381. /// </param>
  1382. /// <returns>
  1383. /// <see cref="ReturnCode.SPSS_OK"/>,
  1384. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1385. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1386. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1387. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1388. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>, or
  1389. /// <see cref="ReturnCode.SPSS_INVALID_MEASURELEVEL"/>.
  1390. /// </returns>
  1391. /// <remarks>
  1392. /// This function sets the value of the measurement level attribute of a variable.
  1393. /// </remarks>
  1394. public static ReturnCode spssSetVarMeasureLevel(int handle, string varName, MeasurementLevelCode measureLevel)
  1395. {
  1396. return SpssThinWrapper.spssSetVarMeasureLevelImpl(handle, ref varName, (int)measureLevel);
  1397. }
  1398. /// <summary>
  1399. /// Sets the missing values for a numeric variable.
  1400. /// </summary>
  1401. /// <param name="handle">
  1402. /// Handle to the data file.
  1403. /// </param>
  1404. /// <param name="varName">
  1405. /// Variable name.
  1406. /// </param>
  1407. /// <param name="missingFormat">
  1408. /// Missing values format code.
  1409. /// </param>
  1410. /// <param name="missingVal1">
  1411. /// First missing value.
  1412. /// </param>
  1413. /// <param name="missingVal2">
  1414. /// Second missing value.
  1415. /// </param>
  1416. /// <param name="missingVal3">
  1417. /// Third missing value.
  1418. /// </param>
  1419. /// <returns>
  1420. /// <see cref="ReturnCode.SPSS_OK"/>,
  1421. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1422. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1423. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1424. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1425. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1426. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>,
  1427. /// <see cref="ReturnCode.SPSS_INVALID_MISSFOR"/>,
  1428. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1429. /// </returns>
  1430. /// <remarks>
  1431. /// This function sets missing values for a numeric variable. The interpretation of the
  1432. /// arguments missingVal1, missingVal2, and missingVal3 depends on the value of
  1433. /// missingFormat. If missingFormat is set to SPSS_MISS_RANGE, missingVal1 and
  1434. /// missingVal2 are taken as the upper and lower limits, respectively, of the range, and
  1435. /// missingVal3 is ignored. If missingFormat is SPSS_MISS_RANGEANDVAL, missingval1
  1436. /// and missingVal2 are taken as limits of the range and missingVal3 is taken as the discrete
  1437. /// missing value. If missingFormat is neither of the above, it must be in the range 0–3,
  1438. /// indicating the number of discrete missing values present. For example, if
  1439. /// missingFormat is 2, missingVal1 and missingVal2 are taken as two discrete missing
  1440. /// values and missingVal3 is ignored. (The macros SPSS_NO_MISSVAL,
  1441. /// SPSS_ONE_MISSVAL, SPSS_TWO_MISSVAL, and SPSS_THREE_MISSVAL may be
  1442. /// used as synonyms for 0–3.)
  1443. /// </remarks>
  1444. public static ReturnCode spssSetVarNMissingValues(int handle, string varName, MissingValueFormatCode missingFormat, double missingVal1, double missingVal2, double missingVal3)
  1445. {
  1446. return SpssThinWrapper.spssSetVarNMissingValuesImpl(handle, ref varName, missingFormat,
  1447. missingVal1, missingVal2, missingVal3);
  1448. }
  1449. /// <summary>
  1450. /// Changes or adds a value label to a numeric variable.
  1451. /// </summary>
  1452. /// <param name="handle">
  1453. /// Handle to the data file.
  1454. /// </param>
  1455. /// <param name="varName">
  1456. /// Variable name.
  1457. /// </param>
  1458. /// <param name="value">
  1459. /// Value to be labeled.
  1460. /// </param>
  1461. /// <param name="label">
  1462. /// Label.
  1463. /// </param>
  1464. /// <returns>
  1465. /// <see cref="ReturnCode.SPSS_OK"/>,
  1466. /// <see cref="ReturnCode.SPSS_EXC_LEN60"/>,
  1467. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1468. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1469. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1470. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1471. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1472. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>,
  1473. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>, or
  1474. /// <see cref="ReturnCode.SPSS_INTERNAL_VLABS"/>.
  1475. /// </returns>
  1476. /// <remarks>
  1477. /// This function changes or adds a value label for the specified value of a numeric
  1478. /// variable. The label should not exceed 60 characters in length.
  1479. /// </remarks>
  1480. public static ReturnCode spssSetVarNValueLabel(int handle, string varName, double value, string label)
  1481. {
  1482. return SpssThinWrapper.spssSetVarNValueLabelImpl(handle, ref varName, value, ref label);
  1483. }
  1484. /// <summary>
  1485. /// Sets the print format of a variable.
  1486. /// </summary>
  1487. /// <param name="handle">
  1488. /// Handle to the data file.
  1489. /// </param>
  1490. /// <param name="varName">
  1491. /// Variable name.
  1492. /// </param>
  1493. /// <param name="printType">
  1494. /// Print format type code (file spssdio.h defines macros of the form
  1495. /// <see cref="FormatTypeCode">SPSS_FMT_...</see> for all
  1496. /// valid format type codes).
  1497. /// </param>
  1498. /// <param name="printDec">
  1499. /// Number of digits after the decimal.
  1500. /// </param>
  1501. /// <param name="printWidth">
  1502. /// Print format width.
  1503. /// </param>
  1504. /// <returns>
  1505. /// <see cref="ReturnCode.SPSS_OK"/>,
  1506. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1507. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1508. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1509. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1510. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1511. /// <see cref="ReturnCode.SPSS_INVALID_PRFOR"/>, or
  1512. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1513. /// </returns>
  1514. /// <remarks>
  1515. /// This function sets the print format of a variable.
  1516. /// </remarks>
  1517. public static ReturnCode spssSetVarPrintFormat(int handle, string varName, FormatTypeCode printType, int printDec, int printWidth)
  1518. {
  1519. return SpssThinWrapper.spssSetVarPrintFormatImpl(handle, ref varName, printType, printDec, printWidth);
  1520. }
  1521. /// <summary>
  1522. /// Sets the write format of a variable.
  1523. /// </summary>
  1524. /// <param name="handle">
  1525. /// Handle to the data file.
  1526. /// </param>
  1527. /// <param name="varName">
  1528. /// Variable name.
  1529. /// </param>
  1530. /// <param name="writeType">
  1531. /// Write format type code (file spssdio.h defines macros of the form
  1532. /// <see cref="FormatTypeCode">SPSS_FMT_...</see> for all valid format type codes).
  1533. /// </param>
  1534. /// <param name="writeDec">
  1535. /// Number of digits after the decimal.
  1536. /// </param>
  1537. /// <param name="writeWidth">
  1538. /// Write format width.
  1539. /// </param>
  1540. /// <returns>
  1541. /// <see cref="ReturnCode.SPSS_OK"/>,
  1542. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1543. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1544. /// <see cref="ReturnCode.SPSS_DICT_COMMIT"/>,
  1545. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1546. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1547. /// <see cref="ReturnCode.SPSS_INVALID_WRFOR"/>, or
  1548. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1549. /// </returns>
  1550. /// <remarks>
  1551. /// This function sets the write format of a variable.
  1552. /// </remarks>
  1553. public static ReturnCode spssSetVarWriteFormat(int handle, string varName, FormatTypeCode writeType, int writeDec, int writeWidth)
  1554. {
  1555. return SpssThinWrapper.spssSetVarWriteFormatImpl(handle, ref varName, writeType, writeDec, writeWidth);
  1556. }
  1557. /// <summary>
  1558. /// Reads in the raw data for an entire case.
  1559. /// </summary>
  1560. /// <param name="handle">
  1561. /// Handle to the data file.
  1562. /// </param>
  1563. /// <param name="caseRec">
  1564. /// Buffer to contain the case.
  1565. /// </param>
  1566. /// <returns>
  1567. /// <see cref="ReturnCode.SPSS_OK"/>,
  1568. /// <see cref="ReturnCode.SPSS_FILE_END"/>,
  1569. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1570. /// <see cref="ReturnCode.SPSS_OPEN_WRMODE"/>, or
  1571. /// <see cref="ReturnCode.SPSS_FILE_RERROR"/>.
  1572. /// </returns>
  1573. /// <remarks>
  1574. /// This function reads a case from a data file into a case buffer provided by the user. The
  1575. /// required size of the buffer may be obtained by calling <see cref="SpssThinWrapper.spssGetCaseSizeDelegate"/>. This is a fairly
  1576. /// low-level function whose use should not be mixed with calls to <see cref="SpssThinWrapper.spssReadCaseRecordDelegate"/>
  1577. /// using the same file handle because both procedures read a new case from the data file.
  1578. /// </remarks>
  1579. public static ReturnCode spssWholeCaseIn(int handle, out string caseRec)
  1580. {
  1581. // Fetch the size of each case to set an appropriately sized buffer
  1582. int caseSize;
  1583. ReturnCode result = spssGetCaseSizeImpl(handle, out caseSize);
  1584. if (result != ReturnCode.SPSS_OK)
  1585. {
  1586. caseRec = null;
  1587. return result;
  1588. }
  1589. caseRec = new string(' ', caseSize);
  1590. return SpssThinWrapper.spssWholeCaseInImpl(handle, ref caseRec);
  1591. }
  1592. /// <summary>
  1593. /// Writes out raw data as a case.
  1594. /// </summary>
  1595. /// <param name="handle">
  1596. /// Handle to the data file.
  1597. /// </param>
  1598. /// <param name="caseRec">
  1599. /// Case record to be written to the data file.
  1600. /// </param>
  1601. /// <returns>
  1602. /// <see cref="ReturnCode.SPSS_OK"/>,
  1603. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1604. /// <see cref="ReturnCode.SPSS_OPEN_RDMODE"/>,
  1605. /// <see cref="ReturnCode.SPSS_DICT_NOTCOMMIT"/>, or
  1606. /// <see cref="ReturnCode.SPSS_FILE_WERROR"/>.
  1607. /// </returns>
  1608. /// <remarks>
  1609. /// This function writes a case assembled by the caller to a data file. The case is assumed
  1610. /// to have been constructed correctly in the buffer caseRec, and its validity is not
  1611. /// checked. This is a fairly low-level function whose use should not be mixed with calls
  1612. /// to <see cref="SpssThinWrapper.spssCommitCaseRecordDelegate"/> using the same file handle
  1613. /// because both procedures write a new case to the data file.
  1614. /// </remarks>
  1615. public static ReturnCode spssWholeCaseOut(int handle, string caseRec)
  1616. {
  1617. return SpssThinWrapper.spssWholeCaseOutImpl(handle, ref caseRec);
  1618. }
  1619. /// <summary>
  1620. /// Gets variable sets information in a data file.
  1621. /// </summary>
  1622. /// <param name="handle">
  1623. /// Handle to the data file.
  1624. /// </param>
  1625. /// <param name="varSets">
  1626. /// Variable sets string.
  1627. /// </param>
  1628. /// <returns>
  1629. /// <see cref="ReturnCode.SPSS_OK"/>,
  1630. /// <see cref="ReturnCode.SPSS_NO_VARSETS"/>,
  1631. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  1632. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1633. /// </returns>
  1634. /// <remarks>
  1635. /// This function reports the variable sets information in the data file.
  1636. /// </remarks>
  1637. unsafe public static ReturnCode spssGetVariableSets(int handle, out string varSets)
  1638. {
  1639. char* cVarSets;
  1640. ReturnCode result = SpssThinWrapper.spssGetVariableSetsImpl(handle, out cVarSets);
  1641. try
  1642. {
  1643. if (result == ReturnCode.SPSS_OK)
  1644. varSets = Marshal.PtrToStringAnsi(new IntPtr(cVarSets));
  1645. else
  1646. varSets = null;
  1647. return result;
  1648. }
  1649. finally
  1650. {
  1651. if (cVarSets != null)
  1652. spssFreeVariableSetsImpl(cVarSets);
  1653. }
  1654. }
  1655. /// <summary>
  1656. /// Reports TRENDS date variable information.
  1657. /// </summary>
  1658. /// <param name="handle">
  1659. /// Handle to the data file.
  1660. /// </param>
  1661. /// <param name="dateInfo">
  1662. /// Pointer to first element of the allocated array.
  1663. /// </param>
  1664. /// <returns>
  1665. /// <see cref="ReturnCode.SPSS_OK"/>,
  1666. /// <see cref="ReturnCode.SPSS_NO_DATEINFO"/>,
  1667. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  1668. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1669. /// </returns>
  1670. /// <remarks>
  1671. /// This function reports the TRENDS date variable information, if any, in an SPSS data file.
  1672. /// It places the information in a dynamically allocated long array, sets *numofElements to
  1673. /// the number of elements in the array, and sets *dateInfo to point to the array. The caller is
  1674. /// expected to free the array by calling <see cref="SpssThinWrapper.spssFreeDateVariablesDelegate"/> when it is no longer needed.
  1675. /// The variable information is copied directly from record 7, subtype 3. Its first six elements
  1676. /// comprise the "fixed" information, followed by a sequence of one or more three-element
  1677. /// groups.
  1678. /// </remarks>
  1679. unsafe public static ReturnCode spssGetDateVariables(int handle, int[] dateInfo)
  1680. {
  1681. int* cDateInfo;
  1682. int numofElements;
  1683. ReturnCode result = SpssThinWrapper.spssGetDateVariablesImpl(handle, out numofElements, out cDateInfo);
  1684. try
  1685. {
  1686. if (result == ReturnCode.SPSS_OK)
  1687. {
  1688. dateInfo = new int[numofElements];
  1689. for (int i = 0; i < numofElements; i++)
  1690. dateInfo[i] = cDateInfo[i];
  1691. }
  1692. return result;
  1693. }
  1694. finally
  1695. {
  1696. if (cDateInfo != null)
  1697. spssFreeDateVariablesImpl(cDateInfo);
  1698. }
  1699. }
  1700. /// <summary>
  1701. /// Retrieves the definitions from a data file.
  1702. /// </summary>
  1703. /// <param name="handle">
  1704. /// Handle to the data file.
  1705. /// </param>
  1706. /// <param name="mrespDefs">
  1707. /// Returned string.
  1708. /// </param>
  1709. /// <returns>
  1710. /// <see cref="ReturnCode.SPSS_OK"/>,
  1711. /// <see cref="ReturnCode.SPSS_NO_MULTRESP"/>,
  1712. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>, or
  1713. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1714. /// </returns>
  1715. /// <remarks>
  1716. /// This function retrieves the definitions from an SPSS data file. The definitions are stored
  1717. /// as a null-terminated ASCII string which is very similar to that containing the variable
  1718. /// set definitions. The memory allocated by this function to contain the string must be freed
  1719. /// by calling <see cref="SpssThinWrapper.spssFreeMultRespDefsDelegate"/>. If the file contains no multiple response definitions,
  1720. /// *mrespDefs is set to NULL, and the function returns the warning code
  1721. /// <see cref="ReturnCode.SPSS_NO_MULTRESP"/>.
  1722. /// </remarks>
  1723. unsafe public static ReturnCode spssGetMultRespDefs(int handle, out string mrespDefs)
  1724. {
  1725. char* cMrespDefs;
  1726. ReturnCode result = SpssThinWrapper.spssGetMultRespDefsImpl(handle, out cMrespDefs);
  1727. try
  1728. {
  1729. if (result == ReturnCode.SPSS_OK)
  1730. mrespDefs = Marshal.PtrToStringAnsi(new IntPtr(cMrespDefs));
  1731. else
  1732. mrespDefs = null;
  1733. return result;
  1734. }
  1735. finally
  1736. {
  1737. if (cMrespDefs != null)
  1738. spssFreeMultRespDefsImpl(cMrespDefs);
  1739. }
  1740. }
  1741. /// <summary>
  1742. /// Gets a list of all response values and labels for a numeric variable.
  1743. /// </summary>
  1744. /// <param name="handle">
  1745. /// Handle to the data file.
  1746. /// </param>
  1747. /// <param name="varName">
  1748. /// Variable name.
  1749. /// </param>
  1750. /// <param name="values">
  1751. /// Array of values.
  1752. /// </param>
  1753. /// <param name="labels">
  1754. /// Array of labels.
  1755. /// </param>
  1756. /// <returns>
  1757. /// <see cref="ReturnCode.SPSS_OK"/>,
  1758. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  1759. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1760. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1761. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1762. /// <see cref="ReturnCode.SPSS_NUME_EXP"/>, or
  1763. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1764. /// </returns>
  1765. /// <remarks>
  1766. /// This function gets the set of labeled values and associated labels for a numeric variable.
  1767. /// The number of values is returned as *numLabels. Values are stored into an array of
  1768. /// *numLabels double elements, and *values is set to point to the first element of the array.
  1769. /// The corresponding labels are structured as an array of *numLabels pointers, each pointing
  1770. /// to a char string containing a null-terminated label, and *labels is set to point to the
  1771. /// first element of the array.
  1772. /// The two arrays and the label strings are allocated on the heap. When they are no longer
  1773. /// needed, <see cref="SpssThinWrapper.spssFreeVarNValueLabelsDelegate"/> should be called to free the memory.
  1774. /// </remarks>
  1775. unsafe public static ReturnCode spssGetVarNValueLabels(int handle, string varName, out double[] values, out string[] labels)
  1776. {
  1777. double* cValues;
  1778. char** cLabels;
  1779. int numLabels;
  1780. ReturnCode result = SpssException.ThrowOnFailure(SpssThinWrapper.spssGetVarNValueLabelsImpl(handle, ref varName, out cValues, out cLabels, out numLabels), "spssGetVarNValueLabels", ReturnCode.SPSS_NO_LABELS);
  1781. if (result == ReturnCode.SPSS_NO_LABELS)
  1782. {
  1783. values = new double[0];
  1784. labels = new string[0];
  1785. }
  1786. else
  1787. { // ReturnCode.SPSS_OK
  1788. values = new double[numLabels];
  1789. labels = new string[numLabels];
  1790. for (int i = 0; i < numLabels; i++)
  1791. {
  1792. values[i] = cValues[i];
  1793. labels[i] = Marshal.PtrToStringAnsi(new IntPtr(cLabels[i]));
  1794. }
  1795. spssFreeVarNValueLabels(cValues, cLabels, numLabels);
  1796. }
  1797. return result;
  1798. }
  1799. /// <summary>
  1800. /// Gets the list of response values and labels for a variable.
  1801. /// </summary>
  1802. /// <param name="handle">
  1803. /// Handle to the data file.
  1804. /// </param>
  1805. /// <param name="varName">
  1806. /// Variable name.
  1807. /// </param>
  1808. /// <param name="values">
  1809. /// Array of values.
  1810. /// </param>
  1811. /// <param name="labels">
  1812. /// Array of labels.
  1813. /// </param>
  1814. /// <returns>
  1815. /// <see cref="ReturnCode.SPSS_OK"/>,
  1816. /// <see cref="ReturnCode.SPSS_NO_LABELS"/>,
  1817. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1818. /// <see cref="ReturnCode.SPSS_INVALID_VARNAME"/>,
  1819. /// <see cref="ReturnCode.SPSS_VAR_NOTFOUND"/>,
  1820. /// <see cref="ReturnCode.SPSS_STR_EXP"/>,
  1821. /// <see cref="ReturnCode.SPSS_SHORTSTR_EXP"/>, or
  1822. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1823. /// </returns>
  1824. /// <remarks>
  1825. /// This function gets the set of labeled values and associated labels for a short string variable.
  1826. /// The number of values is returned as *numLabels. Values are stored into an array
  1827. /// of *numLabels pointers, each pointing to a char string containing a null-terminated
  1828. /// value, and *values is set to point to the first element of the array. Each value string is as
  1829. /// long as the variable. The corresponding labels are structured as an array of *numLabels
  1830. /// pointers, each pointing to a char string containing a null-terminated label, and *labels is
  1831. /// set to point to the first element of the array.
  1832. /// The two arrays and the value and label strings are allocated on the heap. When they
  1833. /// are no longer needed, <see cref="SpssThinWrapper.spssFreeVarCValueLabelsDelegate"/> should be called to free the memory.
  1834. /// </remarks>
  1835. unsafe public static ReturnCode spssGetVarCValueLabels(int handle, string varName, out string[] values, out string[] labels)
  1836. {
  1837. char** cValues;
  1838. char** cLabels;
  1839. int numLabels;
  1840. ReturnCode result = SpssException.ThrowOnFailure(SpssThinWrapper.spssGetVarCValueLabelsImpl(handle, ref varName, out cValues, out cLabels, out numLabels), "spssGetVarCValueLabels", ReturnCode.SPSS_NO_LABELS);
  1841. if (result == ReturnCode.SPSS_NO_LABELS)
  1842. {
  1843. values = new string[0];
  1844. labels = new string[0];
  1845. }
  1846. else
  1847. { // ReturnCode.SPSS_OK
  1848. values = new string[numLabels];
  1849. labels = new string[numLabels];
  1850. for (int i = 0; i < numLabels; i++)
  1851. {
  1852. values[i] = Marshal.PtrToStringAnsi(new IntPtr(cValues[i]));
  1853. labels[i] = Marshal.PtrToStringAnsi(new IntPtr(cLabels[i]));
  1854. }
  1855. SpssThinWrapper.spssFreeVarCValueLabelsImpl(cValues, cLabels, numLabels);
  1856. }
  1857. return result;
  1858. }
  1859. /// <summary>
  1860. /// Reports on all the variables in a data file, including names and types.
  1861. /// </summary>
  1862. /// <param name="handle">
  1863. /// Handle to the data file
  1864. /// </param>
  1865. /// <param name="varNames">
  1866. /// The array to fill with variable names
  1867. /// </param>
  1868. /// <param name="varTypes">
  1869. /// The array to fill with variable types
  1870. /// </param>
  1871. /// <returns>
  1872. /// <see cref="ReturnCode.SPSS_OK"/>,
  1873. /// <see cref="ReturnCode.SPSS_INVALID_HANDLE"/>,
  1874. /// <see cref="ReturnCode.SPSS_INVALID_FILE"/>, or
  1875. /// <see cref="ReturnCode.SPSS_NO_MEMORY"/>.
  1876. /// </returns>
  1877. /// <remarks>
  1878. /// This function gets the names and types of all the variables present in a data file.
  1879. /// The type code is an integer in the range 0-255, 0 indicating a numeric
  1880. /// variable and a positive value indicating a string variable of that size.
  1881. /// </remarks>
  1882. unsafe public static ReturnCode spssGetVarNames(int handle, out string[] varNames, out int[] varTypes)
  1883. {
  1884. int numVars;
  1885. char** cVarNames;
  1886. int* cVarTypes;
  1887. ReturnCode result = SpssThinWrapper.spssGetVarNamesImpl(handle, out numVars, out cVarNames, out cVarTypes);
  1888. if (result != ReturnCode.SPSS_OK)
  1889. {
  1890. varNames = null;
  1891. varTypes = null;
  1892. }
  1893. else // all is well
  1894. {
  1895. varNames = new string[numVars];
  1896. varTypes = new int[numVars];
  1897. for (int i = 0; i < numVars; i++)
  1898. {
  1899. varNames[i] = Marshal.PtrToStringAnsi(new IntPtr(cVarNames[i]));
  1900. varTypes[i] = cVarTypes[i];
  1901. }
  1902. spssFreeVarNamesImpl(cVarNames, cVarTypes, numVars);
  1903. }
  1904. return result;
  1905. }
  1906. #region Obsolete, exception throwing wrappers for SPSS functions
  1907. [Obsolete("Use spssSetVarWriteFormat instead.")]
  1908. public static void SetVarWriteFormat(int handle, string varName, FormatTypeCode writeType, int writeDec, int writeWidth)
  1909. {
  1910. SpssException.ThrowOnFailure(spssSetVarWriteFormat(handle, varName, writeType, writeDec, writeWidth), "spssSetVarWriteFormat");
  1911. }
  1912. [Obsolete("Use spssSetVarPrintFormat instead.")]
  1913. public static void SetVarPrintFormat(int handle, string varName, FormatTypeCode printType, int printDec, int printWidth)
  1914. {
  1915. SpssException.ThrowOnFailure(spssSetVarPrintFormat(handle, varName, printType, printDec, printWidth), "spssSetVarPrintFormat");
  1916. }
  1917. [Obsolete("Use spssSetVarName instead.")]
  1918. public static void SetVarName(int handle, string varName, int varType)
  1919. {
  1920. SpssException.ThrowOnFailure(spssSetVarName(handle, varName, varType), "spssSetVarName");
  1921. }
  1922. [Obsolete("Use spssSetVarLabel instead.")]
  1923. public static void SetVarLabel(int handle, string varName, string varLabel)
  1924. {
  1925. SpssException.ThrowOnFailure(spssSetVarLabel(handle, varName, varLabel), "spssSetVarLabel");
  1926. }
  1927. [Obsolete("Use spssSetVarNValueLabel instead.")]
  1928. public static void SetVarNValueLabel(int handle, string varName, double value, string label)
  1929. {
  1930. SpssException.ThrowOnFailure(spssSetVarNValueLabel(handle, varName, value, label), "spssSetVarNValueLabel");
  1931. }
  1932. [Obsolete("Use spssGetVarLabel instead.")]
  1933. public static string GetVarLabel(int handle, string varName)
  1934. {
  1935. string varLabel;
  1936. SpssException.ThrowOnFailure(spssGetVarLabel(handle, varName, out varLabel), "spssGetVarLabel");
  1937. return varLabel;
  1938. }
  1939. [Obsolete("Use spssGetVarNValueLabel instead.")]
  1940. public static string GetVarNValueLabel(int handle, string varName, double value)
  1941. {
  1942. string label;
  1943. SpssException.ThrowOnFailure(spssGetVarNValueLabel(handle, varName, value, out label), "spssGetVarNValueLabel");
  1944. return label;
  1945. }
  1946. [Obsolete("Use spssGetValueChar instead.")]
  1947. public static string GetValueChar(int handle, double varHandle)
  1948. {
  1949. string value;
  1950. SpssException.ThrowOnFailure(spssGetValueChar(handle, varHandle, out value), "spssGetValueChar");
  1951. return value;
  1952. }
  1953. #endregion
  1954. }
  1955. }