00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010 #include "adioi.h"
00011
00012
00013
00014
00015 void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset)
00016 {
00017 ADIOI_Flatlist_node *flat_file;
00018 int i, flag;
00019 unsigned filetype_size;
00020 int etype_size, filetype_is_contig;
00021 MPI_Aint filetype_extent;
00022 ADIO_Offset disp, byte_offset, sum=0, size_in_file, n_filetypes, frd_size;
00023
00024 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00025 etype_size = fd->etype_size;
00026
00027 if (filetype_is_contig) *offset = (fd->fp_ind - fd->disp)/etype_size;
00028 else {
00029
00030 flat_file = CtvAccess(ADIOI_Flatlist);
00031 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00032
00033 MPI_Type_size(fd->filetype, (int*)&filetype_size);
00034 MPI_Type_extent(fd->filetype, &filetype_extent);
00035
00036 disp = fd->disp;
00037 byte_offset = fd->fp_ind;
00038 n_filetypes = -1;
00039 flag = 0;
00040 while (!flag) {
00041 sum = 0;
00042 n_filetypes++;
00043 for (i=0; i<flat_file->count; i++) {
00044 sum += flat_file->blocklens[i];
00045 if (disp + flat_file->indices[i] +
00046 n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent + flat_file->blocklens[i]
00047 >= byte_offset) {
00048 frd_size = disp + flat_file->indices[i] +
00049 n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent
00050 + flat_file->blocklens[i] - byte_offset;
00051 sum -= frd_size;
00052 flag = 1;
00053 break;
00054 }
00055 }
00056 }
00057 size_in_file = n_filetypes * (ADIO_Offset)filetype_size + sum;
00058 *offset = size_in_file/etype_size;
00059 }
00060 }