Putseq

Putseq writes data on a binary file opened by Openo or Openio.

Syntax

 Putseq INTEGER_EXPR, VAR_LISTPutseq INTEGER_EXPR, VAR_LIST Using [CLASS]

Examples

 # First example: let's write strings in a binary file# The lines will have a constant length of 10# They will be padded by 0Local Schar WORDS(5)(1..10)WORDS(1)="ONE":WORDS(2)="TWO": WORDS(3)="THREE":WORDS(4)="FOUR":WORDS(5)="FIVE":WORD(6)="SIX"WORDS(9)="NINE":WORDS(10)="TEN"Openo "MYFILE",0 Using [DMP]Iomode adxium 50 Using [DMP] : # asciiPutseq 6,WORDS Using [DMP]Putseq 2,WORDS(9..10) Using [DMP]Openo Using [DMP]# The file contains now 30 caracters that are the following (null representing a null character):# 'O','N','E','null','null','T','W','O','null','null','T','H','R','E','E','F','O','U','R','null',# 'F','I','V','E','null','S','I','X','null','null','N','I','N','E','null','T','E','N','null','null'# Second example: let's write a blob in a filePutseq 1,MYBLOB : # The exact size of the blob will be written# Third example: let's append an array of Long integers in a file# These long integer are written on four bytes# We stop the writing operation when a null integer is foundSubprog WR_INT(FILE_NAME,INTEGER_ARRAY)Value Char FILE_NAME()Const Integer INTEGER_ARRAY(1..)Local Integer I# Count the number of elements to be writtenRepeat I+=1 Until I>dim(INTEGER_ARRAY) or INTEGER_ARRAY(I)=0I-=1Openo FILE_NAME,-1 Using [INTG]Putseq I,INTEGER_ARRAY Using [INTG]Openo Using [INTG]End# Fourth example: Write a multi-dimensional arrays of IntegersLocal Integer ARRAY(1..5,1..10,1..5,1..4)Call FILL_ARRAY(ARRAY)Openo "dumpfile",0# If the whole array needs to be written:# Putseq NUMBER,ARRAY will fail (only one unspecified dimension can be given)# Let's perform loopsFor I=1 to dim(ARRAY,1)For J=1 to dim(ARRAY,2)For K=1 to dim(ARRAY,3)Putseq dim(ARRAY,4),ARRAY(I,J,K)Next KNext JNext ISeek 0# Now everything is flushed

Description

Putseq allows creating ASCII or binary files that have any content.

Putseq writes a number of elements provided by the first argument on the list, by using the variables until the number of elements to be written are reached. An element is either a single variable or an element of an array.

The elements are written on the file in the internal format of the data as argument. The following table of arrays provides the format and the number of bytes written according to the data type used:

Data typeFormatNumber of bytes written
TinyIntbyte1 byte
ScharCharacters on one byte in ASCII(padded with zeros).N bytes where N is the maximum size of the string.
ShortintShort integer in big Endian format.2 bytes.
Date variableNumber of days since the [31/12/1599] as an integer in big Endian format.4 bytes.
Date when defined in an [F] classNumber of days since the [31/12/1599] as a 3-bytes integer in big Endian format.3 bytes.
Decimal value with format N.M when defined in an [F] class.Number in a BCD format that corresponds to the C-ISAM format.(N+M+E+3)/2 bytes, where E is 0 if M is even, and 1 if M is odd.
Decimal value when defined as a variableNumber in a BCD format that corresponds to the C-ISAM format with the maximum precision.16 bytes.
CharCharacter string in UCS2 format.2*N bytes where N is the maximum size of the character string.
ClbfileThe contents of the clob padded by zeros.N bytes where N is the maximum size of the CLOB (N=1024 if the Clbfile has a (0) dimension, 2048 if Clbfile has a (1) dimension, and so forth).
Blbfile (binary data)The exact content of the BLOB.The exact size of the BLOB.
Uuident (unique id)UUID in canonical format.16 bytes.
DatetimeDate time stored as an integer in big Endian.8 bytes.

Comments

The function adxseek(1) or adxseek("CLASS") if the file has been opened with a class name, gives the position, in bytes from the beginning of the file, where the next write operation will be done. The return value will be incremented every time a Putseq is performed. Its value is -1 if no file has been opened for writing.

As the write operation is buffered, the file might be completely updated only when the file is closed by [(Openo]] or Openio. It is therefore possible to flush the writing operation by using Seek 0 or Seek 0 Using [CLASS].

Associated errors

Error codeDescription
10INTEGER_EXPR is not an integer expression.
24Error during write execution.
44No more space on device.
55Too many unspecified dimension given on variables written.
65File too large (writing limits exceeded).

See also

Getseq, Rdseq, Wrseq, adxseek, Seek, Openi, Openo, Openio.