Doxygen Source Code Documentation
thd_dsetinsess.c
Go to the documentation of this file.00001 /***************************************************************************** 00002 Major portions of this software are copyrighted by the Medical College 00003 of Wisconsin, 1994-2000, and are released under the Gnu General Public 00004 License, Version 2. See the file README.Copyright for details. 00005 ******************************************************************************/ 00006 00007 #include "mrilib.h" 00008 #include "thd.h" 00009 00010 /*----------------------------------------------------------------- 00011 Find a dataset with a given name in a session 00012 [28 Jul 2003] Modified for new THD_session struct. 00013 -------------------------------------------------------------------*/ 00014 00015 THD_slist_find THD_dset_in_session( int find_type , void *target , 00016 THD_session *sess ) 00017 { 00018 int id , iv , im ; 00019 THD_3dim_dataset *dset ; 00020 THD_slist_find find ; 00021 00022 /*-- sanity check --*/ 00023 00024 if( ! ISVALID_SESSION(sess) || target == NULL ){ 00025 BADFIND(find) ; return find ; 00026 } 00027 00028 switch( find_type ){ 00029 00030 /**** search for a name ****/ 00031 00032 case FIND_NAME:{ 00033 char *target_name = (char *) target ; 00034 if( strlen(target_name) == 0 ){ 00035 BADFIND(find) ; return find ; 00036 } 00037 00038 for( id=0 ; id < sess->num_dsset ; id++ ){ 00039 for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){ 00040 dset = sess->dsset[id][iv] ; 00041 00042 if( dset != NULL && strcmp(dset->self_name,target_name) == 0 ){ 00043 find.dset = dset ; find.dset_index = id ; find.view_index = iv ; 00044 return find ; 00045 } 00046 } 00047 } 00048 } 00049 break ; 00050 00051 /**** search for a prefix ****/ 00052 00053 case FIND_PREFIX:{ 00054 char *target_prefix = (char *) target ; 00055 if( strlen(target_prefix) == 0 ){ 00056 BADFIND(find) ; return find ; 00057 } 00058 00059 for( id=0 ; id < sess->num_dsset ; id++ ){ 00060 for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){ 00061 dset = sess->dsset[id][iv] ; 00062 00063 if( dset != NULL && strcmp(DSET_PREFIX(dset),target_prefix) == 0 ){ 00064 find.dset = dset ; find.dset_index = id ; find.view_index = iv ; 00065 return find ; 00066 } 00067 } 00068 } 00069 } 00070 break ; 00071 00072 /**** search for an idcode ****/ 00073 00074 case FIND_IDCODE:{ 00075 MCW_idcode target_id = *((MCW_idcode *) target) ; 00076 00077 if( ISZERO_IDCODE(target_id) ){ 00078 BADFIND(find) ; return find ; 00079 } 00080 00081 for( id=0 ; id < sess->num_dsset ; id++ ){ 00082 for( iv=FIRST_VIEW_TYPE ; iv <= LAST_VIEW_TYPE ; iv++ ){ 00083 dset = sess->dsset[id][iv] ; 00084 00085 if( dset != NULL && EQUIV_IDCODES(target_id,dset->idcode) ){ 00086 find.dset = dset ; find.dset_index = id ; find.view_index = iv ; 00087 return find ; 00088 } 00089 } 00090 } 00091 } 00092 break ; 00093 00094 } /* end of switch on find_type */ 00095 00096 /*-- fall thru --> not found --*/ 00097 00098 BADFIND(find) ; return find ; 00099 }