📄 vnd.par.lib
字号:
for(i=0;i<N[0];i++) buf[i]=i + j*100 + k*10000; VNDrw('w',0,vnd,0,key,0,(char *)buf,0,1,N[0], 1,"writing 1st dimension (0)"); } } fprintf(stdout,"\nRead slices along second dimension with k=1 \n"); fprintf(stdout,"Values should equal i+j*100+k*10000\n"); fprintf(stdout,"so for this test, the values in buf should\n"); fprintf(stdout,"increment by 100. Each line should increment\n"); fprintf(stdout,"by 1. Since k=1, the starting value is 10000.\n"); key[2]=1; for(i=0;i<N[0];i++) { key[0]=i; VNDrw('r',0,vnd,1,key,0,(char *)buf,0,1,N[1], 2,"reading 2nd dimension (1)"); printf(" First Dimension = %d Values 0-4 = %ld %ld %ld %ld %ld\n i,buf[0],buf[1],buf[2],buf[3],buf[4]); } fprintf(stdout,"\nRead data slices in first dimension\n"); fprintf(stdout,"so that values on a line increment by 1\n"); key[2]=0; fprintf(stdout,"Third dimension is fixed with k=%ld\n",key[2]); fprintf(stdout,"Second dimension varies in reverse order\n"); fprintf(stdout,"so lines will decrement by 100.\n"); for(j=N[1]-1;j>=0;j--) { key[1]=j; VNDrw('r',0,vnd,0,key,0,(char *)buf,0,1,N[0], 3,"reading 1st dimension in reverse order"); printf(" Second Dimension = %d Values 0-4 = %ld %ld %ld %ld %ld\n j,buf[0],buf[1],buf[2],buf[3],buf[4]); } fprintf(stdout,"\nRead data slices in third dimension\n"); fprintf(stdout,"so values on a line should increment by 10000\n"); key[0]=41; fprintf(stdout,"First dimension is fixed with i=%ld\n",key[0]); fprintf(stdout,"Second dimension varies so that successive\n"); fprintf(stdout,"should increment by 100\n"); for(j=0;j<N[1];j++) { key[1]=j; VNDrw('r',0,vnd,2,key,0,(char *)buf,0,1,N[2], 4,"reading 3rd dimension"); printf(" Second Dimension = %d Values 0-4 = %ld %ld %ld %ld %ld\n j,buf[0],buf[1],buf[2],buf[3],buf[4]); } VNDcl(vnd,1); return (0);}Utility routines used internally by VNDop, VNDrw, and VNDcl:int VNDGetDimensions(VND *vnd, long lwmax, int ich)int VNDrwslice(VND *vnd, char *w, char mode, int idim, long islice, long ipanel)int VNDseek(VND *vnd, long ib)void VNDdump(VND *vnd,FILE *fp)int VNDGetDimensions(VND *vnd, long lwmax, int ich) Set dimensions for block matrix transpose in VND control structure. Initialize: vnd.NumBlocksPerPanel vnd.NumBytesMemBuf vnd.NumBytesPerBlock vnd.NumBytes1stDim vnd.NumNodesPerBlock vnd.NNodesPerBlock[k] for k=0 to NumDim-1 vnd.NBlocks[k] vnd.ByteIncr[k] vnd.BlockIncr[k] VND *vnd VND control structure Values required to be set on input include vnd.N[k] and vnd.NumBytesPerNode long lwmax number of characters of memory available int ich 1 if force even number of first dimension nodes per block (useful to allow real-to-complex ffts and make it possible to change number of bytes per node at a later point) return -1 if all fits in memory 0 if successful in partitioning to fit in memory 1 if failed to partition so fits in memoryint VNDrwslice(VND *vnd,int iopanel, char mode, int idim, long iblock, long ipanel) Read or write a slice for dimension idim into or from memory VND *vnd pointer to VND control structure int iopanel open panel counter (0 based. Always equals 0 if only one panel open at a time.) char mode 'r' for read; 'w' for write. int idim Dimension of slice to be read or written. (0 based. First dimension is idim=0.) long iblock Starting block for block matrix transpose slice associated with dimension idim. (Be careful--not sequential 0,1,2,...) long ipanel Panel number (0 based) for desired slice. Function returns a value of 0 if successful.int VNDseek(VND *vnd, long ib) Seek the desired block in VND file structure. (a) Go to the correct physical file, reopen if necessary (b) Seek the correct starting byte within the file VND *vnd pointer to VND control structure long ib desired block number (0 based, covers all panels and all files) The function returns 0 if successful, Nonzero if fail.void VNDdump(VND *vnd,FILE *fp) Dump out values stored in VND structure to file. VND *vnd pointer to VND control structure FILE *fp FILE pointer associated with output filevoid VNDerr(char *msg); Abort and print message. char *msg message to print prior to abort.This is the Fortran user interface to the VND routines.VNDOP(vnd, mode, lwmax, ndim, N, npanels, nbytes, file, ndir, dir, noppanels) Open block matrix file structure. int vnd returns as pointer to filled out I/O control structure integer mode 0 for read only 1 for read and write (existing file) 2 for write and read (create new file) 3 for don't open, just compute buffer sizes and fill out structure integer lwmax Maximum memory buffer size in nodes to use integer ndim Number of block matrix transpose dimensions integer N[ndim] List of number of nodes for each dimension integer npanels Number of panels of block matrix structure integer nbytes Number of bytes per node character*80 file File name from which other file names will be constructed. The actual files used will have .VND0, .VND1, ... extentions. This name should not have such an extention. integer ndir Number of file directories available for holding data. Set ndir=0 to use one file in current directory. Set ndir=-1 to look at .VND file for directories to use. File format is "number of directories" on first line and then one line per directory name. character*80 dir[] list of directories for VND files int noppanels Max number of panels to be open at one timeVNDRW(iop, iopanel, vnd, idim, key, ipanel, values, start, incr, nvalues, msgnum) Read or write a vector for dimension "idim" character*1 iop "r" for read; "w" for write integer iopanel Index of current open panel buffer (Ranges from 1 to noppanels. Used to allow access to multiple panels simultaneously. For most applications, noppanels = 1 and iopanel will always equal 1.) integer vnd Structure holding block matrix file information. integer idim Current dimension for read or write (idim=1 for first dimension.) integer key[] List of node positions for each dimension (Value for dimension "idim" needs to be there but it's value is irrelevant.) integer ipanel Panel number for read or write. (ipanel=1 for first panel.) integer values[]Returns as values read or input as values to be written. integer start starting node (First node is 1, usually equals 1) integer incr node increment (usually 1) integer nvalues number of values to read or write (usually same as number of values in the specified dimension) integer msgnum A message number to be written out if error occurs.VNDCL(vnd, mode) Close VND file structure. integer vnd Structure holding VND block matrix file information. integer mode 0 means keep 1 means deleteVNDFLUSH(vnd) Flush out VND buffers to file. This may be important in applications where checkpoint/restart capabilities are needed. After VNDFLUSH, the data written by the VNDRW routine are safely stored on disk rather than just in a memory buffer where it could be lost in the event of a machine failure. integer vnd VND control structureAn example Fortran code similar to the C code example aboveappears below. On the Cray (or Convex in PD8 mode), be sureto specify the bytes per node to be 8 instead of 4 in thethe VNDOP call. PROGRAM EXAMPLE INTEGER VND, N(3), KEY(3), BUF(50), I, J, K CHARACTER*80 FILE CHARACTER*80 DIR(2) FILE='GEORGE' N(1)=50 N(2)=50 N(3)=5 OPEN(10,FILE='LISTING') CALL VNDOP(VND,2,1000,3,N,1,4,FILE,-1,DIR,1) WRITE(10,*) ' ' WRITE(10,*) ' WRITE OUT THE DATA IN THE FIRST DIMENSION' WRITE(10,*) ' DATA VALUES = I + J*100 + K*10000' WRITE(10,*) ' WHERE I=1ST DIM, J=2ND DIM, AND K=3RD DIM' DO 300 K=1,N(3) KEY(3)=K DO 200 J=1,N(2) DO 100 I=1,N(1) 100 BUF(I) = I + 100*J + 10000*K KEY(2)=J CALL VNDRW('W',1,VND,1,KEY,1,BUF,1,1,N(1),1) 200 CONTINUE 300 CONTINUE WRITE(10,*) ' ' WRITE(10,*) ' READ THE DATA ALONG DIMENSION 2 ' WRITE(10,*) ' THE 3RD DIMENSION IS HELD FIXED WITH K=2' WRITE(10,*) ' VALUES ON A LINE SHOULD INCREMENT BY 100' WRITE(10,*) ' VALUES SHOULD INCREMENT BY 1 FROM LINE TO LINE' KEY(3)=2 DO 400 I=1,N(1) KEY(1)=I CALL VNDRW('R',1,VND,2,KEY,1,BUF,1,1,N(2),2) WRITE(10,*) ' I = ',I,' BUF(1-5)=',(BUF(J),J=1,5) 400 CONTINUE WRITE(10,*) ' ' WRITE(10,*) ' READ THE DATA ALONG DIMENSION 1' WRITE(10,*) ' THE 3RD DIMENSION IS HELD FIXED WITH K=1' WRITE(10,*) ' VALUES ON A LINE SHOULD INCREMENT BY 1' WRITE(10,*) ' VALUES SHOULD DECREMENT BY 100' KEY(3)=1 DO 500 J=1,N(2) KEY(2)=N(2)+1-J CALL VNDRW('R',1,VND,1,KEY,1,BUF,1,1,N(1),3) WRITE(10,*) ' J = ',KEY(2),' BUF(1-5)=',(BUF(I),I=1,5) 500 CONTINUE WRITE(10,*) ' ' WRITE(10,*) ' READ THE DATA ALONG DIMENSION 3' WRITE(10,*) ' THE 1ST DIMENSION IS HELD FIXED WITH I=41 ' WRITE(10,*) ' VALUES ON A LINE SHOULD INCREMENT BY 10000' WRITE(10,*) ' VALUES SHOULD INCREMENT BY 100 FROM LINE TO LINE' KEY(1)=41 DO 600 J=1,N(2) KEY(2)=J CALL VNDRW('R',1,VND,3,KEY,1,BUF,1,1,N(3),4) WRITE(10,*) ' J = ',J,' BUF(1-5)=',(BUF(K),K=1,5) 600 CONTINUE CALL VNDCL(VND,1) CLOSE(10) STOP ENDCredits: J.E. Anderson (CSM Mobil Visiting Scientist, 1993)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -