ccplib contains various low-level utility routines which are potentially machine-dependent. Since CCP4 version 5.0, the original ccplib.f has been split amongst several files. The most commonly used routines have been re-implemented in C, with a Fortran interface, while other routines remain in ccplib.f. This document describes the routines as seen from a Fortran programmer's perspective. For information on the C functions, see C libraries and CCP4 Library Utilities.
To use the pre-processor in existing code you will need to add a call to the routine CCPFYP as the first executable statement in the program. This routine performs all the pre-processing and should be called before any other CCP4 library routines.
Fortran programs should call the routine CCPFYP initially (see "USING THE PRE-PROCESSOR"), allowing one to run them using the mechanism
<program> hklin <file> hklout <file> ...
There should be no STOP statements within the code; rather, call the subroutine CCPERR. This has the form
CALL CCPERR( <num> '<string>')where <num> is an exit value (0 for normal termination) and the <string> is a suitable message. Programs should terminate successfully with the call
CALL CCPERR(0, 'Normal termination')
To terminate a program because an error has been detected use
CALL CCPERR(1, '<string>')where <string> should contain any useful information about why the program is being terminated abnormally.
CCPERR can also be used to send 'warnings' (CCPERR level 2) and messages (CCPERR level 3).
There should be no OPEN statements in Fortran code. Instead call CCPDPN for general files, and appropriate library routines for the standard data formats (MTZ, PDB, CCIF, CCP4 maps etc).
Use the normal Fortran CLOSE to close files opened with CCPDPN. The standard data formats have specific library routines for closing files which should be used in preference to CLOSE in those cases.
The version of the CCP4 library being used can be queried using the CCP4_VERSION routine. The program version number may be different, and can be set (and later retrieved) using CCP4_PROG_VERSION. A call to CCPVRS will output a banner including this version information. The command line switch -i can also be used to get program and version information.
PROGRAM <name> <declarations> C define the program version CALL CCP4_PROG_VERSION('7.2',0) C call the pre-processor: CALL CCPFYP C advertise the version: CALL CCPRCS(LUNSTO(1), '<name>', '$Date$') C open an input file: CALL CCPDPN(IN1, 'INFILE1','READONLY','F','F') . . . C close the file CLOSE(IN1) CALL CCPERR(0, 'Normal termination') END
Routine | Description |
---|---|
CCFILL | Set specified number of elements of byte array |
CCP4_VERSION | Return current CCP4 library version as string |
CCP4_PROG_VERSION | Set or retrieve program version as string |
CCPALC | Call subroutine with allocated memory |
CCPALE | Call subroutine with allocated memory set from environment |
CCPBYI | Copy array of unsigned (or signed) bytes into integer array |
CCPBYT | Indicate whether byte handling is available |
CCPCPI | Copy array of BYTE or INTEGER*2 elements into integer array |
CCPDAT | Get calendar date |
CCPDEX | Periodicity reduction of 1024 (for PROLSQ) |
CCPDPN | more friendly CCPOPN |
CCPE2I | read integer from logical name value |
CCPERR | Report error or normal termination and stop |
CCPEXS | test if file exists |
CCPFYP | Set up environment & parse command line arguments |
CCPGI2 | Get unsigned integer*2 value from 0 to 65535 from N'th unsigned integer*2 element of array. |
CCPGTB | Get unsigned byte value from 0 to 255 from N'th byte of array. |
CCPI2I | Copy an array of INTEGER*2 elements into an integer array |
CCPIBY | Copy array of integers into array of bytes. |
CCPII2 | Copy array of integers into array of INTEGER*2 elements. |
CCPLWC | Convert a string to lower case |
CCPMDE | If byte handling available return nos. of bytes for map modes |
CCPMVB | Move bytes from one non-character array to another if byte handling is available |
CCPMVI | Move words from one integer array to another |
CCPMVR | Move words from one real array to another |
CCPNUN | Return an unconnected i/o unit number |
CCPONL | See if program is being run interactively |
CCPPSF | Parse file name into components |
CCPRCS | Like CCPVRS but use RCS-format date string |
CSETNV | Associate logical name with file name |
CCPPAG | Set paging parameters if available |
CCPSI2 | Set integer value from 0 to 65535 into the N'th unsigned integer*2 element of an array. |
CCPSTB | Set integer value from 0 to 255 into N'th byte of array. |
CCPSUM | Sum the elements of an array |
CCPTIM | Get CPU and Elapsed times |
CCPTOI | Convert n'th byte or I*2 in a non-character array to an integer |
CCPUFL | Suppress underflow messages |
CCPUPC | Convert a string to upper case |
CCPVRS | Print program version number and date header |
CCPPNM | Entry: Return the program name previously set by CCPVRS |
CCPZBI | Sets an array of bytes to zero |
CCPZI | Set 'n' words of an integer array to zero using a simple loop |
CCPZR | Set 'n' words of a real array to zero using a simple loop |
FDIR | Returns the directory part of a file name |
FEXTN | Returns the extension of a file name |
FROOT | Returns the root of a file name |
LITEND | determine endianness |
LENSTR | length of string to last non-space |
LUNSTI | Get logical unit number for input |
LUNSTO | Get logical unit number for output |
NBITST | Return the (unsigned) integer value held within a bit field in a word |
NOCRLF | write line suppressing cr/lf to standard output |
QPRINT | write debug messages |
QPRLVL | Entry: Return debug level used by QPRINT. |
STBITS | Set a bit field within a word to a given (unsigned) integer value |
CCPLIC | Check that license conditions have been agreed |
ARR1 | (o) | (byte) | array to which bytes are to be copied |
SCAL | (i) | (byte) | byte value to be copied into ARR1 |
NTIMES | (i) | (integer) | the number of bytes to be copied |
VERSION | (o) | (character*(*)) | current version of CCP4 suite |
VERSION | (i/o) | (character*(*)) | version of individual program |
IFLAG | (i) | (integer) | if 0 then set version using VERSION argument, else if 1 then return version in VERSION argument |
call ccpalc (fred, 3, types, lens)with types = (/'i', 'r', 'c'/) and lens = (/1000, 2000, 3000/). This effectively does
call fred (1000, arr1, 2000, arr2, 3000, arr3)with
subroutine fred (n1, foo, n2, bar, n3, baz) integer n1, n2, n3, foo (n1) real bar (n2) complex baz (n3) ...Obviously all communication with ROUTNE must be by COMMON (or, possibly, extra ENTRYs). The allocated memory is freed on return from ROUTNE. As a concession, it's initially filled with zeroed bytes.
ROUTNE | (i) | (external) | routine to call | ||||
N | (i) | (integer) | number of arguments to ROUTNE (<=12) | ||||
TYPE | (i) | (character*1 (*)) | LENGTH | (i) | (integer*(*))
| number of elements in each (array) argument of ROUTNE
| |
ROUTNE | (i) | (external) | routine to call | ||||||||||||
N | (i) | (integer) | number of arguments to ROUTNE (<=12) | ||||||||||||
TYPE | (i) | (character*1 (*)) | LENGTH | (i) | (character*(*))
| logical names representing the
number of elements in each (array) argument of ROUTNE
| LENDEF | (i) | (integer (*))
| default lengths for the argument
arrays used if the appropriate LENGTH argument doesn't
represent a defined logical
| PRINT | (i) | (logical)
| whether or not to print the values of the array lengths
| |
IA | (o) | (integer) | array to return integer values |
IBYT | (i) | (byte) | array holding byte data (may be an integer array, for example, with data packed into adjacent bytes). |
NB | (i) | (integer) | if >0, the number of unsigned bytes to be copied if <0, -the number of signed bytes to be copied |
NBW (o) (integer)
Returns CCPBYT | == .TRUE. | byte handling and associated ccplib routines available (assumed). |
== .FALSE. | no byte handling available. |
IA | (o) | (integer (*)) | to return values |
IB | (i) | (integer (*)) | holding data with data packed into adjacent BYTE or INTEGER*2 elements (in routine is byte) |
MINEL | (i) | (integer) | Minimum element to copy |
MAXEL | (i) | (integer) | Maximum element to copy |
ITYP | (i) | (integer) | Type =1 unsigned byte =2 signed byte =3 unsigned two byte integer =4 signed two byte integer |
CALDAT | (o) | (character*8) | variable returning date as dd/mm/yy (returned as a blank string if not available). |
INDX | (i/o) | (integer) | array holding numbers for periodicity reduction |
N | (i) | (integer) | no. of elements in INDX |
IUN | (i) (integer) | unit number | |||||||||
LOGNAM | (i) (character*(*)) | logical file name | |||||||||
STATUS | (i) (character*(*)) | TYPE | (i) (character*(*))
| LREC | (i) (integer)
| record length for direct access file (no. of
characters for a formatted file or words for
an unformatted file). | Not relevant for a sequential file. IFAIL | (i/o) (integer)
| | |
NAME | (I) | (character *(*)) |
DEFVAL | (I) | (integer) |
ISTAT | (I) | (integer) | exit status (0 for normal termination, 1 for fatal error) |
ERRST | (I) | (character)*(*) | message |
NAME | (i) (character*(*)) | file name/logical name |
Returns CCPEXS == | .TRUE. if file exists |
.FALSE. if file does not exist |
Note: A call to CCPFYP should be the first executable statement in ccp4 programs.
IVAL | (o) | (integer) | returned integer values from 0 to 65535 |
IA | (i) | (integer*2(*)) | array from which the unsigned INTEGER*2 value is to be retrieved |
N | (i) | (integer) | position in 'IA' where the unsigned INTEGER*2 value is to be retrieved |
IVAL | (o) | (integer) | the returned integer value from 0 to 255 |
IA | (i) | (byte(*)) | array from which the byte value is to be retrieved |
N | (i) | (integer) | position in IA where the byte value is to be retrieved |
IA | (o) | (integer(*)) | Array to return INTEGER values |
I2 | (i) | (integer*2) | Array holding INTEGER*2 data (may be an INTEGER array for example with data packed into adjacent INTEGER*2 elements). |
NE | (i) | (integer) | The number of elements to be copied |
SIGNED | (i) | (logical) | ==.TRUE. Copy as signed INTEGER*2 values ==.FALSE. Copy as unsigned INTEGER*2 values |
SWAPB | (i) | (logical) | ==.TRUE. Swap bytes in the INTEGER*2 elements ==.FALSE. Do not swap bytes |
IBYT | (o) | (byte(*)) | Array returning byte data (may be an integer array for example with data packed into adjacent bytes). |
IA | (i) | (integer(*)) | array holding integer values |
NB | (i) | (integer) | if >0, the number of elements to be
copied to unsigned bytes if <0, -the number of elements to be copied to signed bytes |
I2 | (o) | (integer*2) | Array returning INTEGER*2 data (may be an INTEGER array for example with data packed into adjacent INTEGER*2 elements |
IA | (i) | (integer(*)) | Array holding INTEGER values |
NE | (i) | (integer) | The number of elements to be copied |
SIGNED | (i) | (logical) | ==.TRUE. Copy as signed integer*2 values ==.FALSE. Copy as unsigned integer*2 values |
SWAPB | (i) | (logical) | ==.TRUE. Swap bytes in the integer*2 elements ==.FALSE. Do not swap bytes |
STRING | (i/o) | (character*(*)) |
MODE | (i) | (integer) | = 0, bytes = 1, short (2 byte) integers = 2, real/integer (single word) = 3, short complex (2 * 2 byte integers) = 4, complex (two words) |
NBYT | (o) ( | integer) | |
Typical values: | 1 2 4 4 8 | if byte handling available with 4 bytes/word |
0 0 1 0 2 | if byte handling unavailable |
ARR1 | (i/o) | (byte(*)) | Array to which bytes are to be copied |
I1 | (i) | (integer) | The start byte number in ARR1 where bytes are to be copied |
ARR2 | (i) | (byte(*)) | Array from which bytes are to be copied |
I2 | (i) | (integer) | The start byte number in ARR2 from which the bytes are to be copied |
NTOMOV | (i) | (integer) | The number of bytes to be copied |
ARR1 | (o) | (integer(*)) |
ARR2 | (i) | (integer(*)) |
NUM | (i) | (integer) |
ARR1 | (o) | (real(*)) |
ARR2 | (i) | (real(*)) |
NUM | (i) | (integer) |
IDUM | (i) | (integer) | Dummy parameter |
Returns | .TRUE. | if program is being run on-line |
.FALSE. | if batch mode or status unknown |
FILNAM | (i) | (character*(*)) | file name string (no embedded blanks assumed) |
PATH | (o) | (character*(*)) | returns path or,
for VAX VMS the part of the file specification
up to the end of the directory specification
(includes terminating ] or : or /)
(blank if none) |
NAME | (o) | (character*(*)) | returns name (blank if none) |
TYPE | (o) | (character*(*)) | returns file type/extension (blank if none) |
VERS | (o) | (character*(*)) | returns the version (blank if none) |
After the removal of the path and version parts of the string then, if there is at least one dot, the name is the string up to the last dot remaining and the type is the part of the string after the dot. If no dot is present then the remaining string is the name and the type is blank.
Interface to CCPVRS passing date in dd/mm/yy
format (DATE). Takes RCS-format date string, e.g.
'$Date$' or its form expanded with
RCS option `-kv', as for a CVS export, in which case it will
have the leading `$Date$' stripped.
Initially, RCSDAT should be '$Date$'.
See the RCS documentation.
ILP | (i) | (integer) | Unit number of printer output |
PROG | (i) | (character*(*)) | Variable holding program name (max of 10 characters) |
VDATE | (i) | (character*(*)) | Character variable holding RCS date string |
LNAME | (i) | (character*(*)) | Logical name (environment variable). |
FILNAM | (i) | (character*(*)) | File name, if extension is omitted it is appended |
ENAME | (i/o) | (character(150)*20) | list of environment variables; if LNAME is not in list it is appended (also to ETYPE & EXTN arrays). |
ETYPE | (i/o) | (character(150)*5) | list of in/out types. |
EXTN | (i/o) | (character(150)*4) | list of extensions. |
ICOUNT | (i/o) | (integer) | lengths of arrays ENAME, ETYPE & EXTN. |
LSKIP | (i) | (logical) | if .TRUE. existing name not re-defined. |
IUN | (i) | (integer) | Fortran unit number |
NCOL | (o) | (integer) | number of columns in the page |
NLIN | (o) | (integer) | number of lines in the page |
Note: Returns 80,132 unless output is terminal whence 0,80.
IVAL | (i) | (integer) | Unsigned integer value. Should be in range 0 to 65535 |
IA | (o) | (integer*2(*)) | Array into which the unsigned INTEGER*2 value is to be inserted |
N | (i) | (integer) | Position in IA where the unsigned INTEGER*2 value is to be inserted |
IVAL | (i) | (integer) | Unsigned integer, value from 0 to 255 |
IA | (o) | (byte*2(*)) | Array into which the byte value is to be inserted |
N | (i) | (integer) | Position in IA where the byte value is to be inserted |
A | (i) | (real(N)) | Array to be summed |
N | (i) | (integer) | dimension of the array |
L | (i) | (integer) | sum every L'th element |
IFLAG | (i/o) | (integer) | == 0, initialise <> 0, return times (documented 1, also -1 for dummy call which is not implemented) |
CPU | (o) | (real) | cpu time in seconds |
ELAPS | (o) | (real) | elapsed time in seconds |
ARRAY | (i) | (real(*)) | Real array containing the element to be extracted | ||||
N | (i) | (integer) | Number of element to be converted | ||||
II | (i) | (integer) | extracted value | ||||
ITYP | (i) | (integer) | FAIL
| (i/o)
| (integer)
| | |
STRING | (i/o) | (character*(*)) | String to be converted |
ILP | (i) | (integer) | Unit number of printer output |
PROG | (i) | (character*(*)) | Variable holding program name (max of 10 characters) |
VDATE | (i) | (character*(*)) | Character variable holding date of the current version as dd/mm/yy |
NAME | (o) | (character*(*)) | Program name |
ARR1 | (i/o) | (byte(*)) |
NUM | (i) | (integer) |
IARR1 | (i/o) | (integer(*)) |
NUM | (i) | (integer) |
ARR1 | (i/o) | (real(*)) |
NUM | (i) | (integer) |
FILNAM | (i) | (character*(*)) | filename |
FILNAM | (i) | (character*(*)) | filename |
FILNAM | (i) | (character*(*)) | filename |
Returns | .TRUE. | if little endian (VAX, FX2800, Ultrix, Convex) |
.FALSE. | if big endian (IBM,IRIS,ESV) |
STRING | (i) | (character*(*) |
IWORD | (i) | (integer) | The word containing the bits to be examined |
LSB | (i) | (integer) | The least significant bit offset for the bit field |
NBITS | (i) | (integer) | The number of bits in the bit field (Must be less than the word length) |
LINE | (i) | (character*(*)) | Line to output. |
IFLAG | (i) | (integer) | debug level 0-9 higher numbers give more output |
MSG | (i) | (character*(*)) | the output message itself |
IWORD | (i/o) | (integer) | The word in which the bits are to be set |
LSB | (i) | (integer) | The least significant bit offset for the bit field |
NBITS | (i) | (integer) | The number of bits in the bit field (must be less than the word length) |
IVAL | (I) | (integer) | The unsigned integer value to be set in the bit field (The user should ensure that this value will fit within the requested bit field) |
NAME | (i) | (character*(*)) | Which license to test for. Only CCP4 currently works. |