/usr/share/doc/libcnf-dev/html/node38.html is in libcnf-dev 4.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>CHARACTER and LOGICAL Arrays</TITLE>
<META NAME="description" CONTENT="CHARACTER and LOGICAL Arrays">
<META NAME="keywords" CONTENT="sun209">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="sun209.css">
<LINK REL="next" HREF="node39.html">
<LINK REL="previous" HREF="node37.html">
<LINK REL="up" HREF="node37.html">
<LINK REL="next" HREF="node39.html">
</HEAD>
<BODY >
<BR> <HR>
<A NAME="tex2html598"
HREF="node39.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
<A NAME="tex2html596"
HREF="node37.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
<A NAME="tex2html590"
HREF="node37.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> <A HREF="sun209.html#stardoccontents"><IMG
ALIGN="BOTTOM" BORDER="0" SRC="contents_motif.gif"
ALT="252"></A>
<BR>
<B> Next:</B> <A NAME="tex2html599"
HREF="node39.html">Arrays of pointer to char</A>
<BR>
<B>Up:</B> <A NAME="tex2html597"
HREF="node37.html">More on Arrays</A>
<BR>
<B> Previous:</B> <A NAME="tex2html591"
HREF="node37.html">More on Arrays</A>
<BR> <HR> <P>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION000101000000000000000"></A><A NAME="xref_character_and_logical_arrays"></A><A NAME="char_arrays"></A>
<BR>
CHARACTER and LOGICAL Arrays
</H2>
There are two versions of the macros for creating dynamic <TT>CHARACTER</TT>
and <TT>LOGICAL</TT> arrays:
<A HREF="node116.html#F77_CREATE_CHARACTER_ARRAY"><TT>F77_CREATE_CHARACTER_ARRAY</TT></A>
will create a 1-dimensional array with the given number of elements, and
<A HREF="node117.html#F77_CREATE_CHARACTER_ARRAY_M"><TT>F77_CREATE_CHARACTER_ARRAY_M</TT></A>
will create an array whose size is defined by an integer specifying the number
of dimensions and an array of integers specifying each dimension.
Similarly
<A HREF="node83.html#F77_CREATE_type_ARRAY"><TT>F77_CREATE_LOGICAL_ARRAY</TT></A>
and
<A HREF="node118.html#F77_CREATE_LOGICAL_ARRAY_M"><TT>F77_CREATE_LOGICAL_ARRAY_M</TT></A>
<P>
Consider the following example of a C program which calls a FORTRAN subroutine
which returns a <TT>CHARACTER</TT> array produced by setting to blank every
non-blank element of a given array for which the corresponding element of a
given <TT>LOGICAL</TT> array is TRUE. A <TT>LOGICAL</TT> output array is
produced with <TT>TRUE</TT> in the element corresponding with each element of
the <TT>CHARACTER</TT> array which has been reset, and <TT>FALSE</TT> elsewhere.
<P>
<A NAME="cook_reset"></A>
<DIV ALIGN="CENTER">
Example
- Import and export of arrays..
</DIV>
<FONT SIZE="-1"><BLOCKQUOTE> </FONT><PRE>
#include <stdio.h>
#include "f77.h"
F77_SUBROUTINE(str_reset)(CHARACTER_ARRAY(in), LOGICAL_ARRAY(lin),
INTEGER(dim1), INTEGER(dim2),
CHARACTER_ARRAY(out), LOGICAL_ARRAY(lout)
TRAIL(in) TRAIL(out) );
void main(){
char inarr[3][2][4]={{"Yes","No "},{" "," "},{"No ","Yes"}};
int inarr_length=4;
char outarr[3][2][4];
int outarr_length=4;
int lin[3][2]={{1,0},{1,1},{0,1}};
int lout[3][2];
DECLARE_CHARACTER_ARRAY(fin,3,2][4);
DECLARE_CHARACTER_ARRAY_DYN(fout);
DECLARE_LOGICAL_ARRAY(flin,3][2);
DECLARE_LOGICAL_ARRAY_DYN(flout);
DECLARE_INTEGER(dim1);
DECLARE_INTEGER(dim2);
int ndims=2;
int dims[2]={3,2};
int i,j;
F77_CREATE_CHARACTER_ARRAY_M(fout,3,ndims,dims);
F77_CREATE_LOGICAL_ARRAY_M(flout,ndims,dims);
(void) cnfExprta(
(char *)inarr, inarr_length, (char *)fin, fin_length, ndims, dims );
(void) cnfExpla( (int *)lin, (F77_LOGICAL_TYPE *)flin, ndims, dims );
dim1 = dims[0];
dim2 = dims[1];
F77_CALL(str_reset)( CHARACTER_ARRAY_ARG(fin), LOGICAL_ARRAY_ARG(flin),
INTEGER_ARG(&dim1), INTEGER_ARG(&dim2),
CHARACTER_ARRAY_ARG(fout), LOGICAL_ARRAY_ARG(flout)
TRAIL_ARG(fin) TRAIL_ARG(fout) );
(void) cnfImprta
( fout, fout_length, outarr[0][0], outarr_length, ndims, dims );
(void) cnfImpla( (F77_LOGICAL_TYPE *)flout, (int *)lout, ndims, dims );
F77_FREE_CHARACTER(fout);
F77_FREE_LOGICAL(flout);
printf("i j in lin out lout\n");
for (j=0;j<3;j++){
for (i=0;i<2;i++){
printf("%d %d %c %s %c %s\n",
i, j, lin[j][i]?'T':'F', inarr[j][i],
lout[j][i]?'T':'F', outarr[j][i] );
}
}
}
</PRE><FONT SIZE="-1"> </BLOCKQUOTE></FONT>
<P>
<FONT SIZE="-1"><BLOCKQUOTE> </FONT><PRE>
SUBROUTINE STR_RESET( ARRAY, LIN, DIM1, DIM2, OUT, LOUT )
* Purpose:
* Reset elements of an array
* Arguments:
* ARRAY(2,3)=CHARACTER*(*) (Given)
* The array to be altered
* LIN(2,3)=LOGICAL (Given)
* The given LOGICAL array
* DIM1=INTEGER (Given)
* The first dimension of the arrays
* DIM2=INTEGER (Given)
* The second dimension of the arrays
* OUT(2,3)=CHARACTER*(*) (Returned)
* LOUT(2,3)=LOGICAL (Returned)
IMPLICIT NONE
INTEGER I, J
INTEGER DIM1, DIM2
CHARACTER*(*) ARRAY(2,3)
CHARACTER*(*) OUT(2,3)
LOGICAL LIN(2,3)
LOGICAL LOUT(2,3)
DO 20, J = 1, 3
DO 10, I = 1, 2
IF( LIN(I,J) .AND. (ARRAY(I,J) .NE. ' ') )THEN
OUT(I,J) = ' '
LOUT(I,J) = .TRUE.
ELSE
OUT(I,J) = ARRAY(I,J)
LOUT(I,J) = .FALSE.
END IF
10 ENDDO
20 ENDDO
END
</PRE><FONT SIZE="-1"> </BLOCKQUOTE></FONT>
<P>
As an example of how to write a C function to be called from FORTRAN with array
arguments, the above subroutine could be re-written in C as follows:
<P>
<FONT SIZE="-1"><BLOCKQUOTE> </FONT><PRE>
#include "f77.h"
F77_SUBROUTINE(str_reset)(CHARACTER_ARRAY(in_f), LOGICAL_ARRAY(lin_f),
INTEGER(dim1), INTEGER(dim2),
CHARACTER_ARRAY(out_f), LOGICAL_ARRAY(lout_f)
TRAIL(in_f) TRAIL(out_f) )
{
GENPTR_CHARACTER_ARRAY(in_f)
GENPTR_LOGICAL_ARRAY(lin_f)
GENPTR_INTEGER(dim1)
GENPTR_INTEGER(dim2)
GENPTR_CHARACTER_ARRAY(out_f)
GENPTR_LOGICAL_ARRAY(lout_f)
int i, j, nels, cpt;
char *in_c, *out_c;
int *lin_c, *lout_c;
int ndims=2;
int dims[2];
dims[0] = *dim1;
dims[1] = *dim2;
nels = *dim1 * *dim2;
in_c = cnfCreat( nels*(in_f_length+1) );
out_c = cnfCreat( nels*(out_f_length+1) );
lin_c = (int *)malloc( nels*sizeof(int) );
lout_c = (int *)malloc( nels*sizeof(int) );
cnfImprta( in_f, in_f_length, in_c, in_f_length+1, ndims, dims );
cnfImpla( lin_f, lin_c, ndims, dims );
cpt = 0;
for(i=0;i<nels;i++){
if( *(lin_c+i) && strlen( in_c+cpt ) ) {
strcpy(out_c+cpt,"");
*(lout_c+i) = 1;
} else {
strcpy( out_c+cpt, in_c+cpt );
*(lout_c+i) = 0;
}
cpt += in_f_length+1;
}
cnfExprta( out_c, out_f_length+1, out_f, out_f_length, ndims, dims );
cnfExpla( lout_c, lout_f, ndims, dims );
cnfFree( in_c );
cnfFree( out_c );
free( lin_c );
free( lout_c );
}
</PRE><FONT SIZE="-1"> </BLOCKQUOTE></FONT>
<P>
<BR> <HR>
<A NAME="tex2html598"
HREF="node39.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
<A NAME="tex2html596"
HREF="node37.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
<A NAME="tex2html590"
HREF="node37.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> <A HREF="sun209.html#stardoccontents"><IMG
ALIGN="BOTTOM" BORDER="0" SRC="contents_motif.gif"
ALT="252"></A>
<BR>
<B> Next:</B> <A NAME="tex2html599"
HREF="node39.html">Arrays of pointer to char</A>
<BR>
<B>Up:</B> <A NAME="tex2html597"
HREF="node37.html">More on Arrays</A>
<BR>
<B> Previous:</B> <A NAME="tex2html591"
HREF="node37.html">More on Arrays</A>
<BR> <HR> <P>
<!--End of Navigation Panel-->
<ADDRESS>
<I>CNF and F77 Mixed Language Programming -- FORTRAN and C<BR>Starlink User Note 209<BR>P.M. Allan<BR>A.J. Chipperfield<BR>R.F. Warren-Smith<BR>19 January 2000<BR>E-mail:<A HREF="mailto:ussc@star.rl.ac.uk">ussc@star.rl.ac.uk</A></I>
</ADDRESS>
</BODY>
</HTML>
|