/*
FILE:     ciflib.h
*/
/*
VERSION:  4
*/
/*
DATE:     6/17/2002
*/
/*
  Comments and Questions to: sw-help@rcsb.rutgers.edu
*/
/*
COPYRIGHT 1999-2002 Rutgers - The State University of New Jersey

This software is provided WITHOUT WARRANTY OF MERCHANTABILITY OR
FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTY, EXPRESS OR
IMPLIED.  RUTGERS MAKE NO REPRESENTATION OR WARRANTY THAT THE
SOFTWARE WILL NOT INFRINGE ANY PATENT, COPYRIGHT OR OTHER
PROPRIETARY RIGHT.

The user of this software shall indemnify, hold harmless and defend
Rutgers, its governors, trustees, officers, employees, students,
agents and the authors against any and all claims, suits,
losses, liabilities, damages, costs, fees, and expenses including
reasonable attorneys' fees resulting from or arising out of the
use of this software.  This indemnification shall include, but is
not limited to, any and all claims alleging products liability.
*/
/*
               PDB SOFTWARE LICENSE AGREEMENT

BY CLICKING THE ACCEPTANCE BUTTON OR INSTALLING OR USING 
THIS "SOFTWARE, THE INDIVIDUAL OR ENTITY LICENSING THE  
SOFTWARE ("LICENSEE") IS CONSENTING TO BE BOUND BY AND IS 
BECOMING A PARTY TO THIS AGREEMENT.  IF LICENSEE DOES NOT 
AGREE TO ALL OF THE TERMS OF THIS AGREEMENT
THE LICENSEE MUST NOT INSTALL OR USE THE SOFTWARE.

1. LICENSE AGREEMENT

This is a license between you ("Licensee") and the Protein Data Bank (PDB) 
at Rutgers, The State University of New Jersey (hereafter referred to 
as "RUTGERS").   The software is owned by RUTGERS and protected by 
copyright laws, and some elements are protected by laws governing 
trademarks, trade dress and trade secrets, and may be protected by 
patent laws. 

2. LICENSE GRANT

RUTGERS grants you, and you hereby accept, non-exclusive, royalty-free 
perpetual license to install, use, modify, prepare derivative works, 
incorporate into other computer software, and distribute in binary 
and source code format, or any derivative work thereof, together with 
any associated media, printed materials, and on-line or electronic 
documentation (if any) provided by RUTGERS (collectively, the "SOFTWARE"), 
subject to the following terms and conditions: (i) any distribution 
of the SOFTWARE shall bind the receiver to the terms and conditions 
of this Agreement; (ii) any distribution of the SOFTWARE in modified 
form shall clearly state that the SOFTWARE has been modified from 
the version originally obtained from RUTGERS.  

2. COPYRIGHT; RETENTION OF RIGHTS.  

The above license grant is conditioned on the following: (i) you must 
reproduce all copyright notices and other proprietary notices on any 
copies of the SOFTWARE and you must not remove such notices; (ii) in 
the event you compile the SOFTWARE, you will include the copyright 
notice with the binary in such a manner as to allow it to be easily 
viewable; (iii) if you incorporate the SOFTWARE into other code, you 
must provide notice that the code contains the SOFTWARE and include 
a copy of the copyright notices and other proprietary notices.  All 
copies of the SOFTWARE shall be subject to the terms of this Agreement.  

3. NO MAINTENANCE OR SUPPORT; TREATMENT OF ENHANCEMENTS 

RUTGERS is under no obligation whatsoever to: (i) provide maintenance 
or support for the SOFTWARE; or (ii) to notify you of bug fixes, patches, 
or upgrades to the features, functionality or performance of the 
SOFTWARE ("Enhancements") (if any), whether developed by RUTGERS 
or third parties.  If, in its sole discretion, RUTGERS makes an 
Enhancement available to you and RUTGERS does not separately enter 
into a written license agreement with you relating to such bug fix, 
patch or upgrade, then it shall be deemed incorporated into the SOFTWARE 
and subject to this Agreement. You are under no obligation whatsoever 
to provide any Enhancements to RUTGERS or the public that you may 
develop over time; however, if you choose to provide your Enhancements 
to RUTGERS, or if you choose to otherwise publish or distribute your 
Enhancements, in source code form without contemporaneously requiring 
end users or RUTGERS to enter into a separate written license agreement 
for such Enhancements, then you hereby grant RUTGERS a non-exclusive,
royalty-free perpetual license to install, use, modify, prepare
derivative works, incorporate into the SOFTWARE or other computer
software, distribute, and sublicense your Enhancements or derivative
works thereof, in binary and source code form.

4. FEES.  There is no license fee for the SOFTWARE.  If Licensee
wishes to receive the SOFTWARE on media, there may be a small charge
for the media and for shipping and handling.  Licensee is
responsible for any and all taxes.

5. TERMINATION.  Without prejudice to any other rights, Licensor
may terminate this Agreement if Licensee breaches any of its terms
and conditions.  Upon termination, Licensee shall destroy all
copies of the SOFTWARE.

6. PROPRIETARY RIGHTS.  Title, ownership rights, and intellectual
property rights in the Product shall remain with RUTGERS.  Licensee 
acknowledges such ownership and intellectual property rights and will 
not take any action to jeopardize, limit or interfere in any manner 
with RUTGERS' ownership of or rights with respect to the SOFTWARE.  
The SOFTWARE is protected by copyright and other intellectual 
property laws and by international treaties.  Title and related 
rights in the content accessed through the SOFTWARE is the property 
of the applicable content owner and is protected by applicable law.  
The license granted under this Agreement gives Licensee no rights to such
content.

7. DISCLAIMER OF WARRANTY.  THE SOFTWARE IS PROVIDED FREE OF 
CHARGE, AND, THEREFORE, ON AN "AS IS" BASIS, WITHOUT WARRANTY OF 
ANY KIND, INCLUDING WITHOUT LIMITATION THE WARRANTIES THAT IT 
IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 
OR NON-INFRINGING.  THE ENTIRE RISK AS TO THE QUALITY AND 
PERFORMANCE OF THE SOFTWARE IS BORNE BY LICENSEE.  SHOULD THE 
SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, THE LICENSEE AND NOT 
LICENSOR ASSUMES THE ENTIRE COST OF ANY SERVICE AND REPAIR.  
THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF 
THIS AGREEMENT.  NO USE OF THE PRODUCT IS AUTHORIZED HEREUNDER 
EXCEPT UNDER THIS DISCLAIMER.

8. LIMITATION OF LIABILITY.  TO THE MAXIMUM EXTENT PERMITTED BY
APPLICABLE LAW,  IN NO EVENT WILL LICENSOR BE LIABLE FOR ANY 
INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 
OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, INCLUDING, 
WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK 
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL 
OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF ADVISED OF THE
POSSIBILITY THEREOF. 
*/
/* **************************************************************** *

  PURPOSE:      This file contains function prototypes for the 
                CIFLIB C API

 * **************************************************************** */

