⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vnd.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 5 页
字号:
		vnd->FileDescriptor = fopen(vnd->FileNames[ifile],vnd->Mode);		if(vnd->FileDescriptor==NULL) {			fprintf(stderr,"fopen failed in VNDseek");			return(-1);		}		vnd->CurrentFile=ifile;	}else{		if(ifile!=vnd->CurrentFile){			(void) fflush(vnd->FileDescriptor);			(void) fclose(vnd->FileDescriptor);			vnd->FileDescriptor = freopen(vnd->FileNames[ifile],					vnd->Mode,vnd->FileDescriptor);			if(vnd->FileDescriptor==NULL) {				fprintf(stderr,"freopen failed in VNDseek");				return(-1);			}			vnd->CurrentFile=ifile;		}	}	ib = ib - ifile*vnd->NumBlocksPerFile;	ib = ib*vnd->NumBytesPerBlock+vnd->FirstDataByte[ifile];	ib = fseeko(vnd->FileDescriptor,(off_t) ib,SEEK_SET);	if(ib!=0){		fprintf(stderr,"fseeko failed in VNDseek");		return(-2);	}	return(0);}void VNDflush(VND *vnd)/*********************************************************************void VNDflush(VND *vnd)	Flush out VND buffers to file	VND *vnd	VND control structure**********************************************************************/{	int j,k;	for(j=0;j<vnd->NumOpenPanels;j++){		if(vnd->Modified[j]==1){			k=VNDrwslice(vnd,j,'w', 				vnd->CurrentDimension[j], 				vnd->CurrentBlock[j], 				vnd->CurrentPanel[j]);			if(k!=0){				fprintf(stderr,				"VNDflush: Error writing out old buffers");				fprintf(stderr,				"VNDflush: writing slice: idim=%d iblock=%ld ipanel=%ld\n",				vnd->CurrentDimension[j], 				vnd->CurrentBlock[j],				vnd->CurrentPanel[j]);				abort();			}		}	}	return;}void VNDrw(char iop, int iopanel,VND *vnd, int idim, 		long *key, long ipanel, char *values, 		long start, long incr, long nvalues,		int msgnum, char *msg)/********************************************************************void VNDrw(char iop, int iopanel, VND *vnd, int idim, long *key, long ipanel, 		char *values, long start, long incr, long nvalues,		int msgnum, char *msg)	Read or write a vector for dimension "idim" 	char iop	'r' for read; 'w' for write	int iopanel	Index of current open panel buffer 			(Ranges from 0 to noppanels-1.  Used to			allow access to multiple panels simultaneously.			For most applications, noppanels = 1 and 			iopanel will always equal 0.)		VND *vnd	Structure holding block matrix file information.	int idim	Current dimension for read or write			(idim=0 is first dimension)	long key[]	List of node positions for each dimension.			(Value for dimension "idim" needs to be there			but it is irrelevant.) 	long ipanel	Panel number for read or write.			(ipanel=0 is first dimension)	char values[]	Returns as values read or input as values to be 			written.	long start	starting node (0 based)	long incr	node increment (usually 1)	long nvalues	number of values to read or write 			(usually same as number of values in 			the specified dimension)	int msgnum	A message number to be written out if error occurs.	char *msg	A message to be written out if error occurs.*********************************************************************/{	int j;	int jj;	int jjj;	int k;	int incore;	long ib;	long iblock;	long ik;	long ibyte;	long iv;	long iw;	long kk;	long NumNodes;	long NBytes;	long NBytesM;	/* Find desired starting block and byte offset within block */	iblock=0;	ibyte=0;	k=0;	if(ipanel<0 || ipanel>(vnd->NumPanels-1)){		fprintf(stderr,"VNDrw: ipanel is out of range \n");		fprintf(stderr,"VNDrw: Message # %d %s \n",msgnum,msg);		fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",			iopanel,idim,ipanel);		for(jj=0;jj<vnd->NumDim;jj++){			fprintf(stderr,"      Dimension = %d  key = %ld \n",				jj,key[jj]);		}		abort();	}	if(vnd->NumDim==1 && start==0 && incr==1 && nvalues==vnd->N[0]){		j=VNDseek(vnd,ipanel);		if(j!=0){			fprintf(stderr,"VNDrw: Seek error on trace %ld \n",				ipanel);			fprintf(stderr,				"VNDrw: Message # %d %s \n",msgnum,msg);			abort();		}		if(iop=='r') {			j=(int) fread(&values[0],vnd->NumBytesPerNode,				vnd->N[0],vnd->FileDescriptor);		}else if(iop=='w'){			 j=(int) fwrite(&values[0],vnd->NumBytesPerNode,				vnd->N[0],vnd->FileDescriptor);		}		if(j!=vnd->N[0]){			fprintf(stderr,"VNDrw: I/O error on trace %ld \n",				ipanel);			fprintf(stderr,			"       Only read/wrote %d values out of %ld \n",				j,vnd->N[0]);			fprintf(stderr,				"VNDrw: Message # %d %s \n",msgnum,msg);			abort();		}		return;	}	if(iopanel<0 || iopanel>(vnd->NumOpenPanels-1)){		fprintf(stderr,"VNDWR: iopanel is out of range \n");		fprintf(stderr,"VNDrw: Message # %d %s \n",msgnum,msg);		fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",			iopanel,idim,ipanel);		for(jj=0;jj<vnd->NumDim;jj++){			fprintf(stderr,"      Dimension = %d  key = %ld \n",				jj,key[jj]);		}		abort();	}	for(j=0;j<vnd->NumDim;j++){		if(j!=idim){			if(key[j]<0 || key[j]>vnd->N[j]){				fprintf(stderr,				"VNDrw: key of %ld for dimension %d is out of range \n",				key[j],j);				fprintf(stderr,				"VNDrw: Message # %d %s \n",msgnum,msg);				fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",				iopanel,idim,ipanel);				for(jj=0;jj<vnd->NumDim;jj++){					fprintf(stderr,"      Dimension = %d  key = %ld \n",					jj,key[jj]);				}				abort();			}			ib = key[j]/vnd->NNodesPerBlock[j];			ik = key[j]-ib*vnd->NNodesPerBlock[j];			iblock=iblock+ib*vnd->BlockIncr[j];			ibyte =ibyte+ik*vnd->ByteIncr[j];			k++;		}	}	ibyte=ibyte+vnd->NumBytesMemBuf*iopanel;/*********************************************************************** 	Check to see if desired data already in memory.	If not, 	(a) write out current data in memory if it has been modified.	(b) read in desired blocks********************************************************************** */	incore=1;	if(ipanel!=vnd->CurrentPanel[iopanel]) incore=0;	if(vnd->NumBlocksPerPanel>1){		if(idim!=vnd->CurrentDimension[iopanel]) incore=0; 		if(iblock!=vnd->CurrentBlock[iopanel]) incore=0;	}	if(incore==0){		if(vnd->Modified[iopanel]==1){/*			fprintf(stdout,"writing slice: idim=%d iblock=%ld \n",				vnd->CurrentDimension[iopanel], 				vnd->CurrentBlock[iopanel]);*/			j=VNDrwslice(vnd,iopanel,'w', 				vnd->CurrentDimension[iopanel], 				vnd->CurrentBlock[iopanel], 				vnd->CurrentPanel[iopanel]);/*			VNDlook((int *)vnd->w,vnd->NumBytesMemBuf/sizeof(int) ); */			if(j!=0){				fprintf(stderr,"VNDrw: Error writing out old buffers");				fprintf(stderr,				"VNDrw: Message # %d %s \n",msgnum,msg);				fprintf(stderr,				"VNDrw: iop = %c byte = %ld iblock = %ld panel = %ld \n",				iop,ibyte, iblock, ipanel);				fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",				iopanel,idim,ipanel);				for(jj=0;jj<vnd->NumDim;jj++){					fprintf(stderr,"      Dimension = %d  key = %ld \n",					jj,key[jj]);				}				abort();			}		}	 	j=VNDrwslice(vnd, iopanel,'r', idim, iblock, ipanel);		if(j!=0){			fprintf(stderr,"VNDrw: Error reading in new buffers\n");			fprintf(stderr,			"VNDrw: Message # %d %s \n",msgnum,msg);			fprintf(stderr,			"VNDrw: iop = %c byte = %ld iblock = %ld panel = %ld \n",			iop,ibyte, iblock, ipanel);				fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",			iopanel,idim,ipanel);			for(jj=0;jj<vnd->NumDim;jj++){				fprintf(stderr,"      Dimension = %d  key = %ld \n",				jj,key[jj]);			}			abort();		}		vnd->CurrentDimension[iopanel] = idim; 		vnd->CurrentBlock[iopanel]     = iblock; 		vnd->CurrentPanel[iopanel]     = ipanel;		vnd->Modified[iopanel]         = 0;	}	if(iop=='r') { /* copy desired data into read buffer */		if(start==0 && incr==1 && nvalues==vnd->N[idim]){			if(idim==0){				NBytes = vnd->NumBytesPerNode * 					vnd->NNodesPerBlock[0];				NBytesM= vnd->NumBytesPerNode * vnd->N[0];				jj=0;				k=0;				for(ib=0;ib<vnd->NBlocks[0];ib++){					NBytes=MIN(NBytes,NBytesM-jj);					for(j=0;j<NBytes;j++){						values[k]=vnd->w[ibyte+j];						k++;					}					ibyte+=vnd->NumBytesPerBlock;					jj+=vnd->NNodesPerBlock[0]*						vnd->NumBytesPerNode;				}			}else{				jj=0;				k=0;				for(ib=0;ib<vnd->NBlocks[idim];ib++){					NumNodes= MIN( vnd->N[idim]-jj,							vnd->NNodesPerBlock[idim]);					jjj=(int) ibyte;					for(j=0;j<NumNodes;j++){						for(kk=0;kk<vnd->NumBytesPerNode;kk++){							values[k]=vnd->w[jjj+kk];							k++;						}						jjj+=vnd->ByteIncr[idim];					}					ibyte+=vnd->NumBytesPerBlock;					jj+=vnd->NNodesPerBlock[idim];				}			}		}else{			iv=0;			for(j=0;j<nvalues;j++){				k=(int) (start + j*incr);				if( k<0 || k>=vnd->N[idim] ){					fprintf(stderr,"VNDrw: index out of range on read\n");					fprintf(stderr,						"VNDrw: Message # %d %s \n",msgnum,msg);					fprintf(stderr,"VNDrw: dimension (0 based for C, add 1 for Fortran) = %d\n",idim);					fprintf(stderr,"VNDrw: number of nodes = %ld\n",vnd->N[idim]);					fprintf(stderr,"VNDrw: index (0 based for C, add 1 for Fortran) = %d\n",k);					fprintf(stderr,						"VNDrw: erroneous values for start, incr, or nvalues might cause this error\n");					fprintf(stderr,"VNDrw: start (0 based for C, add 1 for Fortran) = %ld\n",start);					fprintf(stderr,"VNDrw: incr (0 based for C, add 1 for Fortran) = %ld\n",incr);					fprintf(stderr,"VNDrw: nvalues = %ld\n",nvalues);					fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n",						iopanel,idim,ipanel);					for(jj=0;jj<vnd->NumDim;jj++){						fprintf(stderr,"      Dimension = %d  key = %ld \n",						jj,key[jj]);					}					abort();				}				ib = k/vnd->NNodesPerBlock[idim];				iw = k - ib*vnd->NNodesPerBlock[idim];				iw = ibyte + iw*vnd->ByteIncr[idim] +				ib*vnd->NumBytesPerBlock;				for(kk=0;kk<vnd->NumBytesPerNode;kk++){					values[iv]=vnd->w[iw];					iw++;					iv++;				}			}		}		return;	}	/* copy desired data into write buffer */	if(iop=='w') { /* copy desired data into read buffer */		vnd->Modified[iopanel]=1;		if(start==0 && incr==1 && nvalues==vnd->N[idim]){			if(idim==0){				NBytes = vnd->NumBytesPerNode * 					vnd->NNodesPerBlock[0];				NBytesM= vnd->NumBytesPerNode * vnd->N[0];				jj=0;				k=0;				for(ib=0;ib<vnd->NBlocks[0];ib++){					NBytes=MIN(NBytes,NBytesM-jj);					for(j=0;j<NBytes;j++){						vnd->w[ibyte+j]=values[k];						k++;					}					ibyte+=vnd->NumBytesPerBlock;					jj+=vnd->NNodesPerBlock[0]*					vnd->NumBytesPerNode;				}			}else{				jj=0;				k=0;				for(ib=0;ib<vnd->NBlocks[idim];ib++){					NumNodes= MIN( vnd->N[idim]-jj,						vnd->NNodesPerBlock[idim]);					jjj=(int) ibyte;					for(j=0;j<NumNodes;j++){						for(kk=0;kk<vnd->NumBytesPerNode;kk++){							vnd->w[jjj+kk]=values[k];							k++;						}						jjj+=vnd->ByteIncr[idim];					}					ibyte+=vnd->NumBytesPerBlock;					jj+=vnd->NNodesPerBlock[idim];				}			}		}else{			iv=0;			for(j=0;j<nvalues;j++){				k=(int)(start + j*incr);				if( k<0 || k>=vnd->N[idim] ){					fprintf(stderr,"VNDrw: index out of range on write\n");					fprintf(stderr,					"VNDrw: Message # %d %s \n",msgnum,msg);					fprintf(stderr,"VNDrw: dimension (0 based for C, add 1 for Fortran) = %d\n",idim);					fprintf(stderr,"VNDrw: number of nodes = %ld\n",vnd->N[idim]);					fprintf(stderr,"VNDrw: index (0 based for C, add 1 for Fortran) = %d\n",k);					fprintf(stderr,					"VNDrw: erroneous values for start, incr, or nvalues might cause this error\n");					fprintf(stderr,"VNDrw: start (0 based for C, add 1 for Fortran) = %ld\n",start);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -