ADF_internals.c File Reference

#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
#include "ADF.h"
#include "ADF_internals.h"

Go to the source code of this file.

Defines

#define CHECK_ABORT(E)   if(E!=NO_ERROR)return;
#define file_open   open
#define file_seek   lseek
#define ADF_FILE_INC   5
#define CONVERSION_BUFF_SIZE   100000
#define NUMBER_KNOWN_MACHINES   5
#define MAX_STACK   50
#define EVAL_2_BYTES(C0, C1)   (((C0)<<8)+((C1)))
#define EVAL_4_BYTES(C0, C1, C2, C3)   (((C0)<<24)+((C1)<<16)+((C2)<<8)+((C3)))
#define ZERO_UNION()
#define CHECK_UNION(B)

Typedefs

typedef off_t file_offset_t

Enumerations

enum  { FLUSH, FLUSH_CLOSE }
enum  { TO_FILE_FORMAT, FROM_FILE_FORMAT }
enum  {
  FILE_STK = 1, NODE_STK, DISK_PTR_STK, FREE_CHUNK_STK,
  SUBNODE_STK
}
enum  {
  INIT_STK, CLEAR_STK, CLEAR_STK_TYPE, DEL_STK_ENTRY,
  GET_STK, SET_STK
}

Functions

void ADFI_ASCII_Hex_2_unsigned_int (const unsigned int minimum, const unsigned int maximum, const unsigned int string_length, const char string[], unsigned int *number, int *error_return)
void ADFI_Abort (const int error_code)
void ADFI_ID_2_file_block_offset (const double ID, unsigned int *file_index, unsigned long *file_block, unsigned long *block_offset, int *error_return)
void ADFI_add_2_sub_node_table (const int file_index, const struct DISK_POINTER *parent, const struct DISK_POINTER *child, int *error_return)
void ADFI_adjust_disk_pointer (struct DISK_POINTER *block_offset, int *error_return)
void ADFI_big_endian_32_swap_64 (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_big_endian_to_cray (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_big_little_endian_swap (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_blank_fill_string (char *str, const int length)
void ADFI_find_file (char *filename, int *error_return)
void ADFI_chase_link (const double ID, double *LID, unsigned int *file_index, struct DISK_POINTER *block_offset, struct NODE_HEADER *node_header, int *error_return)
void ADFI_check_4_child_name (const int file_index, const struct DISK_POINTER *parent, const char *name, int *found, struct DISK_POINTER *sub_node_entry_location, struct SUB_NODE_TABLE_ENTRY *sub_node_entry, int *error_return)
void ADFI_check_string_length (const char *str, const int max_length, int *error_return)
void ADFI_close_file (const int file_index, int *error_return)
void ADFI_compare_node_names (const char *name, const char *new_name, int *names_match, int *error_return)
void ADFI_convert_number_format (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const int convert_dir, const struct TOKENIZED_DATA_TYPE *tokenized_data_type, const unsigned int length, unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_count_total_array_points (const unsigned int ndim, const unsigned int dims[], const int dim_start[], const int dim_end[], const int dim_stride[], unsigned long *total_points, unsigned long *starting_offset, int *error_return)
void ADFI_cray_to_big_endian (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_cray_to_little_endian (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_delete_data (const int file_index, const struct NODE_HEADER *node_header, int *error_return)
void ADFI_delete_from_sub_node_table (const int file_index, const struct DISK_POINTER *parent, const struct DISK_POINTER *child, int *error_return)
void ADFI_delete_sub_node_table (const int file_index, const struct DISK_POINTER *block_offset, const unsigned int size_sub_node_table, int *error_return)
void ADFI_disk_pointer_2_ASCII_Hex (const struct DISK_POINTER *block_offset, char block[8], char offset[4], int *error_return)
void ADFI_disk_pointer_from_ASCII_Hex (const char block[8], const char offset[4], struct DISK_POINTER *block_offset, int *error_return)
void ADFI_evaluate_datatype (const int file_index, const char data_type[], int *file_bytes, int *machine_bytes, struct TOKENIZED_DATA_TYPE *tokenized_data_type, char *file_format, char *machine_format, int *error_return)
void ADFI_fflush_file (const unsigned int file_index, int *error_return)
void ADFI_figure_machine_format (const char *format, char *machine_format, char *format_to_use, char *os_to_use, int *error_return)
void ADFI_file_and_machine_compare (const int file_index, const struct TOKENIZED_DATA_TYPE *tokenized_data_type, int *compare, int *error_return)
void ADFI_file_block_offset_2_ID (const int file_index, const unsigned long file_block, const unsigned long block_offset, double *ID, int *error_return)
void ADFI_file_free (const int file_index, const struct DISK_POINTER *block_offset, const long in_number_of_bytes, int *error_return)
void ADFI_file_malloc (const int file_index, const long size_bytes, struct DISK_POINTER *block_offset, int *error_return)
void ADFI_fill_initial_file_header (const char format, const char os_size, const char *what_string, struct FILE_HEADER *file_header, int *error_return)
void ADFI_fill_initial_free_chunk_table (struct FREE_CHUNK_TABLE *free_chunk_table, int *error_return)
void ADFI_fill_initial_node_header (struct NODE_HEADER *node_header, int *error_return)
void ADFI_flush_buffers (const unsigned int file_index, int flush_mode, int *error_return)
void ADFI_fseek_file (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, int *error_return)
void ADFI_get_current_date (char date[])
void ADFI_get_direct_children_ids (const unsigned int file_index, const struct DISK_POINTER *node_block_offset, int *num_ids, double **ids, int *error_return)
void ADFI_get_file_index_from_name (const char *file_name, int *found, unsigned int *file_index, double *ID, int *error_return)
void ADFI_increment_array (const unsigned int ndim, const unsigned int dims[], const int dim_start[], const int dim_end[], const int dim_stride[], int current_position[], unsigned long *element_offset, int *error_return)
void ADFI_is_block_in_core ()
void ADFI_little_endian_32_swap_64 (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_little_endian_to_cray (const char from_format, const char from_os_size, const char to_format, const char to_os_size, const char data_type[2], const unsigned long delta_from_bytes, const unsigned long delta_to_bytes, const unsigned char *from_data, unsigned char *to_data, int *error_return)
void ADFI_open_file (const char *file, const char *status, unsigned int *file_index, int *error_return)
void ADFI_read_chunk_length (const unsigned int file_index, const struct DISK_POINTER *block_offset, char tag[TAG_SIZE+1], struct DISK_POINTER *end_of_chunk_tag, int *error_return)
void ADFI_read_data_chunk (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct TOKENIZED_DATA_TYPE *tokenized_data_type, const int data_size, const long chunk_bytes, const long start_offset, const long total_bytes, char *data, int *error_return)
void ADFI_read_data_chunk_table (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct DATA_CHUNK_TABLE_ENTRY data_chunk_table[], int *error_return)
void ADFI_read_data_translated (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const struct TOKENIZED_DATA_TYPE *tokenized_data_type, const int data_size, const long total_bytes, char *data, int *error_return)
void ADFI_read_disk_block ()
void ADFI_read_disk_pointer_from_disk (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, struct DISK_POINTER *block_and_offset, int *error_return)
int ADFI_read (const unsigned int file_index, const unsigned int data_length, char *data)
void ADFI_read_file (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const unsigned int data_length, char *data, int *error_return)
void ADFI_read_file_header (const unsigned int file_index, struct FILE_HEADER *file_header, int *error_return)
void ADFI_read_free_chunk (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct FREE_CHUNK *free_chunk, int *error_return)
void ADFI_read_free_chunk_table (const unsigned int file_index, struct FREE_CHUNK_TABLE *free_chunk_table, int *error_return)
void ADFI_read_node_header (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct NODE_HEADER *node_header, int *error_return)
void ADFI_read_sub_node_table (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct SUB_NODE_TABLE_ENTRY sub_node_table[], int *error_return)
void ADFI_read_sub_node_table_entry (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct SUB_NODE_TABLE_ENTRY *sub_node_table_entry, int *error_return)
void ADFI_remember_file_format (const int file_index, const char numeric_format, const char os_size, int *error_return)
void ADFI_remember_version_update (const int file_index, const char *what_string, int *error_return)
void ADFI_set_blank_disk_pointer (struct DISK_POINTER *block_offset)
int ADFI_stack_control (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const int stack_mode, const int stack_type, const unsigned long data_length, char *stack_data)
int ADFI_stridx_c (const char *str, const char *substr)
void ADFI_string_2_C_string (const char *string, const int string_length, char *c_string, int *error_return)
void ADFI_unsigned_int_2_ASCII_Hex (const unsigned int number, const unsigned int minimum, const unsigned int maximum, const unsigned int string_length, char string[], int *error_return)
void ADFI_write_data_chunk (const unsigned int file_index, const struct DISK_POINTER *block_offset, const struct TOKENIZED_DATA_TYPE *tokenized_data_type, const int data_size, const long chunk_bytes, const long start_offset, const long total_bytes, const char *data, int *error_return)
void ADFI_write_data_chunk_table (const unsigned int file_index, const struct DISK_POINTER *block_offset, const int number_of_data_chunks, struct DATA_CHUNK_TABLE_ENTRY data_chunk_table[], int *error_return)
void ADFI_write_data_translated (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const struct TOKENIZED_DATA_TYPE *tokenized_data_type, const int data_size, const long total_bytes, const char *data, int *error_return)
void ADFI_write_disk_block ()
void ADFI_write_disk_pointer_2_disk (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const struct DISK_POINTER *block_and_offset, int *error_return)
int ADFI_write (const unsigned int file_index, const unsigned int data_length, const char *data)
void ADFI_write_file (const unsigned int file_index, const unsigned long file_block, const unsigned long block_offset, const unsigned int data_length, const char *data, int *error_return)
void ADFI_write_file_header (const int file_index, const struct FILE_HEADER *file_header, int *error_return)
void ADFI_write_free_chunk (const int file_index, const struct DISK_POINTER *block_offset, const struct FREE_CHUNK *free_chunk, int *error_return)
void ADFI_write_free_chunk_table (const int file_index, const struct FREE_CHUNK_TABLE *free_chunk_table, int *error_return)
void ADFI_write_modification_date (const int file_index, int *error_return)
void ADFI_write_node_header (const int file_index, const struct DISK_POINTER *block_offset, const struct NODE_HEADER *node_header, int *error_return)
void ADFI_write_sub_node_table (const unsigned int file_index, const struct DISK_POINTER *block_offset, const int number_of_sub_nodes, struct SUB_NODE_TABLE_ENTRY sub_node_table[], int *error_return)
void ADFI_write_sub_node_table_entry (const unsigned int file_index, const struct DISK_POINTER *block_offset, struct SUB_NODE_TABLE_ENTRY *sub_node_table_entry, int *error_return)
char * ADFI_strtok (char *string, char **string_pos, char *token)

Variables

int ADF_sys_err
ADF_FILEADF_file
int maximum_files = 0
char data_chunk_start_tag [] = "DaTa"


Define Documentation

#define ADF_FILE_INC   5

Definition at line 228 of file ADF_internals.c.

#define CHECK_ABORT (  )     if(E!=NO_ERROR)return;

Definition at line 194 of file ADF_internals.c.

#define CHECK_UNION (  ) 

Value:

if( (u.bytes[0] != B[0]) || (u.bytes[1] != B[1]) ||             \
       (u.bytes[2] != B[2]) || (u.bytes[3] != B[3]) ||          \
       (u.bytes[4] != B[4]) || (u.bytes[5] != B[5]) ||          \
       (u.bytes[6] != B[6]) || (u.bytes[7] != B[7]) ) continue ;

#define CONVERSION_BUFF_SIZE   100000

read/write conversion buffer

Definition at line 253 of file ADF_internals.c.

#define EVAL_2_BYTES ( C0,
C1   )     (((C0)<<8)+((C1)))

Definition at line 335 of file ADF_internals.c.

#define EVAL_4_BYTES ( C0,
C1,
C2,
C3   )     (((C0)<<24)+((C1)<<16)+((C2)<<8)+((C3)))

Definition at line 336 of file ADF_internals.c.

#define file_open   open

Definition at line 209 of file ADF_internals.c.

#define file_seek   lseek

Definition at line 221 of file ADF_internals.c.

#define MAX_STACK   50

Definition at line 319 of file ADF_internals.c.

#define NUMBER_KNOWN_MACHINES   5

Definition at line 274 of file ADF_internals.c.

 
#define ZERO_UNION (  ) 

Value:

for( k=0; k<8; k++ )                                    \
           u.bytes[k] = '\0' ;


Typedef Documentation

typedef off_t file_offset_t

Definition at line 220 of file ADF_internals.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
FLUSH 
FLUSH_CLOSE 

Definition at line 267 of file ADF_internals.c.

anonymous enum

Assumed machine variable sizes for the currently supported machines. For ordering of data see the Figure_Machine_Format function. Note that when openning a new file not in the machine format these are the sizes used!!

Enumerator:
TO_FILE_FORMAT 
FROM_FILE_FORMAT 

Definition at line 273 of file ADF_internals.c.

anonymous enum

Enumerator:
FILE_STK 
NODE_STK 
DISK_PTR_STK 
FREE_CHUNK_STK 
SUBNODE_STK 

Definition at line 329 of file ADF_internals.c.

anonymous enum

Enumerator:
INIT_STK 
CLEAR_STK 
CLEAR_STK_TYPE 
DEL_STK_ENTRY 
GET_STK 
SET_STK 

Definition at line 331 of file ADF_internals.c.


Function Documentation

void ADFI_Abort ( const int  error_code  ) 

Definition at line 440 of file ADF_internals.c.

void ADFI_add_2_sub_node_table ( const int  file_index,
const struct DISK_POINTER parent,
const struct DISK_POINTER child,
int *  error_return 
)

Get node_header for the node (parent)

Get node_header for the node (child)

Check current length of sub-node_table, add space if needed

Increase the table space (double it)

Allocate memory for the required table space in memory

If sub-node table exists, get it

Blank out the new part of the sub-node_table

Allocate memory for the required table space on disk

Write out modified sub_node_table

Insert new entry in sub-node table

Write the child's name

Write out new sub_node_table entry

Write out modified parent node-header

Definition at line 550 of file ADF_internals.c.

void ADFI_adjust_disk_pointer ( struct DISK_POINTER block_offset,
int *  error_return 
)

Calculate the number of blocks in the current offset

Adjust block/offset checking for block roll-over

Definition at line 702 of file ADF_internals.c.

void ADFI_ASCII_Hex_2_unsigned_int ( const unsigned int  minimum,
const unsigned int  maximum,
const unsigned int  string_length,
const char  string[],
unsigned int *  number,
int *  error_return 
)

Index from 0 to string_length - 1

Index from string_length - 1 to 0

Temoprary integer variable

Working value of ther number

Convert the ASCII-Hex string into decimal

Return the number

Definition at line 360 of file ADF_internals.c.

void ADFI_big_endian_32_swap_64 ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Definition at line 800 of file ADF_internals.c.

void ADFI_big_endian_to_cray ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

8 bits to 14 bits. Sign extent from 8 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

23 bits to 48 bits. Left shift 25 bits, zero fill

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

11 bits to 14 bits. Sign extent from 11 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

52 bits to 48 bits. Use 48, drop last 4 bits

Definition at line 939 of file ADF_internals.c.

void ADFI_big_little_endian_swap ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

end if

Definition at line 1220 of file ADF_internals.c.

void ADFI_blank_fill_string ( char *  str,
const int  length 
)

Definition at line 1268 of file ADF_internals.c.

void ADFI_chase_link ( const double  ID,
double *  LID,
unsigned int *  file_index,
struct DISK_POINTER block_offset,
struct NODE_HEADER node_header,
int *  error_return 
)

Get the file, block, and offset numbers from the ID

Get node_header for the node

node is a link get file and path data

Link_ID = root-node of the new file. note: the file could already be opened, and may be the current file!

Not found; try to open it

Get the node ID of the link to node (may be other links)

node is NOT a link

Definition at line 1377 of file ADF_internals.c.

void ADFI_check_4_child_name ( const int  file_index,
const struct DISK_POINTER parent,
const char *  name,
int *  found,
struct DISK_POINTER sub_node_entry_location,
struct SUB_NODE_TABLE_ENTRY sub_node_entry,
int *  error_return 
)

Get node_header for the node

Check for valid node name

If parent has no children, the new name MUST be NOT found

Allocate memory for the required table space in memory

Check all names for our new name

Also save off the child's name

Get out of the for loop

Definition at line 1504 of file ADF_internals.c.

void ADFI_check_string_length ( const char *  str,
const int  max_length,
int *  error_return 
)

Check for blank string

Definition at line 1615 of file ADF_internals.c.

void ADFI_close_file ( const int  file_index,
int *  error_return 
)

Clear this file's entry

Definition at line 1661 of file ADF_internals.c.

void ADFI_compare_node_names ( const char *  name,
const char *  new_name,
int *  names_match,
int *  error_return 
)

Name mattched for the length of the new name. The existing node name must only contian blanks from here

Definition at line 1738 of file ADF_internals.c.

void ADFI_convert_number_format ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const int  convert_dir,
const struct TOKENIZED_DATA_TYPE tokenized_data_type,
const unsigned int  length,
unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

loop over each element

end if

end else

Increment the data pointers

Definition at line 1858 of file ADF_internals.c.

void ADFI_count_total_array_points ( const unsigned int  ndim,
const unsigned int  dims[],
const int  dim_start[],
const int  dim_end[],
const int  dim_stride[],
unsigned long *  total_points,
unsigned long *  starting_offset,
int *  error_return 
)

Chek the inputs

Check dims[] >=1

Check starting values >=1 and <= dims

Check ending values >=1 and <= dims and >= dim_start

Check stride >= 1

Definition at line 2047 of file ADF_internals.c.

void ADFI_cray_to_big_endian ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

14 bits to 8 bits. Sign extent from 8 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

48 bits to 23 bits, skip the first '1' (2.fract)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

14 bits to 11 bits

Cray exponent is 2 greater than the Iris

Convert the mantissia

48 bits to 52 bits, skip the first '1' (2.fract)

Definition at line 2183 of file ADF_internals.c.

void ADFI_cray_to_little_endian ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

14 bits to 8 bits. Sign extent from 8 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

48 bits to 23 bits, skip the first '1' (2.fract)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

14 bits to 11 bits

Cray exponent is 2 greater than the Iris

Convert the mantissia

48 bits to 52 bits, skip the first '1' (2.fract)

Definition at line 2437 of file ADF_internals.c.

void ADFI_delete_data ( const int  file_index,
const struct NODE_HEADER node_header,
int *  error_return 
)

No data to free, do nothing

A single data-chunk to free, so free it

Multiple data-chunks to free. Free them, and also the data_chunk table

Allocate memory for the required table space in memory

Read in the table

Free each entry in the table

Clear all disk entries off the priority stack for file

Definition at line 2637 of file ADF_internals.c.

void ADFI_delete_from_sub_node_table ( const int  file_index,
const struct DISK_POINTER parent,
const struct DISK_POINTER child,
int *  error_return 
)

Find the child in the parent's sub-node table

Move the rest of the table up to fill the hole

Re-write the parent's sub-node table

Update the sub-node count and write the parent's node-header

Clear all subnode/disk entries off the priority stack for file

Definition at line 2718 of file ADF_internals.c.

void ADFI_delete_sub_node_table ( const int  file_index,
const struct DISK_POINTER block_offset,
const unsigned int  size_sub_node_table,
int *  error_return 
)

Clear all subnode/disk entries off the priority stack for file

Definition at line 2833 of file ADF_internals.c.

void ADFI_disk_pointer_2_ASCII_Hex ( const struct DISK_POINTER block_offset,
char  block[8],
char  offset[4],
int *  error_return 
)

Convert into ASCII-Hex form

Definition at line 2888 of file ADF_internals.c.

void ADFI_disk_pointer_from_ASCII_Hex ( const char  block[8],
const char  offset[4],
struct DISK_POINTER block_offset,
int *  error_return 
)

Convert into numeric form

Definition at line 2935 of file ADF_internals.c.

void ADFI_evaluate_datatype ( const int  file_index,
const char  data_type[],
int *  file_bytes,
int *  machine_bytes,
struct TOKENIZED_DATA_TYPE tokenized_data_type,
char *  file_format,
char *  machine_format,
int *  error_return 
)

Return the file & machine's format info

Convert blank-filled datatype into C string

Upper_CASE the data-type string

end if

Get file_header for the file variable sizes

Loop to calculate the compound data-type length and validity

Look at the 2-byte datatype code

Error condition

Look for arrays '[', commas ',', of end-of-string ''

Check for comma between types

Error condition

Definition at line 3007 of file ADF_internals.c.

void ADFI_fflush_file ( const unsigned int  file_index,
int *  error_return 
)

Definition at line 3226 of file ADF_internals.c.

void ADFI_figure_machine_format ( const char *  format,
char *  machine_format,
char *  format_to_use,
char *  os_to_use,
int *  error_return 
)

Check requested format

Check for numeric bit patterns

Some other format, call it NATIVE

Definition at line 3332 of file ADF_internals.c.

void ADFI_file_and_machine_compare ( const int  file_index,
const struct TOKENIZED_DATA_TYPE tokenized_data_type,
int *  compare,
int *  error_return 
)

Get file_header for the file variable sizes

Make sure the sizes are the same or we are cooked!!

end if

end if

If the file and machine binary type are the same and only the sizes may be different (like long is 32 or 64), then if all the sizes are the same then no converion is necessary and ws can avoid the conversion overhead and just do direct read/writes.

Definition at line 3535 of file ADF_internals.c.

void ADFI_file_block_offset_2_ID ( const int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
double *  ID,
int *  error_return 
)

Map the bytes into the character variable

Definition at line 3620 of file ADF_internals.c.

void ADFI_file_free ( const int  file_index,
const struct DISK_POINTER block_offset,
const long  in_number_of_bytes,
int *  error_return 
)

Check the disk tag to see what kind of disk chunk we have. We need this to determine the length of the chunk.

This is a node

Check disk boundary-tag

Trying to free the free-chunk-table. This is BAD.

Set a temporary block/offset to read disk pointer

Get the end_of_chunk-tag block/offset from disk

Check disk boundary-tag

Set a temporary block/offset to read disk pointer

Get the end_of_chunk-tag block/offset from disk

Check disk boundary-tag

Set a temporary block/offset to read disk pointer

Get the end_of_chunk-tag block/offset from disk

Check disk boundary-tag

Set a temporary block/offset to read disk pointer

Get the end_of_chunk-tag block/offset from disk

Check disk boundary-tag

Use the number of bytes passed in

Too small, z-gas

Initialize the block of 'Z's

Add this chunk to the free table

Get the free-chunk-table

SMALL chunk

If linked-list was empty, also point to this as the last.

MEDIUM chunk

If linked-list was empty, also point to this as the last.

LARGE chunk

If linked-list was empty, also point to this as the last.

Put the free-chunk tags in place

Write out the free chunk

Update the free-chunk-table

Delete the block/offset off the stack

Definition at line 3724 of file ADF_internals.c.

void ADFI_file_malloc ( const int  file_index,
const long  size_bytes,
struct DISK_POINTER block_offset,
int *  error_return 
)

The end-of_file pointer points to the last byte USED, NOT the next byte TO USE.

If the end-of_file is NOT at a block boundary, then see if the new allocated chunk will span a block boundary. If it will, then start at the new block if it will fit within the block. This helps efficiency to have file control headers located within a block boundry.

Free rest of block, allocate from next block

Use the remaining block

Write out the modified file header

Definition at line 4021 of file ADF_internals.c.

void ADFI_fill_initial_file_header ( const char  format,
const char  os_size,
const char *  what_string,
struct FILE_HEADER file_header,
int *  error_return 
)

Put the boundary tags in first. If we then overwrite them, we'll know

The UNIX "what" string" - blank terminated

File creation date/time - blank terminated

File modification date/time - same as creation time

Set sizeof() information for file data

end if

end else

Set root node table pointers

Definition at line 4235 of file ADF_internals.c.

void ADFI_fill_initial_free_chunk_table ( struct FREE_CHUNK_TABLE free_chunk_table,
int *  error_return 
)

Small: First and Last Blocks

Medium: First and Last Blocks

large: First and Last Blocks

Definition at line 4362 of file ADF_internals.c.

void ADFI_fill_initial_node_header ( struct NODE_HEADER node_header,
int *  error_return 
)

Blank out the name

Blank out the label

Set number of sub nodes to zero

Blank out the Data-Type, then set to eMpTy.

Zero out number of dimensions & Set dimension values to zero

Set number of data chunks to zero, zero out data chunk pointer

Definition at line 4400 of file ADF_internals.c.

void ADFI_find_file ( char *  filename,
int *  error_return 
)

Definition at line 1283 of file ADF_internals.c.

void ADFI_flush_buffers ( const unsigned int  file_index,
int  flush_mode,
int *  error_return 
)

Flush any active write buffer, file block is set to a nonsense value so that the buffer flags are not reset

Reset control flags

Reset control flags

Definition at line 4456 of file ADF_internals.c.

void ADFI_fseek_file ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
int *  error_return 
)

Definition at line 4503 of file ADF_internals.c.

void ADFI_get_current_date ( char  date[]  ) 

get the current time

remove '
' from ctime format

blank fill

Definition at line 4554 of file ADF_internals.c.

void ADFI_get_direct_children_ids ( const unsigned int  file_index,
const struct DISK_POINTER node_block_offset,
int *  num_ids,
double **  ids,
int *  error_return 
)

Check for zero children, return if 0

point to the first child

Return the ids for all the children

Read one sub-node table entry

Get the ID from the sub-node table

Increment the disk-pointer

Definition at line 4605 of file ADF_internals.c.

void ADFI_get_file_index_from_name ( const char *  file_name,
int *  found,
unsigned int *  file_index,
double *  ID,
int *  error_return 
)

A Match!!!

Definition at line 4686 of file ADF_internals.c.

void ADFI_ID_2_file_block_offset ( const double  ID,
unsigned int *  file_index,
unsigned long *  file_block,
unsigned long *  block_offset,
int *  error_return 
)

Unmap the bytes from the character

Definition at line 470 of file ADF_internals.c.

void ADFI_increment_array ( const unsigned int  ndim,
const unsigned int  dims[],
const int  dim_start[],
const int  dim_end[],
const int  dim_stride[],
int  current_position[],
unsigned long *  element_offset,
int *  error_return 
)

The -1 above is to let the next loop add its stride

Definition at line 4746 of file ADF_internals.c.

void ADFI_is_block_in_core (  ) 

Definition at line 4801 of file ADF_internals.c.

void ADFI_little_endian_32_swap_64 ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Definition at line 4874 of file ADF_internals.c.

void ADFI_little_endian_to_cray ( const char  from_format,
const char  from_os_size,
const char  to_format,
const char  to_os_size,
const char  data_type[2],
const unsigned long  delta_from_bytes,
const unsigned long  delta_to_bytes,
const unsigned char *  from_data,
unsigned char *  to_data,
int *  error_return 
)

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

8 bits to 14 bits. Sign extent from 8 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

23 bits to 48 bits. Left shift 25 bits, zero fill

Check for zero: a special case on the Cray (exponent sign)

Convert the sign

Convert the exponent

11 bits to 14 bits. Sign extent from 11 to 14

Cray exponent is 2 greater than the Iris

Convert the mantissia

52 bits to 48 bits. Use 48, drop last 4 bits

Definition at line 5013 of file ADF_internals.c.

void ADFI_open_file ( const char *  file,
const char *  status,
unsigned int *  file_index,
int *  error_return 
)

Clear this file's entry

Definition at line 5254 of file ADF_internals.c.

int ADFI_read ( const unsigned int  file_index,
const unsigned int  data_length,
char *  data 
)

Definition at line 5998 of file ADF_internals.c.

void ADFI_read_chunk_length ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
char  tag[TAG_SIZE+1],
struct DISK_POINTER end_of_chunk_tag,
int *  error_return 
)

File Header

point to end-tag

Free-Chunk Table

point to end-tag

Check for 'z's in the file. This is free-data, too small to include tags and pointers

Read TAG and disk_pointer

Check for known tags

Node

Convert pointers into numeric form

Definition at line 5474 of file ADF_internals.c.

void ADFI_read_data_chunk ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct TOKENIZED_DATA_TYPE tokenized_data_type,
const int  data_size,
const long  chunk_bytes,
const long  start_offset,
const long  total_bytes,
char *  data,
int *  error_return 
)

Get tag and chunk length

Check start-of-chunk tag

Check end-of-chunk tag

Point to the start of the data

calculate the total number of data bytes

check for need of data translation

Read the data off of disk

Definition at line 5621 of file ADF_internals.c.

void ADFI_read_data_chunk_table ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct DATA_CHUNK_TABLE_ENTRY  data_chunk_table[],
int *  error_return 
)

Get the tag and the length

Compare the start tag

Read the data from disk

Compare the end tag

Definition at line 5740 of file ADF_internals.c.

void ADFI_read_data_translated ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const struct TOKENIZED_DATA_TYPE tokenized_data_type,
const int  data_size,
const long  total_bytes,
char *  data,
int *  error_return 
)

Get machine size of element stored in the NULL element

Limit the number to the end of the data.

Definition at line 5834 of file ADF_internals.c.

void ADFI_read_disk_block (  ) 

Definition at line 5915 of file ADF_internals.c.

void ADFI_read_disk_pointer_from_disk ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
struct DISK_POINTER block_and_offset,
int *  error_return 
)

Check the stack for block/offset

Get the block/offset from disk

Set the block/offset onto the stack

Convert into numeric form

Definition at line 5937 of file ADF_internals.c.

void ADFI_read_file ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const unsigned int  data_length,
char *  data,
int *  error_return 
)

No need to buffer large pieces of data or to take special measures to cross block boundaries

Position the file

Read the data from disk

For smaller pieces of data, read a block at a time. This will improve performance if neighboring data is requested a small piece at a time (strided reads, file overhead).

Some assumptions apply to the block size. With some experimenting, 1K blocks do not offer much improvement. 4K blocks (4096 bytes) do improve performance remarkably. This is due to the fact that the file structure is based of 4K blocks with offsets.

buffer is not current, re-read

Position the file

Read the data from disk

Remember buffer information

Definition at line 6050 of file ADF_internals.c.

void ADFI_read_file_header ( const unsigned int  file_index,
struct FILE_HEADER file_header,
int *  error_return 
)

Check the stack for header

Read in the header into memory

Check memory tags for proper data

Set the header onto the stack

OK the memory tags look good, let's convert disk-formatted header into memory

Check memory tags for proper data

Definition at line 6159 of file ADF_internals.c.

void ADFI_read_free_chunk ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct FREE_CHUNK free_chunk,
int *  error_return 
)

Get the tag and the length

Compare the start tag

Set block offset to the start of the chunk

Read the data from disk

Compare the end tag

Definition at line 6371 of file ADF_internals.c.

void ADFI_read_free_chunk_table ( const unsigned int  file_index,
struct FREE_CHUNK_TABLE free_chunk_table,
int *  error_return 
)

Check the stack for free chunk

Read the free-chunk table off of disk

Check disk tags

Set the free chunk onto the stack

Convert into memory

Check memory tags

Definition at line 6450 of file ADF_internals.c.

void ADFI_read_node_header ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct NODE_HEADER node_header,
int *  error_return 
)

Check the stack for header

Get the node header from disk

Check disk tags

Set the header onto the stack

Convert into memory

Check memory tags

Definition at line 6572 of file ADF_internals.c.

void ADFI_read_sub_node_table ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct SUB_NODE_TABLE_ENTRY  sub_node_table[],
int *  error_return 
)

Get tag and length

calculate the number of chuldren in the sub-node table

Read and convert the variable-length table into memory

Definition at line 6700 of file ADF_internals.c.

void ADFI_read_sub_node_table_entry ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct SUB_NODE_TABLE_ENTRY sub_node_table_entry,
int *  error_return 
)

Check the stack for subnode

Read the entry from disk

Set the subnode onto the stack

Copy the name

Convert the disk-pointer

Definition at line 6785 of file ADF_internals.c.

void ADFI_remember_file_format ( const int  file_index,
const char  numeric_format,
const char  os_size,
int *  error_return 
)

Definition at line 6849 of file ADF_internals.c.

void ADFI_remember_version_update ( const int  file_index,
const char *  what_string,
int *  error_return 
)

Definition at line 6881 of file ADF_internals.c.

void ADFI_set_blank_disk_pointer ( struct DISK_POINTER block_offset  ) 

Definition at line 6923 of file ADF_internals.c.

int ADFI_stack_control ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const int  stack_mode,
const int  stack_type,
const unsigned long  data_length,
char *  stack_data 
)

Try and find the entry and delete it from the stack

Try and find the entry or an empty slot or the lowest priority slot. If it exist then it has its priority bumped to number 1

Definition at line 6952 of file ADF_internals.c.

int ADFI_stridx_c ( const char *  str,
const char *  substr 
)

Definition at line 7119 of file ADF_internals.c.

void ADFI_string_2_C_string ( const char *  string,
const int  string_length,
char *  c_string,
int *  error_return 
)

Skip and trailing blanks

Copy the non-trailing blank portion of the string

NULL terminate the C string

Definition at line 7153 of file ADF_internals.c.

char* ADFI_strtok ( char *  string,
char **  string_pos,
char *  token 
)

Definition at line 8585 of file ADF_internals.c.

void ADFI_unsigned_int_2_ASCII_Hex ( const unsigned int  number,
const unsigned int  minimum,
const unsigned int  maximum,
const unsigned int  string_length,
char  string[],
int *  error_return 
)

Index from 0 to string_length - 1

Index from string_length - 1 to 0

Temoprary integer variable

Working value of ther number

Convert the number using power-of-2 table

Definition at line 7203 of file ADF_internals.c.

int ADFI_write ( const unsigned int  file_index,
const unsigned int  data_length,
const char *  data 
)

Definition at line 7675 of file ADF_internals.c.

void ADFI_write_data_chunk ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
const struct TOKENIZED_DATA_TYPE tokenized_data_type,
const int  data_size,
const long  chunk_bytes,
const long  start_offset,
const long  total_bytes,
const char *  data,
int *  error_return 
)

Write the tag

Calculate the end-of-chunk-tag pointer

Adjust location and write end-of-chunk pointer

write the data

Zero out the file data

If the data-pointer is NULL, write zeros to the file

Initialize the block of zeros

If the number of bytes to write is larger than the block of zeros we have, write out a series of zero blocks...

write out the remainder of this block

Write blocks of zeros, then a partial block

Write a partial block of zeros to disk

check for need of data translation

Write the data to disk

Write the ending tag to disk

Definition at line 7276 of file ADF_internals.c.

void ADFI_write_data_chunk_table ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
const int  number_of_data_chunks,
struct DATA_CHUNK_TABLE_ENTRY  data_chunk_table[],
int *  error_return 
)

Write Starting boundary tag

Calculate the end-of-chunk-tag location

Write data chunk table entries

Write Ending boundary tag

Definition at line 7438 of file ADF_internals.c.

void ADFI_write_data_translated ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const struct TOKENIZED_DATA_TYPE tokenized_data_type,
const int  data_size,
const long  total_bytes,
const char *  data,
int *  error_return 
)

Get machine size of element stored in the NULL element

Limit the number to the end of the data.

Definition at line 7528 of file ADF_internals.c.

void ADFI_write_disk_block (  ) 

Definition at line 7606 of file ADF_internals.c.

