/* ================================================= LIPS slit stage control program slitcont.c for Linux (Vine 2.1.5; Kernel 2.2.19) Windows/Dos Ver 1.0 2001. 1.19 H.Akitaya Ver 1.1 2001. 1.23 H.Akitaya Ver 1.2 2001. 1.24 H.Akitaya Ver 1.3 2001. 2.07 H.Akitaya Ver 1.40 2001. 6.17 H.Akitaya Serial <-> Parralel circuit test Ver 1.40 2001. 6.24 H.Akitaya Serial <-> Parralel circuit (16bit PIO) Ver 1.50 2001.10.19 H.Akitaya Controller Rack and PIO Board Guide Mirror control Ver 1.51 2001.10.23 H.Akitaya Controller Rack and PIO Board Ver 1.6 2001.10.29 H.Akitaya Ver 1.7 2001.12.26 H.Akitaya GT Turret controler Ver 1.71 2001.12.31 H.Akitaya Ver 1.72 2002. 3. 2 H.Akitaya Ver 1.8 2003. 3.27 K.Homma Slitviewer and Cross Disperser controler Ver 1.81 2003. 3.28 K.Matsuda Ver 1.82 2003. 7. 5 K.Matsuda Ver 1.83 2003. 7.12 K.Matsuda Ver 2.0 2004. 8.23 K.Matsuda Stand Alone Program ================================================= */ /* to complile... Linux : gcc -DLINUX -O2 -lm slitcont.c lpio_lnx.c lipspio.c -o slitcont su; chown root slitcont; chmod +s slitcont Dos/Win : compile slitcont.c and lpio_dos.c with "#DEFINE DOS" */ #include #include #include #include #include "lipspio.h" #define TRUE 0 #define SW_ON 1 #define SW_OFF 0 #define MAXNDIAPH 40 #define DIAPHDEFFILE "diaphdef.dat" #define GDMRDEFFILE "gdmrdef.dat" #define TRRTDEFFILE "trrtdef.dat" #define SVTRDEFFILE "svtrdef.dat" #define CRDSDEFFILE "crdsdef.dat" #define HELPFILE "help.txt" #define SETTINGFILE "pos_set.dat" #define LOGFILE "logfile.lst" #define TRRT_BACKPULSE 150 #define SVTR_BACKPULSE 150 #define CRDS_BACKPULSE 150 #define PAGE 22 #define STRING_MAX 256 struct name_coord { char name[30]; long coord; char comment[80]; }; int port_initialize( void ); int inst_initialize( unsigned long *p_status , unsigned int p_width ); int set_slit_org( unsigned long status , unsigned int p_width ); int setslit( long coord_n, long *p_pos, unsigned long status, unsigned int p_width); int move_slit_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_slit_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int set_gdmr_org( unsigned long status , unsigned int p_width ); int set_gdmr_out( unsigned long status , unsigned int p_width_fin ); int move_gdmr_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_gdmr_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int set_trrt_org( unsigned long status , unsigned int p_width ); int move_trrt_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_trrt_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int set_svtr_org( unsigned long status , unsigned int p_width ); int setsvtr( long coord_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_svtr_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_svtr_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int set_crds_org( unsigned long status , unsigned int p_width ); int move_crds_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); int move_crds_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ); void p_sensor( int on_off , unsigned long *p_status ); void showhelp( void ); void start_msg( void ); void read_diaphdef( int *ndiaph, struct name_coord *diaphdef, char filename[] ); long read_gdmrdef( void ); void show_diaphdef( int ndiaph, struct name_coord diaphdef[] ); /* */ /* main function */ /* */ main() { FILE *f_set, *f_log; unsigned int o_data; unsigned int slit_pwidth, gdmr_pwidth, trrt_pwidth, svtr_pwidth, crds_pwidth; unsigned long outdata, indata, status; long pos_slit, pulse_n, coord_n, n_pulse; long pos_gdmr, gdmr_inpos, pos_trrt, pos_svtr, pos_crds; long p_slit, p_gdmr, p_trrt, p_svtr, p_crds; long p_slit_old, p_gdmr_old, p_trrt_old, p_svtr_old, p_crds_old; int error, i, j, ndiaph, ntrrt, nsvtr, ncrds; char com_line[STRING_MAX], buf[STRING_MAX]; char par_str[STRING_MAX], type[STRING_MAX], equal[STRING_MAX]; char pos_set[STRING_MAX]; char slit_str[STRING_MAX], gdmr_str[STRING_MAX], trrt_str[STRING_MAX]; char svtr_str[STRING_MAX], crds_str[STRING_MAX], hct_str[STRING_MAX]; char slit_str_old[STRING_MAX], gdmr_str_old[STRING_MAX]; char trrt_str_old[STRING_MAX], svtr_str_old[STRING_MAX]; char crds_str_old[STRING_MAX], hct_str_old[STRING_MAX]; struct name_coord diaphdef[MAXNDIAPH]; struct name_coord trrtdef[MAXNDIAPH]; struct name_coord svtrdef[MAXNDIAPH]; struct name_coord crdsdef[MAXNDIAPH]; /* start message */ start_msg(); /* initialize */ pos_slit = 0; pos_gdmr = 0; pos_trrt = 0; pos_svtr = 0; pos_crds = 0; slit_pwidth = SLIT_PULSEWIDTH; gdmr_pwidth = GDMR_PULSEWIDTH; trrt_pwidth = TRRT_PULSEWIDTH; svtr_pwidth = SVTR_PULSEWIDTH; crds_pwidth = CRDS_PULSEWIDTH; port_initialize(); /* port initialization */ inst_initialize( &status , slit_pwidth ); /* stage intialization */ read_diaphdef( &ndiaph, diaphdef , DIAPHDEFFILE ); /* define diaphragm names and coordinates */ gdmr_inpos = read_gdmrdef(); /* define guide-mirror in coordinate */ read_diaphdef( &ntrrt, trrtdef , TRRTDEFFILE ); /* define GT turret componet names and coordinates */ read_diaphdef( &nsvtr, svtrdef , SVTRDEFFILE ); /* define slitviewer componet names and coordinates */ read_diaphdef( &ncrds, crdsdef , CRDSDEFFILE ); /* define cross disperser componet names and coordinates */ printf("Stage position : %i\n", pos_slit ); printf("Pulse width : %i micro sec.\n", slit_pwidth ); if( ( f_set = fopen( SETTINGFILE, "r" ) ) == NULL ){ f_set = fopen( SETTINGFILE, "w" ); fprintf( f_set, "Slit_Stage = origin\n" ); fprintf( f_set, "Guide_Mirror = origin\n" ); fprintf( f_set, "GT_Turret = origin\n" ); fprintf( f_set, "Filter_Turret = origin\n" ); fprintf( f_set, "Cross_Disperser = origin\n" ); fprintf( f_set, "Hollow_Cathode_Tube = off\n" ); strcpy( slit_str_old, "origin" ); strcpy( gdmr_str_old, "origin" ); strcpy( trrt_str_old, "origin" ); strcpy( svtr_str_old, "origin" ); strcpy( crds_str_old, "origin" ); strcpy( hct_str_old, "off" ); fclose( f_set ); } else{ while( fgets( par_str, STRING_MAX, f_set ) != NULL ){ sscanf( par_str, "%s %s %s %ld", type, equal, pos_set, &n_pulse ); if( strncmp( type, "Slit_Stage", 10 ) == TRUE ){ strcpy( slit_str_old, pos_set ); p_slit_old = n_pulse; } if( strncmp( type, "Guide_Mirror", 12 ) == TRUE ){ strcpy( gdmr_str_old, pos_set ); p_gdmr_old = n_pulse; } if( strncmp( type, "GT_Turret", 9 ) == TRUE ){ strcpy( trrt_str_old, pos_set ); p_trrt_old = n_pulse; } if( strncmp( type, "Filter_Turret", 13 ) == TRUE ){ strcpy( svtr_str_old, pos_set ); p_svtr_old = n_pulse; } if( strncmp( type, "Cross_Disperser", 15 ) == TRUE ){ strcpy( crds_str_old, pos_set ); p_crds_old = n_pulse; } if( strncmp( type, "Hollow_Cathode_Tube", 19 ) == TRUE ){ strcpy( hct_str_old, pos_set ); } } fclose( f_set ); } /* main routine */ while(1){ sleep(1); f_log = fopen( LOGFILE, "a" ); if( ( f_set = fopen( SETTINGFILE, "r" ) ) == NULL ){ printf( "There is no POSITION SETTING FILE.\n" ); exit(1); } while( fgets( par_str, STRING_MAX, f_set ) != NULL ){ sscanf( par_str, "%s %s %s %ld", type, equal, pos_set, &n_pulse ); /* slit stage */ if( strncmp( type, "Slit_Stage", 10 ) == TRUE ){ strcpy( slit_str, pos_set ); p_slit = n_pulse; if( strcmp( slit_str, slit_str_old ) == 0 && strcmp( slit_str, "mv" ) != 0 && strcmp( slit_str, "set" ) != 0 ){ } else if( strcmp( slit_str, slit_str_old ) != 0 ){ if( strncmp( slit_str, "origin", 6 ) == TRUE ){ error = set_slit_org( status, slit_pwidth ); pos_slit = 0; printf( "Stage position : %i\n", pos_slit ); fprintf( f_log, "Stage position : %i\n", pos_slit ); strcpy( slit_str_old, slit_str ); } else if( strncmp( slit_str, "mv", 2 ) == TRUE ){ if( p_slit != p_slit_old ){ pulse_n = p_slit; if( pulse_n > 0 ){ move_slit_cw( pulse_n, &pos_slit, status, slit_pwidth ); } if( pulse_n < 0 ){ move_slit_ccw( labs(pulse_n), &pos_slit, status, slit_pwidth ); } printf( "Stage position : %i\n", pos_slit ); fprintf( f_log, "Stage position : %i\n", pos_slit ); strcpy( slit_str_old, slit_str ); p_slit_old = p_slit; } else{ } } else if( strncmp( slit_str, "set", 3 ) == TRUE ){ if( p_slit != p_slit_old ){ coord_n = p_slit; setslit( coord_n, &pos_slit, status, slit_pwidth ); printf( "Stage position : %i\n", pos_slit ); fprintf( f_log, "Stage position : %i\n", pos_slit ); strcpy( slit_str_old, slit_str ); p_slit_old = p_slit; } else{ } } else if( strncmp( slit_str, "on", 2 ) == TRUE ){ status |= PO_SLIT_HOFF; pioout( status ); printf( "slit stage motor current : on\n" ); fprintf( f_log, "slit stage motor current : on\n" ); } else if( strncmp( slit_str, "off", 3 ) == TRUE ){ status &= PO_SLIT_HOFF; pioout( status ); printf( "slit stage motor current : off\n" ); fprintf( f_log, "slit stage motor current : off\n" ); } else if( strncmp( slit_str, "exit", 4 ) == TRUE || strncmp( slit_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } else{ if( ndiaph == 0 ){ printf( "No diaphragm is defiened !!\n" ); } else{ for( i = 1; i <= ndiaph; i++ ){ if( strncmp( slit_str, diaphdef[i].name, 4 ) == TRUE ){ printf( "Finding Origin..." ); fprintf( f_log, "Finding Origin..." ); error = set_slit_org( status, slit_pwidth ); pos_slit = 0; fprintf( f_log, "%s %li %s\n", diaphdef[i].name, diaphdef[i].coord, diaphdef[i].comment ); setslit( diaphdef[i].coord, &pos_slit, status, slit_pwidth ); } } strcpy( slit_str_old, slit_str ); } } } else if( strncmp( slit_str, "mv", 2 ) == TRUE ){ if( p_slit != p_slit_old ){ pulse_n = p_slit; if( pulse_n > 0 ){ move_slit_cw( pulse_n, &pos_slit, status, slit_pwidth ); } if( pulse_n < 0 ){ move_slit_ccw( labs(pulse_n), &pos_slit, status, slit_pwidth ); } printf( "Stage position : %i\n", pos_slit ); fprintf( f_log, "Stage position : %i\n", pos_slit ); strcpy( slit_str_old, slit_str ); p_slit_old = p_slit; } else{ } } else if( strncmp( slit_str, "set", 3 ) == TRUE ){ if( p_slit != p_slit_old ){ coord_n = p_slit; setslit( coord_n, &pos_slit, status, slit_pwidth ); printf( "Stage position : %i\n", pos_slit ); fprintf( f_log, "Stage position : %i\n", pos_slit ); strcpy( slit_str_old, slit_str ); p_slit_old = p_slit; } else{ } } else if( strncmp( slit_str, "exit", 4 ) == TRUE || strncmp( slit_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } /* guide mirror */ if( strncmp( type, "Guide_Mirror", 12 ) == TRUE ){ strcpy( gdmr_str, pos_set ); p_gdmr = n_pulse; if( strcmp( gdmr_str, gdmr_str_old ) == 0 && strcmp( gdmr_str, "mv" ) != 0 ){ } else if( strcmp( gdmr_str, gdmr_str_old ) != 0 ){ if( strncmp( gdmr_str, "origin", 6 ) == TRUE || strncmp( gdmr_str, "out", 3 ) == TRUE ){ pos_gdmr = 0; error = set_gdmr_org( status, gdmr_pwidth ); printf( "Guide-mirror position : %i\n", pos_gdmr ); fprintf( f_log, "Guide-mirror position : %i\n", pos_gdmr ); strcpy( gdmr_str_old, gdmr_str ); } else if( strncmp( gdmr_str, "in", 2 ) == TRUE ){ pulse_n = gdmr_inpos - pos_gdmr; move_gdmr_ccw( (-1.0)*pulse_n, &pos_gdmr, status, gdmr_pwidth ); printf( "Guide-mirror position : %i\n", pos_gdmr ); fprintf( f_log, "Guide-mirror position : %i\n", pos_gdmr ); strcpy( gdmr_str_old, gdmr_str ); } else if( strncmp( gdmr_str, "mv", 2 ) == TRUE ){ if( p_gdmr != p_gdmr_old ){ pulse_n = p_gdmr; if( pulse_n > 0 ){ move_gdmr_cw( pulse_n, &pos_gdmr, status, trrt_pwidth ); } if( pulse_n < 0 ){ move_gdmr_ccw( labs(pulse_n), &pos_gdmr, status, trrt_pwidth ); } printf( "Guide Mirror position : %i\n", pos_gdmr ); fprintf( f_log, "Guide Mirror position : %i\n", pos_gdmr ); strcpy( gdmr_str_old, gdmr_str ); p_gdmr_old = p_gdmr; } else{ } } else if( strncmp( gdmr_str, "on", 2 ) == TRUE ){ status |= PO_GDMR_HOFF; pioout( status ); printf( "GD mirror motor current : on\n" ); fprintf( f_log, "GD mirror motor current : on\n" ); } else if( strncmp( gdmr_str, "off", 3 ) == TRUE ){ status &= PO_GDMR_HOFF; pioout( status ); printf( "GD mirror motor current : off\n" ); fprintf( f_log, "GD mirror motor current : off\n" ); } else if( strncmp( gdmr_str, "exit", 4 ) == TRUE || strncmp( gdmr_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } else if( strncmp( gdmr_str, "mv", 2 ) == TRUE ){ if( p_gdmr != p_gdmr_old ){ pulse_n = p_gdmr; if( pulse_n > 0 ){ move_gdmr_cw( pulse_n, &pos_gdmr, status, trrt_pwidth ); } if( pulse_n < 0 ){ move_gdmr_ccw( labs(pulse_n), &pos_gdmr, status, trrt_pwidth ); } printf( "Guide Mirror position : %i\n", pos_gdmr ); fprintf( f_log, "Guide Mirror position : %i\n", pos_gdmr ); strcpy( gdmr_str_old, gdmr_str ); p_gdmr_old = p_gdmr; } else{ } } else if( strncmp( gdmr_str, "exit", 4 ) == TRUE || strncmp( gdmr_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } /* GT turret */ if( strncmp( type, "GT_Turret", 9 ) == TRUE ){ strcpy( trrt_str, pos_set ); p_trrt = n_pulse; if( strcmp( trrt_str, trrt_str_old ) == 0 && strcmp( trrt_str, "mv" ) != 0 ){ } else if( strcmp( trrt_str, trrt_str_old ) != 0 ){ if( strncmp( trrt_str, "origin", 6 ) == TRUE ){ pos_trrt = 0; error = set_trrt_org( status, trrt_pwidth ); printf( "GT Turret position : %i\n", pos_trrt ); fprintf( f_log, "GT Turret position : %i\n", pos_trrt ); strcpy( trrt_str_old, trrt_str ); } else if( strncmp( trrt_str, "mv", 2 ) == TRUE ){ if( p_trrt != p_trrt_old ){ pulse_n = p_trrt; if( pulse_n > 0 ){ move_trrt_cw( pulse_n, &pos_trrt, status, trrt_pwidth ); } if( pulse_n < 0 ){ move_trrt_ccw( labs(pulse_n), &pos_trrt, status, trrt_pwidth ); } printf( "GT Turret position : %i\n", pos_trrt ); fprintf( f_log, "GT Turret position : %i\n", pos_trrt ); strcpy( trrt_str_old, trrt_str ); p_trrt_old = p_trrt; } else{ } } else if( strncmp( trrt_str, "on", 2 ) == TRUE ){ status |= PO_TRRT_HOFF; pioout( status ); printf( "GT turret motor current : on\n" ); fprintf( f_log, "GT turret motor current : on\n" ); } else if( strncmp( trrt_str, "off", 3 ) == TRUE ){ status &= PO_TRRT_HOFF; pioout( status ); printf( "GT turret motor current : off\n" ); fprintf( f_log, "GT turret motor current : off\n" ); } else if( strncmp( trrt_str, "exit", 4 ) == TRUE || strncmp( trrt_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } else{ if( ntrrt == 0 ){ printf( "No component is defined !!\n" ); } else{ for( i = 1; i <= ntrrt; i++ ){ if( strncmp( trrt_str, trrtdef[i].name, 2 ) == TRUE ){ fprintf( f_log, "%s %li %s\n", trrtdef[i].name, trrtdef[i].coord, trrtdef[i].comment ); pos_trrt = 0; error = set_trrt_org( status, trrt_pwidth ); printf( "GT Turret position : %i\n", pos_trrt ); fprintf( f_log, "GT Turret position : %i\n", pos_trrt ); move_trrt_cw( trrtdef[i].coord, &pos_trrt, status, trrt_pwidth ); printf( "GT Turret position : %i\n", pos_trrt ); fprintf( f_log, "GT Turret position : %i\n", pos_trrt ); break; } } strcpy( trrt_str_old, trrt_str ); } } } else if( strncmp( trrt_str, "mv", 2 ) == TRUE ){ if( p_trrt != p_trrt_old ){ pulse_n = p_trrt; if( pulse_n > 0 ){ move_trrt_cw( pulse_n, &pos_trrt, status, trrt_pwidth ); } if( pulse_n < 0 ){ move_trrt_ccw( labs(pulse_n), &pos_trrt, status, trrt_pwidth ); } printf( "GT Turret position : %i\n", pos_trrt ); fprintf( f_log, "GT Turret position : %i\n", pos_trrt ); strcpy( trrt_str_old, trrt_str ); p_trrt_old = p_trrt; } else{ } } else if( strncmp( trrt_str, "exit", 4 ) == TRUE || strncmp( trrt_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } /* slitviewer turret */ if( strncmp( type, "Filter_Turret", 13 ) == TRUE ){ strcpy( svtr_str, pos_set ); p_svtr = n_pulse; if( strcmp( svtr_str, svtr_str_old ) == 0 && strcmp( svtr_str, "mv" ) != 0 ){ } else if( strcmp( svtr_str, svtr_str_old ) != 0 ){ if( strncmp( svtr_str, "origin", 6 ) == TRUE ){ pos_svtr = 0; error = set_svtr_org( status, svtr_pwidth ); printf( "Slitviewer position : %i\n", pos_svtr ); fprintf( f_log, "Slitviewer position : %i\n", pos_svtr ); strcpy( svtr_str_old, svtr_str ); } else if( strncmp( svtr_str, "mv", 2 ) == TRUE ){ if( p_svtr != p_svtr_old ){ pulse_n = p_svtr; if( pulse_n > 0 ){ move_svtr_cw( pulse_n, &pos_svtr, status, svtr_pwidth ); } if( pulse_n < 0 ){ move_svtr_ccw( labs(pulse_n), &pos_svtr, status, svtr_pwidth ); } printf( "SV turret position : %i\n", pos_svtr ); fprintf( f_log, "SV turret position : %i\n", pos_svtr ); strcpy( svtr_str_old, svtr_str ); p_svtr_old = p_svtr; } else{ } } else if( strncmp( svtr_str, "on", 2 ) == TRUE ){ status |= PO_SVTR_HOFF; pioout( status ); printf( "SV turret motor current : on\n" ); fprintf( f_log, "SV turret motor current : on\n" ); } else if( strncmp( svtr_str, "off", 3 ) == TRUE ){ status &= PO_SVTR_HOFF; pioout( status ); printf( "SV turret motor current : off\n" ); fprintf( f_log, "SV turret motor current : off\n" ); } else if( strncmp( svtr_str, "exit", 4 ) == TRUE || strncmp( svtr_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } else{ if( nsvtr == 0 ){ printf( "No component is defined !!\n" ); } else{ for( i = 1; i <= nsvtr; i++ ){ if( strncmp( svtr_str, svtrdef[i].name, 3 ) == TRUE ){ fprintf( f_log, "%s %li %s\n", svtrdef[i].name, svtrdef[i].coord, svtrdef[i].comment ); setsvtr( svtrdef[i].coord, &pos_svtr, status, svtr_pwidth ); break; } } strcpy( svtr_str_old, svtr_str ); } } } else if( strncmp( svtr_str, "mv", 2 ) == TRUE ){ if( p_svtr != p_svtr_old ){ pulse_n = p_svtr; if( pulse_n > 0 ){ move_svtr_cw( pulse_n, &pos_svtr, status, svtr_pwidth ); } if( pulse_n < 0 ){ move_svtr_ccw( labs(pulse_n), &pos_svtr, status, svtr_pwidth ); } printf( "SV turret position : %i\n", pos_svtr ); fprintf( f_log, "SV turret position : %i\n", pos_svtr ); strcpy( svtr_str_old, svtr_str ); p_svtr_old = p_svtr; } else{ } } else if( strncmp( svtr_str, "exit", 4 ) == TRUE || strncmp( svtr_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } /* cross disperser */ if( strncmp( type, "Cross_Disperser", 15 ) == TRUE ){ strcpy( crds_str, pos_set ); p_crds = n_pulse; if( strcmp( crds_str, crds_str_old ) == 0 && strcmp( crds_str, "mv" ) != 0 ){ } else if( strcmp( crds_str, crds_str_old ) != 0 ){ if( strncmp( crds_str, "origin", 6 ) == TRUE ){ pos_crds = 0; error = set_crds_org( status, crds_pwidth ); printf( "Cross Disperser position : %i\n", pos_crds ); fprintf( f_log, "Cross Disperser position : %i\n", pos_crds ); strcpy( crds_str_old, crds_str ); } else if( strncmp( crds_str, "mv", 2 ) == TRUE ){ if( p_crds != p_crds_old ){ pulse_n = p_crds; if( pulse_n > 0 ){ move_crds_cw( pulse_n, &pos_crds, status, crds_pwidth ); } if( pulse_n < 0 ){ move_crds_ccw( labs(pulse_n), &pos_crds, status, crds_pwidth ); } printf( "Cross Disperser position : %i\n", pos_crds ); fprintf( f_log, "Cross Disperser position : %i\n", pos_crds ); strcpy( crds_str_old, crds_str ); p_crds_old = p_crds; } else{ } } else if( strncmp( crds_str, "on", 2 ) == TRUE ){ status |= PO_CRDS_HOFF; pioout( status ); printf( "cross disperser motor current : on\n" ); fprintf( f_log, "cross disperser motor current : on\n" ); } else if( strncmp( crds_str, "off", 3 ) == TRUE ){ status &= PO_CRDS_HOFF; pioout( status ); printf( "cross disperser motor current : off\n" ); fprintf( f_log, "cross disperser motor current : off\n" ); } else if( strncmp( crds_str, "exit", 4 ) == TRUE || strncmp( crds_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } else{ if( ncrds == 0 ){ printf( "No component is defined !!\n" ); } else{ for( i = 1; i <= ncrds; i++ ){ if( strncmp( crds_str, crdsdef[i].name, 3 ) == TRUE ){ fprintf( f_log, "%s %li %s\n", crdsdef[i].name, crdsdef[i].coord, crdsdef[i].comment ); pos_crds = 0; error = set_crds_org( status, crds_pwidth ); printf( "Cross Disperser position : %i\n", pos_crds ); fprintf( f_log, "Cross Disperser position : %i\n", pos_crds ); move_crds_cw( crdsdef[i].coord, &pos_crds, status, crds_pwidth ); printf( "Cross Disperser position : %i\n", pos_crds ); fprintf( f_log, "Cross Disperser position : %i\n", pos_crds ); break; } } strcpy( crds_str_old, crds_str ); } } } else if( strncmp( crds_str, "mv", 2 ) == TRUE ){ if( p_crds != p_crds_old ){ pulse_n = p_crds; if( pulse_n > 0 ){ move_crds_cw( pulse_n, &pos_crds, status, crds_pwidth ); } if( pulse_n < 0 ){ move_crds_ccw( labs(pulse_n), &pos_crds, status, crds_pwidth ); } printf( "Cross Disperser position : %i\n", pos_crds ); fprintf( f_log, "Cross Disperser position : %i\n", pos_crds ); strcpy( crds_str_old, crds_str ); p_crds_old = p_crds; } else{ } } else if( strncmp( crds_str, "exit", 4 ) == TRUE || strncmp( crds_str, "quit", 4 ) == TRUE ){ fclose( f_log ); fclose( f_set ); printf( "Good bye!!\n" ); exit(0); } } /* hollow cathode tube */ if( strncmp( type, "Hollow_Cathode_Tube", 19 ) == TRUE ){ strcpy( hct_str, pos_set ); if( strcmp( hct_str, hct_str_old ) == 0 ){ } else if( strcmp( hct_str, hct_str_old ) != 0 ){ if( strncmp( hct_str, "on", 2 ) == TRUE ){ status |= PO_HCTON; pioout( status ); printf( "HCT lamp is turned on\n" ); fprintf( f_log, "HCT lamp is turned on\n" ); strcpy( hct_str_old, hct_str ); } if( strncmp( hct_str, "off", 3 ) == TRUE ){ status &= ~PO_HCTON; pioout( status ); printf( "HCT lamp is turned off\n" ); fprintf( f_log, "HCT lamp is turned off\n" ); strcpy( hct_str_old, hct_str ); } } } } fclose( f_log ); fclose( f_set ); } } int inst_initialize( unsigned long *p_status , unsigned int p_width ) { FILE *f_set; int c; unsigned long status, error; printf( "Initializing stage ... " ); status = 0x0000 ; /* guide mirror */ status |= PO_GDMR_CWP | PO_GDMR_CCWP | PO_GDMR_HOFF ; /* slit stage */ status |= PO_SLIT_CWP | PO_SLIT_CCWP | PO_SLIT_HOFF ; /* GT turret */ status |= PO_TRRT_CWP | PO_TRRT_CCWP | PO_TRRT_HOFF ; /* status |= PO_TRRT_HOFF ;*/ /* Slitviewer */ status |= PO_SVTR_CWP | PO_SVTR_CCWP | PO_SVTR_HOFF ; /* Cross Disperser */ status |= PO_CRDS_CWP | PO_CRDS_CCWP | PO_CRDS_HOFF ; pioout( status ); printf( "OK status = 0x%x\n", status ); printf( "Set motors to the origin (y/n)? " ); c = getchar(); if( c == 'y' ){ printf( "Setting slit stage to the origin ...\n" ); error = set_slit_org( status , p_width ); if( error == -1 ){ printf( "ERROR!\n" ); } printf( "OK\n" ); printf( "Setting Gdmr position to the origin ...\n" ); error = set_gdmr_org( status , p_width ); if( error == -1 ){ printf( "ERROR!\n" ); } printf( "OK\n" ); printf( "Setting GT turret position to the origin ...\n" ); error = set_trrt_org( status , p_width ); if( error == -1 ){ printf( "ERROR!\n" ); } printf( "OK\n" ); printf( "Setting Slitviewer position to the origin ...\n" ); error = set_svtr_org( status , p_width ); if( error == -1 ){ printf( "ERROR!\n" ); } printf( "OK\n" ); printf( "Make SETTINGFILE parameters origin ...\n" ); f_set = fopen( SETTINGFILE, "w" ); fprintf( f_set, "Slit_Stage = origin\n" ); fprintf( f_set, "Guide_Mirror = origin\n" ); fprintf( f_set, "GT_Turret = origin\n" ); fprintf( f_set, "Filter_Turret = origin\n" ); fprintf( f_set, "Cross_Disperser = origin\n" ); fprintf( f_set, "Hollow_Cathode_Tube = off\n" ); fclose( f_set ); } else{ printf( "Skiped ....\n" ); } *p_status = status; return(1); } /* set stage to org. position */ int set_slit_org( unsigned long status , unsigned int p_width ) { unsigned int n_limit; /* find CCW-LIMIT (FULL STEP)*/ printf( "Finding the CCW Limit ... " ); n_limit = 30000; /* timeout pulse */ while( ( pioin() & PI_SLIT_CCWLS ) == PI_SLIT_CCWLS ){ pioout( status & ~PO_SLIT_CCWP ); p_wait( p_width ); pioout( status | PO_SLIT_CCWP ); p_wait( p_width ); if( --n_limit == 0 ) return(-1); } printf( "Found!!\n" ); p_wait( p_width * 100 ); /* find ORG (HALF STEP) */ printf( "Finding the origin ... " ); status |= PO_SLIT_FULLHALF; /* half step */ n_limit = 10000; /* timeout pulse */ while( ( pioin() & PI_SLIT_ORG ) == PI_SLIT_ORG ){ pioout( status & ~PO_SLIT_CWP ); p_wait( p_width ); pioout( status | PO_SLIT_CWP ); p_wait( p_width ); if ( --n_limit == 0 ) return(-1); } printf( "Found!!\n" ); return(0); } /* set slit to absolute coordinate (coord_n) */ int setslit( long coord_n, long *p_pos, unsigned long status, unsigned int p_width ) { long pulse_n; pulse_n = coord_n - *p_pos; if( pulse_n > 0 ) move_slit_cw( pulse_n, p_pos, status, p_width ); if( pulse_n < 0 ) move_slit_ccw( labs(pulse_n), p_pos, status, p_width ); return(1); } /* move slit pulse_n steps in CW direction */ int move_slit_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal, speed; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } if( ( status & PO_SLIT_FULLHALF ) == PO_SLIT_FULLHALF ){ speed = 1; /* half step */ } else{ speed = 2; /* full step */ } printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_SLIT_CWLS ) != PI_SLIT_CWLS ){ printf( "CW Limit !! +%i steps moved\n", ( i * speed ) ); *p_pos += ( i * speed ); return(0); } pioout( status & ~PO_SLIT_CWP ); p_wait( p_width ); pioout( status | PO_SLIT_CWP ); p_wait( p_width ); i++; } printf( "Completed. +%i steps moved\n", ( i * speed ) ); *p_pos += ( i * speed ) ; return(0); } /* move slit pulse_n steps in CCW direction */ int move_slit_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal, speed; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } if( ( status & PO_SLIT_FULLHALF ) == PO_SLIT_FULLHALF ){ speed = 1; /* half step */ } else{ speed = 2; /* full step */ } printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_SLIT_CCWLS ) != PI_SLIT_CCWLS ){ printf( "CCW Limit !! -%i steps moved\n", ( i * speed ) ); *p_pos -= ( i * speed ); return(0); } pioout( status & ~PO_SLIT_CCWP ); p_wait( p_width ); pioout( status | PO_SLIT_CCWP ); p_wait( p_width ); i++; } printf( "Completed. -%i steps moved\n", ( i * speed ) ); *p_pos -= ( i * speed ); return(0); } /*-------------------- GUIDE MIRROR --------------------*/ /* set Guide Mirror to org. position */ int set_gdmr_org( unsigned long status , unsigned int p_width ) { unsigned int n_limit; p_sensor( SW_ON, &status ); /* find ORG */ printf( "Finding the CW Limit (Origin) ... " ); n_limit = 30000; /* timeout pulse */ while( ( pioin() & PI_GDMR_ORG ) == PI_GDMR_ORG ){ pioout( status & ~PO_GDMR_CWP ); p_wait( p_width ); pioout( status | PO_GDMR_CWP ); p_wait( p_width ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); return(0); } /* set Guide Mirror OUT-position */ int set_gdmr_out( unsigned long status , unsigned int p_width_fin ) { unsigned int n_limit, p_width; p_width = 10000; p_sensor( SW_ON , &status ); /* find ORG */ printf( "Finding the CW Limit (Origin) ... " ); n_limit = 30000; /* timeout pulse */ while( ( pioin() & PI_GDMR_ORG ) == PI_GDMR_ORG ){ if( p_width >= p_width_fin ) p_width -= GDMR_ACC; pioout( status & ~PO_GDMR_CWP ); p_wait( p_width ); pioout( status | PO_GDMR_CWP ); p_wait( p_width ); if( --n_limit == 0 ){ status &= ~PO_PHSENSOR; pioout( status ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); return(0); } /* move guide-mirror pulse_n steps in CW direction */ int move_gdmr_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 1000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_GDMR_ORG ) != PI_GDMR_ORG ){ printf( "CW Limit (Origin) !! +%i steps moved\n", i ); *p_pos += i; pioout( status & ~PO_PHSENSOR ); return(0); } pioout( status & ~PO_GDMR_CWP ); p_wait( p_width ); pioout( status | PO_GDMR_CWP ); p_wait( p_width ); i++; } printf( "Completed. +%i steps moved\n", i ); *p_pos += i ; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* move guide-mirror pulse_n steps in CCW direction */ int move_gdmr_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 10000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_GDMR_LIMIT ) != PI_GDMR_LIMIT ){ printf( "CCW Limit !! %i steps moved\n", i ); *p_pos -= i; pioout( status & ~PO_PHSENSOR ); return(0); } pioout( status & ~PO_GDMR_CCWP ); p_wait( p_width ); pioout( status | PO_GDMR_CCWP ); p_wait( p_width ); i++; } printf( "Completed. -%i steps moved\n", i ); *p_pos -= i ; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* ------------------- GT Turret ------------------- */ /* set GT Turret to org. position */ int set_trrt_org( unsigned long status , unsigned int p_width ) { unsigned int n_limit; long pos; unsigned long speed; speed = 20; pos = 0; /* find ORG (1st)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin ... " ); n_limit = 5000; /* timeout pulse */ while( ( pioin() & PI_TRRT_ORG ) == PI_TRRT_ORG ){ pioout( status & ~PO_TRRT_CWP ); p_wait( p_width ); pioout( status | PO_TRRT_CWP ); p_wait( p_width ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); p_wait( 500000 ); /* back */ move_trrt_ccw( TRRT_BACKPULSE, &pos, status, p_width * speed ); p_wait( 500000 ); /* find ORG (2nd)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin again... "); n_limit = 5000; /* timeout pulse */ while( ( pioin() & PI_TRRT_ORG ) == PI_TRRT_ORG ){ pioout( status & ~PO_TRRT_CWP ); p_wait( p_width * speed ); pioout( status | PO_TRRT_CWP ); p_wait( p_width * speed ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); return(0); } /* move GT turret pulse_n steps in CW direction */ int move_trrt_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 1000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_TRRT_ORG ) != PI_TRRT_ORG ){ printf( "Origin !! +%i steps moved. Continue... \n", i ); } pioout( status & ~PO_TRRT_CWP ); p_wait( p_width ); pioout( status | PO_TRRT_CWP ); p_wait( p_width ); i++; } printf( "Completed. +%i steps moved\n", i); *p_pos += i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* move GT turret pulse_n steps in CCW direction */ int move_trrt_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 10000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_TRRT_ORG ) != PI_TRRT_ORG ){ printf( "Origin !! -%i steps moved. Continue... \n", i ); } pioout( status & ~PO_TRRT_CCWP ); p_wait( p_width ); pioout( status | PO_TRRT_CCWP ); p_wait( p_width ); i++; } printf( "Completed. -%i steps moved\n", i ); *p_pos -= i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* ------------------- Slitviewer ------------------- */ int setsvtr( long coord_n, long *p_pos, unsigned long status, unsigned int p_width ) { long pulse_n; pulse_n = coord_n - *p_pos; if( pulse_n > 0 ) move_svtr_cw( pulse_n, p_pos, status, p_width ); if( pulse_n < 0 ) move_svtr_ccw( labs(pulse_n), p_pos, status, p_width ); return(1); } /* set Slitviewer to org. position */ int set_svtr_org( unsigned long status , unsigned int p_width ) { unsigned int n_limit; long pos; unsigned long speed; speed = 20; pos = 0; /* find ORG (1st)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin ... " ); n_limit = 100000; /* timeout pulse */ while( ( pioin() & PI_SVTR_ORG ) == PI_SVTR_ORG ){ pioout( status & ~PO_SVTR_CWP ); p_wait( p_width ); pioout( status | PO_SVTR_CWP ); p_wait( p_width ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); p_wait( 500000 ); /* back */ move_svtr_ccw( SVTR_BACKPULSE, &pos, status, p_width * speed ); p_wait( 500000 ); /* find ORG (2nd)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin again... " ); n_limit = 100000; /* timeout pulse */ while( ( pioin() & PI_SVTR_ORG ) == PI_SVTR_ORG ){ pioout( status & ~PO_SVTR_CWP ); p_wait( p_width * speed ); pioout( status | PO_SVTR_CWP ); p_wait( p_width * speed ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); return(0); } /* move Slirviewer pulse_n steps in CW direction */ int move_svtr_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 1000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_SVTR_ORG ) != PI_SVTR_ORG ){ printf( "Origin !! +%i steps moved. Continue... \n", i ); } pioout( status & ~PO_SVTR_CWP ); p_wait( p_width ); pioout( status | PO_SVTR_CWP ); p_wait( p_width ); i++; } printf( "Completed. +%i steps moved\n", i); *p_pos += i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* move Slitviewer pulse_n steps in CCW direction */ int move_svtr_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 10000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_SVTR_ORG ) != PI_SVTR_ORG ){ printf( "Origin !! -%i steps moved. Continue... \n", i ); } pioout( status & ~PO_SVTR_CCWP ); p_wait( p_width ); pioout( status | PO_SVTR_CCWP ); p_wait( p_width ); i++; } printf( "Completed. -%i steps moved\n", i ); *p_pos -= i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* ------------------- Cross Disperser ------------------- */ /* set Cross Disperser to org. position */ int set_crds_org( unsigned long status , unsigned int p_width ) { unsigned int n_limit; long pos; unsigned long speed; speed = 20; pos = 0; /* find ORG (1st)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin ... " ); n_limit = 100000; /* timeout pulse */ while( ( pioin() & PI_CRDS_ORG ) == PI_CRDS_ORG ){ pioout( status & ~PO_CRDS_CWP ); p_wait( p_width ); pioout( status | PO_CRDS_CWP ); p_wait( p_width ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); p_wait( 500000 ); /* back */ move_crds_ccw( CRDS_BACKPULSE, &pos, status, p_width * speed ); p_wait( 500000 ); /* find ORG (2nd)*/ p_sensor( SW_ON, &status ); printf( "Finding Origin again... " ); n_limit = 100000; /* timeout pulse */ while( ( pioin() & PI_CRDS_ORG ) == PI_CRDS_ORG ){ pioout( status & ~PO_CRDS_CWP); p_wait( p_width * speed ); pioout( status | PO_CRDS_CWP); p_wait( p_width * speed ); if( --n_limit == 0 ){ p_sensor( SW_OFF, &status ); printf( "Error !!\n" ); return(-1); } } printf( "Found!!\n" ); p_sensor( SW_OFF, &status ); return(0); } /* move Cross Disperser pulse_n steps in CW direction */ int move_crds_cw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 1000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_CRDS_ORG ) != PI_CRDS_ORG ){ printf( "Origin !! +%i steps moved. Continue... \n", i ); } pioout( status & ~PO_CRDS_CWP ); p_wait( p_width ); pioout( status | PO_CRDS_CWP ); p_wait( p_width ); i++; } printf( "Completed. +%i steps moved\n", i ); *p_pos += i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* move Cross Disperser pulse_n steps in CCW direction */ int move_crds_ccw( unsigned long pulse_n, long *p_pos, unsigned long status, unsigned int p_width ) { unsigned long i; unsigned long signal; if( pulse_n <= 0 ){ printf( "Can't move !\n" ); return(-1); } status |= PO_PHSENSOR; pioout( status ); p_wait( 10000 ); printf( "Moving ...\n" ); i = 0; while( i < pulse_n ){ signal = pioin(); if( ( signal & PI_CRDS_ORG ) != PI_CRDS_ORG ){ printf( "Origin !! -%i steps moved. Continue... \n", i ); } pioout( status & ~PO_CRDS_CCWP ); p_wait( p_width ); pioout( status | PO_CRDS_CCWP ); p_wait( p_width ); i++; } printf( "Completed. -%i steps moved\n", i ); *p_pos -= i; status &= ~PO_PHSENSOR; pioout( status ); return(0); } /* Photomicro sensor ON/OFF */ void p_sensor( int on_off , unsigned long *p_status ) { if( on_off == SW_ON ){ *p_status |= PO_PHSENSOR; } else if( on_off == SW_OFF ){ *p_status &= ~PO_PHSENSOR; } pioout( *p_status ); p_wait( 1000 ); return; } /* slit position definition */ void read_diaphdef( int *ndiaph, struct name_coord *diaphdef, char filename[] ) { FILE *diaph_f; int n; if( ( diaph_f = fopen( filename, "r" ) ) == NULL ){ printf( "command file '%s' is not found!!!\n", filename ); *ndiaph = 0; return; } n = 0; while( fscanf( diaph_f, "%s %li %s", diaphdef[n+1].name, &diaphdef[n+1].coord, diaphdef[n+1].comment ) != EOF ) n++; *ndiaph = n; return; } /* guide mirror position definition */ long read_gdmrdef( void ) { long gdmr_inpos; FILE *gdmr_f; if( ( gdmr_f = fopen( GDMRDEFFILE, "r" ) ) == NULL ){ printf( "command file "GDMRDEFFILE" is not found!!!\n" ); return; } fscanf( gdmr_f, "%i", &gdmr_inpos ); printf( "Guide Mirror IN: position = %i\n", gdmr_inpos ); return( gdmr_inpos ) ; } /* Show diaph definition */ void show_diaphdef( int ndiaph, struct name_coord diaphdef[] ) { int i; if( ndiaph == 0 ){ printf( "No component is defined !!\n" ); return; } printf( "Name Position Comment\n" ); for( i = 1; i <= ndiaph; i++ ) printf( "%-16s%10li %-s\n", diaphdef[i].name, diaphdef[i].coord, diaphdef[i].comment ); return; } /* Show command help void showhelp( void ){ FILE *f_help; char hlp_str[STRING_MAX]; int hlp_line; if( ( f_help = fopen( HELPFILE, "r" ) ) == NULL ){ printf( "Cannot display help!!\n" ); return; } hlp_line = 0; while( fgets( hlp_str, STRING_MAX, f_help ) != NULL ){ ++hlp_line; printf( "%s", hlp_str ); if( hlp_line == PAGE ){ printf( "-- (hit RETURN) --" ); fgets( hlp_str, STRING_MAX, stdin ); hlp_line = 0; } } fclose( f_help ); return; } */ /* startup messages */ void start_msg( void ){ printf( "=================================================\n" ); printf( " LIPS motor control program \n" ); #ifdef LINUX printf( " for Linux \n" ); #endif #ifdef DOS printf( " for Windows/Dos \n" ); #endif printf( " Original Development by H.Akitaya \n" ); printf( " \n" ); printf( " Ver 2.0 2004.8.23 K.Matsuda \n" ); printf( "=================================================\n" ); return; }