#ifndef H_CIFLIB_PROTO
#define H_CIFLIB_PROTO

#include "CifDefs.h"
#include "CifErrorCodes.h"
#include "ciflib_typedefs.h"

/*  
 *  Functions which construct and manipulate schema ...
 */

CifSchema  *cifConstructSchema(const int dataBlockIndex);
CifSchema **cifConstructSchemas(int *numDataBlock);
CifSchema  *cifConstructSchemaByAlias(const int dataBlockIndex);
CifSchema **cifConstructSchemasByAlias(int *numDataBlock);
void        cifFreeSchema(CifSchema *schema);
void        cifFreeSchemas(CifSchema **schema, 
			   const int numDataBlock);
void cifPrintSchema(const CifSchema *schema);
void cifPrintSchemas(CifSchema **schema, 
		     const int numDataBlock);

/*
 *  Functions which perform file operations, initialization and housekeeping ..
 */
int cifInit(const char *fileName, const int verify, const int verbose);
void cifFree(void);
int  cifReadFile(const char *fileName, 
		 const char *dicDataBlockName);
int  cifCloseFile(const char *fileName);
void cifSaveFile(const char *fileName);
int  cifWriteFile(const char *fileName, 
		  const char *outputFileName,
		  const char mode, 
		  const int templateFlag, 
		  const int esdFlag,
		  const char *dictionaryName, 
		  const char *version);
int  cifWriteDataBlock(const char *fileName, 
		       const char mode, 
		       const char *dataBlockName, 
		       const int templateFlag ,
		       const int esdFlag,
		       const char *dictionaryName, 
		       const char *version);

