📄 sds_offil.c
字号:
count = *(int *)thing[level].address; } if (strstr(varname,"_countbits") != NULL) { countbits = 1; count = 1 << count; } else countbits = 0; *temp = (char )0; } }}intCheckVarLength(sds,object, addresses, size)sds_handle sds,object;char **addresses;int size;{ struct direc *dptr = sds_direc(sds); ScanForPreCount(sds,object); if (dptr[object].structype & SDS_VARIABLE_LENGTH) {/* I have variable length objects: chose the correct strategy for loading their address and multiplicity counters */ return FillBaseAddress(sds, object, addresses, size); } else if ((dptr[object].structype & SDS_FORTRAN_RECORDS) || (dptr[object].structype & SDS_SDC_EVENT)) { return ScanFortranFile(sds, object, addresses, size); } return -1;}intScanFortranFile(sds, object, addresses, size)sds_handle sds;sds_handle object;char **addresses;int size;{ struct direc *dptr = sds_direc(sds); char *base = sds_obind2ptr(sds, object); int curplace = 0; int bytecount = 0; int endcount = 0; int nevs = 0; int nrecs; int recsize; char *curaddr = base; struct sds_control_p *scp = sds_control(sds); if (base == NULL) {/* I'm apparently not attached to data - must be just a template */ return 0; } /* Best find out the record size; on Unix this is going to be the size of the object less the two ints which are the bytecounts (yuk) plus a bit of junk.. */ recsize = dptr[object].elemsz - 3 * sizeof(int); if ((size = LoadFromHeader(sds,object, addresses, size)) >= 0) return(size); /* This is the first pass so I really have to scan the datafile */ /* I'm pointing at the count of bytes IN THE RECORDS */ bytecount = *(int *)curaddr; /* Now I point to first record of first event */ curplace += (bytecount + 4); while (curplace < size) { curaddr = base + curplace; endcount = *(int *)curaddr; curplace += 4; curaddr += 4; /* After the records I expect the same bytecount: check it */ if (bytecount != endcount) { fprintf(stderr,"Scan of alleged Fortran record file finds unmatched\n"); fprintf(stderr,"byte counts between events - bailing out\n"); exit(1); } bytecount = *(int *)curaddr; nevs++; curplace += (bytecount + 4); } /* Now I know how many events I have I can build the space for the actual pointers and mutiplicities */ dptr[object].nelems = nevs; allocate_data_pointers(sds,object,nevs); curplace = 0; bytecount = 0; endcount = 0; nevs = 0; /* Now I scan again to fill in the arrays allocated above */ /* I should really do this in one pass. I will when the code works. */ while (curplace < size) { curaddr = base + curplace; bytecount = *(int *)curaddr; nrecs = bytecount/recsize; scp->element_start[object][nevs] = curaddr; scp->varel_count[object][nevs] = nrecs; nevs++; curplace += bytecount + 8; } /* curplace is now the total number of bytes scanned */ return curplace;}intallocate_data_pointers(sds,object,nevs)sds_handle sds,object;int nevs;{ struct direc *dptr = sds_direc(sds); struct sds_control_p *scp = sds_control(sds); if (scp->element_start == NULL) { scp->element_start = (char ***)sds_malloc(sizeof(char *) * dptr[0].nelems); scp->varel_count = (int **)sds_malloc(sizeof(int) * dptr[0].nelems); } scp->element_start[object] = (char **)sds_malloc(sizeof(char *) * nevs); scp->varel_count[object] = (int *)sds_malloc(sizeof(int) * nevs); return 1;}intFillBaseAddress(sds, object, addresses, size)sds_handle sds;sds_handle object;char **addresses;int size;{ struct direc *dptr = sds_direc(sds); struct type_list *tlist = sds_tlist(sds); int obsize = dptr[object].elemsz, varsize; struct sds_odesc *thing; int level; struct sds_control_p *scp = sds_control(sds); int fullsize = 0; int i; int basesize; int foundmatch = 0; sds_code varcode; char *base = sds_obind2ptr(sds, object); if (base == NULL) {/* I'm apparently not attached to data - must be just a template */ return 0; } if ((size = LoadFromHeader(sds,object, addresses, size)) >= 0) return(size); sds_cleanup(sds); while ((level = sds_describe(sds,object,&thing)) >= 0) { if ((varname != NULL) && (!strcmp(varname,thing[level].name))) { varsize = thing[level].size; varcode = thing[level].ind - 1; foundmatch = 1; } } sds_cleanup(sds); if (foundmatch) { if (scp->element_start == NULL) { scp->element_start = (char ***)sds_malloc(sizeof(char *) * dptr[0].nelems); scp->varel_count = (int **)sds_malloc(sizeof(int) * dptr[0].nelems); } scp->element_start[object] = (char **)sds_malloc(sizeof(char *) * dptr[object].nelems); scp->varel_count[object] = (int *)sds_malloc(sizeof(int) * dptr[object].nelems); precount = tlist[varcode].nelems; tlist[varcode].nelems = SDS_LENGTH_UNDETERMINED;/* The nelems number in the header may be 'first element', or, more likely, is marked UNDETERMINED: so find out the base size from that. */ if (precount > 0) basesize = obsize - varsize * precount; else basesize = obsize - varsize; for (i=0;i<dptr[object].nelems;i++) { scp->element_start[object][i] = base; scp->varel_count[object][i] = count; fullsize += (basesize + count * varsize); if (i != (dptr[object].nelems - 1)) { if (count_base != base) count_base += presize; else count_base += (basesize + count * varsize); base += (basesize + count * varsize); if (is_short) count = (int)*(short *)(count_base + countoff); else count = *(int *)(count_base + countoff); if (countbits) count = 1 << count; } } } else fullsize = dptr[object].nelems * dptr[object].elemsz; return fullsize;}int LoadFromHeader(sds,object, addresses, size)sds_handle sds;sds_handle object;char **addresses;int size;{ char buffer[256]; sds_handle ind; struct direc *dptr = sds_direc(sds); char *base = sds_obind2ptr(sds, object); struct sds_control_p *scp = sds_control(sds); /* First check: has this been done before? */ sprintf(buffer,"%s.Address",sds_obind2name(sds,object)); if ((ind = sds_name2ind(sds,buffer)) > 0) { /* Aha! The pointer array has already been saved in the headerSDS */ int *counts,*offsets, i; offsets = (int *)addresses[ind]; /* Find the counts as well */ sprintf(buffer,"%s.Mult",sds_obind2name(sds,object)); ind = sds_like2ind(sds,buffer,1); counts = (int *)addresses[ind]; /* allocate pointer and multiplicity arrays */ allocate_data_pointers(sds,object,dptr[object].nelems); /* And fill them with a little bit of arithmetic */ for (i=0;i<dptr[object].nelems;i++) { scp->element_start[object][i] = base + offsets[i] - offsets[0]; scp->varel_count[object][i] = counts[i]; } /* return total size scanned */ return size; } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -