ADF_interface.c File Reference

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include "ADF.h"
#include "ADF_internals.h"

Go to the source code of this file.

Defines

#define CHECK_ADF_ABORT(error_flag)
#define CHECK_ADF_ABORT1(error_flag)
#define EVAL_2_BYTES(C0, C1)   (((C0)<<8)+((C1)))

Functions

void ADF_Children_Names (const double PID, const int istart, const int imax_num, const int imax_name_len, int *inum_ret, char *names, int *error_return)
void ADF_Children_IDs (const double PID, const int istart, const int imax_num, int *inum_ret, double *IDs, int *error_return)
void ADF_Create (const double PID, const char *name, double *ID, int *error_return)
void ADF_Database_Close (const double Root_ID, int *error_return)
void ADF_Database_Delete (const char *filename, int *error_return)
void ADF_Database_Garbage_Collection (const double ID, int *error_return)
void ADF_Database_Get_Format (const double Root_ID, char *format, int *error_return)
void ADF_Database_Open (const char *filename, const char *status_in, const char *format, double *Root_ID, int *error_return)
void ADF_Database_Valid (const char *filename, int *error_return)
void ADF_Database_Set_Format (const double Root_ID, const char *format, int *error_return)
void ADF_Database_Version (const double Root_ID, char *version, char *creation_date, char *modification_date, int *error_return)
void ADF_Delete (const double PID, const double ID, int *error_return)
void ADF_Error_Message (const int error_return_input, char *error_string)
void ADF_Flush_to_Disk (const double ID, int *error_return)
void ADF_Get_Data_Type (const double ID, char *data_type, int *error_return)
void ADF_Get_Dimension_Values (const double ID, int dim_vals[], int *error_return)
void ADF_Get_Error_State (int *error_state, int *error_return)
void ADF_Get_Label (const double ID, char *label, int *error_return)
void ADF_Get_Link_Path (const double ID, char *file, char *name_in_file, int *error_return)
void ADF_Link_Size (const double ID, int *len_file, int *len_name, int *error_return)
void ADF_Get_Name (const double ID, char *name, int *error_return)
void ADF_Get_Node_ID (const double PID, const char *name, double *ID, int *error_return)
void ADF_Get_Number_of_Dimensions (const double ID, int *num_dims, int *error_return)
void ADF_Get_Root_ID (const double ID, double *Root_ID, int *error_return)
void ADF_Is_Link (const double ID, int *link_path_length, int *error_return)
void ADF_Library_Version (char *version, int *error_return)
void ADF_Link (const double PID, const char *name, const char *file_name, const char *name_in_file, double *ID, int *error_return)
void ADF_Move_Child (const double PID, const double ID, const double NPID, int *error_return)
void ADF_Number_of_Children (const double ID, int *num_children, int *error_return)
void ADF_Put_Dimension_Information (const double ID, const char *data_type, const int dims, const int dim_vals[], int *error_return)
void ADF_Put_Name (const double PID, const double ID, const char *name, int *error_return)
void ADF_Read_All_Data (const double ID, char *data, int *error_return)
void ADF_Read_Block_Data (const double ID, const long b_start, const long b_end, char *data, int *error_return)
void ADF_Read_Data (const double ID, const int s_start[], const int s_end[], const int s_stride[], const int m_num_dims, const int m_dims[], const int m_start[], const int m_end[], const int m_stride[], char *data, int *error_return)
void ADF_Set_Error_State (const int error_state, int *error_return)
void ADF_Set_Label (const double ID, const char *label, int *error_return)
void ADF_Write_All_Data (const double ID, const char *data, int *error_return)
void ADF_Write_Block_Data (const double ID, const long b_start, const long b_end, char *data, int *error_return)
void ADF_Write_Data (const double ID, const int s_start[], const int s_end[], const int s_stride[], const int m_num_dims, const int m_dims[], const int m_start[], const int m_end[], const int m_stride[], const char *data, int *error_return)

Variables

const char * ADF_error_string []
int ADF_sys_err = 0
char data_chunk_start_tag []


Define Documentation

#define CHECK_ADF_ABORT ( error_flag   ) 

Value:

if( error_flag != NO_ERROR ) { \
                    if( ADF_abort_on_error == TRUE ) {    \
                      ADF_Error_Message( error_flag, 0L );\
                      ADFI_Abort( error_flag) ; }         \
                    else { return ; } }

Definition at line 204 of file ADF_interface.c.

#define CHECK_ADF_ABORT1 ( error_flag   ) 

Value:

if( error_flag != NO_ERROR ) { \
                    free (name_tmp);                      \
                    if( ADF_abort_on_error == TRUE ) {    \
                      ADF_Error_Message( error_flag, 0L );\
                      ADFI_Abort( error_flag) ; }         \
                    else { return ; } }

Definition at line 210 of file ADF_interface.c.

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


Function Documentation

void ADF_Children_IDs ( const double  PID,
const int  istart,
const int  imax_num,
int *  inum_ret,
double *  IDs,
int *  error_return 
)

Check for zero children, return if 0

point to the first child wanted

Return the data for the requested children

Read the sub-node entry table

Get the ID from the sub-node table

Increment the disk-pointer and the number of IDs returned

Definition at line 370 of file ADF_interface.c.

void ADF_Children_Names ( const double  PID,
const int  istart,
const int  imax_num,
const int  imax_name_len,
int *  inum_ret,
char *  names,
int *  error_return 
)

Check for zero children, return if 0

point to the first child wanted

Return the data for the requested children

Read the sun-node entry table

Convert the child's name from blank-filled into a C string

Increment the disk-pointer and the number of names returned

Definition at line 278 of file ADF_interface.c.

void ADF_Create ( const double  PID,
const char *  name,
double *  ID,
int *  error_return 
)

Initialize node header

Skip any leading blanks in the name

Check for uniqueness and legality of the name

Assign the name to the new node

Allocate disk space for the new node

Write out the new node header

OK, new node is on disk. Now, update the list of children for the parent...

Return the ID of the new child

Finally, update modification date

Definition at line 464 of file ADF_interface.c.

void ADF_Database_Close ( const double  Root_ID,
int *  error_return 
)

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

Close the ADF file (which may close other sub-files)

Definition at line 570 of file ADF_interface.c.

void ADF_Database_Delete ( const char *  filename,
int *  error_return 
)

Definition at line 600 of file ADF_interface.c.

void ADF_Database_Garbage_Collection ( const double  ID,
int *  error_return 
)

Definition at line 624 of file ADF_interface.c.

void ADF_Database_Get_Format ( const double  Root_ID,
char *  format,
int *  error_return 
)

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

Get node_header for the node

Definition at line 647 of file ADF_interface.c.

void ADF_Database_Open ( const char *  filename,
const char *  status_in,
const char *  format,
double *  Root_ID,
int *  error_return 
)

DO NOT Check filename for NULL here, it may NOT be used...

Get this machine's numeric format

Determine the requested STATUS

Determine the assessability of the filename

Determine the assessability of the filename

open the file

Determine the assessability of the filename

Compose the file header

Open the new file

write out the file header

Compose Initial root-node header

Write out the root-node header

Compose Initial Free-Chunk Table

Write out Free-Chunk Table

Read the header of the ADF file

Check Database version numbers for compatibility

If a new feature is added which requires that the file version be changed then it is done here. Care must be take not to break forward compatibility by changing the file version. Thus new features may not be available for older file versions. For instance version A1 files cannot be upgraded to version A2 and above since a change was made to how links were store and the file version is used to decide how to treat links.

The link separator was changed from " " to ">" in order to support blanks in filenames under Windows. This change is for version A02 and higher

get the root ID for the user

Remember the file's data format

check machine modes, if machine is native the file must be !!

Close the ADF file and free its index

Definition at line 751 of file ADF_interface.c.

void ADF_Database_Set_Format ( const double  Root_ID,
const char *  format,
int *  error_return 
)

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

Get node_header for the node

Get modification date to be updated with the header

Now write the disk header out...

Definition at line 1029 of file ADF_interface.c.

void ADF_Database_Valid ( const char *  filename,
int *  error_return 
)

Definition at line 984 of file ADF_interface.c.

void ADF_Database_Version ( const double  Root_ID,
char *  version,
char *  creation_date,
char *  modification_date,
int *  error_return 
)

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

Get node_header for the node

Convert the "what" string into a C string

Convert the creation date string into a C string

Convert the modification date string into a C string

Definition at line 1092 of file ADF_interface.c.

void ADF_Delete ( const double  PID,
const double  ID,
int *  error_return 
)

Don't use ADFI_chase_link() - delete link nodes but NOT the nodes they are linked too

Delete node data

this node IS a link

Delete the link path data for this node

this node is NOT a link

Recursively delete all sub-nodes (children) of this node

Delete all data for this node

Disassociate node from parent

Delete this node's sub node table

Delete node header from disk

Finally, update modification date

Definition at line 1153 of file ADF_interface.c.

void ADF_Error_Message ( const int  error_return_input,
char *  error_string 
)

If return pointer is NULL, print message to stdout

NO_ERROR is NOT zero for pointer-assignment checking

Check range of error code

Error-code good, copy it for the user

Definition at line 1247 of file ADF_interface.c.

void ADF_Flush_to_Disk ( const double  ID,
int *  error_return 
)

Definition at line 1304 of file ADF_interface.c.

void ADF_Get_Data_Type ( const double  ID,
char *  data_type,
int *  error_return 
)

Copy the blank-filled data-type into a C string

Definition at line 1334 of file ADF_interface.c.

void ADF_Get_Dimension_Values ( const double  ID,
int  dim_vals[],
int *  error_return 
)

Check for zero dimensions

Check for too-large-of dimensions

Copy the dimension information

Definition at line 1375 of file ADF_interface.c.

void ADF_Get_Error_State ( int *  error_state,
int *  error_return 
)

Definition at line 1425 of file ADF_interface.c.

void ADF_Get_Label ( const double  ID,
char *  label,
int *  error_return 
)

Copy the blank-filled label type into a C string

Definition at line 1454 of file ADF_interface.c.

void ADF_Get_Link_Path ( const double  ID,
char *  file,
char *  name_in_file,
int *  error_return 
)

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

Get node_header for the node

Get tokenized datatype

look for file/link delimiter

no filename

no link ?

Definition at line 1495 of file ADF_interface.c.

void ADF_Get_Name ( const double  ID,
char *  name,
int *  error_return 
)

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

Get node_header for the node

Copy the blank-filled name into a C string

Definition at line 1679 of file ADF_interface.c.

void ADF_Get_Node_ID ( const double  PID,
const char *  name,
double *  ID,
int *  error_return 
)

initialize the ID variable to use in intermediate steps

start at the root node

according to user documentation, PID can be any valid node in the database, but we need to use it to get the root ID in order to start at the top

This is the root-node, return the Root-ID

NOT an error, just done and need to get out

start search for tokens (names separated by '/')

this should never happen but check anyway

Get file-index, etc. to start. Note: Parent ID may be a link

Track through the possible compound name string

Find this child under the current parent

Child NOT found

create the child ID

Get the next node-name token (NULL if no more). This is needed for the while-loop check and normally would be done at the end of the loop, but it is useful in the next step to see if there are any more branches in the path.

If this node is the last in the path it may be a link, but there needs to be a mechanism by which a link's ID can be determined and so we cannot follow the link at this time.

This child now becomes the parent. Do it again...