/* 
 *    Functions which provide information or operate on data blocks... 
 */
int    cifCountDataBlocks(void);
char **cifGetDataBlockNames(int *numDataBlock);
char  *cifGetDataBlockName(const int dataBlockIndex);
int    cifGetDataBlockIndex(const char *dataBlockName);
int    cifGetDataBlockDictionaryIndex(const char *dataBlockName);
int    cifGetDataBlockDictionaryIndexByIndex(const int dataBlockIndex);
char  *cifGetDataBlockDictionaryName(const char *dataBlockName);
char  *cifGetDataBlockDictionaryNameByIndex(const int dataBlockIndex);
char  *cifGetDataBlockFileName(const char *dataBlockName);
char  *cifGetDataBlockFileNameByIndex(const int dataBlockIndex);
long   cifGetDataBlockFileOffset(const char *dataBlockName);
long   cifGetDataBlockFileOffsetByIndex(const int dataBlockIndex);
int    cifMergeDataBlocks(const char *newDataBlockName, 
			  const char *dataBlockName1, 
			  const char *dataBlockName2);
int    cifMergeDataBlocksByIndex(const char *newDataBlockName, 
				 const int dataBlockIndex1, 
				 const int dataBlockIndex2);
void   cifDeleteDataBlock(const char  *dataBlockName);
void   cifDeleteDataBlockByIndex(const int dataBlockIndex);

void  cifCheckDataBlock(const char *dataBlockName);
void  cifCheckDataBlockByIndex(const int dataBlockIndex);

/* 
 *   Functions which provide information or operate on categories...
 */

int cifCountCategories(const char *dataBlockName);
int cifCountCategoriesByIndex(const int dataBlockIndex);

char *cifGetCategoryName(const char *dataBlockName, 
			 const int categoryIndex);

char *cifGetCategoryNameByIndex(const int dataBlockIndex, 
				const int categoryIndex);
char **cifGetCategoryNames(const char *dataBlockName, 
			   int *numCategory);
char **cifGetCategoryNamesByIndex(const int dataBlockIndex, 
				  int *numCategory);

int cifGetCategoryIndexByIndex(const int datablckIndex, 
			const char *categoryName);

int cifGetCategoryIndex(const char *datablckName, 
			      const char *categoryName);

char **cifGetCategoryKeys(const char *dataBlockName, 
			  const char *categoryName,
			  int *numKey);
char **cifGetCategoryKeysByIndex(const int dataBlockIndex, 
				 const int categoryIndex,
				 int *numKey);

int cifCountRows(const char *dataBlockName, 
		 const char *categoryName);
int cifCountRowsByIndex(const int dataBlockIndex, 
			const int categoryIndex);

int cifCountColumns(const char *dataBlockName, 
		    const char *categoryName);
int cifCountColumnsByIndex(const int dataBlockIndex, 
			   const int categoryIndex);

/*
 *   Functions which provide information of operate on category groups...
 */
char **cifGetCategoryGroups(const char *dataBlockName, 
			    int *numGroup);
char **cifGetCategoryGroupsByIndex(const int dataBlockIndex, 
				   int *numGroup);

char **cifGetCategoriesInCategoryGroup(const char *dataBlockName, 
				       const char *groupName, 
				       int *numCategory);
/*
 *   Functions which provide information or operate on subcategories ... 
 */

char **cifGetSubcategories(const char *dataBlockName, 
			   const char *categoryName, 
			   int *numSubcategory);
char **cifGetItemNamesInSubcategory(const char *dataBlockName, 
				    const char *categoryName, 
				    const char *subcategoryName, 
				    int *numItemName);
char **cifGetItemKeywordsInSubcategory(const char *dataBlockName, 
				       const char *categoryName, 
				       const char *subcategoryName, 
				       int *numItemKeyword);
/*
 *  Functions which provide information about items ..
 */
int cifGetItemIndexByIndex(const int datablckIndex, 
		    const char *itemKeyword);

int cifGetItemIndexByName(const char *datablckName, 
			  const char *itemName);
int cifGetItemIndex(const char *datablckName, 
		    const char *categoryName, 
		    const char *itemName);

char *cifGetItemKeyword(const char *dataBlockName, 
			const char *categoryName, 
			const int itemIndex);

