/****************************************************************/ /* splitil */ /****************************************************************/ /* Short Description : */ /* Splits a ser file with interleaved data */ /****************************************************************/ /* Syntax: */ /* SPLITIL subspectra startexpno rowsperinc */ /* */ /* subspectra: The number of subspectra (2) */ /* startexpno: Expno to put the first subspectra into, */ /* defaults to expno*1000+1 */ /* rowsperinc: The number of rows (with TD-datapoints) */ /* per increment. Depending on type of */ /* FnMODE and order of the interleaved */ /* data this can be 1 or 2. Defaults to 1. */ /* */ /* Usage: */ /* 1 splitil 2 */ /* Splits to two expnos: */ /* Row 1,3,5,... goes to the first */ /* Row 2,4,6,... goes to the second */ /* */ /* 2 splitil 2 11 2 */ /* Splits to expnos 11 and 12: */ /* Row 1,2,5,6,... goes to expno 11 */ /* Row 3,4,7,8,... goes to expno 12 */ /* */ /* 3 splitil (without parameters) */ /* Opens up a dialog window */ /* */ /****************************************************************/ /* Nils Nyberg, CRC, 2005-07-01 */ /****************************************************************/ /* Changelog */ /* 2005-09-16 Changed default rowsperinc to 1 */ /* 2005-10-13 Changed default startexpno to *1000+1 */ /****************************************************************/ #include #include #define MAXSIZE 16384 #define MAXOUTFILES 16 char infile[PATH_MAX], outfile[MAXOUTFILES][PATH_MAX]; char *outfilepointer[MAXOUTFILES]; int td1, td2, td1s, parmode, mc2; int i; int subspectra, startexpno, rowsperinc; int nargs; int serdata[MAXSIZE]; FILE *fpin, *fpout[MAXOUTFILES]; /* The program only works on 2D datasets */ GETCURDATA FETCHPARS("PARMODE",&parmode); if (parmode != 1) {STOPMSG( "Not a 2D dataset" );} /* Get the processing parameter MC2 */ FETCHPAR1("MC2",&mc2); /* Get arguments */ nargs = sscanf(cmd,"%d %d %d",&subspectra,&startexpno,&rowsperinc); switch (nargs) { default: case -1: case 0: subspectra = 2; GETINT("Enter number of subspectra: ", subspectra); startexpno = 1 + expno * 1000; GETINT("Enter start-expno", startexpno); rowsperinc = 1; GETINT("Enter number of rows per increment: ", rowsperinc); break; case 1: startexpno = 1 + expno * 1000; rowsperinc = 1; break; case 2: rowsperinc = 1; break; case 3: break; } (void)sprintf(text,"%d %d %d",subspectra, startexpno, rowsperinc); Show_status(text); /* Get and set dataset dimension */ FETCHPARS("TD",&td2) td2 = ( (td2 + 255) / 256 ) * 256; FETCHPAR1("TD",&td1) FETCHPAR1S("TD",&td1s) /* Set ser-file name (infile) */ (void)sprintf(infile,"%s/data/%s/nmr/%s/%d/ser",disk,user,name,expno); /* Set output ser files (outfile) */ for (i=0; i < subspectra; i++) { (void)sprintf(outfile[i],"%s/data/%s/nmr/%s/%d/ser",disk,user,name,startexpno+i); outfilepointer[i] = outfile[i]; } /* Copy raw data to new datasets */ for (i=0; i < subspectra; i++) { WRA(startexpno+i); } /* Open files for read and write */ fpin=fopen(infile,"rb"); for (i=0; i < subspectra; i++) { fpout[i]=fopen(outfilepointer[i],"wb"); } /* Do the actual splitting */ for (i=0; i < td1s/rowsperinc; i++) { fread(serdata,sizeof(int),td2*rowsperinc,fpin); fwrite(serdata,sizeof(int),td2*rowsperinc,fpout[i % subspectra]); } /* Close the opened files */ fclose(fpin); for (i=0; i < subspectra; i++) { fclose(fpout[i]); } /* Adjust td1 and td1s to reflect the new datasize */ td1 /= subspectra; td1s /= subspectra; for (i=0; i < subspectra; i++) { DATASET (name,startexpno+i,procno,disk,user) STOREPAR1("TD",td1) STOREPAR1S("TD",td1s) } (void)sprintf( text, "Finished; Subsp = %d, Expno = %d-%d, Rows/inc = %d", subspectra, startexpno, startexpno+subspectra-1, rowsperinc); Show_status(text); QUIT