Definition at line 1747 of file ADF_interface.c.

void ADF_Get_Number_of_Dimensions ( const double  ID,
int *  num_dims,
int *  error_return 
)

Return the number of dimensions

Definition at line 1878 of file ADF_interface.c.

void ADF_Get_Root_ID ( const double  ID,
double *  Root_ID,
int *  error_return 
)

Get the file ID

Use the file header to find the root ID

Format the root ID

Definition at line 1913 of file ADF_interface.c.

void ADF_Is_Link ( const double  ID,
int *  link_path_length,
int *  error_return 
)

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

Get node_header for the node

Definition at line 1959 of file ADF_interface.c.

void ADF_Library_Version ( char *  version,
int *  error_return 
)

Copy the proper portion of the "what" string

remove trailing "what" delimiter ('>')

Definition at line 2002 of file ADF_interface.c.

void ADF_Link ( const double  PID,
const char *  name,
const char *  file_name,
const char *  name_in_file,
double *  ID,
int *  error_return 
)

Don't check file since it can be a NULL pointer

Create the node in the normal way

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

Add the file and linked-to name as data in the child

We must use a datatype of "C1" to put the data into this node. With a datatype of "Lk" (a link), the written data will go into the linked-to node (that's the whole point). To set this up we must be careful...

Change the datatype to be LK, without deleting the data. We can't use ADF_Put_Dimension_Information since the change of datatype will delete the data. We must do this manually.

Finally, update modification date

Definition at line 2044 of file ADF_interface.c.

void ADF_Link_Size ( const double  ID,
int *  len_file,
int *  len_name,
int *  error_return 
)

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

Get node_header for the node

Get tokenized datatype

look for file/link delimiter

no filename

Definition at line 1590 of file ADF_interface.c.

void ADF_Move_Child ( const double  PID,
const double  ID,
const double  NPID,
int *  error_return 
)

check that child is really a child of parent

add child to its new parent's sub node table

remove child from its old parent's sub node table

Definition at line 2162 of file ADF_interface.c.

void ADF_Number_of_Children ( const double  ID,
int *  num_children,
int *  error_return 
)

Return the number of children

Definition at line 2240 of file ADF_interface.c.

void ADF_Put_Dimension_Information ( const double  ID,
const char *  data_type,
const int  dims,
const int  dim_vals[],
int *  error_return 
)

Check new datatype

Look at old datatype

Calculate new data-size

If the number of dimensions is zero, set data-bytes to zero

Calculate the total number of bytes in the data

Calculate old data-size

If the data-types are the same...

If a different datatype, throw-away the data, record new datatype

Copy the datatype

Blank fill the remaining space

Record the number of dimensions and the dimension values

Zero out remaining dimension values

Free the old data

Write modified node_header for the node

Finally, update modification date

Definition at line 2305 of file ADF_interface.c.

void ADF_Put_Name ( const double  PID,
const double  ID,
const char *  name,
int *  error_return 
)

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

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

Get node_header for the node (parent)

Get node_header for the node (child)

Skip any leading blanks in the name

Need to check for uniqueness and legality of the name

Confirm that child is from the parent

Copy the name

Blank fill the remaining space

Write modified node_header

replace the child's name in the parent's sub-node_table

Finally, update modification date

Definition at line 2438 of file ADF_interface.c.

void ADF_Read_All_Data ( const double  ID,
char *  data,
int *  error_return 
)

Get datatype size

Calculate total number of bytes in the data

If there is NO DATA, fill data space with zeros, return error

NO_DATA is really a warning, so don't check & abort...

Read the data from disk

Allocate memory for the required table space in memory

Read in the table

Read data from each entry in the table

Check to be sure we aren't reading too much data (shrinking a data block can cause this)

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

Definition at line 2567 of file ADF_interface.c.

void ADF_Read_Block_Data ( const double  ID,
const long  b_start,
const long  b_end,
char *  data,
int *  error_return 
)

Get datatype size

Calculate total number of bytes in the data

Calculate the starting and ending range in the file

If there is NO DATA, fill data space with zeros, return error

NO_DATA is really a warning, so don't check & abort...

Read the data from disk

Allocate memory for the required table space in memory

Read in the table

Read data from each entry in the table

Check to be sure we don't think the chunk is bigger than it is (shrinking a data block can cause this)

If start of block not in this chunk then continue

Set offset into the current chunk

The start of the block is inside the current chunk so adjust the offset to the beginning of the block

Calculate the number of bytes needed in this chunk

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

Definition at line 2691 of file ADF_interface.c.

void ADF_Read_Data ( const double  ID,
const int  s_start[],
const int  s_end[],
const int  s_stride[],
const int  m_num_dims,
const int  m_dims[],
const int  m_start[],
const int  m_end[],
const int  m_stride[],
char *  data,
int *  error_return 
)

Get datatype length

Check to see if there is actual data to use

Check for multiple data-chunks

A single data chunk

Point to the start of the data

Multiple data chunks

Allocate memory for the required table space in memory

Read in the table

Setup initial indexing

Adjust data pointer

If there is no data on disk, return zeros

A single data chunk

Get the data off of disk

Read the data off of disk directly

Read and translate data

Increment disk pointers, for the special case of one dimensional data we will a simple increment to maximize the throught. Thus for block reads you can temporarily change to 1D for the read to improve efficiency. Note total size shouldn't change!!

Multiple data chunks

Get the data off of disk

Read the data off of disk directly

Read and translate data

Increment disk pointers

Increment memory pointers

Adjust data pointer

Multiple data chunks

Definition at line 2872 of file ADF_interface.c.

void ADF_Set_Error_State ( const int  error_state,
int *  error_return 
)

Definition at line 3143 of file ADF_interface.c.

void ADF_Set_Label ( const double  ID,
const char *  label,
int *  error_return 
)

Don't check for NULL or BLANK label, these are OK

Copy the label

Blank fill the remaining space

Write modified node_header

Finally, update modification date

Definition at line 3170 of file ADF_interface.c.

void ADF_Write_All_Data ( const double  ID,
const char *  data,
int *  error_return 
)

Get the datatype length

Calculate the total number of data bytes

If there currently is NO data, allocate disk space for it

Write the new data

Record the modified the node-header

Get the data length

Check start-of-chunk tag

Point to the start of the data

See if the new data exceedes the existing data space

If Data grew: Write old size, then allocate more data-space and write the rest

Write the part of the new data to existing data-chunk

Allocate a second data chunk

Write the rest of the data

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

Allocate a data-chunk-table for two entries

Write data-chunk-table to disk

get the size of the data_chunk for the table end pointer

get the size of the data_chunk for the table end pointer

Update node header with number of data-chunks = 2 and the pointer to the data-chunk-table

Write the new data to existing data-chunk

Multiple data chunks

Allocate memory for the data-chunk-table, with an additional entry in case we need to grow it

Read in the table

looping on the data-chunks, write the size of the current chunk

Limit the number of bytes written by whats left to write.

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

If we are out of data-chunks and have data left, allocate a new data-chunk in the file.

Write data-chunk-table to disk

allocate data space in the file

allocate space for the new data-chunk-entry-table

Free the old data-chunk-table

Update node header with number of data-chunks++ and the pointer to the data-chunk-table

Finally, update modification date

Definition at line 3225 of file ADF_interface.c.

void ADF_Write_Block_Data ( const double  ID,
const long  b_start,
const long  b_end,
char *  data,
int *  error_return 
)

Get the datatype length

Calculate the total number of data bytes

Calculate the starting and ending range in the file

If there currently is NO data, allocate disk space for it

Write the new data

Record the modified the node-header

Get the data length

Check start-of-chunk tag

Point to the start of the data

See if the new data exceedes the existing data space

If Data grew: Write old size, then allocate more data-space and write the rest

Write the part of the new data to existing data-chunk

Allocate a second data chunk

Write the rest of the data

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

Allocate a data-chunk-table for two entries

Write data-chunk-table to disk

get the size of the data_chunk for the table end pointer

get the size of the data_chunk for the table end pointer

Update node header with number of data-chunks = 2 and the pointer to the data-chunk-table

Write the new data to existing data-chunk

Multiple data chunks

Allocate memory for the data-chunk-table, with an additional entry in case we need to grow it

Read in the table

looping on the data-chunks, write the size of the current chunk

If start of block not in this chunk then continue

Set offset into the current chunk

The start of the block is inside the current chunk so adjust the offset to the beginning of the block

Check to be sure we aren't writing too much data

Write the chunk

note: memory_bytes and file_bytes might be different (e.g., if machine is "IEEE_BIG" and file is "CRAY") in which case data pointer advances at a different rate from file pointer.

If we are out of data-chunks and have data left, allocate a new data-chunk in the file.

Write data-chunk-table to disk

allocate data space in the file

allocate space for the new data-chunk-entry-table

Free the old data-chunk-table

Update node header with number of data-chunks++ and the pointer to the data-chunk-table

Finally, update modification date

Definition at line 3502 of file ADF_interface.c.

void ADF_Write_Data ( const double  ID,
const int  s_start[],
const int  s_end[],
const int  s_stride[],
const int  m_num_dims,
const int  m_dims[],
const int  m_start[],
const int  m_end[],
const int  m_stride[],
const char *  data,
int *  error_return 
)

Get datatype length

Calculate the total number of data bytes

check for need of data translation

If there currently is NO data, allocate disk space for it

initialize the new disk_space with zero's, then we'll write the partial data

Record the modified the node-header

If one data chunk, check to see if we need to add a second

Get the data length

Check start-of-chunk tag

Point to the start of the data

See if the new data exceedes the existing data space

If Data grew: Allocate more data-space and initialize to zero

Allocate memory for the data-chunk-table, with an additional entry in case we need to grow it

Allocate a second data chunk

Initialize the new data with zeros

Allocate a data-chunk-table for two entries

Write data-chunk-table to disk

get the size of the data_chunk for the table end pointer

get the size of the data_chunk for the table end pointer

Update node header with number of data-chunks = 2 and the pointer to the data-chunk-table

Multiple data chunks, check to see if we need to add one mode

Allocate memory for the data-chunk-table, with an additional entry in case we need to grow it

Read in the table

looping on the data-chunks, look at the size of the chunks

If we are out of data-chunks and have data left, allocate a new data-chunk in the file.

Write data-chunk-table to disk

allocate data space in the file

allocate space for the new data-chunk-entry-table

Initialize the new data chunk to zeros

Free the old data-chunk-table

Update node header with number of data-chunks++ and the pointer to the data-chunk-table

Do single data-chunks here...

Point to the start of the data

Setup initial indexing

Adjust data pointer

Put the data to disk

Here is where we need to check for spanning multiple data-chunks

Put the data out to disk

Increment disk/memory pointers, for the special case of one dimensional data we will a simple increment to maximize the throught. Thus for block writes you can temporarily change to 1D for the read to improve efficiency. Note total size shouldn't change!!

Adjust data pointer

Point to the start of the data

Setup initial indexing

Adjust data pointer

Put the data to disk

Put the data out to disk

Increment disk and memory pointers

Adjust data pointer

Finally, update modification date

Definition at line 3849 of file ADF_interface.c.


Variable Documentation

const char* ADF_error_string[]

Definition at line 128 of file ADF_interface.c.

int ADF_sys_err = 0

Definition at line 199 of file ADF_interface.c.

Definition at line 307 of file ADF_internals.c.


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