void ADFI_write_disk_pointer_2_disk ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const struct DISK_POINTER block_and_offset,
int *  error_return 
)

Convert into ASCII_Hex form

Put the block/offset to disk

Set the block/offset onto the stack

Definition at line 7628 of file ADF_internals.c.

void ADFI_write_file ( const unsigned int  file_index,
const unsigned long  file_block,
const unsigned long  block_offset,
const unsigned int  data_length,
const char *  data,
int *  error_return 
)

If the read buffer overlaps the buffer then reset it to make sure its currrent

Check to see if we need to flush the write buffer. this happens if we are writing a large chunk or the write moves out of the current block. If the data length is zero then just flush the buffer and return. Note that the ADF_modification_date routine will flush the buffer after any write operations !!

Position the file

write the buffer

Make sure we don't flush twice due to error

If the write buffer overlaps the buffer then reset it to make sure its currrent, set flush buffer flag to false.

Just a buffer flush

No need to buffer large pieces of data or to take special measures to cross block boundaries

Position the file

write the data

For smaller pieces of data, write a block at a time. This will improve performance if neighboring data is writen a small piece at a time (strided reads, file overhead).

Some assumptions apply to the block size. With some experimenting, 1K blocks do not offer much improvement. 4K blocks (4096 bytes) do improve performance remarkably. This is due to the fact that the file structure is based of 4K blocks with offsets. Also the CRAY loves 4K block writes!!

