Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
3dnewid.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009 void Syntax(void)
00010 {
00011 printf(
00012 "Assigns a new ID code to a dataset; this is useful when making\n"
00013 "a copy of a dataset, so that the internal ID codes remain unique.\n\n"
00014 "Usage: 3dnewid dataset [dataset ...]\n"
00015 " or\n"
00016 " 3dnewid -fun [n]\n"
00017 " to see what n randomly generated ID codes look like.\n"
00018 " (If the integer n is not present, 1 ID code is printed.)\n"
00019 "\n"
00020 "How ID codes are created (here and in other AFNI programs):\n"
00021 "----------------------------------------------------------\n"
00022 "The AFNI ID code generator attempts to create a globally unique\n"
00023 "string identifier, using the following steps.\n"
00024 "1) A long string is created from the system identifier\n"
00025 " information ('uname -a'), the current epoch time in seconds\n"
00026 " and microseconds, the process ID, and the number of times\n"
00027 " the current process has called the ID code function.\n"
00028 "2) This string is then hashed into a 128 bit code using the\n"
00029 " MD5 algorithm. (cf. file thd_md5.c)\n"
00030 "3) This bit code is then converted to a 22 character string\n"
00031 " using Base64 encoding, replacing '/' with '-' and '+' with '_'.\n"
00032 " With these changes, the ID code can be used as a Unix filename\n"
00033 " or an XML name string. (cf. file thd_base64.c)\n"
00034 "4) A 4 character prefix is attached at the beginning to produce\n"
00035 " the final ID code. If you set the environment variable\n"
00036 " IDCODE_PREFIX to something, then its first 3 characters and an\n"
00037 " underscore will be used for the prefix of the new ID code,\n"
00038 " provided that the first character is alphabetic and the other\n"
00039 " 2 alphanumeric; otherwise, the default prefix 'NIH_' will be\n"
00040 " used.\n"
00041 "The source code is function UNIQ_idcode() in file niml.c.\n"
00042 ) ;
00043 exit(0) ;
00044 }
00045
00046 int main( int argc , char * argv[] )
00047 {
00048 THD_3dim_dataset * dset ;
00049 int iarg ;
00050 MCW_idcode idc ;
00051 char str[256] ;
00052
00053 if( argc < 2 || strncmp(argv[1],"-help",4) == 0 ) Syntax() ;
00054
00055 iarg = 1 ;
00056
00057 mainENTRY("3dnewid main"); machdep();
00058
00059 if( strcmp(argv[1],"-fun") == 0 ){
00060 int nid=0 , ii ;
00061 char *eee = getenv("UUID") ;
00062 if( argc > 2 ) nid = strtol(argv[2],NULL,10) ;
00063 if( nid <= 0 ) nid = 1 ;
00064 if( eee == NULL ){
00065 for( ii=0 ; ii < nid ; ii++ ){
00066 idc = MCW_new_idcode() ; printf("%s\n",idc.str) ;
00067 }
00068 } else {
00069 for( ii=0 ; ii < nid ; ii++ ){
00070 eee = UUID_idcode(); printf("%s\n",eee); free(eee);
00071 }
00072 }
00073 exit(0) ;
00074 }
00075
00076
00077
00078 AFNI_logger("3dnewid",argc,argv) ;
00079
00080 for( ; iarg < argc ; iarg++ ){
00081 dset = THD_open_one_dataset( argv[iarg] ) ;
00082 if( dset == NULL ){
00083 fprintf(stderr,"** Skipping dataset %s\n",argv[iarg]) ;
00084 continue ;
00085 }
00086 dset->idcode = MCW_new_idcode() ;
00087 sprintf(str,"3dnewid %s\n",argv[iarg]) ;
00088 tross_Append_History( dset , str) ;
00089 THD_write_3dim_dataset( NULL , NULL , dset , False ) ;
00090 THD_delete_3dim_dataset( dset , False ) ;
00091 }
00092 exit(0) ;
00093 }