char *cifGetItemKeywordByIndex(const int dataBlockIndex, 
			       const int categoryIndex, 
			       const int itemIndex);

char **cifGetItemKeywords(const char *dataBlockName, 
			  const char *categoryName, 
			  int *numKeyword);

char **cifGetItemKeywordsByIndex(const int dataBlockIndex, 
				 const int categoryIndex, 
				 int *numKeyword);

char *cifGetItemName(const char *dataBlockName, 
		     const char *categoryName, 
		     const int itemIndex);

char *cifGetItemNameByIndex(const int dataBlockIndex, 
			    const int categoryIndex, 
			    const int itemIndex);

char **cifGetItemNames(const char *dataBlockName, 
		       const char *categoryName, 
		       int *numItemName);

char **cifGetItemNamesByIndex(const int dataBlockIndex, 
			      const int categoryIndex, 
			      int *numItemName);

char *cifGetItemAliasName(const char *dataBlockName, 
			  const char *categoryName, 
			  const char *itemKeyword);

char *cifGetItemAliasNameByIndex(const int dataBlockIndex, 
				 const int categoryIndex, 
				 const int itemIndex);

char **cifGetItemAliasNames(const char *dataBlockName, 
			    const char *categoryName, 
			    int *numKeyword);

char **cifGetItemAliasNamesByIndex(const int dataBlockIndex, 
				   const int categoryIndex, 
				   int *numKeyword);

/* 
 * Functions which get item values ... 
 */
int  cifGetItemValueByIndex(char **value, 
			    const int dataBlockIndex,
			    const int categoryIndex, 
			    const int itemIndex, 
			    const int rowIndex);

int  cifGetItemValue(char **value, 
		     const char *dataBlockName, 
		     const char *categoryName,
		     const char *itemKeyword, 
		     const int rowIndex);

int  cifGetItemValueByAlias(char **itemValue, 
			    const int dataBlockIndex, 
			    const char *aliasName, 
			    const int rowIndex);

int *cifGetRowByIndex(char ***itemValue, 
		      const int dataBlockIndex,
		      const int categoryIndex, 
		      const int rowIndex,
		      int *numItem);

int *cifGetRow(char ***itemValue, 
	       const char *dataBlockName,
	       const char *categoryName,
	       const int rowIndex, 
	       int *numItem);


int *cifGetColumn(char ***itemValues,
		  const char *dataBlockName, 
		  const char *categoryName,
		  const char *itemKeyword,
		  int *numValues);

int *cifGetColumnByIndex(char *** itemValues,
			 const int dataBlockIndex, 
			 const int categoryIndex,
			 const int itemIndex,
			 int *numValues);

/*  
 * Functions which update item itemValues ...
 */

int  cifUpdateItemValueByIndex(const char *itemValue, 
			       const int dataBlockIndex,
			       const int categoryIndex, 
			       const int itemIndex, 
			       const int rowIndex);

int  cifUpdateItemValue(const char *itemValue, 
			const char *dataBlockName, 
			const char *categoryName,
			const char *itemKeyword, 
			const int rowIndex);

int  cifUpdateItemValueByAlias(char *itemValue, 
			       const int dataBlockIndex, 
			       const char *aliasName, 
			       const int rowIndex);

/* 
 *  Item convenience functions ...
 */

long cifGetItemFileOffset(const int dataBlockIndex, 
			 const char *itemName);

int cifGetItemCaseSensitivityByIndex(const int dataBlockIndex, 
				     const int categoryIndex,
				     const int itemIndex);

int cifGetItemCaseSensitivity(const char *dataBlockName, 
			      const char *categoryName,
			      const char *itemKeyword);

char *cifGetItemDefaultValueByIndex(const int dataBlockIndex, 
				    const int categoryIndex,
				    const int itemIndex);

char *cifGetItemDefaultValue(const char *dataBlockName, 
			     const char *categoryName,
			     const char *itemKeyword);


char * cifGetItemPrimitiveCodeByIndex(const int datablockIndex, const int categoryIndex,
				   const int itemIndex);
char * cifGetItemPrimitiveCode(const char *datablockName, const char *categoryName,
			    const char *itemKeyword);
/* 
 *  Functions which provide information about parent/child relationships...
 */