buffer is not current, re-read

Position the file

Read the data from disk

Remember buffer information

Write into the buffer and set flush buffer flag

Definition at line 7723 of file ADF_internals.c.

void ADFI_write_file_header ( const int  file_index,
const struct FILE_HEADER file_header,
int *  error_return 
)

Check memory tags for proper data

OK the memory tags look good, let's format the file header information into the disk format and write it out.

Now write the disk header out...

Set the header onto the stack

Definition at line 7874 of file ADF_internals.c.

void ADFI_write_free_chunk ( const int  file_index,
const struct DISK_POINTER block_offset,
const struct FREE_CHUNK free_chunk,
int *  error_return 
)

Initialize the block of 'X's

Check memory tags for proper data

Write start TAG

Write disk pointers

Write out a bunch of 'x's in the free chunk's empty space

Fill in partial end of a block

Fill in intermediate whole blocks

Fill in partial block to end-of-free-chunk

Now (finally) write out the free_chunk-end_tag

Definition at line 8034 of file ADF_internals.c.

void ADFI_write_free_chunk_table ( const int  file_index,
const struct FREE_CHUNK_TABLE free_chunk_table,
int *  error_return 
)

Check memory tags for proper data

OK the memory tags look good, let's format the free_chunk header information into the disk format and write it out.

Now write the free_chunk header out to disk...

Set the free chunk onto the stack

Definition at line 8166 of file ADF_internals.c.

void ADFI_write_modification_date ( const int  file_index,
int *  error_return 
)

block offset depends on the location the of modification date in the FILE_HEADER structure

Flush the write buffer to ensure the file is current!!

reset the version to default so that it only gets updated once

Definition at line 8265 of file ADF_internals.c.

void ADFI_write_node_header ( const int  file_index,
const struct DISK_POINTER block_offset,
const struct NODE_HEADER node_header,
int *  error_return 
)

Check memory tags for proper data

OK the memory tags look good, let's format the node header information into the disk format and write it out.

Now write the node-header out to disk...

Set the header onto the stack

Definition at line 8323 of file ADF_internals.c.

void ADFI_write_sub_node_table ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
const int  number_of_sub_nodes,
struct SUB_NODE_TABLE_ENTRY  sub_node_table[],
int *  error_return 
)

calculate the end-of-chunk tag pointer

Write start TAG

Write disk pointer

Format and write out the table entries

Write closing tag

Definition at line 8428 of file ADF_internals.c.

void ADFI_write_sub_node_table_entry ( const unsigned int  file_index,
const struct DISK_POINTER block_offset,
struct SUB_NODE_TABLE_ENTRY sub_node_table_entry,
int *  error_return 
)

Format the tag and disk pointer in memory

Now write it out to disk

Set the subnode onto the stack

Definition at line 8525 of file ADF_internals.c.


Variable Documentation

Definition at line 231 of file ADF_internals.c.

Definition at line 199 of file ADF_interface.c.

unsigned int block_offset

Definition at line 323 of file ADF_internals.c.

char data_chunk_start_tag[] = "DaTa"

Definition at line 307 of file ADF_internals.c.

unsigned int file_block

Definition at line 322 of file ADF_internals.c.

Definition at line 321 of file ADF_internals.c.

int maximum_files = 0

Definition at line 232 of file ADF_internals.c.

Definition at line 326 of file ADF_internals.c.

char* stack_data

Definition at line 325 of file ADF_internals.c.

Definition at line 324 of file ADF_internals.c.


Generated on Thu Jun 25 10:29:47 2009 for CGNS by  doxygen 1.5.9