char **cifGetParentItemNames(const char *dataBlockName, 
			     const char *categoryName, 
			     const char *itemKeyword,  
			     int *numParent);

int cifGetParentIndexList(const char *dataBlockName, 
			  const char *categoryName, 
			  const char *itemKeyword,  
			  int **parentCategoryIndex, 
			  int **parentItemIndex, 
			  int *numParent);

char **cifGetChildItemNames(const char *dataBlockName, 
			    const char *categoryName, 
			    const char *itemKeyword,    
			    int *numChild);

int cifGetChildIndexList(const char *dataBlockName, 
			 const char *categoryName, 
			 const char *itemKeyword,  
			 int **childCategoryIndex, 
			 int **childItemIndex, 
			 int *numChild);

/* 
 * Functions that get itemRelated/ item dependent list
 */
char **cifGetRelatedItemNames(const char *dataBlockName, 
			      const char *categoryName, 
			      const char *itemKeyword,  
			      int *numParent);

int cifGetRelatedItemIndexList(const char *dataBlockName, 
			       const char *categoryName, 
			       const char *itemKeyword,  
			       int **parentCategoryIndex, 
			       int **parentItemIndex, 
			       int *numParent);
char *cifGetRelatedItemFunctionCode(const char *dataBlockName,
				    const char *categoryName, 
				    const char *itemKeyword,
				    const char *relatedItemName);

char *cifGetRelatedItemFunctionCodeByIndex(const int dataBlockIndex,
			       const int categoryIndex, 
			       const int itemIndex,
			       const int relatedItemIndex);

char **cifGetDependentItemNames(const char *dataBlockName, 
				const char *categoryName, 
				const char *itemKeyword,    
				int *numChild);

int cifGetDependentItemIndexList(const char *dataBlockName, 
				 const char *categoryName, 
				 const char *itemKeyword,  
				 int **childCategoryIndex, 
				 int **childItemIndex, 
				 int *numChild);

/* 
 * Functions that print the details of CIFLIB structures...
 */

void cifPrintDataBlock(const char *dataBlockName); 
void cifPrintDataBlockByIndex(const int dataBlockIndex); 
char *cifErrorMessage(const int errorCode);

/*
 *  Functions which extend the schema ... 
 */

int cifAddDataBlock(const char *newDataBlockName, 
		    const char *dicDatalockName);
int cifAddCategory(const char *newCategoryName, 
			const char *dataBlockName);

int cifAddDataItem(const char *newItemKeyword, 
		   const char *dataBlockName,
		   const char *categoryName);

int cifAddRow(const char *dataBlockName,
	      const char *categoryName);


int cifCountDataBlockErrors(const char *dataBlockName);
int cifCountDataBlockErrorsByIndex(const int dataBlockIndex);
char *cifGetDataBlockError(const char *dataBlockName, const int errorIndex);
char *cifGetDataBlockErrorByIndex(const int dataBlockIndex, const int errorIndex);
char **cifGetDataBlockErrors(const char *dataBlockName, int *numError);
char **cifGetDataBlockErrorsByIndex(const int dataBlockIndex, int *numError);
void cifFreeDataBlockError(const char *dataBlockName, const int errorIndex);
void cifFreeDataBlockErrorByIndex(const int dataBlockIndex, const int errorIndex);
void cifFreeDataBlockErrors(const char *dataBlockName);
void cifFreeDataBlockErrorsByIndex(const int dataBlockIndex);

int cifCountDataBlockWarnings(const char *dataBlockName);
int cifCountDataBlockWarningsByIndex(const int dataBlockIndex);
char *cifGetDataBlockWarning(const char *dataBlockName, const int WarningIndex);
char *cifGetDataBlockWarningByIndex(const int dataBlockIndex, const int WarningIndex);
char **cifGetDataBlockWarnings(const char *dataBlockName, int *numWarning);
char **cifGetDataBlockWarningsByIndex(const int dataBlockIndex, int *numWarning);
void cifFreeDataBlockWarning(const char *dataBlockName, const int warningIndex);
void cifFreeDataBlockWarningByIndex(const int dataBlockIndex, const int warningIndex);
void cifFreeDataBlockWarnings(const char *dataBlockName);
void cifFreeDataBlockWarningsByIndex(const int dataBlockIndex);

#endif


